test_ap_hs20.py 139 KB

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