test_ap_hs20.py 227 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636
  1. # Hotspot 2.0 tests
  2. # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. from remotehost import remote_compatible
  7. import base64
  8. import binascii
  9. import struct
  10. import time
  11. import logging
  12. logger = logging.getLogger()
  13. import os
  14. import os.path
  15. import socket
  16. import subprocess
  17. import hostapd
  18. from utils import HwsimSkip, skip_with_fips, alloc_fail, fail_test, wait_fail_trigger
  19. import hwsim_utils
  20. from tshark import run_tshark
  21. from wlantest import Wlantest
  22. from wpasupplicant import WpaSupplicant
  23. from test_ap_eap import check_eap_capa, check_domain_match_full
  24. from test_gas import gas_rx, parse_gas, action_response, anqp_initial_resp, send_gas_resp, ACTION_CATEG_PUBLIC, GAS_INITIAL_RESPONSE
  25. def hs20_ap_params(ssid="test-hs20"):
  26. params = hostapd.wpa2_params(ssid=ssid)
  27. params['wpa_key_mgmt'] = "WPA-EAP"
  28. params['ieee80211w'] = "1"
  29. params['ieee8021x'] = "1"
  30. params['auth_server_addr'] = "127.0.0.1"
  31. params['auth_server_port'] = "1812"
  32. params['auth_server_shared_secret'] = "radius"
  33. params['interworking'] = "1"
  34. params['access_network_type'] = "14"
  35. params['internet'] = "1"
  36. params['asra'] = "0"
  37. params['esr'] = "0"
  38. params['uesa'] = "0"
  39. params['venue_group'] = "7"
  40. params['venue_type'] = "1"
  41. params['venue_name'] = [ "eng:Example venue", "fin:Esimerkkipaikka" ]
  42. params['roaming_consortium'] = [ "112233", "1020304050", "010203040506",
  43. "fedcba" ]
  44. params['domain_name'] = "example.com,another.example.com"
  45. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]",
  46. "0,another.example.com" ]
  47. params['hs20'] = "1"
  48. params['hs20_wan_metrics'] = "01:8000:1000:80:240:3000"
  49. params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0" ]
  50. params['hs20_operating_class'] = "5173"
  51. params['anqp_3gpp_cell_net'] = "244,91"
  52. return params
  53. def check_auto_select(dev, bssid):
  54. dev.scan_for_bss(bssid, freq="2412")
  55. dev.request("INTERWORKING_SELECT auto freq=2412")
  56. ev = dev.wait_connected(timeout=15)
  57. if bssid not in ev:
  58. raise Exception("Connected to incorrect network")
  59. dev.request("REMOVE_NETWORK all")
  60. dev.wait_disconnected()
  61. dev.dump_monitor()
  62. def interworking_select(dev, bssid, type=None, no_match=False, freq=None):
  63. dev.dump_monitor()
  64. if bssid and freq and not no_match:
  65. dev.scan_for_bss(bssid, freq=freq)
  66. freq_extra = " freq=" + str(freq) if freq else ""
  67. dev.request("INTERWORKING_SELECT" + freq_extra)
  68. ev = dev.wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
  69. timeout=15)
  70. if ev is None:
  71. raise Exception("Network selection timed out")
  72. if no_match:
  73. if "INTERWORKING-NO-MATCH" not in ev:
  74. raise Exception("Unexpected network match")
  75. return
  76. if "INTERWORKING-NO-MATCH" in ev:
  77. logger.info("Matching network not found - try again")
  78. dev.dump_monitor()
  79. dev.request("INTERWORKING_SELECT" + freq_extra)
  80. ev = dev.wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
  81. timeout=15)
  82. if ev is None:
  83. raise Exception("Network selection timed out")
  84. if "INTERWORKING-NO-MATCH" in ev:
  85. raise Exception("Matching network not found")
  86. if bssid and bssid not in ev:
  87. raise Exception("Unexpected BSSID in match")
  88. if type and "type=" + type not in ev:
  89. raise Exception("Network type not recognized correctly")
  90. def check_sp_type(dev, sp_type):
  91. type = dev.get_status_field("sp_type")
  92. if type is None:
  93. raise Exception("sp_type not available")
  94. if type != sp_type:
  95. raise Exception("sp_type did not indicate home network")
  96. def hlr_auc_gw_available():
  97. if not os.path.exists("/tmp/hlr_auc_gw.sock"):
  98. raise HwsimSkip("No hlr_auc_gw socket available")
  99. if not os.path.exists("../../hostapd/hlr_auc_gw"):
  100. raise HwsimSkip("No hlr_auc_gw available")
  101. def interworking_ext_sim_connect(dev, bssid, method):
  102. dev.request("INTERWORKING_CONNECT " + bssid)
  103. interworking_ext_sim_auth(dev, method)
  104. def interworking_ext_sim_auth(dev, method):
  105. ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  106. if ev is None:
  107. raise Exception("Network connected timed out")
  108. if "(" + method + ")" not in ev:
  109. raise Exception("Unexpected EAP method selection")
  110. ev = dev.wait_event(["CTRL-REQ-SIM"], timeout=15)
  111. if ev is None:
  112. raise Exception("Wait for external SIM processing request timed out")
  113. p = ev.split(':', 2)
  114. if p[1] != "GSM-AUTH":
  115. raise Exception("Unexpected CTRL-REQ-SIM type")
  116. id = p[0].split('-')[3]
  117. rand = p[2].split(' ')[0]
  118. res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
  119. "-m",
  120. "auth_serv/hlr_auc_gw.milenage_db",
  121. "GSM-AUTH-REQ 232010000000000 " + rand])
  122. if "GSM-AUTH-RESP" not in res:
  123. raise Exception("Unexpected hlr_auc_gw response")
  124. resp = res.split(' ')[2].rstrip()
  125. dev.request("CTRL-RSP-SIM-" + id + ":GSM-AUTH:" + resp)
  126. dev.wait_connected(timeout=15)
  127. def interworking_connect(dev, bssid, method):
  128. dev.request("INTERWORKING_CONNECT " + bssid)
  129. interworking_auth(dev, method)
  130. def interworking_auth(dev, method):
  131. ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  132. if ev is None:
  133. raise Exception("Network connected timed out")
  134. if "(" + method + ")" not in ev:
  135. raise Exception("Unexpected EAP method selection")
  136. dev.wait_connected(timeout=15)
  137. def check_probe_resp(wt, bssid_unexpected, bssid_expected):
  138. if bssid_unexpected:
  139. count = wt.get_bss_counter("probe_response", bssid_unexpected)
  140. if count > 0:
  141. raise Exception("Unexpected Probe Response frame from AP")
  142. if bssid_expected:
  143. count = wt.get_bss_counter("probe_response", bssid_expected)
  144. if count == 0:
  145. raise Exception("No Probe Response frame from AP")
  146. def test_ap_anqp_sharing(dev, apdev):
  147. """ANQP sharing within ESS and explicit unshare"""
  148. check_eap_capa(dev[0], "MSCHAPV2")
  149. dev[0].flush_scan_cache()
  150. bssid = apdev[0]['bssid']
  151. params = hs20_ap_params()
  152. params['hessid'] = bssid
  153. hostapd.add_ap(apdev[0], params)
  154. bssid2 = apdev[1]['bssid']
  155. params = hs20_ap_params()
  156. params['hessid'] = bssid
  157. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]" ]
  158. hostapd.add_ap(apdev[1], params)
  159. dev[0].hs20_enable()
  160. id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test",
  161. 'password': "secret",
  162. 'domain': "example.com" })
  163. logger.info("Normal network selection with shared ANQP results")
  164. dev[0].scan_for_bss(bssid, freq="2412")
  165. dev[0].scan_for_bss(bssid2, freq="2412")
  166. interworking_select(dev[0], None, "home", freq="2412")
  167. dev[0].dump_monitor()
  168. state = dev[0].get_status_field('wpa_state')
  169. if state != "DISCONNECTED":
  170. raise Exception("Unexpected wpa_state after INTERWORKING_SELECT: " + state)
  171. logger.debug("BSS entries:\n" + dev[0].request("BSS RANGE=ALL"))
  172. res1 = dev[0].get_bss(bssid)
  173. res2 = dev[0].get_bss(bssid2)
  174. if 'anqp_nai_realm' not in res1:
  175. raise Exception("anqp_nai_realm not found for AP1")
  176. if 'anqp_nai_realm' not in res2:
  177. raise Exception("anqp_nai_realm not found for AP2")
  178. if res1['anqp_nai_realm'] != res2['anqp_nai_realm']:
  179. raise Exception("ANQP results were not shared between BSSes")
  180. logger.info("Explicit ANQP request to unshare ANQP results")
  181. dev[0].request("ANQP_GET " + bssid + " 263")
  182. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  183. if ev is None:
  184. raise Exception("ANQP operation timed out")
  185. dev[0].request("ANQP_GET " + bssid2 + " 263")
  186. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  187. if ev is None:
  188. raise Exception("ANQP operation timed out")
  189. res1 = dev[0].get_bss(bssid)
  190. res2 = dev[0].get_bss(bssid2)
  191. if res1['anqp_nai_realm'] == res2['anqp_nai_realm']:
  192. raise Exception("ANQP results were not unshared")
  193. def test_ap_anqp_domain_id(dev, apdev):
  194. """ANQP Domain ID"""
  195. check_eap_capa(dev[0], "MSCHAPV2")
  196. dev[0].flush_scan_cache()
  197. bssid = apdev[0]['bssid']
  198. params = hs20_ap_params()
  199. params['hessid'] = bssid
  200. params['anqp_domain_id'] = '1234'
  201. hostapd.add_ap(apdev[0], params)
  202. bssid2 = apdev[1]['bssid']
  203. params = hs20_ap_params()
  204. params['hessid'] = bssid
  205. params['anqp_domain_id'] = '1234'
  206. hostapd.add_ap(apdev[1], params)
  207. dev[0].hs20_enable()
  208. id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test",
  209. 'password': "secret",
  210. 'domain': "example.com" })
  211. dev[0].scan_for_bss(bssid, freq="2412")
  212. dev[0].scan_for_bss(bssid2, freq="2412")
  213. interworking_select(dev[0], None, "home", freq="2412")
  214. def test_ap_anqp_no_sharing_diff_ess(dev, apdev):
  215. """ANQP no sharing between ESSs"""
  216. check_eap_capa(dev[0], "MSCHAPV2")
  217. dev[0].flush_scan_cache()
  218. bssid = apdev[0]['bssid']
  219. params = hs20_ap_params()
  220. params['hessid'] = bssid
  221. hostapd.add_ap(apdev[0], params)
  222. bssid2 = apdev[1]['bssid']
  223. params = hs20_ap_params(ssid="test-hs20-another")
  224. params['hessid'] = bssid
  225. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]" ]
  226. hostapd.add_ap(apdev[1], params)
  227. dev[0].hs20_enable()
  228. id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test",
  229. 'password': "secret",
  230. 'domain': "example.com" })
  231. logger.info("Normal network selection with shared ANQP results")
  232. dev[0].scan_for_bss(bssid, freq="2412")
  233. dev[0].scan_for_bss(bssid2, freq="2412")
  234. interworking_select(dev[0], None, "home", freq="2412")
  235. def test_ap_anqp_no_sharing_missing_info(dev, apdev):
  236. """ANQP no sharing due to missing information"""
  237. check_eap_capa(dev[0], "MSCHAPV2")
  238. dev[0].flush_scan_cache()
  239. bssid = apdev[0]['bssid']
  240. params = hs20_ap_params()
  241. params['hessid'] = bssid
  242. del params['roaming_consortium']
  243. del params['domain_name']
  244. del params['anqp_3gpp_cell_net']
  245. del params['nai_realm']
  246. hostapd.add_ap(apdev[0], params)
  247. bssid2 = apdev[1]['bssid']
  248. params = hs20_ap_params()
  249. params['hessid'] = bssid
  250. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]" ]
  251. hostapd.add_ap(apdev[1], params)
  252. dev[0].hs20_enable()
  253. id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test",
  254. 'password': "secret",
  255. 'domain': "example.com" })
  256. logger.info("Normal network selection with shared ANQP results")
  257. dev[0].scan_for_bss(bssid, freq="2412")
  258. dev[0].scan_for_bss(bssid2, freq="2412")
  259. interworking_select(dev[0], None, "home", freq="2412")
  260. def test_ap_anqp_sharing_oom(dev, apdev):
  261. """ANQP sharing within ESS and explicit unshare OOM"""
  262. check_eap_capa(dev[0], "MSCHAPV2")
  263. dev[0].flush_scan_cache()
  264. bssid = apdev[0]['bssid']
  265. params = hs20_ap_params()
  266. params['hessid'] = bssid
  267. hostapd.add_ap(apdev[0], params)
  268. bssid2 = apdev[1]['bssid']
  269. params = hs20_ap_params()
  270. params['hessid'] = bssid
  271. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]" ]
  272. hostapd.add_ap(apdev[1], params)
  273. dev[0].hs20_enable()
  274. id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test",
  275. 'password': "secret",
  276. 'domain': "example.com" })
  277. dev[0].scan_for_bss(bssid, freq="2412")
  278. dev[0].scan_for_bss(bssid2, freq="2412")
  279. interworking_select(dev[0], None, "home", freq="2412")
  280. dev[0].dump_monitor()
  281. with alloc_fail(dev[0], 1, "wpa_bss_anqp_clone"):
  282. dev[0].request("ANQP_GET " + bssid + " 263")
  283. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  284. if ev is None:
  285. raise Exception("ANQP operation timed out")
  286. def test_ap_nai_home_realm_query(dev, apdev):
  287. """NAI Home Realm Query"""
  288. check_eap_capa(dev[0], "MSCHAPV2")
  289. bssid = apdev[0]['bssid']
  290. params = hs20_ap_params()
  291. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]",
  292. "0,another.example.org" ]
  293. hostapd.add_ap(apdev[0], params)
  294. dev[0].scan(freq="2412")
  295. dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + bssid + " realm=example.com")
  296. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  297. if ev is None:
  298. raise Exception("ANQP operation timed out")
  299. nai1 = dev[0].get_bss(bssid)['anqp_nai_realm']
  300. dev[0].dump_monitor()
  301. dev[0].request("ANQP_GET " + bssid + " 263")
  302. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  303. if ev is None:
  304. raise Exception("ANQP operation timed out")
  305. nai2 = dev[0].get_bss(bssid)['anqp_nai_realm']
  306. if len(nai1) >= len(nai2):
  307. raise Exception("Unexpected NAI Realm list response lengths")
  308. if "example.com".encode('hex') not in nai1:
  309. raise Exception("Home realm not reported")
  310. if "example.org".encode('hex') in nai1:
  311. raise Exception("Non-home realm reported")
  312. if "example.com".encode('hex') not in nai2:
  313. raise Exception("Home realm not reported in wildcard query")
  314. if "example.org".encode('hex') not in nai2:
  315. raise Exception("Non-home realm not reported in wildcard query ")
  316. cmds = [ "foo",
  317. "00:11:22:33:44:55 123",
  318. "00:11:22:33:44:55 qq" ]
  319. for cmd in cmds:
  320. if "FAIL" not in dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + cmd):
  321. raise Exception("Invalid HS20_GET_NAI_HOME_REALM_LIST accepted: " + cmd)
  322. dev[0].dump_monitor()
  323. if "OK" not in dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + bssid):
  324. raise Exception("HS20_GET_NAI_HOME_REALM_LIST failed")
  325. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  326. if ev is None:
  327. raise Exception("ANQP operation timed out")
  328. ev = dev[0].wait_event(["RX-ANQP"], timeout=0.1)
  329. if ev is not None:
  330. raise Exception("Unexpected ANQP response: " + ev)
  331. dev[0].dump_monitor()
  332. if "OK" not in dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + bssid + " 01000b6578616d706c652e636f6d"):
  333. raise Exception("HS20_GET_NAI_HOME_REALM_LIST failed")
  334. ev = dev[0].wait_event(["RX-ANQP"], timeout=10)
  335. if ev is None:
  336. raise Exception("No ANQP response")
  337. if "NAI Realm list" not in ev:
  338. raise Exception("Missing NAI Realm list: " + ev)
  339. dev[0].add_cred_values({ 'realm': "example.com", 'username': "test",
  340. 'password': "secret",
  341. 'domain': "example.com" })
  342. dev[0].dump_monitor()
  343. if "OK" not in dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + bssid):
  344. raise Exception("HS20_GET_NAI_HOME_REALM_LIST failed")
  345. ev = dev[0].wait_event(["RX-ANQP"], timeout=10)
  346. if ev is None:
  347. raise Exception("No ANQP response")
  348. if "NAI Realm list" not in ev:
  349. raise Exception("Missing NAI Realm list: " + ev)
  350. @remote_compatible
  351. def test_ap_interworking_scan_filtering(dev, apdev):
  352. """Interworking scan filtering with HESSID and access network type"""
  353. try:
  354. _test_ap_interworking_scan_filtering(dev, apdev)
  355. finally:
  356. dev[0].request("SET hessid 00:00:00:00:00:00")
  357. dev[0].request("SET access_network_type 15")
  358. def _test_ap_interworking_scan_filtering(dev, apdev):
  359. bssid = apdev[0]['bssid']
  360. params = hs20_ap_params()
  361. ssid = "test-hs20-ap1"
  362. params['ssid'] = ssid
  363. params['hessid'] = bssid
  364. hapd0 = hostapd.add_ap(apdev[0], params)
  365. bssid2 = apdev[1]['bssid']
  366. params = hs20_ap_params()
  367. ssid2 = "test-hs20-ap2"
  368. params['ssid'] = ssid2
  369. params['hessid'] = bssid2
  370. params['access_network_type'] = "1"
  371. del params['venue_group']
  372. del params['venue_type']
  373. hostapd.add_ap(apdev[1], params)
  374. dev[0].hs20_enable()
  375. Wlantest.setup(hapd0)
  376. wt = Wlantest()
  377. wt.flush()
  378. # Make sure wlantest has seen both BSSs to avoid issues in trying to clear
  379. # counters for non-existing BSS.
  380. dev[0].scan_for_bss(bssid, freq="2412")
  381. dev[0].scan_for_bss(bssid2, freq="2412")
  382. wt.clear_bss_counters(bssid)
  383. wt.clear_bss_counters(bssid2)
  384. logger.info("Check probe request filtering based on HESSID")
  385. dev[0].request("SET hessid " + bssid2)
  386. dev[0].scan(freq="2412")
  387. time.sleep(0.03)
  388. check_probe_resp(wt, bssid, bssid2)
  389. logger.info("Check probe request filtering based on access network type")
  390. wt.clear_bss_counters(bssid)
  391. wt.clear_bss_counters(bssid2)
  392. dev[0].request("SET hessid 00:00:00:00:00:00")
  393. dev[0].request("SET access_network_type 14")
  394. dev[0].scan(freq="2412")
  395. time.sleep(0.03)
  396. check_probe_resp(wt, bssid2, bssid)
  397. wt.clear_bss_counters(bssid)
  398. wt.clear_bss_counters(bssid2)
  399. dev[0].request("SET hessid 00:00:00:00:00:00")
  400. dev[0].request("SET access_network_type 1")
  401. dev[0].scan(freq="2412")
  402. time.sleep(0.03)
  403. check_probe_resp(wt, bssid, bssid2)
  404. logger.info("Check probe request filtering based on HESSID and ANT")
  405. wt.clear_bss_counters(bssid)
  406. wt.clear_bss_counters(bssid2)
  407. dev[0].request("SET hessid " + bssid)
  408. dev[0].request("SET access_network_type 14")
  409. dev[0].scan(freq="2412")
  410. time.sleep(0.03)
  411. check_probe_resp(wt, bssid2, bssid)
  412. wt.clear_bss_counters(bssid)
  413. wt.clear_bss_counters(bssid2)
  414. dev[0].request("SET hessid " + bssid2)
  415. dev[0].request("SET access_network_type 14")
  416. dev[0].scan(freq="2412")
  417. time.sleep(0.03)
  418. check_probe_resp(wt, bssid, None)
  419. check_probe_resp(wt, bssid2, None)
  420. wt.clear_bss_counters(bssid)
  421. wt.clear_bss_counters(bssid2)
  422. dev[0].request("SET hessid " + bssid)
  423. dev[0].request("SET access_network_type 1")
  424. dev[0].scan(freq="2412")
  425. time.sleep(0.03)
  426. check_probe_resp(wt, bssid, None)
  427. check_probe_resp(wt, bssid2, None)
  428. def test_ap_hs20_select(dev, apdev):
  429. """Hotspot 2.0 network selection"""
  430. bssid = apdev[0]['bssid']
  431. params = hs20_ap_params()
  432. params['hessid'] = bssid
  433. hostapd.add_ap(apdev[0], params)
  434. dev[0].hs20_enable()
  435. id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test",
  436. 'password': "secret",
  437. 'domain': "example.com" })
  438. interworking_select(dev[0], bssid, "home")
  439. dev[0].remove_cred(id)
  440. id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test",
  441. 'password': "secret",
  442. 'domain': "no.match.example.com" })
  443. interworking_select(dev[0], bssid, "roaming", freq="2412")
  444. dev[0].set_cred_quoted(id, "realm", "no.match.example.com")
  445. interworking_select(dev[0], bssid, no_match=True, freq="2412")
  446. res = dev[0].request("SCAN_RESULTS")
  447. if "[HS20]" not in res:
  448. raise Exception("HS20 flag missing from scan results: " + res)
  449. bssid2 = apdev[1]['bssid']
  450. params = hs20_ap_params()
  451. params['nai_realm'] = [ "0,example.org,21" ]
  452. params['hessid'] = bssid2
  453. params['domain_name'] = "example.org"
  454. hostapd.add_ap(apdev[1], params)
  455. dev[0].remove_cred(id)
  456. id = dev[0].add_cred_values({ 'realm': "example.org", 'username': "test",
  457. 'password': "secret",
  458. 'domain': "example.org" })
  459. interworking_select(dev[0], bssid2, "home", freq="2412")
  460. def hs20_simulated_sim(dev, ap, method):
  461. bssid = ap['bssid']
  462. params = hs20_ap_params()
  463. params['hessid'] = bssid
  464. params['anqp_3gpp_cell_net'] = "555,444"
  465. params['domain_name'] = "wlan.mnc444.mcc555.3gppnetwork.org"
  466. hostapd.add_ap(ap, params)
  467. dev.hs20_enable()
  468. dev.add_cred_values({ 'imsi': "555444-333222111", 'eap': method,
  469. 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123"})
  470. interworking_select(dev, bssid, "home", freq="2412")
  471. interworking_connect(dev, bssid, method)
  472. check_sp_type(dev, "home")
  473. def test_ap_hs20_sim(dev, apdev):
  474. """Hotspot 2.0 with simulated SIM and EAP-SIM"""
  475. hlr_auc_gw_available()
  476. hs20_simulated_sim(dev[0], apdev[0], "SIM")
  477. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  478. ev = dev[0].wait_event(["INTERWORKING-ALREADY-CONNECTED"], timeout=15)
  479. if ev is None:
  480. raise Exception("Timeout on already-connected event")
  481. def test_ap_hs20_sim_invalid(dev, apdev):
  482. """Hotspot 2.0 with simulated SIM and EAP-SIM - invalid IMSI"""
  483. hlr_auc_gw_available()
  484. bssid = apdev[0]['bssid']
  485. params = hs20_ap_params()
  486. params['hessid'] = bssid
  487. params['anqp_3gpp_cell_net'] = "555,444"
  488. params['domain_name'] = "wlan.mnc444.mcc555.3gppnetwork.org"
  489. hostapd.add_ap(apdev[0], params)
  490. dev[0].hs20_enable()
  491. dev[0].add_cred_values({ 'imsi': "555444-3332221110", 'eap': "SIM",
  492. 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123"})
  493. # This hits "No valid IMSI available" in build_root_nai()
  494. interworking_select(dev[0], bssid, freq="2412")
  495. def test_ap_hs20_sim_oom(dev, apdev):
  496. """Hotspot 2.0 with simulated SIM and EAP-SIM - OOM"""
  497. hlr_auc_gw_available()
  498. bssid = apdev[0]['bssid']
  499. params = hs20_ap_params()
  500. params['hessid'] = bssid
  501. params['anqp_3gpp_cell_net'] = "555,444"
  502. params['domain_name'] = "wlan.mnc444.mcc555.3gppnetwork.org"
  503. hostapd.add_ap(apdev[0], params)
  504. dev[0].hs20_enable()
  505. dev[0].add_cred_values({ 'imsi': "555444-333222111", 'eap': "SIM",
  506. 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123"})
  507. dev[0].scan_for_bss(bssid, freq=2412)
  508. interworking_select(dev[0], bssid, freq="2412")
  509. with alloc_fail(dev[0], 1, "wpa_config_add_network;interworking_connect_3gpp"):
  510. dev[0].request("INTERWORKING_CONNECT " + bssid)
  511. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  512. with alloc_fail(dev[0], 1, "=interworking_connect_3gpp"):
  513. dev[0].request("INTERWORKING_CONNECT " + bssid)
  514. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  515. def test_ap_hs20_aka(dev, apdev):
  516. """Hotspot 2.0 with simulated USIM and EAP-AKA"""
  517. hlr_auc_gw_available()
  518. hs20_simulated_sim(dev[0], apdev[0], "AKA")
  519. def test_ap_hs20_aka_prime(dev, apdev):
  520. """Hotspot 2.0 with simulated USIM and EAP-AKA'"""
  521. hlr_auc_gw_available()
  522. hs20_simulated_sim(dev[0], apdev[0], "AKA'")
  523. def test_ap_hs20_ext_sim(dev, apdev):
  524. """Hotspot 2.0 with external SIM processing"""
  525. hlr_auc_gw_available()
  526. bssid = apdev[0]['bssid']
  527. params = hs20_ap_params()
  528. params['hessid'] = bssid
  529. params['anqp_3gpp_cell_net'] = "232,01"
  530. params['domain_name'] = "wlan.mnc001.mcc232.3gppnetwork.org"
  531. hostapd.add_ap(apdev[0], params)
  532. dev[0].hs20_enable()
  533. try:
  534. dev[0].request("SET external_sim 1")
  535. dev[0].add_cred_values({ 'imsi': "23201-0000000000", 'eap': "SIM" })
  536. interworking_select(dev[0], bssid, "home", freq="2412")
  537. interworking_ext_sim_connect(dev[0], bssid, "SIM")
  538. check_sp_type(dev[0], "home")
  539. finally:
  540. dev[0].request("SET external_sim 0")
  541. def test_ap_hs20_ext_sim_roaming(dev, apdev):
  542. """Hotspot 2.0 with external SIM processing in roaming network"""
  543. hlr_auc_gw_available()
  544. bssid = apdev[0]['bssid']
  545. params = hs20_ap_params()
  546. params['hessid'] = bssid
  547. params['anqp_3gpp_cell_net'] = "244,91;310,026;232,01;234,56"
  548. params['domain_name'] = "wlan.mnc091.mcc244.3gppnetwork.org"
  549. hostapd.add_ap(apdev[0], params)
  550. dev[0].hs20_enable()
  551. try:
  552. dev[0].request("SET external_sim 1")
  553. dev[0].add_cred_values({ 'imsi': "23201-0000000000", 'eap': "SIM" })
  554. interworking_select(dev[0], bssid, "roaming", freq="2412")
  555. interworking_ext_sim_connect(dev[0], bssid, "SIM")
  556. check_sp_type(dev[0], "roaming")
  557. finally:
  558. dev[0].request("SET external_sim 0")
  559. def test_ap_hs20_username(dev, apdev):
  560. """Hotspot 2.0 connection in username/password credential"""
  561. check_eap_capa(dev[0], "MSCHAPV2")
  562. bssid = apdev[0]['bssid']
  563. params = hs20_ap_params()
  564. params['hessid'] = bssid
  565. params['disable_dgaf'] = '1'
  566. hostapd.add_ap(apdev[0], params)
  567. dev[0].hs20_enable()
  568. id = dev[0].add_cred_values({ 'realm': "example.com",
  569. 'username': "hs20-test",
  570. 'password': "password",
  571. 'ca_cert': "auth_serv/ca.pem",
  572. 'domain': "example.com",
  573. 'update_identifier': "1234" })
  574. interworking_select(dev[0], bssid, "home", freq="2412")
  575. interworking_connect(dev[0], bssid, "TTLS")
  576. check_sp_type(dev[0], "home")
  577. status = dev[0].get_status()
  578. if status['pairwise_cipher'] != "CCMP":
  579. raise Exception("Unexpected pairwise cipher")
  580. if status['hs20'] != "2":
  581. raise Exception("Unexpected HS 2.0 support indication")
  582. dev[1].connect("test-hs20", key_mgmt="WPA-EAP", eap="TTLS",
  583. identity="hs20-test", password="password",
  584. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  585. scan_freq="2412")
  586. def test_ap_hs20_connect_api(dev, apdev):
  587. """Hotspot 2.0 connection with connect API"""
  588. check_eap_capa(dev[0], "MSCHAPV2")
  589. bssid = apdev[0]['bssid']
  590. params = hs20_ap_params()
  591. params['hessid'] = bssid
  592. params['disable_dgaf'] = '1'
  593. hostapd.add_ap(apdev[0], params)
  594. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  595. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  596. wpas.hs20_enable()
  597. wpas.flush_scan_cache()
  598. id = wpas.add_cred_values({ 'realm': "example.com",
  599. 'username': "hs20-test",
  600. 'password': "password",
  601. 'ca_cert': "auth_serv/ca.pem",
  602. 'domain': "example.com",
  603. 'update_identifier': "1234" })
  604. interworking_select(wpas, bssid, "home", freq="2412")
  605. interworking_connect(wpas, bssid, "TTLS")
  606. check_sp_type(wpas, "home")
  607. status = wpas.get_status()
  608. if status['pairwise_cipher'] != "CCMP":
  609. raise Exception("Unexpected pairwise cipher")
  610. if status['hs20'] != "2":
  611. raise Exception("Unexpected HS 2.0 support indication")
  612. def test_ap_hs20_auto_interworking(dev, apdev):
  613. """Hotspot 2.0 connection with auto_interworking=1"""
  614. check_eap_capa(dev[0], "MSCHAPV2")
  615. bssid = apdev[0]['bssid']
  616. params = hs20_ap_params()
  617. params['hessid'] = bssid
  618. params['disable_dgaf'] = '1'
  619. hostapd.add_ap(apdev[0], params)
  620. dev[0].hs20_enable(auto_interworking=True)
  621. id = dev[0].add_cred_values({ 'realm': "example.com",
  622. 'username': "hs20-test",
  623. 'password': "password",
  624. 'ca_cert': "auth_serv/ca.pem",
  625. 'domain': "example.com",
  626. 'update_identifier': "1234" })
  627. dev[0].request("REASSOCIATE")
  628. dev[0].wait_connected(timeout=15)
  629. check_sp_type(dev[0], "home")
  630. status = dev[0].get_status()
  631. if status['pairwise_cipher'] != "CCMP":
  632. raise Exception("Unexpected pairwise cipher")
  633. if status['hs20'] != "2":
  634. raise Exception("Unexpected HS 2.0 support indication")
  635. @remote_compatible
  636. def test_ap_hs20_auto_interworking_no_match(dev, apdev):
  637. """Hotspot 2.0 connection with auto_interworking=1 and no matching network"""
  638. hapd = hostapd.add_ap(apdev[0], { "ssid": "mismatch" })
  639. dev[0].hs20_enable(auto_interworking=True)
  640. id = dev[0].connect("mismatch", psk="12345678", scan_freq="2412",
  641. only_add_network=True)
  642. dev[0].request("ENABLE_NETWORK " + str(id) + " no-connect")
  643. id = dev[0].add_cred_values({ 'realm': "example.com",
  644. 'username': "hs20-test",
  645. 'password': "password",
  646. 'ca_cert': "auth_serv/ca.pem",
  647. 'domain': "example.com",
  648. 'update_identifier': "1234" })
  649. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  650. time.sleep(0.1)
  651. dev[0].dump_monitor()
  652. for i in range(5):
  653. logger.info("start ping")
  654. if "PONG" not in dev[0].ctrl.request("PING", timeout=2):
  655. raise Exception("PING failed")
  656. logger.info("ping done")
  657. fetch = 0
  658. scan = 0
  659. for j in range(15):
  660. ev = dev[0].wait_event([ "ANQP fetch completed",
  661. "CTRL-EVENT-SCAN-RESULTS" ], timeout=0.05)
  662. if ev is None:
  663. break
  664. if "ANQP fetch completed" in ev:
  665. fetch += 1
  666. else:
  667. scan += 1
  668. if fetch > 2 * scan + 3:
  669. raise Exception("Too many ANQP fetch iterations")
  670. dev[0].dump_monitor()
  671. dev[0].request("DISCONNECT")
  672. @remote_compatible
  673. def test_ap_hs20_auto_interworking_no_cred_match(dev, apdev):
  674. """Hotspot 2.0 connection with auto_interworking=1 but no cred match"""
  675. bssid = apdev[0]['bssid']
  676. params = { "ssid": "test" }
  677. hostapd.add_ap(apdev[0], params)
  678. dev[0].hs20_enable(auto_interworking=True)
  679. dev[0].add_cred_values({ 'realm': "example.com",
  680. 'username': "hs20-test",
  681. 'password': "password",
  682. 'ca_cert': "auth_serv/ca.pem",
  683. 'domain': "example.com" })
  684. id = dev[0].connect("test", psk="12345678", only_add_network=True)
  685. dev[0].request("ENABLE_NETWORK %s" % id)
  686. logger.info("Verify that scanning continues when there is partial network block match")
  687. for i in range(0, 2):
  688. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
  689. if ev is None:
  690. raise Exception("Scan timed out")
  691. logger.info("Scan completed")
  692. def eap_test(dev, ap, eap_params, method, user):
  693. bssid = ap['bssid']
  694. params = hs20_ap_params()
  695. params['nai_realm'] = [ "0,example.com," + eap_params ]
  696. hostapd.add_ap(ap, params)
  697. dev.hs20_enable()
  698. dev.add_cred_values({ 'realm': "example.com",
  699. 'ca_cert': "auth_serv/ca.pem",
  700. 'username': user,
  701. 'password': "password" })
  702. interworking_select(dev, bssid, freq="2412")
  703. interworking_connect(dev, bssid, method)
  704. @remote_compatible
  705. def test_ap_hs20_eap_unknown(dev, apdev):
  706. """Hotspot 2.0 connection with unknown EAP method"""
  707. bssid = apdev[0]['bssid']
  708. params = hs20_ap_params()
  709. params['nai_realm'] = "0,example.com,99"
  710. hostapd.add_ap(apdev[0], params)
  711. dev[0].hs20_enable()
  712. dev[0].add_cred_values(default_cred())
  713. interworking_select(dev[0], None, no_match=True, freq="2412")
  714. def test_ap_hs20_eap_peap_mschapv2(dev, apdev):
  715. """Hotspot 2.0 connection with PEAP/MSCHAPV2"""
  716. check_eap_capa(dev[0], "MSCHAPV2")
  717. eap_test(dev[0], apdev[0], "25[3:26]", "PEAP", "user")
  718. def test_ap_hs20_eap_peap_default(dev, apdev):
  719. """Hotspot 2.0 connection with PEAP/MSCHAPV2 (as default)"""
  720. check_eap_capa(dev[0], "MSCHAPV2")
  721. eap_test(dev[0], apdev[0], "25", "PEAP", "user")
  722. def test_ap_hs20_eap_peap_gtc(dev, apdev):
  723. """Hotspot 2.0 connection with PEAP/GTC"""
  724. eap_test(dev[0], apdev[0], "25[3:6]", "PEAP", "user")
  725. @remote_compatible
  726. def test_ap_hs20_eap_peap_unknown(dev, apdev):
  727. """Hotspot 2.0 connection with PEAP/unknown"""
  728. bssid = apdev[0]['bssid']
  729. params = hs20_ap_params()
  730. params['nai_realm'] = "0,example.com,25[3:99]"
  731. hostapd.add_ap(apdev[0], params)
  732. dev[0].hs20_enable()
  733. dev[0].add_cred_values(default_cred())
  734. interworking_select(dev[0], None, no_match=True, freq="2412")
  735. def test_ap_hs20_eap_ttls_chap(dev, apdev):
  736. """Hotspot 2.0 connection with TTLS/CHAP"""
  737. skip_with_fips(dev[0])
  738. eap_test(dev[0], apdev[0], "21[2:2]", "TTLS", "chap user")
  739. def test_ap_hs20_eap_ttls_mschap(dev, apdev):
  740. """Hotspot 2.0 connection with TTLS/MSCHAP"""
  741. skip_with_fips(dev[0])
  742. eap_test(dev[0], apdev[0], "21[2:3]", "TTLS", "mschap user")
  743. def test_ap_hs20_eap_ttls_default(dev, apdev):
  744. """Hotspot 2.0 connection with TTLS/default"""
  745. skip_with_fips(dev[0])
  746. eap_test(dev[0], apdev[0], "21", "TTLS", "hs20-test")
  747. def test_ap_hs20_eap_ttls_eap_mschapv2(dev, apdev):
  748. """Hotspot 2.0 connection with TTLS/EAP-MSCHAPv2"""
  749. check_eap_capa(dev[0], "MSCHAPV2")
  750. eap_test(dev[0], apdev[0], "21[3:26][6:7][99:99]", "TTLS", "user")
  751. @remote_compatible
  752. def test_ap_hs20_eap_ttls_eap_unknown(dev, apdev):
  753. """Hotspot 2.0 connection with TTLS/EAP-unknown"""
  754. bssid = apdev[0]['bssid']
  755. params = hs20_ap_params()
  756. params['nai_realm'] = "0,example.com,21[3:99]"
  757. hostapd.add_ap(apdev[0], params)
  758. dev[0].hs20_enable()
  759. dev[0].add_cred_values(default_cred())
  760. interworking_select(dev[0], None, no_match=True, freq="2412")
  761. @remote_compatible
  762. def test_ap_hs20_eap_ttls_eap_unsupported(dev, apdev):
  763. """Hotspot 2.0 connection with TTLS/EAP-OTP(unsupported)"""
  764. bssid = apdev[0]['bssid']
  765. params = hs20_ap_params()
  766. params['nai_realm'] = "0,example.com,21[3:5]"
  767. hostapd.add_ap(apdev[0], params)
  768. dev[0].hs20_enable()
  769. dev[0].add_cred_values(default_cred())
  770. interworking_select(dev[0], None, no_match=True, freq="2412")
  771. @remote_compatible
  772. def test_ap_hs20_eap_ttls_unknown(dev, apdev):
  773. """Hotspot 2.0 connection with TTLS/unknown"""
  774. bssid = apdev[0]['bssid']
  775. params = hs20_ap_params()
  776. params['nai_realm'] = "0,example.com,21[2:5]"
  777. hostapd.add_ap(apdev[0], params)
  778. dev[0].hs20_enable()
  779. dev[0].add_cred_values(default_cred())
  780. interworking_select(dev[0], None, no_match=True, freq="2412")
  781. def test_ap_hs20_eap_fast_mschapv2(dev, apdev):
  782. """Hotspot 2.0 connection with FAST/EAP-MSCHAPV2"""
  783. check_eap_capa(dev[0], "FAST")
  784. eap_test(dev[0], apdev[0], "43[3:26]", "FAST", "user")
  785. def test_ap_hs20_eap_fast_gtc(dev, apdev):
  786. """Hotspot 2.0 connection with FAST/EAP-GTC"""
  787. check_eap_capa(dev[0], "FAST")
  788. eap_test(dev[0], apdev[0], "43[3:6]", "FAST", "user")
  789. def test_ap_hs20_eap_tls(dev, apdev):
  790. """Hotspot 2.0 connection with EAP-TLS"""
  791. bssid = apdev[0]['bssid']
  792. params = hs20_ap_params()
  793. params['nai_realm'] = [ "0,example.com,13[5:6]" ]
  794. hostapd.add_ap(apdev[0], params)
  795. dev[0].hs20_enable()
  796. dev[0].add_cred_values({ 'realm': "example.com",
  797. 'username': "certificate-user",
  798. 'ca_cert': "auth_serv/ca.pem",
  799. 'client_cert': "auth_serv/user.pem",
  800. 'private_key': "auth_serv/user.key"})
  801. interworking_select(dev[0], bssid, freq="2412")
  802. interworking_connect(dev[0], bssid, "TLS")
  803. @remote_compatible
  804. def test_ap_hs20_eap_cert_unknown(dev, apdev):
  805. """Hotspot 2.0 connection with certificate, but unknown EAP method"""
  806. bssid = apdev[0]['bssid']
  807. params = hs20_ap_params()
  808. params['nai_realm'] = [ "0,example.com,99[5:6]" ]
  809. hostapd.add_ap(apdev[0], params)
  810. dev[0].hs20_enable()
  811. dev[0].add_cred_values({ 'realm': "example.com",
  812. 'username': "certificate-user",
  813. 'ca_cert': "auth_serv/ca.pem",
  814. 'client_cert': "auth_serv/user.pem",
  815. 'private_key': "auth_serv/user.key"})
  816. interworking_select(dev[0], None, no_match=True, freq="2412")
  817. @remote_compatible
  818. def test_ap_hs20_eap_cert_unsupported(dev, apdev):
  819. """Hotspot 2.0 connection with certificate, but unsupported TTLS"""
  820. bssid = apdev[0]['bssid']
  821. params = hs20_ap_params()
  822. params['nai_realm'] = [ "0,example.com,21[5:6]" ]
  823. hostapd.add_ap(apdev[0], params)
  824. dev[0].hs20_enable()
  825. dev[0].add_cred_values({ 'realm': "example.com",
  826. 'username': "certificate-user",
  827. 'ca_cert': "auth_serv/ca.pem",
  828. 'client_cert': "auth_serv/user.pem",
  829. 'private_key': "auth_serv/user.key"})
  830. interworking_select(dev[0], None, no_match=True, freq="2412")
  831. @remote_compatible
  832. def test_ap_hs20_eap_invalid_cred(dev, apdev):
  833. """Hotspot 2.0 connection with invalid cred configuration"""
  834. bssid = apdev[0]['bssid']
  835. params = hs20_ap_params()
  836. hostapd.add_ap(apdev[0], params)
  837. dev[0].hs20_enable()
  838. dev[0].add_cred_values({ 'realm': "example.com",
  839. 'username': "certificate-user",
  840. 'client_cert': "auth_serv/user.pem" })
  841. interworking_select(dev[0], None, no_match=True, freq="2412")
  842. def test_ap_hs20_nai_realms(dev, apdev):
  843. """Hotspot 2.0 connection and multiple NAI realms and TTLS/PAP"""
  844. bssid = apdev[0]['bssid']
  845. params = hs20_ap_params()
  846. params['hessid'] = bssid
  847. params['nai_realm'] = [ "0,no.match.here;example.com;no.match.here.either,21[2:1][5:7]" ]
  848. hostapd.add_ap(apdev[0], params)
  849. dev[0].hs20_enable()
  850. id = dev[0].add_cred_values({ 'realm': "example.com",
  851. 'ca_cert': "auth_serv/ca.pem",
  852. 'username': "pap user",
  853. 'password': "password",
  854. 'domain': "example.com" })
  855. interworking_select(dev[0], bssid, "home", freq="2412")
  856. interworking_connect(dev[0], bssid, "TTLS")
  857. check_sp_type(dev[0], "home")
  858. def test_ap_hs20_roaming_consortium(dev, apdev):
  859. """Hotspot 2.0 connection based on roaming consortium match"""
  860. bssid = apdev[0]['bssid']
  861. params = hs20_ap_params()
  862. params['hessid'] = bssid
  863. hostapd.add_ap(apdev[0], params)
  864. dev[0].hs20_enable()
  865. for consortium in [ "112233", "1020304050", "010203040506", "fedcba" ]:
  866. id = dev[0].add_cred_values({ 'username': "user",
  867. 'password': "password",
  868. 'domain': "example.com",
  869. 'ca_cert': "auth_serv/ca.pem",
  870. 'roaming_consortium': consortium,
  871. 'eap': "PEAP" })
  872. interworking_select(dev[0], bssid, "home", freq="2412")
  873. interworking_connect(dev[0], bssid, "PEAP")
  874. check_sp_type(dev[0], "home")
  875. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  876. ev = dev[0].wait_event(["INTERWORKING-ALREADY-CONNECTED"], timeout=15)
  877. if ev is None:
  878. raise Exception("Timeout on already-connected event")
  879. dev[0].remove_cred(id)
  880. def test_ap_hs20_roaming_consortium_invalid(dev, apdev):
  881. """Hotspot 2.0 connection and invalid roaming consortium ANQP-element"""
  882. bssid = apdev[0]['bssid']
  883. params = hs20_ap_params()
  884. params['hessid'] = bssid
  885. # Override Roaming Consortium ANQP-element with an incorrectly encoded
  886. # value.
  887. params['anqp_elem'] = "261:04fedcba"
  888. hostapd.add_ap(apdev[0], params)
  889. dev[0].hs20_enable()
  890. id = dev[0].add_cred_values({ 'username': "user",
  891. 'password': "password",
  892. 'domain': "example.com",
  893. 'ca_cert': "auth_serv/ca.pem",
  894. 'roaming_consortium': "fedcba",
  895. 'eap': "PEAP" })
  896. interworking_select(dev[0], bssid, "home", freq="2412", no_match=True)
  897. def test_ap_hs20_roaming_consortium_element(dev, apdev):
  898. """Hotspot 2.0 connection and invalid roaming consortium element"""
  899. bssid = apdev[0]['bssid']
  900. params = hs20_ap_params()
  901. params['hessid'] = bssid
  902. del params['roaming_consortium']
  903. params['vendor_elements'] = '6f00'
  904. hapd = hostapd.add_ap(apdev[0], params)
  905. dev[0].hs20_enable()
  906. dev[0].scan_for_bss(bssid, freq="2412")
  907. id = dev[0].add_cred_values({ 'username': "user",
  908. 'password': "password",
  909. 'domain': "example.com",
  910. 'ca_cert': "auth_serv/ca.pem",
  911. 'roaming_consortium': "112233",
  912. 'eap': "PEAP" })
  913. interworking_select(dev[0], bssid, freq="2412", no_match=True)
  914. hapd.set('vendor_elements', '6f020001')
  915. if "OK" not in hapd.request("UPDATE_BEACON"):
  916. raise Exception("UPDATE_BEACON failed")
  917. dev[0].request("BSS_FLUSH 0")
  918. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  919. interworking_select(dev[0], bssid, freq="2412", no_match=True)
  920. def test_ap_hs20_roaming_consortium_constraints(dev, apdev):
  921. """Hotspot 2.0 connection and roaming consortium constraints"""
  922. bssid = apdev[0]['bssid']
  923. params = hs20_ap_params()
  924. params['hessid'] = bssid
  925. params['bss_load_test'] = "12:200:20000"
  926. hostapd.add_ap(apdev[0], params)
  927. dev[0].hs20_enable()
  928. vals = { 'username': "user",
  929. 'password': "password",
  930. 'domain': "example.com",
  931. 'ca_cert': "auth_serv/ca.pem",
  932. 'roaming_consortium': "fedcba",
  933. 'eap': "TTLS" }
  934. vals2 = vals.copy()
  935. vals2['required_roaming_consortium'] = "223344"
  936. id = dev[0].add_cred_values(vals2)
  937. interworking_select(dev[0], bssid, "home", freq="2412", no_match=True)
  938. dev[0].remove_cred(id)
  939. vals2 = vals.copy()
  940. vals2['min_dl_bandwidth_home'] = "65500"
  941. id = dev[0].add_cred_values(vals2)
  942. dev[0].request("INTERWORKING_SELECT freq=2412")
  943. ev = dev[0].wait_event(["INTERWORKING-AP"], timeout=15)
  944. if ev is None:
  945. raise Exception("No AP found")
  946. if "below_min_backhaul=1" not in ev:
  947. raise Exception("below_min_backhaul not reported")
  948. dev[0].remove_cred(id)
  949. vals2 = vals.copy()
  950. vals2['max_bss_load'] = "100"
  951. id = dev[0].add_cred_values(vals2)
  952. dev[0].request("INTERWORKING_SELECT freq=2412")
  953. ev = dev[0].wait_event(["INTERWORKING-AP"], timeout=15)
  954. if ev is None:
  955. raise Exception("No AP found")
  956. if "over_max_bss_load=1" not in ev:
  957. raise Exception("over_max_bss_load not reported")
  958. dev[0].remove_cred(id)
  959. vals2 = vals.copy()
  960. vals2['req_conn_capab'] = "6:1234"
  961. vals2['domain'] = 'example.org'
  962. id = dev[0].add_cred_values(vals2)
  963. dev[0].request("INTERWORKING_SELECT freq=2412")
  964. ev = dev[0].wait_event(["INTERWORKING-AP"], timeout=15)
  965. if ev is None:
  966. raise Exception("No AP found")
  967. if "conn_capab_missing=1" not in ev:
  968. raise Exception("conn_capab_missing not reported")
  969. dev[0].remove_cred(id)
  970. values = default_cred()
  971. values['roaming_consortium'] = "fedcba"
  972. id3 = dev[0].add_cred_values(values)
  973. vals2 = vals.copy()
  974. vals2['roaming_consortium'] = "fedcba"
  975. vals2['priority'] = "2"
  976. id = dev[0].add_cred_values(vals2)
  977. values = default_cred()
  978. values['roaming_consortium'] = "fedcba"
  979. id2 = dev[0].add_cred_values(values)
  980. dev[0].request("INTERWORKING_SELECT freq=2412")
  981. ev = dev[0].wait_event(["INTERWORKING-AP"], timeout=15)
  982. if ev is None:
  983. raise Exception("No AP found")
  984. dev[0].remove_cred(id)
  985. dev[0].remove_cred(id2)
  986. dev[0].remove_cred(id3)
  987. def test_ap_hs20_3gpp_constraints(dev, apdev):
  988. """Hotspot 2.0 connection and 3GPP credential constraints"""
  989. bssid = apdev[0]['bssid']
  990. params = hs20_ap_params()
  991. params['hessid'] = bssid
  992. params['anqp_3gpp_cell_net'] = "555,444"
  993. params['domain_name'] = "wlan.mnc444.mcc555.3gppnetwork.org"
  994. params['bss_load_test'] = "12:200:20000"
  995. hapd = hostapd.add_ap(apdev[0], params)
  996. dev[0].hs20_enable()
  997. vals = { 'imsi': "555444-333222111",
  998. 'eap': "SIM",
  999. 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123" }
  1000. vals2 = vals.copy()
  1001. vals2['required_roaming_consortium'] = "223344"
  1002. id = dev[0].add_cred_values(vals2)
  1003. interworking_select(dev[0], bssid, "home", freq="2412", no_match=True)
  1004. dev[0].remove_cred(id)
  1005. vals2 = vals.copy()
  1006. vals2['min_dl_bandwidth_home'] = "65500"
  1007. id = dev[0].add_cred_values(vals2)
  1008. dev[0].request("INTERWORKING_SELECT freq=2412")
  1009. ev = dev[0].wait_event(["INTERWORKING-AP"], timeout=15)
  1010. if ev is None:
  1011. raise Exception("No AP found")
  1012. if "below_min_backhaul=1" not in ev:
  1013. raise Exception("below_min_backhaul not reported")
  1014. dev[0].remove_cred(id)
  1015. vals2 = vals.copy()
  1016. vals2['max_bss_load'] = "100"
  1017. id = dev[0].add_cred_values(vals2)
  1018. dev[0].request("INTERWORKING_SELECT freq=2412")
  1019. ev = dev[0].wait_event(["INTERWORKING-AP"], timeout=15)
  1020. if ev is None:
  1021. raise Exception("No AP found")
  1022. if "over_max_bss_load=1" not in ev:
  1023. raise Exception("over_max_bss_load not reported")
  1024. dev[0].remove_cred(id)
  1025. values = default_cred()
  1026. values['roaming_consortium'] = "fedcba"
  1027. id3 = dev[0].add_cred_values(values)
  1028. vals2 = vals.copy()
  1029. vals2['roaming_consortium'] = "fedcba"
  1030. vals2['priority'] = "2"
  1031. id = dev[0].add_cred_values(vals2)
  1032. values = default_cred()
  1033. values['roaming_consortium'] = "fedcba"
  1034. id2 = dev[0].add_cred_values(values)
  1035. dev[0].request("INTERWORKING_SELECT freq=2412")
  1036. ev = dev[0].wait_event(["INTERWORKING-AP"], timeout=15)
  1037. if ev is None:
  1038. raise Exception("No AP found")
  1039. dev[0].remove_cred(id)
  1040. dev[0].remove_cred(id2)
  1041. dev[0].remove_cred(id3)
  1042. hapd.disable()
  1043. params = hs20_ap_params()
  1044. params['hessid'] = bssid
  1045. params['anqp_3gpp_cell_net'] = "555,444"
  1046. params['bss_load_test'] = "12:200:20000"
  1047. hapd = hostapd.add_ap(apdev[0], params)
  1048. vals2 = vals.copy()
  1049. vals2['req_conn_capab'] = "6:1234"
  1050. id = dev[0].add_cred_values(vals2)
  1051. dev[0].request("INTERWORKING_SELECT freq=2412")
  1052. ev = dev[0].wait_event(["INTERWORKING-AP"], timeout=15)
  1053. if ev is None:
  1054. raise Exception("No AP found")
  1055. if "conn_capab_missing=1" not in ev:
  1056. raise Exception("conn_capab_missing not reported")
  1057. dev[0].remove_cred(id)
  1058. def test_ap_hs20_connect_no_full_match(dev, apdev):
  1059. """Hotspot 2.0 connection and no full match"""
  1060. bssid = apdev[0]['bssid']
  1061. params = hs20_ap_params()
  1062. params['hessid'] = bssid
  1063. params['anqp_3gpp_cell_net'] = "555,444"
  1064. hostapd.add_ap(apdev[0], params)
  1065. dev[0].hs20_enable()
  1066. vals = { 'username': "user",
  1067. 'password': "password",
  1068. 'domain': "example.com",
  1069. 'ca_cert': "auth_serv/ca.pem",
  1070. 'roaming_consortium': "fedcba",
  1071. 'eap': "TTLS",
  1072. 'min_dl_bandwidth_home': "65500" }
  1073. id = dev[0].add_cred_values(vals)
  1074. dev[0].request("INTERWORKING_SELECT freq=2412")
  1075. ev = dev[0].wait_event(["INTERWORKING-AP"], timeout=15)
  1076. if ev is None:
  1077. raise Exception("No AP found")
  1078. if "below_min_backhaul=1" not in ev:
  1079. raise Exception("below_min_backhaul not reported")
  1080. interworking_connect(dev[0], bssid, "TTLS")
  1081. dev[0].remove_cred(id)
  1082. dev[0].wait_disconnected()
  1083. vals = { 'imsi': "555444-333222111", 'eap': "SIM",
  1084. 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  1085. 'min_dl_bandwidth_roaming': "65500" }
  1086. id = dev[0].add_cred_values(vals)
  1087. dev[0].request("INTERWORKING_SELECT freq=2412")
  1088. ev = dev[0].wait_event(["INTERWORKING-AP"], timeout=15)
  1089. if ev is None:
  1090. raise Exception("No AP found")
  1091. if "below_min_backhaul=1" not in ev:
  1092. raise Exception("below_min_backhaul not reported")
  1093. interworking_connect(dev[0], bssid, "SIM")
  1094. dev[0].remove_cred(id)
  1095. dev[0].wait_disconnected()
  1096. def test_ap_hs20_username_roaming(dev, apdev):
  1097. """Hotspot 2.0 connection in username/password credential (roaming)"""
  1098. check_eap_capa(dev[0], "MSCHAPV2")
  1099. bssid = apdev[0]['bssid']
  1100. params = hs20_ap_params()
  1101. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]",
  1102. "0,roaming.example.com,21[2:4][5:7]",
  1103. "0,another.example.com" ]
  1104. params['domain_name'] = "another.example.com"
  1105. params['hessid'] = bssid
  1106. hostapd.add_ap(apdev[0], params)
  1107. dev[0].hs20_enable()
  1108. id = dev[0].add_cred_values({ 'realm': "roaming.example.com",
  1109. 'username': "hs20-test",
  1110. 'password': "password",
  1111. 'ca_cert': "auth_serv/ca.pem",
  1112. 'domain': "example.com" })
  1113. interworking_select(dev[0], bssid, "roaming", freq="2412")
  1114. interworking_connect(dev[0], bssid, "TTLS")
  1115. check_sp_type(dev[0], "roaming")
  1116. def test_ap_hs20_username_unknown(dev, apdev):
  1117. """Hotspot 2.0 connection in username/password credential (no domain in cred)"""
  1118. check_eap_capa(dev[0], "MSCHAPV2")
  1119. bssid = apdev[0]['bssid']
  1120. params = hs20_ap_params()
  1121. params['hessid'] = bssid
  1122. hostapd.add_ap(apdev[0], params)
  1123. dev[0].hs20_enable()
  1124. id = dev[0].add_cred_values({ 'realm': "example.com",
  1125. 'ca_cert': "auth_serv/ca.pem",
  1126. 'username': "hs20-test",
  1127. 'password': "password" })
  1128. interworking_select(dev[0], bssid, "unknown", freq="2412")
  1129. interworking_connect(dev[0], bssid, "TTLS")
  1130. check_sp_type(dev[0], "unknown")
  1131. def test_ap_hs20_username_unknown2(dev, apdev):
  1132. """Hotspot 2.0 connection in username/password credential (no domain advertized)"""
  1133. check_eap_capa(dev[0], "MSCHAPV2")
  1134. bssid = apdev[0]['bssid']
  1135. params = hs20_ap_params()
  1136. params['hessid'] = bssid
  1137. del params['domain_name']
  1138. hostapd.add_ap(apdev[0], params)
  1139. dev[0].hs20_enable()
  1140. id = dev[0].add_cred_values({ 'realm': "example.com",
  1141. 'ca_cert': "auth_serv/ca.pem",
  1142. 'username': "hs20-test",
  1143. 'password': "password",
  1144. 'domain': "example.com" })
  1145. interworking_select(dev[0], bssid, "unknown", freq="2412")
  1146. interworking_connect(dev[0], bssid, "TTLS")
  1147. check_sp_type(dev[0], "unknown")
  1148. def test_ap_hs20_gas_while_associated(dev, apdev):
  1149. """Hotspot 2.0 connection with GAS query while associated"""
  1150. check_eap_capa(dev[0], "MSCHAPV2")
  1151. bssid = apdev[0]['bssid']
  1152. params = hs20_ap_params()
  1153. params['hessid'] = bssid
  1154. hostapd.add_ap(apdev[0], params)
  1155. dev[0].hs20_enable()
  1156. id = dev[0].add_cred_values({ 'realm': "example.com",
  1157. 'ca_cert': "auth_serv/ca.pem",
  1158. 'username': "hs20-test",
  1159. 'password': "password",
  1160. 'domain': "example.com" })
  1161. interworking_select(dev[0], bssid, "home", freq="2412")
  1162. interworking_connect(dev[0], bssid, "TTLS")
  1163. logger.info("Verifying GAS query while associated")
  1164. dev[0].request("FETCH_ANQP")
  1165. for i in range(0, 6):
  1166. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  1167. if ev is None:
  1168. raise Exception("Operation timed out")
  1169. def test_ap_hs20_gas_with_another_ap_while_associated(dev, apdev):
  1170. """GAS query with another AP while associated"""
  1171. check_eap_capa(dev[0], "MSCHAPV2")
  1172. bssid = apdev[0]['bssid']
  1173. params = hs20_ap_params()
  1174. params['hessid'] = bssid
  1175. hostapd.add_ap(apdev[0], params)
  1176. bssid2 = apdev[1]['bssid']
  1177. params = hs20_ap_params()
  1178. params['hessid'] = bssid2
  1179. params['nai_realm'] = [ "0,no-match.example.org,13[5:6],21[2:4][5:7]" ]
  1180. hostapd.add_ap(apdev[1], params)
  1181. dev[0].hs20_enable()
  1182. id = dev[0].add_cred_values({ 'realm': "example.com",
  1183. 'ca_cert': "auth_serv/ca.pem",
  1184. 'username': "hs20-test",
  1185. 'password': "password",
  1186. 'domain': "example.com" })
  1187. interworking_select(dev[0], bssid, "home", freq="2412")
  1188. interworking_connect(dev[0], bssid, "TTLS")
  1189. dev[0].dump_monitor()
  1190. logger.info("Verifying GAS query with same AP while associated")
  1191. dev[0].request("ANQP_GET " + bssid + " 263")
  1192. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  1193. if ev is None:
  1194. raise Exception("ANQP operation timed out")
  1195. dev[0].dump_monitor()
  1196. logger.info("Verifying GAS query with another AP while associated")
  1197. dev[0].scan_for_bss(bssid2, 2412)
  1198. dev[0].request("ANQP_GET " + bssid2 + " 263")
  1199. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  1200. if ev is None:
  1201. raise Exception("ANQP operation timed out")
  1202. def test_ap_hs20_gas_while_associated_with_pmf(dev, apdev):
  1203. """Hotspot 2.0 connection with GAS query while associated and using PMF"""
  1204. check_eap_capa(dev[0], "MSCHAPV2")
  1205. try:
  1206. _test_ap_hs20_gas_while_associated_with_pmf(dev, apdev)
  1207. finally:
  1208. dev[0].request("SET pmf 0")
  1209. def _test_ap_hs20_gas_while_associated_with_pmf(dev, apdev):
  1210. bssid = apdev[0]['bssid']
  1211. params = hs20_ap_params()
  1212. params['hessid'] = bssid
  1213. hostapd.add_ap(apdev[0], params)
  1214. bssid2 = apdev[1]['bssid']
  1215. params = hs20_ap_params()
  1216. params['hessid'] = bssid2
  1217. params['nai_realm'] = [ "0,no-match.example.org,13[5:6],21[2:4][5:7]" ]
  1218. hostapd.add_ap(apdev[1], params)
  1219. dev[0].hs20_enable()
  1220. dev[0].request("SET pmf 2")
  1221. id = dev[0].add_cred_values({ 'realm': "example.com",
  1222. 'ca_cert': "auth_serv/ca.pem",
  1223. 'username': "hs20-test",
  1224. 'password': "password",
  1225. 'domain': "example.com" })
  1226. interworking_select(dev[0], bssid, "home", freq="2412")
  1227. interworking_connect(dev[0], bssid, "TTLS")
  1228. logger.info("Verifying GAS query while associated")
  1229. dev[0].request("FETCH_ANQP")
  1230. for i in range(0, 2 * 6):
  1231. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  1232. if ev is None:
  1233. raise Exception("Operation timed out")
  1234. def test_ap_hs20_gas_with_another_ap_while_using_pmf(dev, apdev):
  1235. """GAS query with another AP while associated and using PMF"""
  1236. check_eap_capa(dev[0], "MSCHAPV2")
  1237. try:
  1238. _test_ap_hs20_gas_with_another_ap_while_using_pmf(dev, apdev)
  1239. finally:
  1240. dev[0].request("SET pmf 0")
  1241. def _test_ap_hs20_gas_with_another_ap_while_using_pmf(dev, apdev):
  1242. bssid = apdev[0]['bssid']
  1243. params = hs20_ap_params()
  1244. params['hessid'] = bssid
  1245. hostapd.add_ap(apdev[0], params)
  1246. bssid2 = apdev[1]['bssid']
  1247. params = hs20_ap_params()
  1248. params['hessid'] = bssid2
  1249. params['nai_realm'] = [ "0,no-match.example.org,13[5:6],21[2:4][5:7]" ]
  1250. hostapd.add_ap(apdev[1], params)
  1251. dev[0].hs20_enable()
  1252. dev[0].request("SET pmf 2")
  1253. id = dev[0].add_cred_values({ 'realm': "example.com",
  1254. 'ca_cert': "auth_serv/ca.pem",
  1255. 'username': "hs20-test",
  1256. 'password': "password",
  1257. 'domain': "example.com" })
  1258. interworking_select(dev[0], bssid, "home", freq="2412")
  1259. interworking_connect(dev[0], bssid, "TTLS")
  1260. dev[0].dump_monitor()
  1261. logger.info("Verifying GAS query with same AP while associated")
  1262. dev[0].request("ANQP_GET " + bssid + " 263")
  1263. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  1264. if ev is None:
  1265. raise Exception("ANQP operation timed out")
  1266. dev[0].dump_monitor()
  1267. logger.info("Verifying GAS query with another AP while associated")
  1268. dev[0].scan_for_bss(bssid2, 2412)
  1269. dev[0].request("ANQP_GET " + bssid2 + " 263")
  1270. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  1271. if ev is None:
  1272. raise Exception("ANQP operation timed out")
  1273. def test_ap_hs20_gas_frag_while_associated(dev, apdev):
  1274. """Hotspot 2.0 connection with fragmented GAS query while associated"""
  1275. check_eap_capa(dev[0], "MSCHAPV2")
  1276. bssid = apdev[0]['bssid']
  1277. params = hs20_ap_params()
  1278. params['hessid'] = bssid
  1279. hapd = hostapd.add_ap(apdev[0], params)
  1280. hapd.set("gas_frag_limit", "50")
  1281. dev[0].hs20_enable()
  1282. id = dev[0].add_cred_values({ 'realm': "example.com",
  1283. 'ca_cert': "auth_serv/ca.pem",
  1284. 'username': "hs20-test",
  1285. 'password': "password",
  1286. 'domain': "example.com" })
  1287. interworking_select(dev[0], bssid, "home", freq="2412")
  1288. interworking_connect(dev[0], bssid, "TTLS")
  1289. logger.info("Verifying GAS query while associated")
  1290. dev[0].request("FETCH_ANQP")
  1291. for i in range(0, 6):
  1292. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  1293. if ev is None:
  1294. raise Exception("Operation timed out")
  1295. def test_ap_hs20_multiple_connects(dev, apdev):
  1296. """Hotspot 2.0 connection through multiple network selections"""
  1297. check_eap_capa(dev[0], "MSCHAPV2")
  1298. bssid = apdev[0]['bssid']
  1299. params = hs20_ap_params()
  1300. params['hessid'] = bssid
  1301. hostapd.add_ap(apdev[0], params)
  1302. dev[0].hs20_enable()
  1303. values = { 'realm': "example.com",
  1304. 'ca_cert': "auth_serv/ca.pem",
  1305. 'username': "hs20-test",
  1306. 'password': "password",
  1307. 'domain': "example.com" }
  1308. id = dev[0].add_cred_values(values)
  1309. dev[0].scan_for_bss(bssid, freq="2412")
  1310. for i in range(0, 3):
  1311. logger.info("Starting Interworking network selection")
  1312. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1313. while True:
  1314. ev = dev[0].wait_event(["INTERWORKING-NO-MATCH",
  1315. "INTERWORKING-ALREADY-CONNECTED",
  1316. "CTRL-EVENT-CONNECTED"], timeout=15)
  1317. if ev is None:
  1318. raise Exception("Connection timed out")
  1319. if "INTERWORKING-NO-MATCH" in ev:
  1320. raise Exception("Matching AP not found")
  1321. if "CTRL-EVENT-CONNECTED" in ev:
  1322. break
  1323. if i == 2 and "INTERWORKING-ALREADY-CONNECTED" in ev:
  1324. break
  1325. if i == 0:
  1326. dev[0].request("DISCONNECT")
  1327. dev[0].dump_monitor()
  1328. networks = dev[0].list_networks()
  1329. if len(networks) > 1:
  1330. raise Exception("Duplicated network block detected")
  1331. def test_ap_hs20_disallow_aps(dev, apdev):
  1332. """Hotspot 2.0 connection and disallow_aps"""
  1333. bssid = apdev[0]['bssid']
  1334. params = hs20_ap_params()
  1335. params['hessid'] = bssid
  1336. hostapd.add_ap(apdev[0], params)
  1337. dev[0].hs20_enable()
  1338. values = { 'realm': "example.com",
  1339. 'ca_cert': "auth_serv/ca.pem",
  1340. 'username': "hs20-test",
  1341. 'password': "password",
  1342. 'domain': "example.com" }
  1343. id = dev[0].add_cred_values(values)
  1344. dev[0].scan_for_bss(bssid, freq="2412")
  1345. logger.info("Verify disallow_aps bssid")
  1346. dev[0].request("SET disallow_aps bssid " + bssid.translate(None, ':'))
  1347. dev[0].request("INTERWORKING_SELECT auto")
  1348. ev = dev[0].wait_event(["INTERWORKING-NO-MATCH"], timeout=15)
  1349. if ev is None:
  1350. raise Exception("Network selection timed out")
  1351. dev[0].dump_monitor()
  1352. logger.info("Verify disallow_aps ssid")
  1353. dev[0].request("SET disallow_aps ssid 746573742d68733230")
  1354. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1355. ev = dev[0].wait_event(["INTERWORKING-NO-MATCH"], timeout=15)
  1356. if ev is None:
  1357. raise Exception("Network selection timed out")
  1358. dev[0].dump_monitor()
  1359. logger.info("Verify disallow_aps clear")
  1360. dev[0].request("SET disallow_aps ")
  1361. interworking_select(dev[0], bssid, "home", freq="2412")
  1362. dev[0].request("SET disallow_aps bssid " + bssid.translate(None, ':'))
  1363. ret = dev[0].request("INTERWORKING_CONNECT " + bssid)
  1364. if "FAIL" not in ret:
  1365. raise Exception("INTERWORKING_CONNECT to disallowed BSS not rejected")
  1366. if "FAIL" not in dev[0].request("INTERWORKING_CONNECT foo"):
  1367. raise Exception("Invalid INTERWORKING_CONNECT not rejected")
  1368. if "FAIL" not in dev[0].request("INTERWORKING_CONNECT 00:11:22:33:44:55"):
  1369. raise Exception("Invalid INTERWORKING_CONNECT not rejected")
  1370. def policy_test(dev, ap, values, only_one=True):
  1371. dev.dump_monitor()
  1372. if ap:
  1373. logger.info("Verify network selection to AP " + ap['ifname'])
  1374. bssid = ap['bssid']
  1375. dev.scan_for_bss(bssid, freq="2412")
  1376. else:
  1377. logger.info("Verify network selection")
  1378. bssid = None
  1379. dev.hs20_enable()
  1380. id = dev.add_cred_values(values)
  1381. dev.request("INTERWORKING_SELECT auto freq=2412")
  1382. events = []
  1383. while True:
  1384. ev = dev.wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH",
  1385. "INTERWORKING-BLACKLISTED",
  1386. "INTERWORKING-SELECTED"], timeout=15)
  1387. if ev is None:
  1388. raise Exception("Network selection timed out")
  1389. events.append(ev)
  1390. if "INTERWORKING-NO-MATCH" in ev:
  1391. raise Exception("Matching AP not found")
  1392. if bssid and only_one and "INTERWORKING-AP" in ev and bssid not in ev:
  1393. raise Exception("Unexpected AP claimed acceptable")
  1394. if "INTERWORKING-SELECTED" in ev:
  1395. if bssid and bssid not in ev:
  1396. raise Exception("Selected incorrect BSS")
  1397. break
  1398. ev = dev.wait_connected(timeout=15)
  1399. if bssid and bssid not in ev:
  1400. raise Exception("Connected to incorrect BSS")
  1401. conn_bssid = dev.get_status_field("bssid")
  1402. if bssid and conn_bssid != bssid:
  1403. raise Exception("bssid information points to incorrect BSS")
  1404. dev.remove_cred(id)
  1405. dev.dump_monitor()
  1406. return events
  1407. def default_cred(domain=None, user="hs20-test"):
  1408. cred = { 'realm': "example.com",
  1409. 'ca_cert': "auth_serv/ca.pem",
  1410. 'username': user,
  1411. 'password': "password" }
  1412. if domain:
  1413. cred['domain'] = domain
  1414. return cred
  1415. def test_ap_hs20_prefer_home(dev, apdev):
  1416. """Hotspot 2.0 required roaming consortium"""
  1417. check_eap_capa(dev[0], "MSCHAPV2")
  1418. params = hs20_ap_params()
  1419. params['domain_name'] = "example.org"
  1420. hostapd.add_ap(apdev[0], params)
  1421. params = hs20_ap_params()
  1422. params['ssid'] = "test-hs20-other"
  1423. params['domain_name'] = "example.com"
  1424. hostapd.add_ap(apdev[1], params)
  1425. values = default_cred()
  1426. values['domain'] = "example.com"
  1427. policy_test(dev[0], apdev[1], values, only_one=False)
  1428. values['domain'] = "example.org"
  1429. policy_test(dev[0], apdev[0], values, only_one=False)
  1430. def test_ap_hs20_req_roaming_consortium(dev, apdev):
  1431. """Hotspot 2.0 required roaming consortium"""
  1432. check_eap_capa(dev[0], "MSCHAPV2")
  1433. params = hs20_ap_params()
  1434. hostapd.add_ap(apdev[0], params)
  1435. params = hs20_ap_params()
  1436. params['ssid'] = "test-hs20-other"
  1437. params['roaming_consortium'] = [ "223344" ]
  1438. hostapd.add_ap(apdev[1], params)
  1439. values = default_cred()
  1440. values['required_roaming_consortium'] = "223344"
  1441. policy_test(dev[0], apdev[1], values)
  1442. values['required_roaming_consortium'] = "112233"
  1443. policy_test(dev[0], apdev[0], values)
  1444. id = dev[0].add_cred()
  1445. dev[0].set_cred(id, "required_roaming_consortium", "112233")
  1446. dev[0].set_cred(id, "required_roaming_consortium", "112233445566778899aabbccddeeff")
  1447. for val in [ "", "1", "11", "1122", "1122334", "112233445566778899aabbccddeeff00" ]:
  1448. if "FAIL" not in dev[0].request('SET_CRED {} required_roaming_consortium {}'.format(id, val)):
  1449. raise Exception("Invalid roaming consortium value accepted: " + val)
  1450. def test_ap_hs20_req_roaming_consortium_no_match(dev, apdev):
  1451. """Hotspot 2.0 required roaming consortium and no match"""
  1452. check_eap_capa(dev[0], "MSCHAPV2")
  1453. params = hs20_ap_params()
  1454. del params['roaming_consortium']
  1455. hostapd.add_ap(apdev[0], params)
  1456. params = hs20_ap_params()
  1457. params['ssid'] = "test-hs20-other"
  1458. params['roaming_consortium'] = [ "223345" ]
  1459. hostapd.add_ap(apdev[1], params)
  1460. values = default_cred()
  1461. values['required_roaming_consortium'] = "223344"
  1462. dev[0].hs20_enable()
  1463. id = dev[0].add_cred_values(values)
  1464. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1465. ev = dev[0].wait_event(["INTERWORKING-NO-MATCH"], timeout=10)
  1466. if ev is None:
  1467. raise Exception("INTERWORKING-NO-MATCH not reported")
  1468. def test_ap_hs20_excluded_ssid(dev, apdev):
  1469. """Hotspot 2.0 exclusion based on SSID"""
  1470. check_eap_capa(dev[0], "MSCHAPV2")
  1471. params = hs20_ap_params()
  1472. params['roaming_consortium'] = [ "223344" ]
  1473. params['anqp_3gpp_cell_net'] = "555,444"
  1474. hostapd.add_ap(apdev[0], params)
  1475. params = hs20_ap_params()
  1476. params['ssid'] = "test-hs20-other"
  1477. params['roaming_consortium'] = [ "223344" ]
  1478. params['anqp_3gpp_cell_net'] = "555,444"
  1479. hostapd.add_ap(apdev[1], params)
  1480. values = default_cred()
  1481. values['excluded_ssid'] = "test-hs20"
  1482. events = policy_test(dev[0], apdev[1], values)
  1483. ev = [e for e in events if "INTERWORKING-BLACKLISTED " + apdev[0]['bssid'] in e]
  1484. if len(ev) != 1:
  1485. raise Exception("Excluded network not reported")
  1486. values['excluded_ssid'] = "test-hs20-other"
  1487. events = policy_test(dev[0], apdev[0], values)
  1488. ev = [e for e in events if "INTERWORKING-BLACKLISTED " + apdev[1]['bssid'] in e]
  1489. if len(ev) != 1:
  1490. raise Exception("Excluded network not reported")
  1491. values = default_cred()
  1492. values['roaming_consortium'] = "223344"
  1493. values['eap'] = "TTLS"
  1494. values['phase2'] = "auth=MSCHAPV2"
  1495. values['excluded_ssid'] = "test-hs20"
  1496. events = policy_test(dev[0], apdev[1], values)
  1497. ev = [e for e in events if "INTERWORKING-BLACKLISTED " + apdev[0]['bssid'] in e]
  1498. if len(ev) != 1:
  1499. raise Exception("Excluded network not reported")
  1500. values = { 'imsi': "555444-333222111", 'eap': "SIM",
  1501. 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  1502. 'excluded_ssid': "test-hs20" }
  1503. events = policy_test(dev[0], apdev[1], values)
  1504. ev = [e for e in events if "INTERWORKING-BLACKLISTED " + apdev[0]['bssid'] in e]
  1505. if len(ev) != 1:
  1506. raise Exception("Excluded network not reported")
  1507. def test_ap_hs20_roam_to_higher_prio(dev, apdev):
  1508. """Hotspot 2.0 and roaming from current to higher priority network"""
  1509. check_eap_capa(dev[0], "MSCHAPV2")
  1510. bssid = apdev[0]['bssid']
  1511. params = hs20_ap_params(ssid="test-hs20-visited")
  1512. params['domain_name'] = "visited.example.org"
  1513. hostapd.add_ap(apdev[0], params)
  1514. dev[0].hs20_enable()
  1515. id = dev[0].add_cred_values({ 'realm': "example.com",
  1516. 'ca_cert': "auth_serv/ca.pem",
  1517. 'username': "hs20-test",
  1518. 'password': "password",
  1519. 'domain': "example.com" })
  1520. logger.info("Connect to the only network option")
  1521. interworking_select(dev[0], bssid, "roaming", freq="2412")
  1522. dev[0].dump_monitor()
  1523. interworking_connect(dev[0], bssid, "TTLS")
  1524. logger.info("Start another AP (home operator) and reconnect")
  1525. bssid2 = apdev[1]['bssid']
  1526. params = hs20_ap_params(ssid="test-hs20-home")
  1527. params['domain_name'] = "example.com"
  1528. hostapd.add_ap(apdev[1], params)
  1529. dev[0].scan_for_bss(bssid2, freq="2412", force_scan=True)
  1530. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1531. ev = dev[0].wait_event(["INTERWORKING-NO-MATCH",
  1532. "INTERWORKING-ALREADY-CONNECTED",
  1533. "CTRL-EVENT-CONNECTED"], timeout=15)
  1534. if ev is None:
  1535. raise Exception("Connection timed out")
  1536. if "INTERWORKING-NO-MATCH" in ev:
  1537. raise Exception("Matching AP not found")
  1538. if "INTERWORKING-ALREADY-CONNECTED" in ev:
  1539. raise Exception("Unexpected AP selected")
  1540. if bssid2 not in ev:
  1541. raise Exception("Unexpected BSSID after reconnection")
  1542. def test_ap_hs20_domain_suffix_match_full(dev, apdev):
  1543. """Hotspot 2.0 and domain_suffix_match"""
  1544. check_domain_match_full(dev[0])
  1545. check_eap_capa(dev[0], "MSCHAPV2")
  1546. bssid = apdev[0]['bssid']
  1547. params = hs20_ap_params()
  1548. hostapd.add_ap(apdev[0], params)
  1549. dev[0].hs20_enable()
  1550. id = dev[0].add_cred_values({ 'realm': "example.com",
  1551. 'username': "hs20-test",
  1552. 'password': "password",
  1553. 'ca_cert': "auth_serv/ca.pem",
  1554. 'domain': "example.com",
  1555. 'domain_suffix_match': "server.w1.fi" })
  1556. interworking_select(dev[0], bssid, "home", freq="2412")
  1557. dev[0].dump_monitor()
  1558. interworking_connect(dev[0], bssid, "TTLS")
  1559. dev[0].request("REMOVE_NETWORK all")
  1560. dev[0].dump_monitor()
  1561. dev[0].set_cred_quoted(id, "domain_suffix_match", "no-match.example.com")
  1562. interworking_select(dev[0], bssid, "home", freq="2412")
  1563. dev[0].dump_monitor()
  1564. dev[0].request("INTERWORKING_CONNECT " + bssid)
  1565. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"])
  1566. if ev is None:
  1567. raise Exception("TLS certificate error not reported")
  1568. if "Domain suffix mismatch" not in ev:
  1569. raise Exception("Domain suffix mismatch not reported")
  1570. def test_ap_hs20_domain_suffix_match(dev, apdev):
  1571. """Hotspot 2.0 and domain_suffix_match"""
  1572. check_eap_capa(dev[0], "MSCHAPV2")
  1573. check_domain_match_full(dev[0])
  1574. bssid = apdev[0]['bssid']
  1575. params = hs20_ap_params()
  1576. hostapd.add_ap(apdev[0], params)
  1577. dev[0].hs20_enable()
  1578. id = dev[0].add_cred_values({ 'realm': "example.com",
  1579. 'username': "hs20-test",
  1580. 'password': "password",
  1581. 'ca_cert': "auth_serv/ca.pem",
  1582. 'domain': "example.com",
  1583. 'domain_suffix_match': "w1.fi" })
  1584. interworking_select(dev[0], bssid, "home", freq="2412")
  1585. dev[0].dump_monitor()
  1586. interworking_connect(dev[0], bssid, "TTLS")
  1587. def test_ap_hs20_roaming_partner_preference(dev, apdev):
  1588. """Hotspot 2.0 and roaming partner preference"""
  1589. check_eap_capa(dev[0], "MSCHAPV2")
  1590. params = hs20_ap_params()
  1591. params['domain_name'] = "roaming.example.org"
  1592. hostapd.add_ap(apdev[0], params)
  1593. params = hs20_ap_params()
  1594. params['ssid'] = "test-hs20-other"
  1595. params['domain_name'] = "roaming.example.net"
  1596. hostapd.add_ap(apdev[1], params)
  1597. logger.info("Verify default vs. specified preference")
  1598. values = default_cred()
  1599. values['roaming_partner'] = "roaming.example.net,1,127,*"
  1600. policy_test(dev[0], apdev[1], values, only_one=False)
  1601. values['roaming_partner'] = "roaming.example.net,1,129,*"
  1602. policy_test(dev[0], apdev[0], values, only_one=False)
  1603. logger.info("Verify partial FQDN match")
  1604. values['roaming_partner'] = "example.net,0,0,*"
  1605. policy_test(dev[0], apdev[1], values, only_one=False)
  1606. values['roaming_partner'] = "example.net,0,255,*"
  1607. policy_test(dev[0], apdev[0], values, only_one=False)
  1608. def test_ap_hs20_max_bss_load(dev, apdev):
  1609. """Hotspot 2.0 and maximum BSS load"""
  1610. check_eap_capa(dev[0], "MSCHAPV2")
  1611. params = hs20_ap_params()
  1612. params['bss_load_test'] = "12:200:20000"
  1613. hostapd.add_ap(apdev[0], params)
  1614. params = hs20_ap_params()
  1615. params['ssid'] = "test-hs20-other"
  1616. params['bss_load_test'] = "5:20:10000"
  1617. hostapd.add_ap(apdev[1], params)
  1618. logger.info("Verify maximum BSS load constraint")
  1619. values = default_cred()
  1620. values['domain'] = "example.com"
  1621. values['max_bss_load'] = "100"
  1622. events = policy_test(dev[0], apdev[1], values, only_one=False)
  1623. ev = [e for e in events if "INTERWORKING-AP " + apdev[0]['bssid'] in e]
  1624. if len(ev) != 1 or "over_max_bss_load=1" not in ev[0]:
  1625. raise Exception("Maximum BSS Load case not noticed")
  1626. ev = [e for e in events if "INTERWORKING-AP " + apdev[1]['bssid'] in e]
  1627. if len(ev) != 1 or "over_max_bss_load=1" in ev[0]:
  1628. raise Exception("Maximum BSS Load case reported incorrectly")
  1629. logger.info("Verify maximum BSS load does not prevent connection")
  1630. values['max_bss_load'] = "1"
  1631. events = policy_test(dev[0], None, values)
  1632. ev = [e for e in events if "INTERWORKING-AP " + apdev[0]['bssid'] in e]
  1633. if len(ev) != 1 or "over_max_bss_load=1" not in ev[0]:
  1634. raise Exception("Maximum BSS Load case not noticed")
  1635. ev = [e for e in events if "INTERWORKING-AP " + apdev[1]['bssid'] in e]
  1636. if len(ev) != 1 or "over_max_bss_load=1" not in ev[0]:
  1637. raise Exception("Maximum BSS Load case not noticed")
  1638. def test_ap_hs20_max_bss_load2(dev, apdev):
  1639. """Hotspot 2.0 and maximum BSS load with one AP not advertising"""
  1640. check_eap_capa(dev[0], "MSCHAPV2")
  1641. params = hs20_ap_params()
  1642. params['bss_load_test'] = "12:200:20000"
  1643. hostapd.add_ap(apdev[0], params)
  1644. params = hs20_ap_params()
  1645. params['ssid'] = "test-hs20-other"
  1646. hostapd.add_ap(apdev[1], params)
  1647. logger.info("Verify maximum BSS load constraint with AP advertisement")
  1648. values = default_cred()
  1649. values['domain'] = "example.com"
  1650. values['max_bss_load'] = "100"
  1651. events = policy_test(dev[0], apdev[1], values, only_one=False)
  1652. ev = [e for e in events if "INTERWORKING-AP " + apdev[0]['bssid'] in e]
  1653. if len(ev) != 1 or "over_max_bss_load=1" not in ev[0]:
  1654. raise Exception("Maximum BSS Load case not noticed")
  1655. ev = [e for e in events if "INTERWORKING-AP " + apdev[1]['bssid'] in e]
  1656. if len(ev) != 1 or "over_max_bss_load=1" in ev[0]:
  1657. raise Exception("Maximum BSS Load case reported incorrectly")
  1658. def test_ap_hs20_max_bss_load_roaming(dev, apdev):
  1659. """Hotspot 2.0 and maximum BSS load (roaming)"""
  1660. check_eap_capa(dev[0], "MSCHAPV2")
  1661. params = hs20_ap_params()
  1662. params['bss_load_test'] = "12:200:20000"
  1663. hostapd.add_ap(apdev[0], params)
  1664. values = default_cred()
  1665. values['domain'] = "roaming.example.com"
  1666. values['max_bss_load'] = "100"
  1667. events = policy_test(dev[0], apdev[0], values, only_one=True)
  1668. ev = [e for e in events if "INTERWORKING-AP " + apdev[0]['bssid'] in e]
  1669. if len(ev) != 1:
  1670. raise Exception("No INTERWORKING-AP event")
  1671. if "over_max_bss_load=1" in ev[0]:
  1672. raise Exception("Maximum BSS Load reported for roaming")
  1673. def test_ap_hs20_multi_cred_sp_prio(dev, apdev):
  1674. """Hotspot 2.0 multi-cred sp_priority"""
  1675. check_eap_capa(dev[0], "MSCHAPV2")
  1676. try:
  1677. _test_ap_hs20_multi_cred_sp_prio(dev, apdev)
  1678. finally:
  1679. dev[0].request("SET external_sim 0")
  1680. def _test_ap_hs20_multi_cred_sp_prio(dev, apdev):
  1681. hlr_auc_gw_available()
  1682. bssid = apdev[0]['bssid']
  1683. params = hs20_ap_params()
  1684. params['hessid'] = bssid
  1685. del params['domain_name']
  1686. params['anqp_3gpp_cell_net'] = "232,01"
  1687. hostapd.add_ap(apdev[0], params)
  1688. dev[0].hs20_enable()
  1689. dev[0].scan_for_bss(bssid, freq="2412")
  1690. dev[0].request("SET external_sim 1")
  1691. id1 = dev[0].add_cred_values({ 'imsi': "23201-0000000000", 'eap': "SIM",
  1692. 'provisioning_sp': "example.com",
  1693. 'sp_priority' :"1" })
  1694. id2 = dev[0].add_cred_values({ 'realm': "example.com",
  1695. 'ca_cert': "auth_serv/ca.pem",
  1696. 'username': "hs20-test",
  1697. 'password': "password",
  1698. 'domain': "example.com",
  1699. 'provisioning_sp': "example.com",
  1700. 'sp_priority': "2" })
  1701. dev[0].dump_monitor()
  1702. dev[0].scan_for_bss(bssid, freq="2412")
  1703. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1704. interworking_ext_sim_auth(dev[0], "SIM")
  1705. check_sp_type(dev[0], "unknown")
  1706. dev[0].request("REMOVE_NETWORK all")
  1707. dev[0].set_cred(id1, "sp_priority", "2")
  1708. dev[0].set_cred(id2, "sp_priority", "1")
  1709. dev[0].dump_monitor()
  1710. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1711. interworking_auth(dev[0], "TTLS")
  1712. check_sp_type(dev[0], "unknown")
  1713. def test_ap_hs20_multi_cred_sp_prio2(dev, apdev):
  1714. """Hotspot 2.0 multi-cred sp_priority with two BSSes"""
  1715. check_eap_capa(dev[0], "MSCHAPV2")
  1716. try:
  1717. _test_ap_hs20_multi_cred_sp_prio2(dev, apdev)
  1718. finally:
  1719. dev[0].request("SET external_sim 0")
  1720. def _test_ap_hs20_multi_cred_sp_prio2(dev, apdev):
  1721. hlr_auc_gw_available()
  1722. bssid = apdev[0]['bssid']
  1723. params = hs20_ap_params()
  1724. params['hessid'] = bssid
  1725. del params['nai_realm']
  1726. del params['domain_name']
  1727. params['anqp_3gpp_cell_net'] = "232,01"
  1728. hostapd.add_ap(apdev[0], params)
  1729. bssid2 = apdev[1]['bssid']
  1730. params = hs20_ap_params()
  1731. params['ssid'] = "test-hs20-other"
  1732. params['hessid'] = bssid2
  1733. del params['domain_name']
  1734. del params['anqp_3gpp_cell_net']
  1735. hostapd.add_ap(apdev[1], params)
  1736. dev[0].hs20_enable()
  1737. dev[0].request("SET external_sim 1")
  1738. id1 = dev[0].add_cred_values({ 'imsi': "23201-0000000000", 'eap': "SIM",
  1739. 'provisioning_sp': "example.com",
  1740. 'sp_priority': "1" })
  1741. id2 = dev[0].add_cred_values({ 'realm': "example.com",
  1742. 'ca_cert': "auth_serv/ca.pem",
  1743. 'username': "hs20-test",
  1744. 'password': "password",
  1745. 'domain': "example.com",
  1746. 'provisioning_sp': "example.com",
  1747. 'sp_priority': "2" })
  1748. dev[0].dump_monitor()
  1749. dev[0].scan_for_bss(bssid, freq="2412")
  1750. dev[0].scan_for_bss(bssid2, freq="2412")
  1751. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1752. interworking_ext_sim_auth(dev[0], "SIM")
  1753. check_sp_type(dev[0], "unknown")
  1754. conn_bssid = dev[0].get_status_field("bssid")
  1755. if conn_bssid != bssid:
  1756. raise Exception("Connected to incorrect BSS")
  1757. dev[0].request("REMOVE_NETWORK all")
  1758. dev[0].set_cred(id1, "sp_priority", "2")
  1759. dev[0].set_cred(id2, "sp_priority", "1")
  1760. dev[0].dump_monitor()
  1761. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1762. interworking_auth(dev[0], "TTLS")
  1763. check_sp_type(dev[0], "unknown")
  1764. conn_bssid = dev[0].get_status_field("bssid")
  1765. if conn_bssid != bssid2:
  1766. raise Exception("Connected to incorrect BSS")
  1767. def test_ap_hs20_multi_cred_sp_prio_same(dev, apdev):
  1768. """Hotspot 2.0 multi-cred and same sp_priority"""
  1769. check_eap_capa(dev[0], "MSCHAPV2")
  1770. hlr_auc_gw_available()
  1771. bssid = apdev[0]['bssid']
  1772. params = hs20_ap_params()
  1773. params['hessid'] = bssid
  1774. del params['domain_name']
  1775. params['anqp_3gpp_cell_net'] = "232,01"
  1776. hostapd.add_ap(apdev[0], params)
  1777. dev[0].hs20_enable()
  1778. dev[0].scan_for_bss(bssid, freq="2412")
  1779. id1 = dev[0].add_cred_values({ 'realm': "example.com",
  1780. 'ca_cert': "auth_serv/ca.pem",
  1781. 'username': "hs20-test",
  1782. 'password': "password",
  1783. 'domain': "domain1.example.com",
  1784. 'provisioning_sp': "example.com",
  1785. 'sp_priority': "1" })
  1786. id2 = dev[0].add_cred_values({ 'realm': "example.com",
  1787. 'ca_cert': "auth_serv/ca.pem",
  1788. 'username': "hs20-test",
  1789. 'password': "password",
  1790. 'domain': "domain2.example.com",
  1791. 'provisioning_sp': "example.com",
  1792. 'sp_priority': "1" })
  1793. dev[0].dump_monitor()
  1794. dev[0].scan_for_bss(bssid, freq="2412")
  1795. check_auto_select(dev[0], bssid)
  1796. def check_conn_capab_selection(dev, type, missing):
  1797. dev.request("INTERWORKING_SELECT freq=2412")
  1798. ev = dev.wait_event(["INTERWORKING-AP"])
  1799. if ev is None:
  1800. raise Exception("Network selection timed out")
  1801. if "type=" + type not in ev:
  1802. raise Exception("Unexpected network type")
  1803. if missing and "conn_capab_missing=1" not in ev:
  1804. raise Exception("conn_capab_missing not reported")
  1805. if not missing and "conn_capab_missing=1" in ev:
  1806. raise Exception("conn_capab_missing reported unexpectedly")
  1807. def conn_capab_cred(domain=None, req_conn_capab=None):
  1808. cred = default_cred(domain=domain)
  1809. if req_conn_capab:
  1810. cred['req_conn_capab'] = req_conn_capab
  1811. return cred
  1812. def test_ap_hs20_req_conn_capab(dev, apdev):
  1813. """Hotspot 2.0 network selection with req_conn_capab"""
  1814. check_eap_capa(dev[0], "MSCHAPV2")
  1815. bssid = apdev[0]['bssid']
  1816. params = hs20_ap_params()
  1817. hostapd.add_ap(apdev[0], params)
  1818. dev[0].hs20_enable()
  1819. dev[0].scan_for_bss(bssid, freq="2412")
  1820. logger.info("Not used in home network")
  1821. values = conn_capab_cred(domain="example.com", req_conn_capab="6:1234")
  1822. id = dev[0].add_cred_values(values)
  1823. check_conn_capab_selection(dev[0], "home", False)
  1824. logger.info("Used in roaming network")
  1825. dev[0].remove_cred(id)
  1826. values = conn_capab_cred(domain="example.org", req_conn_capab="6:1234")
  1827. id = dev[0].add_cred_values(values)
  1828. check_conn_capab_selection(dev[0], "roaming", True)
  1829. logger.info("Verify that req_conn_capab does not prevent connection if no other network is available")
  1830. check_auto_select(dev[0], bssid)
  1831. logger.info("Additional req_conn_capab checks")
  1832. dev[0].remove_cred(id)
  1833. values = conn_capab_cred(domain="example.org", req_conn_capab="1:0")
  1834. id = dev[0].add_cred_values(values)
  1835. check_conn_capab_selection(dev[0], "roaming", True)
  1836. dev[0].remove_cred(id)
  1837. values = conn_capab_cred(domain="example.org", req_conn_capab="17:5060")
  1838. id = dev[0].add_cred_values(values)
  1839. check_conn_capab_selection(dev[0], "roaming", True)
  1840. bssid2 = apdev[1]['bssid']
  1841. params = hs20_ap_params(ssid="test-hs20b")
  1842. params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0", "50:0:1" ]
  1843. hostapd.add_ap(apdev[1], params)
  1844. dev[0].remove_cred(id)
  1845. values = conn_capab_cred(domain="example.org", req_conn_capab="50")
  1846. id = dev[0].add_cred_values(values)
  1847. dev[0].set_cred(id, "req_conn_capab", "6:22")
  1848. dev[0].scan_for_bss(bssid2, freq="2412")
  1849. dev[0].request("INTERWORKING_SELECT freq=2412")
  1850. for i in range(0, 2):
  1851. ev = dev[0].wait_event(["INTERWORKING-AP"])
  1852. if ev is None:
  1853. raise Exception("Network selection timed out")
  1854. if bssid in ev and "conn_capab_missing=1" not in ev:
  1855. raise Exception("Missing protocol connection capability not reported")
  1856. if bssid2 in ev and "conn_capab_missing=1" in ev:
  1857. raise Exception("Protocol connection capability not reported correctly")
  1858. def test_ap_hs20_req_conn_capab2(dev, apdev):
  1859. """Hotspot 2.0 network selection with req_conn_capab (not present)"""
  1860. check_eap_capa(dev[0], "MSCHAPV2")
  1861. bssid = apdev[0]['bssid']
  1862. params = hs20_ap_params()
  1863. del params['hs20_conn_capab']
  1864. hostapd.add_ap(apdev[0], params)
  1865. dev[0].hs20_enable()
  1866. dev[0].scan_for_bss(bssid, freq="2412")
  1867. values = conn_capab_cred(domain="example.org", req_conn_capab="6:1234")
  1868. id = dev[0].add_cred_values(values)
  1869. check_conn_capab_selection(dev[0], "roaming", False)
  1870. def test_ap_hs20_req_conn_capab_and_roaming_partner_preference(dev, apdev):
  1871. """Hotspot 2.0 and req_conn_capab with roaming partner preference"""
  1872. check_eap_capa(dev[0], "MSCHAPV2")
  1873. bssid = apdev[0]['bssid']
  1874. params = hs20_ap_params()
  1875. params['domain_name'] = "roaming.example.org"
  1876. params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0", "50:0:1" ]
  1877. hostapd.add_ap(apdev[0], params)
  1878. bssid2 = apdev[1]['bssid']
  1879. params = hs20_ap_params(ssid="test-hs20-b")
  1880. params['domain_name'] = "roaming.example.net"
  1881. hostapd.add_ap(apdev[1], params)
  1882. values = default_cred()
  1883. values['roaming_partner'] = "roaming.example.net,1,127,*"
  1884. id = dev[0].add_cred_values(values)
  1885. check_auto_select(dev[0], bssid2)
  1886. dev[0].set_cred(id, "req_conn_capab", "50")
  1887. check_auto_select(dev[0], bssid)
  1888. dev[0].remove_cred(id)
  1889. id = dev[0].add_cred_values(values)
  1890. dev[0].set_cred(id, "req_conn_capab", "51")
  1891. check_auto_select(dev[0], bssid2)
  1892. def check_bandwidth_selection(dev, type, below):
  1893. dev.request("INTERWORKING_SELECT freq=2412")
  1894. ev = dev.wait_event(["INTERWORKING-AP"])
  1895. if ev is None:
  1896. raise Exception("Network selection timed out")
  1897. logger.debug("BSS entries:\n" + dev.request("BSS RANGE=ALL"))
  1898. if "type=" + type not in ev:
  1899. raise Exception("Unexpected network type")
  1900. if below and "below_min_backhaul=1" not in ev:
  1901. raise Exception("below_min_backhaul not reported")
  1902. if not below and "below_min_backhaul=1" in ev:
  1903. raise Exception("below_min_backhaul reported unexpectedly")
  1904. def bw_cred(domain=None, dl_home=None, ul_home=None, dl_roaming=None, ul_roaming=None):
  1905. cred = default_cred(domain=domain)
  1906. if dl_home:
  1907. cred['min_dl_bandwidth_home'] = str(dl_home)
  1908. if ul_home:
  1909. cred['min_ul_bandwidth_home'] = str(ul_home)
  1910. if dl_roaming:
  1911. cred['min_dl_bandwidth_roaming'] = str(dl_roaming)
  1912. if ul_roaming:
  1913. cred['min_ul_bandwidth_roaming'] = str(ul_roaming)
  1914. return cred
  1915. def test_ap_hs20_min_bandwidth_home(dev, apdev):
  1916. """Hotspot 2.0 network selection with min bandwidth (home)"""
  1917. check_eap_capa(dev[0], "MSCHAPV2")
  1918. bssid = apdev[0]['bssid']
  1919. params = hs20_ap_params()
  1920. hostapd.add_ap(apdev[0], params)
  1921. dev[0].hs20_enable()
  1922. dev[0].scan_for_bss(bssid, freq="2412")
  1923. values = bw_cred(domain="example.com", dl_home=5490, ul_home=58)
  1924. id = dev[0].add_cred_values(values)
  1925. check_bandwidth_selection(dev[0], "home", False)
  1926. dev[0].remove_cred(id)
  1927. values = bw_cred(domain="example.com", dl_home=5491, ul_home=58)
  1928. id = dev[0].add_cred_values(values)
  1929. check_bandwidth_selection(dev[0], "home", True)
  1930. dev[0].remove_cred(id)
  1931. values = bw_cred(domain="example.com", dl_home=5490, ul_home=59)
  1932. id = dev[0].add_cred_values(values)
  1933. check_bandwidth_selection(dev[0], "home", True)
  1934. dev[0].remove_cred(id)
  1935. values = bw_cred(domain="example.com", dl_home=5491, ul_home=59)
  1936. id = dev[0].add_cred_values(values)
  1937. check_bandwidth_selection(dev[0], "home", True)
  1938. check_auto_select(dev[0], bssid)
  1939. bssid2 = apdev[1]['bssid']
  1940. params = hs20_ap_params(ssid="test-hs20-b")
  1941. params['hs20_wan_metrics'] = "01:8000:1000:1:1:3000"
  1942. hostapd.add_ap(apdev[1], params)
  1943. check_auto_select(dev[0], bssid2)
  1944. def test_ap_hs20_min_bandwidth_home2(dev, apdev):
  1945. """Hotspot 2.0 network selection with min bandwidth - special cases"""
  1946. check_eap_capa(dev[0], "MSCHAPV2")
  1947. bssid = apdev[0]['bssid']
  1948. params = hs20_ap_params()
  1949. hapd = hostapd.add_ap(apdev[0], params)
  1950. dev[0].hs20_enable()
  1951. dev[0].scan_for_bss(bssid, freq="2412")
  1952. values = bw_cred(domain="example.com", dl_home=5490, ul_home=58)
  1953. id = dev[0].add_cred_values(values)
  1954. check_bandwidth_selection(dev[0], "home", False)
  1955. logger.info("WAN link at capacity")
  1956. hapd.set('hs20_wan_metrics', "09:8000:1000:80:240:3000")
  1957. check_bandwidth_selection(dev[0], "home", True)
  1958. logger.info("Downlink/Uplink Load was not measured")
  1959. hapd.set('hs20_wan_metrics', "01:8000:1000:80:240:0")
  1960. check_bandwidth_selection(dev[0], "home", False)
  1961. logger.info("Uplink and Downlink max values")
  1962. hapd.set('hs20_wan_metrics', "01:4294967295:4294967295:80:240:3000")
  1963. check_bandwidth_selection(dev[0], "home", False)
  1964. dev[0].remove_cred(id)
  1965. def test_ap_hs20_min_bandwidth_home_hidden_ssid_in_scan_res(dev, apdev):
  1966. """Hotspot 2.0 network selection with min bandwidth (home) while hidden SSID is included in scan results"""
  1967. check_eap_capa(dev[0], "MSCHAPV2")
  1968. bssid = apdev[0]['bssid']
  1969. hapd = hostapd.add_ap(apdev[0], { "ssid": 'secret',
  1970. "ignore_broadcast_ssid": "1" })
  1971. dev[0].scan_for_bss(bssid, freq=2412)
  1972. hapd.disable()
  1973. hapd_global = hostapd.HostapdGlobal(apdev[0])
  1974. hapd_global.flush()
  1975. hapd_global.remove(apdev[0]['ifname'])
  1976. params = hs20_ap_params()
  1977. hostapd.add_ap(apdev[0], params)
  1978. dev[0].hs20_enable()
  1979. dev[0].scan_for_bss(bssid, freq="2412")
  1980. values = bw_cred(domain="example.com", dl_home=5490, ul_home=58)
  1981. id = dev[0].add_cred_values(values)
  1982. check_bandwidth_selection(dev[0], "home", False)
  1983. dev[0].remove_cred(id)
  1984. values = bw_cred(domain="example.com", dl_home=5491, ul_home=58)
  1985. id = dev[0].add_cred_values(values)
  1986. check_bandwidth_selection(dev[0], "home", True)
  1987. dev[0].remove_cred(id)
  1988. values = bw_cred(domain="example.com", dl_home=5490, ul_home=59)
  1989. id = dev[0].add_cred_values(values)
  1990. check_bandwidth_selection(dev[0], "home", True)
  1991. dev[0].remove_cred(id)
  1992. values = bw_cred(domain="example.com", dl_home=5491, ul_home=59)
  1993. id = dev[0].add_cred_values(values)
  1994. check_bandwidth_selection(dev[0], "home", True)
  1995. check_auto_select(dev[0], bssid)
  1996. bssid2 = apdev[1]['bssid']
  1997. params = hs20_ap_params(ssid="test-hs20-b")
  1998. params['hs20_wan_metrics'] = "01:8000:1000:1:1:3000"
  1999. hostapd.add_ap(apdev[1], params)
  2000. check_auto_select(dev[0], bssid2)
  2001. dev[0].flush_scan_cache()
  2002. def test_ap_hs20_min_bandwidth_roaming(dev, apdev):
  2003. """Hotspot 2.0 network selection with min bandwidth (roaming)"""
  2004. check_eap_capa(dev[0], "MSCHAPV2")
  2005. bssid = apdev[0]['bssid']
  2006. params = hs20_ap_params()
  2007. hostapd.add_ap(apdev[0], params)
  2008. dev[0].hs20_enable()
  2009. dev[0].scan_for_bss(bssid, freq="2412")
  2010. values = bw_cred(domain="example.org", dl_roaming=5490, ul_roaming=58)
  2011. id = dev[0].add_cred_values(values)
  2012. check_bandwidth_selection(dev[0], "roaming", False)
  2013. dev[0].remove_cred(id)
  2014. values = bw_cred(domain="example.org", dl_roaming=5491, ul_roaming=58)
  2015. id = dev[0].add_cred_values(values)
  2016. check_bandwidth_selection(dev[0], "roaming", True)
  2017. dev[0].remove_cred(id)
  2018. values = bw_cred(domain="example.org", dl_roaming=5490, ul_roaming=59)
  2019. id = dev[0].add_cred_values(values)
  2020. check_bandwidth_selection(dev[0], "roaming", True)
  2021. dev[0].remove_cred(id)
  2022. values = bw_cred(domain="example.org", dl_roaming=5491, ul_roaming=59)
  2023. id = dev[0].add_cred_values(values)
  2024. check_bandwidth_selection(dev[0], "roaming", True)
  2025. check_auto_select(dev[0], bssid)
  2026. bssid2 = apdev[1]['bssid']
  2027. params = hs20_ap_params(ssid="test-hs20-b")
  2028. params['hs20_wan_metrics'] = "01:8000:1000:1:1:3000"
  2029. hostapd.add_ap(apdev[1], params)
  2030. check_auto_select(dev[0], bssid2)
  2031. def test_ap_hs20_min_bandwidth_and_roaming_partner_preference(dev, apdev):
  2032. """Hotspot 2.0 and minimum bandwidth with roaming partner preference"""
  2033. check_eap_capa(dev[0], "MSCHAPV2")
  2034. bssid = apdev[0]['bssid']
  2035. params = hs20_ap_params()
  2036. params['domain_name'] = "roaming.example.org"
  2037. params['hs20_wan_metrics'] = "01:8000:1000:1:1:3000"
  2038. hostapd.add_ap(apdev[0], params)
  2039. bssid2 = apdev[1]['bssid']
  2040. params = hs20_ap_params(ssid="test-hs20-b")
  2041. params['domain_name'] = "roaming.example.net"
  2042. hostapd.add_ap(apdev[1], params)
  2043. values = default_cred()
  2044. values['roaming_partner'] = "roaming.example.net,1,127,*"
  2045. id = dev[0].add_cred_values(values)
  2046. check_auto_select(dev[0], bssid2)
  2047. dev[0].set_cred(id, "min_dl_bandwidth_roaming", "6000")
  2048. check_auto_select(dev[0], bssid)
  2049. dev[0].set_cred(id, "min_dl_bandwidth_roaming", "10000")
  2050. check_auto_select(dev[0], bssid2)
  2051. def test_ap_hs20_min_bandwidth_no_wan_metrics(dev, apdev):
  2052. """Hotspot 2.0 network selection with min bandwidth but no WAN Metrics"""
  2053. bssid = apdev[0]['bssid']
  2054. params = hs20_ap_params()
  2055. del params['hs20_wan_metrics']
  2056. hostapd.add_ap(apdev[0], params)
  2057. dev[0].hs20_enable()
  2058. dev[0].scan_for_bss(bssid, freq="2412")
  2059. values = bw_cred(domain="example.com", dl_home=10000, ul_home=10000,
  2060. dl_roaming=10000, ul_roaming=10000)
  2061. dev[0].add_cred_values(values)
  2062. check_bandwidth_selection(dev[0], "home", False)
  2063. def test_ap_hs20_deauth_req_ess(dev, apdev):
  2064. """Hotspot 2.0 connection and deauthentication request for ESS"""
  2065. check_eap_capa(dev[0], "MSCHAPV2")
  2066. try:
  2067. _test_ap_hs20_deauth_req_ess(dev, apdev)
  2068. finally:
  2069. dev[0].request("SET pmf 0")
  2070. def _test_ap_hs20_deauth_req_ess(dev, apdev):
  2071. dev[0].request("SET pmf 2")
  2072. eap_test(dev[0], apdev[0], "21[3:26]", "TTLS", "user")
  2073. dev[0].dump_monitor()
  2074. addr = dev[0].p2p_interface_addr()
  2075. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  2076. hapd.request("HS20_DEAUTH_REQ " + addr + " 1 120 http://example.com/")
  2077. ev = dev[0].wait_event(["HS20-DEAUTH-IMMINENT-NOTICE"])
  2078. if ev is None:
  2079. raise Exception("Timeout on deauth imminent notice")
  2080. if "1 120 http://example.com/" not in ev:
  2081. raise Exception("Unexpected deauth imminent notice: " + ev)
  2082. hapd.request("DEAUTHENTICATE " + addr)
  2083. dev[0].wait_disconnected(timeout=10)
  2084. if "[TEMP-DISABLED]" not in dev[0].list_networks()[0]['flags']:
  2085. raise Exception("Network not marked temporarily disabled")
  2086. ev = dev[0].wait_event(["SME: Trying to authenticate",
  2087. "Trying to associate",
  2088. "CTRL-EVENT-CONNECTED"], timeout=5)
  2089. if ev is not None:
  2090. raise Exception("Unexpected connection attempt")
  2091. def test_ap_hs20_deauth_req_bss(dev, apdev):
  2092. """Hotspot 2.0 connection and deauthentication request for BSS"""
  2093. check_eap_capa(dev[0], "MSCHAPV2")
  2094. try:
  2095. _test_ap_hs20_deauth_req_bss(dev, apdev)
  2096. finally:
  2097. dev[0].request("SET pmf 0")
  2098. def _test_ap_hs20_deauth_req_bss(dev, apdev):
  2099. dev[0].request("SET pmf 2")
  2100. eap_test(dev[0], apdev[0], "21[3:26]", "TTLS", "user")
  2101. dev[0].dump_monitor()
  2102. addr = dev[0].p2p_interface_addr()
  2103. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  2104. hapd.request("HS20_DEAUTH_REQ " + addr + " 0 120 http://example.com/")
  2105. ev = dev[0].wait_event(["HS20-DEAUTH-IMMINENT-NOTICE"])
  2106. if ev is None:
  2107. raise Exception("Timeout on deauth imminent notice")
  2108. if "0 120 http://example.com/" not in ev:
  2109. raise Exception("Unexpected deauth imminent notice: " + ev)
  2110. hapd.request("DEAUTHENTICATE " + addr + " reason=4")
  2111. ev = dev[0].wait_disconnected(timeout=10)
  2112. if "reason=4" not in ev:
  2113. raise Exception("Unexpected disconnection reason")
  2114. if "[TEMP-DISABLED]" not in dev[0].list_networks()[0]['flags']:
  2115. raise Exception("Network not marked temporarily disabled")
  2116. ev = dev[0].wait_event(["SME: Trying to authenticate",
  2117. "Trying to associate",
  2118. "CTRL-EVENT-CONNECTED"], timeout=5)
  2119. if ev is not None:
  2120. raise Exception("Unexpected connection attempt")
  2121. def test_ap_hs20_deauth_req_from_radius(dev, apdev):
  2122. """Hotspot 2.0 connection and deauthentication request from RADIUS"""
  2123. check_eap_capa(dev[0], "MSCHAPV2")
  2124. try:
  2125. _test_ap_hs20_deauth_req_from_radius(dev, apdev)
  2126. finally:
  2127. dev[0].request("SET pmf 0")
  2128. def _test_ap_hs20_deauth_req_from_radius(dev, apdev):
  2129. bssid = apdev[0]['bssid']
  2130. params = hs20_ap_params()
  2131. params['nai_realm'] = [ "0,example.com,21[2:4]" ]
  2132. params['hs20_deauth_req_timeout'] = "2"
  2133. hostapd.add_ap(apdev[0], params)
  2134. dev[0].request("SET pmf 2")
  2135. dev[0].hs20_enable()
  2136. dev[0].add_cred_values({ 'realm': "example.com",
  2137. 'username': "hs20-deauth-test",
  2138. 'password': "password" })
  2139. interworking_select(dev[0], bssid, freq="2412")
  2140. interworking_connect(dev[0], bssid, "TTLS")
  2141. ev = dev[0].wait_event(["HS20-DEAUTH-IMMINENT-NOTICE"], timeout=5)
  2142. if ev is None:
  2143. raise Exception("Timeout on deauth imminent notice")
  2144. if " 1 100" not in ev:
  2145. raise Exception("Unexpected deauth imminent contents")
  2146. dev[0].wait_disconnected(timeout=3)
  2147. def test_ap_hs20_deauth_req_without_pmf(dev, apdev):
  2148. """Hotspot 2.0 connection and deauthentication request without PMF"""
  2149. check_eap_capa(dev[0], "MSCHAPV2")
  2150. dev[0].request("SET pmf 0")
  2151. eap_test(dev[0], apdev[0], "21[3:26]", "TTLS", "user")
  2152. dev[0].dump_monitor()
  2153. addr = dev[0].own_addr()
  2154. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  2155. hapd.request("HS20_DEAUTH_REQ " + addr + " 1 120 http://example.com/")
  2156. ev = dev[0].wait_event(["HS20-DEAUTH-IMMINENT-NOTICE"], timeout=0.2)
  2157. if ev is not None:
  2158. raise Exception("Deauth imminent notice without PMF accepted")
  2159. with alloc_fail(hapd, 1, "wpabuf_alloc;hostapd_ctrl_iface_hs20_deauth_req"):
  2160. if "FAIL" not in hapd.request("HS20_DEAUTH_REQ " + addr + " 1 120 http://example.com/"):
  2161. raise Exception("HS20_DEAUTH_REQ accepted during OOM")
  2162. def test_ap_hs20_remediation_required(dev, apdev):
  2163. """Hotspot 2.0 connection and remediation required from RADIUS"""
  2164. check_eap_capa(dev[0], "MSCHAPV2")
  2165. try:
  2166. _test_ap_hs20_remediation_required(dev, apdev)
  2167. finally:
  2168. dev[0].request("SET pmf 0")
  2169. def _test_ap_hs20_remediation_required(dev, apdev):
  2170. bssid = apdev[0]['bssid']
  2171. params = hs20_ap_params()
  2172. params['nai_realm'] = [ "0,example.com,21[2:4]" ]
  2173. hostapd.add_ap(apdev[0], params)
  2174. dev[0].request("SET pmf 1")
  2175. dev[0].hs20_enable()
  2176. dev[0].add_cred_values({ 'realm': "example.com",
  2177. 'username': "hs20-subrem-test",
  2178. 'password': "password" })
  2179. interworking_select(dev[0], bssid, freq="2412")
  2180. interworking_connect(dev[0], bssid, "TTLS")
  2181. ev = dev[0].wait_event(["HS20-SUBSCRIPTION-REMEDIATION"], timeout=5)
  2182. if ev is None:
  2183. raise Exception("Timeout on subscription remediation notice")
  2184. if " 1 https://example.com/" not in ev:
  2185. raise Exception("Unexpected subscription remediation event contents")
  2186. def test_ap_hs20_remediation_required_ctrl(dev, apdev):
  2187. """Hotspot 2.0 connection and subrem from ctrl_iface"""
  2188. check_eap_capa(dev[0], "MSCHAPV2")
  2189. try:
  2190. _test_ap_hs20_remediation_required_ctrl(dev, apdev)
  2191. finally:
  2192. dev[0].request("SET pmf 0")
  2193. def _test_ap_hs20_remediation_required_ctrl(dev, apdev):
  2194. bssid = apdev[0]['bssid']
  2195. addr = dev[0].own_addr()
  2196. params = hs20_ap_params()
  2197. params['nai_realm'] = [ "0,example.com,21[2:4]" ]
  2198. hapd = hostapd.add_ap(apdev[0], params)
  2199. dev[0].request("SET pmf 1")
  2200. dev[0].hs20_enable()
  2201. dev[0].add_cred_values(default_cred())
  2202. interworking_select(dev[0], bssid, freq="2412")
  2203. interworking_connect(dev[0], bssid, "TTLS")
  2204. hapd.request("HS20_WNM_NOTIF " + addr + " https://example.com/")
  2205. ev = dev[0].wait_event(["HS20-SUBSCRIPTION-REMEDIATION"], timeout=5)
  2206. if ev is None:
  2207. raise Exception("Timeout on subscription remediation notice")
  2208. if " 1 https://example.com/" not in ev:
  2209. raise Exception("Unexpected subscription remediation event contents")
  2210. hapd.request("HS20_WNM_NOTIF " + addr)
  2211. ev = dev[0].wait_event(["HS20-SUBSCRIPTION-REMEDIATION"], timeout=5)
  2212. if ev is None:
  2213. raise Exception("Timeout on subscription remediation notice")
  2214. if not ev.endswith("HS20-SUBSCRIPTION-REMEDIATION "):
  2215. raise Exception("Unexpected subscription remediation event contents: " + ev)
  2216. if "FAIL" not in hapd.request("HS20_WNM_NOTIF "):
  2217. raise Exception("Unexpected HS20_WNM_NOTIF success")
  2218. if "FAIL" not in hapd.request("HS20_WNM_NOTIF foo"):
  2219. raise Exception("Unexpected HS20_WNM_NOTIF success")
  2220. if "FAIL" not in hapd.request("HS20_WNM_NOTIF " + addr + " https://12345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678927.very.long.example.com/"):
  2221. raise Exception("Unexpected HS20_WNM_NOTIF success")
  2222. if "OK" not in hapd.request("HS20_WNM_NOTIF " + addr + " "):
  2223. raise Exception("HS20_WNM_NOTIF failed with empty URL")
  2224. def test_ap_hs20_session_info(dev, apdev):
  2225. """Hotspot 2.0 connection and session information from RADIUS"""
  2226. check_eap_capa(dev[0], "MSCHAPV2")
  2227. try:
  2228. _test_ap_hs20_session_info(dev, apdev)
  2229. finally:
  2230. dev[0].request("SET pmf 0")
  2231. def _test_ap_hs20_session_info(dev, apdev):
  2232. bssid = apdev[0]['bssid']
  2233. params = hs20_ap_params()
  2234. params['nai_realm'] = [ "0,example.com,21[2:4]" ]
  2235. hostapd.add_ap(apdev[0], params)
  2236. dev[0].request("SET pmf 1")
  2237. dev[0].hs20_enable()
  2238. dev[0].add_cred_values({ 'realm': "example.com",
  2239. 'username': "hs20-session-info-test",
  2240. 'password': "password" })
  2241. interworking_select(dev[0], bssid, freq="2412")
  2242. interworking_connect(dev[0], bssid, "TTLS")
  2243. ev = dev[0].wait_event(["ESS-DISASSOC-IMMINENT"], timeout=10)
  2244. if ev is None:
  2245. raise Exception("Timeout on ESS disassociation imminent notice")
  2246. if " 1 59904 https://example.com/" not in ev:
  2247. raise Exception("Unexpected ESS disassociation imminent event contents")
  2248. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"])
  2249. if ev is None:
  2250. raise Exception("Scan not started")
  2251. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=30)
  2252. if ev is None:
  2253. raise Exception("Scan not completed")
  2254. def test_ap_hs20_osen(dev, apdev):
  2255. """Hotspot 2.0 OSEN connection"""
  2256. params = { 'ssid': "osen",
  2257. 'osen': "1",
  2258. 'auth_server_addr': "127.0.0.1",
  2259. 'auth_server_port': "1812",
  2260. 'auth_server_shared_secret': "radius" }
  2261. hostapd.add_ap(apdev[0], params)
  2262. dev[1].connect("osen", key_mgmt="NONE", scan_freq="2412",
  2263. wait_connect=False)
  2264. dev[2].connect("osen", key_mgmt="NONE", wep_key0='"hello"',
  2265. scan_freq="2412", wait_connect=False)
  2266. dev[0].flush_scan_cache()
  2267. dev[0].connect("osen", proto="OSEN", key_mgmt="OSEN", pairwise="CCMP",
  2268. group="GTK_NOT_USED",
  2269. eap="WFA-UNAUTH-TLS", identity="osen@example.com",
  2270. ca_cert="auth_serv/ca.pem",
  2271. scan_freq="2412")
  2272. res = dev[0].get_bss(apdev[0]['bssid'])['flags']
  2273. if "[OSEN-OSEN-CCMP]" not in res:
  2274. raise Exception("OSEN not reported in BSS")
  2275. if "[WEP]" in res:
  2276. raise Exception("WEP reported in BSS")
  2277. res = dev[0].request("SCAN_RESULTS")
  2278. if "[OSEN-OSEN-CCMP]" not in res:
  2279. raise Exception("OSEN not reported in SCAN_RESULTS")
  2280. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  2281. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  2282. wpas.connect("osen", proto="OSEN", key_mgmt="OSEN", pairwise="CCMP",
  2283. group="GTK_NOT_USED",
  2284. eap="WFA-UNAUTH-TLS", identity="osen@example.com",
  2285. ca_cert="auth_serv/ca.pem",
  2286. scan_freq="2412")
  2287. wpas.request("DISCONNECT")
  2288. def test_ap_hs20_network_preference(dev, apdev):
  2289. """Hotspot 2.0 network selection with preferred home network"""
  2290. check_eap_capa(dev[0], "MSCHAPV2")
  2291. bssid = apdev[0]['bssid']
  2292. params = hs20_ap_params()
  2293. hostapd.add_ap(apdev[0], params)
  2294. dev[0].hs20_enable()
  2295. values = { 'realm': "example.com",
  2296. 'username': "hs20-test",
  2297. 'password': "password",
  2298. 'domain': "example.com" }
  2299. dev[0].add_cred_values(values)
  2300. id = dev[0].add_network()
  2301. dev[0].set_network_quoted(id, "ssid", "home")
  2302. dev[0].set_network_quoted(id, "psk", "12345678")
  2303. dev[0].set_network(id, "priority", "1")
  2304. dev[0].request("ENABLE_NETWORK %s no-connect" % id)
  2305. dev[0].scan_for_bss(bssid, freq="2412")
  2306. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  2307. ev = dev[0].wait_connected(timeout=15)
  2308. if bssid not in ev:
  2309. raise Exception("Unexpected network selected")
  2310. bssid2 = apdev[1]['bssid']
  2311. params = hostapd.wpa2_params(ssid="home", passphrase="12345678")
  2312. hostapd.add_ap(apdev[1], params)
  2313. dev[0].scan_for_bss(bssid2, freq="2412")
  2314. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  2315. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  2316. "INTERWORKING-ALREADY-CONNECTED" ], timeout=15)
  2317. if ev is None:
  2318. raise Exception("Connection timed out")
  2319. if "INTERWORKING-ALREADY-CONNECTED" in ev:
  2320. raise Exception("No roam to higher priority network")
  2321. if bssid2 not in ev:
  2322. raise Exception("Unexpected network selected")
  2323. def test_ap_hs20_network_preference2(dev, apdev):
  2324. """Hotspot 2.0 network selection with preferred credential"""
  2325. check_eap_capa(dev[0], "MSCHAPV2")
  2326. bssid2 = apdev[1]['bssid']
  2327. params = hostapd.wpa2_params(ssid="home", passphrase="12345678")
  2328. hostapd.add_ap(apdev[1], params)
  2329. dev[0].hs20_enable()
  2330. values = { 'realm': "example.com",
  2331. 'username': "hs20-test",
  2332. 'password': "password",
  2333. 'domain': "example.com",
  2334. 'priority': "1" }
  2335. dev[0].add_cred_values(values)
  2336. id = dev[0].add_network()
  2337. dev[0].set_network_quoted(id, "ssid", "home")
  2338. dev[0].set_network_quoted(id, "psk", "12345678")
  2339. dev[0].request("ENABLE_NETWORK %s no-connect" % id)
  2340. dev[0].scan_for_bss(bssid2, freq="2412")
  2341. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  2342. ev = dev[0].wait_connected(timeout=15)
  2343. if bssid2 not in ev:
  2344. raise Exception("Unexpected network selected")
  2345. bssid = apdev[0]['bssid']
  2346. params = hs20_ap_params()
  2347. hostapd.add_ap(apdev[0], params)
  2348. dev[0].scan_for_bss(bssid, freq="2412")
  2349. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  2350. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  2351. "INTERWORKING-ALREADY-CONNECTED" ], timeout=15)
  2352. if ev is None:
  2353. raise Exception("Connection timed out")
  2354. if "INTERWORKING-ALREADY-CONNECTED" in ev:
  2355. raise Exception("No roam to higher priority network")
  2356. if bssid not in ev:
  2357. raise Exception("Unexpected network selected")
  2358. def test_ap_hs20_network_preference3(dev, apdev):
  2359. """Hotspot 2.0 network selection with two credential (one preferred)"""
  2360. check_eap_capa(dev[0], "MSCHAPV2")
  2361. bssid = apdev[0]['bssid']
  2362. params = hs20_ap_params()
  2363. hostapd.add_ap(apdev[0], params)
  2364. bssid2 = apdev[1]['bssid']
  2365. params = hs20_ap_params(ssid="test-hs20b")
  2366. params['nai_realm'] = "0,example.org,13[5:6],21[2:4][5:7]"
  2367. hostapd.add_ap(apdev[1], params)
  2368. dev[0].hs20_enable()
  2369. values = { 'realm': "example.com",
  2370. 'username': "hs20-test",
  2371. 'password': "password",
  2372. 'priority': "1" }
  2373. dev[0].add_cred_values(values)
  2374. values = { 'realm': "example.org",
  2375. 'username': "hs20-test",
  2376. 'password': "password" }
  2377. id = dev[0].add_cred_values(values)
  2378. dev[0].scan_for_bss(bssid, freq="2412")
  2379. dev[0].scan_for_bss(bssid2, freq="2412")
  2380. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  2381. ev = dev[0].wait_connected(timeout=15)
  2382. if bssid not in ev:
  2383. raise Exception("Unexpected network selected")
  2384. dev[0].set_cred(id, "priority", "2")
  2385. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  2386. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  2387. "INTERWORKING-ALREADY-CONNECTED" ], timeout=15)
  2388. if ev is None:
  2389. raise Exception("Connection timed out")
  2390. if "INTERWORKING-ALREADY-CONNECTED" in ev:
  2391. raise Exception("No roam to higher priority network")
  2392. if bssid2 not in ev:
  2393. raise Exception("Unexpected network selected")
  2394. def test_ap_hs20_network_preference4(dev, apdev):
  2395. """Hotspot 2.0 network selection with username vs. SIM credential"""
  2396. check_eap_capa(dev[0], "MSCHAPV2")
  2397. bssid = apdev[0]['bssid']
  2398. params = hs20_ap_params()
  2399. hostapd.add_ap(apdev[0], params)
  2400. bssid2 = apdev[1]['bssid']
  2401. params = hs20_ap_params(ssid="test-hs20b")
  2402. params['hessid'] = bssid2
  2403. params['anqp_3gpp_cell_net'] = "555,444"
  2404. params['domain_name'] = "wlan.mnc444.mcc555.3gppnetwork.org"
  2405. hostapd.add_ap(apdev[1], params)
  2406. dev[0].hs20_enable()
  2407. values = { 'realm': "example.com",
  2408. 'username': "hs20-test",
  2409. 'password': "password",
  2410. 'priority': "1" }
  2411. dev[0].add_cred_values(values)
  2412. values = { 'imsi': "555444-333222111",
  2413. 'eap': "SIM",
  2414. 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123" }
  2415. id = dev[0].add_cred_values(values)
  2416. dev[0].scan_for_bss(bssid, freq="2412")
  2417. dev[0].scan_for_bss(bssid2, freq="2412")
  2418. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  2419. ev = dev[0].wait_connected(timeout=15)
  2420. if bssid not in ev:
  2421. raise Exception("Unexpected network selected")
  2422. dev[0].set_cred(id, "priority", "2")
  2423. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  2424. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  2425. "INTERWORKING-ALREADY-CONNECTED" ], timeout=15)
  2426. if ev is None:
  2427. raise Exception("Connection timed out")
  2428. if "INTERWORKING-ALREADY-CONNECTED" in ev:
  2429. raise Exception("No roam to higher priority network")
  2430. if bssid2 not in ev:
  2431. raise Exception("Unexpected network selected")
  2432. def test_ap_hs20_interworking_select_blocking_scan(dev, apdev):
  2433. """Ongoing INTERWORKING_SELECT blocking SCAN"""
  2434. check_eap_capa(dev[0], "MSCHAPV2")
  2435. bssid = apdev[0]['bssid']
  2436. params = hs20_ap_params()
  2437. hostapd.add_ap(apdev[0], params)
  2438. dev[0].hs20_enable()
  2439. values = { 'realm': "example.com",
  2440. 'username': "hs20-test",
  2441. 'password': "password",
  2442. 'domain': "example.com" }
  2443. dev[0].add_cred_values(values)
  2444. dev[0].scan_for_bss(bssid, freq="2412")
  2445. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  2446. if "FAIL-BUSY" not in dev[0].request("SCAN"):
  2447. raise Exception("Unexpected SCAN command result")
  2448. dev[0].wait_connected(timeout=15)
  2449. def test_ap_hs20_fetch_osu(dev, apdev):
  2450. """Hotspot 2.0 OSU provider and icon fetch"""
  2451. bssid = apdev[0]['bssid']
  2452. params = hs20_ap_params()
  2453. params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png"
  2454. params['osu_ssid'] = '"HS 2.0 OSU open"'
  2455. params['osu_method_list'] = "1"
  2456. params['osu_friendly_name'] = [ "eng:Test OSU", "fin:Testi-OSU" ]
  2457. params['osu_icon'] = "w1fi_logo"
  2458. params['osu_service_desc'] = [ "eng:Example services", "fin:Esimerkkipalveluja" ]
  2459. params['osu_server_uri'] = "https://example.com/osu/"
  2460. hostapd.add_ap(apdev[0], params)
  2461. bssid2 = apdev[1]['bssid']
  2462. params = hs20_ap_params(ssid="test-hs20b")
  2463. params['hessid'] = bssid2
  2464. params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png"
  2465. params['osu_ssid'] = '"HS 2.0 OSU OSEN"'
  2466. params['osu_method_list'] = "0"
  2467. params['osu_nai'] = "osen@example.com"
  2468. params['osu_friendly_name'] = [ "eng:Test2 OSU", "fin:Testi2-OSU" ]
  2469. params['osu_icon'] = "w1fi_logo"
  2470. params['osu_service_desc'] = [ "eng:Example services2", "fin:Esimerkkipalveluja2" ]
  2471. params['osu_server_uri'] = "https://example.org/osu/"
  2472. hostapd.add_ap(apdev[1], params)
  2473. with open("w1fi_logo.png", "r") as f:
  2474. orig_logo = f.read()
  2475. dev[0].hs20_enable()
  2476. dir = "/tmp/osu-fetch"
  2477. if os.path.isdir(dir):
  2478. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  2479. for f in files:
  2480. os.remove(dir + "/" + f)
  2481. else:
  2482. try:
  2483. os.makedirs(dir)
  2484. except:
  2485. pass
  2486. try:
  2487. dev[1].scan_for_bss(bssid, freq="2412")
  2488. dev[2].scan_for_bss(bssid, freq="2412")
  2489. dev[0].request("SET osu_dir " + dir)
  2490. dev[0].request("FETCH_OSU")
  2491. if "FAIL" not in dev[1].request("HS20_ICON_REQUEST foo w1fi_logo"):
  2492. raise Exception("Invalid HS20_ICON_REQUEST accepted")
  2493. if "OK" not in dev[1].request("HS20_ICON_REQUEST " + bssid + " w1fi_logo"):
  2494. raise Exception("HS20_ICON_REQUEST failed")
  2495. if "OK" not in dev[2].request("REQ_HS20_ICON " + bssid + " w1fi_logo"):
  2496. raise Exception("REQ_HS20_ICON failed")
  2497. icons = 0
  2498. while True:
  2499. ev = dev[0].wait_event(["OSU provider fetch completed",
  2500. "RX-HS20-ANQP-ICON"], timeout=15)
  2501. if ev is None:
  2502. raise Exception("Timeout on OSU fetch")
  2503. if "OSU provider fetch completed" in ev:
  2504. break
  2505. if "RX-HS20-ANQP-ICON" in ev:
  2506. with open(ev.split(' ')[1], "r") as f:
  2507. logo = f.read()
  2508. if logo == orig_logo:
  2509. icons += 1
  2510. with open(dir + "/osu-providers.txt", "r") as f:
  2511. prov = f.read()
  2512. logger.debug("osu-providers.txt: " + prov)
  2513. if "OSU-PROVIDER " + bssid not in prov:
  2514. raise Exception("Missing OSU_PROVIDER(1)")
  2515. if "OSU-PROVIDER " + bssid2 not in prov:
  2516. raise Exception("Missing OSU_PROVIDER(2)")
  2517. finally:
  2518. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  2519. for f in files:
  2520. os.remove(dir + "/" + f)
  2521. os.rmdir(dir)
  2522. if icons != 2:
  2523. raise Exception("Unexpected number of icons fetched")
  2524. ev = dev[1].wait_event(["GAS-QUERY-START"], timeout=5)
  2525. if ev is None:
  2526. raise Exception("Timeout on GAS-QUERY-DONE")
  2527. ev = dev[1].wait_event(["GAS-QUERY-DONE"], timeout=5)
  2528. if ev is None:
  2529. raise Exception("Timeout on GAS-QUERY-DONE")
  2530. if "freq=2412 status_code=0 result=SUCCESS" not in ev:
  2531. raise Exception("Unexpected GAS-QUERY-DONE: " + ev)
  2532. ev = dev[1].wait_event(["RX-HS20-ANQP"], timeout=15)
  2533. if ev is None:
  2534. raise Exception("Timeout on icon fetch")
  2535. if "Icon Binary File" not in ev:
  2536. raise Exception("Unexpected ANQP element")
  2537. ev = dev[2].wait_event(["RX-HS20-ICON"], timeout=5)
  2538. if ev is None:
  2539. raise Exception("Timeout on RX-HS20-ICON")
  2540. event_icon_len = ev.split(' ')[3]
  2541. if " w1fi_logo " not in ev:
  2542. raise Exception("RX-HS20-ICON did not have the expected file name")
  2543. if bssid not in ev:
  2544. raise Exception("RX-HS20-ICON did not have the expected BSSID")
  2545. if "FAIL" in dev[2].request("GET_HS20_ICON " + bssid + " w1fi_logo 0 10"):
  2546. raise Exception("GET_HS20_ICON 0..10 failed")
  2547. if "FAIL" in dev[2].request("GET_HS20_ICON " + bssid + " w1fi_logo 5 10"):
  2548. raise Exception("GET_HS20_ICON 5..15 failed")
  2549. if "FAIL" not in dev[2].request("GET_HS20_ICON " + bssid + " w1fi_logo 100000 10"):
  2550. raise Exception("Unexpected success of GET_HS20_ICON with too large offset")
  2551. if "FAIL" not in dev[2].request("GET_HS20_ICON " + bssid + " no_such_logo 0 10"):
  2552. raise Exception("GET_HS20_ICON for not existing icon succeeded")
  2553. if "FAIL" not in dev[2].request("GET_HS20_ICON " + bssid + " w1fi_logo 0 3070"):
  2554. raise Exception("GET_HS20_ICON with too many output bytes to fit the buffer succeeded")
  2555. if "FAIL" not in dev[2].request("GET_HS20_ICON " + bssid + " w1fi_logo 0 0"):
  2556. raise Exception("GET_HS20_ICON 0..0 succeeded")
  2557. icon = ""
  2558. pos = 0
  2559. while True:
  2560. if pos > 100000:
  2561. raise Exception("Unexpectedly long icon")
  2562. res = dev[2].request("GET_HS20_ICON " + bssid + " w1fi_logo %d 1000" % pos)
  2563. if res.startswith("FAIL"):
  2564. break
  2565. icon += base64.b64decode(res)
  2566. pos += 1000
  2567. hex = binascii.hexlify(icon)
  2568. if not hex.startswith("0009696d6167652f706e677d1d"):
  2569. raise Exception("Unexpected beacon binary header: " + hex)
  2570. with open('w1fi_logo.png', 'r') as f:
  2571. data = f.read()
  2572. if icon[13:] != data:
  2573. raise Exception("Unexpected icon data")
  2574. if len(icon) != int(event_icon_len):
  2575. raise Exception("Unexpected RX-HS20-ICON event length: " + event_icon_len)
  2576. for i in range(3):
  2577. if "OK" not in dev[i].request("REQ_HS20_ICON " + bssid + " w1fi_logo"):
  2578. raise Exception("REQ_HS20_ICON failed [2]")
  2579. for i in range(3):
  2580. ev = dev[i].wait_event(["RX-HS20-ICON"], timeout=5)
  2581. if ev is None:
  2582. raise Exception("Timeout on RX-HS20-ICON [2]")
  2583. if "FAIL" not in dev[2].request("DEL_HS20_ICON foo w1fi_logo"):
  2584. raise Exception("Invalid DEL_HS20_ICON accepted")
  2585. if "OK" not in dev[2].request("DEL_HS20_ICON " + bssid + " w1fi_logo"):
  2586. raise Exception("DEL_HS20_ICON failed")
  2587. if "OK" not in dev[1].request("DEL_HS20_ICON " + bssid):
  2588. raise Exception("DEL_HS20_ICON failed")
  2589. if "OK" not in dev[0].request("DEL_HS20_ICON "):
  2590. raise Exception("DEL_HS20_ICON failed")
  2591. for i in range(3):
  2592. if "FAIL" not in dev[i].request("DEL_HS20_ICON "):
  2593. raise Exception("DEL_HS20_ICON accepted when no icons left")
  2594. def test_ap_hs20_fetch_osu_no_info(dev, apdev):
  2595. """Hotspot 2.0 OSU provider and no AP with info"""
  2596. bssid = apdev[0]['bssid']
  2597. params = hs20_ap_params()
  2598. hostapd.add_ap(apdev[0], params)
  2599. dev[0].hs20_enable()
  2600. dir = "/tmp/osu-fetch"
  2601. if os.path.isdir(dir):
  2602. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  2603. for f in files:
  2604. os.remove(dir + "/" + f)
  2605. else:
  2606. try:
  2607. os.makedirs(dir)
  2608. except:
  2609. pass
  2610. dev[0].scan_for_bss(bssid, freq="2412")
  2611. try:
  2612. dev[0].request("SET osu_dir " + dir)
  2613. dev[0].request("FETCH_OSU")
  2614. ev = dev[0].wait_event(["OSU provider fetch completed"], timeout=30)
  2615. if ev is None:
  2616. raise Exception("Timeout on OSU fetch")
  2617. finally:
  2618. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  2619. for f in files:
  2620. os.remove(dir + "/" + f)
  2621. os.rmdir(dir)
  2622. def test_ap_hs20_fetch_osu_no_icon(dev, apdev):
  2623. """Hotspot 2.0 OSU provider and no icon found"""
  2624. bssid = apdev[0]['bssid']
  2625. params = hs20_ap_params()
  2626. params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo-no-file.png"
  2627. params['osu_ssid'] = '"HS 2.0 OSU open"'
  2628. params['osu_method_list'] = "1"
  2629. params['osu_friendly_name'] = [ "eng:Test OSU", "fin:Testi-OSU" ]
  2630. params['osu_icon'] = "w1fi_logo"
  2631. params['osu_service_desc'] = [ "eng:Example services", "fin:Esimerkkipalveluja" ]
  2632. params['osu_server_uri'] = "https://example.com/osu/"
  2633. hostapd.add_ap(apdev[0], params)
  2634. dev[0].hs20_enable()
  2635. dir = "/tmp/osu-fetch"
  2636. if os.path.isdir(dir):
  2637. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  2638. for f in files:
  2639. os.remove(dir + "/" + f)
  2640. else:
  2641. try:
  2642. os.makedirs(dir)
  2643. except:
  2644. pass
  2645. dev[0].scan_for_bss(bssid, freq="2412")
  2646. try:
  2647. dev[0].request("SET osu_dir " + dir)
  2648. dev[0].request("FETCH_OSU")
  2649. ev = dev[0].wait_event(["OSU provider fetch completed"], timeout=30)
  2650. if ev is None:
  2651. raise Exception("Timeout on OSU fetch")
  2652. finally:
  2653. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  2654. for f in files:
  2655. os.remove(dir + "/" + f)
  2656. os.rmdir(dir)
  2657. def get_icon(dev, bssid, iconname):
  2658. icon = ""
  2659. pos = 0
  2660. while True:
  2661. if pos > 100000:
  2662. raise Exception("Unexpectedly long icon")
  2663. res = dev.request("GET_HS20_ICON " + bssid + " " + iconname + " %d 3000" % pos)
  2664. if res.startswith("FAIL"):
  2665. break
  2666. icon += base64.b64decode(res)
  2667. pos += 3000
  2668. if len(icon) < 13:
  2669. raise Exception("Too short GET_HS20_ICON response")
  2670. return icon[0:13], icon[13:]
  2671. def test_ap_hs20_req_hs20_icon(dev, apdev):
  2672. """Hotspot 2.0 OSU provider and multi-icon fetch with REQ_HS20_ICON"""
  2673. bssid = apdev[0]['bssid']
  2674. params = hs20_ap_params()
  2675. params['hs20_icon'] = [ "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png",
  2676. "128:80:zxx:image/png:test_logo:auth_serv/sha512-server.pem" ]
  2677. params['osu_ssid'] = '"HS 2.0 OSU open"'
  2678. params['osu_method_list'] = "1"
  2679. params['osu_friendly_name'] = [ "eng:Test OSU", "fin:Testi-OSU" ]
  2680. params['osu_icon'] = [ "w1fi_logo", "w1fi_logo2" ]
  2681. params['osu_service_desc'] = [ "eng:Example services", "fin:Esimerkkipalveluja" ]
  2682. params['osu_server_uri'] = "https://example.com/osu/"
  2683. hostapd.add_ap(apdev[0], params)
  2684. dev[0].scan_for_bss(bssid, freq="2412")
  2685. # First, fetch two icons from the AP to wpa_supplicant
  2686. if "OK" not in dev[0].request("REQ_HS20_ICON " + bssid + " w1fi_logo"):
  2687. raise Exception("REQ_HS20_ICON failed")
  2688. ev = dev[0].wait_event(["RX-HS20-ICON"], timeout=5)
  2689. if ev is None:
  2690. raise Exception("Timeout on RX-HS20-ICON (1)")
  2691. if "OK" not in dev[0].request("REQ_HS20_ICON " + bssid + " test_logo"):
  2692. raise Exception("REQ_HS20_ICON failed")
  2693. ev = dev[0].wait_event(["RX-HS20-ICON"], timeout=5)
  2694. if ev is None:
  2695. raise Exception("Timeout on RX-HS20-ICON (2)")
  2696. # Then, fetch the icons from wpa_supplicant for validation
  2697. hdr, data1 = get_icon(dev[0], bssid, "w1fi_logo")
  2698. hdr, data2 = get_icon(dev[0], bssid, "test_logo")
  2699. with open('w1fi_logo.png', 'r') as f:
  2700. data = f.read()
  2701. if data1 != data:
  2702. raise Exception("Unexpected icon data (1)")
  2703. with open('auth_serv/sha512-server.pem', 'r') as f:
  2704. data = f.read()
  2705. if data2 != data:
  2706. raise Exception("Unexpected icon data (2)")
  2707. # Finally, delete the icons from wpa_supplicant
  2708. if "OK" not in dev[0].request("DEL_HS20_ICON " + bssid + " w1fi_logo"):
  2709. raise Exception("DEL_HS20_ICON failed")
  2710. if "OK" not in dev[0].request("DEL_HS20_ICON " + bssid + " test_logo"):
  2711. raise Exception("DEL_HS20_ICON failed")
  2712. def test_ap_hs20_req_hs20_icon_oom(dev, apdev):
  2713. """Hotspot 2.0 icon fetch OOM with REQ_HS20_ICON"""
  2714. bssid = apdev[0]['bssid']
  2715. params = hs20_ap_params()
  2716. params['hs20_icon'] = [ "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png",
  2717. "128:80:zxx:image/png:test_logo:auth_serv/sha512-server.pem" ]
  2718. params['osu_ssid'] = '"HS 2.0 OSU open"'
  2719. params['osu_method_list'] = "1"
  2720. params['osu_friendly_name'] = [ "eng:Test OSU", "fin:Testi-OSU" ]
  2721. params['osu_icon'] = [ "w1fi_logo", "w1fi_logo2" ]
  2722. params['osu_service_desc'] = [ "eng:Example services", "fin:Esimerkkipalveluja" ]
  2723. params['osu_server_uri'] = "https://example.com/osu/"
  2724. hostapd.add_ap(apdev[0], params)
  2725. dev[0].scan_for_bss(bssid, freq="2412")
  2726. if "FAIL" not in dev[0].request("REQ_HS20_ICON 11:22:33:44:55:66 w1fi_logo"):
  2727. raise Exception("REQ_HS20_ICON succeeded with unknown BSSID")
  2728. with alloc_fail(dev[0], 1, "hs20_build_anqp_req;hs20_anqp_send_req"):
  2729. if "FAIL" not in dev[0].request("REQ_HS20_ICON " + bssid + " w1fi_logo"):
  2730. raise Exception("REQ_HS20_ICON succeeded during OOM")
  2731. with alloc_fail(dev[0], 1, "gas_query_req;hs20_anqp_send_req"):
  2732. if "FAIL" not in dev[0].request("REQ_HS20_ICON " + bssid + " w1fi_logo"):
  2733. raise Exception("REQ_HS20_ICON succeeded during OOM")
  2734. with alloc_fail(dev[0], 1, "=hs20_anqp_send_req"):
  2735. if "FAIL" not in dev[0].request("REQ_HS20_ICON " + bssid + " w1fi_logo"):
  2736. raise Exception("REQ_HS20_ICON succeeded during OOM")
  2737. with alloc_fail(dev[0], 2, "=hs20_anqp_send_req"):
  2738. if "FAIL" not in dev[0].request("REQ_HS20_ICON " + bssid + " w1fi_logo"):
  2739. raise Exception("REQ_HS20_ICON succeeded during OOM")
  2740. if "OK" not in dev[0].request("REQ_HS20_ICON " + bssid + " w1fi_logo"):
  2741. raise Exception("REQ_HS20_ICON failed")
  2742. ev = dev[0].wait_event(["RX-HS20-ICON"], timeout=5)
  2743. if ev is None:
  2744. raise Exception("Timeout on RX-HS20-ICON (1)")
  2745. with alloc_fail(dev[0], 1, "hs20_get_icon"):
  2746. if "FAIL" not in dev[0].request("GET_HS20_ICON " + bssid + "w1fi_logo 0 100"):
  2747. raise Exception("GET_HS20_ICON succeeded during OOM")
  2748. if "OK" not in dev[0].request("DEL_HS20_ICON " + bssid + " w1fi_logo"):
  2749. raise Exception("DEL_HS20_ICON failed")
  2750. with alloc_fail(dev[0], 1, "=hs20_process_icon_binary_file"):
  2751. if "OK" not in dev[0].request("REQ_HS20_ICON " + bssid + " w1fi_logo"):
  2752. raise Exception("REQ_HS20_ICON failed")
  2753. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  2754. def test_ap_hs20_req_hs20_icon_parallel(dev, apdev):
  2755. """Hotspot 2.0 OSU provider and multi-icon parallel fetch with REQ_HS20_ICON"""
  2756. bssid = apdev[0]['bssid']
  2757. params = hs20_ap_params()
  2758. params['hs20_icon'] = [ "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png",
  2759. "128:80:zxx:image/png:test_logo:auth_serv/sha512-server.pem" ]
  2760. params['osu_ssid'] = '"HS 2.0 OSU open"'
  2761. params['osu_method_list'] = "1"
  2762. params['osu_friendly_name'] = [ "eng:Test OSU", "fin:Testi-OSU" ]
  2763. params['osu_icon'] = [ "w1fi_logo", "w1fi_logo2" ]
  2764. params['osu_service_desc'] = [ "eng:Example services", "fin:Esimerkkipalveluja" ]
  2765. params['osu_server_uri'] = "https://example.com/osu/"
  2766. hostapd.add_ap(apdev[0], params)
  2767. dev[0].scan_for_bss(bssid, freq="2412")
  2768. # First, fetch two icons from the AP to wpa_supplicant
  2769. if "OK" not in dev[0].request("REQ_HS20_ICON " + bssid + " w1fi_logo"):
  2770. raise Exception("REQ_HS20_ICON failed")
  2771. if "OK" not in dev[0].request("REQ_HS20_ICON " + bssid + " test_logo"):
  2772. raise Exception("REQ_HS20_ICON failed")
  2773. ev = dev[0].wait_event(["RX-HS20-ICON"], timeout=5)
  2774. if ev is None:
  2775. raise Exception("Timeout on RX-HS20-ICON (1)")
  2776. ev = dev[0].wait_event(["RX-HS20-ICON"], timeout=5)
  2777. if ev is None:
  2778. raise Exception("Timeout on RX-HS20-ICON (2)")
  2779. # Then, fetch the icons from wpa_supplicant for validation
  2780. hdr, data1 = get_icon(dev[0], bssid, "w1fi_logo")
  2781. hdr, data2 = get_icon(dev[0], bssid, "test_logo")
  2782. with open('w1fi_logo.png', 'r') as f:
  2783. data = f.read()
  2784. if data1 != data:
  2785. raise Exception("Unexpected icon data (1)")
  2786. with open('auth_serv/sha512-server.pem', 'r') as f:
  2787. data = f.read()
  2788. if data2 != data:
  2789. raise Exception("Unexpected icon data (2)")
  2790. # Finally, delete the icons from wpa_supplicant
  2791. if "OK" not in dev[0].request("DEL_HS20_ICON " + bssid + " w1fi_logo"):
  2792. raise Exception("DEL_HS20_ICON failed")
  2793. if "OK" not in dev[0].request("DEL_HS20_ICON " + bssid + " test_logo"):
  2794. raise Exception("DEL_HS20_ICON failed")
  2795. def test_ap_hs20_fetch_osu_stop(dev, apdev):
  2796. """Hotspot 2.0 OSU provider fetch stopped"""
  2797. bssid = apdev[0]['bssid']
  2798. params = hs20_ap_params()
  2799. params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png"
  2800. params['osu_ssid'] = '"HS 2.0 OSU open"'
  2801. params['osu_method_list'] = "1"
  2802. params['osu_friendly_name'] = [ "eng:Test OSU", "fin:Testi-OSU" ]
  2803. params['osu_icon'] = "w1fi_logo"
  2804. params['osu_service_desc'] = [ "eng:Example services", "fin:Esimerkkipalveluja" ]
  2805. params['osu_server_uri'] = "https://example.com/osu/"
  2806. hapd = hostapd.add_ap(apdev[0], params)
  2807. dev[0].hs20_enable()
  2808. dir = "/tmp/osu-fetch"
  2809. if os.path.isdir(dir):
  2810. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  2811. for f in files:
  2812. os.remove(dir + "/" + f)
  2813. else:
  2814. try:
  2815. os.makedirs(dir)
  2816. except:
  2817. pass
  2818. try:
  2819. dev[0].request("SET osu_dir " + dir)
  2820. dev[0].request("SCAN freq=2412-2462")
  2821. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=10)
  2822. if ev is None:
  2823. raise Exception("Scan did not start")
  2824. if "FAIL" not in dev[0].request("FETCH_OSU"):
  2825. raise Exception("FETCH_OSU accepted while scanning")
  2826. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
  2827. if ev is None:
  2828. raise Exception("Scan timed out")
  2829. hapd.set("ext_mgmt_frame_handling", "1")
  2830. dev[0].request("FETCH_ANQP")
  2831. if "FAIL" not in dev[0].request("FETCH_OSU"):
  2832. raise Exception("FETCH_OSU accepted while in FETCH_ANQP")
  2833. dev[0].request("STOP_FETCH_ANQP")
  2834. dev[0].wait_event(["GAS-QUERY-DONE"], timeout=5)
  2835. dev[0].dump_monitor()
  2836. hapd.dump_monitor()
  2837. dev[0].request("INTERWORKING_SELECT freq=2412")
  2838. for i in range(5):
  2839. msg = hapd.mgmt_rx()
  2840. if msg['subtype'] == 13:
  2841. break
  2842. if "FAIL" not in dev[0].request("FETCH_OSU"):
  2843. raise Exception("FETCH_OSU accepted while in INTERWORKING_SELECT")
  2844. ev = dev[0].wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
  2845. timeout=15)
  2846. if ev is None:
  2847. raise Exception("Network selection timed out")
  2848. dev[0].dump_monitor()
  2849. if "OK" not in dev[0].request("FETCH_OSU"):
  2850. raise Exception("FETCH_OSU failed")
  2851. dev[0].request("CANCEL_FETCH_OSU")
  2852. for i in range(15):
  2853. time.sleep(0.5)
  2854. if dev[0].get_driver_status_field("scan_state") == "SCAN_COMPLETED":
  2855. break
  2856. dev[0].dump_monitor()
  2857. if "OK" not in dev[0].request("FETCH_OSU"):
  2858. raise Exception("FETCH_OSU failed")
  2859. if "FAIL" not in dev[0].request("FETCH_OSU"):
  2860. raise Exception("FETCH_OSU accepted while in FETCH_OSU")
  2861. ev = dev[0].wait_event(["GAS-QUERY-START"], 10)
  2862. if ev is None:
  2863. raise Exception("GAS timed out")
  2864. if "FAIL" not in dev[0].request("FETCH_OSU"):
  2865. raise Exception("FETCH_OSU accepted while in FETCH_OSU")
  2866. dev[0].request("CANCEL_FETCH_OSU")
  2867. ev = dev[0].wait_event(["GAS-QUERY-DONE"], 10)
  2868. if ev is None:
  2869. raise Exception("GAS event timed out after CANCEL_FETCH_OSU")
  2870. finally:
  2871. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  2872. for f in files:
  2873. os.remove(dir + "/" + f)
  2874. os.rmdir(dir)
  2875. def test_ap_hs20_fetch_osu_proto(dev, apdev):
  2876. """Hotspot 2.0 OSU provider and protocol testing"""
  2877. bssid = apdev[0]['bssid']
  2878. params = hs20_ap_params()
  2879. hapd = hostapd.add_ap(apdev[0], params)
  2880. dev[0].hs20_enable()
  2881. dir = "/tmp/osu-fetch"
  2882. if os.path.isdir(dir):
  2883. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  2884. for f in files:
  2885. os.remove(dir + "/" + f)
  2886. else:
  2887. try:
  2888. os.makedirs(dir)
  2889. except:
  2890. pass
  2891. tests = [ ( "Empty provider list (no OSU SSID field)", '' ),
  2892. ( "HS 2.0: Not enough room for OSU SSID",
  2893. binascii.unhexlify('01') ),
  2894. ( "HS 2.0: Invalid OSU SSID Length 33",
  2895. binascii.unhexlify('21') + 33*'A' ),
  2896. ( "HS 2.0: Not enough room for Number of OSU Providers",
  2897. binascii.unhexlify('0130') ),
  2898. ( "Truncated OSU Provider",
  2899. binascii.unhexlify('013001020000') ),
  2900. ( "HS 2.0: Ignored 5 bytes of extra data after OSU Providers",
  2901. binascii.unhexlify('0130001122334455') ),
  2902. ( "HS 2.0: Not enough room for OSU Friendly Name Length",
  2903. binascii.unhexlify('013001000000') ),
  2904. ( "HS 2.0: Not enough room for OSU Friendly Name Duples",
  2905. build_prov('0100') ),
  2906. ( "Invalid OSU Friendly Name", build_prov('040000000000') ),
  2907. ( "Invalid OSU Friendly Name(2)", build_prov('040004000000') ),
  2908. ( "HS 2.0: Not enough room for OSU Server URI length",
  2909. build_prov('0000') ),
  2910. ( "HS 2.0: Not enough room for OSU Server URI",
  2911. build_prov('000001') ),
  2912. ( "HS 2.0: Not enough room for OSU Method list length",
  2913. build_prov('000000') ),
  2914. ( "HS 2.0: Not enough room for OSU Method list",
  2915. build_prov('00000001') ),
  2916. ( "HS 2.0: Not enough room for Icons Available Length",
  2917. build_prov('00000000') ),
  2918. ( "HS 2.0: Not enough room for Icons Available Length(2)",
  2919. build_prov('00000001ff00') ),
  2920. ( "HS 2.0: Not enough room for Icons Available",
  2921. build_prov('000000000100') ),
  2922. ( "HS 2.0: Invalid Icon Metadata",
  2923. build_prov('00000000010000') ),
  2924. ( "HS 2.0: Not room for Icon Type",
  2925. build_prov('000000000900111122223333330200') ),
  2926. ( "HS 2.0: Not room for Icon Filename length",
  2927. build_prov('000000000900111122223333330100') ),
  2928. ( "HS 2.0: Not room for Icon Filename",
  2929. build_prov('000000000900111122223333330001') ),
  2930. ( "HS 2.0: Not enough room for OSU_NAI",
  2931. build_prov('000000000000') ),
  2932. ( "HS 2.0: Not enough room for OSU_NAI(2)",
  2933. build_prov('00000000000001') ),
  2934. ( "HS 2.0: Not enough room for OSU Service Description Length",
  2935. build_prov('00000000000000') ),
  2936. ( "HS 2.0: Not enough room for OSU Service Description Length(2)",
  2937. build_prov('0000000000000000') ),
  2938. ( "HS 2.0: Not enough room for OSU Service Description Duples",
  2939. build_prov('000000000000000100') ),
  2940. ( "Invalid OSU Service Description",
  2941. build_prov('00000000000000040000000000') ),
  2942. ( "Invalid OSU Service Description(2)",
  2943. build_prov('00000000000000040004000000') ) ]
  2944. try:
  2945. dev[0].request("SET osu_dir " + dir)
  2946. run_fetch_osu_icon_failure(hapd, dev, bssid)
  2947. for note, prov in tests:
  2948. run_fetch_osu(hapd, dev, bssid, note, prov)
  2949. finally:
  2950. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  2951. for f in files:
  2952. os.remove(dir + "/" + f)
  2953. os.rmdir(dir)
  2954. def test_ap_hs20_fetch_osu_invalid_dir(dev, apdev):
  2955. """Hotspot 2.0 OSU provider and invalid directory"""
  2956. bssid = apdev[0]['bssid']
  2957. params = hs20_ap_params()
  2958. params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png"
  2959. params['osu_ssid'] = '"HS 2.0 OSU open"'
  2960. params['osu_method_list'] = "1"
  2961. params['osu_friendly_name'] = [ "eng:Test OSU", "fin:Testi-OSU" ]
  2962. params['osu_icon'] = "w1fi_logo"
  2963. params['osu_service_desc'] = [ "eng:Example services", "fin:Esimerkkipalveluja" ]
  2964. params['osu_server_uri'] = "https://example.com/osu/"
  2965. hostapd.add_ap(apdev[0], params)
  2966. dev[0].hs20_enable()
  2967. dir = "/tmp/osu-fetch-no-such-dir"
  2968. dev[0].scan_for_bss(bssid, freq="2412")
  2969. dev[0].request("SET osu_dir " + dir)
  2970. dev[0].request("FETCH_OSU no-scan")
  2971. ev = dev[0].wait_event(["Could not write OSU provider information"],
  2972. timeout=15)
  2973. if ev is None:
  2974. raise Exception("Timeout on OSU fetch")
  2975. def test_ap_hs20_fetch_osu_oom(dev, apdev):
  2976. """Hotspot 2.0 OSU provider and OOM"""
  2977. bssid = apdev[0]['bssid']
  2978. params = hs20_ap_params()
  2979. params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png"
  2980. params['osu_ssid'] = '"HS 2.0 OSU open"'
  2981. params['osu_method_list'] = "1"
  2982. params['osu_friendly_name'] = [ "eng:Test OSU", "fin:Testi-OSU" ]
  2983. params['osu_icon'] = "w1fi_logo"
  2984. params['osu_service_desc'] = [ "eng:Example services", "fin:Esimerkkipalveluja" ]
  2985. params['osu_server_uri'] = "https://example.com/osu/"
  2986. hostapd.add_ap(apdev[0], params)
  2987. dev[0].hs20_enable()
  2988. dir = "/tmp/osu-fetch"
  2989. if os.path.isdir(dir):
  2990. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  2991. for f in files:
  2992. os.remove(dir + "/" + f)
  2993. else:
  2994. try:
  2995. os.makedirs(dir)
  2996. except:
  2997. pass
  2998. dev[0].scan_for_bss(bssid, freq="2412")
  2999. try:
  3000. dev[0].request("SET osu_dir " + dir)
  3001. with alloc_fail(dev[0], 1, "=hs20_osu_add_prov"):
  3002. dev[0].request("FETCH_OSU no-scan")
  3003. ev = dev[0].wait_event(["OSU provider fetch completed"], timeout=30)
  3004. if ev is None:
  3005. raise Exception("Timeout on OSU fetch")
  3006. with alloc_fail(dev[0], 1, "hs20_anqp_send_req;hs20_next_osu_icon"):
  3007. dev[0].request("FETCH_OSU no-scan")
  3008. ev = dev[0].wait_event(["OSU provider fetch completed"], timeout=30)
  3009. if ev is None:
  3010. raise Exception("Timeout on OSU fetch")
  3011. finally:
  3012. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  3013. for f in files:
  3014. os.remove(dir + "/" + f)
  3015. os.rmdir(dir)
  3016. def build_prov(prov):
  3017. data = binascii.unhexlify(prov)
  3018. return binascii.unhexlify('013001') + struct.pack('<H', len(data)) + data
  3019. def handle_osu_prov_fetch(hapd, dev, prov):
  3020. # GAS/ANQP query for OSU Providers List
  3021. query = gas_rx(hapd)
  3022. gas = parse_gas(query['payload'])
  3023. dialog_token = gas['dialog_token']
  3024. resp = action_response(query)
  3025. osu_prov = struct.pack('<HH', 0xdddd, len(prov) + 6) + binascii.unhexlify('506f9a110800') + prov
  3026. data = struct.pack('<H', len(osu_prov)) + osu_prov
  3027. resp['payload'] = anqp_initial_resp(dialog_token, 0) + data
  3028. send_gas_resp(hapd, resp)
  3029. ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=5)
  3030. if ev is None:
  3031. raise Exception("ANQP query response for OSU Providers not received")
  3032. if "OSU Providers list" not in ev:
  3033. raise Exception("ANQP query response for OSU Providers not received(2)")
  3034. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=5)
  3035. if ev is None:
  3036. raise Exception("ANQP query for OSU Providers list not completed")
  3037. def start_osu_fetch(hapd, dev, bssid, note):
  3038. hapd.set("ext_mgmt_frame_handling", "0")
  3039. dev[0].request("BSS_FLUSH 0")
  3040. dev[0].scan_for_bss(bssid, freq="2412")
  3041. hapd.set("ext_mgmt_frame_handling", "1")
  3042. dev[0].dump_monitor()
  3043. dev[0].request("NOTE " + note)
  3044. dev[0].request("FETCH_OSU no-scan")
  3045. def wait_osu_fetch_completed(dev):
  3046. ev = dev[0].wait_event(["OSU provider fetch completed"], timeout=5)
  3047. if ev is None:
  3048. raise Exception("Timeout on OSU fetch")
  3049. def run_fetch_osu_icon_failure(hapd, dev, bssid):
  3050. start_osu_fetch(hapd, dev, bssid, "Icon fetch failure")
  3051. prov = binascii.unhexlify('01ff' + '01' + '800019000b656e6754657374204f53550c66696e54657374692d4f53551868747470733a2f2f6578616d706c652e636f6d2f6f73752f01011b00800050007a787809696d6167652f706e6709773166695f6c6f676f002a0013656e674578616d706c652073657276696365731566696e4573696d65726b6b6970616c76656c756a61')
  3052. handle_osu_prov_fetch(hapd, dev, prov)
  3053. # GAS/ANQP query for icon
  3054. query = gas_rx(hapd)
  3055. gas = parse_gas(query['payload'])
  3056. dialog_token = gas['dialog_token']
  3057. resp = action_response(query)
  3058. # Unexpected Advertisement Protocol in response
  3059. adv_proto = struct.pack('8B', 108, 6, 127, 0xdd, 0x00, 0x11, 0x22, 0x33)
  3060. data = struct.pack('<H', 0)
  3061. resp['payload'] = struct.pack('<BBBHH', ACTION_CATEG_PUBLIC,
  3062. GAS_INITIAL_RESPONSE,
  3063. gas['dialog_token'], 0, 0) + adv_proto + data
  3064. send_gas_resp(hapd, resp)
  3065. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=5)
  3066. if ev is None:
  3067. raise Exception("ANQP query for icon not completed")
  3068. wait_osu_fetch_completed(dev)
  3069. def run_fetch_osu(hapd, dev, bssid, note, prov):
  3070. start_osu_fetch(hapd, dev, bssid, note)
  3071. handle_osu_prov_fetch(hapd, dev, prov)
  3072. wait_osu_fetch_completed(dev)
  3073. def test_ap_hs20_ft(dev, apdev):
  3074. """Hotspot 2.0 connection with FT"""
  3075. check_eap_capa(dev[0], "MSCHAPV2")
  3076. bssid = apdev[0]['bssid']
  3077. params = hs20_ap_params()
  3078. params['wpa_key_mgmt'] = "FT-EAP"
  3079. params['nas_identifier'] = "nas1.w1.fi"
  3080. params['r1_key_holder'] = "000102030405"
  3081. params["mobility_domain"] = "a1b2"
  3082. params["reassociation_deadline"] = "1000"
  3083. hostapd.add_ap(apdev[0], params)
  3084. dev[0].hs20_enable()
  3085. id = dev[0].add_cred_values({ 'realm': "example.com",
  3086. 'username': "hs20-test",
  3087. 'password': "password",
  3088. 'ca_cert': "auth_serv/ca.pem",
  3089. 'domain': "example.com",
  3090. 'update_identifier': "1234" })
  3091. interworking_select(dev[0], bssid, "home", freq="2412")
  3092. interworking_connect(dev[0], bssid, "TTLS")
  3093. def test_ap_hs20_remediation_sql(dev, apdev, params):
  3094. """Hotspot 2.0 connection and remediation required using SQLite for user DB"""
  3095. check_eap_capa(dev[0], "MSCHAPV2")
  3096. try:
  3097. import sqlite3
  3098. except ImportError:
  3099. raise HwsimSkip("No sqlite3 module available")
  3100. dbfile = os.path.join(params['logdir'], "eap-user.db")
  3101. try:
  3102. os.remove(dbfile)
  3103. except:
  3104. pass
  3105. con = sqlite3.connect(dbfile)
  3106. with con:
  3107. cur = con.cursor()
  3108. cur.execute("CREATE TABLE users(identity TEXT PRIMARY KEY, methods TEXT, password TEXT, remediation TEXT, phase2 INTEGER)")
  3109. cur.execute("CREATE TABLE wildcards(identity TEXT PRIMARY KEY, methods TEXT)")
  3110. cur.execute("INSERT INTO users(identity,methods,password,phase2,remediation) VALUES ('user-mschapv2','TTLS-MSCHAPV2','password',1,'user')")
  3111. cur.execute("INSERT INTO wildcards(identity,methods) VALUES ('','TTLS,TLS')")
  3112. cur.execute("CREATE TABLE authlog(timestamp TEXT, session TEXT, nas_ip TEXT, username TEXT, note TEXT)")
  3113. try:
  3114. params = { "ssid": "as", "beacon_int": "2000",
  3115. "radius_server_clients": "auth_serv/radius_clients.conf",
  3116. "radius_server_auth_port": '18128',
  3117. "eap_server": "1",
  3118. "eap_user_file": "sqlite:" + dbfile,
  3119. "ca_cert": "auth_serv/ca.pem",
  3120. "server_cert": "auth_serv/server.pem",
  3121. "private_key": "auth_serv/server.key",
  3122. "subscr_remediation_url": "https://example.org/",
  3123. "subscr_remediation_method": "1" }
  3124. hostapd.add_ap(apdev[1], params)
  3125. bssid = apdev[0]['bssid']
  3126. params = hs20_ap_params()
  3127. params['auth_server_port'] = "18128"
  3128. hostapd.add_ap(apdev[0], params)
  3129. dev[0].request("SET pmf 1")
  3130. dev[0].hs20_enable()
  3131. id = dev[0].add_cred_values({ 'realm': "example.com",
  3132. 'username': "user-mschapv2",
  3133. 'password': "password",
  3134. 'ca_cert': "auth_serv/ca.pem" })
  3135. interworking_select(dev[0], bssid, freq="2412")
  3136. interworking_connect(dev[0], bssid, "TTLS")
  3137. ev = dev[0].wait_event(["HS20-SUBSCRIPTION-REMEDIATION"], timeout=5)
  3138. if ev is None:
  3139. raise Exception("Timeout on subscription remediation notice")
  3140. if " 1 https://example.org/" not in ev:
  3141. raise Exception("Unexpected subscription remediation event contents")
  3142. with con:
  3143. cur = con.cursor()
  3144. cur.execute("SELECT * from authlog")
  3145. rows = cur.fetchall()
  3146. if len(rows) < 1:
  3147. raise Exception("No authlog entries")
  3148. finally:
  3149. os.remove(dbfile)
  3150. dev[0].request("SET pmf 0")
  3151. def test_ap_hs20_external_selection(dev, apdev):
  3152. """Hotspot 2.0 connection using external network selection and creation"""
  3153. check_eap_capa(dev[0], "MSCHAPV2")
  3154. bssid = apdev[0]['bssid']
  3155. params = hs20_ap_params()
  3156. params['hessid'] = bssid
  3157. params['disable_dgaf'] = '1'
  3158. hostapd.add_ap(apdev[0], params)
  3159. dev[0].hs20_enable()
  3160. dev[0].connect("test-hs20", proto="RSN", key_mgmt="WPA-EAP", eap="TTLS",
  3161. identity="hs20-test", password="password",
  3162. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3163. scan_freq="2412", update_identifier="54321")
  3164. if dev[0].get_status_field("hs20") != "2":
  3165. raise Exception("Unexpected hs20 indication")
  3166. def test_ap_hs20_random_mac_addr(dev, apdev):
  3167. """Hotspot 2.0 connection with random MAC address"""
  3168. check_eap_capa(dev[0], "MSCHAPV2")
  3169. bssid = apdev[0]['bssid']
  3170. params = hs20_ap_params()
  3171. params['hessid'] = bssid
  3172. params['disable_dgaf'] = '1'
  3173. hapd = hostapd.add_ap(apdev[0], params)
  3174. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  3175. wpas.interface_add("wlan5")
  3176. addr = wpas.p2p_interface_addr()
  3177. wpas.request("SET mac_addr 1")
  3178. wpas.request("SET preassoc_mac_addr 1")
  3179. wpas.request("SET rand_addr_lifetime 60")
  3180. wpas.hs20_enable()
  3181. wpas.flush_scan_cache()
  3182. id = wpas.add_cred_values({ 'realm': "example.com",
  3183. 'username': "hs20-test",
  3184. 'password': "password",
  3185. 'ca_cert': "auth_serv/ca.pem",
  3186. 'domain': "example.com",
  3187. 'update_identifier': "1234" })
  3188. interworking_select(wpas, bssid, "home", freq="2412")
  3189. interworking_connect(wpas, bssid, "TTLS")
  3190. addr1 = wpas.get_driver_status_field("addr")
  3191. if addr == addr1:
  3192. raise Exception("Did not use random MAC address")
  3193. sta = hapd.get_sta(addr)
  3194. if sta['addr'] != "FAIL":
  3195. raise Exception("Unexpected STA association with permanent address")
  3196. sta = hapd.get_sta(addr1)
  3197. if sta['addr'] != addr1:
  3198. raise Exception("STA association with random address not found")
  3199. def test_ap_hs20_multi_network_and_cred_removal(dev, apdev):
  3200. """Multiple networks and cred removal"""
  3201. check_eap_capa(dev[0], "MSCHAPV2")
  3202. bssid = apdev[0]['bssid']
  3203. params = hs20_ap_params()
  3204. params['nai_realm'] = [ "0,example.com,25[3:26]"]
  3205. hapd = hostapd.add_ap(apdev[0], params)
  3206. dev[0].add_network()
  3207. dev[0].hs20_enable()
  3208. id = dev[0].add_cred_values({ 'realm': "example.com",
  3209. 'username': "user",
  3210. 'password': "password" })
  3211. interworking_select(dev[0], bssid, freq="2412")
  3212. interworking_connect(dev[0], bssid, "PEAP")
  3213. dev[0].add_network()
  3214. dev[0].request("DISCONNECT")
  3215. dev[0].wait_disconnected(timeout=10)
  3216. hapd.disable()
  3217. hapd.set("ssid", "another ssid")
  3218. hapd.enable()
  3219. interworking_select(dev[0], bssid, freq="2412")
  3220. interworking_connect(dev[0], bssid, "PEAP")
  3221. dev[0].add_network()
  3222. if len(dev[0].list_networks()) != 5:
  3223. raise Exception("Unexpected number of networks prior to remove_crec")
  3224. dev[0].dump_monitor()
  3225. dev[0].remove_cred(id)
  3226. if len(dev[0].list_networks()) != 3:
  3227. raise Exception("Unexpected number of networks after to remove_crec")
  3228. dev[0].wait_disconnected(timeout=10)
  3229. def test_ap_hs20_interworking_add_network(dev, apdev):
  3230. """Hotspot 2.0 connection using INTERWORKING_ADD_NETWORK"""
  3231. check_eap_capa(dev[0], "MSCHAPV2")
  3232. bssid = apdev[0]['bssid']
  3233. params = hs20_ap_params()
  3234. params['nai_realm'] = [ "0,example.com,21[3:26][6:7][99:99]" ]
  3235. hostapd.add_ap(apdev[0], params)
  3236. dev[0].hs20_enable()
  3237. dev[0].add_cred_values(default_cred(user="user"))
  3238. interworking_select(dev[0], bssid, freq=2412)
  3239. id = dev[0].interworking_add_network(bssid)
  3240. dev[0].select_network(id, freq=2412)
  3241. dev[0].wait_connected()
  3242. def _test_ap_hs20_proxyarp(dev, apdev):
  3243. bssid = apdev[0]['bssid']
  3244. params = hs20_ap_params()
  3245. params['hessid'] = bssid
  3246. params['disable_dgaf'] = '0'
  3247. params['proxy_arp'] = '1'
  3248. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  3249. if "OK" in hapd.request("ENABLE"):
  3250. raise Exception("Incomplete hostapd configuration was accepted")
  3251. hapd.set("ap_isolate", "1")
  3252. if "OK" in hapd.request("ENABLE"):
  3253. raise Exception("Incomplete hostapd configuration was accepted")
  3254. hapd.set('bridge', 'ap-br0')
  3255. hapd.dump_monitor()
  3256. try:
  3257. hapd.enable()
  3258. except:
  3259. # For now, do not report failures due to missing kernel support
  3260. raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version")
  3261. ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=10)
  3262. if ev is None:
  3263. raise Exception("AP startup timed out")
  3264. if "AP-ENABLED" not in ev:
  3265. raise Exception("AP startup failed")
  3266. dev[0].hs20_enable()
  3267. subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
  3268. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  3269. id = dev[0].add_cred_values({ 'realm': "example.com",
  3270. 'username': "hs20-test",
  3271. 'password': "password",
  3272. 'ca_cert': "auth_serv/ca.pem",
  3273. 'domain': "example.com",
  3274. 'update_identifier': "1234" })
  3275. interworking_select(dev[0], bssid, "home", freq="2412")
  3276. interworking_connect(dev[0], bssid, "TTLS")
  3277. dev[1].connect("test-hs20", key_mgmt="WPA-EAP", eap="TTLS",
  3278. identity="hs20-test", password="password",
  3279. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3280. scan_freq="2412")
  3281. time.sleep(0.1)
  3282. addr0 = dev[0].p2p_interface_addr()
  3283. addr1 = dev[1].p2p_interface_addr()
  3284. src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':',''))
  3285. src_ll_opt1 = "\x01\x01" + binascii.unhexlify(addr1.replace(':',''))
  3286. pkt = build_ns(src_ll=addr0, ip_src="aaaa:bbbb:cccc::2",
  3287. ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:cccc::2",
  3288. opt=src_ll_opt0)
  3289. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  3290. raise Exception("DATA_TEST_FRAME failed")
  3291. pkt = build_ns(src_ll=addr1, ip_src="aaaa:bbbb:dddd::2",
  3292. ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:dddd::2",
  3293. opt=src_ll_opt1)
  3294. if "OK" not in dev[1].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  3295. raise Exception("DATA_TEST_FRAME failed")
  3296. pkt = build_ns(src_ll=addr1, ip_src="aaaa:bbbb:eeee::2",
  3297. ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:eeee::2",
  3298. opt=src_ll_opt1)
  3299. if "OK" not in dev[1].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  3300. raise Exception("DATA_TEST_FRAME failed")
  3301. matches = get_permanent_neighbors("ap-br0")
  3302. logger.info("After connect: " + str(matches))
  3303. if len(matches) != 3:
  3304. raise Exception("Unexpected number of neighbor entries after connect")
  3305. if 'aaaa:bbbb:cccc::2 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  3306. raise Exception("dev0 addr missing")
  3307. if 'aaaa:bbbb:dddd::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches:
  3308. raise Exception("dev1 addr(1) missing")
  3309. if 'aaaa:bbbb:eeee::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches:
  3310. raise Exception("dev1 addr(2) missing")
  3311. dev[0].request("DISCONNECT")
  3312. dev[1].request("DISCONNECT")
  3313. time.sleep(0.5)
  3314. matches = get_permanent_neighbors("ap-br0")
  3315. logger.info("After disconnect: " + str(matches))
  3316. if len(matches) > 0:
  3317. raise Exception("Unexpected neighbor entries after disconnect")
  3318. def test_ap_hs20_hidden_ssid_in_scan_res(dev, apdev):
  3319. """Hotspot 2.0 connection with hidden SSId in scan results"""
  3320. check_eap_capa(dev[0], "MSCHAPV2")
  3321. bssid = apdev[0]['bssid']
  3322. hapd = hostapd.add_ap(apdev[0], { "ssid": 'secret',
  3323. "ignore_broadcast_ssid": "1" })
  3324. dev[0].scan_for_bss(bssid, freq=2412)
  3325. hapd.disable()
  3326. hapd_global = hostapd.HostapdGlobal(apdev[0])
  3327. hapd_global.flush()
  3328. hapd_global.remove(apdev[0]['ifname'])
  3329. params = hs20_ap_params()
  3330. params['hessid'] = bssid
  3331. hapd = hostapd.add_ap(apdev[0], params)
  3332. dev[0].hs20_enable()
  3333. id = dev[0].add_cred_values({ 'realm': "example.com",
  3334. 'username': "hs20-test",
  3335. 'password': "password",
  3336. 'ca_cert': "auth_serv/ca.pem",
  3337. 'domain': "example.com" })
  3338. interworking_select(dev[0], bssid, "home", freq="2412")
  3339. interworking_connect(dev[0], bssid, "TTLS")
  3340. # clear BSS table to avoid issues in following test cases
  3341. dev[0].request("DISCONNECT")
  3342. dev[0].wait_disconnected()
  3343. hapd.disable()
  3344. dev[0].flush_scan_cache()
  3345. dev[0].flush_scan_cache()
  3346. def test_ap_hs20_proxyarp(dev, apdev):
  3347. """Hotspot 2.0 and ProxyARP"""
  3348. check_eap_capa(dev[0], "MSCHAPV2")
  3349. try:
  3350. _test_ap_hs20_proxyarp(dev, apdev)
  3351. finally:
  3352. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  3353. stderr=open('/dev/null', 'w'))
  3354. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  3355. stderr=open('/dev/null', 'w'))
  3356. def _test_ap_hs20_proxyarp_dgaf(dev, apdev, disabled):
  3357. bssid = apdev[0]['bssid']
  3358. params = hs20_ap_params()
  3359. params['hessid'] = bssid
  3360. params['disable_dgaf'] = '1' if disabled else '0'
  3361. params['proxy_arp'] = '1'
  3362. params['na_mcast_to_ucast'] = '1'
  3363. params['ap_isolate'] = '1'
  3364. params['bridge'] = 'ap-br0'
  3365. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  3366. try:
  3367. hapd.enable()
  3368. except:
  3369. # For now, do not report failures due to missing kernel support
  3370. raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version")
  3371. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  3372. if ev is None:
  3373. raise Exception("AP startup timed out")
  3374. dev[0].hs20_enable()
  3375. subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
  3376. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  3377. id = dev[0].add_cred_values({ 'realm': "example.com",
  3378. 'username': "hs20-test",
  3379. 'password': "password",
  3380. 'ca_cert': "auth_serv/ca.pem",
  3381. 'domain': "example.com",
  3382. 'update_identifier': "1234" })
  3383. interworking_select(dev[0], bssid, "home", freq="2412")
  3384. interworking_connect(dev[0], bssid, "TTLS")
  3385. dev[1].connect("test-hs20", key_mgmt="WPA-EAP", eap="TTLS",
  3386. identity="hs20-test", password="password",
  3387. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3388. scan_freq="2412")
  3389. time.sleep(0.1)
  3390. addr0 = dev[0].p2p_interface_addr()
  3391. src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':',''))
  3392. pkt = build_ns(src_ll=addr0, ip_src="aaaa:bbbb:cccc::2",
  3393. ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:cccc::2",
  3394. opt=src_ll_opt0)
  3395. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  3396. raise Exception("DATA_TEST_FRAME failed")
  3397. pkt = build_ra(src_ll=apdev[0]['bssid'], ip_src="aaaa:bbbb:cccc::33",
  3398. ip_dst="ff01::1")
  3399. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  3400. raise Exception("DATA_TEST_FRAME failed")
  3401. pkt = build_na(src_ll=apdev[0]['bssid'], ip_src="aaaa:bbbb:cccc::44",
  3402. ip_dst="ff01::1", target="aaaa:bbbb:cccc::55")
  3403. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  3404. raise Exception("DATA_TEST_FRAME failed")
  3405. pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid,
  3406. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  3407. yiaddr="192.168.1.123", chaddr=addr0)
  3408. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  3409. raise Exception("DATA_TEST_FRAME failed")
  3410. # another copy for additional code coverage
  3411. pkt = build_dhcp_ack(dst_ll=addr0, src_ll=bssid,
  3412. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  3413. yiaddr="192.168.1.123", chaddr=addr0)
  3414. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  3415. raise Exception("DATA_TEST_FRAME failed")
  3416. matches = get_permanent_neighbors("ap-br0")
  3417. logger.info("After connect: " + str(matches))
  3418. if len(matches) != 2:
  3419. raise Exception("Unexpected number of neighbor entries after connect")
  3420. if 'aaaa:bbbb:cccc::2 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  3421. raise Exception("dev0 addr missing")
  3422. if '192.168.1.123 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  3423. raise Exception("dev0 IPv4 addr missing")
  3424. dev[0].request("DISCONNECT")
  3425. dev[1].request("DISCONNECT")
  3426. time.sleep(0.5)
  3427. matches = get_permanent_neighbors("ap-br0")
  3428. logger.info("After disconnect: " + str(matches))
  3429. if len(matches) > 0:
  3430. raise Exception("Unexpected neighbor entries after disconnect")
  3431. def test_ap_hs20_proxyarp_disable_dgaf(dev, apdev):
  3432. """Hotspot 2.0 and ProxyARP with DGAF disabled"""
  3433. check_eap_capa(dev[0], "MSCHAPV2")
  3434. try:
  3435. _test_ap_hs20_proxyarp_dgaf(dev, apdev, True)
  3436. finally:
  3437. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  3438. stderr=open('/dev/null', 'w'))
  3439. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  3440. stderr=open('/dev/null', 'w'))
  3441. def test_ap_hs20_proxyarp_enable_dgaf(dev, apdev):
  3442. """Hotspot 2.0 and ProxyARP with DGAF enabled"""
  3443. check_eap_capa(dev[0], "MSCHAPV2")
  3444. try:
  3445. _test_ap_hs20_proxyarp_dgaf(dev, apdev, False)
  3446. finally:
  3447. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  3448. stderr=open('/dev/null', 'w'))
  3449. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  3450. stderr=open('/dev/null', 'w'))
  3451. def ip_checksum(buf):
  3452. sum = 0
  3453. if len(buf) & 0x01:
  3454. buf += '\0x00'
  3455. for i in range(0, len(buf), 2):
  3456. val, = struct.unpack('H', buf[i:i+2])
  3457. sum += val
  3458. while (sum >> 16):
  3459. sum = (sum & 0xffff) + (sum >> 16)
  3460. return struct.pack('H', ~sum & 0xffff)
  3461. def ipv6_solicited_node_mcaddr(target):
  3462. prefix = socket.inet_pton(socket.AF_INET6, "ff02::1:ff00:0")
  3463. mask = socket.inet_pton(socket.AF_INET6, "::ff:ffff")
  3464. _target = socket.inet_pton(socket.AF_INET6, target)
  3465. p = struct.unpack('4I', prefix)
  3466. m = struct.unpack('4I', mask)
  3467. t = struct.unpack('4I', _target)
  3468. res = (p[0] | (t[0] & m[0]),
  3469. p[1] | (t[1] & m[1]),
  3470. p[2] | (t[2] & m[2]),
  3471. p[3] | (t[3] & m[3]))
  3472. return socket.inet_ntop(socket.AF_INET6, struct.pack('4I', *res))
  3473. def build_icmpv6(ipv6_addrs, type, code, payload):
  3474. start = struct.pack("BB", type, code)
  3475. end = payload
  3476. icmp = start + '\x00\x00' + end
  3477. pseudo = ipv6_addrs + struct.pack(">LBBBB", len(icmp), 0, 0, 0, 58)
  3478. csum = ip_checksum(pseudo + icmp)
  3479. return start + csum + end
  3480. def build_ra(src_ll, ip_src, ip_dst, cur_hop_limit=0, router_lifetime=0,
  3481. reachable_time=0, retrans_timer=0, opt=None):
  3482. link_mc = binascii.unhexlify("3333ff000002")
  3483. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  3484. proto = '\x86\xdd'
  3485. ehdr = link_mc + _src_ll + proto
  3486. _ip_src = socket.inet_pton(socket.AF_INET6, ip_src)
  3487. _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst)
  3488. adv = struct.pack('>BBHLL', cur_hop_limit, 0, router_lifetime,
  3489. reachable_time, retrans_timer)
  3490. if opt:
  3491. payload = adv + opt
  3492. else:
  3493. payload = adv
  3494. icmp = build_icmpv6(_ip_src + _ip_dst, 134, 0, payload)
  3495. ipv6 = struct.pack('>BBBBHBB', 0x60, 0, 0, 0, len(icmp), 58, 255)
  3496. ipv6 += _ip_src + _ip_dst
  3497. return ehdr + ipv6 + icmp
  3498. def build_ns(src_ll, ip_src, ip_dst, target, opt=None):
  3499. link_mc = binascii.unhexlify("3333ff000002")
  3500. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  3501. proto = '\x86\xdd'
  3502. ehdr = link_mc + _src_ll + proto
  3503. _ip_src = socket.inet_pton(socket.AF_INET6, ip_src)
  3504. if ip_dst is None:
  3505. ip_dst = ipv6_solicited_node_mcaddr(target)
  3506. _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst)
  3507. reserved = '\x00\x00\x00\x00'
  3508. _target = socket.inet_pton(socket.AF_INET6, target)
  3509. if opt:
  3510. payload = reserved + _target + opt
  3511. else:
  3512. payload = reserved + _target
  3513. icmp = build_icmpv6(_ip_src + _ip_dst, 135, 0, payload)
  3514. ipv6 = struct.pack('>BBBBHBB', 0x60, 0, 0, 0, len(icmp), 58, 255)
  3515. ipv6 += _ip_src + _ip_dst
  3516. return ehdr + ipv6 + icmp
  3517. def send_ns(dev, src_ll=None, target=None, ip_src=None, ip_dst=None, opt=None,
  3518. hapd_bssid=None):
  3519. if hapd_bssid:
  3520. if src_ll is None:
  3521. src_ll = hapd_bssid
  3522. cmd = "DATA_TEST_FRAME ifname=ap-br0 "
  3523. else:
  3524. if src_ll is None:
  3525. src_ll = dev.p2p_interface_addr()
  3526. cmd = "DATA_TEST_FRAME "
  3527. if opt is None:
  3528. opt = "\x01\x01" + binascii.unhexlify(src_ll.replace(':',''))
  3529. pkt = build_ns(src_ll=src_ll, ip_src=ip_src, ip_dst=ip_dst, target=target,
  3530. opt=opt)
  3531. if "OK" not in dev.request(cmd + binascii.hexlify(pkt)):
  3532. raise Exception("DATA_TEST_FRAME failed")
  3533. def build_na(src_ll, ip_src, ip_dst, target, opt=None, flags=0):
  3534. link_mc = binascii.unhexlify("3333ff000002")
  3535. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  3536. proto = '\x86\xdd'
  3537. ehdr = link_mc + _src_ll + proto
  3538. _ip_src = socket.inet_pton(socket.AF_INET6, ip_src)
  3539. _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst)
  3540. _target = socket.inet_pton(socket.AF_INET6, target)
  3541. if opt:
  3542. payload = struct.pack('>Bxxx', flags) + _target + opt
  3543. else:
  3544. payload = struct.pack('>Bxxx', flags) + _target
  3545. icmp = build_icmpv6(_ip_src + _ip_dst, 136, 0, payload)
  3546. ipv6 = struct.pack('>BBBBHBB', 0x60, 0, 0, 0, len(icmp), 58, 255)
  3547. ipv6 += _ip_src + _ip_dst
  3548. return ehdr + ipv6 + icmp
  3549. def send_na(dev, src_ll=None, target=None, ip_src=None, ip_dst=None, opt=None,
  3550. hapd_bssid=None):
  3551. if hapd_bssid:
  3552. if src_ll is None:
  3553. src_ll = hapd_bssid
  3554. cmd = "DATA_TEST_FRAME ifname=ap-br0 "
  3555. else:
  3556. if src_ll is None:
  3557. src_ll = dev.p2p_interface_addr()
  3558. cmd = "DATA_TEST_FRAME "
  3559. pkt = build_na(src_ll=src_ll, ip_src=ip_src, ip_dst=ip_dst, target=target,
  3560. opt=opt)
  3561. if "OK" not in dev.request(cmd + binascii.hexlify(pkt)):
  3562. raise Exception("DATA_TEST_FRAME failed")
  3563. def build_dhcp_ack(dst_ll, src_ll, ip_src, ip_dst, yiaddr, chaddr,
  3564. subnet_mask="255.255.255.0", truncated_opt=False,
  3565. wrong_magic=False, force_tot_len=None, no_dhcp=False):
  3566. _dst_ll = binascii.unhexlify(dst_ll.replace(':',''))
  3567. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  3568. proto = '\x08\x00'
  3569. ehdr = _dst_ll + _src_ll + proto
  3570. _ip_src = socket.inet_pton(socket.AF_INET, ip_src)
  3571. _ip_dst = socket.inet_pton(socket.AF_INET, ip_dst)
  3572. _subnet_mask = socket.inet_pton(socket.AF_INET, subnet_mask)
  3573. _ciaddr = '\x00\x00\x00\x00'
  3574. _yiaddr = socket.inet_pton(socket.AF_INET, yiaddr)
  3575. _siaddr = '\x00\x00\x00\x00'
  3576. _giaddr = '\x00\x00\x00\x00'
  3577. _chaddr = binascii.unhexlify(chaddr.replace(':','') + "00000000000000000000")
  3578. payload = struct.pack('>BBBBL3BB', 2, 1, 6, 0, 12345, 0, 0, 0, 0)
  3579. payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192*'\x00'
  3580. # magic
  3581. if wrong_magic:
  3582. payload += '\x63\x82\x53\x00'
  3583. else:
  3584. payload += '\x63\x82\x53\x63'
  3585. if truncated_opt:
  3586. payload += '\x22\xff\x00'
  3587. # Option: DHCP Message Type = ACK
  3588. payload += '\x35\x01\x05'
  3589. # Pad Option
  3590. payload += '\x00'
  3591. # Option: Subnet Mask
  3592. payload += '\x01\x04' + _subnet_mask
  3593. # Option: Time Offset
  3594. payload += struct.pack('>BBL', 2, 4, 0)
  3595. # End Option
  3596. payload += '\xff'
  3597. # Pad Option
  3598. payload += '\x00\x00\x00\x00'
  3599. if no_dhcp:
  3600. payload = struct.pack('>BBBBL3BB', 2, 1, 6, 0, 12345, 0, 0, 0, 0)
  3601. payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192*'\x00'
  3602. udp = struct.pack('>HHHH', 67, 68, 8 + len(payload), 0) + payload
  3603. if force_tot_len:
  3604. tot_len = force_tot_len
  3605. else:
  3606. tot_len = 20 + len(udp)
  3607. start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17)
  3608. ipv4 = start + '\x00\x00' + _ip_src + _ip_dst
  3609. csum = ip_checksum(ipv4)
  3610. ipv4 = start + csum + _ip_src + _ip_dst
  3611. return ehdr + ipv4 + udp
  3612. def build_arp(dst_ll, src_ll, opcode, sender_mac, sender_ip,
  3613. target_mac, target_ip):
  3614. _dst_ll = binascii.unhexlify(dst_ll.replace(':',''))
  3615. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  3616. proto = '\x08\x06'
  3617. ehdr = _dst_ll + _src_ll + proto
  3618. _sender_mac = binascii.unhexlify(sender_mac.replace(':',''))
  3619. _sender_ip = socket.inet_pton(socket.AF_INET, sender_ip)
  3620. _target_mac = binascii.unhexlify(target_mac.replace(':',''))
  3621. _target_ip = socket.inet_pton(socket.AF_INET, target_ip)
  3622. arp = struct.pack('>HHBBH', 1, 0x0800, 6, 4, opcode)
  3623. arp += _sender_mac + _sender_ip
  3624. arp += _target_mac + _target_ip
  3625. return ehdr + arp
  3626. def send_arp(dev, dst_ll="ff:ff:ff:ff:ff:ff", src_ll=None, opcode=1,
  3627. sender_mac=None, sender_ip="0.0.0.0",
  3628. target_mac="00:00:00:00:00:00", target_ip="0.0.0.0",
  3629. hapd_bssid=None):
  3630. if hapd_bssid:
  3631. if src_ll is None:
  3632. src_ll = hapd_bssid
  3633. if sender_mac is None:
  3634. sender_mac = hapd_bssid
  3635. cmd = "DATA_TEST_FRAME ifname=ap-br0 "
  3636. else:
  3637. if src_ll is None:
  3638. src_ll = dev.p2p_interface_addr()
  3639. if sender_mac is None:
  3640. sender_mac = dev.p2p_interface_addr()
  3641. cmd = "DATA_TEST_FRAME "
  3642. pkt = build_arp(dst_ll=dst_ll, src_ll=src_ll, opcode=opcode,
  3643. sender_mac=sender_mac, sender_ip=sender_ip,
  3644. target_mac=target_mac, target_ip=target_ip)
  3645. if "OK" not in dev.request(cmd + binascii.hexlify(pkt)):
  3646. raise Exception("DATA_TEST_FRAME failed")
  3647. def get_permanent_neighbors(ifname):
  3648. cmd = subprocess.Popen(['ip', 'nei'], stdout=subprocess.PIPE)
  3649. res = cmd.stdout.read()
  3650. cmd.stdout.close()
  3651. return [ line for line in res.splitlines() if "PERMANENT" in line and ifname in line ]
  3652. def get_bridge_macs(ifname):
  3653. cmd = subprocess.Popen(['brctl', 'showmacs', ifname],
  3654. stdout=subprocess.PIPE)
  3655. res = cmd.stdout.read()
  3656. cmd.stdout.close()
  3657. return res
  3658. def tshark_get_arp(cap, filter):
  3659. res = run_tshark(cap, filter,
  3660. [ "eth.dst", "eth.src",
  3661. "arp.src.hw_mac", "arp.src.proto_ipv4",
  3662. "arp.dst.hw_mac", "arp.dst.proto_ipv4" ],
  3663. wait=False)
  3664. frames = []
  3665. for l in res.splitlines():
  3666. frames.append(l.split('\t'))
  3667. return frames
  3668. def tshark_get_ns(cap):
  3669. res = run_tshark(cap, "icmpv6.type == 135",
  3670. [ "eth.dst", "eth.src",
  3671. "ipv6.src", "ipv6.dst",
  3672. "icmpv6.nd.ns.target_address",
  3673. "icmpv6.opt.linkaddr" ],
  3674. wait=False)
  3675. frames = []
  3676. for l in res.splitlines():
  3677. frames.append(l.split('\t'))
  3678. return frames
  3679. def tshark_get_na(cap):
  3680. res = run_tshark(cap, "icmpv6.type == 136",
  3681. [ "eth.dst", "eth.src",
  3682. "ipv6.src", "ipv6.dst",
  3683. "icmpv6.nd.na.target_address",
  3684. "icmpv6.opt.linkaddr" ],
  3685. wait=False)
  3686. frames = []
  3687. for l in res.splitlines():
  3688. frames.append(l.split('\t'))
  3689. return frames
  3690. def _test_proxyarp_open(dev, apdev, params, ebtables=False):
  3691. prefix = "proxyarp_open"
  3692. if ebtables:
  3693. prefix += "_ebtables"
  3694. cap_br = os.path.join(params['logdir'], prefix + ".ap-br0.pcap")
  3695. cap_dev0 = os.path.join(params['logdir'],
  3696. prefix + ".%s.pcap" % dev[0].ifname)
  3697. cap_dev1 = os.path.join(params['logdir'],
  3698. prefix + ".%s.pcap" % dev[1].ifname)
  3699. cap_dev2 = os.path.join(params['logdir'],
  3700. prefix + ".%s.pcap" % dev[2].ifname)
  3701. bssid = apdev[0]['bssid']
  3702. params = { 'ssid': 'open' }
  3703. params['proxy_arp'] = '1'
  3704. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  3705. hapd.set("ap_isolate", "1")
  3706. hapd.set('bridge', 'ap-br0')
  3707. hapd.dump_monitor()
  3708. try:
  3709. hapd.enable()
  3710. except:
  3711. # For now, do not report failures due to missing kernel support
  3712. raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version")
  3713. ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=10)
  3714. if ev is None:
  3715. raise Exception("AP startup timed out")
  3716. if "AP-ENABLED" not in ev:
  3717. raise Exception("AP startup failed")
  3718. params2 = { 'ssid': 'another' }
  3719. hapd2 = hostapd.add_ap(apdev[1], params2, no_enable=True)
  3720. hapd2.set('bridge', 'ap-br0')
  3721. hapd2.enable()
  3722. subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
  3723. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  3724. if ebtables:
  3725. for chain in [ 'FORWARD', 'OUTPUT' ]:
  3726. try:
  3727. subprocess.call(['ebtables', '-A', chain, '-p', 'ARP',
  3728. '-d', 'Broadcast', '-o', apdev[0]['ifname'],
  3729. '-j', 'DROP'])
  3730. except:
  3731. raise HwsimSkip("No ebtables available")
  3732. time.sleep(0.5)
  3733. cmd = {}
  3734. cmd[0] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', 'ap-br0',
  3735. '-w', cap_br, '-s', '2000'],
  3736. stderr=open('/dev/null', 'w'))
  3737. cmd[1] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[0].ifname,
  3738. '-w', cap_dev0, '-s', '2000'],
  3739. stderr=open('/dev/null', 'w'))
  3740. cmd[2] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[1].ifname,
  3741. '-w', cap_dev1, '-s', '2000'],
  3742. stderr=open('/dev/null', 'w'))
  3743. cmd[3] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[2].ifname,
  3744. '-w', cap_dev2, '-s', '2000'],
  3745. stderr=open('/dev/null', 'w'))
  3746. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  3747. dev[1].connect("open", key_mgmt="NONE", scan_freq="2412")
  3748. dev[2].connect("another", key_mgmt="NONE", scan_freq="2412")
  3749. time.sleep(0.1)
  3750. brcmd = subprocess.Popen(['brctl', 'show'], stdout=subprocess.PIPE)
  3751. res = brcmd.stdout.read()
  3752. brcmd.stdout.close()
  3753. logger.info("Bridge setup: " + res)
  3754. brcmd = subprocess.Popen(['brctl', 'showstp', 'ap-br0'],
  3755. stdout=subprocess.PIPE)
  3756. res = brcmd.stdout.read()
  3757. brcmd.stdout.close()
  3758. logger.info("Bridge showstp: " + res)
  3759. addr0 = dev[0].p2p_interface_addr()
  3760. addr1 = dev[1].p2p_interface_addr()
  3761. addr2 = dev[2].p2p_interface_addr()
  3762. pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid,
  3763. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  3764. yiaddr="192.168.1.124", chaddr=addr0)
  3765. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  3766. raise Exception("DATA_TEST_FRAME failed")
  3767. # Change address and verify unicast
  3768. pkt = build_dhcp_ack(dst_ll=addr0, src_ll=bssid,
  3769. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  3770. yiaddr="192.168.1.123", chaddr=addr0)
  3771. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  3772. raise Exception("DATA_TEST_FRAME failed")
  3773. # Not-associated client MAC address
  3774. pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid,
  3775. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  3776. yiaddr="192.168.1.125", chaddr="22:33:44:55:66:77")
  3777. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  3778. raise Exception("DATA_TEST_FRAME failed")
  3779. # No IP address
  3780. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  3781. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  3782. yiaddr="0.0.0.0", chaddr=addr1)
  3783. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  3784. raise Exception("DATA_TEST_FRAME failed")
  3785. # Zero subnet mask
  3786. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  3787. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  3788. yiaddr="192.168.1.126", chaddr=addr1,
  3789. subnet_mask="0.0.0.0")
  3790. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  3791. raise Exception("DATA_TEST_FRAME failed")
  3792. # Truncated option
  3793. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  3794. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  3795. yiaddr="192.168.1.127", chaddr=addr1,
  3796. truncated_opt=True)
  3797. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  3798. raise Exception("DATA_TEST_FRAME failed")
  3799. # Wrong magic
  3800. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  3801. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  3802. yiaddr="192.168.1.128", chaddr=addr1,
  3803. wrong_magic=True)
  3804. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  3805. raise Exception("DATA_TEST_FRAME failed")
  3806. # Wrong IPv4 total length
  3807. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  3808. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  3809. yiaddr="192.168.1.129", chaddr=addr1,
  3810. force_tot_len=1000)
  3811. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  3812. raise Exception("DATA_TEST_FRAME failed")
  3813. # BOOTP
  3814. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  3815. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  3816. yiaddr="192.168.1.129", chaddr=addr1,
  3817. no_dhcp=True)
  3818. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  3819. raise Exception("DATA_TEST_FRAME failed")
  3820. macs = get_bridge_macs("ap-br0")
  3821. logger.info("After connect (showmacs): " + str(macs))
  3822. matches = get_permanent_neighbors("ap-br0")
  3823. logger.info("After connect: " + str(matches))
  3824. if len(matches) != 1:
  3825. raise Exception("Unexpected number of neighbor entries after connect")
  3826. if '192.168.1.123 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  3827. raise Exception("dev0 IPv4 addr missing")
  3828. targets = [ "192.168.1.123", "192.168.1.124", "192.168.1.125",
  3829. "192.168.1.126" ]
  3830. for target in targets:
  3831. send_arp(dev[1], sender_ip="192.168.1.100", target_ip=target)
  3832. for target in targets:
  3833. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.101",
  3834. target_ip=target)
  3835. for target in targets:
  3836. send_arp(dev[2], sender_ip="192.168.1.103", target_ip=target)
  3837. # ARP Probe from wireless STA
  3838. send_arp(dev[1], target_ip="192.168.1.127")
  3839. # ARP Announcement from wireless STA
  3840. send_arp(dev[1], sender_ip="192.168.1.127", target_ip="192.168.1.127")
  3841. send_arp(dev[1], sender_ip="192.168.1.127", target_ip="192.168.1.127",
  3842. opcode=2)
  3843. macs = get_bridge_macs("ap-br0")
  3844. logger.info("After ARP Probe + Announcement (showmacs): " + str(macs))
  3845. matches = get_permanent_neighbors("ap-br0")
  3846. logger.info("After ARP Probe + Announcement: " + str(matches))
  3847. # ARP Request for the newly introduced IP address from wireless STA
  3848. send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.127")
  3849. # ARP Request for the newly introduced IP address from bridge
  3850. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.102",
  3851. target_ip="192.168.1.127")
  3852. send_arp(dev[2], sender_ip="192.168.1.103", target_ip="192.168.1.127")
  3853. # ARP Probe from bridge
  3854. send_arp(hapd, hapd_bssid=bssid, target_ip="192.168.1.130")
  3855. send_arp(dev[2], target_ip="192.168.1.131")
  3856. # ARP Announcement from bridge (not to be learned by AP for proxyarp)
  3857. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.130",
  3858. target_ip="192.168.1.130")
  3859. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.130",
  3860. target_ip="192.168.1.130", opcode=2)
  3861. send_arp(dev[2], sender_ip="192.168.1.131", target_ip="192.168.1.131")
  3862. send_arp(dev[2], sender_ip="192.168.1.131", target_ip="192.168.1.131",
  3863. opcode=2)
  3864. macs = get_bridge_macs("ap-br0")
  3865. logger.info("After ARP Probe + Announcement (showmacs): " + str(macs))
  3866. matches = get_permanent_neighbors("ap-br0")
  3867. logger.info("After ARP Probe + Announcement: " + str(matches))
  3868. # ARP Request for the newly introduced IP address from wireless STA
  3869. send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.130")
  3870. # ARP Response from bridge (AP does not proxy for non-wireless devices)
  3871. send_arp(hapd, hapd_bssid=bssid, dst_ll=addr0, sender_ip="192.168.1.130",
  3872. target_ip="192.168.1.123", opcode=2)
  3873. # ARP Request for the newly introduced IP address from wireless STA
  3874. send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.131")
  3875. # ARP Response from bridge (AP does not proxy for non-wireless devices)
  3876. send_arp(dev[2], dst_ll=addr0, sender_ip="192.168.1.131",
  3877. target_ip="192.168.1.123", opcode=2)
  3878. # ARP Request for the newly introduced IP address from bridge
  3879. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.102",
  3880. target_ip="192.168.1.130")
  3881. send_arp(dev[2], sender_ip="192.168.1.104", target_ip="192.168.1.131")
  3882. # ARP Probe from wireless STA (duplicate address; learned through DHCP)
  3883. send_arp(dev[1], target_ip="192.168.1.123")
  3884. # ARP Probe from wireless STA (duplicate address; learned through ARP)
  3885. send_arp(dev[0], target_ip="192.168.1.127")
  3886. # Gratuitous ARP Reply for another STA's IP address
  3887. send_arp(dev[0], opcode=2, sender_mac=addr0, sender_ip="192.168.1.127",
  3888. target_mac=addr1, target_ip="192.168.1.127")
  3889. send_arp(dev[1], opcode=2, sender_mac=addr1, sender_ip="192.168.1.123",
  3890. target_mac=addr0, target_ip="192.168.1.123")
  3891. # ARP Request to verify previous mapping
  3892. send_arp(dev[1], sender_ip="192.168.1.127", target_ip="192.168.1.123")
  3893. send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.127")
  3894. try:
  3895. hwsim_utils.test_connectivity_iface(dev[0], hapd, "ap-br0")
  3896. except Exception, e:
  3897. logger.info("test_connectibity_iface failed: " + str(e))
  3898. raise HwsimSkip("Assume kernel did not have the required patches for proxyarp")
  3899. hwsim_utils.test_connectivity_iface(dev[1], hapd, "ap-br0")
  3900. hwsim_utils.test_connectivity(dev[0], dev[1])
  3901. dev[0].request("DISCONNECT")
  3902. dev[1].request("DISCONNECT")
  3903. time.sleep(0.5)
  3904. for i in range(len(cmd)):
  3905. cmd[i].terminate()
  3906. macs = get_bridge_macs("ap-br0")
  3907. logger.info("After disconnect (showmacs): " + str(macs))
  3908. matches = get_permanent_neighbors("ap-br0")
  3909. logger.info("After disconnect: " + str(matches))
  3910. if len(matches) > 0:
  3911. raise Exception("Unexpected neighbor entries after disconnect")
  3912. if ebtables:
  3913. cmd = subprocess.Popen(['ebtables', '-L', '--Lc'],
  3914. stdout=subprocess.PIPE)
  3915. res = cmd.stdout.read()
  3916. cmd.stdout.close()
  3917. logger.info("ebtables results:\n" + res)
  3918. # Verify that expected ARP messages were seen and no unexpected
  3919. # ARP messages were seen.
  3920. arp_req = tshark_get_arp(cap_dev0, "arp.opcode == 1")
  3921. arp_reply = tshark_get_arp(cap_dev0, "arp.opcode == 2")
  3922. logger.info("dev0 seen ARP requests:\n" + str(arp_req))
  3923. logger.info("dev0 seen ARP replies:\n" + str(arp_reply))
  3924. if [ 'ff:ff:ff:ff:ff:ff', addr1,
  3925. addr1, '192.168.1.100',
  3926. '00:00:00:00:00:00', '192.168.1.123' ] in arp_req:
  3927. raise Exception("dev0 saw ARP request from dev1")
  3928. if [ 'ff:ff:ff:ff:ff:ff', addr2,
  3929. addr2, '192.168.1.103',
  3930. '00:00:00:00:00:00', '192.168.1.123' ] in arp_req:
  3931. raise Exception("dev0 saw ARP request from dev2")
  3932. # TODO: Uncomment once fixed in kernel
  3933. #if [ 'ff:ff:ff:ff:ff:ff', bssid,
  3934. # bssid, '192.168.1.101',
  3935. # '00:00:00:00:00:00', '192.168.1.123' ] in arp_req:
  3936. # raise Exception("dev0 saw ARP request from br")
  3937. if ebtables:
  3938. for req in arp_req:
  3939. if req[1] != addr0:
  3940. raise Exception("Unexpected foreign ARP request on dev0")
  3941. arp_req = tshark_get_arp(cap_dev1, "arp.opcode == 1")
  3942. arp_reply = tshark_get_arp(cap_dev1, "arp.opcode == 2")
  3943. logger.info("dev1 seen ARP requests:\n" + str(arp_req))
  3944. logger.info("dev1 seen ARP replies:\n" + str(arp_reply))
  3945. if [ 'ff:ff:ff:ff:ff:ff', addr2,
  3946. addr2, '192.168.1.103',
  3947. '00:00:00:00:00:00', '192.168.1.123' ] in arp_req:
  3948. raise Exception("dev1 saw ARP request from dev2")
  3949. if [addr1, addr0, addr0, '192.168.1.123', addr1, '192.168.1.100'] not in arp_reply:
  3950. raise Exception("dev1 did not get ARP response for 192.168.1.123")
  3951. if ebtables:
  3952. for req in arp_req:
  3953. if req[1] != addr1:
  3954. raise Exception("Unexpected foreign ARP request on dev1")
  3955. arp_req = tshark_get_arp(cap_dev2, "arp.opcode == 1")
  3956. arp_reply = tshark_get_arp(cap_dev2, "arp.opcode == 2")
  3957. logger.info("dev2 seen ARP requests:\n" + str(arp_req))
  3958. logger.info("dev2 seen ARP replies:\n" + str(arp_reply))
  3959. if [ addr2, addr0,
  3960. addr0, '192.168.1.123',
  3961. addr2, '192.168.1.103' ] not in arp_reply:
  3962. raise Exception("dev2 did not get ARP response for 192.168.1.123")
  3963. arp_req = tshark_get_arp(cap_br, "arp.opcode == 1")
  3964. arp_reply = tshark_get_arp(cap_br, "arp.opcode == 2")
  3965. logger.info("br seen ARP requests:\n" + str(arp_req))
  3966. logger.info("br seen ARP replies:\n" + str(arp_reply))
  3967. # TODO: Uncomment once fixed in kernel
  3968. #if [ bssid, addr0,
  3969. # addr0, '192.168.1.123',
  3970. # bssid, '192.168.1.101' ] not in arp_reply:
  3971. # raise Exception("br did not get ARP response for 192.168.1.123")
  3972. def _test_proxyarp_open_ipv6(dev, apdev, params, ebtables=False):
  3973. prefix = "proxyarp_open"
  3974. if ebtables:
  3975. prefix += "_ebtables"
  3976. cap_br = os.path.join(params['logdir'], prefix + ".ap-br0.pcap")
  3977. cap_dev0 = os.path.join(params['logdir'],
  3978. prefix + ".%s.pcap" % dev[0].ifname)
  3979. cap_dev1 = os.path.join(params['logdir'],
  3980. prefix + ".%s.pcap" % dev[1].ifname)
  3981. cap_dev2 = os.path.join(params['logdir'],
  3982. prefix + ".%s.pcap" % dev[2].ifname)
  3983. bssid = apdev[0]['bssid']
  3984. params = { 'ssid': 'open' }
  3985. params['proxy_arp'] = '1'
  3986. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  3987. hapd.set("ap_isolate", "1")
  3988. hapd.set('bridge', 'ap-br0')
  3989. hapd.dump_monitor()
  3990. try:
  3991. hapd.enable()
  3992. except:
  3993. # For now, do not report failures due to missing kernel support
  3994. raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version")
  3995. ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=10)
  3996. if ev is None:
  3997. raise Exception("AP startup timed out")
  3998. if "AP-ENABLED" not in ev:
  3999. raise Exception("AP startup failed")
  4000. params2 = { 'ssid': 'another' }
  4001. hapd2 = hostapd.add_ap(apdev[1], params2, no_enable=True)
  4002. hapd2.set('bridge', 'ap-br0')
  4003. hapd2.enable()
  4004. subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
  4005. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  4006. if ebtables:
  4007. for chain in [ 'FORWARD', 'OUTPUT' ]:
  4008. try:
  4009. subprocess.call(['ebtables', '-A', chain, '-d', 'Multicast',
  4010. '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp',
  4011. '--ip6-icmp-type', 'neighbor-solicitation',
  4012. '-o', apdev[0]['ifname'], '-j', 'DROP'])
  4013. subprocess.call(['ebtables', '-A', chain, '-d', 'Multicast',
  4014. '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp',
  4015. '--ip6-icmp-type', 'neighbor-advertisement',
  4016. '-o', apdev[0]['ifname'], '-j', 'DROP'])
  4017. subprocess.call(['ebtables', '-A', chain,
  4018. '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp',
  4019. '--ip6-icmp-type', 'router-solicitation',
  4020. '-o', apdev[0]['ifname'], '-j', 'DROP'])
  4021. # Multicast Listener Report Message
  4022. subprocess.call(['ebtables', '-A', chain, '-d', 'Multicast',
  4023. '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp',
  4024. '--ip6-icmp-type', '143',
  4025. '-o', apdev[0]['ifname'], '-j', 'DROP'])
  4026. except:
  4027. raise HwsimSkip("No ebtables available")
  4028. time.sleep(0.5)
  4029. cmd = {}
  4030. cmd[0] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', 'ap-br0',
  4031. '-w', cap_br, '-s', '2000'],
  4032. stderr=open('/dev/null', 'w'))
  4033. cmd[1] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[0].ifname,
  4034. '-w', cap_dev0, '-s', '2000'],
  4035. stderr=open('/dev/null', 'w'))
  4036. cmd[2] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[1].ifname,
  4037. '-w', cap_dev1, '-s', '2000'],
  4038. stderr=open('/dev/null', 'w'))
  4039. cmd[3] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[2].ifname,
  4040. '-w', cap_dev2, '-s', '2000'],
  4041. stderr=open('/dev/null', 'w'))
  4042. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  4043. dev[1].connect("open", key_mgmt="NONE", scan_freq="2412")
  4044. dev[2].connect("another", key_mgmt="NONE", scan_freq="2412")
  4045. time.sleep(0.1)
  4046. brcmd = subprocess.Popen(['brctl', 'show'], stdout=subprocess.PIPE)
  4047. res = brcmd.stdout.read()
  4048. brcmd.stdout.close()
  4049. logger.info("Bridge setup: " + res)
  4050. brcmd = subprocess.Popen(['brctl', 'showstp', 'ap-br0'],
  4051. stdout=subprocess.PIPE)
  4052. res = brcmd.stdout.read()
  4053. brcmd.stdout.close()
  4054. logger.info("Bridge showstp: " + res)
  4055. addr0 = dev[0].p2p_interface_addr()
  4056. addr1 = dev[1].p2p_interface_addr()
  4057. addr2 = dev[2].p2p_interface_addr()
  4058. src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':',''))
  4059. src_ll_opt1 = "\x01\x01" + binascii.unhexlify(addr1.replace(':',''))
  4060. # DAD NS
  4061. send_ns(dev[0], ip_src="::", target="aaaa:bbbb:cccc::2")
  4062. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2")
  4063. # test frame without source link-layer address option
  4064. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2",
  4065. opt='')
  4066. # test frame with bogus option
  4067. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2",
  4068. opt="\x70\x01\x01\x02\x03\x04\x05\x05")
  4069. # test frame with truncated source link-layer address option
  4070. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2",
  4071. opt="\x01\x01\x01\x02\x03\x04")
  4072. # test frame with foreign source link-layer address option
  4073. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2",
  4074. opt="\x01\x01\x01\x02\x03\x04\x05\x06")
  4075. send_ns(dev[1], ip_src="aaaa:bbbb:dddd::2", target="aaaa:bbbb:dddd::2")
  4076. send_ns(dev[1], ip_src="aaaa:bbbb:eeee::2", target="aaaa:bbbb:eeee::2")
  4077. # another copy for additional code coverage
  4078. send_ns(dev[1], ip_src="aaaa:bbbb:eeee::2", target="aaaa:bbbb:eeee::2")
  4079. macs = get_bridge_macs("ap-br0")
  4080. logger.info("After connect (showmacs): " + str(macs))
  4081. matches = get_permanent_neighbors("ap-br0")
  4082. logger.info("After connect: " + str(matches))
  4083. if len(matches) != 3:
  4084. raise Exception("Unexpected number of neighbor entries after connect")
  4085. if 'aaaa:bbbb:cccc::2 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  4086. raise Exception("dev0 addr missing")
  4087. if 'aaaa:bbbb:dddd::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches:
  4088. raise Exception("dev1 addr(1) missing")
  4089. if 'aaaa:bbbb:eeee::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches:
  4090. raise Exception("dev1 addr(2) missing")
  4091. send_ns(dev[0], target="aaaa:bbbb:dddd::2", ip_src="aaaa:bbbb:cccc::2")
  4092. time.sleep(0.1)
  4093. send_ns(dev[1], target="aaaa:bbbb:cccc::2", ip_src="aaaa:bbbb:dddd::2")
  4094. time.sleep(0.1)
  4095. send_ns(hapd, hapd_bssid=bssid, target="aaaa:bbbb:dddd::2",
  4096. ip_src="aaaa:bbbb:ffff::2")
  4097. time.sleep(0.1)
  4098. send_ns(dev[2], target="aaaa:bbbb:cccc::2", ip_src="aaaa:bbbb:ff00::2")
  4099. time.sleep(0.1)
  4100. send_ns(dev[2], target="aaaa:bbbb:dddd::2", ip_src="aaaa:bbbb:ff00::2")
  4101. time.sleep(0.1)
  4102. send_ns(dev[2], target="aaaa:bbbb:eeee::2", ip_src="aaaa:bbbb:ff00::2")
  4103. time.sleep(0.1)
  4104. # Try to probe for an already assigned address
  4105. send_ns(dev[1], target="aaaa:bbbb:cccc::2", ip_src="::")
  4106. time.sleep(0.1)
  4107. send_ns(hapd, hapd_bssid=bssid, target="aaaa:bbbb:cccc::2", ip_src="::")
  4108. time.sleep(0.1)
  4109. send_ns(dev[2], target="aaaa:bbbb:cccc::2", ip_src="::")
  4110. time.sleep(0.1)
  4111. # Unsolicited NA
  4112. send_na(dev[1], target="aaaa:bbbb:cccc:aeae::3",
  4113. ip_src="aaaa:bbbb:cccc:aeae::3", ip_dst="ff02::1")
  4114. send_na(hapd, hapd_bssid=bssid, target="aaaa:bbbb:cccc:aeae::4",
  4115. ip_src="aaaa:bbbb:cccc:aeae::4", ip_dst="ff02::1")
  4116. send_na(dev[2], target="aaaa:bbbb:cccc:aeae::5",
  4117. ip_src="aaaa:bbbb:cccc:aeae::5", ip_dst="ff02::1")
  4118. try:
  4119. hwsim_utils.test_connectivity_iface(dev[0], hapd, "ap-br0")
  4120. except Exception, e:
  4121. logger.info("test_connectibity_iface failed: " + str(e))
  4122. raise HwsimSkip("Assume kernel did not have the required patches for proxyarp")
  4123. hwsim_utils.test_connectivity_iface(dev[1], hapd, "ap-br0")
  4124. hwsim_utils.test_connectivity(dev[0], dev[1])
  4125. dev[0].request("DISCONNECT")
  4126. dev[1].request("DISCONNECT")
  4127. time.sleep(0.5)
  4128. for i in range(len(cmd)):
  4129. cmd[i].terminate()
  4130. macs = get_bridge_macs("ap-br0")
  4131. logger.info("After disconnect (showmacs): " + str(macs))
  4132. matches = get_permanent_neighbors("ap-br0")
  4133. logger.info("After disconnect: " + str(matches))
  4134. if len(matches) > 0:
  4135. raise Exception("Unexpected neighbor entries after disconnect")
  4136. if ebtables:
  4137. cmd = subprocess.Popen(['ebtables', '-L', '--Lc'],
  4138. stdout=subprocess.PIPE)
  4139. res = cmd.stdout.read()
  4140. cmd.stdout.close()
  4141. logger.info("ebtables results:\n" + res)
  4142. ns = tshark_get_ns(cap_dev0)
  4143. logger.info("dev0 seen NS: " + str(ns))
  4144. na = tshark_get_na(cap_dev0)
  4145. logger.info("dev0 seen NA: " + str(na))
  4146. if [ addr0, addr1, 'aaaa:bbbb:dddd::2', 'aaaa:bbbb:cccc::2',
  4147. 'aaaa:bbbb:dddd::2', addr1 ] not in na:
  4148. # For now, skip the test instead of reporting the error since the IPv6
  4149. # proxyarp support is not yet in the upstream kernel tree.
  4150. #raise Exception("dev0 did not get NA for aaaa:bbbb:dddd::2")
  4151. raise HwsimSkip("Assume kernel did not have the required patches for proxyarp (IPv6)")
  4152. if ebtables:
  4153. for req in ns:
  4154. if req[1] != addr0:
  4155. raise Exception("Unexpected foreign NS on dev0: " + str(req))
  4156. ns = tshark_get_ns(cap_dev1)
  4157. logger.info("dev1 seen NS: " + str(ns))
  4158. na = tshark_get_na(cap_dev1)
  4159. logger.info("dev1 seen NA: " + str(na))
  4160. if [ addr1, addr0, 'aaaa:bbbb:cccc::2', 'aaaa:bbbb:dddd::2',
  4161. 'aaaa:bbbb:cccc::2', addr0 ] not in na:
  4162. raise Exception("dev1 did not get NA for aaaa:bbbb:cccc::2")
  4163. if ebtables:
  4164. for req in ns:
  4165. if req[1] != addr1:
  4166. raise Exception("Unexpected foreign NS on dev1: " + str(req))
  4167. ns = tshark_get_ns(cap_dev2)
  4168. logger.info("dev2 seen NS: " + str(ns))
  4169. na = tshark_get_na(cap_dev2)
  4170. logger.info("dev2 seen NA: " + str(na))
  4171. # FIX: enable once kernel implementation for proxyarp IPv6 is fixed
  4172. #if [ addr2, addr0, 'aaaa:bbbb:cccc::2', 'aaaa:bbbb:ff00::2',
  4173. # 'aaaa:bbbb:cccc::2', addr0 ] not in na:
  4174. # raise Exception("dev2 did not get NA for aaaa:bbbb:cccc::2")
  4175. #if [ addr2, addr1, 'aaaa:bbbb:dddd::2', 'aaaa:bbbb:ff00::2',
  4176. # 'aaaa:bbbb:dddd::2', addr1 ] not in na:
  4177. # raise Exception("dev2 did not get NA for aaaa:bbbb:dddd::2")
  4178. #if [ addr2, addr1, 'aaaa:bbbb:eeee::2', 'aaaa:bbbb:ff00::2',
  4179. # 'aaaa:bbbb:eeee::2', addr1 ] not in na:
  4180. # raise Exception("dev2 did not get NA for aaaa:bbbb:eeee::2")
  4181. def test_proxyarp_open(dev, apdev, params):
  4182. """ProxyARP with open network"""
  4183. try:
  4184. _test_proxyarp_open(dev, apdev, params)
  4185. finally:
  4186. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  4187. stderr=open('/dev/null', 'w'))
  4188. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  4189. stderr=open('/dev/null', 'w'))
  4190. def test_proxyarp_open_ipv6(dev, apdev, params):
  4191. """ProxyARP with open network (IPv6)"""
  4192. try:
  4193. _test_proxyarp_open_ipv6(dev, apdev, params)
  4194. finally:
  4195. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  4196. stderr=open('/dev/null', 'w'))
  4197. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  4198. stderr=open('/dev/null', 'w'))
  4199. def test_proxyarp_open_ebtables(dev, apdev, params):
  4200. """ProxyARP with open network"""
  4201. try:
  4202. _test_proxyarp_open(dev, apdev, params, ebtables=True)
  4203. finally:
  4204. try:
  4205. subprocess.call(['ebtables', '-F', 'FORWARD'])
  4206. subprocess.call(['ebtables', '-F', 'OUTPUT'])
  4207. except:
  4208. pass
  4209. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  4210. stderr=open('/dev/null', 'w'))
  4211. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  4212. stderr=open('/dev/null', 'w'))
  4213. def test_proxyarp_open_ebtables_ipv6(dev, apdev, params):
  4214. """ProxyARP with open network (IPv6)"""
  4215. try:
  4216. _test_proxyarp_open_ipv6(dev, apdev, params, ebtables=True)
  4217. finally:
  4218. try:
  4219. subprocess.call(['ebtables', '-F', 'FORWARD'])
  4220. subprocess.call(['ebtables', '-F', 'OUTPUT'])
  4221. except:
  4222. pass
  4223. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  4224. stderr=open('/dev/null', 'w'))
  4225. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  4226. stderr=open('/dev/null', 'w'))
  4227. def test_proxyarp_errors(dev, apdev, params):
  4228. """ProxyARP error cases"""
  4229. try:
  4230. run_proxyarp_errors(dev, apdev, params)
  4231. finally:
  4232. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  4233. stderr=open('/dev/null', 'w'))
  4234. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  4235. stderr=open('/dev/null', 'w'))
  4236. def run_proxyarp_errors(dev, apdev, params):
  4237. params = { 'ssid': 'open',
  4238. 'proxy_arp': '1',
  4239. 'ap_isolate': '1',
  4240. 'bridge': 'ap-br0',
  4241. 'disable_dgaf': '1' }
  4242. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  4243. try:
  4244. hapd.enable()
  4245. except:
  4246. # For now, do not report failures due to missing kernel support
  4247. raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version")
  4248. ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=10)
  4249. if ev is None:
  4250. raise Exception("AP startup timed out")
  4251. if "AP-ENABLED" not in ev:
  4252. raise Exception("AP startup failed")
  4253. hapd.disable()
  4254. with alloc_fail(hapd, 1, "l2_packet_init;x_snoop_get_l2_packet;dhcp_snoop_init"):
  4255. if "FAIL" not in hapd.request("ENABLE"):
  4256. raise Exception("ENABLE accepted unexpectedly")
  4257. with alloc_fail(hapd, 1, "l2_packet_init;x_snoop_get_l2_packet;ndisc_snoop_init"):
  4258. if "FAIL" not in hapd.request("ENABLE"):
  4259. raise Exception("ENABLE accepted unexpectedly")
  4260. with fail_test(hapd, 1, "l2_packet_set_packet_filter;x_snoop_get_l2_packet;ndisc_snoop_init"):
  4261. if "FAIL" not in hapd.request("ENABLE"):
  4262. raise Exception("ENABLE accepted unexpectedly")
  4263. with fail_test(hapd, 1, "l2_packet_set_packet_filter;x_snoop_get_l2_packet;dhcp_snoop_init"):
  4264. if "FAIL" not in hapd.request("ENABLE"):
  4265. raise Exception("ENABLE accepted unexpectedly")
  4266. hapd.enable()
  4267. subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
  4268. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  4269. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  4270. addr0 = dev[0].own_addr()
  4271. pkt = build_ra(src_ll=apdev[0]['bssid'], ip_src="aaaa:bbbb:cccc::33",
  4272. ip_dst="ff01::1")
  4273. with fail_test(hapd, 1, "x_snoop_mcast_to_ucast_convert_send"):
  4274. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  4275. raise Exception("DATA_TEST_FRAME failed")
  4276. wait_fail_trigger(dev[0], "GET_FAIL")
  4277. with alloc_fail(hapd, 1, "sta_ip6addr_add"):
  4278. src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':',''))
  4279. pkt = build_ns(src_ll=addr0, ip_src="aaaa:bbbb:cccc::2",
  4280. ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:cccc::2",
  4281. opt=src_ll_opt0)
  4282. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  4283. raise Exception("DATA_TEST_FRAME failed")
  4284. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4285. def test_ap_hs20_connect_deinit(dev, apdev):
  4286. """Hotspot 2.0 connection interrupted with deinit"""
  4287. check_eap_capa(dev[0], "MSCHAPV2")
  4288. bssid = apdev[0]['bssid']
  4289. params = hs20_ap_params()
  4290. params['hessid'] = bssid
  4291. hapd = hostapd.add_ap(apdev[0], params)
  4292. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  4293. wpas.interface_add("wlan5", drv_params="")
  4294. wpas.hs20_enable()
  4295. wpas.flush_scan_cache()
  4296. wpas.add_cred_values({ 'realm': "example.com",
  4297. 'username': "hs20-test",
  4298. 'password': "password",
  4299. 'ca_cert': "auth_serv/ca.pem",
  4300. 'domain': "example.com" })
  4301. wpas.scan_for_bss(bssid, freq=2412)
  4302. hapd.disable()
  4303. wpas.request("INTERWORKING_SELECT freq=2412")
  4304. id = wpas.request("RADIO_WORK add block-work")
  4305. ev = wpas.wait_event(["GAS-QUERY-START", "EXT-RADIO-WORK-START"], timeout=5)
  4306. if ev is None:
  4307. raise Exception("Timeout while waiting radio work to start")
  4308. ev = wpas.wait_event(["GAS-QUERY-START", "EXT-RADIO-WORK-START"], timeout=5)
  4309. if ev is None:
  4310. raise Exception("Timeout while waiting radio work to start (2)")
  4311. # Remove the interface while the gas-query radio work is still pending and
  4312. # GAS query has not yet been started.
  4313. wpas.interface_remove("wlan5")
  4314. def test_ap_hs20_anqp_format_errors(dev, apdev):
  4315. """Interworking network selection and ANQP format errors"""
  4316. bssid = apdev[0]['bssid']
  4317. params = hs20_ap_params()
  4318. params['hessid'] = bssid
  4319. hapd = hostapd.add_ap(apdev[0], params)
  4320. dev[0].hs20_enable()
  4321. values = { 'realm': "example.com",
  4322. 'ca_cert': "auth_serv/ca.pem",
  4323. 'username': "hs20-test",
  4324. 'password': "password",
  4325. 'domain': "example.com" }
  4326. id = dev[0].add_cred_values(values)
  4327. dev[0].scan_for_bss(bssid, freq="2412")
  4328. tests = [ "00", "ffff", "010011223344", "020008000005112233445500",
  4329. "01000400000000", "01000000000000",
  4330. "01000300000200", "0100040000ff0000", "01000300000100",
  4331. "01000300000001",
  4332. "01000600000056112233",
  4333. "01000900000002050001000111",
  4334. "01000600000001000000", "01000600000001ff0000",
  4335. "01000600000001020001",
  4336. "010008000000010400010001", "0100080000000104000100ff",
  4337. "010011000000010d00050200020100030005000600",
  4338. "0000" ]
  4339. for t in tests:
  4340. hapd.set("anqp_elem", "263:" + t)
  4341. dev[0].request("INTERWORKING_SELECT freq=2412")
  4342. ev = dev[0].wait_event(["INTERWORKING-NO-MATCH"], timeout=5)
  4343. if ev is None:
  4344. raise Exception("Network selection timed out")
  4345. dev[0].dump_monitor()
  4346. dev[0].remove_cred(id)
  4347. id = dev[0].add_cred_values({ 'imsi': "555444-333222111", 'eap': "AKA",
  4348. 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123"})
  4349. tests = [ "00", "0100", "0001", "00ff", "000200ff", "0003000101",
  4350. "00020100" ]
  4351. for t in tests:
  4352. hapd.set("anqp_elem", "264:" + t)
  4353. dev[0].request("INTERWORKING_SELECT freq=2412")
  4354. ev = dev[0].wait_event(["INTERWORKING-NO-MATCH"], timeout=5)
  4355. if ev is None:
  4356. raise Exception("Network selection timed out")
  4357. dev[0].dump_monitor()
  4358. def test_ap_hs20_cred_with_nai_realm(dev, apdev):
  4359. """Hotspot 2.0 network selection and cred_with_nai_realm cred->realm"""
  4360. bssid = apdev[0]['bssid']
  4361. params = hs20_ap_params()
  4362. params['hessid'] = bssid
  4363. hostapd.add_ap(apdev[0], params)
  4364. dev[0].hs20_enable()
  4365. id = dev[0].add_cred_values({ 'realm': "example.com",
  4366. 'username': "test",
  4367. 'password': "secret",
  4368. 'domain': "example.com",
  4369. 'eap': 'TTLS' })
  4370. interworking_select(dev[0], bssid, "home", freq=2412)
  4371. dev[0].remove_cred(id)
  4372. id = dev[0].add_cred_values({ 'realm': "foo.com",
  4373. 'username': "test",
  4374. 'password': "secret",
  4375. 'domain': "example.com",
  4376. 'roaming_consortium': "112234",
  4377. 'eap': 'TTLS' })
  4378. interworking_select(dev[0], bssid, "home", freq=2412, no_match=True)
  4379. dev[0].remove_cred(id)
  4380. def test_ap_hs20_cred_and_no_roaming_consortium(dev, apdev):
  4381. """Hotspot 2.0 network selection and no roaming consortium"""
  4382. bssid = apdev[0]['bssid']
  4383. params = hs20_ap_params()
  4384. params['hessid'] = bssid
  4385. del params['roaming_consortium']
  4386. hostapd.add_ap(apdev[0], params)
  4387. dev[0].hs20_enable()
  4388. id = dev[0].add_cred_values({ 'realm': "example.com",
  4389. 'username': "test",
  4390. 'password': "secret",
  4391. 'domain': "example.com",
  4392. 'roaming_consortium': "112234",
  4393. 'eap': 'TTLS' })
  4394. interworking_select(dev[0], bssid, "home", freq=2412, no_match=True)
  4395. def test_ap_hs20_interworking_oom(dev, apdev):
  4396. """Hotspot 2.0 network selection and OOM"""
  4397. bssid = apdev[0]['bssid']
  4398. params = hs20_ap_params()
  4399. params['hessid'] = bssid
  4400. params['nai_realm'] = [ "0,no.match.here;example.com;no.match.here.either,21[2:1][5:7]",
  4401. "0,example.com,13[5:6],21[2:4][5:7]",
  4402. "0,another.example.com" ]
  4403. hostapd.add_ap(apdev[0], params)
  4404. dev[0].hs20_enable()
  4405. id = dev[0].add_cred_values({ 'realm': "example.com",
  4406. 'username': "test",
  4407. 'password': "secret",
  4408. 'domain': "example.com",
  4409. 'eap': 'TTLS' })
  4410. dev[0].scan_for_bss(bssid, freq="2412")
  4411. funcs = [ "wpabuf_alloc;interworking_anqp_send_req",
  4412. "anqp_build_req;interworking_anqp_send_req",
  4413. "gas_query_req;interworking_anqp_send_req",
  4414. "dup_binstr;nai_realm_parse_realm",
  4415. "=nai_realm_parse_realm",
  4416. "=nai_realm_parse",
  4417. "=nai_realm_match" ]
  4418. for func in funcs:
  4419. with alloc_fail(dev[0], 1, func):
  4420. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  4421. ev = dev[0].wait_event(["Starting ANQP"], timeout=5)
  4422. if ev is None:
  4423. raise Exception("ANQP did not start")
  4424. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4425. def test_ap_hs20_no_cred_connect(dev, apdev):
  4426. """Hotspot 2.0 and connect attempt without credential"""
  4427. bssid = apdev[0]['bssid']
  4428. params = hs20_ap_params()
  4429. params['hessid'] = bssid
  4430. hapd = hostapd.add_ap(apdev[0], params)
  4431. dev[0].hs20_enable()
  4432. dev[0].scan_for_bss(bssid, freq="2412")
  4433. if "FAIL" not in dev[0].request("INTERWORKING_CONNECT " + bssid):
  4434. raise Exception("Unexpected INTERWORKING_CONNECT success")
  4435. def test_ap_hs20_no_rsn_connect(dev, apdev):
  4436. """Hotspot 2.0 and connect attempt without RSN"""
  4437. bssid = apdev[0]['bssid']
  4438. params = hostapd.wpa_params(ssid="test-hs20")
  4439. params['wpa_key_mgmt'] = "WPA-EAP"
  4440. params['ieee80211w'] = "1"
  4441. params['ieee8021x'] = "1"
  4442. params['auth_server_addr'] = "127.0.0.1"
  4443. params['auth_server_port'] = "1812"
  4444. params['auth_server_shared_secret'] = "radius"
  4445. params['interworking'] = "1"
  4446. params['roaming_consortium'] = [ "112233", "1020304050", "010203040506",
  4447. "fedcba" ]
  4448. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]",
  4449. "0,another.example.com" ]
  4450. hapd = hostapd.add_ap(apdev[0], params)
  4451. dev[0].hs20_enable()
  4452. dev[0].scan_for_bss(bssid, freq="2412")
  4453. id = dev[0].add_cred_values({ 'realm': "example.com",
  4454. 'username': "test",
  4455. 'password': "secret",
  4456. 'domain': "example.com",
  4457. 'roaming_consortium': "112233",
  4458. 'eap': 'TTLS' })
  4459. interworking_select(dev[0], bssid, freq=2412, no_match=True)
  4460. if "FAIL" not in dev[0].request("INTERWORKING_CONNECT " + bssid):
  4461. raise Exception("Unexpected INTERWORKING_CONNECT success")
  4462. def test_ap_hs20_no_match_connect(dev, apdev):
  4463. """Hotspot 2.0 and connect attempt without matching cred"""
  4464. bssid = apdev[0]['bssid']
  4465. params = hs20_ap_params()
  4466. hapd = hostapd.add_ap(apdev[0], params)
  4467. dev[0].hs20_enable()
  4468. dev[0].scan_for_bss(bssid, freq="2412")
  4469. id = dev[0].add_cred_values({ 'realm': "example.org",
  4470. 'username': "test",
  4471. 'password': "secret",
  4472. 'domain': "example.org",
  4473. 'roaming_consortium': "112234",
  4474. 'eap': 'TTLS' })
  4475. interworking_select(dev[0], bssid, freq=2412, no_match=True)
  4476. if "FAIL" not in dev[0].request("INTERWORKING_CONNECT " + bssid):
  4477. raise Exception("Unexpected INTERWORKING_CONNECT success")
  4478. def test_ap_hs20_multiple_home_cred(dev, apdev):
  4479. """Hotspot 2.0 and select with multiple matching home credentials"""
  4480. bssid = apdev[0]['bssid']
  4481. params = hs20_ap_params()
  4482. params['hessid'] = bssid
  4483. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]" ]
  4484. params['domain_name'] = "example.com"
  4485. hapd = hostapd.add_ap(apdev[0], params)
  4486. bssid2 = apdev[1]['bssid']
  4487. params = hs20_ap_params(ssid="test-hs20-other")
  4488. params['hessid'] = bssid2
  4489. params['nai_realm'] = [ "0,example.org,13[5:6],21[2:4][5:7]" ]
  4490. params['domain_name'] = "example.org"
  4491. hapd2 = hostapd.add_ap(apdev[1], params)
  4492. dev[0].hs20_enable()
  4493. dev[0].scan_for_bss(bssid2, freq="2412")
  4494. dev[0].scan_for_bss(bssid, freq="2412")
  4495. id = dev[0].add_cred_values({ 'realm': "example.com",
  4496. 'priority': '2',
  4497. 'username': "hs20-test",
  4498. 'password': "password",
  4499. 'domain': "example.com" })
  4500. id2 = dev[0].add_cred_values({ 'realm': "example.org",
  4501. 'priority': '3',
  4502. 'username': "hs20-test",
  4503. 'password': "password",
  4504. 'domain': "example.org" })
  4505. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  4506. ev = dev[0].wait_connected(timeout=15)
  4507. if bssid2 not in ev:
  4508. raise Exception("Connected to incorrect network")
  4509. def test_ap_hs20_anqp_invalid_gas_response(dev, apdev):
  4510. """Hotspot 2.0 network selection and invalid GAS response"""
  4511. bssid = apdev[0]['bssid']
  4512. params = hs20_ap_params()
  4513. params['hessid'] = bssid
  4514. hapd = hostapd.add_ap(apdev[0], params)
  4515. dev[0].scan_for_bss(bssid, freq="2412")
  4516. hapd.set("ext_mgmt_frame_handling", "1")
  4517. dev[0].hs20_enable()
  4518. id = dev[0].add_cred_values({ 'realm': "example.com",
  4519. 'username': "test",
  4520. 'password': "secret",
  4521. 'domain': "example.com",
  4522. 'roaming_consortium': "112234",
  4523. 'eap': 'TTLS' })
  4524. dev[0].request("INTERWORKING_SELECT freq=2412")
  4525. query = gas_rx(hapd)
  4526. gas = parse_gas(query['payload'])
  4527. logger.info("ANQP: Unexpected Advertisement Protocol in response")
  4528. resp = action_response(query)
  4529. adv_proto = struct.pack('8B', 108, 6, 127, 0xdd, 0x00, 0x11, 0x22, 0x33)
  4530. data = struct.pack('<H', 0)
  4531. resp['payload'] = struct.pack('<BBBHH', ACTION_CATEG_PUBLIC,
  4532. GAS_INITIAL_RESPONSE,
  4533. gas['dialog_token'], 0, 0) + adv_proto + data
  4534. send_gas_resp(hapd, resp)
  4535. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=5)
  4536. if ev is None:
  4537. raise Exception("No ANQP-QUERY-DONE seen")
  4538. if "result=INVALID_FRAME" not in ev:
  4539. raise Exception("Unexpected result: " + ev)
  4540. dev[0].request("INTERWORKING_SELECT freq=2412")
  4541. query = gas_rx(hapd)
  4542. gas = parse_gas(query['payload'])
  4543. logger.info("ANQP: Invalid element length for Info ID 1234")
  4544. resp = action_response(query)
  4545. adv_proto = struct.pack('BBBB', 108, 2, 127, 0)
  4546. elements = struct.pack('<HH', 1234, 1)
  4547. data = struct.pack('<H', len(elements)) + elements
  4548. resp['payload'] = struct.pack('<BBBHH', ACTION_CATEG_PUBLIC,
  4549. GAS_INITIAL_RESPONSE,
  4550. gas['dialog_token'], 0, 0) + adv_proto + data
  4551. send_gas_resp(hapd, resp)
  4552. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=5)
  4553. if ev is None:
  4554. raise Exception("No ANQP-QUERY-DONE seen")
  4555. if "result=INVALID_FRAME" not in ev:
  4556. raise Exception("Unexpected result: " + ev)
  4557. with alloc_fail(dev[0], 1, "=anqp_add_extra"):
  4558. dev[0].request("INTERWORKING_SELECT freq=2412")
  4559. query = gas_rx(hapd)
  4560. gas = parse_gas(query['payload'])
  4561. resp = action_response(query)
  4562. elements = struct.pack('<HHHH', 1, 0, 1, 0)
  4563. data = struct.pack('<H', len(elements)) + elements
  4564. resp['payload'] = struct.pack('<BBBHH', ACTION_CATEG_PUBLIC,
  4565. GAS_INITIAL_RESPONSE,
  4566. gas['dialog_token'], 0, 0) + adv_proto + data
  4567. send_gas_resp(hapd, resp)
  4568. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=5)
  4569. if ev is None:
  4570. raise Exception("No ANQP-QUERY-DONE seen")
  4571. if "result=SUCCESS" not in ev:
  4572. raise Exception("Unexpected result: " + ev)
  4573. with alloc_fail(dev[0], 1, "wpabuf_alloc_copy;anqp_add_extra"):
  4574. dev[0].request("INTERWORKING_SELECT freq=2412")
  4575. query = gas_rx(hapd)
  4576. gas = parse_gas(query['payload'])
  4577. resp = action_response(query)
  4578. elements = struct.pack('<HHHH', 1, 0, 1, 0)
  4579. data = struct.pack('<H', len(elements)) + elements
  4580. resp['payload'] = struct.pack('<BBBHH', ACTION_CATEG_PUBLIC,
  4581. GAS_INITIAL_RESPONSE,
  4582. gas['dialog_token'], 0, 0) + adv_proto + data
  4583. send_gas_resp(hapd, resp)
  4584. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=5)
  4585. if ev is None:
  4586. raise Exception("No ANQP-QUERY-DONE seen")
  4587. if "result=SUCCESS" not in ev:
  4588. raise Exception("Unexpected result: " + ev)
  4589. tests = [ struct.pack('<HH', 0xdddd, 0),
  4590. struct.pack('<HH3B', 0xdddd, 3, 0x50, 0x6f, 0x9a),
  4591. struct.pack('<HH4B', 0xdddd, 4, 0x50, 0x6f, 0x9a, 0),
  4592. struct.pack('<HH4B', 0xdddd, 4, 0x11, 0x22, 0x33, 0),
  4593. struct.pack('<HHHH', 1, 0, 1, 0) ]
  4594. for elements in tests:
  4595. dev[0].request("INTERWORKING_SELECT freq=2412")
  4596. query = gas_rx(hapd)
  4597. gas = parse_gas(query['payload'])
  4598. resp = action_response(query)
  4599. data = struct.pack('<H', len(elements)) + elements
  4600. resp['payload'] = struct.pack('<BBBHH', ACTION_CATEG_PUBLIC,
  4601. GAS_INITIAL_RESPONSE,
  4602. gas['dialog_token'], 0, 0) + adv_proto + data
  4603. send_gas_resp(hapd, resp)
  4604. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=5)
  4605. if ev is None:
  4606. raise Exception("No ANQP-QUERY-DONE seen")
  4607. if "result=SUCCESS" not in ev:
  4608. raise Exception("Unexpected result: " + ev)
  4609. def test_ap_hs20_set_profile_failures(dev, apdev):
  4610. """Hotspot 2.0 and failures during profile configuration"""
  4611. bssid = apdev[0]['bssid']
  4612. params = hs20_ap_params()
  4613. params['hessid'] = bssid
  4614. params['anqp_3gpp_cell_net'] = "555,444"
  4615. hapd = hostapd.add_ap(apdev[0], params)
  4616. dev[0].hs20_enable()
  4617. dev[0].scan_for_bss(bssid, freq="2412")
  4618. id = dev[0].add_cred_values({ 'realm': "example.com",
  4619. 'domain': "example.com",
  4620. 'username': "test",
  4621. 'password': "secret",
  4622. 'eap': 'TTLS' })
  4623. interworking_select(dev[0], bssid, "home", freq=2412)
  4624. dev[0].dump_monitor()
  4625. dev[0].request("NOTE ssid->eap.eap_methods = os_malloc()")
  4626. with alloc_fail(dev[0], 1, "interworking_set_eap_params"):
  4627. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4628. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4629. dev[0].remove_cred(id)
  4630. id = dev[0].add_cred_values({ 'realm': "example.com",
  4631. 'domain': "example.com",
  4632. 'username': "hs20-test-with-domain@example.com",
  4633. 'password': "password" })
  4634. interworking_select(dev[0], bssid, "home", freq=2412)
  4635. dev[0].dump_monitor()
  4636. dev[0].request("NOTE anon = os_malloc()")
  4637. with alloc_fail(dev[0], 1, "interworking_set_eap_params"):
  4638. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4639. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4640. dev[0].request("NOTE Successful connection with cred->username including realm")
  4641. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4642. dev[0].wait_connected()
  4643. dev[0].remove_cred(id)
  4644. dev[0].wait_disconnected()
  4645. id = dev[0].add_cred_values({ 'realm': "example.com",
  4646. 'domain': "example.com",
  4647. 'username': "hs20-test",
  4648. 'password': "password" })
  4649. interworking_select(dev[0], bssid, "home", freq=2412)
  4650. dev[0].dump_monitor()
  4651. dev[0].request("NOTE anon = os_malloc() (second)")
  4652. with alloc_fail(dev[0], 1, "interworking_set_eap_params"):
  4653. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4654. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4655. with alloc_fail(dev[0], 1, "wpa_config_add_network;interworking_connect"):
  4656. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4657. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4658. with alloc_fail(dev[0], 1, "=interworking_connect"):
  4659. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4660. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4661. dev[0].request("NOTE wpa_config_set(eap)")
  4662. with alloc_fail(dev[0], 1, "wpa_config_parse_eap;wpa_config_set;interworking_connect"):
  4663. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4664. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4665. dev[0].request("NOTE wpa_config_set(TTLS-NON_EAP_MSCHAPV2-phase2)")
  4666. with alloc_fail(dev[0], 1, "wpa_config_parse_str;wpa_config_set;interworking_connect"):
  4667. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4668. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4669. dev[0].remove_cred(id)
  4670. id = dev[0].add_cred_values({ 'roaming_consortium': "112233",
  4671. 'domain': "example.com",
  4672. 'username': "hs20-test",
  4673. 'password': "password",
  4674. 'eap': 'TTLS',
  4675. 'phase2': "auth=MSCHAPV2" })
  4676. interworking_select(dev[0], bssid, "home", freq=2412)
  4677. dev[0].dump_monitor()
  4678. dev[0].request("NOTE anon = os_strdup()")
  4679. with alloc_fail(dev[0], 2, "interworking_set_eap_params"):
  4680. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4681. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4682. dev[0].request("NOTE wpa_config_set_quoted(anonymous_identity)")
  4683. with alloc_fail(dev[0], 1, "=wpa_config_set_quoted;interworking_set_eap_params"):
  4684. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4685. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4686. dev[0].request("NOTE Successful connection with cred->realm not included")
  4687. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4688. dev[0].wait_connected()
  4689. dev[0].remove_cred(id)
  4690. dev[0].wait_disconnected()
  4691. id = dev[0].add_cred_values({ 'roaming_consortium': "112233",
  4692. 'domain': "example.com",
  4693. 'realm': "example.com",
  4694. 'username': "user",
  4695. 'password': "password",
  4696. 'eap': 'PEAP' })
  4697. interworking_select(dev[0], bssid, "home", freq=2412)
  4698. dev[0].dump_monitor()
  4699. dev[0].request("NOTE id = os_strdup()")
  4700. with alloc_fail(dev[0], 2, "interworking_set_eap_params"):
  4701. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4702. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4703. dev[0].request("NOTE wpa_config_set_quoted(identity)")
  4704. with alloc_fail(dev[0], 1, "=wpa_config_set_quoted;interworking_set_eap_params"):
  4705. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4706. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4707. dev[0].remove_cred(id)
  4708. id = dev[0].add_cred_values({ 'roaming_consortium': "112233",
  4709. 'domain': "example.com",
  4710. 'realm': "example.com",
  4711. 'username': "user",
  4712. 'password': "password",
  4713. 'eap': "TTLS" })
  4714. interworking_select(dev[0], bssid, "home", freq=2412)
  4715. dev[0].dump_monitor()
  4716. dev[0].request("NOTE wpa_config_set_quoted(identity) (second)")
  4717. with alloc_fail(dev[0], 2, "=wpa_config_set_quoted;interworking_set_eap_params"):
  4718. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4719. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4720. dev[0].request("NOTE wpa_config_set_quoted(password)")
  4721. with alloc_fail(dev[0], 3, "=wpa_config_set_quoted;interworking_set_eap_params"):
  4722. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4723. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4724. with alloc_fail(dev[0], 1, "wpa_config_add_network;interworking_connect_roaming_consortium"):
  4725. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4726. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4727. with alloc_fail(dev[0], 1, "=interworking_connect_roaming_consortium"):
  4728. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4729. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4730. dev[0].remove_cred(id)
  4731. id = dev[0].add_cred_values({ 'roaming_consortium': "112233",
  4732. 'domain': "example.com",
  4733. 'realm': "example.com",
  4734. 'username': "user",
  4735. 'eap': "PEAP" })
  4736. dev[0].set_cred(id, "password", "ext:password");
  4737. interworking_select(dev[0], bssid, "home", freq=2412)
  4738. dev[0].dump_monitor()
  4739. dev[0].request("NOTE wpa_config_set(password)")
  4740. with alloc_fail(dev[0], 3, "wpa_config_set;interworking_set_eap_params"):
  4741. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4742. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4743. with alloc_fail(dev[0], 1, "interworking_set_hs20_params"):
  4744. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4745. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4746. dev[0].remove_cred(id)
  4747. id = dev[0].add_cred_values({ 'realm': "example.com",
  4748. 'domain': "example.com",
  4749. 'username': "certificate-user",
  4750. 'phase1': "include_tls_length=0",
  4751. 'domain_suffix_match': "example.com",
  4752. 'ca_cert': "auth_serv/ca.pem",
  4753. 'client_cert': "auth_serv/user.pem",
  4754. 'private_key': "auth_serv/user.key",
  4755. 'private_key_passwd': "secret" })
  4756. interworking_select(dev[0], bssid, "home", freq=2412)
  4757. dev[0].dump_monitor()
  4758. dev[0].request("NOTE wpa_config_set_quoted(client_cert)")
  4759. with alloc_fail(dev[0], 2, "=wpa_config_set_quoted;interworking_set_eap_params"):
  4760. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4761. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4762. dev[0].request("NOTE wpa_config_set_quoted(private_key)")
  4763. with alloc_fail(dev[0], 3, "=wpa_config_set_quoted;interworking_set_eap_params"):
  4764. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4765. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4766. dev[0].request("NOTE wpa_config_set_quoted(private_key_passwd)")
  4767. with alloc_fail(dev[0], 4, "=wpa_config_set_quoted;interworking_set_eap_params"):
  4768. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4769. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4770. dev[0].request("NOTE wpa_config_set_quoted(ca_cert)")
  4771. with alloc_fail(dev[0], 5, "=wpa_config_set_quoted;interworking_set_eap_params"):
  4772. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4773. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4774. dev[0].request("NOTE wpa_config_set_quoted(domain_suffix_match)")
  4775. with alloc_fail(dev[0], 6, "=wpa_config_set_quoted;interworking_set_eap_params"):
  4776. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4777. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4778. with alloc_fail(dev[0], 1, "interworking_set_hs20_params"):
  4779. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4780. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4781. dev[0].remove_cred(id)
  4782. id = dev[0].add_cred_values({ 'imsi': "555444-333222111", 'eap': "SIM",
  4783. 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123"})
  4784. interworking_select(dev[0], bssid, freq=2412)
  4785. dev[0].dump_monitor()
  4786. with alloc_fail(dev[0], 1, "interworking_set_hs20_params"):
  4787. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4788. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4789. dev[0].request("NOTE wpa_config_set_quoted(password;milenage)")
  4790. with alloc_fail(dev[0], 2, "=wpa_config_set_quoted;interworking_connect_3gpp"):
  4791. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4792. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4793. dev[0].request("NOTE wpa_config_set(eap)")
  4794. with alloc_fail(dev[0], 1, "wpa_config_parse_eap;wpa_config_set;interworking_connect_3gpp"):
  4795. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4796. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4797. dev[0].request("NOTE set_root_nai:wpa_config_set(identity)")
  4798. with alloc_fail(dev[0], 1, "wpa_config_parse_str;interworking_connect_3gpp"):
  4799. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4800. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4801. dev[0].remove_cred(id)
  4802. id = dev[0].add_cred_values({ 'roaming_consortium': "112233",
  4803. 'username': "user@example.com",
  4804. 'password': "password" })
  4805. interworking_select(dev[0], bssid, freq=2412)
  4806. dev[0].dump_monitor()
  4807. dev[0].request("NOTE Interworking: No EAP method set for credential using roaming consortium")
  4808. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4809. dev[0].remove_cred(id)
  4810. hapd.disable()
  4811. params = hs20_ap_params()
  4812. params['nai_realm'] = "0,example.com,25[3:26]"
  4813. hapd = hostapd.add_ap(apdev[0], params)
  4814. id = dev[0].add_cred_values({ 'realm': "example.com",
  4815. 'domain': "example.com",
  4816. 'username': "hs20-test",
  4817. 'password': "password" })
  4818. interworking_select(dev[0], bssid, freq=2412)
  4819. dev[0].dump_monitor()
  4820. dev[0].request("NOTE wpa_config_set(PEAP/FAST-phase1)")
  4821. with alloc_fail(dev[0], 1, "wpa_config_parse_str;wpa_config_set;interworking_connect"):
  4822. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4823. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4824. dev[0].request("NOTE wpa_config_set(PEAP/FAST-pac_interworking)")
  4825. with alloc_fail(dev[0], 2, "wpa_config_parse_str;wpa_config_set;interworking_connect"):
  4826. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4827. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4828. dev[0].request("NOTE wpa_config_set(PEAP/FAST-phase2)")
  4829. with alloc_fail(dev[0], 3, "wpa_config_parse_str;wpa_config_set;interworking_connect"):
  4830. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4831. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4832. hapd.disable()
  4833. params = hs20_ap_params()
  4834. params['nai_realm'] = "0,example.com,21"
  4835. hapd = hostapd.add_ap(apdev[0], params)
  4836. interworking_select(dev[0], bssid, freq=2412)
  4837. dev[0].request("NOTE wpa_config_set(TTLS-defaults-phase2)")
  4838. with alloc_fail(dev[0], 1, "wpa_config_parse_str;wpa_config_set;interworking_connect"):
  4839. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4840. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4841. hapd.disable()
  4842. params = hs20_ap_params()
  4843. params['nai_realm'] = "0,example.com,21[2:3]"
  4844. hapd = hostapd.add_ap(apdev[0], params)
  4845. interworking_select(dev[0], bssid, freq=2412)
  4846. dev[0].request("NOTE wpa_config_set(TTLS-NON_EAP_MSCHAP-phase2)")
  4847. with alloc_fail(dev[0], 1, "wpa_config_parse_str;wpa_config_set;interworking_connect"):
  4848. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4849. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4850. hapd.disable()
  4851. params = hs20_ap_params()
  4852. params['nai_realm'] = "0,example.com,21[2:2]"
  4853. hapd = hostapd.add_ap(apdev[0], params)
  4854. interworking_select(dev[0], bssid, freq=2412)
  4855. dev[0].request("NOTE wpa_config_set(TTLS-NON_EAP_CHAP-phase2)")
  4856. with alloc_fail(dev[0], 1, "wpa_config_parse_str;wpa_config_set;interworking_connect"):
  4857. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4858. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4859. hapd.disable()
  4860. params = hs20_ap_params()
  4861. params['nai_realm'] = "0,example.com,21[2:1]"
  4862. hapd = hostapd.add_ap(apdev[0], params)
  4863. interworking_select(dev[0], bssid, freq=2412)
  4864. dev[0].request("NOTE wpa_config_set(TTLS-NON_EAP_PAP-phase2)")
  4865. with alloc_fail(dev[0], 1, "wpa_config_parse_str;wpa_config_set;interworking_connect"):
  4866. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4867. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4868. hapd.disable()
  4869. params = hs20_ap_params()
  4870. params['nai_realm'] = "0,example.com,21[3:26]"
  4871. hapd = hostapd.add_ap(apdev[0], params)
  4872. interworking_select(dev[0], bssid, freq=2412)
  4873. dev[0].request("NOTE wpa_config_set(TTLS-EAP-MSCHAPV2-phase2)")
  4874. with alloc_fail(dev[0], 1, "wpa_config_parse_str;wpa_config_set;interworking_connect"):
  4875. dev[0].request("INTERWORKING_CONNECT " + bssid)
  4876. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4877. dev[0].remove_cred(id)
  4878. def test_ap_hs20_unexpected(dev, apdev):
  4879. """Unexpected Hotspot 2.0 AP configuration"""
  4880. check_eap_capa(dev[0], "MSCHAPV2")
  4881. bssid = apdev[0]['bssid']
  4882. params = hostapd.wpa_eap_params(ssid="test-hs20-fake")
  4883. params['wpa'] = "3"
  4884. params['wpa_pairwise'] = "TKIP CCMP"
  4885. params['rsn_pairwise'] = "CCMP"
  4886. #params['vendor_elements'] = 'dd07506f9a10140000'
  4887. params['vendor_elements'] = 'dd04506f9a10'
  4888. hostapd.add_ap(apdev[0], params)
  4889. dev[0].hs20_enable()
  4890. dev[0].scan_for_bss(bssid, freq="2412")
  4891. dev[0].connect("test-hs20-fake", key_mgmt="WPA-EAP", eap="TTLS",
  4892. pairwise="TKIP",
  4893. identity="hs20-test", password="password",
  4894. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  4895. scan_freq="2412")
  4896. dev[1].hs20_enable()
  4897. dev[1].scan_for_bss(bssid, freq="2412")
  4898. dev[1].connect("test-hs20-fake", key_mgmt="WPA-EAP", eap="TTLS",
  4899. proto="WPA",
  4900. identity="hs20-test", password="password",
  4901. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  4902. scan_freq="2412")
  4903. dev[2].hs20_enable()
  4904. dev[2].scan_for_bss(bssid, freq="2412")
  4905. dev[2].connect("test-hs20-fake", key_mgmt="WPA-EAP", eap="TTLS",
  4906. proto="RSN", pairwise="CCMP",
  4907. identity="hs20-test", password="password",
  4908. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  4909. scan_freq="2412")
  4910. def test_ap_interworking_element_update(dev, apdev):
  4911. """Dynamic Interworking element update"""
  4912. bssid = apdev[0]['bssid']
  4913. params = hs20_ap_params()
  4914. params['hessid'] = bssid
  4915. hapd = hostapd.add_ap(apdev[0], params)
  4916. dev[0].hs20_enable()
  4917. dev[0].scan_for_bss(bssid, freq="2412")
  4918. bss = dev[0].get_bss(bssid)
  4919. logger.info("Before update: " + str(bss))
  4920. if '6b091e0701020000000300' not in bss['ie']:
  4921. raise Exception("Expected Interworking element not seen before update")
  4922. # Update configuration parameters related to Interworking element
  4923. hapd.set('access_network_type', '2')
  4924. hapd.set('asra', '1')
  4925. hapd.set('esr', '1')
  4926. hapd.set('uesa', '1')
  4927. hapd.set('venue_group', '2')
  4928. hapd.set('venue_type', '8')
  4929. if "OK" not in hapd.request("UPDATE_BEACON"):
  4930. raise Exception("UPDATE_BEACON failed")
  4931. dev[0].request("BSS_FLUSH 0")
  4932. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  4933. bss = dev[0].get_bss(bssid)
  4934. logger.info("After update: " + str(bss))
  4935. if '6b09f20208020000000300' not in bss['ie']:
  4936. raise Exception("Expected Interworking element not seen after update")