test_ap_hs20.py 139 KB

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