test_ap_hs20.py 138 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452
  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_fetch_osu(dev, apdev):
  1825. """Hotspot 2.0 OSU provider and icon fetch"""
  1826. bssid = apdev[0]['bssid']
  1827. params = hs20_ap_params()
  1828. params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png"
  1829. params['osu_ssid'] = '"HS 2.0 OSU open"'
  1830. params['osu_method_list'] = "1"
  1831. params['osu_friendly_name'] = [ "eng:Test OSU", "fin:Testi-OSU" ]
  1832. params['osu_icon'] = "w1fi_logo"
  1833. params['osu_service_desc'] = [ "eng:Example services", "fin:Esimerkkipalveluja" ]
  1834. params['osu_server_uri'] = "https://example.com/osu/"
  1835. hostapd.add_ap(apdev[0]['ifname'], params)
  1836. bssid2 = apdev[1]['bssid']
  1837. params = hs20_ap_params(ssid="test-hs20b")
  1838. params['hessid'] = bssid2
  1839. params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png"
  1840. params['osu_ssid'] = '"HS 2.0 OSU OSEN"'
  1841. params['osu_method_list'] = "0"
  1842. params['osu_nai'] = "osen@example.com"
  1843. params['osu_friendly_name'] = [ "eng:Test2 OSU", "fin:Testi2-OSU" ]
  1844. params['osu_icon'] = "w1fi_logo"
  1845. params['osu_service_desc'] = [ "eng:Example services2", "fin:Esimerkkipalveluja2" ]
  1846. params['osu_server_uri'] = "https://example.org/osu/"
  1847. hostapd.add_ap(apdev[1]['ifname'], params)
  1848. with open("w1fi_logo.png", "r") as f:
  1849. orig_logo = f.read()
  1850. dev[0].hs20_enable()
  1851. dir = "/tmp/osu-fetch"
  1852. if os.path.isdir(dir):
  1853. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  1854. for f in files:
  1855. os.remove(dir + "/" + f)
  1856. else:
  1857. try:
  1858. os.makedirs(dir)
  1859. except:
  1860. pass
  1861. try:
  1862. dev[1].scan_for_bss(bssid, freq="2412")
  1863. dev[0].request("SET osu_dir " + dir)
  1864. dev[0].request("FETCH_OSU")
  1865. if "FAIL" not in dev[1].request("HS20_ICON_REQUEST foo w1fi_logo"):
  1866. raise Exception("Invalid HS20_ICON_REQUEST accepted")
  1867. if "OK" not in dev[1].request("HS20_ICON_REQUEST " + bssid + " w1fi_logo"):
  1868. raise Exception("HS20_ICON_REQUEST failed")
  1869. icons = 0
  1870. while True:
  1871. ev = dev[0].wait_event(["OSU provider fetch completed",
  1872. "RX-HS20-ANQP-ICON"], timeout=15)
  1873. if ev is None:
  1874. raise Exception("Timeout on OSU fetch")
  1875. if "OSU provider fetch completed" in ev:
  1876. break
  1877. if "RX-HS20-ANQP-ICON" in ev:
  1878. with open(ev.split(' ')[1], "r") as f:
  1879. logo = f.read()
  1880. if logo == orig_logo:
  1881. icons += 1
  1882. with open(dir + "/osu-providers.txt", "r") as f:
  1883. prov = f.read()
  1884. logger.debug("osu-providers.txt: " + prov)
  1885. if "OSU-PROVIDER " + bssid not in prov:
  1886. raise Exception("Missing OSU_PROVIDER(1)")
  1887. if "OSU-PROVIDER " + bssid2 not in prov:
  1888. raise Exception("Missing OSU_PROVIDER(2)")
  1889. finally:
  1890. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  1891. for f in files:
  1892. os.remove(dir + "/" + f)
  1893. os.rmdir(dir)
  1894. if icons != 2:
  1895. raise Exception("Unexpected number of icons fetched")
  1896. ev = dev[1].wait_event(["GAS-QUERY-START"], timeout=5)
  1897. if ev is None:
  1898. raise Exception("Timeout on GAS-QUERY-DONE")
  1899. ev = dev[1].wait_event(["GAS-QUERY-DONE"], timeout=5)
  1900. if ev is None:
  1901. raise Exception("Timeout on GAS-QUERY-DONE")
  1902. if "freq=2412 status_code=0 result=SUCCESS" not in ev:
  1903. raise Exception("Unexpected GAS-QUERY-DONE: " + ev)
  1904. ev = dev[1].wait_event(["RX-HS20-ANQP"], timeout=15)
  1905. if ev is None:
  1906. raise Exception("Timeout on icon fetch")
  1907. if "Icon Binary File" not in ev:
  1908. raise Exception("Unexpected ANQP element")
  1909. def test_ap_hs20_fetch_osu_stop(dev, apdev):
  1910. """Hotspot 2.0 OSU provider fetch stopped"""
  1911. bssid = apdev[0]['bssid']
  1912. params = hs20_ap_params()
  1913. params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png"
  1914. params['osu_ssid'] = '"HS 2.0 OSU open"'
  1915. params['osu_method_list'] = "1"
  1916. params['osu_friendly_name'] = [ "eng:Test OSU", "fin:Testi-OSU" ]
  1917. params['osu_icon'] = "w1fi_logo"
  1918. params['osu_service_desc'] = [ "eng:Example services", "fin:Esimerkkipalveluja" ]
  1919. params['osu_server_uri'] = "https://example.com/osu/"
  1920. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1921. dev[0].hs20_enable()
  1922. dir = "/tmp/osu-fetch"
  1923. if os.path.isdir(dir):
  1924. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  1925. for f in files:
  1926. os.remove(dir + "/" + f)
  1927. else:
  1928. try:
  1929. os.makedirs(dir)
  1930. except:
  1931. pass
  1932. try:
  1933. dev[0].request("SET osu_dir " + dir)
  1934. dev[0].request("SCAN freq=2412-2462")
  1935. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=10)
  1936. if ev is None:
  1937. raise Exception("Scan did not start")
  1938. if "FAIL" not in dev[0].request("FETCH_OSU"):
  1939. raise Exception("FETCH_OSU accepted while scanning")
  1940. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
  1941. if ev is None:
  1942. raise Exception("Scan timed out")
  1943. hapd.set("ext_mgmt_frame_handling", "1")
  1944. dev[0].request("FETCH_ANQP")
  1945. if "FAIL" not in dev[0].request("FETCH_OSU"):
  1946. raise Exception("FETCH_OSU accepted while in FETCH_ANQP")
  1947. dev[0].request("STOP_FETCH_ANQP")
  1948. dev[0].wait_event(["GAS-QUERY-DONE"], timeout=5)
  1949. dev[0].dump_monitor()
  1950. hapd.dump_monitor()
  1951. dev[0].request("INTERWORKING_SELECT freq=2412")
  1952. for i in range(5):
  1953. msg = hapd.mgmt_rx()
  1954. if msg['subtype'] == 13:
  1955. break
  1956. if "FAIL" not in dev[0].request("FETCH_OSU"):
  1957. raise Exception("FETCH_OSU accepted while in INTERWORKING_SELECT")
  1958. ev = dev[0].wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
  1959. timeout=15)
  1960. if ev is None:
  1961. raise Exception("Network selection timed out");
  1962. dev[0].dump_monitor()
  1963. if "OK" not in dev[0].request("FETCH_OSU"):
  1964. raise Exception("FETCH_OSU failed")
  1965. dev[0].request("CANCEL_FETCH_OSU")
  1966. for i in range(15):
  1967. time.sleep(0.5)
  1968. if dev[0].get_driver_status_field("scan_state") == "SCAN_COMPLETED":
  1969. break
  1970. dev[0].dump_monitor()
  1971. if "OK" not in dev[0].request("FETCH_OSU"):
  1972. raise Exception("FETCH_OSU failed")
  1973. if "FAIL" not in dev[0].request("FETCH_OSU"):
  1974. raise Exception("FETCH_OSU accepted while in FETCH_OSU")
  1975. ev = dev[0].wait_event(["GAS-QUERY-START"], 10)
  1976. if ev is None:
  1977. raise Exception("GAS timed out")
  1978. if "FAIL" not in dev[0].request("FETCH_OSU"):
  1979. raise Exception("FETCH_OSU accepted while in FETCH_OSU")
  1980. dev[0].request("CANCEL_FETCH_OSU")
  1981. ev = dev[0].wait_event(["GAS-QUERY-DONE"], 10)
  1982. if ev is None:
  1983. raise Exception("GAS event timed out after CANCEL_FETCH_OSU")
  1984. finally:
  1985. files = [ f for f in os.listdir(dir) if f.startswith("osu-") ]
  1986. for f in files:
  1987. os.remove(dir + "/" + f)
  1988. os.rmdir(dir)
  1989. def test_ap_hs20_ft(dev, apdev):
  1990. """Hotspot 2.0 connection with FT"""
  1991. bssid = apdev[0]['bssid']
  1992. params = hs20_ap_params()
  1993. params['wpa_key_mgmt'] = "FT-EAP"
  1994. params['nas_identifier'] = "nas1.w1.fi"
  1995. params['r1_key_holder'] = "000102030405"
  1996. params["mobility_domain"] = "a1b2"
  1997. params["reassociation_deadline"] = "1000"
  1998. hostapd.add_ap(apdev[0]['ifname'], params)
  1999. dev[0].hs20_enable()
  2000. id = dev[0].add_cred_values({ 'realm': "example.com",
  2001. 'username': "hs20-test",
  2002. 'password': "password",
  2003. 'ca_cert': "auth_serv/ca.pem",
  2004. 'domain': "example.com",
  2005. 'update_identifier': "1234" })
  2006. interworking_select(dev[0], bssid, "home", freq="2412")
  2007. interworking_connect(dev[0], bssid, "TTLS")
  2008. def test_ap_hs20_remediation_sql(dev, apdev, params):
  2009. """Hotspot 2.0 connection and remediation required using SQLite for user DB"""
  2010. try:
  2011. import sqlite3
  2012. except ImportError:
  2013. raise HwsimSkip("No sqlite3 module available")
  2014. dbfile = os.path.join(params['logdir'], "eap-user.db")
  2015. try:
  2016. os.remove(dbfile)
  2017. except:
  2018. pass
  2019. con = sqlite3.connect(dbfile)
  2020. with con:
  2021. cur = con.cursor()
  2022. cur.execute("CREATE TABLE users(identity TEXT PRIMARY KEY, methods TEXT, password TEXT, remediation TEXT, phase2 INTEGER)")
  2023. cur.execute("CREATE TABLE wildcards(identity TEXT PRIMARY KEY, methods TEXT)")
  2024. cur.execute("INSERT INTO users(identity,methods,password,phase2,remediation) VALUES ('user-mschapv2','TTLS-MSCHAPV2','password',1,'user')")
  2025. cur.execute("INSERT INTO wildcards(identity,methods) VALUES ('','TTLS,TLS')")
  2026. cur.execute("CREATE TABLE authlog(timestamp TEXT, session TEXT, nas_ip TEXT, username TEXT, note TEXT)")
  2027. try:
  2028. params = { "ssid": "as", "beacon_int": "2000",
  2029. "radius_server_clients": "auth_serv/radius_clients.conf",
  2030. "radius_server_auth_port": '18128',
  2031. "eap_server": "1",
  2032. "eap_user_file": "sqlite:" + dbfile,
  2033. "ca_cert": "auth_serv/ca.pem",
  2034. "server_cert": "auth_serv/server.pem",
  2035. "private_key": "auth_serv/server.key",
  2036. "subscr_remediation_url": "https://example.org/",
  2037. "subscr_remediation_method": "1" }
  2038. hostapd.add_ap(apdev[1]['ifname'], params)
  2039. bssid = apdev[0]['bssid']
  2040. params = hs20_ap_params()
  2041. params['auth_server_port'] = "18128"
  2042. hostapd.add_ap(apdev[0]['ifname'], params)
  2043. dev[0].request("SET pmf 1")
  2044. dev[0].hs20_enable()
  2045. id = dev[0].add_cred_values({ 'realm': "example.com",
  2046. 'username': "user-mschapv2",
  2047. 'password': "password",
  2048. 'ca_cert': "auth_serv/ca.pem" })
  2049. interworking_select(dev[0], bssid, freq="2412")
  2050. interworking_connect(dev[0], bssid, "TTLS")
  2051. ev = dev[0].wait_event(["HS20-SUBSCRIPTION-REMEDIATION"], timeout=5)
  2052. if ev is None:
  2053. raise Exception("Timeout on subscription remediation notice")
  2054. if " 1 https://example.org/" not in ev:
  2055. raise Exception("Unexpected subscription remediation event contents")
  2056. with con:
  2057. cur = con.cursor()
  2058. cur.execute("SELECT * from authlog")
  2059. rows = cur.fetchall()
  2060. if len(rows) < 1:
  2061. raise Exception("No authlog entries")
  2062. finally:
  2063. os.remove(dbfile)
  2064. dev[0].request("SET pmf 0")
  2065. def test_ap_hs20_external_selection(dev, apdev):
  2066. """Hotspot 2.0 connection using external network selection and creation"""
  2067. bssid = apdev[0]['bssid']
  2068. params = hs20_ap_params()
  2069. params['hessid'] = bssid
  2070. params['disable_dgaf'] = '1'
  2071. hostapd.add_ap(apdev[0]['ifname'], params)
  2072. dev[0].hs20_enable()
  2073. dev[0].connect("test-hs20", proto="RSN", key_mgmt="WPA-EAP", eap="TTLS",
  2074. identity="hs20-test", password="password",
  2075. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2076. scan_freq="2412", update_identifier="54321")
  2077. if dev[0].get_status_field("hs20") != "2":
  2078. raise Exception("Unexpected hs20 indication")
  2079. def test_ap_hs20_random_mac_addr(dev, apdev):
  2080. """Hotspot 2.0 connection with random MAC address"""
  2081. bssid = apdev[0]['bssid']
  2082. params = hs20_ap_params()
  2083. params['hessid'] = bssid
  2084. params['disable_dgaf'] = '1'
  2085. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2086. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  2087. wpas.interface_add("wlan5")
  2088. addr = wpas.p2p_interface_addr()
  2089. wpas.request("SET mac_addr 1")
  2090. wpas.request("SET preassoc_mac_addr 1")
  2091. wpas.request("SET rand_addr_lifetime 60")
  2092. wpas.hs20_enable()
  2093. wpas.flush_scan_cache()
  2094. id = wpas.add_cred_values({ 'realm': "example.com",
  2095. 'username': "hs20-test",
  2096. 'password': "password",
  2097. 'ca_cert': "auth_serv/ca.pem",
  2098. 'domain': "example.com",
  2099. 'update_identifier': "1234" })
  2100. interworking_select(wpas, bssid, "home", freq="2412")
  2101. interworking_connect(wpas, bssid, "TTLS")
  2102. addr1 = wpas.get_driver_status_field("addr")
  2103. if addr == addr1:
  2104. raise Exception("Did not use random MAC address")
  2105. sta = hapd.get_sta(addr)
  2106. if sta['addr'] != "FAIL":
  2107. raise Exception("Unexpected STA association with permanent address")
  2108. sta = hapd.get_sta(addr1)
  2109. if sta['addr'] != addr1:
  2110. raise Exception("STA association with random address not found")
  2111. def test_ap_hs20_multi_network_and_cred_removal(dev, apdev):
  2112. """Multiple networks and cred removal"""
  2113. bssid = apdev[0]['bssid']
  2114. params = hs20_ap_params()
  2115. params['nai_realm'] = [ "0,example.com,25[3:26]"]
  2116. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2117. dev[0].add_network()
  2118. dev[0].hs20_enable()
  2119. id = dev[0].add_cred_values({ 'realm': "example.com",
  2120. 'username': "user",
  2121. 'password': "password" })
  2122. interworking_select(dev[0], bssid, freq="2412")
  2123. interworking_connect(dev[0], bssid, "PEAP")
  2124. dev[0].add_network()
  2125. dev[0].request("DISCONNECT")
  2126. dev[0].wait_disconnected(timeout=10)
  2127. hapd.disable()
  2128. hapd.set("ssid", "another ssid")
  2129. hapd.enable()
  2130. interworking_select(dev[0], bssid, freq="2412")
  2131. interworking_connect(dev[0], bssid, "PEAP")
  2132. dev[0].add_network()
  2133. if len(dev[0].list_networks()) != 5:
  2134. raise Exception("Unexpected number of networks prior to remove_crec")
  2135. dev[0].dump_monitor()
  2136. dev[0].remove_cred(id)
  2137. if len(dev[0].list_networks()) != 3:
  2138. raise Exception("Unexpected number of networks after to remove_crec")
  2139. dev[0].wait_disconnected(timeout=10)
  2140. def test_ap_hs20_interworking_add_network(dev, apdev):
  2141. """Hotspot 2.0 connection using INTERWORKING_ADD_NETWORK"""
  2142. bssid = apdev[0]['bssid']
  2143. params = hs20_ap_params()
  2144. params['nai_realm'] = [ "0,example.com,21[3:26][6:7][99:99]" ]
  2145. hostapd.add_ap(apdev[0]['ifname'], params)
  2146. dev[0].hs20_enable()
  2147. dev[0].add_cred_values(default_cred(user="user"))
  2148. interworking_select(dev[0], bssid, freq=2412)
  2149. id = dev[0].interworking_add_network(bssid)
  2150. dev[0].select_network(id, freq=2412)
  2151. dev[0].wait_connected()
  2152. def _test_ap_hs20_proxyarp(dev, apdev):
  2153. bssid = apdev[0]['bssid']
  2154. params = hs20_ap_params()
  2155. params['hessid'] = bssid
  2156. params['disable_dgaf'] = '0'
  2157. params['proxy_arp'] = '1'
  2158. hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True)
  2159. if "OK" in hapd.request("ENABLE"):
  2160. raise Exception("Incomplete hostapd configuration was accepted")
  2161. hapd.set("ap_isolate", "1")
  2162. if "OK" in hapd.request("ENABLE"):
  2163. raise Exception("Incomplete hostapd configuration was accepted")
  2164. hapd.set('bridge', 'ap-br0')
  2165. hapd.dump_monitor()
  2166. try:
  2167. hapd.enable()
  2168. except:
  2169. # For now, do not report failures due to missing kernel support
  2170. raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version")
  2171. ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=10)
  2172. if ev is None:
  2173. raise Exception("AP startup timed out")
  2174. if "AP-ENABLED" not in ev:
  2175. raise Exception("AP startup failed")
  2176. dev[0].hs20_enable()
  2177. subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
  2178. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  2179. id = dev[0].add_cred_values({ 'realm': "example.com",
  2180. 'username': "hs20-test",
  2181. 'password': "password",
  2182. 'ca_cert': "auth_serv/ca.pem",
  2183. 'domain': "example.com",
  2184. 'update_identifier': "1234" })
  2185. interworking_select(dev[0], bssid, "home", freq="2412")
  2186. interworking_connect(dev[0], bssid, "TTLS")
  2187. dev[1].connect("test-hs20", key_mgmt="WPA-EAP", eap="TTLS",
  2188. identity="hs20-test", password="password",
  2189. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2190. scan_freq="2412")
  2191. time.sleep(0.1)
  2192. addr0 = dev[0].p2p_interface_addr()
  2193. addr1 = dev[1].p2p_interface_addr()
  2194. src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':',''))
  2195. src_ll_opt1 = "\x01\x01" + binascii.unhexlify(addr1.replace(':',''))
  2196. pkt = build_ns(src_ll=addr0, ip_src="aaaa:bbbb:cccc::2",
  2197. ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:cccc::2",
  2198. opt=src_ll_opt0)
  2199. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  2200. raise Exception("DATA_TEST_FRAME failed")
  2201. pkt = build_ns(src_ll=addr1, ip_src="aaaa:bbbb:dddd::2",
  2202. ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:dddd::2",
  2203. opt=src_ll_opt1)
  2204. if "OK" not in dev[1].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  2205. raise Exception("DATA_TEST_FRAME failed")
  2206. pkt = build_ns(src_ll=addr1, ip_src="aaaa:bbbb:eeee::2",
  2207. ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:eeee::2",
  2208. opt=src_ll_opt1)
  2209. if "OK" not in dev[1].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  2210. raise Exception("DATA_TEST_FRAME failed")
  2211. matches = get_permanent_neighbors("ap-br0")
  2212. logger.info("After connect: " + str(matches))
  2213. if len(matches) != 3:
  2214. raise Exception("Unexpected number of neighbor entries after connect")
  2215. if 'aaaa:bbbb:cccc::2 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  2216. raise Exception("dev0 addr missing")
  2217. if 'aaaa:bbbb:dddd::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches:
  2218. raise Exception("dev1 addr(1) missing")
  2219. if 'aaaa:bbbb:eeee::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches:
  2220. raise Exception("dev1 addr(2) missing")
  2221. dev[0].request("DISCONNECT")
  2222. dev[1].request("DISCONNECT")
  2223. time.sleep(0.5)
  2224. matches = get_permanent_neighbors("ap-br0")
  2225. logger.info("After disconnect: " + str(matches))
  2226. if len(matches) > 0:
  2227. raise Exception("Unexpected neighbor entries after disconnect")
  2228. def test_ap_hs20_hidden_ssid_in_scan_res(dev, apdev):
  2229. """Hotspot 2.0 connection with hidden SSId in scan results"""
  2230. bssid = apdev[0]['bssid']
  2231. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'secret',
  2232. "ignore_broadcast_ssid": "1" })
  2233. dev[0].scan_for_bss(bssid, freq=2412)
  2234. hapd.disable()
  2235. hapd_global = hostapd.HostapdGlobal()
  2236. hapd_global.flush()
  2237. hapd_global.remove(apdev[0]['ifname'])
  2238. params = hs20_ap_params()
  2239. params['hessid'] = bssid
  2240. hostapd.add_ap(apdev[0]['ifname'], params)
  2241. dev[0].hs20_enable()
  2242. id = dev[0].add_cred_values({ 'realm': "example.com",
  2243. 'username': "hs20-test",
  2244. 'password': "password",
  2245. 'ca_cert': "auth_serv/ca.pem",
  2246. 'domain': "example.com" })
  2247. interworking_select(dev[0], bssid, "home", freq="2412")
  2248. interworking_connect(dev[0], bssid, "TTLS")
  2249. # clear BSS table to avoid issues in following test cases
  2250. dev[0].request("DISCONNECT")
  2251. dev[0].wait_disconnected()
  2252. dev[0].flush_scan_cache()
  2253. def test_ap_hs20_proxyarp(dev, apdev):
  2254. """Hotspot 2.0 and ProxyARP"""
  2255. try:
  2256. _test_ap_hs20_proxyarp(dev, apdev)
  2257. finally:
  2258. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  2259. stderr=open('/dev/null', 'w'))
  2260. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  2261. stderr=open('/dev/null', 'w'))
  2262. def _test_ap_hs20_proxyarp_dgaf(dev, apdev, disabled):
  2263. bssid = apdev[0]['bssid']
  2264. params = hs20_ap_params()
  2265. params['hessid'] = bssid
  2266. params['disable_dgaf'] = '1' if disabled else '0'
  2267. params['proxy_arp'] = '1'
  2268. params['ap_isolate'] = '1'
  2269. params['bridge'] = 'ap-br0'
  2270. hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True)
  2271. try:
  2272. hapd.enable()
  2273. except:
  2274. # For now, do not report failures due to missing kernel support
  2275. raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version")
  2276. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  2277. if ev is None:
  2278. raise Exception("AP startup timed out")
  2279. dev[0].hs20_enable()
  2280. subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
  2281. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  2282. id = dev[0].add_cred_values({ 'realm': "example.com",
  2283. 'username': "hs20-test",
  2284. 'password': "password",
  2285. 'ca_cert': "auth_serv/ca.pem",
  2286. 'domain': "example.com",
  2287. 'update_identifier': "1234" })
  2288. interworking_select(dev[0], bssid, "home", freq="2412")
  2289. interworking_connect(dev[0], bssid, "TTLS")
  2290. dev[1].connect("test-hs20", key_mgmt="WPA-EAP", eap="TTLS",
  2291. identity="hs20-test", password="password",
  2292. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2293. scan_freq="2412")
  2294. time.sleep(0.1)
  2295. addr0 = dev[0].p2p_interface_addr()
  2296. src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':',''))
  2297. pkt = build_ns(src_ll=addr0, ip_src="aaaa:bbbb:cccc::2",
  2298. ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:cccc::2",
  2299. opt=src_ll_opt0)
  2300. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  2301. raise Exception("DATA_TEST_FRAME failed")
  2302. pkt = build_ra(src_ll=apdev[0]['bssid'], ip_src="aaaa:bbbb:cccc::33",
  2303. ip_dst="ff01::1")
  2304. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2305. raise Exception("DATA_TEST_FRAME failed")
  2306. pkt = build_na(src_ll=apdev[0]['bssid'], ip_src="aaaa:bbbb:cccc::44",
  2307. ip_dst="ff01::1", target="aaaa:bbbb:cccc::55")
  2308. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2309. raise Exception("DATA_TEST_FRAME failed")
  2310. pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid,
  2311. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2312. yiaddr="192.168.1.123", chaddr=addr0)
  2313. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2314. raise Exception("DATA_TEST_FRAME failed")
  2315. # another copy for additional code coverage
  2316. pkt = build_dhcp_ack(dst_ll=addr0, src_ll=bssid,
  2317. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2318. yiaddr="192.168.1.123", chaddr=addr0)
  2319. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2320. raise Exception("DATA_TEST_FRAME failed")
  2321. matches = get_permanent_neighbors("ap-br0")
  2322. logger.info("After connect: " + str(matches))
  2323. if len(matches) != 2:
  2324. raise Exception("Unexpected number of neighbor entries after connect")
  2325. if 'aaaa:bbbb:cccc::2 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  2326. raise Exception("dev0 addr missing")
  2327. if '192.168.1.123 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  2328. raise Exception("dev0 IPv4 addr missing")
  2329. dev[0].request("DISCONNECT")
  2330. dev[1].request("DISCONNECT")
  2331. time.sleep(0.5)
  2332. matches = get_permanent_neighbors("ap-br0")
  2333. logger.info("After disconnect: " + str(matches))
  2334. if len(matches) > 0:
  2335. raise Exception("Unexpected neighbor entries after disconnect")
  2336. def test_ap_hs20_proxyarp_disable_dgaf(dev, apdev):
  2337. """Hotspot 2.0 and ProxyARP with DGAF disabled"""
  2338. try:
  2339. _test_ap_hs20_proxyarp_dgaf(dev, apdev, True)
  2340. finally:
  2341. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  2342. stderr=open('/dev/null', 'w'))
  2343. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  2344. stderr=open('/dev/null', 'w'))
  2345. def test_ap_hs20_proxyarp_enable_dgaf(dev, apdev):
  2346. """Hotspot 2.0 and ProxyARP with DGAF enabled"""
  2347. try:
  2348. _test_ap_hs20_proxyarp_dgaf(dev, apdev, False)
  2349. finally:
  2350. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  2351. stderr=open('/dev/null', 'w'))
  2352. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  2353. stderr=open('/dev/null', 'w'))
  2354. def ip_checksum(buf):
  2355. sum = 0
  2356. if len(buf) & 0x01:
  2357. buf += '\0x00'
  2358. for i in range(0, len(buf), 2):
  2359. val, = struct.unpack('H', buf[i:i+2])
  2360. sum += val
  2361. while (sum >> 16):
  2362. sum = (sum & 0xffff) + (sum >> 16)
  2363. return struct.pack('H', ~sum & 0xffff)
  2364. def ipv6_solicited_node_mcaddr(target):
  2365. prefix = socket.inet_pton(socket.AF_INET6, "ff02::1:ff00:0")
  2366. mask = socket.inet_pton(socket.AF_INET6, "::ff:ffff")
  2367. _target = socket.inet_pton(socket.AF_INET6, target)
  2368. p = struct.unpack('4I', prefix)
  2369. m = struct.unpack('4I', mask)
  2370. t = struct.unpack('4I', _target)
  2371. res = (p[0] | (t[0] & m[0]),
  2372. p[1] | (t[1] & m[1]),
  2373. p[2] | (t[2] & m[2]),
  2374. p[3] | (t[3] & m[3]))
  2375. return socket.inet_ntop(socket.AF_INET6, struct.pack('4I', *res))
  2376. def build_icmpv6(ipv6_addrs, type, code, payload):
  2377. start = struct.pack("BB", type, code)
  2378. end = payload
  2379. icmp = start + '\x00\x00' + end
  2380. pseudo = ipv6_addrs + struct.pack(">LBBBB", len(icmp), 0, 0, 0, 58)
  2381. csum = ip_checksum(pseudo + icmp)
  2382. return start + csum + end
  2383. def build_ra(src_ll, ip_src, ip_dst, cur_hop_limit=0, router_lifetime=0,
  2384. reachable_time=0, retrans_timer=0, opt=None):
  2385. link_mc = binascii.unhexlify("3333ff000002")
  2386. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  2387. proto = '\x86\xdd'
  2388. ehdr = link_mc + _src_ll + proto
  2389. _ip_src = socket.inet_pton(socket.AF_INET6, ip_src)
  2390. _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst)
  2391. adv = struct.pack('>BBHLL', cur_hop_limit, 0, router_lifetime,
  2392. reachable_time, retrans_timer)
  2393. if opt:
  2394. payload = adv + opt
  2395. else:
  2396. payload = adv
  2397. icmp = build_icmpv6(_ip_src + _ip_dst, 134, 0, payload)
  2398. ipv6 = struct.pack('>BBBBHBB', 0x60, 0, 0, 0, len(icmp), 58, 255)
  2399. ipv6 += _ip_src + _ip_dst
  2400. return ehdr + ipv6 + icmp
  2401. def build_ns(src_ll, ip_src, ip_dst, target, opt=None):
  2402. link_mc = binascii.unhexlify("3333ff000002")
  2403. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  2404. proto = '\x86\xdd'
  2405. ehdr = link_mc + _src_ll + proto
  2406. _ip_src = socket.inet_pton(socket.AF_INET6, ip_src)
  2407. if ip_dst is None:
  2408. ip_dst = ipv6_solicited_node_mcaddr(target)
  2409. _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst)
  2410. reserved = '\x00\x00\x00\x00'
  2411. _target = socket.inet_pton(socket.AF_INET6, target)
  2412. if opt:
  2413. payload = reserved + _target + opt
  2414. else:
  2415. payload = reserved + _target
  2416. icmp = build_icmpv6(_ip_src + _ip_dst, 135, 0, payload)
  2417. ipv6 = struct.pack('>BBBBHBB', 0x60, 0, 0, 0, len(icmp), 58, 255)
  2418. ipv6 += _ip_src + _ip_dst
  2419. return ehdr + ipv6 + icmp
  2420. def send_ns(dev, src_ll=None, target=None, ip_src=None, ip_dst=None, opt=None,
  2421. hapd_bssid=None):
  2422. if hapd_bssid:
  2423. if src_ll is None:
  2424. src_ll = hapd_bssid
  2425. cmd = "DATA_TEST_FRAME ifname=ap-br0 "
  2426. else:
  2427. if src_ll is None:
  2428. src_ll = dev.p2p_interface_addr()
  2429. cmd = "DATA_TEST_FRAME "
  2430. if opt is None:
  2431. opt = "\x01\x01" + binascii.unhexlify(src_ll.replace(':',''))
  2432. pkt = build_ns(src_ll=src_ll, ip_src=ip_src, ip_dst=ip_dst, target=target,
  2433. opt=opt)
  2434. if "OK" not in dev.request(cmd + binascii.hexlify(pkt)):
  2435. raise Exception("DATA_TEST_FRAME failed")
  2436. def build_na(src_ll, ip_src, ip_dst, target, opt=None):
  2437. link_mc = binascii.unhexlify("3333ff000002")
  2438. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  2439. proto = '\x86\xdd'
  2440. ehdr = link_mc + _src_ll + proto
  2441. _ip_src = socket.inet_pton(socket.AF_INET6, ip_src)
  2442. _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst)
  2443. reserved = '\x00\x00\x00\x00'
  2444. _target = socket.inet_pton(socket.AF_INET6, target)
  2445. if opt:
  2446. payload = reserved + _target + opt
  2447. else:
  2448. payload = reserved + _target
  2449. icmp = build_icmpv6(_ip_src + _ip_dst, 136, 0, payload)
  2450. ipv6 = struct.pack('>BBBBHBB', 0x60, 0, 0, 0, len(icmp), 58, 255)
  2451. ipv6 += _ip_src + _ip_dst
  2452. return ehdr + ipv6 + icmp
  2453. def send_na(dev, src_ll=None, target=None, ip_src=None, ip_dst=None, opt=None,
  2454. hapd_bssid=None):
  2455. if hapd_bssid:
  2456. if src_ll is None:
  2457. src_ll = hapd_bssid
  2458. cmd = "DATA_TEST_FRAME ifname=ap-br0 "
  2459. else:
  2460. if src_ll is None:
  2461. src_ll = dev.p2p_interface_addr()
  2462. cmd = "DATA_TEST_FRAME "
  2463. pkt = build_na(src_ll=src_ll, ip_src=ip_src, ip_dst=ip_dst, target=target,
  2464. opt=opt)
  2465. if "OK" not in dev.request(cmd + binascii.hexlify(pkt)):
  2466. raise Exception("DATA_TEST_FRAME failed")
  2467. def build_dhcp_ack(dst_ll, src_ll, ip_src, ip_dst, yiaddr, chaddr,
  2468. subnet_mask="255.255.255.0", truncated_opt=False,
  2469. wrong_magic=False, force_tot_len=None, no_dhcp=False):
  2470. _dst_ll = binascii.unhexlify(dst_ll.replace(':',''))
  2471. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  2472. proto = '\x08\x00'
  2473. ehdr = _dst_ll + _src_ll + proto
  2474. _ip_src = socket.inet_pton(socket.AF_INET, ip_src)
  2475. _ip_dst = socket.inet_pton(socket.AF_INET, ip_dst)
  2476. _subnet_mask = socket.inet_pton(socket.AF_INET, subnet_mask)
  2477. _ciaddr = '\x00\x00\x00\x00'
  2478. _yiaddr = socket.inet_pton(socket.AF_INET, yiaddr)
  2479. _siaddr = '\x00\x00\x00\x00'
  2480. _giaddr = '\x00\x00\x00\x00'
  2481. _chaddr = binascii.unhexlify(chaddr.replace(':','') + "00000000000000000000")
  2482. payload = struct.pack('>BBBBL3BB', 2, 1, 6, 0, 12345, 0, 0, 0, 0)
  2483. payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192*'\x00'
  2484. # magic
  2485. if wrong_magic:
  2486. payload += '\x63\x82\x53\x00'
  2487. else:
  2488. payload += '\x63\x82\x53\x63'
  2489. if truncated_opt:
  2490. payload += '\x22\xff\x00'
  2491. # Option: DHCP Message Type = ACK
  2492. payload += '\x35\x01\x05'
  2493. # Pad Option
  2494. payload += '\x00'
  2495. # Option: Subnet Mask
  2496. payload += '\x01\x04' + _subnet_mask
  2497. # Option: Time Offset
  2498. payload += struct.pack('>BBL', 2, 4, 0)
  2499. # End Option
  2500. payload += '\xff'
  2501. # Pad Option
  2502. payload += '\x00\x00\x00\x00'
  2503. if no_dhcp:
  2504. payload = struct.pack('>BBBBL3BB', 2, 1, 6, 0, 12345, 0, 0, 0, 0)
  2505. payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192*'\x00'
  2506. udp = struct.pack('>HHHH', 67, 68, 8 + len(payload), 0) + payload
  2507. if force_tot_len:
  2508. tot_len = force_tot_len
  2509. else:
  2510. tot_len = 20 + len(udp)
  2511. start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17)
  2512. ipv4 = start + '\x00\x00' + _ip_src + _ip_dst
  2513. csum = ip_checksum(ipv4)
  2514. ipv4 = start + csum + _ip_src + _ip_dst
  2515. return ehdr + ipv4 + udp
  2516. def build_arp(dst_ll, src_ll, opcode, sender_mac, sender_ip,
  2517. target_mac, target_ip):
  2518. _dst_ll = binascii.unhexlify(dst_ll.replace(':',''))
  2519. _src_ll = binascii.unhexlify(src_ll.replace(':',''))
  2520. proto = '\x08\x06'
  2521. ehdr = _dst_ll + _src_ll + proto
  2522. _sender_mac = binascii.unhexlify(sender_mac.replace(':',''))
  2523. _sender_ip = socket.inet_pton(socket.AF_INET, sender_ip)
  2524. _target_mac = binascii.unhexlify(target_mac.replace(':',''))
  2525. _target_ip = socket.inet_pton(socket.AF_INET, target_ip)
  2526. arp = struct.pack('>HHBBH', 1, 0x0800, 6, 4, opcode)
  2527. arp += _sender_mac + _sender_ip
  2528. arp += _target_mac + _target_ip
  2529. return ehdr + arp
  2530. def send_arp(dev, dst_ll="ff:ff:ff:ff:ff:ff", src_ll=None, opcode=1,
  2531. sender_mac=None, sender_ip="0.0.0.0",
  2532. target_mac="00:00:00:00:00:00", target_ip="0.0.0.0",
  2533. hapd_bssid=None):
  2534. if hapd_bssid:
  2535. if src_ll is None:
  2536. src_ll = hapd_bssid
  2537. if sender_mac is None:
  2538. sender_mac = hapd_bssid
  2539. cmd = "DATA_TEST_FRAME ifname=ap-br0 "
  2540. else:
  2541. if src_ll is None:
  2542. src_ll = dev.p2p_interface_addr()
  2543. if sender_mac is None:
  2544. sender_mac = dev.p2p_interface_addr()
  2545. cmd = "DATA_TEST_FRAME "
  2546. pkt = build_arp(dst_ll=dst_ll, src_ll=src_ll, opcode=opcode,
  2547. sender_mac=sender_mac, sender_ip=sender_ip,
  2548. target_mac=target_mac, target_ip=target_ip)
  2549. if "OK" not in dev.request(cmd + binascii.hexlify(pkt)):
  2550. raise Exception("DATA_TEST_FRAME failed")
  2551. def get_permanent_neighbors(ifname):
  2552. cmd = subprocess.Popen(['ip', 'nei'], stdout=subprocess.PIPE)
  2553. res = cmd.stdout.read()
  2554. cmd.stdout.close()
  2555. return [ line for line in res.splitlines() if "PERMANENT" in line and ifname in line ]
  2556. def get_bridge_macs(ifname):
  2557. cmd = subprocess.Popen(['brctl', 'showmacs', ifname],
  2558. stdout=subprocess.PIPE)
  2559. res = cmd.stdout.read()
  2560. cmd.stdout.close()
  2561. return res
  2562. def tshark_get_arp(cap, filter):
  2563. res = run_tshark(cap, filter,
  2564. [ "eth.dst", "eth.src",
  2565. "arp.src.hw_mac", "arp.src.proto_ipv4",
  2566. "arp.dst.hw_mac", "arp.dst.proto_ipv4" ],
  2567. wait=False)
  2568. frames = []
  2569. for l in res.splitlines():
  2570. frames.append(l.split('\t'))
  2571. return frames
  2572. def tshark_get_ns(cap):
  2573. res = run_tshark(cap, "icmpv6.type == 135",
  2574. [ "eth.dst", "eth.src",
  2575. "ipv6.src", "ipv6.dst",
  2576. "icmpv6.nd.ns.target_address",
  2577. "icmpv6.opt.linkaddr" ],
  2578. wait=False)
  2579. frames = []
  2580. for l in res.splitlines():
  2581. frames.append(l.split('\t'))
  2582. return frames
  2583. def tshark_get_na(cap):
  2584. res = run_tshark(cap, "icmpv6.type == 136",
  2585. [ "eth.dst", "eth.src",
  2586. "ipv6.src", "ipv6.dst",
  2587. "icmpv6.nd.na.target_address",
  2588. "icmpv6.opt.linkaddr" ],
  2589. wait=False)
  2590. frames = []
  2591. for l in res.splitlines():
  2592. frames.append(l.split('\t'))
  2593. return frames
  2594. def _test_proxyarp_open(dev, apdev, params, ebtables=False):
  2595. prefix = "proxyarp_open"
  2596. if ebtables:
  2597. prefix += "_ebtables"
  2598. cap_br = os.path.join(params['logdir'], prefix + ".ap-br0.pcap")
  2599. cap_dev0 = os.path.join(params['logdir'],
  2600. prefix + ".%s.pcap" % dev[0].ifname)
  2601. cap_dev1 = os.path.join(params['logdir'],
  2602. prefix + ".%s.pcap" % dev[1].ifname)
  2603. cap_dev2 = os.path.join(params['logdir'],
  2604. prefix + ".%s.pcap" % dev[2].ifname)
  2605. bssid = apdev[0]['bssid']
  2606. params = { 'ssid': 'open' }
  2607. params['proxy_arp'] = '1'
  2608. hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True)
  2609. hapd.set("ap_isolate", "1")
  2610. hapd.set('bridge', 'ap-br0')
  2611. hapd.dump_monitor()
  2612. try:
  2613. hapd.enable()
  2614. except:
  2615. # For now, do not report failures due to missing kernel support
  2616. raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version")
  2617. ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=10)
  2618. if ev is None:
  2619. raise Exception("AP startup timed out")
  2620. if "AP-ENABLED" not in ev:
  2621. raise Exception("AP startup failed")
  2622. params2 = { 'ssid': 'another' }
  2623. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params2, no_enable=True)
  2624. hapd2.set('bridge', 'ap-br0')
  2625. hapd2.enable()
  2626. subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
  2627. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  2628. if ebtables:
  2629. for chain in [ 'FORWARD', 'OUTPUT' ]:
  2630. subprocess.call(['ebtables', '-A', chain, '-p', 'ARP',
  2631. '-d', 'Broadcast', '-o', apdev[0]['ifname'],
  2632. '-j', 'DROP'])
  2633. subprocess.call(['ebtables', '-A', chain, '-d', 'Multicast',
  2634. '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp',
  2635. '--ip6-icmp-type', 'neighbor-solicitation',
  2636. '-o', apdev[0]['ifname'], '-j', 'DROP'])
  2637. subprocess.call(['ebtables', '-A', chain, '-d', 'Multicast',
  2638. '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp',
  2639. '--ip6-icmp-type', 'neighbor-advertisement',
  2640. '-o', apdev[0]['ifname'], '-j', 'DROP'])
  2641. subprocess.call(['ebtables', '-A', chain,
  2642. '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp',
  2643. '--ip6-icmp-type', 'router-solicitation',
  2644. '-o', apdev[0]['ifname'], '-j', 'DROP'])
  2645. # Multicast Listener Report Message
  2646. subprocess.call(['ebtables', '-A', chain, '-d', 'Multicast',
  2647. '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp',
  2648. '--ip6-icmp-type', '143',
  2649. '-o', apdev[0]['ifname'], '-j', 'DROP'])
  2650. time.sleep(0.5)
  2651. cmd = {}
  2652. cmd[0] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', 'ap-br0',
  2653. '-w', cap_br, '-s', '2000'],
  2654. stderr=open('/dev/null', 'w'))
  2655. cmd[1] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[0].ifname,
  2656. '-w', cap_dev0, '-s', '2000'],
  2657. stderr=open('/dev/null', 'w'))
  2658. cmd[2] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[1].ifname,
  2659. '-w', cap_dev1, '-s', '2000'],
  2660. stderr=open('/dev/null', 'w'))
  2661. cmd[3] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[2].ifname,
  2662. '-w', cap_dev2, '-s', '2000'],
  2663. stderr=open('/dev/null', 'w'))
  2664. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  2665. dev[1].connect("open", key_mgmt="NONE", scan_freq="2412")
  2666. dev[2].connect("another", key_mgmt="NONE", scan_freq="2412")
  2667. time.sleep(0.1)
  2668. brcmd = subprocess.Popen(['brctl', 'show'], stdout=subprocess.PIPE)
  2669. res = brcmd.stdout.read()
  2670. brcmd.stdout.close()
  2671. logger.info("Bridge setup: " + res)
  2672. brcmd = subprocess.Popen(['brctl', 'showstp', 'ap-br0'],
  2673. stdout=subprocess.PIPE)
  2674. res = brcmd.stdout.read()
  2675. brcmd.stdout.close()
  2676. logger.info("Bridge showstp: " + res)
  2677. addr0 = dev[0].p2p_interface_addr()
  2678. addr1 = dev[1].p2p_interface_addr()
  2679. addr2 = dev[2].p2p_interface_addr()
  2680. src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':',''))
  2681. src_ll_opt1 = "\x01\x01" + binascii.unhexlify(addr1.replace(':',''))
  2682. # DAD NS
  2683. send_ns(dev[0], ip_src="::", target="aaaa:bbbb:cccc::2")
  2684. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2")
  2685. # test frame without source link-layer address option
  2686. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2",
  2687. opt='')
  2688. # test frame with bogus option
  2689. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2",
  2690. opt="\x70\x01\x01\x02\x03\x04\x05\x05")
  2691. # test frame with truncated source link-layer address option
  2692. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2",
  2693. opt="\x01\x01\x01\x02\x03\x04")
  2694. # test frame with foreign source link-layer address option
  2695. send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2",
  2696. opt="\x01\x01\x01\x02\x03\x04\x05\x06")
  2697. send_ns(dev[1], ip_src="aaaa:bbbb:dddd::2", target="aaaa:bbbb:dddd::2")
  2698. send_ns(dev[1], ip_src="aaaa:bbbb:eeee::2", target="aaaa:bbbb:eeee::2")
  2699. # another copy for additional code coverage
  2700. send_ns(dev[1], ip_src="aaaa:bbbb:eeee::2", target="aaaa:bbbb:eeee::2")
  2701. pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid,
  2702. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2703. yiaddr="192.168.1.124", chaddr=addr0)
  2704. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2705. raise Exception("DATA_TEST_FRAME failed")
  2706. # Change address and verify unicast
  2707. pkt = build_dhcp_ack(dst_ll=addr0, src_ll=bssid,
  2708. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2709. yiaddr="192.168.1.123", chaddr=addr0)
  2710. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2711. raise Exception("DATA_TEST_FRAME failed")
  2712. # Not-associated client MAC address
  2713. pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid,
  2714. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2715. yiaddr="192.168.1.125", chaddr="22:33:44:55:66:77")
  2716. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2717. raise Exception("DATA_TEST_FRAME failed")
  2718. # No IP address
  2719. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  2720. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2721. yiaddr="0.0.0.0", chaddr=addr1)
  2722. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2723. raise Exception("DATA_TEST_FRAME failed")
  2724. # Zero subnet mask
  2725. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  2726. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2727. yiaddr="192.168.1.126", chaddr=addr1,
  2728. subnet_mask="0.0.0.0")
  2729. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2730. raise Exception("DATA_TEST_FRAME failed")
  2731. # Truncated option
  2732. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  2733. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2734. yiaddr="192.168.1.127", chaddr=addr1,
  2735. truncated_opt=True)
  2736. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2737. raise Exception("DATA_TEST_FRAME failed")
  2738. # Wrong magic
  2739. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  2740. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2741. yiaddr="192.168.1.128", chaddr=addr1,
  2742. wrong_magic=True)
  2743. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2744. raise Exception("DATA_TEST_FRAME failed")
  2745. # Wrong IPv4 total length
  2746. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  2747. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2748. yiaddr="192.168.1.129", chaddr=addr1,
  2749. force_tot_len=1000)
  2750. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2751. raise Exception("DATA_TEST_FRAME failed")
  2752. # BOOTP
  2753. pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid,
  2754. ip_src="192.168.1.1", ip_dst="255.255.255.255",
  2755. yiaddr="192.168.1.129", chaddr=addr1,
  2756. no_dhcp=True)
  2757. if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)):
  2758. raise Exception("DATA_TEST_FRAME failed")
  2759. macs = get_bridge_macs("ap-br0")
  2760. logger.info("After connect (showmacs): " + str(macs))
  2761. matches = get_permanent_neighbors("ap-br0")
  2762. logger.info("After connect: " + str(matches))
  2763. if len(matches) != 4:
  2764. raise Exception("Unexpected number of neighbor entries after connect")
  2765. if 'aaaa:bbbb:cccc::2 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  2766. raise Exception("dev0 addr missing")
  2767. if 'aaaa:bbbb:dddd::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches:
  2768. raise Exception("dev1 addr(1) missing")
  2769. if 'aaaa:bbbb:eeee::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches:
  2770. raise Exception("dev1 addr(2) missing")
  2771. if '192.168.1.123 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches:
  2772. raise Exception("dev0 IPv4 addr missing")
  2773. targets = [ "192.168.1.123", "192.168.1.124", "192.168.1.125",
  2774. "192.168.1.126" ]
  2775. for target in targets:
  2776. send_arp(dev[1], sender_ip="192.168.1.100", target_ip=target)
  2777. for target in targets:
  2778. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.101",
  2779. target_ip=target)
  2780. for target in targets:
  2781. send_arp(dev[2], sender_ip="192.168.1.103", target_ip=target)
  2782. # ARP Probe from wireless STA
  2783. send_arp(dev[1], target_ip="192.168.1.127")
  2784. # ARP Announcement from wireless STA
  2785. send_arp(dev[1], sender_ip="192.168.1.127", target_ip="192.168.1.127")
  2786. send_arp(dev[1], sender_ip="192.168.1.127", target_ip="192.168.1.127",
  2787. opcode=2)
  2788. macs = get_bridge_macs("ap-br0")
  2789. logger.info("After ARP Probe + Announcement (showmacs): " + str(macs))
  2790. matches = get_permanent_neighbors("ap-br0")
  2791. logger.info("After ARP Probe + Announcement: " + str(matches))
  2792. # ARP Request for the newly introduced IP address from wireless STA
  2793. send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.127")
  2794. # ARP Request for the newly introduced IP address from bridge
  2795. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.102",
  2796. target_ip="192.168.1.127")
  2797. send_arp(dev[2], sender_ip="192.168.1.103", target_ip="192.168.1.127")
  2798. # ARP Probe from bridge
  2799. send_arp(hapd, hapd_bssid=bssid, target_ip="192.168.1.130")
  2800. send_arp(dev[2], target_ip="192.168.1.131")
  2801. # ARP Announcement from bridge (not to be learned by AP for proxyarp)
  2802. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.130",
  2803. target_ip="192.168.1.130")
  2804. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.130",
  2805. target_ip="192.168.1.130", opcode=2)
  2806. send_arp(dev[2], sender_ip="192.168.1.131", target_ip="192.168.1.131")
  2807. send_arp(dev[2], sender_ip="192.168.1.131", target_ip="192.168.1.131",
  2808. opcode=2)
  2809. macs = get_bridge_macs("ap-br0")
  2810. logger.info("After ARP Probe + Announcement (showmacs): " + str(macs))
  2811. matches = get_permanent_neighbors("ap-br0")
  2812. logger.info("After ARP Probe + Announcement: " + str(matches))
  2813. # ARP Request for the newly introduced IP address from wireless STA
  2814. send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.130")
  2815. # ARP Response from bridge (AP does not proxy for non-wireless devices)
  2816. send_arp(hapd, hapd_bssid=bssid, dst_ll=addr0, sender_ip="192.168.1.130",
  2817. target_ip="192.168.1.123", opcode=2)
  2818. # ARP Request for the newly introduced IP address from wireless STA
  2819. send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.131")
  2820. # ARP Response from bridge (AP does not proxy for non-wireless devices)
  2821. send_arp(dev[2], dst_ll=addr0, sender_ip="192.168.1.131",
  2822. target_ip="192.168.1.123", opcode=2)
  2823. # ARP Request for the newly introduced IP address from bridge
  2824. send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.102",
  2825. target_ip="192.168.1.130")
  2826. send_arp(dev[2], sender_ip="192.168.1.104", target_ip="192.168.1.131")
  2827. # ARP Probe from wireless STA (duplicate address; learned through DHCP)
  2828. send_arp(dev[1], target_ip="192.168.1.123")
  2829. # ARP Probe from wireless STA (duplicate address; learned through ARP)
  2830. send_arp(dev[0], target_ip="192.168.1.127")
  2831. # Gratuitous ARP Reply for another STA's IP address
  2832. send_arp(dev[0], opcode=2, sender_mac=addr0, sender_ip="192.168.1.127",
  2833. target_mac=addr1, target_ip="192.168.1.127")
  2834. send_arp(dev[1], opcode=2, sender_mac=addr1, sender_ip="192.168.1.123",
  2835. target_mac=addr0, target_ip="192.168.1.123")
  2836. # ARP Request to verify previous mapping
  2837. send_arp(dev[1], sender_ip="192.168.1.127", target_ip="192.168.1.123")
  2838. send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.127")
  2839. time.sleep(0.1)
  2840. send_ns(dev[0], target="aaaa:bbbb:dddd::2", ip_src="aaaa:bbbb:cccc::2")
  2841. time.sleep(0.1)
  2842. send_ns(dev[1], target="aaaa:bbbb:cccc::2", ip_src="aaaa:bbbb:dddd::2")
  2843. time.sleep(0.1)
  2844. send_ns(hapd, hapd_bssid=bssid, target="aaaa:bbbb:dddd::2",
  2845. ip_src="aaaa:bbbb:ffff::2")
  2846. time.sleep(0.1)
  2847. send_ns(dev[2], target="aaaa:bbbb:cccc::2", ip_src="aaaa:bbbb:ff00::2")
  2848. time.sleep(0.1)
  2849. send_ns(dev[2], target="aaaa:bbbb:dddd::2", ip_src="aaaa:bbbb:ff00::2")
  2850. time.sleep(0.1)
  2851. send_ns(dev[2], target="aaaa:bbbb:eeee::2", ip_src="aaaa:bbbb:ff00::2")
  2852. time.sleep(0.1)
  2853. # Try to probe for an already assigned address
  2854. send_ns(dev[1], target="aaaa:bbbb:cccc::2", ip_src="::")
  2855. time.sleep(0.1)
  2856. send_ns(hapd, hapd_bssid=bssid, target="aaaa:bbbb:cccc::2", ip_src="::")
  2857. time.sleep(0.1)
  2858. send_ns(dev[2], target="aaaa:bbbb:cccc::2", ip_src="::")
  2859. time.sleep(0.1)
  2860. # Unsolicited NA
  2861. send_na(dev[1], target="aaaa:bbbb:cccc:aeae::3",
  2862. ip_src="aaaa:bbbb:cccc:aeae::3", ip_dst="ff02::1")
  2863. send_na(hapd, hapd_bssid=bssid, target="aaaa:bbbb:cccc:aeae::4",
  2864. ip_src="aaaa:bbbb:cccc:aeae::4", ip_dst="ff02::1")
  2865. send_na(dev[2], target="aaaa:bbbb:cccc:aeae::5",
  2866. ip_src="aaaa:bbbb:cccc:aeae::5", ip_dst="ff02::1")
  2867. try:
  2868. hwsim_utils.test_connectivity_iface(dev[0], hapd, "ap-br0")
  2869. except Exception, e:
  2870. logger.info("test_connectibity_iface failed: " + str(e))
  2871. raise HwsimSkip("Assume kernel did not have the required patches for proxyarp")
  2872. hwsim_utils.test_connectivity_iface(dev[1], hapd, "ap-br0")
  2873. hwsim_utils.test_connectivity(dev[0], dev[1])
  2874. dev[0].request("DISCONNECT")
  2875. dev[1].request("DISCONNECT")
  2876. time.sleep(0.5)
  2877. for i in range(len(cmd)):
  2878. cmd[i].terminate()
  2879. macs = get_bridge_macs("ap-br0")
  2880. logger.info("After disconnect (showmacs): " + str(macs))
  2881. matches = get_permanent_neighbors("ap-br0")
  2882. logger.info("After disconnect: " + str(matches))
  2883. if len(matches) > 0:
  2884. raise Exception("Unexpected neighbor entries after disconnect")
  2885. if ebtables:
  2886. cmd = subprocess.Popen(['ebtables', '-L', '--Lc'],
  2887. stdout=subprocess.PIPE)
  2888. res = cmd.stdout.read()
  2889. cmd.stdout.close()
  2890. logger.info("ebtables results:\n" + res)
  2891. # Verify that expected ARP messages were seen and no unexpected
  2892. # ARP messages were seen.
  2893. arp_req = tshark_get_arp(cap_dev0, "arp.opcode == 1")
  2894. arp_reply = tshark_get_arp(cap_dev0, "arp.opcode == 2")
  2895. logger.info("dev0 seen ARP requests:\n" + str(arp_req))
  2896. logger.info("dev0 seen ARP replies:\n" + str(arp_reply))
  2897. if [ 'ff:ff:ff:ff:ff:ff', addr1,
  2898. addr1, '192.168.1.100',
  2899. '00:00:00:00:00:00', '192.168.1.123' ] in arp_req:
  2900. raise Exception("dev0 saw ARP request from dev1")
  2901. if [ 'ff:ff:ff:ff:ff:ff', addr2,
  2902. addr2, '192.168.1.103',
  2903. '00:00:00:00:00:00', '192.168.1.123' ] in arp_req:
  2904. raise Exception("dev0 saw ARP request from dev2")
  2905. # TODO: Uncomment once fixed in kernel
  2906. #if [ 'ff:ff:ff:ff:ff:ff', bssid,
  2907. # bssid, '192.168.1.101',
  2908. # '00:00:00:00:00:00', '192.168.1.123' ] in arp_req:
  2909. # raise Exception("dev0 saw ARP request from br")
  2910. if ebtables:
  2911. for req in arp_req:
  2912. if req[1] != addr0:
  2913. raise Exception("Unexpected foreign ARP request on dev0")
  2914. arp_req = tshark_get_arp(cap_dev1, "arp.opcode == 1")
  2915. arp_reply = tshark_get_arp(cap_dev1, "arp.opcode == 2")
  2916. logger.info("dev1 seen ARP requests:\n" + str(arp_req))
  2917. logger.info("dev1 seen ARP replies:\n" + str(arp_reply))
  2918. if [ 'ff:ff:ff:ff:ff:ff', addr2,
  2919. addr2, '192.168.1.103',
  2920. '00:00:00:00:00:00', '192.168.1.123' ] in arp_req:
  2921. raise Exception("dev1 saw ARP request from dev2")
  2922. if [addr1, addr0, addr0, '192.168.1.123', addr1, '192.168.1.100'] not in arp_reply:
  2923. raise Exception("dev1 did not get ARP response for 192.168.1.123")
  2924. if ebtables:
  2925. for req in arp_req:
  2926. if req[1] != addr1:
  2927. raise Exception("Unexpected foreign ARP request on dev1")
  2928. arp_req = tshark_get_arp(cap_dev2, "arp.opcode == 1")
  2929. arp_reply = tshark_get_arp(cap_dev2, "arp.opcode == 2")
  2930. logger.info("dev2 seen ARP requests:\n" + str(arp_req))
  2931. logger.info("dev2 seen ARP replies:\n" + str(arp_reply))
  2932. if [ addr2, addr0,
  2933. addr0, '192.168.1.123',
  2934. addr2, '192.168.1.103' ] not in arp_reply:
  2935. raise Exception("dev2 did not get ARP response for 192.168.1.123")
  2936. arp_req = tshark_get_arp(cap_br, "arp.opcode == 1")
  2937. arp_reply = tshark_get_arp(cap_br, "arp.opcode == 2")
  2938. logger.info("br seen ARP requests:\n" + str(arp_req))
  2939. logger.info("br seen ARP replies:\n" + str(arp_reply))
  2940. # TODO: Uncomment once fixed in kernel
  2941. #if [ bssid, addr0,
  2942. # addr0, '192.168.1.123',
  2943. # bssid, '192.168.1.101' ] not in arp_reply:
  2944. # raise Exception("br did not get ARP response for 192.168.1.123")
  2945. ns = tshark_get_ns(cap_dev0)
  2946. logger.info("dev0 seen NS: " + str(ns))
  2947. na = tshark_get_na(cap_dev0)
  2948. logger.info("dev0 seen NA: " + str(na))
  2949. # FIX: src mac addr is supposed to be addr1, not bssid
  2950. if [ addr0, bssid, 'aaaa:bbbb:dddd::2', 'aaaa:bbbb:cccc::2',
  2951. 'aaaa:bbbb:dddd::2', addr1 ] not in na:
  2952. raise Exception("dev0 did not get NA for aaaa:bbbb:dddd::2")
  2953. if ebtables:
  2954. for req in ns:
  2955. if req[1] != addr0:
  2956. raise Exception("Unexpected foreign NS on dev0: " + str(req))
  2957. ns = tshark_get_ns(cap_dev1)
  2958. logger.info("dev1 seen NS: " + str(ns))
  2959. na = tshark_get_na(cap_dev1)
  2960. logger.info("dev1 seen NA: " + str(na))
  2961. # FIX: src mac addr is supposed to be addr0, not bssid
  2962. if [ addr1, bssid, 'aaaa:bbbb:cccc::2', 'aaaa:bbbb:dddd::2',
  2963. 'aaaa:bbbb:cccc::2', addr0 ] not in na:
  2964. raise Exception("dev1 did not get NA for aaaa:bbbb:cccc::2")
  2965. if ebtables:
  2966. for req in ns:
  2967. if req[1] != addr1:
  2968. raise Exception("Unexpected foreign NS on dev1: " + str(req))
  2969. ns = tshark_get_ns(cap_dev2)
  2970. logger.info("dev2 seen NS: " + str(ns))
  2971. na = tshark_get_na(cap_dev2)
  2972. logger.info("dev2 seen NA: " + str(na))
  2973. # FIX: enable once kernel implementation for proxyarp IPv6 is fixed
  2974. # FIX: src mac addr is supposed to be addr0/addr1, not bssid
  2975. #if [ addr2, bssid, 'aaaa:bbbb:cccc::2', 'aaaa:bbbb:ff00::2',
  2976. # 'aaaa:bbbb:cccc::2', addr0 ] not in na:
  2977. # raise Exception("dev2 did not get NA for aaaa:bbbb:cccc::2")
  2978. #if [ addr2, bssid, 'aaaa:bbbb:dddd::2', 'aaaa:bbbb:ff00::2',
  2979. # 'aaaa:bbbb:dddd::2', addr1 ] not in na:
  2980. # raise Exception("dev2 did not get NA for aaaa:bbbb:dddd::2")
  2981. #if [ addr2, bssid, 'aaaa:bbbb:eeee::2', 'aaaa:bbbb:ff00::2',
  2982. # 'aaaa:bbbb:eeee::2', addr1 ] not in na:
  2983. # raise Exception("dev2 did not get NA for aaaa:bbbb:eeee::2")
  2984. def test_proxyarp_open(dev, apdev, params):
  2985. """ProxyARP with open network"""
  2986. try:
  2987. _test_proxyarp_open(dev, apdev, params)
  2988. finally:
  2989. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  2990. stderr=open('/dev/null', 'w'))
  2991. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  2992. stderr=open('/dev/null', 'w'))
  2993. def test_proxyarp_open_ebtables(dev, apdev, params):
  2994. """ProxyARP with open network"""
  2995. try:
  2996. _test_proxyarp_open(dev, apdev, params, ebtables=True)
  2997. finally:
  2998. try:
  2999. subprocess.call(['ebtables', '-F', 'FORWARD'])
  3000. subprocess.call(['ebtables', '-F', 'OUTPUT'])
  3001. except:
  3002. pass
  3003. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
  3004. stderr=open('/dev/null', 'w'))
  3005. subprocess.call(['brctl', 'delbr', 'ap-br0'],
  3006. stderr=open('/dev/null', 'w'))