test_ap_hs20.py 122 KB

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