test_ap_hs20.py 143 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570
  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. import binascii
  7. import struct
  8. import time
  9. import subprocess
  10. import logging
  11. logger = logging.getLogger()
  12. import os
  13. import os.path
  14. import socket
  15. import subprocess
  16. import hostapd
  17. from utils import HwsimSkip, skip_with_fips
  18. import hwsim_utils
  19. from tshark import run_tshark
  20. from wlantest import Wlantest
  21. from wpasupplicant import WpaSupplicant
  22. from test_ap_eap import check_eap_capa, check_domain_match_full
  23. def hs20_ap_params(ssid="test-hs20"):
  24. params = hostapd.wpa2_params(ssid=ssid)
  25. params['wpa_key_mgmt'] = "WPA-EAP"
  26. params['ieee80211w'] = "1"
  27. params['ieee8021x'] = "1"
  28. params['auth_server_addr'] = "127.0.0.1"
  29. params['auth_server_port'] = "1812"
  30. params['auth_server_shared_secret'] = "radius"
  31. params['interworking'] = "1"
  32. params['access_network_type'] = "14"
  33. params['internet'] = "1"
  34. params['asra'] = "0"
  35. params['esr'] = "0"
  36. params['uesa'] = "0"
  37. params['venue_group'] = "7"
  38. params['venue_type'] = "1"
  39. params['venue_name'] = [ "eng:Example venue", "fin:Esimerkkipaikka" ]
  40. params['roaming_consortium'] = [ "112233", "1020304050", "010203040506",
  41. "fedcba" ]
  42. params['domain_name'] = "example.com,another.example.com"
  43. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]",
  44. "0,another.example.com" ]
  45. params['hs20'] = "1"
  46. params['hs20_wan_metrics'] = "01:8000:1000:80:240:3000"
  47. params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0" ]
  48. params['hs20_operating_class'] = "5173"
  49. params['anqp_3gpp_cell_net'] = "244,91"
  50. return params
  51. def check_auto_select(dev, bssid):
  52. dev.scan_for_bss(bssid, freq="2412")
  53. dev.request("INTERWORKING_SELECT auto freq=2412")
  54. ev = dev.wait_connected(timeout=15)
  55. if bssid not in ev:
  56. raise Exception("Connected to incorrect network")
  57. dev.request("REMOVE_NETWORK all")
  58. dev.wait_disconnected()
  59. def interworking_select(dev, bssid, type=None, no_match=False, freq=None):
  60. dev.dump_monitor()
  61. if bssid and freq and not no_match:
  62. dev.scan_for_bss(bssid, freq=freq)
  63. freq_extra = " freq=" + str(freq) if freq else ""
  64. dev.request("INTERWORKING_SELECT" + freq_extra)
  65. ev = dev.wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
  66. timeout=15)
  67. if ev is None:
  68. raise Exception("Network selection timed out");
  69. if no_match:
  70. if "INTERWORKING-NO-MATCH" not in ev:
  71. raise Exception("Unexpected network match")
  72. return
  73. if "INTERWORKING-NO-MATCH" in ev:
  74. logger.info("Matching network not found - try again")
  75. dev.dump_monitor()
  76. dev.request("INTERWORKING_SELECT" + freq_extra)
  77. ev = dev.wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
  78. timeout=15)
  79. if ev is None:
  80. raise Exception("Network selection timed out");
  81. if "INTERWORKING-NO-MATCH" in ev:
  82. raise Exception("Matching network not found")
  83. if bssid and bssid not in ev:
  84. raise Exception("Unexpected BSSID in match")
  85. if type and "type=" + type not in ev:
  86. raise Exception("Network type not recognized correctly")
  87. def check_sp_type(dev, sp_type):
  88. type = dev.get_status_field("sp_type")
  89. if type is None:
  90. raise Exception("sp_type not available")
  91. if type != sp_type:
  92. raise Exception("sp_type did not indicate home network")
  93. def hlr_auc_gw_available():
  94. if not os.path.exists("/tmp/hlr_auc_gw.sock"):
  95. raise HwsimSkip("No hlr_auc_gw socket available")
  96. if not os.path.exists("../../hostapd/hlr_auc_gw"):
  97. raise HwsimSkip("No hlr_auc_gw available")
  98. def interworking_ext_sim_connect(dev, bssid, method):
  99. dev.request("INTERWORKING_CONNECT " + bssid)
  100. interworking_ext_sim_auth(dev, method)
  101. def interworking_ext_sim_auth(dev, method):
  102. ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  103. if ev is None:
  104. raise Exception("Network connected timed out")
  105. if "(" + method + ")" not in ev:
  106. raise Exception("Unexpected EAP method selection")
  107. ev = dev.wait_event(["CTRL-REQ-SIM"], timeout=15)
  108. if ev is None:
  109. raise Exception("Wait for external SIM processing request timed out")
  110. p = ev.split(':', 2)
  111. if p[1] != "GSM-AUTH":
  112. raise Exception("Unexpected CTRL-REQ-SIM type")
  113. id = p[0].split('-')[3]
  114. rand = p[2].split(' ')[0]
  115. res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
  116. "-m",
  117. "auth_serv/hlr_auc_gw.milenage_db",
  118. "GSM-AUTH-REQ 232010000000000 " + rand])
  119. if "GSM-AUTH-RESP" not in res:
  120. raise Exception("Unexpected hlr_auc_gw response")
  121. resp = res.split(' ')[2].rstrip()
  122. dev.request("CTRL-RSP-SIM-" + id + ":GSM-AUTH:" + resp)
  123. dev.wait_connected(timeout=15)
  124. def interworking_connect(dev, bssid, method):
  125. dev.request("INTERWORKING_CONNECT " + bssid)
  126. interworking_auth(dev, method)
  127. def interworking_auth(dev, method):
  128. ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  129. if ev is None:
  130. raise Exception("Network connected timed out")
  131. if "(" + method + ")" not in ev:
  132. raise Exception("Unexpected EAP method selection")
  133. dev.wait_connected(timeout=15)
  134. def check_probe_resp(wt, bssid_unexpected, bssid_expected):
  135. if bssid_unexpected:
  136. count = wt.get_bss_counter("probe_response", bssid_unexpected)
  137. if count > 0:
  138. raise Exception("Unexpected Probe Response frame from AP")
  139. if bssid_expected:
  140. count = wt.get_bss_counter("probe_response", bssid_expected)
  141. if count == 0:
  142. raise Exception("No Probe Response frame from AP")
  143. def test_ap_anqp_sharing(dev, apdev):
  144. """ANQP sharing within ESS and explicit unshare"""
  145. check_eap_capa(dev[0], "MSCHAPV2")
  146. dev[0].flush_scan_cache()
  147. bssid = apdev[0]['bssid']
  148. params = hs20_ap_params()
  149. params['hessid'] = bssid
  150. hostapd.add_ap(apdev[0]['ifname'], params)
  151. bssid2 = apdev[1]['bssid']
  152. params = hs20_ap_params()
  153. params['hessid'] = bssid
  154. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]" ]
  155. hostapd.add_ap(apdev[1]['ifname'], params)
  156. dev[0].hs20_enable()
  157. id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test",
  158. 'password': "secret",
  159. 'domain': "example.com" })
  160. logger.info("Normal network selection with shared ANQP results")
  161. dev[0].scan_for_bss(bssid, freq="2412")
  162. dev[0].scan_for_bss(bssid2, freq="2412")
  163. interworking_select(dev[0], None, "home", freq="2412")
  164. dev[0].dump_monitor()
  165. logger.debug("BSS entries:\n" + dev[0].request("BSS RANGE=ALL"))
  166. res1 = dev[0].get_bss(bssid)
  167. res2 = dev[0].get_bss(bssid2)
  168. if 'anqp_nai_realm' not in res1:
  169. raise Exception("anqp_nai_realm not found for AP1")
  170. if 'anqp_nai_realm' not in res2:
  171. raise Exception("anqp_nai_realm not found for AP2")
  172. if res1['anqp_nai_realm'] != res2['anqp_nai_realm']:
  173. raise Exception("ANQP results were not shared between BSSes")
  174. logger.info("Explicit ANQP request to unshare ANQP results")
  175. dev[0].request("ANQP_GET " + bssid + " 263")
  176. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  177. if ev is None:
  178. raise Exception("ANQP operation timed out")
  179. dev[0].request("ANQP_GET " + bssid2 + " 263")
  180. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  181. if ev is None:
  182. raise Exception("ANQP operation timed out")
  183. res1 = dev[0].get_bss(bssid)
  184. res2 = dev[0].get_bss(bssid2)
  185. if res1['anqp_nai_realm'] == res2['anqp_nai_realm']:
  186. raise Exception("ANQP results were not unshared")
  187. def test_ap_nai_home_realm_query(dev, apdev):
  188. """NAI Home Realm Query"""
  189. check_eap_capa(dev[0], "MSCHAPV2")
  190. bssid = apdev[0]['bssid']
  191. params = hs20_ap_params()
  192. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]",
  193. "0,another.example.org" ]
  194. hostapd.add_ap(apdev[0]['ifname'], params)
  195. dev[0].scan(freq="2412")
  196. dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + bssid + " realm=example.com")
  197. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  198. if ev is None:
  199. raise Exception("ANQP operation timed out")
  200. nai1 = dev[0].get_bss(bssid)['anqp_nai_realm']
  201. dev[0].dump_monitor()
  202. dev[0].request("ANQP_GET " + bssid + " 263")
  203. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  204. if ev is None:
  205. raise Exception("ANQP operation timed out")
  206. nai2 = dev[0].get_bss(bssid)['anqp_nai_realm']
  207. if len(nai1) >= len(nai2):
  208. raise Exception("Unexpected NAI Realm list response lengths")
  209. if "example.com".encode('hex') not in nai1:
  210. raise Exception("Home realm not reported")
  211. if "example.org".encode('hex') in nai1:
  212. raise Exception("Non-home realm reported")
  213. if "example.com".encode('hex') not in nai2:
  214. raise Exception("Home realm not reported in wildcard query")
  215. if "example.org".encode('hex') not in nai2:
  216. raise Exception("Non-home realm not reported in wildcard query ")
  217. cmds = [ "foo",
  218. "00:11:22:33:44:55 123",
  219. "00:11:22:33:44:55 qq" ]
  220. for cmd in cmds:
  221. if "FAIL" not in dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + cmd):
  222. raise Exception("Invalid HS20_GET_NAI_HOME_REALM_LIST accepted: " + cmd)
  223. dev[0].dump_monitor()
  224. if "OK" not in dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + bssid):
  225. raise Exception("HS20_GET_NAI_HOME_REALM_LIST failed")
  226. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  227. if ev is None:
  228. raise Exception("ANQP operation timed out")
  229. ev = dev[0].wait_event(["RX-ANQP"], timeout=0.1)
  230. if ev is not None:
  231. raise Exception("Unexpected ANQP response: " + ev)
  232. dev[0].dump_monitor()
  233. if "OK" not in dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + bssid + " 01000b6578616d706c652e636f6d"):
  234. raise Exception("HS20_GET_NAI_HOME_REALM_LIST failed")
  235. ev = dev[0].wait_event(["RX-ANQP"], timeout=10)
  236. if ev is None:
  237. raise Exception("No ANQP response")
  238. if "NAI Realm list" not in ev:
  239. raise Exception("Missing NAI Realm list: " + ev)
  240. dev[0].add_cred_values({ 'realm': "example.com", 'username': "test",
  241. 'password': "secret",
  242. 'domain': "example.com" })
  243. dev[0].dump_monitor()
  244. if "OK" not in dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + bssid):
  245. raise Exception("HS20_GET_NAI_HOME_REALM_LIST failed")
  246. ev = dev[0].wait_event(["RX-ANQP"], timeout=10)
  247. if ev is None:
  248. raise Exception("No ANQP response")
  249. if "NAI Realm list" not in ev:
  250. raise Exception("Missing NAI Realm list: " + ev)
  251. def test_ap_interworking_scan_filtering(dev, apdev):
  252. """Interworking scan filtering with HESSID and access network type"""
  253. try:
  254. _test_ap_interworking_scan_filtering(dev, apdev)
  255. finally:
  256. dev[0].request("SET hessid 00:00:00:00:00:00")
  257. dev[0].request("SET access_network_type 15")
  258. def _test_ap_interworking_scan_filtering(dev, apdev):
  259. bssid = apdev[0]['bssid']
  260. params = hs20_ap_params()
  261. ssid = "test-hs20-ap1"
  262. params['ssid'] = ssid
  263. params['hessid'] = bssid
  264. hostapd.add_ap(apdev[0]['ifname'], params)
  265. bssid2 = apdev[1]['bssid']
  266. params = hs20_ap_params()
  267. ssid2 = "test-hs20-ap2"
  268. params['ssid'] = ssid2
  269. params['hessid'] = bssid2
  270. params['access_network_type'] = "1"
  271. del params['venue_group']
  272. del params['venue_type']
  273. hostapd.add_ap(apdev[1]['ifname'], params)
  274. dev[0].hs20_enable()
  275. wt = Wlantest()
  276. wt.flush()
  277. logger.info("Check probe request filtering based on HESSID")
  278. dev[0].request("SET hessid " + bssid2)
  279. dev[0].scan(freq="2412")
  280. time.sleep(0.03)
  281. check_probe_resp(wt, bssid, bssid2)
  282. logger.info("Check probe request filtering based on access network type")
  283. wt.clear_bss_counters(bssid)
  284. wt.clear_bss_counters(bssid2)
  285. dev[0].request("SET hessid 00:00:00:00:00:00")
  286. dev[0].request("SET access_network_type 14")
  287. dev[0].scan(freq="2412")
  288. time.sleep(0.03)
  289. check_probe_resp(wt, bssid2, bssid)
  290. wt.clear_bss_counters(bssid)
  291. wt.clear_bss_counters(bssid2)
  292. dev[0].request("SET hessid 00:00:00:00:00:00")
  293. dev[0].request("SET access_network_type 1")
  294. dev[0].scan(freq="2412")
  295. time.sleep(0.03)
  296. check_probe_resp(wt, bssid, bssid2)
  297. logger.info("Check probe request filtering based on HESSID and ANT")
  298. wt.clear_bss_counters(bssid)
  299. wt.clear_bss_counters(bssid2)
  300. dev[0].request("SET hessid " + bssid)
  301. dev[0].request("SET access_network_type 14")
  302. dev[0].scan(freq="2412")
  303. time.sleep(0.03)
  304. check_probe_resp(wt, bssid2, bssid)
  305. wt.clear_bss_counters(bssid)
  306. wt.clear_bss_counters(bssid2)
  307. dev[0].request("SET hessid " + bssid2)
  308. dev[0].request("SET access_network_type 14")
  309. dev[0].scan(freq="2412")
  310. time.sleep(0.03)
  311. check_probe_resp(wt, bssid, None)
  312. check_probe_resp(wt, bssid2, None)
  313. wt.clear_bss_counters(bssid)
  314. wt.clear_bss_counters(bssid2)
  315. dev[0].request("SET hessid " + bssid)
  316. dev[0].request("SET access_network_type 1")
  317. dev[0].scan(freq="2412")
  318. time.sleep(0.03)
  319. check_probe_resp(wt, bssid, None)
  320. check_probe_resp(wt, bssid2, None)
  321. def test_ap_hs20_select(dev, apdev):
  322. """Hotspot 2.0 network selection"""
  323. bssid = apdev[0]['bssid']
  324. params = hs20_ap_params()
  325. params['hessid'] = bssid
  326. hostapd.add_ap(apdev[0]['ifname'], params)
  327. dev[0].hs20_enable()
  328. id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test",
  329. 'password': "secret",
  330. 'domain': "example.com" })
  331. interworking_select(dev[0], bssid, "home")
  332. dev[0].remove_cred(id)
  333. id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test",
  334. 'password': "secret",
  335. 'domain': "no.match.example.com" })
  336. interworking_select(dev[0], bssid, "roaming", freq="2412")
  337. dev[0].set_cred_quoted(id, "realm", "no.match.example.com");
  338. interworking_select(dev[0], bssid, no_match=True, freq="2412")
  339. res = dev[0].request("SCAN_RESULTS")
  340. if "[HS20]" not in res:
  341. raise Exception("HS20 flag missing from scan results: " + res)
  342. bssid2 = apdev[1]['bssid']
  343. params = hs20_ap_params()
  344. params['nai_realm'] = [ "0,example.org,21" ]
  345. params['hessid'] = bssid2
  346. params['domain_name'] = "example.org"
  347. hostapd.add_ap(apdev[1]['ifname'], params)
  348. dev[0].remove_cred(id)
  349. id = dev[0].add_cred_values({ 'realm': "example.org", 'username': "test",
  350. 'password': "secret",
  351. 'domain': "example.org" })
  352. interworking_select(dev[0], bssid2, "home", freq="2412")
  353. def hs20_simulated_sim(dev, ap, method):
  354. bssid = ap['bssid']
  355. params = hs20_ap_params()
  356. params['hessid'] = bssid
  357. params['anqp_3gpp_cell_net'] = "555,444"
  358. params['domain_name'] = "wlan.mnc444.mcc555.3gppnetwork.org"
  359. hostapd.add_ap(ap['ifname'], params)
  360. dev.hs20_enable()
  361. dev.add_cred_values({ 'imsi': "555444-333222111", 'eap': method,
  362. 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123"})
  363. interworking_select(dev, "home", freq="2412")
  364. interworking_connect(dev, bssid, method)
  365. check_sp_type(dev, "home")
  366. def test_ap_hs20_sim(dev, apdev):
  367. """Hotspot 2.0 with simulated SIM and EAP-SIM"""
  368. hlr_auc_gw_available()
  369. hs20_simulated_sim(dev[0], apdev[0], "SIM")
  370. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  371. ev = dev[0].wait_event(["INTERWORKING-ALREADY-CONNECTED"], timeout=15)
  372. if ev is None:
  373. raise Exception("Timeout on already-connected event")
  374. def test_ap_hs20_aka(dev, apdev):
  375. """Hotspot 2.0 with simulated USIM and EAP-AKA"""
  376. hlr_auc_gw_available()
  377. hs20_simulated_sim(dev[0], apdev[0], "AKA")
  378. def test_ap_hs20_aka_prime(dev, apdev):
  379. """Hotspot 2.0 with simulated USIM and EAP-AKA'"""
  380. hlr_auc_gw_available()
  381. hs20_simulated_sim(dev[0], apdev[0], "AKA'")
  382. def test_ap_hs20_ext_sim(dev, apdev):
  383. """Hotspot 2.0 with external SIM processing"""
  384. hlr_auc_gw_available()
  385. bssid = apdev[0]['bssid']
  386. params = hs20_ap_params()
  387. params['hessid'] = bssid
  388. params['anqp_3gpp_cell_net'] = "232,01"
  389. params['domain_name'] = "wlan.mnc001.mcc232.3gppnetwork.org"
  390. hostapd.add_ap(apdev[0]['ifname'], params)
  391. dev[0].hs20_enable()
  392. try:
  393. dev[0].request("SET external_sim 1")
  394. dev[0].add_cred_values({ 'imsi': "23201-0000000000", 'eap': "SIM" })
  395. interworking_select(dev[0], "home", freq="2412")
  396. interworking_ext_sim_connect(dev[0], bssid, "SIM")
  397. check_sp_type(dev[0], "home")
  398. finally:
  399. dev[0].request("SET external_sim 0")
  400. def test_ap_hs20_ext_sim_roaming(dev, apdev):
  401. """Hotspot 2.0 with external SIM processing in roaming network"""
  402. hlr_auc_gw_available()
  403. bssid = apdev[0]['bssid']
  404. params = hs20_ap_params()
  405. params['hessid'] = bssid
  406. params['anqp_3gpp_cell_net'] = "244,91;310,026;232,01;234,56"
  407. params['domain_name'] = "wlan.mnc091.mcc244.3gppnetwork.org"
  408. hostapd.add_ap(apdev[0]['ifname'], params)
  409. dev[0].hs20_enable()
  410. try:
  411. dev[0].request("SET external_sim 1")
  412. dev[0].add_cred_values({ 'imsi': "23201-0000000000", 'eap': "SIM" })
  413. interworking_select(dev[0], "roaming", freq="2412")
  414. interworking_ext_sim_connect(dev[0], bssid, "SIM")
  415. check_sp_type(dev[0], "roaming")
  416. finally:
  417. dev[0].request("SET external_sim 0")
  418. def test_ap_hs20_username(dev, apdev):
  419. """Hotspot 2.0 connection in username/password credential"""
  420. check_eap_capa(dev[0], "MSCHAPV2")
  421. bssid = apdev[0]['bssid']
  422. params = hs20_ap_params()
  423. params['hessid'] = bssid
  424. params['disable_dgaf'] = '1'
  425. hostapd.add_ap(apdev[0]['ifname'], params)
  426. dev[0].hs20_enable()
  427. id = dev[0].add_cred_values({ 'realm': "example.com",
  428. 'username': "hs20-test",
  429. 'password': "password",
  430. 'ca_cert': "auth_serv/ca.pem",
  431. 'domain': "example.com",
  432. 'update_identifier': "1234" })
  433. interworking_select(dev[0], bssid, "home", freq="2412")
  434. interworking_connect(dev[0], bssid, "TTLS")
  435. check_sp_type(dev[0], "home")
  436. status = dev[0].get_status()
  437. if status['pairwise_cipher'] != "CCMP":
  438. raise Exception("Unexpected pairwise cipher")
  439. if status['hs20'] != "2":
  440. raise Exception("Unexpected HS 2.0 support indication")
  441. dev[1].connect("test-hs20", key_mgmt="WPA-EAP", eap="TTLS",
  442. identity="hs20-test", password="password",
  443. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  444. scan_freq="2412")
  445. def test_ap_hs20_connect_api(dev, apdev):
  446. """Hotspot 2.0 connection with connect API"""
  447. check_eap_capa(dev[0], "MSCHAPV2")
  448. bssid = apdev[0]['bssid']
  449. params = hs20_ap_params()
  450. params['hessid'] = bssid
  451. params['disable_dgaf'] = '1'
  452. hostapd.add_ap(apdev[0]['ifname'], params)
  453. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  454. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  455. wpas.hs20_enable()
  456. wpas.flush_scan_cache()
  457. id = wpas.add_cred_values({ 'realm': "example.com",
  458. 'username': "hs20-test",
  459. 'password': "password",
  460. 'ca_cert': "auth_serv/ca.pem",
  461. 'domain': "example.com",
  462. 'update_identifier': "1234" })
  463. interworking_select(wpas, bssid, "home", freq="2412")
  464. interworking_connect(wpas, bssid, "TTLS")
  465. check_sp_type(wpas, "home")
  466. status = wpas.get_status()
  467. if status['pairwise_cipher'] != "CCMP":
  468. raise Exception("Unexpected pairwise cipher")
  469. if status['hs20'] != "2":
  470. raise Exception("Unexpected HS 2.0 support indication")
  471. def test_ap_hs20_auto_interworking(dev, apdev):
  472. """Hotspot 2.0 connection with auto_interworking=1"""
  473. check_eap_capa(dev[0], "MSCHAPV2")
  474. bssid = apdev[0]['bssid']
  475. params = hs20_ap_params()
  476. params['hessid'] = bssid
  477. params['disable_dgaf'] = '1'
  478. hostapd.add_ap(apdev[0]['ifname'], params)
  479. dev[0].hs20_enable(auto_interworking=True)
  480. id = dev[0].add_cred_values({ 'realm': "example.com",
  481. 'username': "hs20-test",
  482. 'password': "password",
  483. 'ca_cert': "auth_serv/ca.pem",
  484. 'domain': "example.com",
  485. 'update_identifier': "1234" })
  486. dev[0].request("REASSOCIATE")
  487. dev[0].wait_connected(timeout=15)
  488. check_sp_type(dev[0], "home")
  489. status = dev[0].get_status()
  490. if status['pairwise_cipher'] != "CCMP":
  491. raise Exception("Unexpected pairwise cipher")
  492. if status['hs20'] != "2":
  493. raise Exception("Unexpected HS 2.0 support indication")
  494. def test_ap_hs20_auto_interworking_no_match(dev, apdev):
  495. """Hotspot 2.0 connection with auto_interworking=1 and no matching network"""
  496. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "mismatch" })
  497. dev[0].hs20_enable(auto_interworking=True)
  498. id = dev[0].connect("mismatch", psk="12345678", scan_freq="2412",
  499. only_add_network=True)
  500. dev[0].request("ENABLE_NETWORK " + str(id) + " no-connect")
  501. id = dev[0].add_cred_values({ 'realm': "example.com",
  502. 'username': "hs20-test",
  503. 'password': "password",
  504. 'ca_cert': "auth_serv/ca.pem",
  505. 'domain': "example.com",
  506. 'update_identifier': "1234" })
  507. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  508. time.sleep(0.1)
  509. dev[0].dump_monitor()
  510. for i in range(5):
  511. logger.info("start ping")
  512. if "PONG" not in dev[0].ctrl.request("PING", timeout=2):
  513. raise Exception("PING failed")
  514. logger.info("ping done")
  515. fetch = 0
  516. scan = 0
  517. for j in range(15):
  518. ev = dev[0].wait_event([ "ANQP fetch completed",
  519. "CTRL-EVENT-SCAN-RESULTS" ], timeout=0.05)
  520. if ev is None:
  521. break
  522. if "ANQP fetch completed" in ev:
  523. fetch += 1
  524. else:
  525. scan += 1
  526. if fetch > 2 * scan + 3:
  527. raise Exception("Too many ANQP fetch iterations")
  528. dev[0].dump_monitor()
  529. dev[0].request("DISCONNECT")
  530. def test_ap_hs20_auto_interworking_no_cred_match(dev, apdev):
  531. """Hotspot 2.0 connection with auto_interworking=1 but no cred match"""
  532. bssid = apdev[0]['bssid']
  533. params = { "ssid": "test" }
  534. hostapd.add_ap(apdev[0]['ifname'], params)
  535. dev[0].hs20_enable(auto_interworking=True)
  536. dev[0].add_cred_values({ 'realm': "example.com",
  537. 'username': "hs20-test",
  538. 'password': "password",
  539. 'ca_cert': "auth_serv/ca.pem",
  540. 'domain': "example.com" })
  541. id = dev[0].connect("test", psk="12345678", only_add_network=True)
  542. dev[0].request("ENABLE_NETWORK %s" % id)
  543. logger.info("Verify that scanning continues when there is partial network block match")
  544. for i in range(0, 2):
  545. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
  546. if ev is None:
  547. raise Exception("Scan timed out")
  548. logger.info("Scan completed")
  549. def eap_test(dev, ap, eap_params, method, user):
  550. bssid = ap['bssid']
  551. params = hs20_ap_params()
  552. params['nai_realm'] = [ "0,example.com," + eap_params ]
  553. hostapd.add_ap(ap['ifname'], params)
  554. dev.hs20_enable()
  555. dev.add_cred_values({ 'realm': "example.com",
  556. 'ca_cert': "auth_serv/ca.pem",
  557. 'username': user,
  558. 'password': "password" })
  559. interworking_select(dev, bssid, freq="2412")
  560. interworking_connect(dev, bssid, method)
  561. def test_ap_hs20_eap_unknown(dev, apdev):
  562. """Hotspot 2.0 connection with unknown EAP method"""
  563. bssid = apdev[0]['bssid']
  564. params = hs20_ap_params()
  565. params['nai_realm'] = "0,example.com,99"
  566. hostapd.add_ap(apdev[0]['ifname'], params)
  567. dev[0].hs20_enable()
  568. dev[0].add_cred_values(default_cred())
  569. interworking_select(dev[0], None, no_match=True, freq="2412")
  570. def test_ap_hs20_eap_peap_mschapv2(dev, apdev):
  571. """Hotspot 2.0 connection with PEAP/MSCHAPV2"""
  572. check_eap_capa(dev[0], "MSCHAPV2")
  573. eap_test(dev[0], apdev[0], "25[3:26]", "PEAP", "user")
  574. def test_ap_hs20_eap_peap_default(dev, apdev):
  575. """Hotspot 2.0 connection with PEAP/MSCHAPV2 (as default)"""
  576. check_eap_capa(dev[0], "MSCHAPV2")
  577. eap_test(dev[0], apdev[0], "25", "PEAP", "user")
  578. def test_ap_hs20_eap_peap_gtc(dev, apdev):
  579. """Hotspot 2.0 connection with PEAP/GTC"""
  580. eap_test(dev[0], apdev[0], "25[3:6]", "PEAP", "user")
  581. def test_ap_hs20_eap_peap_unknown(dev, apdev):
  582. """Hotspot 2.0 connection with PEAP/unknown"""
  583. bssid = apdev[0]['bssid']
  584. params = hs20_ap_params()
  585. params['nai_realm'] = "0,example.com,25[3:99]"
  586. hostapd.add_ap(apdev[0]['ifname'], params)
  587. dev[0].hs20_enable()
  588. dev[0].add_cred_values(default_cred())
  589. interworking_select(dev[0], None, no_match=True, freq="2412")
  590. def test_ap_hs20_eap_ttls_chap(dev, apdev):
  591. """Hotspot 2.0 connection with TTLS/CHAP"""
  592. skip_with_fips(dev[0])
  593. eap_test(dev[0], apdev[0], "21[2:2]", "TTLS", "chap user")
  594. def test_ap_hs20_eap_ttls_mschap(dev, apdev):
  595. """Hotspot 2.0 connection with TTLS/MSCHAP"""
  596. skip_with_fips(dev[0])
  597. eap_test(dev[0], apdev[0], "21[2:3]", "TTLS", "mschap user")
  598. def test_ap_hs20_eap_ttls_eap_mschapv2(dev, apdev):
  599. """Hotspot 2.0 connection with TTLS/EAP-MSCHAPv2"""
  600. check_eap_capa(dev[0], "MSCHAPV2")
  601. eap_test(dev[0], apdev[0], "21[3:26][6:7][99:99]", "TTLS", "user")
  602. def test_ap_hs20_eap_ttls_eap_unknown(dev, apdev):
  603. """Hotspot 2.0 connection with TTLS/EAP-unknown"""
  604. bssid = apdev[0]['bssid']
  605. params = hs20_ap_params()
  606. params['nai_realm'] = "0,example.com,21[3:99]"
  607. hostapd.add_ap(apdev[0]['ifname'], params)
  608. dev[0].hs20_enable()
  609. dev[0].add_cred_values(default_cred())
  610. interworking_select(dev[0], None, no_match=True, freq="2412")
  611. def test_ap_hs20_eap_ttls_eap_unsupported(dev, apdev):
  612. """Hotspot 2.0 connection with TTLS/EAP-OTP(unsupported)"""
  613. bssid = apdev[0]['bssid']
  614. params = hs20_ap_params()
  615. params['nai_realm'] = "0,example.com,21[3:5]"
  616. hostapd.add_ap(apdev[0]['ifname'], params)
  617. dev[0].hs20_enable()
  618. dev[0].add_cred_values(default_cred())
  619. interworking_select(dev[0], None, no_match=True, freq="2412")
  620. def test_ap_hs20_eap_ttls_unknown(dev, apdev):
  621. """Hotspot 2.0 connection with TTLS/unknown"""
  622. bssid = apdev[0]['bssid']
  623. params = hs20_ap_params()
  624. params['nai_realm'] = "0,example.com,21[2:5]"
  625. hostapd.add_ap(apdev[0]['ifname'], params)
  626. dev[0].hs20_enable()
  627. dev[0].add_cred_values(default_cred())
  628. interworking_select(dev[0], None, no_match=True, freq="2412")
  629. def test_ap_hs20_eap_fast_mschapv2(dev, apdev):
  630. """Hotspot 2.0 connection with FAST/EAP-MSCHAPV2"""
  631. check_eap_capa(dev[0], "FAST")
  632. eap_test(dev[0], apdev[0], "43[3:26]", "FAST", "user")
  633. def test_ap_hs20_eap_fast_gtc(dev, apdev):
  634. """Hotspot 2.0 connection with FAST/EAP-GTC"""
  635. check_eap_capa(dev[0], "FAST")
  636. eap_test(dev[0], apdev[0], "43[3:6]", "FAST", "user")
  637. def test_ap_hs20_eap_tls(dev, apdev):
  638. """Hotspot 2.0 connection with EAP-TLS"""
  639. bssid = apdev[0]['bssid']
  640. params = hs20_ap_params()
  641. params['nai_realm'] = [ "0,example.com,13[5:6]" ]
  642. hostapd.add_ap(apdev[0]['ifname'], params)
  643. dev[0].hs20_enable()
  644. dev[0].add_cred_values({ 'realm': "example.com",
  645. 'username': "certificate-user",
  646. 'ca_cert': "auth_serv/ca.pem",
  647. 'client_cert': "auth_serv/user.pem",
  648. 'private_key': "auth_serv/user.key"})
  649. interworking_select(dev[0], bssid, freq="2412")
  650. interworking_connect(dev[0], bssid, "TLS")
  651. def test_ap_hs20_eap_cert_unknown(dev, apdev):
  652. """Hotspot 2.0 connection with certificate, but unknown EAP method"""
  653. bssid = apdev[0]['bssid']
  654. params = hs20_ap_params()
  655. params['nai_realm'] = [ "0,example.com,99[5:6]" ]
  656. hostapd.add_ap(apdev[0]['ifname'], params)
  657. dev[0].hs20_enable()
  658. dev[0].add_cred_values({ 'realm': "example.com",
  659. 'username': "certificate-user",
  660. 'ca_cert': "auth_serv/ca.pem",
  661. 'client_cert': "auth_serv/user.pem",
  662. 'private_key': "auth_serv/user.key"})
  663. interworking_select(dev[0], None, no_match=True, freq="2412")
  664. def test_ap_hs20_eap_cert_unsupported(dev, apdev):
  665. """Hotspot 2.0 connection with certificate, but unsupported TTLS"""
  666. bssid = apdev[0]['bssid']
  667. params = hs20_ap_params()
  668. params['nai_realm'] = [ "0,example.com,21[5:6]" ]
  669. hostapd.add_ap(apdev[0]['ifname'], params)
  670. dev[0].hs20_enable()
  671. dev[0].add_cred_values({ 'realm': "example.com",
  672. 'username': "certificate-user",
  673. 'ca_cert': "auth_serv/ca.pem",
  674. 'client_cert': "auth_serv/user.pem",
  675. 'private_key': "auth_serv/user.key"})
  676. interworking_select(dev[0], None, no_match=True, freq="2412")
  677. def test_ap_hs20_eap_invalid_cred(dev, apdev):
  678. """Hotspot 2.0 connection with invalid cred configuration"""
  679. bssid = apdev[0]['bssid']
  680. params = hs20_ap_params()
  681. hostapd.add_ap(apdev[0]['ifname'], params)
  682. dev[0].hs20_enable()
  683. dev[0].add_cred_values({ 'realm': "example.com",
  684. 'username': "certificate-user",
  685. 'client_cert': "auth_serv/user.pem" })
  686. interworking_select(dev[0], None, no_match=True, freq="2412")
  687. def test_ap_hs20_nai_realms(dev, apdev):
  688. """Hotspot 2.0 connection and multiple NAI realms and TTLS/PAP"""
  689. bssid = apdev[0]['bssid']
  690. params = hs20_ap_params()
  691. params['hessid'] = bssid
  692. params['nai_realm'] = [ "0,no.match.here;example.com;no.match.here.either,21[2:1][5:7]" ]
  693. hostapd.add_ap(apdev[0]['ifname'], params)
  694. dev[0].hs20_enable()
  695. id = dev[0].add_cred_values({ 'realm': "example.com",
  696. 'ca_cert': "auth_serv/ca.pem",
  697. 'username': "pap user",
  698. 'password': "password",
  699. 'domain': "example.com" })
  700. interworking_select(dev[0], bssid, "home", freq="2412")
  701. interworking_connect(dev[0], bssid, "TTLS")
  702. check_sp_type(dev[0], "home")
  703. def test_ap_hs20_roaming_consortium(dev, apdev):
  704. """Hotspot 2.0 connection based on roaming consortium match"""
  705. bssid = apdev[0]['bssid']
  706. params = hs20_ap_params()
  707. params['hessid'] = bssid
  708. hostapd.add_ap(apdev[0]['ifname'], params)
  709. dev[0].hs20_enable()
  710. for consortium in [ "112233", "1020304050", "010203040506", "fedcba" ]:
  711. id = dev[0].add_cred_values({ 'username': "user",
  712. 'password': "password",
  713. 'domain': "example.com",
  714. 'ca_cert': "auth_serv/ca.pem",
  715. 'roaming_consortium': consortium,
  716. 'eap': "PEAP" })
  717. interworking_select(dev[0], bssid, "home", freq="2412")
  718. interworking_connect(dev[0], bssid, "PEAP")
  719. check_sp_type(dev[0], "home")
  720. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  721. ev = dev[0].wait_event(["INTERWORKING-ALREADY-CONNECTED"], timeout=15)
  722. if ev is None:
  723. raise Exception("Timeout on already-connected event")
  724. dev[0].remove_cred(id)
  725. def test_ap_hs20_username_roaming(dev, apdev):
  726. """Hotspot 2.0 connection in username/password credential (roaming)"""
  727. check_eap_capa(dev[0], "MSCHAPV2")
  728. bssid = apdev[0]['bssid']
  729. params = hs20_ap_params()
  730. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]",
  731. "0,roaming.example.com,21[2:4][5:7]",
  732. "0,another.example.com" ]
  733. params['domain_name'] = "another.example.com"
  734. params['hessid'] = bssid
  735. hostapd.add_ap(apdev[0]['ifname'], params)
  736. dev[0].hs20_enable()
  737. id = dev[0].add_cred_values({ 'realm': "roaming.example.com",
  738. 'username': "hs20-test",
  739. 'password': "password",
  740. 'ca_cert': "auth_serv/ca.pem",
  741. 'domain': "example.com" })
  742. interworking_select(dev[0], bssid, "roaming", freq="2412")
  743. interworking_connect(dev[0], bssid, "TTLS")
  744. check_sp_type(dev[0], "roaming")
  745. def test_ap_hs20_username_unknown(dev, apdev):
  746. """Hotspot 2.0 connection in username/password credential (no domain in cred)"""
  747. check_eap_capa(dev[0], "MSCHAPV2")
  748. bssid = apdev[0]['bssid']
  749. params = hs20_ap_params()
  750. params['hessid'] = bssid
  751. hostapd.add_ap(apdev[0]['ifname'], params)
  752. dev[0].hs20_enable()
  753. id = dev[0].add_cred_values({ 'realm': "example.com",
  754. 'ca_cert': "auth_serv/ca.pem",
  755. 'username': "hs20-test",
  756. 'password': "password" })
  757. interworking_select(dev[0], bssid, "unknown", freq="2412")
  758. interworking_connect(dev[0], bssid, "TTLS")
  759. check_sp_type(dev[0], "unknown")
  760. def test_ap_hs20_username_unknown2(dev, apdev):
  761. """Hotspot 2.0 connection in username/password credential (no domain advertized)"""
  762. check_eap_capa(dev[0], "MSCHAPV2")
  763. bssid = apdev[0]['bssid']
  764. params = hs20_ap_params()
  765. params['hessid'] = bssid
  766. del params['domain_name']
  767. hostapd.add_ap(apdev[0]['ifname'], params)
  768. dev[0].hs20_enable()
  769. id = dev[0].add_cred_values({ 'realm': "example.com",
  770. 'ca_cert': "auth_serv/ca.pem",
  771. 'username': "hs20-test",
  772. 'password': "password",
  773. 'domain': "example.com" })
  774. interworking_select(dev[0], bssid, "unknown", freq="2412")
  775. interworking_connect(dev[0], bssid, "TTLS")
  776. check_sp_type(dev[0], "unknown")
  777. def test_ap_hs20_gas_while_associated(dev, apdev):
  778. """Hotspot 2.0 connection with GAS query while associated"""
  779. check_eap_capa(dev[0], "MSCHAPV2")
  780. bssid = apdev[0]['bssid']
  781. params = hs20_ap_params()
  782. params['hessid'] = bssid
  783. hostapd.add_ap(apdev[0]['ifname'], params)
  784. dev[0].hs20_enable()
  785. id = dev[0].add_cred_values({ 'realm': "example.com",
  786. 'ca_cert': "auth_serv/ca.pem",
  787. 'username': "hs20-test",
  788. 'password': "password",
  789. 'domain': "example.com" })
  790. interworking_select(dev[0], bssid, "home", freq="2412")
  791. interworking_connect(dev[0], bssid, "TTLS")
  792. logger.info("Verifying GAS query while associated")
  793. dev[0].request("FETCH_ANQP")
  794. for i in range(0, 6):
  795. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  796. if ev is None:
  797. raise Exception("Operation timed out")
  798. def test_ap_hs20_gas_while_associated_with_pmf(dev, apdev):
  799. """Hotspot 2.0 connection with GAS query while associated and using PMF"""
  800. check_eap_capa(dev[0], "MSCHAPV2")
  801. try:
  802. _test_ap_hs20_gas_while_associated_with_pmf(dev, apdev)
  803. finally:
  804. dev[0].request("SET pmf 0")
  805. def _test_ap_hs20_gas_while_associated_with_pmf(dev, apdev):
  806. bssid = apdev[0]['bssid']
  807. params = hs20_ap_params()
  808. params['hessid'] = bssid
  809. hostapd.add_ap(apdev[0]['ifname'], params)
  810. bssid2 = apdev[1]['bssid']
  811. params = hs20_ap_params()
  812. params['hessid'] = bssid2
  813. params['nai_realm'] = [ "0,no-match.example.org,13[5:6],21[2:4][5:7]" ]
  814. hostapd.add_ap(apdev[1]['ifname'], params)
  815. dev[0].hs20_enable()
  816. dev[0].request("SET pmf 2")
  817. id = dev[0].add_cred_values({ 'realm': "example.com",
  818. 'ca_cert': "auth_serv/ca.pem",
  819. 'username': "hs20-test",
  820. 'password': "password",
  821. 'domain': "example.com" })
  822. interworking_select(dev[0], bssid, "home", freq="2412")
  823. interworking_connect(dev[0], bssid, "TTLS")
  824. logger.info("Verifying GAS query while associated")
  825. dev[0].request("FETCH_ANQP")
  826. for i in range(0, 2 * 6):
  827. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  828. if ev is None:
  829. raise Exception("Operation timed out")
  830. def test_ap_hs20_gas_frag_while_associated(dev, apdev):
  831. """Hotspot 2.0 connection with fragmented GAS query while associated"""
  832. check_eap_capa(dev[0], "MSCHAPV2")
  833. bssid = apdev[0]['bssid']
  834. params = hs20_ap_params()
  835. params['hessid'] = bssid
  836. hostapd.add_ap(apdev[0]['ifname'], params)
  837. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  838. hapd.set("gas_frag_limit", "50")
  839. dev[0].hs20_enable()
  840. id = dev[0].add_cred_values({ 'realm': "example.com",
  841. 'ca_cert': "auth_serv/ca.pem",
  842. 'username': "hs20-test",
  843. 'password': "password",
  844. 'domain': "example.com" })
  845. interworking_select(dev[0], bssid, "home", freq="2412")
  846. interworking_connect(dev[0], bssid, "TTLS")
  847. logger.info("Verifying GAS query while associated")
  848. dev[0].request("FETCH_ANQP")
  849. for i in range(0, 6):
  850. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  851. if ev is None:
  852. raise Exception("Operation timed out")
  853. def test_ap_hs20_multiple_connects(dev, apdev):
  854. """Hotspot 2.0 connection through multiple network selections"""
  855. check_eap_capa(dev[0], "MSCHAPV2")
  856. bssid = apdev[0]['bssid']
  857. params = hs20_ap_params()
  858. params['hessid'] = bssid
  859. hostapd.add_ap(apdev[0]['ifname'], params)
  860. dev[0].hs20_enable()
  861. values = { 'realm': "example.com",
  862. 'ca_cert': "auth_serv/ca.pem",
  863. 'username': "hs20-test",
  864. 'password': "password",
  865. 'domain': "example.com" }
  866. id = dev[0].add_cred_values(values)
  867. dev[0].scan_for_bss(bssid, freq="2412")
  868. for i in range(0, 3):
  869. logger.info("Starting Interworking network selection")
  870. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  871. while True:
  872. ev = dev[0].wait_event(["INTERWORKING-NO-MATCH",
  873. "INTERWORKING-ALREADY-CONNECTED",
  874. "CTRL-EVENT-CONNECTED"], timeout=15)
  875. if ev is None:
  876. raise Exception("Connection timed out")
  877. if "INTERWORKING-NO-MATCH" in ev:
  878. raise Exception("Matching AP not found")
  879. if "CTRL-EVENT-CONNECTED" in ev:
  880. break
  881. if i == 2 and "INTERWORKING-ALREADY-CONNECTED" in ev:
  882. break
  883. if i == 0:
  884. dev[0].request("DISCONNECT")
  885. dev[0].dump_monitor()
  886. networks = dev[0].list_networks()
  887. if len(networks) > 1:
  888. raise Exception("Duplicated network block detected")
  889. def test_ap_hs20_disallow_aps(dev, apdev):
  890. """Hotspot 2.0 connection and disallow_aps"""
  891. bssid = apdev[0]['bssid']
  892. params = hs20_ap_params()
  893. params['hessid'] = bssid
  894. hostapd.add_ap(apdev[0]['ifname'], params)
  895. dev[0].hs20_enable()
  896. values = { 'realm': "example.com",
  897. 'ca_cert': "auth_serv/ca.pem",
  898. 'username': "hs20-test",
  899. 'password': "password",
  900. 'domain': "example.com" }
  901. id = dev[0].add_cred_values(values)
  902. dev[0].scan_for_bss(bssid, freq="2412")
  903. logger.info("Verify disallow_aps bssid")
  904. dev[0].request("SET disallow_aps bssid " + bssid.translate(None, ':'))
  905. dev[0].request("INTERWORKING_SELECT auto")
  906. ev = dev[0].wait_event(["INTERWORKING-NO-MATCH"], timeout=15)
  907. if ev is None:
  908. raise Exception("Network selection timed out")
  909. dev[0].dump_monitor()
  910. logger.info("Verify disallow_aps ssid")
  911. dev[0].request("SET disallow_aps ssid 746573742d68733230")
  912. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  913. ev = dev[0].wait_event(["INTERWORKING-NO-MATCH"], timeout=15)
  914. if ev is None:
  915. raise Exception("Network selection timed out")
  916. dev[0].dump_monitor()
  917. logger.info("Verify disallow_aps clear")
  918. dev[0].request("SET disallow_aps ")
  919. interworking_select(dev[0], bssid, "home", freq="2412")
  920. dev[0].request("SET disallow_aps bssid " + bssid.translate(None, ':'))
  921. ret = dev[0].request("INTERWORKING_CONNECT " + bssid)
  922. if "FAIL" not in ret:
  923. raise Exception("INTERWORKING_CONNECT to disallowed BSS not rejected")
  924. if "FAIL" not in dev[0].request("INTERWORKING_CONNECT foo"):
  925. raise Exception("Invalid INTERWORKING_CONNECT not rejected")
  926. if "FAIL" not in dev[0].request("INTERWORKING_CONNECT 00:11:22:33:44:55"):
  927. raise Exception("Invalid INTERWORKING_CONNECT not rejected")
  928. def policy_test(dev, ap, values, only_one=True):
  929. dev.dump_monitor()
  930. if ap:
  931. logger.info("Verify network selection to AP " + ap['ifname'])
  932. bssid = ap['bssid']
  933. dev.scan_for_bss(bssid, freq="2412")
  934. else:
  935. logger.info("Verify network selection")
  936. bssid = None
  937. dev.hs20_enable()
  938. id = dev.add_cred_values(values)
  939. dev.request("INTERWORKING_SELECT auto freq=2412")
  940. events = []
  941. while True:
  942. ev = dev.wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH",
  943. "INTERWORKING-BLACKLISTED",
  944. "INTERWORKING-SELECTED"], timeout=15)
  945. if ev is None:
  946. raise Exception("Network selection timed out")
  947. events.append(ev)
  948. if "INTERWORKING-NO-MATCH" in ev:
  949. raise Exception("Matching AP not found")
  950. if bssid and only_one and "INTERWORKING-AP" in ev and bssid not in ev:
  951. raise Exception("Unexpected AP claimed acceptable")
  952. if "INTERWORKING-SELECTED" in ev:
  953. if bssid and bssid not in ev:
  954. raise Exception("Selected incorrect BSS")
  955. break
  956. ev = dev.wait_connected(timeout=15)
  957. if bssid and bssid not in ev:
  958. raise Exception("Connected to incorrect BSS")
  959. conn_bssid = dev.get_status_field("bssid")
  960. if bssid and conn_bssid != bssid:
  961. raise Exception("bssid information points to incorrect BSS")
  962. dev.remove_cred(id)
  963. dev.dump_monitor()
  964. return events
  965. def default_cred(domain=None, user="hs20-test"):
  966. cred = { 'realm': "example.com",
  967. 'ca_cert': "auth_serv/ca.pem",
  968. 'username': user,
  969. 'password': "password" }
  970. if domain:
  971. cred['domain'] = domain
  972. return cred
  973. def test_ap_hs20_prefer_home(dev, apdev):
  974. """Hotspot 2.0 required roaming consortium"""
  975. check_eap_capa(dev[0], "MSCHAPV2")
  976. params = hs20_ap_params()
  977. params['domain_name'] = "example.org"
  978. hostapd.add_ap(apdev[0]['ifname'], params)
  979. params = hs20_ap_params()
  980. params['ssid'] = "test-hs20-other"
  981. params['domain_name'] = "example.com"
  982. hostapd.add_ap(apdev[1]['ifname'], params)
  983. values = default_cred()
  984. values['domain'] = "example.com"
  985. policy_test(dev[0], apdev[1], values, only_one=False)
  986. values['domain'] = "example.org"
  987. policy_test(dev[0], apdev[0], values, only_one=False)
  988. def test_ap_hs20_req_roaming_consortium(dev, apdev):
  989. """Hotspot 2.0 required roaming consortium"""
  990. check_eap_capa(dev[0], "MSCHAPV2")
  991. params = hs20_ap_params()
  992. hostapd.add_ap(apdev[0]['ifname'], params)
  993. params = hs20_ap_params()
  994. params['ssid'] = "test-hs20-other"
  995. params['roaming_consortium'] = [ "223344" ]
  996. hostapd.add_ap(apdev[1]['ifname'], params)
  997. values = default_cred()
  998. values['required_roaming_consortium'] = "223344"
  999. policy_test(dev[0], apdev[1], values)
  1000. values['required_roaming_consortium'] = "112233"
  1001. policy_test(dev[0], apdev[0], values)
  1002. id = dev[0].add_cred()
  1003. dev[0].set_cred(id, "required_roaming_consortium", "112233")
  1004. dev[0].set_cred(id, "required_roaming_consortium", "112233445566778899aabbccddeeff")
  1005. for val in [ "", "1", "11", "1122", "1122334", "112233445566778899aabbccddeeff00" ]:
  1006. if "FAIL" not in dev[0].request('SET_CRED {} required_roaming_consortium {}'.format(id, val)):
  1007. raise Exception("Invalid roaming consortium value accepted: " + val)
  1008. def test_ap_hs20_excluded_ssid(dev, apdev):
  1009. """Hotspot 2.0 exclusion based on SSID"""
  1010. check_eap_capa(dev[0], "MSCHAPV2")
  1011. params = hs20_ap_params()
  1012. params['roaming_consortium'] = [ "223344" ]
  1013. params['anqp_3gpp_cell_net'] = "555,444"
  1014. hostapd.add_ap(apdev[0]['ifname'], params)
  1015. params = hs20_ap_params()
  1016. params['ssid'] = "test-hs20-other"
  1017. params['roaming_consortium'] = [ "223344" ]
  1018. params['anqp_3gpp_cell_net'] = "555,444"
  1019. hostapd.add_ap(apdev[1]['ifname'], params)
  1020. values = default_cred()
  1021. values['excluded_ssid'] = "test-hs20"
  1022. events = policy_test(dev[0], apdev[1], values)
  1023. ev = [e for e in events if "INTERWORKING-BLACKLISTED " + apdev[0]['bssid'] in e]
  1024. if len(ev) != 1:
  1025. raise Exception("Excluded network not reported")
  1026. values['excluded_ssid'] = "test-hs20-other"
  1027. events = policy_test(dev[0], apdev[0], values)
  1028. ev = [e for e in events if "INTERWORKING-BLACKLISTED " + apdev[1]['bssid'] in e]
  1029. if len(ev) != 1:
  1030. raise Exception("Excluded network not reported")
  1031. values = default_cred()
  1032. values['roaming_consortium'] = "223344"
  1033. values['eap'] = "TTLS"
  1034. values['phase2'] = "auth=MSCHAPV2"
  1035. values['excluded_ssid'] = "test-hs20"
  1036. events = policy_test(dev[0], apdev[1], values)
  1037. ev = [e for e in events if "INTERWORKING-BLACKLISTED " + apdev[0]['bssid'] in e]
  1038. if len(ev) != 1:
  1039. raise Exception("Excluded network not reported")
  1040. values = { 'imsi': "555444-333222111", 'eap': "SIM",
  1041. 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  1042. 'excluded_ssid': "test-hs20" }
  1043. events = policy_test(dev[0], apdev[1], values)
  1044. ev = [e for e in events if "INTERWORKING-BLACKLISTED " + apdev[0]['bssid'] in e]
  1045. if len(ev) != 1:
  1046. raise Exception("Excluded network not reported")
  1047. def test_ap_hs20_roam_to_higher_prio(dev, apdev):
  1048. """Hotspot 2.0 and roaming from current to higher priority network"""
  1049. check_eap_capa(dev[0], "MSCHAPV2")
  1050. bssid = apdev[0]['bssid']
  1051. params = hs20_ap_params(ssid="test-hs20-visited")
  1052. params['domain_name'] = "visited.example.org"
  1053. hostapd.add_ap(apdev[0]['ifname'], params)
  1054. dev[0].hs20_enable()
  1055. id = dev[0].add_cred_values({ 'realm': "example.com",
  1056. 'ca_cert': "auth_serv/ca.pem",
  1057. 'username': "hs20-test",
  1058. 'password': "password",
  1059. 'domain': "example.com" })
  1060. logger.info("Connect to the only network option")
  1061. interworking_select(dev[0], bssid, "roaming", freq="2412")
  1062. dev[0].dump_monitor()
  1063. interworking_connect(dev[0], bssid, "TTLS")
  1064. logger.info("Start another AP (home operator) and reconnect")
  1065. bssid2 = apdev[1]['bssid']
  1066. params = hs20_ap_params(ssid="test-hs20-home")
  1067. params['domain_name'] = "example.com"
  1068. hostapd.add_ap(apdev[1]['ifname'], params)
  1069. dev[0].scan_for_bss(bssid2, freq="2412", force_scan=True)
  1070. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1071. ev = dev[0].wait_event(["INTERWORKING-NO-MATCH",
  1072. "INTERWORKING-ALREADY-CONNECTED",
  1073. "CTRL-EVENT-CONNECTED"], timeout=15)
  1074. if ev is None:
  1075. raise Exception("Connection timed out")
  1076. if "INTERWORKING-NO-MATCH" in ev:
  1077. raise Exception("Matching AP not found")
  1078. if "INTERWORKING-ALREADY-CONNECTED" in ev:
  1079. raise Exception("Unexpected AP selected")
  1080. if bssid2 not in ev:
  1081. raise Exception("Unexpected BSSID after reconnection")
  1082. def test_ap_hs20_domain_suffix_match_full(dev, apdev):
  1083. """Hotspot 2.0 and domain_suffix_match"""
  1084. check_eap_capa(dev[0], "MSCHAPV2")
  1085. bssid = apdev[0]['bssid']
  1086. params = hs20_ap_params()
  1087. hostapd.add_ap(apdev[0]['ifname'], params)
  1088. dev[0].hs20_enable()
  1089. id = dev[0].add_cred_values({ 'realm': "example.com",
  1090. 'username': "hs20-test",
  1091. 'password': "password",
  1092. 'ca_cert': "auth_serv/ca.pem",
  1093. 'domain': "example.com",
  1094. 'domain_suffix_match': "server.w1.fi" })
  1095. interworking_select(dev[0], bssid, "home", freq="2412")
  1096. dev[0].dump_monitor()
  1097. interworking_connect(dev[0], bssid, "TTLS")
  1098. dev[0].request("REMOVE_NETWORK all")
  1099. dev[0].dump_monitor()
  1100. dev[0].set_cred_quoted(id, "domain_suffix_match", "no-match.example.com")
  1101. interworking_select(dev[0], bssid, "home", freq="2412")
  1102. dev[0].dump_monitor()
  1103. dev[0].request("INTERWORKING_CONNECT " + bssid)
  1104. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"])
  1105. if ev is None:
  1106. raise Exception("TLS certificate error not reported")
  1107. if "Domain suffix mismatch" not in ev:
  1108. raise Exception("Domain suffix mismatch not reported")
  1109. def test_ap_hs20_domain_suffix_match(dev, apdev):
  1110. """Hotspot 2.0 and domain_suffix_match"""
  1111. check_eap_capa(dev[0], "MSCHAPV2")
  1112. check_domain_match_full(dev[0])
  1113. bssid = apdev[0]['bssid']
  1114. params = hs20_ap_params()
  1115. hostapd.add_ap(apdev[0]['ifname'], params)
  1116. dev[0].hs20_enable()
  1117. id = dev[0].add_cred_values({ 'realm': "example.com",
  1118. 'username': "hs20-test",
  1119. 'password': "password",
  1120. 'ca_cert': "auth_serv/ca.pem",
  1121. 'domain': "example.com",
  1122. 'domain_suffix_match': "w1.fi" })
  1123. interworking_select(dev[0], bssid, "home", freq="2412")
  1124. dev[0].dump_monitor()
  1125. interworking_connect(dev[0], bssid, "TTLS")
  1126. def test_ap_hs20_roaming_partner_preference(dev, apdev):
  1127. """Hotspot 2.0 and roaming partner preference"""
  1128. check_eap_capa(dev[0], "MSCHAPV2")
  1129. params = hs20_ap_params()
  1130. params['domain_name'] = "roaming.example.org"
  1131. hostapd.add_ap(apdev[0]['ifname'], params)
  1132. params = hs20_ap_params()
  1133. params['ssid'] = "test-hs20-other"
  1134. params['domain_name'] = "roaming.example.net"
  1135. hostapd.add_ap(apdev[1]['ifname'], params)
  1136. logger.info("Verify default vs. specified preference")
  1137. values = default_cred()
  1138. values['roaming_partner'] = "roaming.example.net,1,127,*"
  1139. policy_test(dev[0], apdev[1], values, only_one=False)
  1140. values['roaming_partner'] = "roaming.example.net,1,129,*"
  1141. policy_test(dev[0], apdev[0], values, only_one=False)
  1142. logger.info("Verify partial FQDN match")
  1143. values['roaming_partner'] = "example.net,0,0,*"
  1144. policy_test(dev[0], apdev[1], values, only_one=False)
  1145. values['roaming_partner'] = "example.net,0,255,*"
  1146. policy_test(dev[0], apdev[0], values, only_one=False)
  1147. def test_ap_hs20_max_bss_load(dev, apdev):
  1148. """Hotspot 2.0 and maximum BSS load"""
  1149. check_eap_capa(dev[0], "MSCHAPV2")
  1150. params = hs20_ap_params()
  1151. params['bss_load_test'] = "12:200:20000"
  1152. hostapd.add_ap(apdev[0]['ifname'], params)
  1153. params = hs20_ap_params()
  1154. params['ssid'] = "test-hs20-other"
  1155. params['bss_load_test'] = "5:20:10000"
  1156. hostapd.add_ap(apdev[1]['ifname'], params)
  1157. logger.info("Verify maximum BSS load constraint")
  1158. values = default_cred()
  1159. values['domain'] = "example.com"
  1160. values['max_bss_load'] = "100"
  1161. events = policy_test(dev[0], apdev[1], values, only_one=False)
  1162. ev = [e for e in events if "INTERWORKING-AP " + apdev[0]['bssid'] in e]
  1163. if len(ev) != 1 or "over_max_bss_load=1" not in ev[0]:
  1164. raise Exception("Maximum BSS Load case not noticed")
  1165. ev = [e for e in events if "INTERWORKING-AP " + apdev[1]['bssid'] in e]
  1166. if len(ev) != 1 or "over_max_bss_load=1" in ev[0]:
  1167. raise Exception("Maximum BSS Load case reported incorrectly")
  1168. logger.info("Verify maximum BSS load does not prevent connection")
  1169. values['max_bss_load'] = "1"
  1170. events = policy_test(dev[0], None, values)
  1171. ev = [e for e in events if "INTERWORKING-AP " + apdev[0]['bssid'] in e]
  1172. if len(ev) != 1 or "over_max_bss_load=1" not in ev[0]:
  1173. raise Exception("Maximum BSS Load case not noticed")
  1174. ev = [e for e in events if "INTERWORKING-AP " + apdev[1]['bssid'] in e]
  1175. if len(ev) != 1 or "over_max_bss_load=1" not in ev[0]:
  1176. raise Exception("Maximum BSS Load case not noticed")
  1177. def test_ap_hs20_max_bss_load2(dev, apdev):
  1178. """Hotspot 2.0 and maximum BSS load with one AP not advertising"""
  1179. check_eap_capa(dev[0], "MSCHAPV2")
  1180. params = hs20_ap_params()
  1181. params['bss_load_test'] = "12:200:20000"
  1182. hostapd.add_ap(apdev[0]['ifname'], params)
  1183. params = hs20_ap_params()
  1184. params['ssid'] = "test-hs20-other"
  1185. hostapd.add_ap(apdev[1]['ifname'], params)
  1186. logger.info("Verify maximum BSS load constraint with AP advertisement")
  1187. values = default_cred()
  1188. values['domain'] = "example.com"
  1189. values['max_bss_load'] = "100"
  1190. events = policy_test(dev[0], apdev[1], values, only_one=False)
  1191. ev = [e for e in events if "INTERWORKING-AP " + apdev[0]['bssid'] in e]
  1192. if len(ev) != 1 or "over_max_bss_load=1" not in ev[0]:
  1193. raise Exception("Maximum BSS Load case not noticed")
  1194. ev = [e for e in events if "INTERWORKING-AP " + apdev[1]['bssid'] in e]
  1195. if len(ev) != 1 or "over_max_bss_load=1" in ev[0]:
  1196. raise Exception("Maximum BSS Load case reported incorrectly")
  1197. def test_ap_hs20_multi_cred_sp_prio(dev, apdev):
  1198. """Hotspot 2.0 multi-cred sp_priority"""
  1199. check_eap_capa(dev[0], "MSCHAPV2")
  1200. try:
  1201. _test_ap_hs20_multi_cred_sp_prio(dev, apdev)
  1202. finally:
  1203. dev[0].request("SET external_sim 0")
  1204. def _test_ap_hs20_multi_cred_sp_prio(dev, apdev):
  1205. hlr_auc_gw_available()
  1206. bssid = apdev[0]['bssid']
  1207. params = hs20_ap_params()
  1208. params['hessid'] = bssid
  1209. del params['domain_name']
  1210. params['anqp_3gpp_cell_net'] = "232,01"
  1211. hostapd.add_ap(apdev[0]['ifname'], params)
  1212. dev[0].hs20_enable()
  1213. dev[0].scan_for_bss(bssid, freq="2412")
  1214. dev[0].request("SET external_sim 1")
  1215. id1 = dev[0].add_cred_values({ 'imsi': "23201-0000000000", 'eap': "SIM",
  1216. 'provisioning_sp': "example.com",
  1217. 'sp_priority' :"1" })
  1218. id2 = dev[0].add_cred_values({ 'realm': "example.com",
  1219. 'ca_cert': "auth_serv/ca.pem",
  1220. 'username': "hs20-test",
  1221. 'password': "password",
  1222. 'domain': "example.com",
  1223. 'provisioning_sp': "example.com",
  1224. 'sp_priority': "2" })
  1225. dev[0].dump_monitor()
  1226. dev[0].scan_for_bss(bssid, freq="2412")
  1227. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1228. interworking_ext_sim_auth(dev[0], "SIM")
  1229. check_sp_type(dev[0], "unknown")
  1230. dev[0].request("REMOVE_NETWORK all")
  1231. dev[0].set_cred(id1, "sp_priority", "2")
  1232. dev[0].set_cred(id2, "sp_priority", "1")
  1233. dev[0].dump_monitor()
  1234. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1235. interworking_auth(dev[0], "TTLS")
  1236. check_sp_type(dev[0], "unknown")
  1237. def test_ap_hs20_multi_cred_sp_prio2(dev, apdev):
  1238. """Hotspot 2.0 multi-cred sp_priority with two BSSes"""
  1239. check_eap_capa(dev[0], "MSCHAPV2")
  1240. try:
  1241. _test_ap_hs20_multi_cred_sp_prio2(dev, apdev)
  1242. finally:
  1243. dev[0].request("SET external_sim 0")
  1244. def _test_ap_hs20_multi_cred_sp_prio2(dev, apdev):
  1245. hlr_auc_gw_available()
  1246. bssid = apdev[0]['bssid']
  1247. params = hs20_ap_params()
  1248. params['hessid'] = bssid
  1249. del params['nai_realm']
  1250. del params['domain_name']
  1251. params['anqp_3gpp_cell_net'] = "232,01"
  1252. hostapd.add_ap(apdev[0]['ifname'], params)
  1253. bssid2 = apdev[1]['bssid']
  1254. params = hs20_ap_params()
  1255. params['ssid'] = "test-hs20-other"
  1256. params['hessid'] = bssid2
  1257. del params['domain_name']
  1258. del params['anqp_3gpp_cell_net']
  1259. hostapd.add_ap(apdev[1]['ifname'], params)
  1260. dev[0].hs20_enable()
  1261. dev[0].request("SET external_sim 1")
  1262. id1 = dev[0].add_cred_values({ 'imsi': "23201-0000000000", 'eap': "SIM",
  1263. 'provisioning_sp': "example.com",
  1264. 'sp_priority': "1" })
  1265. id2 = dev[0].add_cred_values({ 'realm': "example.com",
  1266. 'ca_cert': "auth_serv/ca.pem",
  1267. 'username': "hs20-test",
  1268. 'password': "password",
  1269. 'domain': "example.com",
  1270. 'provisioning_sp': "example.com",
  1271. 'sp_priority': "2" })
  1272. dev[0].dump_monitor()
  1273. dev[0].scan_for_bss(bssid, freq="2412")
  1274. dev[0].scan_for_bss(bssid2, freq="2412")
  1275. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1276. interworking_ext_sim_auth(dev[0], "SIM")
  1277. check_sp_type(dev[0], "unknown")
  1278. conn_bssid = dev[0].get_status_field("bssid")
  1279. if conn_bssid != bssid:
  1280. raise Exception("Connected to incorrect BSS")
  1281. dev[0].request("REMOVE_NETWORK all")
  1282. dev[0].set_cred(id1, "sp_priority", "2")
  1283. dev[0].set_cred(id2, "sp_priority", "1")
  1284. dev[0].dump_monitor()
  1285. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1286. interworking_auth(dev[0], "TTLS")
  1287. check_sp_type(dev[0], "unknown")
  1288. conn_bssid = dev[0].get_status_field("bssid")
  1289. if conn_bssid != bssid2:
  1290. raise Exception("Connected to incorrect BSS")
  1291. def check_conn_capab_selection(dev, type, missing):
  1292. dev.request("INTERWORKING_SELECT freq=2412")
  1293. ev = dev.wait_event(["INTERWORKING-AP"])
  1294. if ev is None:
  1295. raise Exception("Network selection timed out");
  1296. if "type=" + type not in ev:
  1297. raise Exception("Unexpected network type")
  1298. if missing and "conn_capab_missing=1" not in ev:
  1299. raise Exception("conn_capab_missing not reported")
  1300. if not missing and "conn_capab_missing=1" in ev:
  1301. raise Exception("conn_capab_missing reported unexpectedly")
  1302. def conn_capab_cred(domain=None, req_conn_capab=None):
  1303. cred = default_cred(domain=domain)
  1304. if req_conn_capab:
  1305. cred['req_conn_capab'] = req_conn_capab
  1306. return cred
  1307. def test_ap_hs20_req_conn_capab(dev, apdev):
  1308. """Hotspot 2.0 network selection with req_conn_capab"""
  1309. check_eap_capa(dev[0], "MSCHAPV2")
  1310. bssid = apdev[0]['bssid']
  1311. params = hs20_ap_params()
  1312. hostapd.add_ap(apdev[0]['ifname'], params)
  1313. dev[0].hs20_enable()
  1314. dev[0].scan_for_bss(bssid, freq="2412")
  1315. logger.info("Not used in home network")
  1316. values = conn_capab_cred(domain="example.com", req_conn_capab="6:1234")
  1317. id = dev[0].add_cred_values(values)
  1318. check_conn_capab_selection(dev[0], "home", False)
  1319. logger.info("Used in roaming network")
  1320. dev[0].remove_cred(id)
  1321. values = conn_capab_cred(domain="example.org", req_conn_capab="6:1234")
  1322. id = dev[0].add_cred_values(values)
  1323. check_conn_capab_selection(dev[0], "roaming", True)
  1324. logger.info("Verify that req_conn_capab does not prevent connection if no other network is available")
  1325. check_auto_select(dev[0], bssid)
  1326. logger.info("Additional req_conn_capab checks")
  1327. dev[0].remove_cred(id)
  1328. values = conn_capab_cred(domain="example.org", req_conn_capab="1:0")
  1329. id = dev[0].add_cred_values(values)
  1330. check_conn_capab_selection(dev[0], "roaming", True)
  1331. dev[0].remove_cred(id)
  1332. values = conn_capab_cred(domain="example.org", req_conn_capab="17:5060")
  1333. id = dev[0].add_cred_values(values)
  1334. check_conn_capab_selection(dev[0], "roaming", True)
  1335. bssid2 = apdev[1]['bssid']
  1336. params = hs20_ap_params(ssid="test-hs20b")
  1337. params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0", "50:0:1" ]
  1338. hostapd.add_ap(apdev[1]['ifname'], params)
  1339. dev[0].remove_cred(id)
  1340. values = conn_capab_cred(domain="example.org", req_conn_capab="50")
  1341. id = dev[0].add_cred_values(values)
  1342. dev[0].set_cred(id, "req_conn_capab", "6:22")
  1343. dev[0].scan_for_bss(bssid2, freq="2412")
  1344. dev[0].request("INTERWORKING_SELECT freq=2412")
  1345. for i in range(0, 2):
  1346. ev = dev[0].wait_event(["INTERWORKING-AP"])
  1347. if ev is None:
  1348. raise Exception("Network selection timed out");
  1349. if bssid in ev and "conn_capab_missing=1" not in ev:
  1350. raise Exception("Missing protocol connection capability not reported")
  1351. if bssid2 in ev and "conn_capab_missing=1" in ev:
  1352. raise Exception("Protocol connection capability not reported correctly")
  1353. def test_ap_hs20_req_conn_capab_and_roaming_partner_preference(dev, apdev):
  1354. """Hotspot 2.0 and req_conn_capab with roaming partner preference"""
  1355. check_eap_capa(dev[0], "MSCHAPV2")
  1356. bssid = apdev[0]['bssid']
  1357. params = hs20_ap_params()
  1358. params['domain_name'] = "roaming.example.org"
  1359. params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0", "50:0:1" ]
  1360. hostapd.add_ap(apdev[0]['ifname'], params)
  1361. bssid2 = apdev[1]['bssid']
  1362. params = hs20_ap_params(ssid="test-hs20-b")
  1363. params['domain_name'] = "roaming.example.net"
  1364. hostapd.add_ap(apdev[1]['ifname'], params)
  1365. values = default_cred()
  1366. values['roaming_partner'] = "roaming.example.net,1,127,*"
  1367. id = dev[0].add_cred_values(values)
  1368. check_auto_select(dev[0], bssid2)
  1369. dev[0].set_cred(id, "req_conn_capab", "50")
  1370. check_auto_select(dev[0], bssid)
  1371. dev[0].remove_cred(id)
  1372. id = dev[0].add_cred_values(values)
  1373. dev[0].set_cred(id, "req_conn_capab", "51")
  1374. check_auto_select(dev[0], bssid2)
  1375. def check_bandwidth_selection(dev, type, below):
  1376. dev.request("INTERWORKING_SELECT freq=2412")
  1377. ev = dev.wait_event(["INTERWORKING-AP"])
  1378. if ev is None:
  1379. raise Exception("Network selection timed out");
  1380. logger.debug("BSS entries:\n" + dev.request("BSS RANGE=ALL"))
  1381. if "type=" + type not in ev:
  1382. raise Exception("Unexpected network type")
  1383. if below and "below_min_backhaul=1" not in ev:
  1384. raise Exception("below_min_backhaul not reported")
  1385. if not below and "below_min_backhaul=1" in ev:
  1386. raise Exception("below_min_backhaul reported unexpectedly")
  1387. def bw_cred(domain=None, dl_home=None, ul_home=None, dl_roaming=None, ul_roaming=None):
  1388. cred = default_cred(domain=domain)
  1389. if dl_home:
  1390. cred['min_dl_bandwidth_home'] = str(dl_home)
  1391. if ul_home:
  1392. cred['min_ul_bandwidth_home'] = str(ul_home)
  1393. if dl_roaming:
  1394. cred['min_dl_bandwidth_roaming'] = str(dl_roaming)
  1395. if ul_roaming:
  1396. cred['min_ul_bandwidth_roaming'] = str(ul_roaming)
  1397. return cred
  1398. def test_ap_hs20_min_bandwidth_home(dev, apdev):
  1399. """Hotspot 2.0 network selection with min bandwidth (home)"""
  1400. check_eap_capa(dev[0], "MSCHAPV2")
  1401. bssid = apdev[0]['bssid']
  1402. params = hs20_ap_params()
  1403. hostapd.add_ap(apdev[0]['ifname'], params)
  1404. dev[0].hs20_enable()
  1405. dev[0].scan_for_bss(bssid, freq="2412")
  1406. values = bw_cred(domain="example.com", dl_home=5490, ul_home=58)
  1407. id = dev[0].add_cred_values(values)
  1408. check_bandwidth_selection(dev[0], "home", False)
  1409. dev[0].remove_cred(id)
  1410. values = bw_cred(domain="example.com", dl_home=5491, ul_home=58)
  1411. id = dev[0].add_cred_values(values)
  1412. check_bandwidth_selection(dev[0], "home", True)
  1413. dev[0].remove_cred(id)
  1414. values = bw_cred(domain="example.com", dl_home=5490, ul_home=59)
  1415. id = dev[0].add_cred_values(values)
  1416. check_bandwidth_selection(dev[0], "home", True)
  1417. dev[0].remove_cred(id)
  1418. values = bw_cred(domain="example.com", dl_home=5491, ul_home=59)
  1419. id = dev[0].add_cred_values(values)
  1420. check_bandwidth_selection(dev[0], "home", True)
  1421. check_auto_select(dev[0], bssid)
  1422. bssid2 = apdev[1]['bssid']
  1423. params = hs20_ap_params(ssid="test-hs20-b")
  1424. params['hs20_wan_metrics'] = "01:8000:1000:1:1:3000"
  1425. hostapd.add_ap(apdev[1]['ifname'], params)
  1426. check_auto_select(dev[0], bssid2)
  1427. def test_ap_hs20_min_bandwidth_home_hidden_ssid_in_scan_res(dev, apdev):
  1428. """Hotspot 2.0 network selection with min bandwidth (home) while hidden SSID is included in scan results"""
  1429. check_eap_capa(dev[0], "MSCHAPV2")
  1430. bssid = apdev[0]['bssid']
  1431. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'secret',
  1432. "ignore_broadcast_ssid": "1" })
  1433. dev[0].scan_for_bss(bssid, freq=2412)
  1434. hapd.disable()
  1435. hapd_global = hostapd.HostapdGlobal()
  1436. hapd_global.flush()
  1437. hapd_global.remove(apdev[0]['ifname'])
  1438. params = hs20_ap_params()
  1439. hostapd.add_ap(apdev[0]['ifname'], params)
  1440. dev[0].hs20_enable()
  1441. dev[0].scan_for_bss(bssid, freq="2412")
  1442. values = bw_cred(domain="example.com", dl_home=5490, ul_home=58)
  1443. id = dev[0].add_cred_values(values)
  1444. check_bandwidth_selection(dev[0], "home", False)
  1445. dev[0].remove_cred(id)
  1446. values = bw_cred(domain="example.com", dl_home=5491, ul_home=58)
  1447. id = dev[0].add_cred_values(values)
  1448. check_bandwidth_selection(dev[0], "home", True)
  1449. dev[0].remove_cred(id)
  1450. values = bw_cred(domain="example.com", dl_home=5490, ul_home=59)
  1451. id = dev[0].add_cred_values(values)
  1452. check_bandwidth_selection(dev[0], "home", True)
  1453. dev[0].remove_cred(id)
  1454. values = bw_cred(domain="example.com", dl_home=5491, ul_home=59)
  1455. id = dev[0].add_cred_values(values)
  1456. check_bandwidth_selection(dev[0], "home", True)
  1457. check_auto_select(dev[0], bssid)
  1458. bssid2 = apdev[1]['bssid']
  1459. params = hs20_ap_params(ssid="test-hs20-b")
  1460. params['hs20_wan_metrics'] = "01:8000:1000:1:1:3000"
  1461. hostapd.add_ap(apdev[1]['ifname'], params)
  1462. check_auto_select(dev[0], bssid2)
  1463. dev[0].flush_scan_cache()
  1464. def test_ap_hs20_min_bandwidth_roaming(dev, apdev):
  1465. """Hotspot 2.0 network selection with min bandwidth (roaming)"""
  1466. check_eap_capa(dev[0], "MSCHAPV2")
  1467. bssid = apdev[0]['bssid']
  1468. params = hs20_ap_params()
  1469. hostapd.add_ap(apdev[0]['ifname'], params)
  1470. dev[0].hs20_enable()
  1471. dev[0].scan_for_bss(bssid, freq="2412")
  1472. values = bw_cred(domain="example.org", dl_roaming=5490, ul_roaming=58)
  1473. id = dev[0].add_cred_values(values)
  1474. check_bandwidth_selection(dev[0], "roaming", False)
  1475. dev[0].remove_cred(id)
  1476. values = bw_cred(domain="example.org", dl_roaming=5491, ul_roaming=58)
  1477. id = dev[0].add_cred_values(values)
  1478. check_bandwidth_selection(dev[0], "roaming", True)
  1479. dev[0].remove_cred(id)
  1480. values = bw_cred(domain="example.org", dl_roaming=5490, ul_roaming=59)
  1481. id = dev[0].add_cred_values(values)
  1482. check_bandwidth_selection(dev[0], "roaming", True)
  1483. dev[0].remove_cred(id)
  1484. values = bw_cred(domain="example.org", dl_roaming=5491, ul_roaming=59)
  1485. id = dev[0].add_cred_values(values)
  1486. check_bandwidth_selection(dev[0], "roaming", True)
  1487. check_auto_select(dev[0], bssid)
  1488. bssid2 = apdev[1]['bssid']
  1489. params = hs20_ap_params(ssid="test-hs20-b")
  1490. params['hs20_wan_metrics'] = "01:8000:1000:1:1:3000"
  1491. hostapd.add_ap(apdev[1]['ifname'], params)
  1492. check_auto_select(dev[0], bssid2)
  1493. def test_ap_hs20_min_bandwidth_and_roaming_partner_preference(dev, apdev):
  1494. """Hotspot 2.0 and minimum bandwidth with roaming partner preference"""
  1495. check_eap_capa(dev[0], "MSCHAPV2")
  1496. bssid = apdev[0]['bssid']
  1497. params = hs20_ap_params()
  1498. params['domain_name'] = "roaming.example.org"
  1499. params['hs20_wan_metrics'] = "01:8000:1000:1:1:3000"
  1500. hostapd.add_ap(apdev[0]['ifname'], params)
  1501. bssid2 = apdev[1]['bssid']
  1502. params = hs20_ap_params(ssid="test-hs20-b")
  1503. params['domain_name'] = "roaming.example.net"
  1504. hostapd.add_ap(apdev[1]['ifname'], params)
  1505. values = default_cred()
  1506. values['roaming_partner'] = "roaming.example.net,1,127,*"
  1507. id = dev[0].add_cred_values(values)
  1508. check_auto_select(dev[0], bssid2)
  1509. dev[0].set_cred(id, "min_dl_bandwidth_roaming", "6000")
  1510. check_auto_select(dev[0], bssid)
  1511. dev[0].set_cred(id, "min_dl_bandwidth_roaming", "10000")
  1512. check_auto_select(dev[0], bssid2)
  1513. def test_ap_hs20_min_bandwidth_no_wan_metrics(dev, apdev):
  1514. """Hotspot 2.0 network selection with min bandwidth but no WAN Metrics"""
  1515. bssid = apdev[0]['bssid']
  1516. params = hs20_ap_params()
  1517. del params['hs20_wan_metrics']
  1518. hostapd.add_ap(apdev[0]['ifname'], params)
  1519. dev[0].hs20_enable()
  1520. dev[0].scan_for_bss(bssid, freq="2412")
  1521. values = bw_cred(domain="example.com", dl_home=10000, ul_home=10000,
  1522. dl_roaming=10000, ul_roaming=10000)
  1523. dev[0].add_cred_values(values)
  1524. check_bandwidth_selection(dev[0], "home", False)
  1525. def test_ap_hs20_deauth_req_ess(dev, apdev):
  1526. """Hotspot 2.0 connection and deauthentication request for ESS"""
  1527. check_eap_capa(dev[0], "MSCHAPV2")
  1528. try:
  1529. _test_ap_hs20_deauth_req_ess(dev, apdev)
  1530. finally:
  1531. dev[0].request("SET pmf 0")
  1532. def _test_ap_hs20_deauth_req_ess(dev, apdev):
  1533. dev[0].request("SET pmf 2")
  1534. eap_test(dev[0], apdev[0], "21[3:26]", "TTLS", "user")
  1535. dev[0].dump_monitor()
  1536. addr = dev[0].p2p_interface_addr()
  1537. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  1538. hapd.request("HS20_DEAUTH_REQ " + addr + " 1 120 http://example.com/")
  1539. ev = dev[0].wait_event(["HS20-DEAUTH-IMMINENT-NOTICE"])
  1540. if ev is None:
  1541. raise Exception("Timeout on deauth imminent notice")
  1542. if "1 120 http://example.com/" not in ev:
  1543. raise Exception("Unexpected deauth imminent notice: " + ev)
  1544. hapd.request("DEAUTHENTICATE " + addr)
  1545. dev[0].wait_disconnected(timeout=10)
  1546. if "[TEMP-DISABLED]" not in dev[0].list_networks()[0]['flags']:
  1547. raise Exception("Network not marked temporarily disabled")
  1548. ev = dev[0].wait_event(["SME: Trying to authenticate",
  1549. "Trying to associate",
  1550. "CTRL-EVENT-CONNECTED"], timeout=5)
  1551. if ev is not None:
  1552. raise Exception("Unexpected connection attempt")
  1553. def test_ap_hs20_deauth_req_bss(dev, apdev):
  1554. """Hotspot 2.0 connection and deauthentication request for BSS"""
  1555. check_eap_capa(dev[0], "MSCHAPV2")
  1556. try:
  1557. _test_ap_hs20_deauth_req_bss(dev, apdev)
  1558. finally:
  1559. dev[0].request("SET pmf 0")
  1560. def _test_ap_hs20_deauth_req_bss(dev, apdev):
  1561. dev[0].request("SET pmf 2")
  1562. eap_test(dev[0], apdev[0], "21[3:26]", "TTLS", "user")
  1563. dev[0].dump_monitor()
  1564. addr = dev[0].p2p_interface_addr()
  1565. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  1566. hapd.request("HS20_DEAUTH_REQ " + addr + " 0 120 http://example.com/")
  1567. ev = dev[0].wait_event(["HS20-DEAUTH-IMMINENT-NOTICE"])
  1568. if ev is None:
  1569. raise Exception("Timeout on deauth imminent notice")
  1570. if "0 120 http://example.com/" not in ev:
  1571. raise Exception("Unexpected deauth imminent notice: " + ev)
  1572. hapd.request("DEAUTHENTICATE " + addr + " reason=4")
  1573. ev = dev[0].wait_disconnected(timeout=10)
  1574. if "reason=4" not in ev:
  1575. raise Exception("Unexpected disconnection reason")
  1576. if "[TEMP-DISABLED]" not in dev[0].list_networks()[0]['flags']:
  1577. raise Exception("Network not marked temporarily disabled")
  1578. ev = dev[0].wait_event(["SME: Trying to authenticate",
  1579. "Trying to associate",
  1580. "CTRL-EVENT-CONNECTED"], timeout=5)
  1581. if ev is not None:
  1582. raise Exception("Unexpected connection attempt")
  1583. def test_ap_hs20_deauth_req_from_radius(dev, apdev):
  1584. """Hotspot 2.0 connection and deauthentication request from RADIUS"""
  1585. check_eap_capa(dev[0], "MSCHAPV2")
  1586. try:
  1587. _test_ap_hs20_deauth_req_from_radius(dev, apdev)
  1588. finally:
  1589. dev[0].request("SET pmf 0")
  1590. def _test_ap_hs20_deauth_req_from_radius(dev, apdev):
  1591. bssid = apdev[0]['bssid']
  1592. params = hs20_ap_params()
  1593. params['nai_realm'] = [ "0,example.com,21[2:4]" ]
  1594. params['hs20_deauth_req_timeout'] = "2"
  1595. hostapd.add_ap(apdev[0]['ifname'], params)
  1596. dev[0].request("SET pmf 2")
  1597. dev[0].hs20_enable()
  1598. dev[0].add_cred_values({ 'realm': "example.com",
  1599. 'username': "hs20-deauth-test",
  1600. 'password': "password" })
  1601. interworking_select(dev[0], bssid, freq="2412")
  1602. interworking_connect(dev[0], bssid, "TTLS")
  1603. ev = dev[0].wait_event(["HS20-DEAUTH-IMMINENT-NOTICE"], timeout=5)
  1604. if ev is None:
  1605. raise Exception("Timeout on deauth imminent notice")
  1606. if " 1 100" not in ev:
  1607. raise Exception("Unexpected deauth imminent contents")
  1608. dev[0].wait_disconnected(timeout=3)
  1609. def test_ap_hs20_remediation_required(dev, apdev):
  1610. """Hotspot 2.0 connection and remediation required from RADIUS"""
  1611. check_eap_capa(dev[0], "MSCHAPV2")
  1612. try:
  1613. _test_ap_hs20_remediation_required(dev, apdev)
  1614. finally:
  1615. dev[0].request("SET pmf 0")
  1616. def _test_ap_hs20_remediation_required(dev, apdev):
  1617. bssid = apdev[0]['bssid']
  1618. params = hs20_ap_params()
  1619. params['nai_realm'] = [ "0,example.com,21[2:4]" ]
  1620. hostapd.add_ap(apdev[0]['ifname'], params)
  1621. dev[0].request("SET pmf 1")
  1622. dev[0].hs20_enable()
  1623. dev[0].add_cred_values({ 'realm': "example.com",
  1624. 'username': "hs20-subrem-test",
  1625. 'password': "password" })
  1626. interworking_select(dev[0], bssid, freq="2412")
  1627. interworking_connect(dev[0], bssid, "TTLS")
  1628. ev = dev[0].wait_event(["HS20-SUBSCRIPTION-REMEDIATION"], timeout=5)
  1629. if ev is None:
  1630. raise Exception("Timeout on subscription remediation notice")
  1631. if " 1 https://example.com/" not in ev:
  1632. raise Exception("Unexpected subscription remediation event contents")
  1633. def test_ap_hs20_remediation_required_ctrl(dev, apdev):
  1634. """Hotspot 2.0 connection and subrem from ctrl_iface"""
  1635. check_eap_capa(dev[0], "MSCHAPV2")
  1636. try:
  1637. _test_ap_hs20_remediation_required_ctrl(dev, apdev)
  1638. finally:
  1639. dev[0].request("SET pmf 0")
  1640. def _test_ap_hs20_remediation_required_ctrl(dev, apdev):
  1641. bssid = apdev[0]['bssid']
  1642. addr = dev[0].own_addr()
  1643. params = hs20_ap_params()
  1644. params['nai_realm'] = [ "0,example.com,21[2:4]" ]
  1645. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1646. dev[0].request("SET pmf 1")
  1647. dev[0].hs20_enable()
  1648. dev[0].add_cred_values(default_cred())
  1649. interworking_select(dev[0], bssid, freq="2412")
  1650. interworking_connect(dev[0], bssid, "TTLS")
  1651. hapd.request("HS20_WNM_NOTIF " + addr + " https://example.com/")
  1652. ev = dev[0].wait_event(["HS20-SUBSCRIPTION-REMEDIATION"], timeout=5)
  1653. if ev is None:
  1654. raise Exception("Timeout on subscription remediation notice")
  1655. if " 1 https://example.com/" not in ev:
  1656. raise Exception("Unexpected subscription remediation event contents")
  1657. hapd.request("HS20_WNM_NOTIF " + addr)
  1658. ev = dev[0].wait_event(["HS20-SUBSCRIPTION-REMEDIATION"], timeout=5)
  1659. if ev is None:
  1660. raise Exception("Timeout on subscription remediation notice")
  1661. if not ev.endswith("HS20-SUBSCRIPTION-REMEDIATION "):
  1662. raise Exception("Unexpected subscription remediation event contents: " + ev)
  1663. if "FAIL" not in hapd.request("HS20_WNM_NOTIF "):
  1664. raise Exception("Unexpected HS20_WNM_NOTIF success")
  1665. if "FAIL" not in hapd.request("HS20_WNM_NOTIF foo"):
  1666. raise Exception("Unexpected HS20_WNM_NOTIF success")
  1667. if "FAIL" not in hapd.request("HS20_WNM_NOTIF " + addr + " https://12345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678927.very.long.example.com/"):
  1668. raise Exception("Unexpected HS20_WNM_NOTIF success")
  1669. def test_ap_hs20_session_info(dev, apdev):
  1670. """Hotspot 2.0 connection and session information from RADIUS"""
  1671. check_eap_capa(dev[0], "MSCHAPV2")
  1672. try:
  1673. _test_ap_hs20_session_info(dev, apdev)
  1674. finally:
  1675. dev[0].request("SET pmf 0")
  1676. def _test_ap_hs20_session_info(dev, apdev):
  1677. bssid = apdev[0]['bssid']
  1678. params = hs20_ap_params()
  1679. params['nai_realm'] = [ "0,example.com,21[2:4]" ]
  1680. hostapd.add_ap(apdev[0]['ifname'], params)
  1681. dev[0].request("SET pmf 1")
  1682. dev[0].hs20_enable()
  1683. dev[0].add_cred_values({ 'realm': "example.com",
  1684. 'username': "hs20-session-info-test",
  1685. 'password': "password" })
  1686. interworking_select(dev[0], bssid, freq="2412")
  1687. interworking_connect(dev[0], bssid, "TTLS")
  1688. ev = dev[0].wait_event(["ESS-DISASSOC-IMMINENT"], timeout=10)
  1689. if ev is None:
  1690. raise Exception("Timeout on ESS disassociation imminent notice")
  1691. if " 1 59904 https://example.com/" not in ev:
  1692. raise Exception("Unexpected ESS disassociation imminent event contents")
  1693. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"])
  1694. if ev is None:
  1695. raise Exception("Scan not started")
  1696. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=30)
  1697. if ev is None:
  1698. raise Exception("Scan not completed")
  1699. def test_ap_hs20_osen(dev, apdev):
  1700. """Hotspot 2.0 OSEN connection"""
  1701. params = { 'ssid': "osen",
  1702. 'osen': "1",
  1703. 'auth_server_addr': "127.0.0.1",
  1704. 'auth_server_port': "1812",
  1705. 'auth_server_shared_secret': "radius" }
  1706. hostapd.add_ap(apdev[0]['ifname'], params)
  1707. dev[1].connect("osen", key_mgmt="NONE", scan_freq="2412",
  1708. wait_connect=False)
  1709. dev[2].connect("osen", key_mgmt="NONE", wep_key0='"hello"',
  1710. scan_freq="2412", wait_connect=False)
  1711. dev[0].flush_scan_cache()
  1712. dev[0].connect("osen", proto="OSEN", key_mgmt="OSEN", pairwise="CCMP",
  1713. group="GTK_NOT_USED",
  1714. eap="WFA-UNAUTH-TLS", identity="osen@example.com",
  1715. ca_cert="auth_serv/ca.pem",
  1716. scan_freq="2412")
  1717. res = dev[0].get_bss(apdev[0]['bssid'])['flags']
  1718. if "[OSEN-OSEN-CCMP]" not in res:
  1719. raise Exception("OSEN not reported in BSS")
  1720. if "[WEP]" in res:
  1721. raise Exception("WEP reported in BSS")
  1722. res = dev[0].request("SCAN_RESULTS")
  1723. if "[OSEN-OSEN-CCMP]" not in res:
  1724. raise Exception("OSEN not reported in SCAN_RESULTS")
  1725. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1726. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  1727. wpas.connect("osen", proto="OSEN", key_mgmt="OSEN", pairwise="CCMP",
  1728. group="GTK_NOT_USED",
  1729. eap="WFA-UNAUTH-TLS", identity="osen@example.com",
  1730. ca_cert="auth_serv/ca.pem",
  1731. scan_freq="2412")
  1732. wpas.request("DISCONNECT")
  1733. def test_ap_hs20_network_preference(dev, apdev):
  1734. """Hotspot 2.0 network selection with preferred home network"""
  1735. check_eap_capa(dev[0], "MSCHAPV2")
  1736. bssid = apdev[0]['bssid']
  1737. params = hs20_ap_params()
  1738. hostapd.add_ap(apdev[0]['ifname'], params)
  1739. dev[0].hs20_enable()
  1740. values = { 'realm': "example.com",
  1741. 'username': "hs20-test",
  1742. 'password': "password",
  1743. 'domain': "example.com" }
  1744. dev[0].add_cred_values(values)
  1745. id = dev[0].add_network()
  1746. dev[0].set_network_quoted(id, "ssid", "home")
  1747. dev[0].set_network_quoted(id, "psk", "12345678")
  1748. dev[0].set_network(id, "priority", "1")
  1749. dev[0].request("ENABLE_NETWORK %s no-connect" % id)
  1750. dev[0].scan_for_bss(bssid, freq="2412")
  1751. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1752. ev = dev[0].wait_connected(timeout=15)
  1753. if bssid not in ev:
  1754. raise Exception("Unexpected network selected")
  1755. bssid2 = apdev[1]['bssid']
  1756. params = hostapd.wpa2_params(ssid="home", passphrase="12345678")
  1757. hostapd.add_ap(apdev[1]['ifname'], params)
  1758. dev[0].scan_for_bss(bssid2, freq="2412")
  1759. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1760. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1761. "INTERWORKING-ALREADY-CONNECTED" ], timeout=15)
  1762. if ev is None:
  1763. raise Exception("Connection timed out")
  1764. if "INTERWORKING-ALREADY-CONNECTED" in ev:
  1765. raise Exception("No roam to higher priority network")
  1766. if bssid2 not in ev:
  1767. raise Exception("Unexpected network selected")
  1768. def test_ap_hs20_network_preference2(dev, apdev):
  1769. """Hotspot 2.0 network selection with preferred credential"""
  1770. check_eap_capa(dev[0], "MSCHAPV2")
  1771. bssid2 = apdev[1]['bssid']
  1772. params = hostapd.wpa2_params(ssid="home", passphrase="12345678")
  1773. hostapd.add_ap(apdev[1]['ifname'], params)
  1774. dev[0].hs20_enable()
  1775. values = { 'realm': "example.com",
  1776. 'username': "hs20-test",
  1777. 'password': "password",
  1778. 'domain': "example.com",
  1779. 'priority': "1" }
  1780. dev[0].add_cred_values(values)
  1781. id = dev[0].add_network()
  1782. dev[0].set_network_quoted(id, "ssid", "home")
  1783. dev[0].set_network_quoted(id, "psk", "12345678")
  1784. dev[0].request("ENABLE_NETWORK %s no-connect" % id)
  1785. dev[0].scan_for_bss(bssid2, freq="2412")
  1786. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1787. ev = dev[0].wait_connected(timeout=15)
  1788. if bssid2 not in ev:
  1789. raise Exception("Unexpected network selected")
  1790. bssid = apdev[0]['bssid']
  1791. params = hs20_ap_params()
  1792. hostapd.add_ap(apdev[0]['ifname'], params)
  1793. dev[0].scan_for_bss(bssid, freq="2412")
  1794. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1795. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1796. "INTERWORKING-ALREADY-CONNECTED" ], timeout=15)
  1797. if ev is None:
  1798. raise Exception("Connection timed out")
  1799. if "INTERWORKING-ALREADY-CONNECTED" in ev:
  1800. raise Exception("No roam to higher priority network")
  1801. if bssid not in ev:
  1802. raise Exception("Unexpected network selected")
  1803. def test_ap_hs20_network_preference3(dev, apdev):
  1804. """Hotspot 2.0 network selection with two credential (one preferred)"""
  1805. check_eap_capa(dev[0], "MSCHAPV2")
  1806. bssid = apdev[0]['bssid']
  1807. params = hs20_ap_params()
  1808. hostapd.add_ap(apdev[0]['ifname'], params)
  1809. bssid2 = apdev[1]['bssid']
  1810. params = hs20_ap_params(ssid="test-hs20b")
  1811. params['nai_realm'] = "0,example.org,13[5:6],21[2:4][5:7]"
  1812. hostapd.add_ap(apdev[1]['ifname'], params)
  1813. dev[0].hs20_enable()
  1814. values = { 'realm': "example.com",
  1815. 'username': "hs20-test",
  1816. 'password': "password",
  1817. 'priority': "1" }
  1818. dev[0].add_cred_values(values)
  1819. values = { 'realm': "example.org",
  1820. 'username': "hs20-test",
  1821. 'password': "password" }
  1822. id = dev[0].add_cred_values(values)
  1823. dev[0].scan_for_bss(bssid, freq="2412")
  1824. dev[0].scan_for_bss(bssid2, freq="2412")
  1825. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1826. ev = dev[0].wait_connected(timeout=15)
  1827. if bssid not in ev:
  1828. raise Exception("Unexpected network selected")
  1829. dev[0].set_cred(id, "priority", "2")
  1830. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1831. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1832. "INTERWORKING-ALREADY-CONNECTED" ], timeout=15)
  1833. if ev is None:
  1834. raise Exception("Connection timed out")
  1835. if "INTERWORKING-ALREADY-CONNECTED" in ev:
  1836. raise Exception("No roam to higher priority network")
  1837. if bssid2 not in ev:
  1838. raise Exception("Unexpected network selected")
  1839. def test_ap_hs20_network_preference4(dev, apdev):
  1840. """Hotspot 2.0 network selection with username vs. SIM credential"""
  1841. check_eap_capa(dev[0], "MSCHAPV2")
  1842. bssid = apdev[0]['bssid']
  1843. params = hs20_ap_params()
  1844. hostapd.add_ap(apdev[0]['ifname'], params)
  1845. bssid2 = apdev[1]['bssid']
  1846. params = hs20_ap_params(ssid="test-hs20b")
  1847. params['hessid'] = bssid2
  1848. params['anqp_3gpp_cell_net'] = "555,444"
  1849. params['domain_name'] = "wlan.mnc444.mcc555.3gppnetwork.org"
  1850. hostapd.add_ap(apdev[1]['ifname'], params)
  1851. dev[0].hs20_enable()
  1852. values = { 'realm': "example.com",
  1853. 'username': "hs20-test",
  1854. 'password': "password",
  1855. 'priority': "1" }
  1856. dev[0].add_cred_values(values)
  1857. values = { 'imsi': "555444-333222111",
  1858. 'eap': "SIM",
  1859. 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123" }
  1860. id = dev[0].add_cred_values(values)
  1861. dev[0].scan_for_bss(bssid, freq="2412")
  1862. dev[0].scan_for_bss(bssid2, freq="2412")
  1863. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1864. ev = dev[0].wait_connected(timeout=15)
  1865. if bssid not in ev:
  1866. raise Exception("Unexpected network selected")
  1867. dev[0].set_cred(id, "priority", "2")
  1868. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1869. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1870. "INTERWORKING-ALREADY-CONNECTED" ], timeout=15)
  1871. if ev is None:
  1872. raise Exception("Connection timed out")
  1873. if "INTERWORKING-ALREADY-CONNECTED" in ev:
  1874. raise Exception("No roam to higher priority network")
  1875. if bssid2 not in ev:
  1876. raise Exception("Unexpected network selected")
  1877. def test_ap_hs20_interworking_select_blocking_scan(dev, apdev):
  1878. """Ongoing INTERWORKING_SELECT blocking SCAN"""
  1879. check_eap_capa(dev[0], "MSCHAPV2")
  1880. bssid = apdev[0]['bssid']
  1881. params = hs20_ap_params()
  1882. hostapd.add_ap(apdev[0]['ifname'], params)
  1883. dev[0].hs20_enable()
  1884. values = { 'realm': "example.com",
  1885. 'username': "hs20-test",
  1886. 'password': "password",
  1887. 'domain': "example.com" }
  1888. dev[0].add_cred_values(values)
  1889. dev[0].scan_for_bss(bssid, freq="2412")
  1890. dev[0].request("INTERWORKING_SELECT auto freq=2412")
  1891. if "FAIL-BUSY" not in dev[0].request("SCAN"):
  1892. raise Exception("Unexpected SCAN command result")
  1893. dev[0].wait_connected(timeout=15)
  1894. def test_ap_hs20_fetch_osu(dev, apdev):
  1895. """Hotspot 2.0 OSU provider and icon fetch"""
  1896. bssid = apdev[0]['bssid']
  1897. params = hs20_ap_params()
  1898. params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png"
  1899. params['osu_ssid'] = '"HS 2.0 OSU open"'
  1900. params['osu_method_list'] = "1"
  1901. params['osu_friendly_name'] = [ "eng:Test OSU", "fin:Testi-OSU" ]
  1902. params['osu_icon'] = "w1fi_logo"
  1903. params['osu_service_desc'] = [ "eng:Example services", "fin:Esimerkkipalveluja" ]
  1904. params['osu_server_uri'] = "https://example.com/osu/"
  1905. hostapd.add_ap(apdev[0]['ifname'], params)
  1906. bssid2 = apdev[1]['bssid']
  1907. params = hs20_ap_params(ssid="test-hs20b")
  1908. params['hessid'] = bssid2
  1909. params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png"
  1910. params['osu_ssid'] = '"HS 2.0 OSU OSEN"'
  1911. params['osu_method_list'] = "0"
  1912. params['osu_nai'] = "osen@example.com"
  1913. params['osu_friendly_name'] = [ "eng:Test2 OSU", "fin:Testi2-OSU" ]
  1914. params['osu_icon'] = "w1fi_logo"
  1915. params['osu_service_desc'] = [ "eng:Example services2", "fin:Esimerkkipalveluja2" ]
  1916. params['osu_server_uri'] = "https://example.org/osu/"
  1917. hostapd.add_ap(apdev[1]['ifname'], params)
  1918. with open("w1fi_logo.png", "r") as f:
  1919. orig_logo = f.read()
  1920. dev[0].hs20_enable()
  1921. dir = "/tmp/osu-fetch"
  1922. if os.path.isdir(dir):
  1923. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  1924. for f in files:
  1925. os.remove(dir + "/" + f)
  1926. else:
  1927. try:
  1928. os.makedirs(dir)
  1929. except:
  1930. pass
  1931. try:
  1932. dev[1].scan_for_bss(bssid, freq="2412")
  1933. dev[0].request("SET osu_dir " + dir)
  1934. dev[0].request("FETCH_OSU")
  1935. if "FAIL" not in dev[1].request("HS20_ICON_REQUEST foo w1fi_logo"):
  1936. raise Exception("Invalid HS20_ICON_REQUEST accepted")
  1937. if "OK" not in dev[1].request("HS20_ICON_REQUEST " + bssid + " w1fi_logo"):
  1938. raise Exception("HS20_ICON_REQUEST failed")
  1939. icons = 0
  1940. while True:
  1941. ev = dev[0].wait_event(["OSU provider fetch completed",
  1942. "RX-HS20-ANQP-ICON"], timeout=15)
  1943. if ev is None:
  1944. raise Exception("Timeout on OSU fetch")
  1945. if "OSU provider fetch completed" in ev:
  1946. break
  1947. if "RX-HS20-ANQP-ICON" in ev:
  1948. with open(ev.split(' ')[1], "r") as f:
  1949. logo = f.read()
  1950. if logo == orig_logo:
  1951. icons += 1
  1952. with open(dir + "/osu-providers.txt", "r") as f:
  1953. prov = f.read()
  1954. logger.debug("osu-providers.txt: " + prov)
  1955. if "OSU-PROVIDER " + bssid not in prov:
  1956. raise Exception("Missing OSU_PROVIDER(1)")
  1957. if "OSU-PROVIDER " + bssid2 not in prov:
  1958. raise Exception("Missing OSU_PROVIDER(2)")
  1959. finally:
  1960. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  1961. for f in files:
  1962. os.remove(dir + "/" + f)
  1963. os.rmdir(dir)
  1964. if icons != 2:
  1965. raise Exception("Unexpected number of icons fetched")
  1966. ev = dev[1].wait_event(["GAS-QUERY-START"], timeout=5)
  1967. if ev is None:
  1968. raise Exception("Timeout on GAS-QUERY-DONE")
  1969. ev = dev[1].wait_event(["GAS-QUERY-DONE"], timeout=5)
  1970. if ev is None:
  1971. raise Exception("Timeout on GAS-QUERY-DONE")
  1972. if "freq=2412 status_code=0 result=SUCCESS" not in ev:
  1973. raise Exception("Unexpected GAS-QUERY-DONE: " + ev)
  1974. ev = dev[1].wait_event(["RX-HS20-ANQP"], timeout=15)
  1975. if ev is None:
  1976. raise Exception("Timeout on icon fetch")
  1977. if "Icon Binary File" not in ev:
  1978. raise Exception("Unexpected ANQP element")
  1979. def test_ap_hs20_fetch_osu_stop(dev, apdev):
  1980. """Hotspot 2.0 OSU provider fetch stopped"""
  1981. bssid = apdev[0]['bssid']
  1982. params = hs20_ap_params()
  1983. params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png"
  1984. params['osu_ssid'] = '"HS 2.0 OSU open"'
  1985. params['osu_method_list'] = "1"
  1986. params['osu_friendly_name'] = [ "eng:Test OSU", "fin:Testi-OSU" ]
  1987. params['osu_icon'] = "w1fi_logo"
  1988. params['osu_service_desc'] = [ "eng:Example services", "fin:Esimerkkipalveluja" ]
  1989. params['osu_server_uri'] = "https://example.com/osu/"
  1990. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1991. dev[0].hs20_enable()
  1992. dir = "/tmp/osu-fetch"
  1993. if os.path.isdir(dir):
  1994. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  1995. for f in files:
  1996. os.remove(dir + "/" + f)
  1997. else:
  1998. try:
  1999. os.makedirs(dir)
  2000. except:
  2001. pass
  2002. try:
  2003. dev[0].request("SET osu_dir " + dir)
  2004. dev[0].request("SCAN freq=2412-2462")
  2005. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=10)
  2006. if ev is None:
  2007. raise Exception("Scan did not start")
  2008. if "FAIL" not in dev[0].request("FETCH_OSU"):
  2009. raise Exception("FETCH_OSU accepted while scanning")
  2010. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
  2011. if ev is None:
  2012. raise Exception("Scan timed out")
  2013. hapd.set("ext_mgmt_frame_handling", "1")
  2014. dev[0].request("FETCH_ANQP")
  2015. if "FAIL" not in dev[0].request("FETCH_OSU"):
  2016. raise Exception("FETCH_OSU accepted while in FETCH_ANQP")
  2017. dev[0].request("STOP_FETCH_ANQP")
  2018. dev[0].wait_event(["GAS-QUERY-DONE"], timeout=5)
  2019. dev[0].dump_monitor()
  2020. hapd.dump_monitor()
  2021. dev[0].request("INTERWORKING_SELECT freq=2412")
  2022. for i in range(5):
  2023. msg = hapd.mgmt_rx()
  2024. if msg['subtype'] == 13:
  2025. break
  2026. if "FAIL" not in dev[0].request("FETCH_OSU"):
  2027. raise Exception("FETCH_OSU accepted while in INTERWORKING_SELECT")
  2028. ev = dev[0].wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
  2029. timeout=15)
  2030. if ev is None:
  2031. raise Exception("Network selection timed out");
  2032. dev[0].dump_monitor()
  2033. if "OK" not in dev[0].request("FETCH_OSU"):
  2034. raise Exception("FETCH_OSU failed")
  2035. dev[0].request("CANCEL_FETCH_OSU")
  2036. for i in range(15):
  2037. time.sleep(0.5)
  2038. if dev[0].get_driver_status_field("scan_state") == "SCAN_COMPLETED":
  2039. break
  2040. dev[0].dump_monitor()
  2041. if "OK" not in dev[0].request("FETCH_OSU"):
  2042. raise Exception("FETCH_OSU failed")
  2043. if "FAIL" not in dev[0].request("FETCH_OSU"):
  2044. raise Exception("FETCH_OSU accepted while in FETCH_OSU")
  2045. ev = dev[0].wait_event(["GAS-QUERY-START"], 10)
  2046. if ev is None:
  2047. raise Exception("GAS timed out")
  2048. if "FAIL" not in dev[0].request("FETCH_OSU"):
  2049. raise Exception("FETCH_OSU accepted while in FETCH_OSU")
  2050. dev[0].request("CANCEL_FETCH_OSU")
  2051. ev = dev[0].wait_event(["GAS-QUERY-DONE"], 10)
  2052. if ev is None:
  2053. raise Exception("GAS event timed out after CANCEL_FETCH_OSU")
  2054. finally:
  2055. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  2056. for f in files:
  2057. os.remove(dir + "/" + f)
  2058. os.rmdir(dir)
  2059. def test_ap_hs20_ft(dev, apdev):
  2060. """Hotspot 2.0 connection with FT"""
  2061. check_eap_capa(dev[0], "MSCHAPV2")
  2062. bssid = apdev[0]['bssid']
  2063. params = hs20_ap_params()
  2064. params['wpa_key_mgmt'] = "FT-EAP"
  2065. params['nas_identifier'] = "nas1.w1.fi"
  2066. params['r1_key_holder'] = "000102030405"
  2067. params["mobility_domain"] = "a1b2"
  2068. params["reassociation_deadline"] = "1000"
  2069. hostapd.add_ap(apdev[0]['ifname'], params)
  2070. dev[0].hs20_enable()
  2071. id = dev[0].add_cred_values({ 'realm': "example.com",
  2072. 'username': "hs20-test",
  2073. 'password': "password",
  2074. 'ca_cert': "auth_serv/ca.pem",
  2075. 'domain': "example.com",
  2076. 'update_identifier': "1234" })
  2077. interworking_select(dev[0], bssid, "home", freq="2412")
  2078. interworking_connect(dev[0], bssid, "TTLS")
  2079. def test_ap_hs20_remediation_sql(dev, apdev, params):
  2080. """Hotspot 2.0 connection and remediation required using SQLite for user DB"""
  2081. check_eap_capa(dev[0], "MSCHAPV2")
  2082. try:
  2083. import sqlite3
  2084. except ImportError:
  2085. raise HwsimSkip("No sqlite3 module available")
  2086. dbfile = os.path.join(params['logdir'], "eap-user.db")
  2087. try:
  2088. os.remove(dbfile)
  2089. except:
  2090. pass
  2091. con = sqlite3.connect(dbfile)
  2092. with con:
  2093. cur = con.cursor()
  2094. cur.execute("CREATE TABLE users(identity TEXT PRIMARY KEY, methods TEXT, password TEXT, remediation TEXT, phase2 INTEGER)")
  2095. cur.execute("CREATE TABLE wildcards(identity TEXT PRIMARY KEY, methods TEXT)")
  2096. cur.execute("INSERT INTO users(identity,methods,password,phase2,remediation) VALUES ('user-mschapv2','TTLS-MSCHAPV2','password',1,'user')")
  2097. cur.execute("INSERT INTO wildcards(identity,methods) VALUES ('','TTLS,TLS')")
  2098. cur.execute("CREATE TABLE authlog(timestamp TEXT, session TEXT, nas_ip TEXT, username TEXT, note TEXT)")
  2099. try:
  2100. params = { "ssid": "as", "beacon_int": "2000",
  2101. "radius_server_clients": "auth_serv/radius_clients.conf",
  2102. "radius_server_auth_port": '18128',
  2103. "eap_server": "1",
  2104. "eap_user_file": "sqlite:" + dbfile,
  2105. "ca_cert": "auth_serv/ca.pem",
  2106. "server_cert": "auth_serv/server.pem",
  2107. "private_key": "auth_serv/server.key",
  2108. "subscr_remediation_url": "https://example.org/",
  2109. "subscr_remediation_method": "1" }
  2110. hostapd.add_ap(apdev[1]['ifname'], params)
  2111. bssid = apdev[0]['bssid']
  2112. params = hs20_ap_params()
  2113. params['auth_server_port'] = "18128"
  2114. hostapd.add_ap(apdev[0]['ifname'], params)
  2115. dev[0].request("SET pmf 1")
  2116. dev[0].hs20_enable()
  2117. id = dev[0].add_cred_values({ 'realm': "example.com",
  2118. 'username': "user-mschapv2",
  2119. 'password': "password",
  2120. 'ca_cert': "auth_serv/ca.pem" })
  2121. interworking_select(dev[0], bssid, freq="2412")
  2122. interworking_connect(dev[0], bssid, "TTLS")
  2123. ev = dev[0].wait_event(["HS20-SUBSCRIPTION-REMEDIATION"], timeout=5)
  2124. if ev is None:
  2125. raise Exception("Timeout on subscription remediation notice")
  2126. if " 1 https://example.org/" not in ev:
  2127. raise Exception("Unexpected subscription remediation event contents")
  2128. with con:
  2129. cur = con.cursor()
  2130. cur.execute("SELECT * from authlog")
  2131. rows = cur.fetchall()
  2132. if len(rows) < 1:
  2133. raise Exception("No authlog entries")
  2134. finally:
  2135. os.remove(dbfile)
  2136. dev[0].request("SET pmf 0")
  2137. def test_ap_hs20_external_selection(dev, apdev):
  2138. """Hotspot 2.0 connection using external network selection and creation"""
  2139. check_eap_capa(dev[0], "MSCHAPV2")
  2140. bssid = apdev[0]['bssid']
  2141. params = hs20_ap_params()
  2142. params['hessid'] = bssid
  2143. params['disable_dgaf'] = '1'
  2144. hostapd.add_ap(apdev[0]['ifname'], params)
  2145. dev[0].hs20_enable()
  2146. dev[0].connect("test-hs20", proto="RSN", key_mgmt="WPA-EAP", eap="TTLS",
  2147. identity="hs20-test", password="password",
  2148. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2149. scan_freq="2412", update_identifier="54321")
  2150. if dev[0].get_status_field("hs20") != "2":
  2151. raise Exception("Unexpected hs20 indication")
  2152. def test_ap_hs20_random_mac_addr(dev, apdev):
  2153. """Hotspot 2.0 connection with random MAC address"""
  2154. check_eap_capa(dev[0], "MSCHAPV2")
  2155. bssid = apdev[0]['bssid']
  2156. params = hs20_ap_params()
  2157. params['hessid'] = bssid
  2158. params['disable_dgaf'] = '1'
  2159. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2160. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  2161. wpas.interface_add("wlan5")
  2162. addr = wpas.p2p_interface_addr()
  2163. wpas.request("SET mac_addr 1")
  2164. wpas.request("SET preassoc_mac_addr 1")
  2165. wpas.request("SET rand_addr_lifetime 60")
  2166. wpas.hs20_enable()
  2167. wpas.flush_scan_cache()
  2168. id = wpas.add_cred_values({ 'realm': "example.com",
  2169. 'username': "hs20-test",
  2170. 'password': "password",
  2171. 'ca_cert': "auth_serv/ca.pem",
  2172. 'domain': "example.com",
  2173. 'update_identifier': "1234" })
  2174. interworking_select(wpas, bssid, "home", freq="2412")
  2175. interworking_connect(wpas, bssid, "TTLS")
  2176. addr1 = wpas.get_driver_status_field("addr")
  2177. if addr == addr1:
  2178. raise Exception("Did not use random MAC address")
  2179. sta = hapd.get_sta(addr)
  2180. if sta['addr'] != "FAIL":
  2181. raise Exception("Unexpected STA association with permanent address")
  2182. sta = hapd.get_sta(addr1)
  2183. if sta['addr'] != addr1:
  2184. raise Exception("STA association with random address not found")
  2185. def test_ap_hs20_multi_network_and_cred_removal(dev, apdev):
  2186. """Multiple networks and cred removal"""
  2187. check_eap_capa(dev[0], "MSCHAPV2")
  2188. bssid = apdev[0]['bssid']
  2189. params = hs20_ap_params()
  2190. params['nai_realm'] = [ "0,example.com,25[3:26]"]
  2191. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2192. dev[0].add_network()
  2193. dev[0].hs20_enable()
  2194. id = dev[0].add_cred_values({ 'realm': "example.com",
  2195. 'username': "user",
  2196. 'password': "password" })
  2197. interworking_select(dev[0], bssid, freq="2412")
  2198. interworking_connect(dev[0], bssid, "PEAP")
  2199. dev[0].add_network()
  2200. dev[0].request("DISCONNECT")
  2201. dev[0].wait_disconnected(timeout=10)
  2202. hapd.disable()
  2203. hapd.set("ssid", "another ssid")
  2204. hapd.enable()
  2205. interworking_select(dev[0], bssid, freq="2412")
  2206. interworking_connect(dev[0], bssid, "PEAP")
  2207. dev[0].add_network()
  2208. if len(dev[0].list_networks()) != 5:
  2209. raise Exception("Unexpected number of networks prior to remove_crec")
  2210. dev[0].dump_monitor()
  2211. dev[0].remove_cred(id)
  2212. if len(dev[0].list_networks()) != 3:
  2213. raise Exception("Unexpected number of networks after to remove_crec")
  2214. dev[0].wait_disconnected(timeout=10)
  2215. def test_ap_hs20_interworking_add_network(dev, apdev):
  2216. """Hotspot 2.0 connection using INTERWORKING_ADD_NETWORK"""
  2217. check_eap_capa(dev[0], "MSCHAPV2")
  2218. bssid = apdev[0]['bssid']
  2219. params = hs20_ap_params()
  2220. params['nai_realm'] = [ "0,example.com,21[3:26][6:7][99:99]" ]
  2221. hostapd.add_ap(apdev[0]['ifname'], params)
  2222. dev[0].hs20_enable()
  2223. dev[0].add_cred_values(default_cred(user="user"))
  2224. interworking_select(dev[0], bssid, freq=2412)
  2225. id = dev[0].interworking_add_network(bssid)
  2226. dev[0].select_network(id, freq=2412)
  2227. dev[0].wait_connected()
  2228. def _test_ap_hs20_proxyarp(dev, apdev):
  2229. bssid = apdev[0]['bssid']
  2230. params = hs20_ap_params()
  2231. params['hessid'] = bssid
  2232. params['disable_dgaf'] = '0'
  2233. params['proxy_arp'] = '1'
  2234. hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True)
  2235. if "OK" in hapd.request("ENABLE"):
  2236. raise Exception("Incomplete hostapd configuration was accepted")
  2237. hapd.set("ap_isolate", "1")
  2238. if "OK" in hapd.request("ENABLE"):
  2239. raise Exception("Incomplete hostapd configuration was accepted")
  2240. hapd.set('bridge', 'ap-br0')
  2241. hapd.dump_monitor()
  2242. try:
  2243. hapd.enable()
  2244. except:
  2245. # For now, do not report failures due to missing kernel support
  2246. raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version")
  2247. ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=10)
  2248. if ev is None:
  2249. raise Exception("AP startup timed out")
  2250. if "AP-ENABLED" not in ev:
  2251. raise Exception("AP startup failed")
  2252. dev[0].hs20_enable()
  2253. subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
  2254. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  2255. id = dev[0].add_cred_values({ 'realm': "example.com",
  2256. 'username': "hs20-test",
  2257. 'password': "password",
  2258. 'ca_cert': "auth_serv/ca.pem",
  2259. 'domain': "example.com",
  2260. 'update_identifier': "1234" })
  2261. interworking_select(dev[0], bssid, "home", freq="2412")
  2262. interworking_connect(dev[0], bssid, "TTLS")
  2263. dev[1].connect("test-hs20", key_mgmt="WPA-EAP", eap="TTLS",
  2264. identity="hs20-test", password="password",
  2265. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2266. scan_freq="2412")
  2267. time.sleep(0.1)
  2268. addr0 = dev[0].p2p_interface_addr()
  2269. addr1 = dev[1].p2p_interface_addr()
  2270. src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':',''))
  2271. src_ll_opt1 = "\x01\x01" + binascii.unhexlify(addr1.replace(':',''))
  2272. pkt = build_ns(src_ll=addr0, ip_src="aaaa:bbbb:cccc::2",
  2273. ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:cccc::2",
  2274. opt=src_ll_opt0)
  2275. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  2276. raise Exception("DATA_TEST_FRAME failed")
  2277. pkt = build_ns(src_ll=addr1, ip_src="aaaa:bbbb:dddd::2",
  2278. ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:dddd::2",
  2279. opt=src_ll_opt1)
  2280. if "OK" not in dev[1].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  2281. raise Exception("DATA_TEST_FRAME failed")
  2282. pkt = build_ns(src_ll=addr1, ip_src="aaaa:bbbb:eeee::2",
  2283. ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:eeee::2",
  2284. opt=src_ll_opt1)
  2285. if "OK" not in dev[1].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  2286. raise Exception("DATA_TEST_FRAME failed")
  2287. matches = get_permanent_neighbors("ap-br0")
  2288. logger.info("After connect: " + str(matches))
  2289. if len(matches) != 3:
  2290. raise Exception("Unexpected number of neighbor entries after connect")
  2291. if 'aaaa:bbbb:cccc::2 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  2292. raise Exception("dev0 addr missing")
  2293. if 'aaaa:bbbb:dddd::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches:
  2294. raise Exception("dev1 addr(1) missing")
  2295. if 'aaaa:bbbb:eeee::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches:
  2296. raise Exception("dev1 addr(2) missing")
  2297. dev[0].request("DISCONNECT")
  2298. dev[1].request("DISCONNECT")
  2299. time.sleep(0.5)
  2300. matches = get_permanent_neighbors("ap-br0")
  2301. logger.info("After disconnect: " + str(matches))
  2302. if len(matches) > 0:
  2303. raise Exception("Unexpected neighbor entries after disconnect")
  2304. def test_ap_hs20_hidden_ssid_in_scan_res(dev, apdev):
  2305. """Hotspot 2.0 connection with hidden SSId in scan results"""
  2306. check_eap_capa(dev[0], "MSCHAPV2")
  2307. bssid = apdev[0]['bssid']
  2308. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'secret',
  2309. "ignore_broadcast_ssid": "1" })
  2310. dev[0].scan_for_bss(bssid, freq=2412)
  2311. hapd.disable()
  2312. hapd_global = hostapd.HostapdGlobal()
  2313. hapd_global.flush()
  2314. hapd_global.remove(apdev[0]['ifname'])
  2315. params = hs20_ap_params()
  2316. params['hessid'] = bssid
  2317. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2318. dev[0].hs20_enable()
  2319. id = dev[0].add_cred_values({ 'realm': "example.com",
  2320. 'username': "hs20-test",
  2321. 'password': "password",
  2322. 'ca_cert': "auth_serv/ca.pem",
  2323. 'domain': "example.com" })
  2324. interworking_select(dev[0], bssid, "home", freq="2412")
  2325. interworking_connect(dev[0], bssid, "TTLS")
  2326. # clear BSS table to avoid issues in following test cases
  2327. dev[0].request("DISCONNECT")
  2328. dev[0].wait_disconnected()
  2329. hapd.disable()
  2330. dev[0].flush_scan_cache()
  2331. dev[0].flush_scan_cache()
  2332. def test_ap_hs20_proxyarp(dev, apdev):
  2333. """Hotspot 2.0 and ProxyARP"""
  2334. check_eap_capa(dev[0], "MSCHAPV2")
  2335. try:
  2336. _test_ap_hs20_proxyarp(dev, apdev)
  2337. finally:
  2338. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  2339. stderr=open('/dev/null', 'w'))
  2340. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  2341. stderr=open('/dev/null', 'w'))
  2342. def _test_ap_hs20_proxyarp_dgaf(dev, apdev, disabled):
  2343. bssid = apdev[0]['bssid']
  2344. params = hs20_ap_params()
  2345. params['hessid'] = bssid
  2346. params['disable_dgaf'] = '1' if disabled else '0'
  2347. params['proxy_arp'] = '1'
  2348. params['na_mcast_to_ucast'] = '1'
  2349. params['ap_isolate'] = '1'
  2350. params['bridge'] = 'ap-br0'
  2351. hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True)
  2352. try:
  2353. hapd.enable()
  2354. except:
  2355. # For now, do not report failures due to missing kernel support
  2356. raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version")
  2357. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  2358. if ev is None:
  2359. raise Exception("AP startup timed out")
  2360. dev[0].hs20_enable()
  2361. subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
  2362. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  2363. id = dev[0].add_cred_values({ 'realm': "example.com",
  2364. 'username': "hs20-test",
  2365. 'password': "password",
  2366. 'ca_cert': "auth_serv/ca.pem",
  2367. 'domain': "example.com",
  2368. 'update_identifier': "1234" })
  2369. interworking_select(dev[0], bssid, "home", freq="2412")
  2370. interworking_connect(dev[0], bssid, "TTLS")
  2371. dev[1].connect("test-hs20", key_mgmt="WPA-EAP", eap="TTLS",
  2372. identity="hs20-test", password="password",
  2373. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2374. scan_freq="2412")
  2375. time.sleep(0.1)
  2376. addr0 = dev[0].p2p_interface_addr()
  2377. src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':',''))
  2378. pkt = build_ns(src_ll=addr0, ip_src="aaaa:bbbb:cccc::2",
  2379. ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:cccc::2",
  2380. opt=src_ll_opt0)
  2381. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  2382. raise Exception("DATA_TEST_FRAME failed")
  2383. pkt = build_ra(src_ll=apdev[0]['bssid'], ip_src="aaaa:bbbb:cccc::33",
  2384. ip_dst="ff01::1")
  2385. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2386. raise Exception("DATA_TEST_FRAME failed")
  2387. pkt = build_na(src_ll=apdev[0]['bssid'], ip_src="aaaa:bbbb:cccc::44",
  2388. ip_dst="ff01::1", target="aaaa:bbbb:cccc::55")
  2389. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2390. raise Exception("DATA_TEST_FRAME failed")
  2391. pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid,
  2392. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2393. yiaddr="192.168.1.123", chaddr=addr0)
  2394. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2395. raise Exception("DATA_TEST_FRAME failed")
  2396. # another copy for additional code coverage
  2397. pkt = build_dhcp_ack(dst_ll=addr0, src_ll=bssid,
  2398. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2399. yiaddr="192.168.1.123", chaddr=addr0)
  2400. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2401. raise Exception("DATA_TEST_FRAME failed")
  2402. matches = get_permanent_neighbors("ap-br0")
  2403. logger.info("After connect: " + str(matches))
  2404. if len(matches) != 2:
  2405. raise Exception("Unexpected number of neighbor entries after connect")
  2406. if 'aaaa:bbbb:cccc::2 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  2407. raise Exception("dev0 addr missing")
  2408. if '192.168.1.123 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  2409. raise Exception("dev0 IPv4 addr missing")
  2410. dev[0].request("DISCONNECT")
  2411. dev[1].request("DISCONNECT")
  2412. time.sleep(0.5)
  2413. matches = get_permanent_neighbors("ap-br0")
  2414. logger.info("After disconnect: " + str(matches))
  2415. if len(matches) > 0:
  2416. raise Exception("Unexpected neighbor entries after disconnect")
  2417. def test_ap_hs20_proxyarp_disable_dgaf(dev, apdev):
  2418. """Hotspot 2.0 and ProxyARP with DGAF disabled"""
  2419. check_eap_capa(dev[0], "MSCHAPV2")
  2420. try:
  2421. _test_ap_hs20_proxyarp_dgaf(dev, apdev, True)
  2422. finally:
  2423. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  2424. stderr=open('/dev/null', 'w'))
  2425. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  2426. stderr=open('/dev/null', 'w'))
  2427. def test_ap_hs20_proxyarp_enable_dgaf(dev, apdev):
  2428. """Hotspot 2.0 and ProxyARP with DGAF enabled"""
  2429. check_eap_capa(dev[0], "MSCHAPV2")
  2430. try:
  2431. _test_ap_hs20_proxyarp_dgaf(dev, apdev, False)
  2432. finally:
  2433. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  2434. stderr=open('/dev/null', 'w'))
  2435. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  2436. stderr=open('/dev/null', 'w'))
  2437. def ip_checksum(buf):
  2438. sum = 0
  2439. if len(buf) & 0x01:
  2440. buf += '\0x00'
  2441. for i in range(0, len(buf), 2):
  2442. val, = struct.unpack('H', buf[i:i+2])
  2443. sum += val
  2444. while (sum >> 16):
  2445. sum = (sum & 0xffff) + (sum >> 16)
  2446. return struct.pack('H', ~sum & 0xffff)
  2447. def ipv6_solicited_node_mcaddr(target):
  2448. prefix = socket.inet_pton(socket.AF_INET6, "ff02::1:ff00:0")
  2449. mask = socket.inet_pton(socket.AF_INET6, "::ff:ffff")
  2450. _target = socket.inet_pton(socket.AF_INET6, target)
  2451. p = struct.unpack('4I', prefix)
  2452. m = struct.unpack('4I', mask)
  2453. t = struct.unpack('4I', _target)
  2454. res = (p[0] | (t[0] & m[0]),
  2455. p[1] | (t[1] & m[1]),
  2456. p[2] | (t[2] & m[2]),
  2457. p[3] | (t[3] & m[3]))
  2458. return socket.inet_ntop(socket.AF_INET6, struct.pack('4I', *res))
  2459. def build_icmpv6(ipv6_addrs, type, code, payload):
  2460. start = struct.pack("BB", type, code)
  2461. end = payload
  2462. icmp = start + '\x00\x00' + end
  2463. pseudo = ipv6_addrs + struct.pack(">LBBBB", len(icmp), 0, 0, 0, 58)
  2464. csum = ip_checksum(pseudo + icmp)
  2465. return start + csum + end
  2466. def build_ra(src_ll, ip_src, ip_dst, cur_hop_limit=0, router_lifetime=0,
  2467. reachable_time=0, retrans_timer=0, opt=None):
  2468. link_mc = binascii.unhexlify("3333ff000002")
  2469. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  2470. proto = '\x86\xdd'
  2471. ehdr = link_mc + _src_ll + proto
  2472. _ip_src = socket.inet_pton(socket.AF_INET6, ip_src)
  2473. _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst)
  2474. adv = struct.pack('>BBHLL', cur_hop_limit, 0, router_lifetime,
  2475. reachable_time, retrans_timer)
  2476. if opt:
  2477. payload = adv + opt
  2478. else:
  2479. payload = adv
  2480. icmp = build_icmpv6(_ip_src + _ip_dst, 134, 0, payload)
  2481. ipv6 = struct.pack('>BBBBHBB', 0x60, 0, 0, 0, len(icmp), 58, 255)
  2482. ipv6 += _ip_src + _ip_dst
  2483. return ehdr + ipv6 + icmp
  2484. def build_ns(src_ll, ip_src, ip_dst, target, opt=None):
  2485. link_mc = binascii.unhexlify("3333ff000002")
  2486. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  2487. proto = '\x86\xdd'
  2488. ehdr = link_mc + _src_ll + proto
  2489. _ip_src = socket.inet_pton(socket.AF_INET6, ip_src)
  2490. if ip_dst is None:
  2491. ip_dst = ipv6_solicited_node_mcaddr(target)
  2492. _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst)
  2493. reserved = '\x00\x00\x00\x00'
  2494. _target = socket.inet_pton(socket.AF_INET6, target)
  2495. if opt:
  2496. payload = reserved + _target + opt
  2497. else:
  2498. payload = reserved + _target
  2499. icmp = build_icmpv6(_ip_src + _ip_dst, 135, 0, payload)
  2500. ipv6 = struct.pack('>BBBBHBB', 0x60, 0, 0, 0, len(icmp), 58, 255)
  2501. ipv6 += _ip_src + _ip_dst
  2502. return ehdr + ipv6 + icmp
  2503. def send_ns(dev, src_ll=None, target=None, ip_src=None, ip_dst=None, opt=None,
  2504. hapd_bssid=None):
  2505. if hapd_bssid:
  2506. if src_ll is None:
  2507. src_ll = hapd_bssid
  2508. cmd = "DATA_TEST_FRAME ifname=ap-br0 "
  2509. else:
  2510. if src_ll is None:
  2511. src_ll = dev.p2p_interface_addr()
  2512. cmd = "DATA_TEST_FRAME "
  2513. if opt is None:
  2514. opt = "\x01\x01" + binascii.unhexlify(src_ll.replace(':',''))
  2515. pkt = build_ns(src_ll=src_ll, ip_src=ip_src, ip_dst=ip_dst, target=target,
  2516. opt=opt)
  2517. if "OK" not in dev.request(cmd + binascii.hexlify(pkt)):
  2518. raise Exception("DATA_TEST_FRAME failed")
  2519. def build_na(src_ll, ip_src, ip_dst, target, opt=None):
  2520. link_mc = binascii.unhexlify("3333ff000002")
  2521. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  2522. proto = '\x86\xdd'
  2523. ehdr = link_mc + _src_ll + proto
  2524. _ip_src = socket.inet_pton(socket.AF_INET6, ip_src)
  2525. _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst)
  2526. reserved = '\x00\x00\x00\x00'
  2527. _target = socket.inet_pton(socket.AF_INET6, target)
  2528. if opt:
  2529. payload = reserved + _target + opt
  2530. else:
  2531. payload = reserved + _target
  2532. icmp = build_icmpv6(_ip_src + _ip_dst, 136, 0, payload)
  2533. ipv6 = struct.pack('>BBBBHBB', 0x60, 0, 0, 0, len(icmp), 58, 255)
  2534. ipv6 += _ip_src + _ip_dst
  2535. return ehdr + ipv6 + icmp
  2536. def send_na(dev, src_ll=None, target=None, ip_src=None, ip_dst=None, opt=None,
  2537. hapd_bssid=None):
  2538. if hapd_bssid:
  2539. if src_ll is None:
  2540. src_ll = hapd_bssid
  2541. cmd = "DATA_TEST_FRAME ifname=ap-br0 "
  2542. else:
  2543. if src_ll is None:
  2544. src_ll = dev.p2p_interface_addr()
  2545. cmd = "DATA_TEST_FRAME "
  2546. pkt = build_na(src_ll=src_ll, ip_src=ip_src, ip_dst=ip_dst, target=target,
  2547. opt=opt)
  2548. if "OK" not in dev.request(cmd + binascii.hexlify(pkt)):
  2549. raise Exception("DATA_TEST_FRAME failed")
  2550. def build_dhcp_ack(dst_ll, src_ll, ip_src, ip_dst, yiaddr, chaddr,
  2551. subnet_mask="255.255.255.0", truncated_opt=False,
  2552. wrong_magic=False, force_tot_len=None, no_dhcp=False):
  2553. _dst_ll = binascii.unhexlify(dst_ll.replace(':',''))
  2554. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  2555. proto = '\x08\x00'
  2556. ehdr = _dst_ll + _src_ll + proto
  2557. _ip_src = socket.inet_pton(socket.AF_INET, ip_src)
  2558. _ip_dst = socket.inet_pton(socket.AF_INET, ip_dst)
  2559. _subnet_mask = socket.inet_pton(socket.AF_INET, subnet_mask)
  2560. _ciaddr = '\x00\x00\x00\x00'
  2561. _yiaddr = socket.inet_pton(socket.AF_INET, yiaddr)
  2562. _siaddr = '\x00\x00\x00\x00'
  2563. _giaddr = '\x00\x00\x00\x00'
  2564. _chaddr = binascii.unhexlify(chaddr.replace(':','') + "00000000000000000000")
  2565. payload = struct.pack('>BBBBL3BB', 2, 1, 6, 0, 12345, 0, 0, 0, 0)
  2566. payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192*'\x00'
  2567. # magic
  2568. if wrong_magic:
  2569. payload += '\x63\x82\x53\x00'
  2570. else:
  2571. payload += '\x63\x82\x53\x63'
  2572. if truncated_opt:
  2573. payload += '\x22\xff\x00'
  2574. # Option: DHCP Message Type = ACK
  2575. payload += '\x35\x01\x05'
  2576. # Pad Option
  2577. payload += '\x00'
  2578. # Option: Subnet Mask
  2579. payload += '\x01\x04' + _subnet_mask
  2580. # Option: Time Offset
  2581. payload += struct.pack('>BBL', 2, 4, 0)
  2582. # End Option
  2583. payload += '\xff'
  2584. # Pad Option
  2585. payload += '\x00\x00\x00\x00'
  2586. if no_dhcp:
  2587. payload = struct.pack('>BBBBL3BB', 2, 1, 6, 0, 12345, 0, 0, 0, 0)
  2588. payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192*'\x00'
  2589. udp = struct.pack('>HHHH', 67, 68, 8 + len(payload), 0) + payload
  2590. if force_tot_len:
  2591. tot_len = force_tot_len
  2592. else:
  2593. tot_len = 20 + len(udp)
  2594. start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17)
  2595. ipv4 = start + '\x00\x00' + _ip_src + _ip_dst
  2596. csum = ip_checksum(ipv4)
  2597. ipv4 = start + csum + _ip_src + _ip_dst
  2598. return ehdr + ipv4 + udp
  2599. def build_arp(dst_ll, src_ll, opcode, sender_mac, sender_ip,
  2600. target_mac, target_ip):
  2601. _dst_ll = binascii.unhexlify(dst_ll.replace(':',''))
  2602. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  2603. proto = '\x08\x06'
  2604. ehdr = _dst_ll + _src_ll + proto
  2605. _sender_mac = binascii.unhexlify(sender_mac.replace(':',''))
  2606. _sender_ip = socket.inet_pton(socket.AF_INET, sender_ip)
  2607. _target_mac = binascii.unhexlify(target_mac.replace(':',''))
  2608. _target_ip = socket.inet_pton(socket.AF_INET, target_ip)
  2609. arp = struct.pack('>HHBBH', 1, 0x0800, 6, 4, opcode)
  2610. arp += _sender_mac + _sender_ip
  2611. arp += _target_mac + _target_ip
  2612. return ehdr + arp
  2613. def send_arp(dev, dst_ll="ff:ff:ff:ff:ff:ff", src_ll=None, opcode=1,
  2614. sender_mac=None, sender_ip="0.0.0.0",
  2615. target_mac="00:00:00:00:00:00", target_ip="0.0.0.0",
  2616. hapd_bssid=None):
  2617. if hapd_bssid:
  2618. if src_ll is None:
  2619. src_ll = hapd_bssid
  2620. if sender_mac is None:
  2621. sender_mac = hapd_bssid
  2622. cmd = "DATA_TEST_FRAME ifname=ap-br0 "
  2623. else:
  2624. if src_ll is None:
  2625. src_ll = dev.p2p_interface_addr()
  2626. if sender_mac is None:
  2627. sender_mac = dev.p2p_interface_addr()
  2628. cmd = "DATA_TEST_FRAME "
  2629. pkt = build_arp(dst_ll=dst_ll, src_ll=src_ll, opcode=opcode,
  2630. sender_mac=sender_mac, sender_ip=sender_ip,
  2631. target_mac=target_mac, target_ip=target_ip)
  2632. if "OK" not in dev.request(cmd + binascii.hexlify(pkt)):
  2633. raise Exception("DATA_TEST_FRAME failed")
  2634. def get_permanent_neighbors(ifname):
  2635. cmd = subprocess.Popen(['ip', 'nei'], stdout=subprocess.PIPE)
  2636. res = cmd.stdout.read()
  2637. cmd.stdout.close()
  2638. return [ line for line in res.splitlines() if "PERMANENT" in line and ifname in line ]
  2639. def get_bridge_macs(ifname):
  2640. cmd = subprocess.Popen(['brctl', 'showmacs', ifname],
  2641. stdout=subprocess.PIPE)
  2642. res = cmd.stdout.read()
  2643. cmd.stdout.close()
  2644. return res
  2645. def tshark_get_arp(cap, filter):
  2646. res = run_tshark(cap, filter,
  2647. [ "eth.dst", "eth.src",
  2648. "arp.src.hw_mac", "arp.src.proto_ipv4",
  2649. "arp.dst.hw_mac", "arp.dst.proto_ipv4" ],
  2650. wait=False)
  2651. frames = []
  2652. for l in res.splitlines():
  2653. frames.append(l.split('\t'))
  2654. return frames
  2655. def tshark_get_ns(cap):
  2656. res = run_tshark(cap, "icmpv6.type == 135",
  2657. [ "eth.dst", "eth.src",
  2658. "ipv6.src", "ipv6.dst",
  2659. "icmpv6.nd.ns.target_address",
  2660. "icmpv6.opt.linkaddr" ],
  2661. wait=False)
  2662. frames = []
  2663. for l in res.splitlines():
  2664. frames.append(l.split('\t'))
  2665. return frames
  2666. def tshark_get_na(cap):
  2667. res = run_tshark(cap, "icmpv6.type == 136",
  2668. [ "eth.dst", "eth.src",
  2669. "ipv6.src", "ipv6.dst",
  2670. "icmpv6.nd.na.target_address",
  2671. "icmpv6.opt.linkaddr" ],
  2672. wait=False)
  2673. frames = []
  2674. for l in res.splitlines():
  2675. frames.append(l.split('\t'))
  2676. return frames
  2677. def _test_proxyarp_open(dev, apdev, params, ebtables=False):
  2678. prefix = "proxyarp_open"
  2679. if ebtables:
  2680. prefix += "_ebtables"
  2681. cap_br = os.path.join(params['logdir'], prefix + ".ap-br0.pcap")
  2682. cap_dev0 = os.path.join(params['logdir'],
  2683. prefix + ".%s.pcap" % dev[0].ifname)
  2684. cap_dev1 = os.path.join(params['logdir'],
  2685. prefix + ".%s.pcap" % dev[1].ifname)
  2686. cap_dev2 = os.path.join(params['logdir'],
  2687. prefix + ".%s.pcap" % dev[2].ifname)
  2688. bssid = apdev[0]['bssid']
  2689. params = { 'ssid': 'open' }
  2690. params['proxy_arp'] = '1'
  2691. hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True)
  2692. hapd.set("ap_isolate", "1")
  2693. hapd.set('bridge', 'ap-br0')
  2694. hapd.dump_monitor()
  2695. try:
  2696. hapd.enable()
  2697. except:
  2698. # For now, do not report failures due to missing kernel support
  2699. raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version")
  2700. ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=10)
  2701. if ev is None:
  2702. raise Exception("AP startup timed out")
  2703. if "AP-ENABLED" not in ev:
  2704. raise Exception("AP startup failed")
  2705. params2 = { 'ssid': 'another' }
  2706. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params2, no_enable=True)
  2707. hapd2.set('bridge', 'ap-br0')
  2708. hapd2.enable()
  2709. subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
  2710. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  2711. if ebtables:
  2712. for chain in [ 'FORWARD', 'OUTPUT' ]:
  2713. subprocess.call(['ebtables', '-A', chain, '-p', 'ARP',
  2714. '-d', 'Broadcast', '-o', apdev[0]['ifname'],
  2715. '-j', 'DROP'])
  2716. subprocess.call(['ebtables', '-A', chain, '-d', 'Multicast',
  2717. '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp',
  2718. '--ip6-icmp-type', 'neighbor-solicitation',
  2719. '-o', apdev[0]['ifname'], '-j', 'DROP'])
  2720. subprocess.call(['ebtables', '-A', chain, '-d', 'Multicast',
  2721. '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp',
  2722. '--ip6-icmp-type', 'neighbor-advertisement',
  2723. '-o', apdev[0]['ifname'], '-j', 'DROP'])
  2724. subprocess.call(['ebtables', '-A', chain,
  2725. '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp',
  2726. '--ip6-icmp-type', 'router-solicitation',
  2727. '-o', apdev[0]['ifname'], '-j', 'DROP'])
  2728. # Multicast Listener Report Message
  2729. subprocess.call(['ebtables', '-A', chain, '-d', 'Multicast',
  2730. '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp',
  2731. '--ip6-icmp-type', '143',
  2732. '-o', apdev[0]['ifname'], '-j', 'DROP'])
  2733. time.sleep(0.5)
  2734. cmd = {}
  2735. cmd[0] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', 'ap-br0',
  2736. '-w', cap_br, '-s', '2000'],
  2737. stderr=open('/dev/null', 'w'))
  2738. cmd[1] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[0].ifname,
  2739. '-w', cap_dev0, '-s', '2000'],
  2740. stderr=open('/dev/null', 'w'))
  2741. cmd[2] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[1].ifname,
  2742. '-w', cap_dev1, '-s', '2000'],
  2743. stderr=open('/dev/null', 'w'))
  2744. cmd[3] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[2].ifname,
  2745. '-w', cap_dev2, '-s', '2000'],
  2746. stderr=open('/dev/null', 'w'))
  2747. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  2748. dev[1].connect("open", key_mgmt="NONE", scan_freq="2412")
  2749. dev[2].connect("another", key_mgmt="NONE", scan_freq="2412")
  2750. time.sleep(0.1)
  2751. brcmd = subprocess.Popen(['brctl', 'show'], stdout=subprocess.PIPE)
  2752. res = brcmd.stdout.read()
  2753. brcmd.stdout.close()
  2754. logger.info("Bridge setup: " + res)
  2755. brcmd = subprocess.Popen(['brctl', 'showstp', 'ap-br0'],
  2756. stdout=subprocess.PIPE)
  2757. res = brcmd.stdout.read()
  2758. brcmd.stdout.close()
  2759. logger.info("Bridge showstp: " + res)
  2760. addr0 = dev[0].p2p_interface_addr()
  2761. addr1 = dev[1].p2p_interface_addr()
  2762. addr2 = dev[2].p2p_interface_addr()
  2763. src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':',''))
  2764. src_ll_opt1 = "\x01\x01" + binascii.unhexlify(addr1.replace(':',''))
  2765. # DAD NS
  2766. send_ns(dev[0], ip_src="::", target="aaaa:bbbb:cccc::2")
  2767. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2")
  2768. # test frame without source link-layer address option
  2769. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2",
  2770. opt='')
  2771. # test frame with bogus option
  2772. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2",
  2773. opt="\x70\x01\x01\x02\x03\x04\x05\x05")
  2774. # test frame with truncated source link-layer address option
  2775. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2",
  2776. opt="\x01\x01\x01\x02\x03\x04")
  2777. # test frame with foreign source link-layer address option
  2778. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2",
  2779. opt="\x01\x01\x01\x02\x03\x04\x05\x06")
  2780. send_ns(dev[1], ip_src="aaaa:bbbb:dddd::2", target="aaaa:bbbb:dddd::2")
  2781. send_ns(dev[1], ip_src="aaaa:bbbb:eeee::2", target="aaaa:bbbb:eeee::2")
  2782. # another copy for additional code coverage
  2783. send_ns(dev[1], ip_src="aaaa:bbbb:eeee::2", target="aaaa:bbbb:eeee::2")
  2784. pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid,
  2785. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2786. yiaddr="192.168.1.124", chaddr=addr0)
  2787. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2788. raise Exception("DATA_TEST_FRAME failed")
  2789. # Change address and verify unicast
  2790. pkt = build_dhcp_ack(dst_ll=addr0, src_ll=bssid,
  2791. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2792. yiaddr="192.168.1.123", chaddr=addr0)
  2793. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2794. raise Exception("DATA_TEST_FRAME failed")
  2795. # Not-associated client MAC address
  2796. pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid,
  2797. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2798. yiaddr="192.168.1.125", chaddr="22:33:44:55:66:77")
  2799. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2800. raise Exception("DATA_TEST_FRAME failed")
  2801. # No IP address
  2802. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  2803. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2804. yiaddr="0.0.0.0", chaddr=addr1)
  2805. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2806. raise Exception("DATA_TEST_FRAME failed")
  2807. # Zero subnet mask
  2808. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  2809. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2810. yiaddr="192.168.1.126", chaddr=addr1,
  2811. subnet_mask="0.0.0.0")
  2812. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2813. raise Exception("DATA_TEST_FRAME failed")
  2814. # Truncated option
  2815. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  2816. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2817. yiaddr="192.168.1.127", chaddr=addr1,
  2818. truncated_opt=True)
  2819. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2820. raise Exception("DATA_TEST_FRAME failed")
  2821. # Wrong magic
  2822. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  2823. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2824. yiaddr="192.168.1.128", chaddr=addr1,
  2825. wrong_magic=True)
  2826. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2827. raise Exception("DATA_TEST_FRAME failed")
  2828. # Wrong IPv4 total length
  2829. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  2830. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2831. yiaddr="192.168.1.129", chaddr=addr1,
  2832. force_tot_len=1000)
  2833. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2834. raise Exception("DATA_TEST_FRAME failed")
  2835. # BOOTP
  2836. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  2837. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2838. yiaddr="192.168.1.129", chaddr=addr1,
  2839. no_dhcp=True)
  2840. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2841. raise Exception("DATA_TEST_FRAME failed")
  2842. macs = get_bridge_macs("ap-br0")
  2843. logger.info("After connect (showmacs): " + str(macs))
  2844. matches = get_permanent_neighbors("ap-br0")
  2845. logger.info("After connect: " + str(matches))
  2846. if len(matches) != 4:
  2847. raise Exception("Unexpected number of neighbor entries after connect")
  2848. if 'aaaa:bbbb:cccc::2 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  2849. raise Exception("dev0 addr missing")
  2850. if 'aaaa:bbbb:dddd::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches:
  2851. raise Exception("dev1 addr(1) missing")
  2852. if 'aaaa:bbbb:eeee::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches:
  2853. raise Exception("dev1 addr(2) missing")
  2854. if '192.168.1.123 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  2855. raise Exception("dev0 IPv4 addr missing")
  2856. targets = [ "192.168.1.123", "192.168.1.124", "192.168.1.125",
  2857. "192.168.1.126" ]
  2858. for target in targets:
  2859. send_arp(dev[1], sender_ip="192.168.1.100", target_ip=target)
  2860. for target in targets:
  2861. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.101",
  2862. target_ip=target)
  2863. for target in targets:
  2864. send_arp(dev[2], sender_ip="192.168.1.103", target_ip=target)
  2865. # ARP Probe from wireless STA
  2866. send_arp(dev[1], target_ip="192.168.1.127")
  2867. # ARP Announcement from wireless STA
  2868. send_arp(dev[1], sender_ip="192.168.1.127", target_ip="192.168.1.127")
  2869. send_arp(dev[1], sender_ip="192.168.1.127", target_ip="192.168.1.127",
  2870. opcode=2)
  2871. macs = get_bridge_macs("ap-br0")
  2872. logger.info("After ARP Probe + Announcement (showmacs): " + str(macs))
  2873. matches = get_permanent_neighbors("ap-br0")
  2874. logger.info("After ARP Probe + Announcement: " + str(matches))
  2875. # ARP Request for the newly introduced IP address from wireless STA
  2876. send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.127")
  2877. # ARP Request for the newly introduced IP address from bridge
  2878. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.102",
  2879. target_ip="192.168.1.127")
  2880. send_arp(dev[2], sender_ip="192.168.1.103", target_ip="192.168.1.127")
  2881. # ARP Probe from bridge
  2882. send_arp(hapd, hapd_bssid=bssid, target_ip="192.168.1.130")
  2883. send_arp(dev[2], target_ip="192.168.1.131")
  2884. # ARP Announcement from bridge (not to be learned by AP for proxyarp)
  2885. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.130",
  2886. target_ip="192.168.1.130")
  2887. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.130",
  2888. target_ip="192.168.1.130", opcode=2)
  2889. send_arp(dev[2], sender_ip="192.168.1.131", target_ip="192.168.1.131")
  2890. send_arp(dev[2], sender_ip="192.168.1.131", target_ip="192.168.1.131",
  2891. opcode=2)
  2892. macs = get_bridge_macs("ap-br0")
  2893. logger.info("After ARP Probe + Announcement (showmacs): " + str(macs))
  2894. matches = get_permanent_neighbors("ap-br0")
  2895. logger.info("After ARP Probe + Announcement: " + str(matches))
  2896. # ARP Request for the newly introduced IP address from wireless STA
  2897. send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.130")
  2898. # ARP Response from bridge (AP does not proxy for non-wireless devices)
  2899. send_arp(hapd, hapd_bssid=bssid, dst_ll=addr0, sender_ip="192.168.1.130",
  2900. target_ip="192.168.1.123", opcode=2)
  2901. # ARP Request for the newly introduced IP address from wireless STA
  2902. send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.131")
  2903. # ARP Response from bridge (AP does not proxy for non-wireless devices)
  2904. send_arp(dev[2], dst_ll=addr0, sender_ip="192.168.1.131",
  2905. target_ip="192.168.1.123", opcode=2)
  2906. # ARP Request for the newly introduced IP address from bridge
  2907. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.102",
  2908. target_ip="192.168.1.130")
  2909. send_arp(dev[2], sender_ip="192.168.1.104", target_ip="192.168.1.131")
  2910. # ARP Probe from wireless STA (duplicate address; learned through DHCP)
  2911. send_arp(dev[1], target_ip="192.168.1.123")
  2912. # ARP Probe from wireless STA (duplicate address; learned through ARP)
  2913. send_arp(dev[0], target_ip="192.168.1.127")
  2914. # Gratuitous ARP Reply for another STA's IP address
  2915. send_arp(dev[0], opcode=2, sender_mac=addr0, sender_ip="192.168.1.127",
  2916. target_mac=addr1, target_ip="192.168.1.127")
  2917. send_arp(dev[1], opcode=2, sender_mac=addr1, sender_ip="192.168.1.123",
  2918. target_mac=addr0, target_ip="192.168.1.123")
  2919. # ARP Request to verify previous mapping
  2920. send_arp(dev[1], sender_ip="192.168.1.127", target_ip="192.168.1.123")
  2921. send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.127")
  2922. time.sleep(0.1)
  2923. send_ns(dev[0], target="aaaa:bbbb:dddd::2", ip_src="aaaa:bbbb:cccc::2")
  2924. time.sleep(0.1)
  2925. send_ns(dev[1], target="aaaa:bbbb:cccc::2", ip_src="aaaa:bbbb:dddd::2")
  2926. time.sleep(0.1)
  2927. send_ns(hapd, hapd_bssid=bssid, target="aaaa:bbbb:dddd::2",
  2928. ip_src="aaaa:bbbb:ffff::2")
  2929. time.sleep(0.1)
  2930. send_ns(dev[2], target="aaaa:bbbb:cccc::2", ip_src="aaaa:bbbb:ff00::2")
  2931. time.sleep(0.1)
  2932. send_ns(dev[2], target="aaaa:bbbb:dddd::2", ip_src="aaaa:bbbb:ff00::2")
  2933. time.sleep(0.1)
  2934. send_ns(dev[2], target="aaaa:bbbb:eeee::2", ip_src="aaaa:bbbb:ff00::2")
  2935. time.sleep(0.1)
  2936. # Try to probe for an already assigned address
  2937. send_ns(dev[1], target="aaaa:bbbb:cccc::2", ip_src="::")
  2938. time.sleep(0.1)
  2939. send_ns(hapd, hapd_bssid=bssid, target="aaaa:bbbb:cccc::2", ip_src="::")
  2940. time.sleep(0.1)
  2941. send_ns(dev[2], target="aaaa:bbbb:cccc::2", ip_src="::")
  2942. time.sleep(0.1)
  2943. # Unsolicited NA
  2944. send_na(dev[1], target="aaaa:bbbb:cccc:aeae::3",
  2945. ip_src="aaaa:bbbb:cccc:aeae::3", ip_dst="ff02::1")
  2946. send_na(hapd, hapd_bssid=bssid, target="aaaa:bbbb:cccc:aeae::4",
  2947. ip_src="aaaa:bbbb:cccc:aeae::4", ip_dst="ff02::1")
  2948. send_na(dev[2], target="aaaa:bbbb:cccc:aeae::5",
  2949. ip_src="aaaa:bbbb:cccc:aeae::5", ip_dst="ff02::1")
  2950. try:
  2951. hwsim_utils.test_connectivity_iface(dev[0], hapd, "ap-br0")
  2952. except Exception, e:
  2953. logger.info("test_connectibity_iface failed: " + str(e))
  2954. raise HwsimSkip("Assume kernel did not have the required patches for proxyarp")
  2955. hwsim_utils.test_connectivity_iface(dev[1], hapd, "ap-br0")
  2956. hwsim_utils.test_connectivity(dev[0], dev[1])
  2957. dev[0].request("DISCONNECT")
  2958. dev[1].request("DISCONNECT")
  2959. time.sleep(0.5)
  2960. for i in range(len(cmd)):
  2961. cmd[i].terminate()
  2962. macs = get_bridge_macs("ap-br0")
  2963. logger.info("After disconnect (showmacs): " + str(macs))
  2964. matches = get_permanent_neighbors("ap-br0")
  2965. logger.info("After disconnect: " + str(matches))
  2966. if len(matches) > 0:
  2967. raise Exception("Unexpected neighbor entries after disconnect")
  2968. if ebtables:
  2969. cmd = subprocess.Popen(['ebtables', '-L', '--Lc'],
  2970. stdout=subprocess.PIPE)
  2971. res = cmd.stdout.read()
  2972. cmd.stdout.close()
  2973. logger.info("ebtables results:\n" + res)
  2974. # Verify that expected ARP messages were seen and no unexpected
  2975. # ARP messages were seen.
  2976. arp_req = tshark_get_arp(cap_dev0, "arp.opcode == 1")
  2977. arp_reply = tshark_get_arp(cap_dev0, "arp.opcode == 2")
  2978. logger.info("dev0 seen ARP requests:\n" + str(arp_req))
  2979. logger.info("dev0 seen ARP replies:\n" + str(arp_reply))
  2980. if [ 'ff:ff:ff:ff:ff:ff', addr1,
  2981. addr1, '192.168.1.100',
  2982. '00:00:00:00:00:00', '192.168.1.123' ] in arp_req:
  2983. raise Exception("dev0 saw ARP request from dev1")
  2984. if [ 'ff:ff:ff:ff:ff:ff', addr2,
  2985. addr2, '192.168.1.103',
  2986. '00:00:00:00:00:00', '192.168.1.123' ] in arp_req:
  2987. raise Exception("dev0 saw ARP request from dev2")
  2988. # TODO: Uncomment once fixed in kernel
  2989. #if [ 'ff:ff:ff:ff:ff:ff', bssid,
  2990. # bssid, '192.168.1.101',
  2991. # '00:00:00:00:00:00', '192.168.1.123' ] in arp_req:
  2992. # raise Exception("dev0 saw ARP request from br")
  2993. if ebtables:
  2994. for req in arp_req:
  2995. if req[1] != addr0:
  2996. raise Exception("Unexpected foreign ARP request on dev0")
  2997. arp_req = tshark_get_arp(cap_dev1, "arp.opcode == 1")
  2998. arp_reply = tshark_get_arp(cap_dev1, "arp.opcode == 2")
  2999. logger.info("dev1 seen ARP requests:\n" + str(arp_req))
  3000. logger.info("dev1 seen ARP replies:\n" + str(arp_reply))
  3001. if [ 'ff:ff:ff:ff:ff:ff', addr2,
  3002. addr2, '192.168.1.103',
  3003. '00:00:00:00:00:00', '192.168.1.123' ] in arp_req:
  3004. raise Exception("dev1 saw ARP request from dev2")
  3005. if [addr1, addr0, addr0, '192.168.1.123', addr1, '192.168.1.100'] not in arp_reply:
  3006. raise Exception("dev1 did not get ARP response for 192.168.1.123")
  3007. if ebtables:
  3008. for req in arp_req:
  3009. if req[1] != addr1:
  3010. raise Exception("Unexpected foreign ARP request on dev1")
  3011. arp_req = tshark_get_arp(cap_dev2, "arp.opcode == 1")
  3012. arp_reply = tshark_get_arp(cap_dev2, "arp.opcode == 2")
  3013. logger.info("dev2 seen ARP requests:\n" + str(arp_req))
  3014. logger.info("dev2 seen ARP replies:\n" + str(arp_reply))
  3015. if [ addr2, addr0,
  3016. addr0, '192.168.1.123',
  3017. addr2, '192.168.1.103' ] not in arp_reply:
  3018. raise Exception("dev2 did not get ARP response for 192.168.1.123")
  3019. arp_req = tshark_get_arp(cap_br, "arp.opcode == 1")
  3020. arp_reply = tshark_get_arp(cap_br, "arp.opcode == 2")
  3021. logger.info("br seen ARP requests:\n" + str(arp_req))
  3022. logger.info("br seen ARP replies:\n" + str(arp_reply))
  3023. # TODO: Uncomment once fixed in kernel
  3024. #if [ bssid, addr0,
  3025. # addr0, '192.168.1.123',
  3026. # bssid, '192.168.1.101' ] not in arp_reply:
  3027. # raise Exception("br did not get ARP response for 192.168.1.123")
  3028. ns = tshark_get_ns(cap_dev0)
  3029. logger.info("dev0 seen NS: " + str(ns))
  3030. na = tshark_get_na(cap_dev0)
  3031. logger.info("dev0 seen NA: " + str(na))
  3032. if [ addr0, addr1, 'aaaa:bbbb:dddd::2', 'aaaa:bbbb:cccc::2',
  3033. 'aaaa:bbbb:dddd::2', addr1 ] not in na:
  3034. raise Exception("dev0 did not get NA for aaaa:bbbb:dddd::2")
  3035. if ebtables:
  3036. for req in ns:
  3037. if req[1] != addr0:
  3038. raise Exception("Unexpected foreign NS on dev0: " + str(req))
  3039. ns = tshark_get_ns(cap_dev1)
  3040. logger.info("dev1 seen NS: " + str(ns))
  3041. na = tshark_get_na(cap_dev1)
  3042. logger.info("dev1 seen NA: " + str(na))
  3043. if [ addr1, addr0, 'aaaa:bbbb:cccc::2', 'aaaa:bbbb:dddd::2',
  3044. 'aaaa:bbbb:cccc::2', addr0 ] not in na:
  3045. raise Exception("dev1 did not get NA for aaaa:bbbb:cccc::2")
  3046. if ebtables:
  3047. for req in ns:
  3048. if req[1] != addr1:
  3049. raise Exception("Unexpected foreign NS on dev1: " + str(req))
  3050. ns = tshark_get_ns(cap_dev2)
  3051. logger.info("dev2 seen NS: " + str(ns))
  3052. na = tshark_get_na(cap_dev2)
  3053. logger.info("dev2 seen NA: " + str(na))
  3054. # FIX: enable once kernel implementation for proxyarp IPv6 is fixed
  3055. #if [ addr2, addr0, 'aaaa:bbbb:cccc::2', 'aaaa:bbbb:ff00::2',
  3056. # 'aaaa:bbbb:cccc::2', addr0 ] not in na:
  3057. # raise Exception("dev2 did not get NA for aaaa:bbbb:cccc::2")
  3058. #if [ addr2, addr1, 'aaaa:bbbb:dddd::2', 'aaaa:bbbb:ff00::2',
  3059. # 'aaaa:bbbb:dddd::2', addr1 ] not in na:
  3060. # raise Exception("dev2 did not get NA for aaaa:bbbb:dddd::2")
  3061. #if [ addr2, addr1, 'aaaa:bbbb:eeee::2', 'aaaa:bbbb:ff00::2',
  3062. # 'aaaa:bbbb:eeee::2', addr1 ] not in na:
  3063. # raise Exception("dev2 did not get NA for aaaa:bbbb:eeee::2")
  3064. def test_proxyarp_open(dev, apdev, params):
  3065. """ProxyARP with open network"""
  3066. try:
  3067. _test_proxyarp_open(dev, apdev, params)
  3068. finally:
  3069. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  3070. stderr=open('/dev/null', 'w'))
  3071. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  3072. stderr=open('/dev/null', 'w'))
  3073. def test_proxyarp_open_ebtables(dev, apdev, params):
  3074. """ProxyARP with open network"""
  3075. try:
  3076. _test_proxyarp_open(dev, apdev, params, ebtables=True)
  3077. finally:
  3078. try:
  3079. subprocess.call(['ebtables', '-F', 'FORWARD'])
  3080. subprocess.call(['ebtables', '-F', 'OUTPUT'])
  3081. except:
  3082. pass
  3083. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  3084. stderr=open('/dev/null', 'w'))
  3085. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  3086. stderr=open('/dev/null', 'w'))
  3087. def test_ap_hs20_connect_deinit(dev, apdev):
  3088. """Hotspot 2.0 connection interrupted with deinit"""
  3089. check_eap_capa(dev[0], "MSCHAPV2")
  3090. bssid = apdev[0]['bssid']
  3091. params = hs20_ap_params()
  3092. params['hessid'] = bssid
  3093. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3094. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  3095. wpas.interface_add("wlan5", drv_params="")
  3096. wpas.hs20_enable()
  3097. wpas.flush_scan_cache()
  3098. wpas.add_cred_values({ 'realm': "example.com",
  3099. 'username': "hs20-test",
  3100. 'password': "password",
  3101. 'ca_cert': "auth_serv/ca.pem",
  3102. 'domain': "example.com" })
  3103. wpas.scan_for_bss(bssid, freq=2412)
  3104. hapd.disable()
  3105. wpas.request("INTERWORKING_SELECT freq=2412")
  3106. id = wpas.request("RADIO_WORK add block-work")
  3107. ev = wpas.wait_event(["GAS-QUERY-START", "EXT-RADIO-WORK-START"], timeout=5)
  3108. if ev is None:
  3109. raise Exception("Timeout while waiting radio work to start")
  3110. ev = wpas.wait_event(["GAS-QUERY-START", "EXT-RADIO-WORK-START"], timeout=5)
  3111. if ev is None:
  3112. raise Exception("Timeout while waiting radio work to start (2)")
  3113. # Remove the interface while the gas-query radio work is still pending and
  3114. # GAS query has not yet been started.
  3115. wpas.interface_remove("wlan5")