test_ap_hs20.py 160 KB

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