test_wpas_ctrl.py 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104
  1. # wpa_supplicant control interface
  2. # Copyright (c) 2014, Qualcomm Atheros, Inc.
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. from remotehost import remote_compatible
  7. import logging
  8. logger = logging.getLogger()
  9. import os
  10. import socket
  11. import subprocess
  12. import time
  13. import hostapd
  14. import hwsim_utils
  15. from hwsim import HWSimRadio
  16. from wpasupplicant import WpaSupplicant
  17. from utils import alloc_fail, fail_test
  18. from test_wpas_ap import wait_ap_ready
  19. @remote_compatible
  20. def test_wpas_ctrl_network(dev):
  21. """wpa_supplicant ctrl_iface network set/get"""
  22. id = dev[0].add_network()
  23. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id)):
  24. raise Exception("Unexpected success for invalid SET_NETWORK")
  25. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " name"):
  26. raise Exception("Unexpected success for invalid SET_NETWORK")
  27. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id + 1) + " proto OPEN"):
  28. raise Exception("Unexpected success for invalid network id")
  29. if "FAIL" not in dev[0].request("GET_NETWORK " + str(id)):
  30. raise Exception("Unexpected success for invalid GET_NETWORK")
  31. if "FAIL" not in dev[0].request("GET_NETWORK " + str(id + 1) + " proto"):
  32. raise Exception("Unexpected success for invalid network id")
  33. if "OK" not in dev[0].request("SET_NETWORK " + str(id) + " proto \t WPA2 "):
  34. raise Exception("Unexpected failure for SET_NETWORK proto")
  35. res = dev[0].request("GET_NETWORK " + str(id) + " proto")
  36. if res != "RSN":
  37. raise Exception("Unexpected SET_NETWORK/GET_NETWORK conversion for proto: " + res)
  38. if "OK" not in dev[0].request("SET_NETWORK " + str(id) + " key_mgmt \t WPA-PSK "):
  39. raise Exception("Unexpected success for SET_NETWORK key_mgmt")
  40. res = dev[0].request("GET_NETWORK " + str(id) + " key_mgmt")
  41. if res != "WPA-PSK":
  42. raise Exception("Unexpected SET_NETWORK/GET_NETWORK conversion for key_mgmt: " + res)
  43. if "OK" not in dev[0].request("SET_NETWORK " + str(id) + " auth_alg \t OPEN "):
  44. raise Exception("Unexpected failure for SET_NETWORK auth_alg")
  45. res = dev[0].request("GET_NETWORK " + str(id) + " auth_alg")
  46. if res != "OPEN":
  47. raise Exception("Unexpected SET_NETWORK/GET_NETWORK conversion for auth_alg: " + res)
  48. if "OK" not in dev[0].request("SET_NETWORK " + str(id) + " eap \t TLS "):
  49. raise Exception("Unexpected failure for SET_NETWORK eap")
  50. res = dev[0].request("GET_NETWORK " + str(id) + " eap")
  51. if res != "TLS":
  52. raise Exception("Unexpected SET_NETWORK/GET_NETWORK conversion for eap: " + res)
  53. tests = ("bssid foo", "key_mgmt foo", "key_mgmt ", "group NONE")
  54. for t in tests:
  55. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " " + t):
  56. raise Exception("Unexpected success for invalid SET_NETWORK: " + t)
  57. tests = [("key_mgmt", "WPA-PSK WPA-EAP IEEE8021X NONE WPA-NONE FT-PSK FT-EAP WPA-PSK-SHA256 WPA-EAP-SHA256"),
  58. ("pairwise", "CCMP-256 GCMP-256 CCMP GCMP TKIP"),
  59. ("group", "CCMP-256 GCMP-256 CCMP GCMP TKIP"),
  60. ("auth_alg", "OPEN SHARED LEAP"),
  61. ("scan_freq", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"),
  62. ("freq_list", "2412 2417"),
  63. ("scan_ssid", "1"),
  64. ("bssid", "00:11:22:33:44:55"),
  65. ("proto", "WPA RSN OSEN"),
  66. ("eap", "TLS"),
  67. ("go_p2p_dev_addr", "22:33:44:55:66:aa"),
  68. ("p2p_client_list", "22:33:44:55:66:bb 02:11:22:33:44:55")]
  69. if "SAE" not in dev[0].get_capability("auth_alg"):
  70. tests.append(("key_mgmt", "WPS OSEN"))
  71. else:
  72. tests.append(("key_mgmt", "WPS SAE FT-SAE OSEN"))
  73. dev[0].set_network_quoted(id, "ssid", "test")
  74. for field, value in tests:
  75. dev[0].set_network(id, field, value)
  76. res = dev[0].get_network(id, field)
  77. if res != value:
  78. raise Exception("Unexpected response for '" + field + "': '" + res + "'")
  79. try:
  80. value = "WPA-EAP-SUITE-B WPA-EAP-SUITE-B-192"
  81. dev[0].set_network(id, "key_mgmt", value)
  82. res = dev[0].get_network(id, "key_mgmt")
  83. if res != value:
  84. raise Exception("Unexpected response for key_mgmt")
  85. except Exception, e:
  86. if str(e).startswith("Unexpected"):
  87. raise
  88. else:
  89. pass
  90. q_tests = (("identity", "hello"),
  91. ("anonymous_identity", "foo@nowhere.com"))
  92. for field, value in q_tests:
  93. dev[0].set_network_quoted(id, field, value)
  94. res = dev[0].get_network(id, field)
  95. if res != '"' + value + '"':
  96. raise Exception("Unexpected quoted response for '" + field + "': '" + res + "'")
  97. get_tests = (("foo", None), ("ssid", '"test"'))
  98. for field, value in get_tests:
  99. res = dev[0].get_network(id, field)
  100. if res != value:
  101. raise Exception("Unexpected response for '" + field + "': '" + res + "'")
  102. if dev[0].get_network(id, "password"):
  103. raise Exception("Unexpected response for 'password'")
  104. dev[0].set_network_quoted(id, "password", "foo")
  105. if dev[0].get_network(id, "password") != '*':
  106. raise Exception("Unexpected response for 'password' (expected *)")
  107. dev[0].set_network(id, "password", "hash:12345678901234567890123456789012")
  108. if dev[0].get_network(id, "password") != '*':
  109. raise Exception("Unexpected response for 'password' (expected *)")
  110. dev[0].set_network(id, "password", "NULL")
  111. if dev[0].get_network(id, "password"):
  112. raise Exception("Unexpected response for 'password'")
  113. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " password hash:12"):
  114. raise Exception("Unexpected success for invalid password hash")
  115. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " password hash:123456789012345678x0123456789012"):
  116. raise Exception("Unexpected success for invalid password hash")
  117. dev[0].set_network(id, "identity", "414243")
  118. if dev[0].get_network(id, "identity") != '"ABC"':
  119. raise Exception("Unexpected identity hex->text response")
  120. dev[0].set_network(id, "identity", 'P"abc\ndef"')
  121. if dev[0].get_network(id, "identity") != "6162630a646566":
  122. raise Exception("Unexpected identity printf->hex response")
  123. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' identity P"foo'):
  124. raise Exception("Unexpected success for invalid identity string")
  125. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' identity 12x3'):
  126. raise Exception("Unexpected success for invalid identity string")
  127. for i in range(0, 4):
  128. if "FAIL" in dev[0].request("SET_NETWORK " + str(id) + ' wep_key' + str(i) + ' aabbccddee'):
  129. raise Exception("Unexpected wep_key set failure")
  130. if dev[0].get_network(id, "wep_key" + str(i)) != '*':
  131. raise Exception("Unexpected wep_key get failure")
  132. if "FAIL" in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
  133. raise Exception("Unexpected failure for psk_list string")
  134. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list 00:11:x2:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
  135. raise Exception("Unexpected success for invalid psk_list string")
  136. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:x2:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
  137. raise Exception("Unexpected success for invalid psk_list string")
  138. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55+0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
  139. raise Exception("Unexpected success for invalid psk_list string")
  140. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde'):
  141. raise Exception("Unexpected success for invalid psk_list string")
  142. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdex'):
  143. raise Exception("Unexpected success for invalid psk_list string")
  144. if dev[0].get_network(id, "psk_list"):
  145. raise Exception("Unexpected psk_list get response")
  146. if dev[0].list_networks()[0]['ssid'] != "test":
  147. raise Exception("Unexpected ssid in LIST_NETWORKS")
  148. dev[0].set_network(id, "ssid", "NULL")
  149. if dev[0].list_networks()[0]['ssid'] != "":
  150. raise Exception("Unexpected ssid in LIST_NETWORKS after clearing it")
  151. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' ssid "0123456789abcdef0123456789abcdef0"'):
  152. raise Exception("Too long SSID accepted")
  153. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' scan_ssid qwerty'):
  154. raise Exception("Invalid integer accepted")
  155. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' scan_ssid 2'):
  156. raise Exception("Too large integer accepted")
  157. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk 12345678'):
  158. raise Exception("Invalid PSK accepted")
  159. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk "1234567"'):
  160. raise Exception("Too short PSK accepted")
  161. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk "1234567890123456789012345678901234567890123456789012345678901234"'):
  162. raise Exception("Too long PSK accepted")
  163. dev[0].set_network_quoted(id, "psk", "123456768")
  164. dev[0].set_network_quoted(id, "psk", "123456789012345678901234567890123456789012345678901234567890123")
  165. if dev[0].get_network(id, "psk") != '*':
  166. raise Exception("Unexpected psk read result")
  167. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' eap UNKNOWN'):
  168. raise Exception("Unknown EAP method accepted")
  169. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' password "foo'):
  170. raise Exception("Invalid password accepted")
  171. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' wep_key0 "foo'):
  172. raise Exception("Invalid WEP key accepted")
  173. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' wep_key0 "12345678901234567"'):
  174. raise Exception("Too long WEP key accepted")
  175. # too short WEP key is ignored
  176. dev[0].set_network_quoted(id, "wep_key0", "1234")
  177. dev[0].set_network_quoted(id, "wep_key1", "12345")
  178. dev[0].set_network_quoted(id, "wep_key2", "1234567890123")
  179. dev[0].set_network_quoted(id, "wep_key3", "1234567890123456")
  180. dev[0].set_network(id, "go_p2p_dev_addr", "any")
  181. if dev[0].get_network(id, "go_p2p_dev_addr") is not None:
  182. raise Exception("Unexpected go_p2p_dev_addr value")
  183. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' go_p2p_dev_addr 00:11:22:33:44'):
  184. raise Exception("Invalid go_p2p_dev_addr accepted")
  185. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' p2p_client_list 00:11:22:33:44'):
  186. raise Exception("Invalid p2p_client_list accepted")
  187. if "FAIL" in dev[0].request('SET_NETWORK ' + str(id) + ' p2p_client_list 00:11:22:33:44:55 00:1'):
  188. raise Exception("p2p_client_list truncation workaround failed")
  189. if dev[0].get_network(id, "p2p_client_list") != "00:11:22:33:44:55":
  190. raise Exception("p2p_client_list truncation workaround did not work")
  191. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' auth_alg '):
  192. raise Exception("Empty auth_alg accepted")
  193. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' auth_alg FOO'):
  194. raise Exception("Invalid auth_alg accepted")
  195. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' proto '):
  196. raise Exception("Empty proto accepted")
  197. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' proto FOO'):
  198. raise Exception("Invalid proto accepted")
  199. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise '):
  200. raise Exception("Empty pairwise accepted")
  201. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise FOO'):
  202. raise Exception("Invalid pairwise accepted")
  203. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise WEP40'):
  204. raise Exception("Invalid pairwise accepted")
  205. if "OK" not in dev[0].request('BSSID ' + str(id) + ' 00:11:22:33:44:55'):
  206. raise Exception("Unexpected BSSID failure")
  207. if dev[0].request("GET_NETWORK 0 bssid") != '00:11:22:33:44:55':
  208. raise Exception("BSSID command did not set network bssid")
  209. if "OK" not in dev[0].request('BSSID ' + str(id) + ' 00:00:00:00:00:00'):
  210. raise Exception("Unexpected BSSID failure")
  211. if "FAIL" not in dev[0].request("GET_NETWORK 0 bssid"):
  212. raise Exception("bssid claimed configured after clearing")
  213. if "FAIL" not in dev[0].request('BSSID 123 00:11:22:33:44:55'):
  214. raise Exception("Unexpected BSSID success")
  215. if "FAIL" not in dev[0].request('BSSID ' + str(id) + ' 00:11:22:33:44'):
  216. raise Exception("Unexpected BSSID success")
  217. if "FAIL" not in dev[0].request('BSSID ' + str(id)):
  218. raise Exception("Unexpected BSSID success")
  219. tests = [ "02:11:22:33:44:55",
  220. "02:11:22:33:44:55 02:ae:be:ce:53:77",
  221. "02:11:22:33:44:55/ff:00:ff:00:ff:00",
  222. "02:11:22:33:44:55/ff:00:ff:00:ff:00 f2:99:88:77:66:55",
  223. "f2:99:88:77:66:55 02:11:22:33:44:55/ff:00:ff:00:ff:00",
  224. "f2:99:88:77:66:55 02:11:22:33:44:55/ff:00:ff:00:ff:00 12:34:56:78:90:ab",
  225. "02:11:22:33:44:55/ff:ff:ff:00:00:00 02:ae:be:ce:53:77/00:00:00:00:00:ff" ]
  226. for val in tests:
  227. dev[0].set_network(id, "bssid_blacklist", val)
  228. res = dev[0].get_network(id, "bssid_blacklist")
  229. if res != val:
  230. raise Exception("Unexpected bssid_blacklist value: %s != %s" % (res, val))
  231. dev[0].set_network(id, "bssid_whitelist", val)
  232. res = dev[0].get_network(id, "bssid_whitelist")
  233. if res != val:
  234. raise Exception("Unexpected bssid_whitelist value: %s != %s" % (res, val))
  235. tests = [ "foo",
  236. "00:11:22:33:44:5",
  237. "00:11:22:33:44:55q",
  238. "00:11:22:33:44:55/",
  239. "00:11:22:33:44:55/66:77:88:99:aa:b" ]
  240. for val in tests:
  241. if "FAIL" not in dev[0].request("SET_NETWORK %d bssid_blacklist %s" % (id, val)):
  242. raise Exception("Invalid bssid_blacklist value accepted")
  243. @remote_compatible
  244. def test_wpas_ctrl_network_oom(dev):
  245. """wpa_supplicant ctrl_iface network OOM in string parsing"""
  246. id = dev[0].add_network()
  247. tests = [ ('"foo"', 1, 'dup_binstr;wpa_config_set'),
  248. ('P"foo"', 1, 'dup_binstr;wpa_config_set'),
  249. ('P"foo"', 2, 'wpa_config_set'),
  250. ('112233', 1, 'wpa_config_set') ]
  251. for val,count,func in tests:
  252. with alloc_fail(dev[0], count, func):
  253. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' ssid ' + val):
  254. raise Exception("Unexpected success for SET_NETWORK during OOM")
  255. @remote_compatible
  256. def test_wpas_ctrl_many_networks(dev, apdev):
  257. """wpa_supplicant ctrl_iface LIST_NETWORKS with huge number of networks"""
  258. for i in range(1000):
  259. id = dev[0].add_network()
  260. res = dev[0].request("LIST_NETWORKS")
  261. if str(id) in res:
  262. raise Exception("Last added network was unexpectedly included")
  263. res = dev[0].request("LIST_NETWORKS LAST_ID=%d" % (id - 2))
  264. if str(id) not in res:
  265. raise Exception("Last added network was not present when using LAST_ID")
  266. # This command can take a very long time under valgrind testing on a low
  267. # power CPU, so increase the command timeout significantly to avoid issues
  268. # with the test case failing and following reset operation timing out.
  269. dev[0].request("REMOVE_NETWORK all", timeout=60)
  270. @remote_compatible
  271. def test_wpas_ctrl_dup_network(dev, apdev):
  272. """wpa_supplicant ctrl_iface DUP_NETWORK"""
  273. ssid = "target"
  274. passphrase = 'qwertyuiop'
  275. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  276. hostapd.add_ap(apdev[0], params)
  277. src = dev[0].connect("another", psk=passphrase, scan_freq="2412",
  278. only_add_network=True)
  279. id = dev[0].add_network()
  280. dev[0].set_network_quoted(id, "ssid", ssid)
  281. for f in [ "key_mgmt", "psk", "scan_freq" ]:
  282. res = dev[0].request("DUP_NETWORK {} {} {}".format(src, id, f))
  283. if "OK" not in res:
  284. raise Exception("DUP_NETWORK failed")
  285. dev[0].connect_network(id)
  286. if "FAIL" not in dev[0].request("DUP_NETWORK "):
  287. raise Exception("Unexpected DUP_NETWORK success")
  288. if "FAIL" not in dev[0].request("DUP_NETWORK %d " % id):
  289. raise Exception("Unexpected DUP_NETWORK success")
  290. if "FAIL" not in dev[0].request("DUP_NETWORK %d %d" % (id, id)):
  291. raise Exception("Unexpected DUP_NETWORK success")
  292. if "FAIL" not in dev[0].request("DUP_NETWORK 123456 1234567 "):
  293. raise Exception("Unexpected DUP_NETWORK success")
  294. if "FAIL" not in dev[0].request("DUP_NETWORK %d 123456 " % id):
  295. raise Exception("Unexpected DUP_NETWORK success")
  296. if "FAIL" not in dev[0].request("DUP_NETWORK %d %d foo" % (id, id)):
  297. raise Exception("Unexpected DUP_NETWORK success")
  298. dev[0].request("DISCONNECT")
  299. if "OK" not in dev[0].request("DUP_NETWORK %d %d ssid" % (id, id)):
  300. raise Exception("Unexpected DUP_NETWORK failure")
  301. @remote_compatible
  302. def test_wpas_ctrl_dup_network_global(dev, apdev):
  303. """wpa_supplicant ctrl_iface DUP_NETWORK (global)"""
  304. ssid = "target"
  305. passphrase = 'qwertyuiop'
  306. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  307. hostapd.add_ap(apdev[0], params)
  308. src = dev[0].connect("another", psk=passphrase, scan_freq="2412",
  309. only_add_network=True)
  310. id = dev[0].add_network()
  311. dev[0].set_network_quoted(id, "ssid", ssid)
  312. for f in [ "key_mgmt", "psk", "scan_freq" ]:
  313. res = dev[0].global_request("DUP_NETWORK {} {} {} {} {}".format(dev[0].ifname, dev[0].ifname, src, id, f))
  314. if "OK" not in res:
  315. raise Exception("DUP_NETWORK failed")
  316. dev[0].connect_network(id)
  317. if "FAIL" not in dev[0].global_request("DUP_NETWORK "):
  318. raise Exception("Unexpected DUP_NETWORK success")
  319. if "FAIL" not in dev[0].global_request("DUP_NETWORK %s" % dev[0].ifname):
  320. raise Exception("Unexpected DUP_NETWORK success")
  321. if "FAIL" not in dev[0].global_request("DUP_NETWORK %s %s" % (dev[0].ifname, dev[0].ifname)):
  322. raise Exception("Unexpected DUP_NETWORK success")
  323. if "FAIL" not in dev[0].global_request("DUP_NETWORK %s %s %d" % (dev[0].ifname, dev[0].ifname, id)):
  324. raise Exception("Unexpected DUP_NETWORK success")
  325. if "FAIL" not in dev[0].global_request("DUP_NETWORK %s %s %d %d" % (dev[0].ifname, dev[0].ifname, id, id)):
  326. raise Exception("Unexpected DUP_NETWORK success")
  327. dev[0].request("DISCONNECT")
  328. if "OK" not in dev[0].global_request("DUP_NETWORK %s %s %d %d ssid" % (dev[0].ifname, dev[0].ifname, id, id)):
  329. raise Exception("Unexpected DUP_NETWORK failure")
  330. def add_cred(dev):
  331. id = dev.add_cred()
  332. ev = dev.wait_event(["CRED-ADDED"])
  333. if ev is None:
  334. raise Exception("Missing CRED-ADDED event")
  335. if " " + str(id) not in ev:
  336. raise Exception("CRED-ADDED event without matching id")
  337. return id
  338. def set_cred(dev, id, field, value):
  339. dev.set_cred(id, field, value)
  340. ev = dev.wait_event(["CRED-MODIFIED"])
  341. if ev is None:
  342. raise Exception("Missing CRED-MODIFIED event")
  343. if " " + str(id) + " " not in ev:
  344. raise Exception("CRED-MODIFIED event without matching id")
  345. if field not in ev:
  346. raise Exception("CRED-MODIFIED event without matching field")
  347. def set_cred_quoted(dev, id, field, value):
  348. dev.set_cred_quoted(id, field, value)
  349. ev = dev.wait_event(["CRED-MODIFIED"])
  350. if ev is None:
  351. raise Exception("Missing CRED-MODIFIED event")
  352. if " " + str(id) + " " not in ev:
  353. raise Exception("CRED-MODIFIED event without matching id")
  354. if field not in ev:
  355. raise Exception("CRED-MODIFIED event without matching field")
  356. def remove_cred(dev, id):
  357. dev.remove_cred(id)
  358. ev = dev.wait_event(["CRED-REMOVED"])
  359. if ev is None:
  360. raise Exception("Missing CRED-REMOVED event")
  361. if " " + str(id) not in ev:
  362. raise Exception("CRED-REMOVED event without matching id")
  363. @remote_compatible
  364. def test_wpas_ctrl_cred(dev):
  365. """wpa_supplicant ctrl_iface cred set"""
  366. id1 = add_cred(dev[0])
  367. if "FAIL" not in dev[0].request("SET_CRED " + str(id1 + 1) + " temporary 1"):
  368. raise Exception("SET_CRED succeeded unexpectedly on unknown cred id")
  369. if "FAIL" not in dev[0].request("SET_CRED " + str(id1)):
  370. raise Exception("Invalid SET_CRED succeeded unexpectedly")
  371. if "FAIL" not in dev[0].request("SET_CRED " + str(id1) + " temporary"):
  372. raise Exception("Invalid SET_CRED succeeded unexpectedly")
  373. if "FAIL" not in dev[0].request("GET_CRED " + str(id1 + 1) + " temporary"):
  374. raise Exception("GET_CRED succeeded unexpectedly on unknown cred id")
  375. if "FAIL" not in dev[0].request("GET_CRED " + str(id1)):
  376. raise Exception("Invalid GET_CRED succeeded unexpectedly")
  377. if "FAIL" not in dev[0].request("GET_CRED " + str(id1) + " foo"):
  378. raise Exception("Invalid GET_CRED succeeded unexpectedly")
  379. id = add_cred(dev[0])
  380. id2 = add_cred(dev[0])
  381. set_cred(dev[0], id, "temporary", "1")
  382. set_cred(dev[0], id, "priority", "1")
  383. set_cred(dev[0], id, "pcsc", "1")
  384. set_cred(dev[0], id, "sim_num", "0")
  385. set_cred_quoted(dev[0], id, "private_key_passwd", "test")
  386. set_cred_quoted(dev[0], id, "domain_suffix_match", "test")
  387. set_cred_quoted(dev[0], id, "phase1", "test")
  388. set_cred_quoted(dev[0], id, "phase2", "test")
  389. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " eap FOO"):
  390. raise Exception("Unexpected success on unknown EAP method")
  391. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " username 12xa"):
  392. raise Exception("Unexpected success on invalid string")
  393. for i in ("11", "1122", "112233445566778899aabbccddeeff00"):
  394. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " roaming_consortium " + i):
  395. raise Exception("Unexpected success on invalid roaming_consortium")
  396. dev[0].set_cred(id, "excluded_ssid", "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff")
  397. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " excluded_ssid 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"):
  398. raise Exception("Unexpected success on invalid excluded_ssid")
  399. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " foo 4142"):
  400. raise Exception("Unexpected success on unknown field")
  401. tests = ["sp_priority 256",
  402. 'roaming_partner "example.org"',
  403. 'roaming_partner "' + 200*'a' + '.example.org,"',
  404. 'roaming_partner "example.org,1"',
  405. 'roaming_partner "example.org,1,2"',
  406. 'roaming_partner "example.org,1,2,ABC"' ]
  407. for t in tests:
  408. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " " + t):
  409. raise Exception("Unexpected success on invalid SET_CRED value: " + t)
  410. id3 = add_cred(dev[0])
  411. id4 = add_cred(dev[0])
  412. if len(dev[0].request("LIST_CREDS").splitlines()) != 6:
  413. raise Exception("Unexpected LIST_CREDS result(1)")
  414. remove_cred(dev[0], id1)
  415. remove_cred(dev[0], id3)
  416. remove_cred(dev[0], id4)
  417. remove_cred(dev[0], id2)
  418. remove_cred(dev[0], id)
  419. if "FAIL" not in dev[0].request("REMOVE_CRED 1"):
  420. raise Exception("Unexpected success on invalid remove cred")
  421. if len(dev[0].request("LIST_CREDS").splitlines()) != 1:
  422. raise Exception("Unexpected LIST_CREDS result(2)")
  423. id = add_cred(dev[0])
  424. values = [ ("temporary", "1", False),
  425. ("temporary", "0", False),
  426. ("pcsc", "1", False),
  427. ("realm", "example.com", True),
  428. ("username", "user@example.com", True),
  429. ("password", "foo", True, "*"),
  430. ("ca_cert", "ca.pem", True),
  431. ("client_cert", "user.pem", True),
  432. ("private_key", "key.pem", True),
  433. ("private_key_passwd", "foo", True, "*"),
  434. ("imsi", "310026-000000000", True),
  435. ("milenage", "foo", True, "*"),
  436. ("domain_suffix_match", "example.com", True),
  437. ("domain", "example.com", True),
  438. ("domain", "example.org", True, "example.com\nexample.org"),
  439. ("roaming_consortium", "0123456789", False),
  440. ("required_roaming_consortium", "456789", False),
  441. ("eap", "TTLS", False),
  442. ("phase1", "foo=bar1", True),
  443. ("phase2", "foo=bar2", True),
  444. ("excluded_ssid", "test", True),
  445. ("excluded_ssid", "foo", True, "test\nfoo"),
  446. ("roaming_partner", "example.com,0,4,*", True),
  447. ("roaming_partner", "example.org,1,2,US", True,
  448. "example.com,0,4,*\nexample.org,1,2,US"),
  449. ("update_identifier", "4", False),
  450. ("provisioning_sp", "sp.example.com", True),
  451. ("sp_priority", "7", False),
  452. ("min_dl_bandwidth_home", "100", False),
  453. ("min_ul_bandwidth_home", "101", False),
  454. ("min_dl_bandwidth_roaming", "102", False),
  455. ("min_ul_bandwidth_roaming", "103", False),
  456. ("max_bss_load", "57", False),
  457. ("req_conn_capab", "6:22,80,443", False),
  458. ("req_conn_capab", "17:500", False, "6:22,80,443\n17:500"),
  459. ("req_conn_capab", "50", False, "6:22,80,443\n17:500\n50"),
  460. ("ocsp", "1", False) ]
  461. for v in values:
  462. if v[2]:
  463. set_cred_quoted(dev[0], id, v[0], v[1])
  464. else:
  465. set_cred(dev[0], id, v[0], v[1])
  466. val = dev[0].get_cred(id, v[0])
  467. if len(v) == 4:
  468. expect = v[3]
  469. else:
  470. expect = v[1]
  471. if val != expect:
  472. raise Exception("Unexpected GET_CRED value for {}: {} != {}".format(v[0], val, expect))
  473. creds = dev[0].request("LIST_CREDS").splitlines()
  474. if len(creds) != 2:
  475. raise Exception("Unexpected LIST_CREDS result(3)")
  476. if creds[1] != "0\texample.com\tuser@example.com\texample.com\t310026-000000000":
  477. raise Exception("Unexpected LIST_CREDS value")
  478. remove_cred(dev[0], id)
  479. if len(dev[0].request("LIST_CREDS").splitlines()) != 1:
  480. raise Exception("Unexpected LIST_CREDS result(4)")
  481. id = add_cred(dev[0])
  482. set_cred_quoted(dev[0], id, "domain", "foo.example.com")
  483. id = add_cred(dev[0])
  484. set_cred_quoted(dev[0], id, "domain", "bar.example.com")
  485. id = add_cred(dev[0])
  486. set_cred_quoted(dev[0], id, "domain", "foo.example.com")
  487. if "OK" not in dev[0].request("REMOVE_CRED sp_fqdn=foo.example.com"):
  488. raise Exception("REMOVE_CRED failed")
  489. creds = dev[0].request("LIST_CREDS")
  490. if "foo.example.com" in creds:
  491. raise Exception("REMOVE_CRED sp_fqdn did not remove cred")
  492. if "bar.example.com" not in creds:
  493. raise Exception("REMOVE_CRED sp_fqdn removed incorrect cred")
  494. dev[0].request("REMOVE_CRED all")
  495. id = add_cred(dev[0])
  496. set_cred_quoted(dev[0], id, "domain", "foo.example.com")
  497. set_cred_quoted(dev[0], id, "provisioning_sp", "sp.foo.example.com")
  498. id = add_cred(dev[0])
  499. set_cred_quoted(dev[0], id, "domain", "bar.example.com")
  500. set_cred_quoted(dev[0], id, "provisioning_sp", "sp.bar.example.com")
  501. id = add_cred(dev[0])
  502. set_cred_quoted(dev[0], id, "domain", "foo.example.com")
  503. set_cred_quoted(dev[0], id, "provisioning_sp", "sp.foo.example.com")
  504. if "OK" not in dev[0].request("REMOVE_CRED provisioning_sp=sp.foo.example.com"):
  505. raise Exception("REMOVE_CRED failed")
  506. creds = dev[0].request("LIST_CREDS")
  507. if "foo.example.com" in creds:
  508. raise Exception("REMOVE_CRED provisioning_sp did not remove cred")
  509. if "bar.example.com" not in creds:
  510. raise Exception("REMOVE_CRED provisioning_sp removed incorrect cred")
  511. dev[0].request("REMOVE_CRED all")
  512. # Test large number of creds and LIST_CREDS truncation
  513. dev[0].dump_monitor()
  514. for i in range(0, 100):
  515. id = add_cred(dev[0])
  516. set_cred_quoted(dev[0], id, "realm", "relatively.long.realm.test%d.example.com" % i)
  517. dev[0].dump_monitor()
  518. creds = dev[0].request("LIST_CREDS")
  519. for i in range(0, 100):
  520. dev[0].remove_cred(i)
  521. dev[0].dump_monitor()
  522. if len(creds) < 3900 or len(creds) > 4100:
  523. raise Exception("Unexpected LIST_CREDS length: %d" % len(creds))
  524. if "test10.example.com" not in creds:
  525. raise Exception("Missing credential")
  526. if len(creds.splitlines()) > 95:
  527. raise Exception("Too many LIST_CREDS entries in the buffer")
  528. def test_wpas_ctrl_pno(dev):
  529. """wpa_supplicant ctrl_iface pno"""
  530. if "FAIL" not in dev[0].request("SET pno 1"):
  531. raise Exception("Unexpected success in enabling PNO without enabled network blocks")
  532. id = dev[0].add_network()
  533. dev[0].set_network_quoted(id, "ssid", "test")
  534. dev[0].set_network(id, "key_mgmt", "NONE")
  535. dev[0].request("ENABLE_NETWORK " + str(id) + " no-connect")
  536. #mac80211_hwsim does not yet support PNO, so this fails
  537. if "FAIL" not in dev[0].request("SET pno 1"):
  538. raise Exception("Unexpected success in enabling PNO")
  539. if "FAIL" not in dev[0].request("SET pno 1 freq=2000-3000,5180"):
  540. raise Exception("Unexpected success in enabling PNO")
  541. if "FAIL" not in dev[0].request("SET pno 1 freq=0-6000"):
  542. raise Exception("Unexpected success in enabling PNO")
  543. if "FAIL" in dev[0].request("SET pno 0"):
  544. raise Exception("Unexpected failure in disabling PNO")
  545. @remote_compatible
  546. def test_wpas_ctrl_get(dev):
  547. """wpa_supplicant ctrl_iface get"""
  548. if "FAIL" in dev[0].request("GET version"):
  549. raise Exception("Unexpected get failure for version")
  550. if "FAIL" in dev[0].request("GET wifi_display"):
  551. raise Exception("Unexpected get failure for wifi_display")
  552. if "FAIL" not in dev[0].request("GET foo"):
  553. raise Exception("Unexpected success on get command")
  554. dev[0].set("wifi_display", "0")
  555. if dev[0].request("GET wifi_display") != '0':
  556. raise Exception("Unexpected wifi_display value")
  557. dev[0].set("wifi_display", "1")
  558. if dev[0].request("GET wifi_display") != '1':
  559. raise Exception("Unexpected wifi_display value")
  560. dev[0].request("P2P_SET disabled 1")
  561. if dev[0].request("GET wifi_display") != '0':
  562. raise Exception("Unexpected wifi_display value (P2P disabled)")
  563. dev[0].request("P2P_SET disabled 0")
  564. if dev[0].request("GET wifi_display") != '1':
  565. raise Exception("Unexpected wifi_display value (P2P re-enabled)")
  566. dev[0].set("wifi_display", "0")
  567. if dev[0].request("GET wifi_display") != '0':
  568. raise Exception("Unexpected wifi_display value")
  569. @remote_compatible
  570. def test_wpas_ctrl_preauth(dev):
  571. """wpa_supplicant ctrl_iface preauth"""
  572. if "FAIL" not in dev[0].request("PREAUTH "):
  573. raise Exception("Unexpected success on invalid PREAUTH")
  574. if "FAIL" in dev[0].request("PREAUTH 00:11:22:33:44:55"):
  575. raise Exception("Unexpected failure on PREAUTH")
  576. @remote_compatible
  577. def test_wpas_ctrl_tdls_discover(dev):
  578. """wpa_supplicant ctrl_iface tdls_discover"""
  579. if "FAIL" not in dev[0].request("TDLS_DISCOVER "):
  580. raise Exception("Unexpected success on invalid TDLS_DISCOVER")
  581. if "FAIL" not in dev[0].request("TDLS_DISCOVER 00:11:22:33:44:55"):
  582. raise Exception("Unexpected success on TDLS_DISCOVER")
  583. @remote_compatible
  584. def test_wpas_ctrl_tdls_chan_switch(dev):
  585. """wpa_supplicant ctrl_iface tdls_chan_switch error cases"""
  586. for args in [ '', '00:11:22:33:44:55' ]:
  587. if "FAIL" not in dev[0].request("TDLS_CANCEL_CHAN_SWITCH " + args):
  588. raise Exception("Unexpected success on invalid TDLS_CANCEL_CHAN_SWITCH: " + args)
  589. for args in [ '', 'foo ', '00:11:22:33:44:55 ', '00:11:22:33:44:55 q',
  590. '00:11:22:33:44:55 81', '00:11:22:33:44:55 81 1234',
  591. '00:11:22:33:44:55 81 1234 center_freq1=234 center_freq2=345 bandwidth=456 sec_channel_offset=567 ht vht' ]:
  592. if "FAIL" not in dev[0].request("TDLS_CHAN_SWITCH " + args):
  593. raise Exception("Unexpected success on invalid TDLS_CHAN_SWITCH: " + args)
  594. @remote_compatible
  595. def test_wpas_ctrl_addr(dev):
  596. """wpa_supplicant ctrl_iface invalid address"""
  597. if "FAIL" not in dev[0].request("TDLS_SETUP "):
  598. raise Exception("Unexpected success on invalid TDLS_SETUP")
  599. if "FAIL" not in dev[0].request("TDLS_TEARDOWN "):
  600. raise Exception("Unexpected success on invalid TDLS_TEARDOWN")
  601. if "FAIL" not in dev[0].request("FT_DS "):
  602. raise Exception("Unexpected success on invalid FT_DS")
  603. if "FAIL" not in dev[0].request("WPS_PBC 00:11:22:33:44"):
  604. raise Exception("Unexpected success on invalid WPS_PBC")
  605. if "FAIL" not in dev[0].request("WPS_PIN 00:11:22:33:44"):
  606. raise Exception("Unexpected success on invalid WPS_PIN")
  607. if "FAIL" not in dev[0].request("WPS_NFC 00:11:22:33:44"):
  608. raise Exception("Unexpected success on invalid WPS_NFC")
  609. if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44 12345670"):
  610. raise Exception("Unexpected success on invalid WPS_REG")
  611. if "FAIL" not in dev[0].request("IBSS_RSN 00:11:22:33:44"):
  612. raise Exception("Unexpected success on invalid IBSS_RSN")
  613. if "FAIL" not in dev[0].request("BLACKLIST 00:11:22:33:44"):
  614. raise Exception("Unexpected success on invalid BLACKLIST")
  615. @remote_compatible
  616. def test_wpas_ctrl_wps_errors(dev):
  617. """wpa_supplicant ctrl_iface WPS error cases"""
  618. if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55"):
  619. raise Exception("Unexpected success on invalid WPS_REG")
  620. if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55 12345670 2233"):
  621. raise Exception("Unexpected success on invalid WPS_REG")
  622. if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55 12345670 2233 OPEN"):
  623. raise Exception("Unexpected success on invalid WPS_REG")
  624. if "FAIL" not in dev[0].request("WPS_REG 00:11:22:33:44:55 12345670 2233 OPEN NONE"):
  625. raise Exception("Unexpected success on invalid WPS_REG")
  626. if "FAIL" not in dev[0].request("WPS_AP_PIN random"):
  627. raise Exception("Unexpected success on WPS_AP_PIN in non-AP mode")
  628. if "FAIL" not in dev[0].request("WPS_ER_PIN any"):
  629. raise Exception("Unexpected success on invalid WPS_ER_PIN")
  630. if "FAIL" not in dev[0].request("WPS_ER_LEARN 00:11:22:33:44:55"):
  631. raise Exception("Unexpected success on invalid WPS_ER_LEARN")
  632. if "FAIL" not in dev[0].request("WPS_ER_SET_CONFIG 00:11:22:33:44:55"):
  633. raise Exception("Unexpected success on invalid WPS_ER_SET_CONFIG")
  634. if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55"):
  635. raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
  636. if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670"):
  637. raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
  638. if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670 2233"):
  639. raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
  640. if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670 2233 OPEN"):
  641. raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
  642. if "FAIL" not in dev[0].request("WPS_ER_CONFIG 00:11:22:33:44:55 12345670 2233 OPEN NONE"):
  643. raise Exception("Unexpected success on invalid WPS_ER_CONFIG")
  644. if "FAIL" not in dev[0].request("WPS_ER_NFC_CONFIG_TOKEN WPS"):
  645. raise Exception("Unexpected success on invalid WPS_ER_NFC_CONFIG_TOKEN")
  646. if "FAIL" not in dev[0].request("WPS_ER_NFC_CONFIG_TOKEN FOO 00:11:22:33:44:55"):
  647. raise Exception("Unexpected success on invalid WPS_ER_NFC_CONFIG_TOKEN")
  648. if "FAIL" not in dev[0].request("WPS_ER_NFC_CONFIG_TOKEN NDEF 00:11:22:33:44:55"):
  649. raise Exception("Unexpected success on invalid WPS_ER_NFC_CONFIG_TOKEN")
  650. if "FAIL" not in dev[0].request("WPS_NFC_CONFIG_TOKEN FOO"):
  651. raise Exception("Unexpected success on invalid WPS_NFC_CONFIG_TOKEN")
  652. if "FAIL" not in dev[0].request("WPS_NFC_CONFIG_TOKEN WPS FOO"):
  653. raise Exception("Unexpected success on invalid WPS_NFC_CONFIG_TOKEN")
  654. if "FAIL" not in dev[0].request("WPS_NFC_TOKEN FOO"):
  655. raise Exception("Unexpected success on invalid WPS_NFC_TOKEN")
  656. @remote_compatible
  657. def test_wpas_ctrl_config_parser(dev):
  658. """wpa_supplicant ctrl_iface SET config parser"""
  659. if "FAIL" not in dev[0].request("SET pbc_in_m1 qwerty"):
  660. raise Exception("Non-number accepted as integer")
  661. if "FAIL" not in dev[0].request("SET eapol_version 0"):
  662. raise Exception("Out-of-range value accepted")
  663. if "FAIL" not in dev[0].request("SET eapol_version 10"):
  664. raise Exception("Out-of-range value accepted")
  665. if "FAIL" not in dev[0].request("SET serial_number 0123456789abcdef0123456789abcdef0"):
  666. raise Exception("Too long string accepted")
  667. @remote_compatible
  668. def test_wpas_ctrl_mib(dev):
  669. """wpa_supplicant ctrl_iface MIB"""
  670. mib = dev[0].get_mib()
  671. if "dot11RSNAOptionImplemented" not in mib:
  672. raise Exception("Missing MIB entry")
  673. if mib["dot11RSNAOptionImplemented"] != "TRUE":
  674. raise Exception("Unexpected dot11RSNAOptionImplemented value")
  675. def test_wpas_ctrl_set_wps_params(dev):
  676. """wpa_supplicant ctrl_iface SET config_methods"""
  677. try:
  678. _test_wpas_ctrl_set_wps_params(dev)
  679. finally:
  680. dev[2].request("SET config_methods ")
  681. def _test_wpas_ctrl_set_wps_params(dev):
  682. ts = [ "config_methods label virtual_display virtual_push_button keypad",
  683. "device_type 1-0050F204-1",
  684. "os_version 01020300",
  685. "uuid 12345678-9abc-def0-1234-56789abcdef0" ]
  686. for t in ts:
  687. if "OK" not in dev[2].request("SET " + t):
  688. raise Exception("SET failed for: " + t)
  689. ts = [ "uuid 12345678+9abc-def0-1234-56789abcdef0",
  690. "uuid 12345678-qabc-def0-1234-56789abcdef0",
  691. "uuid 12345678-9abc+def0-1234-56789abcdef0",
  692. "uuid 12345678-9abc-qef0-1234-56789abcdef0",
  693. "uuid 12345678-9abc-def0+1234-56789abcdef0",
  694. "uuid 12345678-9abc-def0-q234-56789abcdef0",
  695. "uuid 12345678-9abc-def0-1234+56789abcdef0",
  696. "uuid 12345678-9abc-def0-1234-q6789abcdef0",
  697. "uuid qwerty" ]
  698. for t in ts:
  699. if "FAIL" not in dev[2].request("SET " + t):
  700. raise Exception("SET succeeded for: " + t)
  701. def test_wpas_ctrl_level(dev):
  702. """wpa_supplicant ctrl_iface LEVEL"""
  703. try:
  704. if "FAIL" not in dev[2].request("LEVEL 3"):
  705. raise Exception("Unexpected LEVEL success")
  706. if "OK" not in dev[2].mon.request("LEVEL 2"):
  707. raise Exception("Unexpected LEVEL failure")
  708. dev[2].request("SCAN freq=2412")
  709. ev = dev[2].wait_event(["State:"], timeout=5)
  710. if ev is None:
  711. raise Exception("No debug message received")
  712. dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=5)
  713. finally:
  714. dev[2].mon.request("LEVEL 3")
  715. def test_wpas_ctrl_bssid_filter(dev, apdev):
  716. """wpa_supplicant bssid_filter"""
  717. try:
  718. if "OK" not in dev[2].request("SET bssid_filter " + apdev[0]['bssid']):
  719. raise Exception("Failed to set bssid_filter")
  720. params = { "ssid": "test" }
  721. hostapd.add_ap(apdev[0], params)
  722. hostapd.add_ap(apdev[1], params)
  723. dev[2].scan_for_bss(apdev[0]['bssid'], freq="2412")
  724. dev[2].scan(freq="2412")
  725. bss = dev[2].get_bss(apdev[0]['bssid'])
  726. if bss is None or len(bss) == 0:
  727. raise Exception("Missing BSS data")
  728. bss = dev[2].get_bss(apdev[1]['bssid'])
  729. if bss and len(bss) != 0:
  730. raise Exception("Unexpected BSS data")
  731. dev[2].request("SET bssid_filter ")
  732. dev[2].scan(freq="2412")
  733. bss = dev[2].get_bss(apdev[0]['bssid'])
  734. if bss is None or len(bss) == 0:
  735. raise Exception("Missing BSS data")
  736. bss = dev[2].get_bss(apdev[1]['bssid'])
  737. if bss is None or len(bss) == 0:
  738. raise Exception("Missing BSS data(2)")
  739. res = dev[2].request("SCAN_RESULTS").splitlines()
  740. if "test" not in res[1] or "test" not in res[2]:
  741. raise Exception("SSID missing from SCAN_RESULTS")
  742. if apdev[0]['bssid'] not in res[1] and apdev[1]['bssid'] not in res[1]:
  743. raise Exception("BSS1 missing from SCAN_RESULTS")
  744. if apdev[0]['bssid'] not in res[2] and apdev[1]['bssid'] not in res[2]:
  745. raise Exception("BSS1 missing from SCAN_RESULTS")
  746. if "FAIL" not in dev[2].request("SET bssid_filter 00:11:22:33:44:55 00:11:22:33:44"):
  747. raise Exception("Unexpected success for invalid SET bssid_filter")
  748. finally:
  749. dev[2].request("SET bssid_filter ")
  750. @remote_compatible
  751. def test_wpas_ctrl_disallow_aps(dev, apdev):
  752. """wpa_supplicant ctrl_iface disallow_aps"""
  753. params = { "ssid": "test" }
  754. hostapd.add_ap(apdev[0], params)
  755. if "FAIL" not in dev[0].request("SET disallow_aps bssid "):
  756. raise Exception("Unexpected success on invalid disallow_aps")
  757. if "FAIL" not in dev[0].request("SET disallow_aps bssid 00:11:22:33:44"):
  758. raise Exception("Unexpected success on invalid disallow_aps")
  759. if "FAIL" not in dev[0].request("SET disallow_aps ssid 0"):
  760. raise Exception("Unexpected success on invalid disallow_aps")
  761. if "FAIL" not in dev[0].request("SET disallow_aps ssid 4q"):
  762. raise Exception("Unexpected success on invalid disallow_aps")
  763. if "FAIL" not in dev[0].request("SET disallow_aps bssid 00:11:22:33:44:55 ssid 112233 ssid 123"):
  764. raise Exception("Unexpected success on invalid disallow_aps")
  765. if "FAIL" not in dev[0].request("SET disallow_aps ssid 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f00"):
  766. raise Exception("Unexpected success on invalid disallow_aps")
  767. if "FAIL" not in dev[0].request("SET disallow_aps foo 112233445566"):
  768. raise Exception("Unexpected success on invalid disallow_aps")
  769. dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
  770. hostapd.add_ap(apdev[1], params)
  771. dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
  772. dev[0].dump_monitor()
  773. if "OK" not in dev[0].request("SET disallow_aps bssid 00:11:22:33:44:55 bssid 00:22:33:44:55:66"):
  774. raise Exception("Failed to set disallow_aps")
  775. if "OK" not in dev[0].request("SET disallow_aps bssid " + apdev[0]['bssid']):
  776. raise Exception("Failed to set disallow_aps")
  777. ev = dev[0].wait_connected(timeout=30, error="Reassociation timed out")
  778. if apdev[1]['bssid'] not in ev:
  779. raise Exception("Unexpected BSSID")
  780. dev[0].dump_monitor()
  781. if "OK" not in dev[0].request("SET disallow_aps ssid " + "test".encode("hex")):
  782. raise Exception("Failed to set disallow_aps")
  783. dev[0].wait_disconnected(timeout=5, error="Disconnection not seen")
  784. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  785. if ev is not None:
  786. raise Exception("Unexpected reassociation")
  787. dev[0].request("DISCONNECT")
  788. dev[0].p2p_start_go(freq=2412)
  789. if "OK" not in dev[0].request("SET disallow_aps "):
  790. raise Exception("Failed to set disallow_aps")
  791. @remote_compatible
  792. def test_wpas_ctrl_blob(dev):
  793. """wpa_supplicant ctrl_iface SET blob"""
  794. if "FAIL" not in dev[0].request("SET blob foo"):
  795. raise Exception("Unexpected SET success")
  796. if "FAIL" not in dev[0].request("SET blob foo 0"):
  797. raise Exception("Unexpected SET success")
  798. if "FAIL" not in dev[0].request("SET blob foo 0q"):
  799. raise Exception("Unexpected SET success")
  800. if "OK" not in dev[0].request("SET blob foo 00"):
  801. raise Exception("Unexpected SET failure")
  802. if "OK" not in dev[0].request("SET blob foo 0011"):
  803. raise Exception("Unexpected SET failure")
  804. @remote_compatible
  805. def test_wpas_ctrl_set_uapsd(dev):
  806. """wpa_supplicant ctrl_iface SET uapsd"""
  807. if "FAIL" not in dev[0].request("SET uapsd foo"):
  808. raise Exception("Unexpected SET success")
  809. if "FAIL" not in dev[0].request("SET uapsd 0,0,0"):
  810. raise Exception("Unexpected SET success")
  811. if "FAIL" not in dev[0].request("SET uapsd 0,0"):
  812. raise Exception("Unexpected SET success")
  813. if "FAIL" not in dev[0].request("SET uapsd 0"):
  814. raise Exception("Unexpected SET success")
  815. if "OK" not in dev[0].request("SET uapsd 1,1,1,1;1"):
  816. raise Exception("Unexpected SET failure")
  817. if "OK" not in dev[0].request("SET uapsd 0,0,0,0;0"):
  818. raise Exception("Unexpected SET failure")
  819. if "OK" not in dev[0].request("SET uapsd disable"):
  820. raise Exception("Unexpected SET failure")
  821. def test_wpas_ctrl_set(dev):
  822. """wpa_supplicant ctrl_iface SET"""
  823. vals = [ "foo",
  824. "ampdu 0",
  825. "radio_disable 0",
  826. "ps 10",
  827. "ps 1",
  828. "dot11RSNAConfigPMKLifetime 0",
  829. "dot11RSNAConfigPMKReauthThreshold 101",
  830. "dot11RSNAConfigSATimeout 0",
  831. "wps_version_number -1",
  832. "wps_version_number 256",
  833. "fst_group_id ",
  834. "fst_llt 0"]
  835. for val in vals:
  836. if "FAIL" not in dev[0].request("SET " + val):
  837. raise Exception("Unexpected SET success for " + val)
  838. vals = [ "EAPOL::heldPeriod 60",
  839. "EAPOL::authPeriod 30",
  840. "EAPOL::startPeriod 30",
  841. "EAPOL::maxStart 3",
  842. "dot11RSNAConfigSATimeout 60",
  843. "ps -1",
  844. "ps 0",
  845. "no_keep_alive 0",
  846. "tdls_disabled 1",
  847. "tdls_disabled 0" ]
  848. for val in vals:
  849. if "OK" not in dev[0].request("SET " + val):
  850. raise Exception("Unexpected SET failure for " + val)
  851. # This fails if wpa_supplicant is built with loadable EAP peer method
  852. # support due to missing file and succeeds if no support for loadable
  853. # methods is included, so don't check the return value for now.
  854. dev[0].request("SET load_dynamic_eap /tmp/hwsim-eap-not-found.so")
  855. @remote_compatible
  856. def test_wpas_ctrl_get_capability(dev):
  857. """wpa_supplicant ctrl_iface GET_CAPABILITY"""
  858. if "FAIL" not in dev[0].request("GET_CAPABILITY 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"):
  859. raise Exception("Unexpected success on invalid GET_CAPABILITY")
  860. if "FAIL" not in dev[0].request("GET_CAPABILITY eap foo"):
  861. raise Exception("Unexpected success on invalid GET_CAPABILITY")
  862. if "AP" not in dev[0].request("GET_CAPABILITY modes strict"):
  863. raise Exception("Unexpected GET_CAPABILITY response")
  864. res = dev[0].get_capability("eap")
  865. if "TTLS" not in res:
  866. raise Exception("Unexpected GET_CAPABILITY eap response: " + str(res))
  867. res = dev[0].get_capability("pairwise")
  868. if "CCMP" not in res:
  869. raise Exception("Unexpected GET_CAPABILITY pairwise response: " + str(res))
  870. res = dev[0].get_capability("group")
  871. if "CCMP" not in res:
  872. raise Exception("Unexpected GET_CAPABILITY group response: " + str(res))
  873. res = dev[0].get_capability("key_mgmt")
  874. if "WPA-PSK" not in res or "WPA-EAP" not in res:
  875. raise Exception("Unexpected GET_CAPABILITY key_mgmt response: " + str(res))
  876. res = dev[0].get_capability("proto")
  877. if "WPA" not in res or "RSN" not in res:
  878. raise Exception("Unexpected GET_CAPABILITY proto response: " + str(res))
  879. res = dev[0].get_capability("auth_alg")
  880. if "OPEN" not in res or "SHARED" not in res:
  881. raise Exception("Unexpected GET_CAPABILITY auth_alg response: " + str(res))
  882. res = dev[0].get_capability("modes")
  883. if "IBSS" not in res or "AP" not in res:
  884. raise Exception("Unexpected GET_CAPABILITY modes response: " + str(res))
  885. res = dev[0].get_capability("channels")
  886. if "8" not in res or "36" not in res:
  887. raise Exception("Unexpected GET_CAPABILITY channels response: " + str(res))
  888. res = dev[0].get_capability("freq")
  889. if "2457" not in res or "5180" not in res:
  890. raise Exception("Unexpected GET_CAPABILITY freq response: " + str(res))
  891. res = dev[0].get_capability("tdls")
  892. if "EXTERNAL" not in res[0]:
  893. raise Exception("Unexpected GET_CAPABILITY tdls response: " + str(res))
  894. res = dev[0].get_capability("erp")
  895. if res is None or "ERP" not in res[0]:
  896. raise Exception("Unexpected GET_CAPABILITY erp response: " + str(res))
  897. if dev[0].get_capability("foo") is not None:
  898. raise Exception("Unexpected GET_CAPABILITY foo response: " + str(res))
  899. @remote_compatible
  900. def test_wpas_ctrl_nfc_report_handover(dev):
  901. """wpa_supplicant ctrl_iface NFC_REPORT_HANDOVER"""
  902. vals = [ "FOO",
  903. "ROLE freq=12345",
  904. "ROLE TYPE",
  905. "ROLE TYPE REQ",
  906. "ROLE TYPE REQ SEL",
  907. "ROLE TYPE 0Q SEL",
  908. "ROLE TYPE 00 SEL",
  909. "ROLE TYPE 00 0Q",
  910. "ROLE TYPE 00 00" ]
  911. for v in vals:
  912. if "FAIL" not in dev[0].request("NFC_REPORT_HANDOVER " + v):
  913. raise Exception("Unexpected NFC_REPORT_HANDOVER success for " + v)
  914. @remote_compatible
  915. def test_wpas_ctrl_nfc_tag_read(dev):
  916. """wpa_supplicant ctrl_iface WPS_NFC_TAG_READ"""
  917. vals = [ "FOO", "0Q", "00", "000000", "10000001", "10000000", "00000000",
  918. "100e0000", "100e0001ff", "100e000411110000", "100e0004100e0001" ]
  919. for v in vals:
  920. if "FAIL" not in dev[0].request("WPS_NFC_TAG_READ " + v):
  921. raise Exception("Unexpected WPS_NFC_TAG_READ success for " + v)
  922. @remote_compatible
  923. def test_wpas_ctrl_nfc_get_handover(dev):
  924. """wpa_supplicant ctrl_iface NFC_GET_HANDOVER"""
  925. vals = [ "FOO", "FOO BAR", "WPS WPS", "WPS WPS-CR", "WPS FOO", "NDEF P2P" ]
  926. for v in vals:
  927. if "FAIL" not in dev[0].request("NFC_GET_HANDOVER_REQ " + v):
  928. raise Exception("Unexpected NFC_GET_HANDOVER_REQ success for " + v)
  929. vals = [ "NDEF WPS", "NDEF P2P-CR", "WPS P2P-CR" ]
  930. for v in vals:
  931. if "FAIL" in dev[0].request("NFC_GET_HANDOVER_REQ " + v):
  932. raise Exception("Unexpected NFC_GET_HANDOVER_REQ failure for " + v)
  933. vals = [ "FOO", "FOO BAR", "WPS WPS", "WPS WPS-CR", "WPS FOO", "NDEF P2P",
  934. "NDEF WPS", "NDEF WPS uuid" ]
  935. for v in vals:
  936. if "FAIL" not in dev[0].request("NFC_GET_HANDOVER_SEL " + v):
  937. raise Exception("Unexpected NFC_GET_HANDOVER_SEL success for " + v)
  938. vals = [ "NDEF P2P-CR", "WPS P2P-CR", "NDEF P2P-CR-TAG",
  939. "WPS P2P-CR-TAG" ]
  940. for v in vals:
  941. if "FAIL" in dev[0].request("NFC_GET_HANDOVER_SEL " + v):
  942. raise Exception("Unexpected NFC_GET_HANDOVER_SEL failure for " + v)
  943. def get_blacklist(dev):
  944. return dev.request("BLACKLIST").splitlines()
  945. @remote_compatible
  946. def test_wpas_ctrl_blacklist(dev):
  947. """wpa_supplicant ctrl_iface BLACKLIST"""
  948. if "OK" not in dev[0].request("BLACKLIST clear"):
  949. raise Exception("BLACKLIST clear failed")
  950. b = get_blacklist(dev[0])
  951. if len(b) != 0:
  952. raise Exception("Unexpected blacklist contents: " + str(b))
  953. if "OK" not in dev[0].request("BLACKLIST 00:11:22:33:44:55"):
  954. raise Exception("BLACKLIST add failed")
  955. b = get_blacklist(dev[0])
  956. if "00:11:22:33:44:55" not in b:
  957. raise Exception("Unexpected blacklist contents: " + str(b))
  958. if "OK" not in dev[0].request("BLACKLIST 00:11:22:33:44:56"):
  959. raise Exception("BLACKLIST add failed")
  960. b = get_blacklist(dev[0])
  961. if "00:11:22:33:44:55" not in b or "00:11:22:33:44:56" not in b:
  962. raise Exception("Unexpected blacklist contents: " + str(b))
  963. if "OK" not in dev[0].request("BLACKLIST 00:11:22:33:44:56"):
  964. raise Exception("BLACKLIST add failed")
  965. b = get_blacklist(dev[0])
  966. if "00:11:22:33:44:55" not in b or "00:11:22:33:44:56" not in b or len(b) != 2:
  967. raise Exception("Unexpected blacklist contents: " + str(b))
  968. if "OK" not in dev[0].request("BLACKLIST clear"):
  969. raise Exception("BLACKLIST clear failed")
  970. if dev[0].request("BLACKLIST") != "":
  971. raise Exception("Unexpected blacklist contents")
  972. @remote_compatible
  973. def test_wpas_ctrl_blacklist_oom(dev):
  974. """wpa_supplicant ctrl_iface BLACKLIST and out-of-memory"""
  975. with alloc_fail(dev[0], 1, "wpa_blacklist_add"):
  976. if "FAIL" not in dev[0].request("BLACKLIST aa:bb:cc:dd:ee:ff"):
  977. raise Exception("Unexpected success with allocation failure")
  978. def test_wpas_ctrl_log_level(dev):
  979. """wpa_supplicant ctrl_iface LOG_LEVEL"""
  980. level = dev[2].request("LOG_LEVEL")
  981. if "Current level: MSGDUMP" not in level:
  982. raise Exception("Unexpected debug level(1): " + level)
  983. if "Timestamp: 1" not in level:
  984. raise Exception("Unexpected timestamp(1): " + level)
  985. if "OK" not in dev[2].request("LOG_LEVEL MSGDUMP 0"):
  986. raise Exception("LOG_LEVEL failed")
  987. level = dev[2].request("LOG_LEVEL")
  988. if "Current level: MSGDUMP" not in level:
  989. raise Exception("Unexpected debug level(2): " + level)
  990. if "Timestamp: 0" not in level:
  991. raise Exception("Unexpected timestamp(2): " + level)
  992. if "OK" not in dev[2].request("LOG_LEVEL MSGDUMP 1"):
  993. raise Exception("LOG_LEVEL failed")
  994. level = dev[2].request("LOG_LEVEL")
  995. if "Current level: MSGDUMP" not in level:
  996. raise Exception("Unexpected debug level(3): " + level)
  997. if "Timestamp: 1" not in level:
  998. raise Exception("Unexpected timestamp(3): " + level)
  999. if "FAIL" not in dev[2].request("LOG_LEVEL FOO"):
  1000. raise Exception("Invalid LOG_LEVEL accepted")
  1001. for lev in [ "EXCESSIVE", "MSGDUMP", "DEBUG", "INFO", "WARNING", "ERROR" ]:
  1002. if "OK" not in dev[2].request("LOG_LEVEL " + lev):
  1003. raise Exception("LOG_LEVEL failed for " + lev)
  1004. level = dev[2].request("LOG_LEVEL")
  1005. if "Current level: " + lev not in level:
  1006. raise Exception("Unexpected debug level: " + level)
  1007. if "OK" not in dev[2].request("LOG_LEVEL MSGDUMP 1"):
  1008. raise Exception("LOG_LEVEL failed")
  1009. level = dev[2].request("LOG_LEVEL")
  1010. if "Current level: MSGDUMP" not in level:
  1011. raise Exception("Unexpected debug level(3): " + level)
  1012. if "Timestamp: 1" not in level:
  1013. raise Exception("Unexpected timestamp(3): " + level)
  1014. @remote_compatible
  1015. def test_wpas_ctrl_enable_disable_network(dev, apdev):
  1016. """wpa_supplicant ctrl_iface ENABLE/DISABLE_NETWORK"""
  1017. params = { "ssid": "test" }
  1018. hostapd.add_ap(apdev[0], params)
  1019. id = dev[0].connect("test", key_mgmt="NONE", scan_freq="2412",
  1020. only_add_network=True)
  1021. if "OK" not in dev[0].request("DISABLE_NETWORK " + str(id)):
  1022. raise Exception("Failed to disable network")
  1023. if "OK" not in dev[0].request("ENABLE_NETWORK " + str(id) + " no-connect"):
  1024. raise Exception("Failed to enable network")
  1025. if "OK" not in dev[0].request("DISABLE_NETWORK all"):
  1026. raise Exception("Failed to disable networks")
  1027. if "OK" not in dev[0].request("ENABLE_NETWORK " + str(id)):
  1028. raise Exception("Failed to enable network")
  1029. dev[0].wait_connected(timeout=10)
  1030. if "OK" not in dev[0].request("DISABLE_NETWORK " + str(id)):
  1031. raise Exception("Failed to disable network")
  1032. dev[0].wait_disconnected(timeout=10)
  1033. time.sleep(0.1)
  1034. if "OK" not in dev[0].request("ENABLE_NETWORK all"):
  1035. raise Exception("Failed to enable network")
  1036. dev[0].wait_connected(timeout=10)
  1037. if "OK" not in dev[0].request("DISABLE_NETWORK all"):
  1038. raise Exception("Failed to disable network")
  1039. dev[0].wait_disconnected(timeout=10)
  1040. def test_wpas_ctrl_country(dev, apdev):
  1041. """wpa_supplicant SET/GET country code"""
  1042. try:
  1043. # work around issues with possible pending regdom event from the end of
  1044. # the previous test case
  1045. time.sleep(0.2)
  1046. dev[0].dump_monitor()
  1047. if "OK" not in dev[0].request("SET country FI"):
  1048. raise Exception("Failed to set country code")
  1049. if dev[0].request("GET country") != "FI":
  1050. raise Exception("Country code set failed")
  1051. ev = dev[0].wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"], 10)
  1052. if ev is None:
  1053. raise Exception("regdom change event not seen")
  1054. if "init=USER type=COUNTRY alpha2=FI" not in ev:
  1055. raise Exception("Unexpected event contents: " + ev)
  1056. dev[0].request("SET country 00")
  1057. if dev[0].request("GET country") != "00":
  1058. raise Exception("Country code set failed")
  1059. ev = dev[0].wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"], 10)
  1060. if ev is None:
  1061. raise Exception("regdom change event not seen")
  1062. # init=CORE was previously used due to invalid db.txt data for 00. For
  1063. # now, allow both it and the new init=USER after fixed db.txt.
  1064. if "init=CORE type=WORLD" not in ev and "init=USER type=WORLD" not in ev:
  1065. raise Exception("Unexpected event contents: " + ev)
  1066. finally:
  1067. subprocess.call(['iw', 'reg', 'set', '00'])
  1068. def test_wpas_ctrl_suspend_resume(dev):
  1069. """wpa_supplicant SUSPEND/RESUME"""
  1070. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1071. wpas.interface_add("wlan5")
  1072. if "OK" not in wpas.global_request("SUSPEND"):
  1073. raise Exception("SUSPEND failed")
  1074. time.sleep(1)
  1075. if "OK" not in wpas.global_request("RESUME"):
  1076. raise Exception("RESUME failed")
  1077. if "OK" not in wpas.request("SUSPEND"):
  1078. raise Exception("Per-interface SUSPEND failed")
  1079. if "OK" not in wpas.request("RESUME"):
  1080. raise Exception("Per-interface RESUME failed")
  1081. ev = wpas.wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
  1082. if ev is None:
  1083. raise Exception("Scan not completed")
  1084. def test_wpas_ctrl_global(dev):
  1085. """wpa_supplicant global control interface"""
  1086. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1087. wpas.interface_add("wlan5")
  1088. if "PONG" not in wpas.global_request("PING"):
  1089. raise Exception("PING failed")
  1090. if "wlan5" not in wpas.global_request("INTERFACES"):
  1091. raise Exception("Interface not found")
  1092. if "UNKNOWN COMMAND" not in wpas.global_request("FOO"):
  1093. raise Exception("Unexpected response to unknown command")
  1094. if "PONG" not in wpas.global_request("IFNAME=wlan5 PING"):
  1095. raise Exception("Per-interface PING failed")
  1096. if "FAIL-NO-IFNAME-MATCH" not in wpas.global_request("IFNAME=notfound PING"):
  1097. raise Exception("Unknown interface not reported correctly")
  1098. if "FAIL" not in wpas.global_request("SAVE_CONFIG"):
  1099. raise Exception("SAVE_CONFIG succeeded unexpectedly")
  1100. if "OK" not in wpas.global_request("SET wifi_display 0"):
  1101. raise Exception("SET failed")
  1102. if "wifi_display=0" not in wpas.global_request("STATUS"):
  1103. raise Exception("wifi_display not disabled")
  1104. if "OK" not in wpas.global_request("SET wifi_display 1"):
  1105. raise Exception("SET failed")
  1106. if "wifi_display=1" not in wpas.global_request("STATUS"):
  1107. raise Exception("wifi_display not enabled")
  1108. if "FAIL" not in wpas.global_request("SET foo 1"):
  1109. raise Exception("SET succeeded unexpectedly")
  1110. if "p2p_state=IDLE" not in wpas.global_request("STATUS"):
  1111. raise Exception("P2P was disabled")
  1112. wpas.global_request("P2P_SET disabled 1")
  1113. if "p2p_state=DISABLED" not in wpas.global_request("STATUS"):
  1114. raise Exception("P2P was not disabled")
  1115. wpas.global_request("P2P_SET disabled 0")
  1116. if "p2p_state=IDLE" not in wpas.global_request("STATUS"):
  1117. raise Exception("P2P was not enabled")
  1118. # driver_nl80211.c does not support interface list, so do not fail because
  1119. # of that
  1120. logger.debug(wpas.global_request("INTERFACE_LIST"))
  1121. if "FAIL" not in wpas.global_request("INTERFACE_ADD "):
  1122. raise Exception("INTERFACE_ADD succeeded unexpectedly")
  1123. if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO"):
  1124. raise Exception("INTERFACE_ADD succeeded unexpectedly")
  1125. if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf"):
  1126. raise Exception("INTERFACE_ADD succeeded unexpectedly")
  1127. if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver"):
  1128. raise Exception("INTERFACE_ADD succeeded unexpectedly")
  1129. if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface"):
  1130. raise Exception("INTERFACE_ADD succeeded unexpectedly")
  1131. if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface driverparam"):
  1132. raise Exception("INTERFACE_ADD succeeded unexpectedly")
  1133. if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface driverparam bridge"):
  1134. raise Exception("INTERFACE_ADD succeeded unexpectedly")
  1135. if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface driverparam bridge foo"):
  1136. raise Exception("INTERFACE_ADD succeeded unexpectedly")
  1137. if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO "):
  1138. raise Exception("INTERFACE_ADD succeeded unexpectedly")
  1139. if "FAIL" not in wpas.global_request("INTERFACE_ADD FOO conf driver ctrliface driverparam bridge create abcd"):
  1140. raise Exception("INTERFACE_ADD succeeded unexpectedly")
  1141. @remote_compatible
  1142. def test_wpas_ctrl_roam(dev, apdev):
  1143. """wpa_supplicant ctrl_iface ROAM error cases"""
  1144. if "FAIL" not in dev[0].request("ROAM 00:11:22:33:44"):
  1145. raise Exception("Unexpected success")
  1146. if "FAIL" not in dev[0].request("ROAM 00:11:22:33:44:55"):
  1147. raise Exception("Unexpected success")
  1148. params = { "ssid": "test" }
  1149. hostapd.add_ap(apdev[0], params)
  1150. id = dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
  1151. if "FAIL" not in dev[0].request("ROAM 00:11:22:33:44:55"):
  1152. raise Exception("Unexpected success")
  1153. @remote_compatible
  1154. def test_wpas_ctrl_ipaddr(dev, apdev):
  1155. """wpa_supplicant IP address in STATUS"""
  1156. try:
  1157. dev[0].cmd_execute(['ip', 'addr', 'add', '10.174.65.207/32', 'dev',
  1158. dev[0].ifname])
  1159. ipaddr = dev[0].get_status_field('ip_address')
  1160. if ipaddr != '10.174.65.207':
  1161. raise Exception("IP address not in STATUS output")
  1162. finally:
  1163. dev[0].cmd_execute(['ip', 'addr', 'del', '10.174.65.207/32', 'dev',
  1164. dev[0].ifname])
  1165. @remote_compatible
  1166. def test_wpas_ctrl_rsp(dev, apdev):
  1167. """wpa_supplicant ctrl_iface CTRL-RSP-"""
  1168. if "FAIL" not in dev[0].request("CTRL-RSP-"):
  1169. raise Exception("Request succeeded unexpectedly")
  1170. if "FAIL" not in dev[0].request("CTRL-RSP-foo-"):
  1171. raise Exception("Request succeeded unexpectedly")
  1172. if "FAIL" not in dev[0].request("CTRL-RSP-foo-1234567"):
  1173. raise Exception("Request succeeded unexpectedly")
  1174. if "FAIL" not in dev[0].request("CTRL-RSP-foo-1234567:"):
  1175. raise Exception("Request succeeded unexpectedly")
  1176. id = dev[0].add_network()
  1177. if "FAIL" not in dev[0].request("CTRL-RSP-foo-%d:" % id):
  1178. raise Exception("Request succeeded unexpectedly")
  1179. for req in [ "IDENTITY", "PASSWORD", "NEW_PASSWORD", "PIN", "OTP",
  1180. "PASSPHRASE", "SIM" ]:
  1181. if "OK" not in dev[0].request("CTRL-RSP-%s-%d:" % (req, id)):
  1182. raise Exception("Request failed unexpectedly")
  1183. if "OK" not in dev[0].request("CTRL-RSP-%s-%d:" % (req, id)):
  1184. raise Exception("Request failed unexpectedly")
  1185. @remote_compatible
  1186. def test_wpas_ctrl_vendor(dev, apdev):
  1187. """wpa_supplicant ctrl_iface VENDOR"""
  1188. cmds = [ "foo",
  1189. "1",
  1190. "1 foo",
  1191. "1 2foo",
  1192. "1 2 qq" ]
  1193. for cmd in cmds:
  1194. if "FAIL" not in dev[0].request("VENDOR " + cmd):
  1195. raise Exception("Invalid VENDOR command accepted: " + cmd)
  1196. @remote_compatible
  1197. def test_wpas_ctrl_mgmt_tx(dev, apdev):
  1198. """wpa_supplicant ctrl_iface MGMT_TX"""
  1199. cmds = [ "foo",
  1200. "00:11:22:33:44:55 foo",
  1201. "00:11:22:33:44:55 11:22:33:44:55:66",
  1202. "00:11:22:33:44:55 11:22:33:44:55:66 freq=0 no_cck=0 wait_time=0 action=123",
  1203. "00:11:22:33:44:55 11:22:33:44:55:66 action=12qq" ]
  1204. for cmd in cmds:
  1205. if "FAIL" not in dev[0].request("MGMT_TX " + cmd):
  1206. raise Exception("Invalid MGMT_TX command accepted: " + cmd)
  1207. if "OK" not in dev[0].request("MGMT_TX_DONE"):
  1208. raise Exception("MGMT_TX_DONE failed")
  1209. @remote_compatible
  1210. def test_wpas_ctrl_driver_event(dev, apdev):
  1211. """wpa_supplicant ctrl_iface DRIVER_EVENT"""
  1212. if "FAIL" not in dev[0].request("DRIVER_EVENT foo"):
  1213. raise Exception("Invalid DRIVER_EVENT accepted")
  1214. @remote_compatible
  1215. def test_wpas_ctrl_eapol_rx(dev, apdev):
  1216. """wpa_supplicant ctrl_iface EAPOL_RX"""
  1217. cmds = [ "foo",
  1218. "00:11:22:33:44:55 123",
  1219. "00:11:22:33:44:55 12qq" ]
  1220. for cmd in cmds:
  1221. if "FAIL" not in dev[0].request("EAPOL_RX " + cmd):
  1222. raise Exception("Invalid EAPOL_RX command accepted: " + cmd)
  1223. @remote_compatible
  1224. def test_wpas_ctrl_data_test(dev, apdev):
  1225. """wpa_supplicant ctrl_iface DATA_TEST"""
  1226. dev[0].request("DATA_TEST_CONFIG 0")
  1227. if "FAIL" not in dev[0].request("DATA_TEST_TX 00:11:22:33:44:55 00:11:22:33:44:55 0"):
  1228. raise Exception("DATA_TEST_TX accepted when not in test mode")
  1229. try:
  1230. if "OK" not in dev[0].request("DATA_TEST_CONFIG 1"):
  1231. raise Exception("DATA_TEST_CONFIG failed")
  1232. if "OK" not in dev[0].request("DATA_TEST_CONFIG 1"):
  1233. raise Exception("DATA_TEST_CONFIG failed")
  1234. cmds = [ "foo",
  1235. "00:11:22:33:44:55 foo",
  1236. "00:11:22:33:44:55 00:11:22:33:44:55 -1",
  1237. "00:11:22:33:44:55 00:11:22:33:44:55 256" ]
  1238. for cmd in cmds:
  1239. if "FAIL" not in dev[0].request("DATA_TEST_TX " + cmd):
  1240. raise Exception("Invalid DATA_TEST_TX command accepted: " + cmd)
  1241. if "OK" not in dev[0].request("DATA_TEST_TX 00:11:22:33:44:55 00:11:22:33:44:55 0"):
  1242. raise Exception("DATA_TEST_TX failed")
  1243. finally:
  1244. dev[0].request("DATA_TEST_CONFIG 0")
  1245. cmds = [ "",
  1246. "00",
  1247. "00112233445566778899aabbccdde",
  1248. "00112233445566778899aabbccdq" ]
  1249. for cmd in cmds:
  1250. if "FAIL" not in dev[0].request("DATA_TEST_FRAME " + cmd):
  1251. raise Exception("Invalid DATA_TEST_FRAME command accepted: " + cmd)
  1252. if "OK" not in dev[0].request("DATA_TEST_FRAME 00112233445566778899aabbccddee"):
  1253. raise Exception("DATA_TEST_FRAME failed")
  1254. @remote_compatible
  1255. def test_wpas_ctrl_vendor_elem(dev, apdev):
  1256. """wpa_supplicant ctrl_iface VENDOR_ELEM"""
  1257. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 1 "):
  1258. raise Exception("VENDOR_ELEM_ADD failed")
  1259. cmds = [ "-1 ",
  1260. "255 ",
  1261. "1",
  1262. "1 123",
  1263. "1 12qq34" ]
  1264. for cmd in cmds:
  1265. if "FAIL" not in dev[0].request("VENDOR_ELEM_ADD " + cmd):
  1266. raise Exception("Invalid VENDOR_ELEM_ADD command accepted: " + cmd)
  1267. cmds = [ "-1 ",
  1268. "255 " ]
  1269. for cmd in cmds:
  1270. if "FAIL" not in dev[0].request("VENDOR_ELEM_GET " + cmd):
  1271. raise Exception("Invalid VENDOR_ELEM_GET command accepted: " + cmd)
  1272. dev[0].request("VENDOR_ELEM_REMOVE 1 *")
  1273. cmds = [ "-1 ",
  1274. "255 ",
  1275. "1",
  1276. "1",
  1277. "1 123",
  1278. "1 12qq34",
  1279. "1 12",
  1280. "1 0000" ]
  1281. for cmd in cmds:
  1282. if "FAIL" not in dev[0].request("VENDOR_ELEM_REMOVE " + cmd):
  1283. raise Exception("Invalid VENDOR_ELEM_REMOVE command accepted: " + cmd)
  1284. dev[0].request("VENDOR_ELEM_ADD 1 000100")
  1285. if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 "):
  1286. raise Exception("VENDOR_ELEM_REMOVE failed")
  1287. cmds = [ "-1 ",
  1288. "255 ",
  1289. "1",
  1290. "1 123",
  1291. "1 12qq34",
  1292. "1 12",
  1293. "1 0000" ]
  1294. for cmd in cmds:
  1295. if "FAIL" not in dev[0].request("VENDOR_ELEM_REMOVE " + cmd):
  1296. raise Exception("Invalid VENDOR_ELEM_REMOVE command accepted: " + cmd)
  1297. if "OK" not in dev[0].request("VENDOR_ELEM_REMOVE 1 000100"):
  1298. raise Exception("VENDOR_ELEM_REMOVE failed")
  1299. def test_wpas_ctrl_misc(dev, apdev):
  1300. """wpa_supplicant ctrl_iface and miscellaneous commands"""
  1301. if "OK" not in dev[0].request("RELOG"):
  1302. raise Exception("RELOG failed")
  1303. if dev[0].request("IFNAME") != dev[0].ifname:
  1304. raise Exception("IFNAME returned unexpected response")
  1305. if "FAIL" not in dev[0].request("REATTACH"):
  1306. raise Exception("REATTACH accepted while disabled")
  1307. if "OK" not in dev[2].request("RECONFIGURE"):
  1308. raise Exception("RECONFIGURE failed")
  1309. if "FAIL" in dev[0].request("INTERFACE_LIST"):
  1310. raise Exception("INTERFACE_LIST failed")
  1311. if "UNKNOWN COMMAND" not in dev[0].request("FOO"):
  1312. raise Exception("Unknown command accepted")
  1313. if "FAIL" not in dev[0].global_request("INTERFACE_REMOVE foo"):
  1314. raise Exception("Invalid INTERFACE_REMOVE accepted")
  1315. if "FAIL" not in dev[0].global_request("SET foo"):
  1316. raise Exception("Invalid global SET accepted")
  1317. @remote_compatible
  1318. def test_wpas_ctrl_dump(dev, apdev):
  1319. """wpa_supplicant ctrl_iface and DUMP/GET global parameters"""
  1320. vals = dev[0].get_config()
  1321. logger.info("Config values from DUMP: " + str(vals))
  1322. for field in vals:
  1323. res = dev[0].request("GET " + field)
  1324. if res == 'FAIL\n':
  1325. res = "null"
  1326. if res != vals[field]:
  1327. print "'{}' != '{}'".format(res, vals[field])
  1328. raise Exception("Mismatch in config field " + field)
  1329. if "beacon_int" not in vals:
  1330. raise Exception("Missing config field")
  1331. def test_wpas_ctrl_interface_add(dev, apdev):
  1332. """wpa_supplicant INTERFACE_ADD/REMOVE with vif creation/removal"""
  1333. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  1334. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  1335. hwsim_utils.test_connectivity(dev[0], hapd)
  1336. ifname = "test-" + dev[0].ifname
  1337. dev[0].interface_add(ifname, create=True)
  1338. wpas = WpaSupplicant(ifname=ifname)
  1339. wpas.connect("open", key_mgmt="NONE", scan_freq="2412")
  1340. hwsim_utils.test_connectivity(wpas, hapd)
  1341. hwsim_utils.test_connectivity(dev[0], hapd)
  1342. dev[0].global_request("INTERFACE_REMOVE " + ifname)
  1343. hwsim_utils.test_connectivity(dev[0], hapd)
  1344. def test_wpas_ctrl_interface_add_sta(dev, apdev):
  1345. """wpa_supplicant INTERFACE_ADD/REMOVE with STA vif creation/removal"""
  1346. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  1347. ifname = "test-" + dev[0].ifname
  1348. dev[0].interface_add(ifname, create=True, if_type='sta')
  1349. wpas = WpaSupplicant(ifname=ifname)
  1350. wpas.connect("open", key_mgmt="NONE", scan_freq="2412")
  1351. wpas.request("DISCONNECT")
  1352. wpas.wait_disconnected()
  1353. dev[0].global_request("INTERFACE_REMOVE " + ifname)
  1354. def test_wpas_ctrl_interface_add_ap(dev, apdev):
  1355. """wpa_supplicant INTERFACE_ADD/REMOVE AP interface"""
  1356. with HWSimRadio() as (radio, iface):
  1357. wpas0 = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1358. wpas0.interface_add(iface)
  1359. ifname = "test-wpas-ap"
  1360. wpas0.interface_add(ifname, create=True, if_type='ap')
  1361. wpas = WpaSupplicant(ifname=ifname)
  1362. id = wpas.add_network()
  1363. wpas.set_network(id, "mode", "2")
  1364. wpas.set_network_quoted(id, "ssid", "wpas-ap-open")
  1365. wpas.set_network(id, "key_mgmt", "NONE")
  1366. wpas.set_network(id, "frequency", "2412")
  1367. wpas.set_network(id, "scan_freq", "2412")
  1368. wpas.select_network(id)
  1369. wait_ap_ready(wpas)
  1370. dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
  1371. dev[2].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
  1372. hwsim_utils.test_connectivity(wpas, dev[1])
  1373. hwsim_utils.test_connectivity(dev[1], dev[2])
  1374. dev[1].request("DISCONNECT")
  1375. dev[2].request("DISCONNECT")
  1376. dev[1].wait_disconnected()
  1377. dev[2].wait_disconnected()
  1378. wpas0.global_request("INTERFACE_REMOVE " + ifname)
  1379. def test_wpas_ctrl_interface_add_many(dev, apdev):
  1380. """wpa_supplicant INTERFACE_ADD/REMOVE with vif creation/removal (many)"""
  1381. try:
  1382. _test_wpas_ctrl_interface_add_many(dev, apdev)
  1383. finally:
  1384. for i in range(10):
  1385. ifname = "test%d-" % i + dev[0].ifname
  1386. dev[0].global_request("INTERFACE_REMOVE " + ifname)
  1387. def _test_wpas_ctrl_interface_add_many(dev, apdev):
  1388. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  1389. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  1390. hwsim_utils.test_connectivity(dev[0], hapd)
  1391. dev[0].dump_monitor()
  1392. l = []
  1393. for i in range(10):
  1394. ifname = "test%d-" % i + dev[0].ifname
  1395. dev[0].interface_add(ifname, create=True)
  1396. wpas = WpaSupplicant(ifname=ifname)
  1397. wpas.connect("open", key_mgmt="NONE", scan_freq="2412")
  1398. wpas.dump_monitor()
  1399. l.append(wpas)
  1400. dev[0].dump_monitor()
  1401. for wpas in l:
  1402. wpas.dump_monitor()
  1403. hwsim_utils.test_connectivity(wpas, hapd)
  1404. wpas.dump_monitor()
  1405. dev[0].dump_monitor()
  1406. def test_wpas_ctrl_interface_add2(dev, apdev):
  1407. """wpa_supplicant INTERFACE_ADD/REMOVE with vif without creation/removal"""
  1408. ifname = "test-ext-" + dev[0].ifname
  1409. try:
  1410. _test_wpas_ctrl_interface_add2(dev, apdev, ifname)
  1411. finally:
  1412. subprocess.call(['iw', 'dev', ifname, 'del'])
  1413. def _test_wpas_ctrl_interface_add2(dev, apdev, ifname):
  1414. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  1415. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  1416. hwsim_utils.test_connectivity(dev[0], hapd)
  1417. subprocess.call(['iw', 'dev', dev[0].ifname, 'interface', 'add', ifname,
  1418. 'type', 'station'])
  1419. subprocess.call(['ip', 'link', 'set', 'dev', ifname, 'address',
  1420. '02:01:00:00:02:01'])
  1421. dev[0].interface_add(ifname, set_ifname=False, all_params=True)
  1422. wpas = WpaSupplicant(ifname=ifname)
  1423. wpas.connect("open", key_mgmt="NONE", scan_freq="2412")
  1424. hwsim_utils.test_connectivity(wpas, hapd)
  1425. hwsim_utils.test_connectivity(dev[0], hapd)
  1426. del wpas
  1427. dev[0].global_request("INTERFACE_REMOVE " + ifname)
  1428. hwsim_utils.test_connectivity(dev[0], hapd)
  1429. def test_wpas_ctrl_wait(dev, apdev, test_params):
  1430. """wpa_supplicant control interface wait for client"""
  1431. logfile = os.path.join(test_params['logdir'], 'wpas_ctrl_wait.log-wpas')
  1432. pidfile = os.path.join(test_params['logdir'], 'wpas_ctrl_wait.pid-wpas')
  1433. conffile = os.path.join(test_params['logdir'], 'wpas_ctrl_wait.conf')
  1434. with open(conffile, 'w') as f:
  1435. f.write("ctrl_interface=DIR=/var/run/wpa_supplicant\n")
  1436. prg = os.path.join(test_params['logdir'],
  1437. 'alt-wpa_supplicant/wpa_supplicant/wpa_supplicant')
  1438. if not os.path.exists(prg):
  1439. prg = '../../wpa_supplicant/wpa_supplicant'
  1440. arg = [ prg ]
  1441. cmd = subprocess.Popen(arg, stdout=subprocess.PIPE)
  1442. out = cmd.communicate()[0]
  1443. cmd.wait()
  1444. tracing = "Linux tracing" in out
  1445. with HWSimRadio() as (radio, iface):
  1446. arg = [ prg, '-BdddW', '-P', pidfile, '-f', logfile,
  1447. '-Dnl80211', '-c', conffile, '-i', iface ]
  1448. if tracing:
  1449. arg += [ '-T' ]
  1450. logger.info("Start wpa_supplicant: " + str(arg))
  1451. subprocess.call(arg)
  1452. wpas = WpaSupplicant(ifname=iface)
  1453. if "PONG" not in wpas.request("PING"):
  1454. raise Exception("Could not PING wpa_supplicant")
  1455. if not os.path.exists(pidfile):
  1456. raise Exception("PID file not created")
  1457. if "OK" not in wpas.request("TERMINATE"):
  1458. raise Exception("Could not TERMINATE")
  1459. ev = wpas.wait_event([ "CTRL-EVENT-TERMINATING" ], timeout=2)
  1460. if ev is None:
  1461. raise Exception("No termination event received")
  1462. for i in range(20):
  1463. if not os.path.exists(pidfile):
  1464. break
  1465. time.sleep(0.1)
  1466. if os.path.exists(pidfile):
  1467. raise Exception("PID file not removed")
  1468. @remote_compatible
  1469. def test_wpas_ctrl_oom(dev):
  1470. """Various wpa_supplicant ctrl_iface OOM cases"""
  1471. try:
  1472. _test_wpas_ctrl_oom(dev)
  1473. finally:
  1474. dev[0].request("VENDOR_ELEM_REMOVE 1 *")
  1475. dev[0].request("VENDOR_ELEM_REMOVE 2 *")
  1476. dev[0].request("SET bssid_filter ")
  1477. def _test_wpas_ctrl_oom(dev):
  1478. dev[0].request('VENDOR_ELEM_ADD 2 000100')
  1479. tests = [ ('DRIVER_EVENT AVOID_FREQUENCIES 2412', 'FAIL',
  1480. 1, 'freq_range_list_parse'),
  1481. ('P2P_SET disallow_freq 2412', 'FAIL',
  1482. 1, 'freq_range_list_parse'),
  1483. ('SCAN freq=2412', 'FAIL',
  1484. 1, 'freq_range_list_parse'),
  1485. ('INTERWORKING_SELECT freq=2412', 'FAIL',
  1486. 1, 'freq_range_list_parse'),
  1487. ('SCAN ssid 112233', 'FAIL',
  1488. 1, 'wpas_ctrl_scan'),
  1489. ('MGMT_TX 00:00:00:00:00:00 00:00:00:00:00:00 action=00', 'FAIL',
  1490. 1, 'wpas_ctrl_iface_mgmt_tx'),
  1491. ('EAPOL_RX 00:00:00:00:00:00 00', 'FAIL',
  1492. 1, 'wpas_ctrl_iface_eapol_rx'),
  1493. ('DATA_TEST_FRAME 00112233445566778899aabbccddee', 'FAIL',
  1494. 1, 'wpas_ctrl_iface_data_test_frame'),
  1495. ('DATA_TEST_FRAME 00112233445566778899aabbccddee', 'FAIL',
  1496. 1, 'l2_packet_init;wpas_ctrl_iface_data_test_frame'),
  1497. ('VENDOR_ELEM_ADD 1 000100', 'FAIL',
  1498. 1, 'wpas_ctrl_vendor_elem_add'),
  1499. ('VENDOR_ELEM_ADD 2 000100', 'FAIL',
  1500. 2, 'wpas_ctrl_vendor_elem_add'),
  1501. ('VENDOR_ELEM_REMOVE 2 000100', 'FAIL',
  1502. 1, 'wpas_ctrl_vendor_elem_remove'),
  1503. ('SET bssid_filter 00:11:22:33:44:55', 'FAIL',
  1504. 1, 'set_bssid_filter'),
  1505. ('SET disallow_aps bssid 00:11:22:33:44:55', 'FAIL',
  1506. 1, 'set_disallow_aps'),
  1507. ('SET disallow_aps ssid 11', 'FAIL',
  1508. 1, 'set_disallow_aps'),
  1509. ('SET blob foo 0011', 'FAIL',
  1510. 1, 'wpas_ctrl_set_blob'),
  1511. ('SET blob foo 0011', 'FAIL',
  1512. 2, 'wpas_ctrl_set_blob'),
  1513. ('SET blob foo 0011', 'FAIL',
  1514. 3, 'wpas_ctrl_set_blob'),
  1515. ('WPS_NFC_TAG_READ 00', 'FAIL',
  1516. 1, 'wpa_supplicant_ctrl_iface_wps_nfc_tag_read'),
  1517. ('WPS_NFC_TOKEN NDEF', 'FAIL',
  1518. 1, 'wpa_supplicant_ctrl_iface_wps_nfc_token'),
  1519. ('WPS_NFC_TOKEN NDEF', 'FAIL',
  1520. 2, 'wpa_supplicant_ctrl_iface_wps_nfc_token'),
  1521. ('WPS_NFC_TOKEN NDEF', 'FAIL',
  1522. 3, 'wpa_supplicant_ctrl_iface_wps_nfc_token'),
  1523. ('WPS_NFC_TOKEN NDEF', 'FAIL',
  1524. 4, 'wpa_supplicant_ctrl_iface_wps_nfc_token'),
  1525. ('NFC_REPORT_HANDOVER ROLE TYPE 00 00', 'FAIL',
  1526. 1, 'wpas_ctrl_nfc_report_handover'),
  1527. ('NFC_REPORT_HANDOVER ROLE TYPE 00 00', 'FAIL',
  1528. 2, 'wpas_ctrl_nfc_report_handover'),
  1529. ('NFC_GET_HANDOVER_REQ NDEF WPS-CR', 'FAIL',
  1530. 1, 'wps_build_nfc_handover_req'),
  1531. ('NFC_GET_HANDOVER_REQ NDEF WPS-CR', 'FAIL',
  1532. 1, 'ndef_build_record'),
  1533. ('NFC_GET_HANDOVER_REQ NDEF P2P-CR', None,
  1534. 1, 'wpas_p2p_nfc_handover'),
  1535. ('NFC_GET_HANDOVER_REQ NDEF P2P-CR', None,
  1536. 1, 'wps_build_nfc_handover_req_p2p'),
  1537. ('NFC_GET_HANDOVER_REQ NDEF P2P-CR', 'FAIL',
  1538. 1, 'ndef_build_record'),
  1539. ('NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG', None,
  1540. 1, 'wpas_ctrl_nfc_get_handover_sel_p2p'),
  1541. ('NFC_GET_HANDOVER_SEL NDEF P2P-CR', None,
  1542. 1, 'wpas_ctrl_nfc_get_handover_sel_p2p'),
  1543. ('P2P_ASP_PROVISION_RESP 00:11:22:33:44:55 id=1', 'FAIL',
  1544. 1, 'p2p_parse_asp_provision_cmd'),
  1545. ('P2P_SERV_DISC_REQ 00:11:22:33:44:55 02000001', 'FAIL',
  1546. 1, 'p2p_ctrl_serv_disc_req'),
  1547. ('P2P_SERV_DISC_RESP 2412 00:11:22:33:44:55 1 00', 'FAIL',
  1548. 1, 'p2p_ctrl_serv_disc_resp'),
  1549. ('P2P_SERVICE_ADD bonjour 0b5f6166706f766572746370c00c000c01 074578616d706c65c027',
  1550. 'FAIL',
  1551. 1, 'p2p_ctrl_service_add_bonjour'),
  1552. ('P2P_SERVICE_ADD bonjour 0b5f6166706f766572746370c00c000c01 074578616d706c65c027',
  1553. 'FAIL',
  1554. 2, 'p2p_ctrl_service_add_bonjour'),
  1555. ('P2P_SERVICE_ADD bonjour 0b5f6166706f766572746370c00c000c01 074578616d706c65c027',
  1556. 'FAIL',
  1557. 3, 'p2p_ctrl_service_add_bonjour'),
  1558. ('P2P_SERVICE_DEL bonjour 0b5f6166706f766572746370c00c000c01',
  1559. 'FAIL',
  1560. 1, 'p2p_ctrl_service_del_bonjour'),
  1561. ('GAS_REQUEST 00:11:22:33:44:55 00', 'FAIL',
  1562. 1, 'gas_request'),
  1563. ('GAS_REQUEST 00:11:22:33:44:55 00 11', 'FAIL',
  1564. 2, 'gas_request'),
  1565. ('HS20_GET_NAI_HOME_REALM_LIST 00:11:22:33:44:55 realm=example.com',
  1566. 'FAIL',
  1567. 1, 'hs20_nai_home_realm_list'),
  1568. ('HS20_GET_NAI_HOME_REALM_LIST 00:11:22:33:44:55 00',
  1569. 'FAIL',
  1570. 1, 'hs20_get_nai_home_realm_list'),
  1571. ('WNM_SLEEP enter tfs_req=11', 'FAIL',
  1572. 1, 'wpas_ctrl_iface_wnm_sleep'),
  1573. ('WNM_SLEEP enter tfs_req=11', 'FAIL',
  1574. 2, 'wpas_ctrl_iface_wnm_sleep'),
  1575. ('WNM_SLEEP enter tfs_req=11', 'FAIL',
  1576. 3, 'wpas_ctrl_iface_wnm_sleep'),
  1577. ('WNM_SLEEP enter tfs_req=11', 'FAIL',
  1578. 4, 'wpas_ctrl_iface_wnm_sleep'),
  1579. ('WNM_SLEEP enter tfs_req=11', 'FAIL',
  1580. 5, 'wpas_ctrl_iface_wnm_sleep'),
  1581. ('WNM_SLEEP enter', 'FAIL',
  1582. 3, 'wpas_ctrl_iface_wnm_sleep'),
  1583. ('VENDOR 1 1 00', 'FAIL',
  1584. 1, 'wpa_supplicant_vendor_cmd'),
  1585. ('VENDOR 1 1 00', 'FAIL',
  1586. 2, 'wpa_supplicant_vendor_cmd'),
  1587. ('RADIO_WORK add test', 'FAIL',
  1588. 1, 'wpas_ctrl_radio_work_add'),
  1589. ('RADIO_WORK add test', 'FAIL',
  1590. 2, 'wpas_ctrl_radio_work_add'),
  1591. ('AUTOSCAN periodic:1', 'FAIL',
  1592. 1, 'wpa_supplicant_ctrl_iface_autoscan'),
  1593. ('PING', None,
  1594. 1, 'wpa_supplicant_ctrl_iface_process') ]
  1595. tls = dev[0].request("GET tls_library")
  1596. if not tls.startswith("internal"):
  1597. tests.append(('NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG', 'FAIL',
  1598. 4, 'wpas_ctrl_nfc_get_handover_sel_p2p'))
  1599. for cmd,exp,count,func in tests:
  1600. with alloc_fail(dev[0], count, func):
  1601. res = dev[0].request(cmd)
  1602. if exp and exp not in res:
  1603. raise Exception("Unexpected success for '%s' during OOM (%d:%s)" % (cmd, count, func))
  1604. tests = [ ('FOO', None,
  1605. 1, 'wpa_supplicant_global_ctrl_iface_process'),
  1606. ('IFNAME=notfound PING', 'FAIL\n',
  1607. 1, 'wpas_global_ctrl_iface_ifname') ]
  1608. for cmd,exp,count,func in tests:
  1609. with alloc_fail(dev[0], count, func):
  1610. res = dev[0].global_request(cmd)
  1611. if exp and exp not in res:
  1612. raise Exception("Unexpected success for '%s' during OOM" % cmd)
  1613. @remote_compatible
  1614. def test_wpas_ctrl_error(dev):
  1615. """Various wpa_supplicant ctrl_iface error cases"""
  1616. tests = [ ('WPS_NFC_TOKEN NDEF', 'FAIL',
  1617. 1, 'wpa_supplicant_ctrl_iface_wps_nfc_token'),
  1618. ('WPS_NFC_TOKEN NDEF', 'FAIL',
  1619. 2, 'wpa_supplicant_ctrl_iface_wps_nfc_token'),
  1620. ('NFC_GET_HANDOVER_REQ NDEF P2P-CR', None,
  1621. 1, 'wpas_p2p_nfc_handover'),
  1622. ('NFC_GET_HANDOVER_REQ NDEF P2P-CR', None,
  1623. 1, 'wps_build_nfc_handover_req_p2p') ]
  1624. for cmd,exp,count,func in tests:
  1625. with fail_test(dev[0], count, func):
  1626. res = dev[0].request(cmd)
  1627. if exp and exp not in res:
  1628. raise Exception("Unexpected success for '%s' during failure testing (%d:%s)" % (cmd, count, func))
  1629. def test_wpas_ctrl_socket_full(dev, apdev, test_params):
  1630. """wpa_supplicant control socket and full send buffer"""
  1631. if not dev[0].ping():
  1632. raise Exception("Could not ping wpa_supplicant at the beginning of the test")
  1633. dev[0].get_status()
  1634. counter = 0
  1635. s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
  1636. local = "/tmp/wpa_ctrl_test_%d-%d" % (os.getpid(), counter)
  1637. counter += 1
  1638. s.bind(local)
  1639. s.connect("/var/run/wpa_supplicant/wlan0")
  1640. for i in range(20):
  1641. logger.debug("Command %d" % i)
  1642. try:
  1643. s.send("MIB")
  1644. except Exception, e:
  1645. logger.info("Could not send command %d: %s" % (i, str(e)))
  1646. break
  1647. # Close without receiving response
  1648. time.sleep(0.01)
  1649. if not dev[0].ping():
  1650. raise Exception("Could not ping wpa_supplicant in the middle of the test")
  1651. dev[0].get_status()
  1652. s2 = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
  1653. local2 = "/tmp/wpa_ctrl_test_%d-%d" % (os.getpid(), counter)
  1654. counter += 1
  1655. s2.bind(local2)
  1656. s2.connect("/var/run/wpa_supplicant/wlan0")
  1657. for i in range(10):
  1658. logger.debug("Command %d [2]" % i)
  1659. try:
  1660. s2.send("MIB")
  1661. except Exception, e:
  1662. logger.info("Could not send command %d [2]: %s" % (i, str(e)))
  1663. break
  1664. # Close without receiving response
  1665. time.sleep(0.01)
  1666. s.close()
  1667. os.unlink(local)
  1668. for i in range(10):
  1669. logger.debug("Command %d [3]" % i)
  1670. try:
  1671. s2.send("MIB")
  1672. except Exception, e:
  1673. logger.info("Could not send command %d [3]: %s" % (i, str(e)))
  1674. break
  1675. # Close without receiving response
  1676. time.sleep(0.01)
  1677. s2.close()
  1678. os.unlink(local2)
  1679. if not dev[0].ping():
  1680. raise Exception("Could not ping wpa_supplicant in the middle of the test [2]")
  1681. dev[0].get_status()
  1682. s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
  1683. local = "/tmp/wpa_ctrl_test_%d-%d" % (os.getpid(), counter)
  1684. counter += 1
  1685. s.bind(local)
  1686. s.connect("/var/run/wpa_supplicant/wlan0")
  1687. s.send("ATTACH")
  1688. res = s.recv(100)
  1689. if "OK" not in res:
  1690. raise Exception("Could not attach a test socket")
  1691. for i in range(5):
  1692. dev[0].scan(freq=2412)
  1693. s.close()
  1694. os.unlink(local)
  1695. for i in range(5):
  1696. dev[0].scan(freq=2412)
  1697. if not dev[0].ping():
  1698. raise Exception("Could not ping wpa_supplicant at the end of the test")
  1699. dev[0].get_status()
  1700. def test_wpas_ctrl_event_burst(dev, apdev):
  1701. """wpa_supplicant control socket and event burst"""
  1702. if "OK" not in dev[0].request("EVENT_TEST 1000"):
  1703. raise Exception("Could not request event messages")
  1704. total_i = 0
  1705. total_g = 0
  1706. for i in range(100):
  1707. (i,g) = dev[0].dump_monitor()
  1708. total_i += i
  1709. total_g += g
  1710. logger.info("Received i=%d g=%d" % (i, g))
  1711. if total_i >= 1000 and total_g >= 1000:
  1712. break
  1713. time.sleep(0.05)
  1714. if total_i < 1000:
  1715. raise Exception("Some per-interface events not seen: %d" % total_i)
  1716. if total_g < 1000:
  1717. raise Exception("Some global events not seen: %d" % total_g)
  1718. if not dev[0].ping():
  1719. raise Exception("Could not ping wpa_supplicant at the end of the test")
  1720. @remote_compatible
  1721. def test_wpas_ctrl_sched_scan_plans(dev, apdev):
  1722. """wpa_supplicant sched_scan_plans parsing"""
  1723. dev[0].request("SET sched_scan_plans foo")
  1724. dev[0].request("SET sched_scan_plans 10:100 20:200 30")
  1725. dev[0].request("SET sched_scan_plans 4294967295:0")
  1726. dev[0].request("SET sched_scan_plans 1 1")
  1727. dev[0].request("SET sched_scan_plans ")
  1728. try:
  1729. with alloc_fail(dev[0], 1, "wpas_sched_scan_plans_set"):
  1730. dev[0].request("SET sched_scan_plans 10:100")
  1731. finally:
  1732. dev[0].request("SET sched_scan_plans ")
  1733. def test_wpas_ctrl_signal_monitor(dev, apdev):
  1734. """wpa_supplicant SIGNAL_MONITOR command"""
  1735. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  1736. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  1737. dev[1].connect("open", key_mgmt="NONE", scan_freq="2412",
  1738. bgscan="simple:1:-45:2")
  1739. dev[2].connect("open", key_mgmt="NONE", scan_freq="2412")
  1740. tests = [ " THRESHOLD=-45", " THRESHOLD=-44 HYSTERESIS=5", "" ]
  1741. try:
  1742. if "FAIL" in dev[2].request("SIGNAL_MONITOR THRESHOLD=-1 HYSTERESIS=5"):
  1743. raise Exception("SIGNAL_MONITOR command failed")
  1744. for t in tests:
  1745. if "OK" not in dev[0].request("SIGNAL_MONITOR" + t):
  1746. raise Exception("SIGNAL_MONITOR command failed: " + t)
  1747. if "FAIL" not in dev[1].request("SIGNAL_MONITOR THRESHOLD=-44 HYSTERESIS=5"):
  1748. raise Exception("SIGNAL_MONITOR command accepted while using bgscan")
  1749. ev = dev[2].wait_event(["CTRL-EVENT-SIGNAL-CHANGE"], timeout=10)
  1750. if ev is None:
  1751. raise Exception("No signal change event seen")
  1752. if "above=0" not in ev:
  1753. raise Exception("Unexpected signal change event contents: " + ev)
  1754. finally:
  1755. dev[0].request("SIGNAL_MONITOR")
  1756. dev[1].request("SIGNAL_MONITOR")
  1757. dev[2].request("SIGNAL_MONITOR")
  1758. dev[0].request("REMOVE_NETWORK all")
  1759. dev[1].request("REMOVE_NETWORK all")
  1760. dev[1].wait_disconnected()
  1761. def test_wpas_ctrl_p2p_listen_offload(dev, apdev):
  1762. """wpa_supplicant P2P_LO_START and P2P_LO_STOP commands"""
  1763. dev[0].request("P2P_LO_STOP")
  1764. dev[0].request("P2P_LO_START ")
  1765. dev[0].request("P2P_LO_START 2412")
  1766. dev[0].request("P2P_LO_START 2412 100 200 3")
  1767. dev[0].request("P2P_LO_STOP")
  1768. def test_wpas_ctrl_driver_flags(dev, apdev):
  1769. """DRIVER_FLAGS command"""
  1770. params = hostapd.wpa2_params(ssid="test", passphrase="12345678")
  1771. hapd = hostapd.add_ap(apdev[0], params)
  1772. hapd_flags = hapd.request("DRIVER_FLAGS")
  1773. wpas_flags = dev[0].request("DRIVER_FLAGS")
  1774. if "FAIL" in hapd_flags:
  1775. raise Exception("DRIVER_FLAGS failed")
  1776. if hapd_flags != wpas_flags:
  1777. raise Exception("Unexpected difference in hostapd vs. wpa_supplicant DRIVER_FLAGS output")
  1778. logger.info("DRIVER_FLAGS: " + hapd_flags)
  1779. flags = hapd_flags.split('\n')
  1780. if 'AP' not in flags:
  1781. raise Exception("AP flag missing from DRIVER_FLAGS")
  1782. def test_wpas_ctrl_bss_current(dev, apdev):
  1783. """wpa_supplicant BSS CURRENT command"""
  1784. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  1785. bssid = hapd.own_addr()
  1786. res = dev[0].request("BSS CURRENT")
  1787. if res != '':
  1788. raise Exception("Unexpected BSS CURRENT response in disconnected state")
  1789. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  1790. res = dev[0].request("BSS CURRENT")
  1791. if bssid not in res:
  1792. raise Exception("Unexpected BSS CURRENT response in connected state")
  1793. def test_wpas_ctrl_set_lci_errors(dev):
  1794. """wpa_supplicant SET lci error cases"""
  1795. if "FAIL" not in dev[0].request("SET lci q"):
  1796. raise Exception("Invalid LCI value accepted")
  1797. with fail_test(dev[0], 1, "os_get_reltime;wpas_ctrl_iface_set_lci"):
  1798. if "FAIL" not in dev[0].request("SET lci 00"):
  1799. raise Exception("SET lci accepted with failing os_get_reltime")
  1800. def test_wpas_ctrl_set_radio_disabled(dev):
  1801. """wpa_supplicant SET radio_disabled"""
  1802. # This is not currently supported with nl80211, but execute the commands
  1803. # without checking the result for some additional code coverage.
  1804. dev[0].request("SET radio_disabled 1")
  1805. dev[0].request("SET radio_disabled 0")
  1806. def test_wpas_ctrl_set_tdls_trigger_control(dev):
  1807. """wpa_supplicant SET tdls_trigger_control"""
  1808. # This is not supported with upstream nl80211, but execute the commands
  1809. # without checking the result for some additional code coverage.
  1810. dev[0].request("SET tdls_trigger_control 1")
  1811. dev[0].request("SET tdls_trigger_control 0")
  1812. def test_wpas_ctrl_set_sched_scan_relative_rssi(dev):
  1813. """wpa_supplicant SET relative RSSI"""
  1814. tests = [ "relative_rssi -1",
  1815. "relative_rssi 101",
  1816. "relative_band_adjust 2G",
  1817. "relative_band_adjust 2G:-101",
  1818. "relative_band_adjust 2G:101",
  1819. "relative_band_adjust 3G:1" ]
  1820. for t in tests:
  1821. if "FAIL" not in dev[0].request("SET " + t):
  1822. raise Exception("No failure reported for SET " + t)
  1823. tests = [ "relative_rssi 0",
  1824. "relative_rssi 10",
  1825. "relative_rssi disable",
  1826. "relative_band_adjust 2G:-1",
  1827. "relative_band_adjust 2G:0",
  1828. "relative_band_adjust 2G:1",
  1829. "relative_band_adjust 5G:-1",
  1830. "relative_band_adjust 5G:1",
  1831. "relative_band_adjust 5G:0" ]
  1832. for t in tests:
  1833. if "OK" not in dev[0].request("SET " + t):
  1834. raise Exception("Failed to SET " + t)
  1835. def test_wpas_ctrl_get_pref_freq_list_override(dev):
  1836. """wpa_supplicant get_pref_freq_list_override"""
  1837. if dev[0].request("GET_PREF_FREQ_LIST ").strip() != "FAIL":
  1838. raise Exception("Invalid GET_PREF_FREQ_LIST accepted")
  1839. dev[0].set("get_pref_freq_list_override", "foo")
  1840. res = dev[0].request("GET_PREF_FREQ_LIST STATION").strip()
  1841. if res != "FAIL":
  1842. raise Exception("Unexpected GET_PREF_FREQ_LIST response: " + res)
  1843. dev[0].set("get_pref_freq_list_override", "1234:1,2,3 0")
  1844. res = dev[0].request("GET_PREF_FREQ_LIST STATION").strip()
  1845. if res != "FAIL":
  1846. raise Exception("Unexpected GET_PREF_FREQ_LIST response: " + res)
  1847. dev[0].set("get_pref_freq_list_override", "1234:1,2,3 0:")
  1848. res = dev[0].request("GET_PREF_FREQ_LIST STATION").strip()
  1849. if res != "0":
  1850. raise Exception("Unexpected GET_PREF_FREQ_LIST response: " + res)
  1851. dev[0].set("get_pref_freq_list_override", "0:1,2")
  1852. res = dev[0].request("GET_PREF_FREQ_LIST STATION").strip()
  1853. if res != "1,2":
  1854. raise Exception("Unexpected GET_PREF_FREQ_LIST response: " + res)
  1855. dev[0].set("get_pref_freq_list_override", "1:3,4 0:1,2 2:5,6")
  1856. res = dev[0].request("GET_PREF_FREQ_LIST STATION").strip()
  1857. if res != "1,2":
  1858. raise Exception("Unexpected GET_PREF_FREQ_LIST response: " + res)
  1859. dev[0].set("get_pref_freq_list_override", "1:3,4 0:1 2:5,6")
  1860. res = dev[0].request("GET_PREF_FREQ_LIST STATION").strip()
  1861. if res != "1":
  1862. raise Exception("Unexpected GET_PREF_FREQ_LIST response: " + res)
  1863. dev[0].set("get_pref_freq_list_override", "0:1000,1001 2:1002,1003 3:1004,1005 4:1006,1007 8:1010,1011 9:1008,1009")
  1864. res = dev[0].request("GET_PREF_FREQ_LIST STATION").strip()
  1865. if res != "1000,1001":
  1866. raise Exception("Unexpected GET_PREF_FREQ_LIST response: " + res)
  1867. res = dev[0].request("GET_PREF_FREQ_LIST AP").strip()
  1868. if res != "1002,1003":
  1869. raise Exception("Unexpected GET_PREF_FREQ_LIST response: " + res)
  1870. res = dev[0].request("GET_PREF_FREQ_LIST P2P_GO").strip()
  1871. if res != "1004,1005":
  1872. raise Exception("Unexpected GET_PREF_FREQ_LIST response: " + res)
  1873. res = dev[0].request("GET_PREF_FREQ_LIST P2P_CLIENT").strip()
  1874. if res != "1006,1007":
  1875. raise Exception("Unexpected GET_PREF_FREQ_LIST response: " + res)
  1876. res = dev[0].request("GET_PREF_FREQ_LIST IBSS").strip()
  1877. if res != "1008,1009":
  1878. raise Exception("Unexpected GET_PREF_FREQ_LIST response: " + res)
  1879. res = dev[0].request("GET_PREF_FREQ_LIST TDLS").strip()
  1880. if res != "1010,1011":
  1881. raise Exception("Unexpected GET_PREF_FREQ_LIST response: " + res)
  1882. dev[0].set("get_pref_freq_list_override", "")
  1883. res = dev[0].request("GET_PREF_FREQ_LIST STATION").strip()
  1884. logger.info("STATION (without override): " + res)