test_p2p_autogo.py 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. # P2P autonomous GO test cases
  2. # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. from remotehost import remote_compatible
  7. import time
  8. import subprocess
  9. import logging
  10. logger = logging.getLogger()
  11. import hwsim_utils
  12. import utils
  13. from utils import HwsimSkip
  14. from wlantest import Wlantest
  15. from wpasupplicant import WpaSupplicant
  16. from p2p_utils import *
  17. from test_p2p_messages import mgmt_tx, parse_p2p_public_action
  18. def test_autogo(dev):
  19. """P2P autonomous GO and client joining group"""
  20. addr0 = dev[0].p2p_dev_addr()
  21. addr2 = dev[2].p2p_dev_addr()
  22. res = autogo(dev[0])
  23. if "p2p-wlan" in res['ifname']:
  24. raise Exception("Unexpected group interface name on GO")
  25. res = connect_cli(dev[0], dev[1])
  26. if "p2p-wlan" in res['ifname']:
  27. raise Exception("Unexpected group interface name on client")
  28. bss = dev[1].get_bss("p2p_dev_addr=" + addr0, res['ifname'])
  29. if not bss or bss['bssid'] != dev[0].p2p_interface_addr():
  30. raise Exception("Unexpected BSSID in the BSS entry for the GO")
  31. id = bss['id']
  32. bss = dev[1].get_bss("ID-" + id, res['ifname'])
  33. if not bss or bss['id'] != id:
  34. raise Exception("Could not find BSS entry based on id")
  35. res = dev[1].group_request("BSS RANGE=" + id + "- MASK=0x1")
  36. if "id=" + id not in res:
  37. raise Exception("Could not find BSS entry based on id range")
  38. res = dev[1].request("SCAN_RESULTS")
  39. if "[P2P]" not in res:
  40. raise Exception("P2P flag missing from scan results: " + res)
  41. # Presence request to increase testing coverage
  42. if "FAIL" not in dev[1].group_request("P2P_PRESENCE_REQ 30000"):
  43. raise Exception("Invald P2P_PRESENCE_REQ accepted")
  44. if "FAIL" not in dev[1].group_request("P2P_PRESENCE_REQ 30000 102400 30001"):
  45. raise Exception("Invald P2P_PRESENCE_REQ accepted")
  46. if "FAIL" in dev[1].group_request("P2P_PRESENCE_REQ 30000 102400"):
  47. raise Exception("Could not send presence request")
  48. ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"], 10)
  49. if ev is None:
  50. raise Exception("Timeout while waiting for Presence Response")
  51. if "FAIL" in dev[1].group_request("P2P_PRESENCE_REQ 30000 102400 20000 102400"):
  52. raise Exception("Could not send presence request")
  53. ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
  54. if ev is None:
  55. raise Exception("Timeout while waiting for Presence Response")
  56. if "FAIL" in dev[1].group_request("P2P_PRESENCE_REQ"):
  57. raise Exception("Could not send presence request")
  58. ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
  59. if ev is None:
  60. raise Exception("Timeout while waiting for Presence Response")
  61. if not dev[2].discover_peer(addr0):
  62. raise Exception("Could not discover GO")
  63. dev[0].dump_monitor()
  64. dev[2].global_request("P2P_PROV_DISC " + addr0 + " display join")
  65. ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=10)
  66. if ev is None:
  67. raise Exception("GO did not report P2P-PROV-DISC-SHOW-PIN")
  68. if "p2p_dev_addr=" + addr2 not in ev:
  69. raise Exception("Unexpected P2P Device Address in event: " + ev)
  70. if "group=" + dev[0].group_ifname not in ev:
  71. raise Exception("Unexpected group interface in event: " + ev)
  72. ev = dev[2].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=10)
  73. if ev is None:
  74. raise Exception("P2P-PROV-DISC-ENTER-PIN not reported")
  75. dev[0].remove_group()
  76. dev[1].wait_go_ending_session()
  77. def test_autogo2(dev):
  78. """P2P autonomous GO with a separate group interface and client joining group"""
  79. dev[0].global_request("SET p2p_no_group_iface 0")
  80. res = autogo(dev[0], freq=2437)
  81. if "p2p-wlan" not in res['ifname']:
  82. raise Exception("Unexpected group interface name on GO")
  83. if res['ifname'] not in utils.get_ifnames():
  84. raise Exception("Could not find group interface netdev")
  85. connect_cli(dev[0], dev[1], social=True, freq=2437)
  86. dev[0].remove_group()
  87. dev[1].wait_go_ending_session()
  88. if res['ifname'] in utils.get_ifnames():
  89. raise Exception("Group interface netdev was not removed")
  90. def test_autogo3(dev):
  91. """P2P autonomous GO and client with a separate group interface joining group"""
  92. dev[1].global_request("SET p2p_no_group_iface 0")
  93. autogo(dev[0], freq=2462)
  94. res = connect_cli(dev[0], dev[1], social=True, freq=2462)
  95. if "p2p-wlan" not in res['ifname']:
  96. raise Exception("Unexpected group interface name on client")
  97. if res['ifname'] not in utils.get_ifnames():
  98. raise Exception("Could not find group interface netdev")
  99. dev[0].remove_group()
  100. dev[1].wait_go_ending_session()
  101. dev[1].ping()
  102. if res['ifname'] in utils.get_ifnames():
  103. raise Exception("Group interface netdev was not removed")
  104. def test_autogo4(dev):
  105. """P2P autonomous GO and client joining group (both with a separate group interface)"""
  106. dev[0].global_request("SET p2p_no_group_iface 0")
  107. dev[1].global_request("SET p2p_no_group_iface 0")
  108. res1 = autogo(dev[0], freq=2412)
  109. res2 = connect_cli(dev[0], dev[1], social=True, freq=2412)
  110. if "p2p-wlan" not in res1['ifname']:
  111. raise Exception("Unexpected group interface name on GO")
  112. if "p2p-wlan" not in res2['ifname']:
  113. raise Exception("Unexpected group interface name on client")
  114. ifnames = utils.get_ifnames()
  115. if res1['ifname'] not in ifnames:
  116. raise Exception("Could not find GO group interface netdev")
  117. if res2['ifname'] not in ifnames:
  118. raise Exception("Could not find client group interface netdev")
  119. dev[0].remove_group()
  120. dev[1].wait_go_ending_session()
  121. dev[1].ping()
  122. ifnames = utils.get_ifnames()
  123. if res1['ifname'] in ifnames:
  124. raise Exception("GO group interface netdev was not removed")
  125. if res2['ifname'] in ifnames:
  126. raise Exception("Client group interface netdev was not removed")
  127. def test_autogo_m2d(dev):
  128. """P2P autonomous GO and clients not authorized"""
  129. autogo(dev[0], freq=2412)
  130. go_addr = dev[0].p2p_dev_addr()
  131. dev[1].global_request("SET p2p_no_group_iface 0")
  132. if not dev[1].discover_peer(go_addr, social=True):
  133. raise Exception("GO " + go_addr + " not found")
  134. dev[1].dump_monitor()
  135. if not dev[2].discover_peer(go_addr, social=True):
  136. raise Exception("GO " + go_addr + " not found")
  137. dev[2].dump_monitor()
  138. logger.info("Trying to join the group when GO has not authorized the client")
  139. pin = dev[1].wps_read_pin()
  140. cmd = "P2P_CONNECT " + go_addr + " " + pin + " join"
  141. if "OK" not in dev[1].global_request(cmd):
  142. raise Exception("P2P_CONNECT join failed")
  143. pin = dev[2].wps_read_pin()
  144. cmd = "P2P_CONNECT " + go_addr + " " + pin + " join"
  145. if "OK" not in dev[2].global_request(cmd):
  146. raise Exception("P2P_CONNECT join failed")
  147. ev = dev[1].wait_global_event(["WPS-M2D"], timeout=16)
  148. if ev is None:
  149. raise Exception("No global M2D event")
  150. ifaces = dev[1].request("INTERFACES").splitlines()
  151. iface = ifaces[0] if "p2p-wlan" in ifaces[0] else ifaces[1]
  152. wpas = WpaSupplicant(ifname=iface)
  153. ev = wpas.wait_event(["WPS-M2D"], timeout=10)
  154. if ev is None:
  155. raise Exception("No M2D event on group interface")
  156. ev = dev[2].wait_global_event(["WPS-M2D"], timeout=10)
  157. if ev is None:
  158. raise Exception("No global M2D event (2)")
  159. ev = dev[2].wait_event(["WPS-M2D"], timeout=10)
  160. if ev is None:
  161. raise Exception("No M2D event on group interface (2)")
  162. @remote_compatible
  163. def test_autogo_fail(dev):
  164. """P2P autonomous GO and incorrect PIN"""
  165. autogo(dev[0], freq=2412)
  166. go_addr = dev[0].p2p_dev_addr()
  167. dev[0].p2p_go_authorize_client("00000000")
  168. dev[1].global_request("SET p2p_no_group_iface 0")
  169. if not dev[1].discover_peer(go_addr, social=True):
  170. raise Exception("GO " + go_addr + " not found")
  171. dev[1].dump_monitor()
  172. logger.info("Trying to join the group when GO has not authorized the client")
  173. pin = dev[1].wps_read_pin()
  174. cmd = "P2P_CONNECT " + go_addr + " " + pin + " join"
  175. if "OK" not in dev[1].global_request(cmd):
  176. raise Exception("P2P_CONNECT join failed")
  177. ev = dev[1].wait_global_event(["WPS-FAIL"], timeout=10)
  178. if ev is None:
  179. raise Exception("No global WPS-FAIL event")
  180. def test_autogo_2cli(dev):
  181. """P2P autonomous GO and two clients joining group"""
  182. autogo(dev[0], freq=2412)
  183. connect_cli(dev[0], dev[1], social=True, freq=2412)
  184. connect_cli(dev[0], dev[2], social=True, freq=2412)
  185. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  186. dev[0].global_request("P2P_REMOVE_CLIENT " + dev[1].p2p_dev_addr())
  187. dev[1].wait_go_ending_session()
  188. dev[0].global_request("P2P_REMOVE_CLIENT iface=" + dev[2].p2p_interface_addr())
  189. dev[2].wait_go_ending_session()
  190. if "FAIL" not in dev[0].global_request("P2P_REMOVE_CLIENT foo"):
  191. raise Exception("Invalid P2P_REMOVE_CLIENT command accepted")
  192. dev[0].remove_group()
  193. def test_autogo_pbc(dev):
  194. """P2P autonomous GO and PBC"""
  195. dev[1].global_request("SET p2p_no_group_iface 0")
  196. autogo(dev[0], freq=2412)
  197. if "FAIL" not in dev[0].group_request("WPS_PBC p2p_dev_addr=00:11:22:33:44"):
  198. raise Exception("Invalid WPS_PBC succeeded")
  199. if "OK" not in dev[0].group_request("WPS_PBC p2p_dev_addr=" + dev[1].p2p_dev_addr()):
  200. raise Exception("WPS_PBC failed")
  201. dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), "pbc", timeout=0,
  202. social=True)
  203. ev = dev[2].wait_global_event(["WPS-M2D"], timeout=15)
  204. if ev is None:
  205. raise Exception("WPS-M2D not reported")
  206. if "config_error=12" not in ev:
  207. raise Exception("Unexpected config_error: " + ev)
  208. dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), "pbc", timeout=15,
  209. social=True)
  210. def test_autogo_tdls(dev):
  211. """P2P autonomous GO and two clients using TDLS"""
  212. go = dev[0]
  213. logger.info("Start autonomous GO with fixed parameters " + go.ifname)
  214. id = go.add_network()
  215. go.set_network_quoted(id, "ssid", "DIRECT-tdls")
  216. go.set_network_quoted(id, "psk", "12345678")
  217. go.set_network(id, "mode", "3")
  218. go.set_network(id, "disabled", "2")
  219. res = go.p2p_start_go(persistent=id, freq="2462")
  220. logger.debug("res: " + str(res))
  221. Wlantest.setup(go, True)
  222. wt = Wlantest()
  223. wt.flush()
  224. wt.add_passphrase("12345678")
  225. connect_cli(go, dev[1], social=True, freq=2462)
  226. connect_cli(go, dev[2], social=True, freq=2462)
  227. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  228. bssid = dev[0].p2p_interface_addr()
  229. addr1 = dev[1].p2p_interface_addr()
  230. addr2 = dev[2].p2p_interface_addr()
  231. dev[1].tdls_setup(addr2)
  232. time.sleep(1)
  233. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  234. conf = wt.get_tdls_counter("setup_conf_ok", bssid, addr1, addr2)
  235. if conf == 0:
  236. raise Exception("No TDLS Setup Confirm (success) seen")
  237. dl = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2)
  238. if dl == 0:
  239. raise Exception("No valid frames through direct link")
  240. wt.tdls_clear(bssid, addr1, addr2)
  241. dev[1].tdls_teardown(addr2)
  242. time.sleep(1)
  243. teardown = wt.get_tdls_counter("teardown", bssid, addr1, addr2)
  244. if teardown == 0:
  245. raise Exception("No TDLS Setup Teardown seen")
  246. wt.tdls_clear(bssid, addr1, addr2)
  247. hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
  248. ap_path = wt.get_tdls_counter("valid_ap_path", bssid, addr1, addr2)
  249. if ap_path == 0:
  250. raise Exception("No valid frames via AP path")
  251. direct_link = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2)
  252. if direct_link > 0:
  253. raise Exception("Unexpected frames through direct link")
  254. idirect_link = wt.get_tdls_counter("invalid_direct_link", bssid, addr1,
  255. addr2)
  256. if idirect_link > 0:
  257. raise Exception("Unexpected frames through direct link (invalid)")
  258. dev[2].remove_group()
  259. dev[1].remove_group()
  260. dev[0].remove_group()
  261. def test_autogo_legacy(dev):
  262. """P2P autonomous GO and legacy clients"""
  263. res = autogo(dev[0], freq=2462)
  264. if dev[0].get_group_status_field("passphrase", extra="WPS") != res['passphrase']:
  265. raise Exception("passphrase mismatch")
  266. if dev[0].group_request("P2P_GET_PASSPHRASE") != res['passphrase']:
  267. raise Exception("passphrase mismatch(2)")
  268. logger.info("Connect P2P client")
  269. connect_cli(dev[0], dev[1], social=True, freq=2462)
  270. if "FAIL" not in dev[1].request("P2P_GET_PASSPHRASE"):
  271. raise Exception("P2P_GET_PASSPHRASE succeeded on P2P Client")
  272. logger.info("Connect legacy WPS client")
  273. pin = dev[2].wps_read_pin()
  274. dev[0].p2p_go_authorize_client(pin)
  275. dev[2].request("P2P_SET disabled 1")
  276. dev[2].dump_monitor()
  277. dev[2].request("WPS_PIN any " + pin)
  278. dev[2].wait_connected(timeout=30)
  279. status = dev[2].get_status()
  280. if status['wpa_state'] != 'COMPLETED':
  281. raise Exception("Not fully connected")
  282. hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
  283. dev[2].request("DISCONNECT")
  284. logger.info("Connect legacy non-WPS client")
  285. dev[2].request("FLUSH")
  286. dev[2].request("P2P_SET disabled 1")
  287. dev[2].connect(ssid=res['ssid'], psk=res['passphrase'], proto='RSN',
  288. key_mgmt='WPA-PSK', pairwise='CCMP', group='CCMP',
  289. scan_freq=res['freq'])
  290. hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
  291. dev[2].request("DISCONNECT")
  292. dev[0].remove_group()
  293. dev[1].wait_go_ending_session()
  294. def test_autogo_chan_switch(dev):
  295. """P2P autonomous GO switching channels"""
  296. run_autogo_chan_switch(dev)
  297. def run_autogo_chan_switch(dev):
  298. autogo(dev[0], freq=2417)
  299. connect_cli(dev[0], dev[1], freq=2417)
  300. res = dev[0].group_request("CHAN_SWITCH 5 2422")
  301. if "FAIL" in res:
  302. # for now, skip test since mac80211_hwsim support is not yet widely
  303. # deployed
  304. raise HwsimSkip("Assume mac80211_hwsim did not support channel switching")
  305. ev = dev[0].wait_group_event(["AP-CSA-FINISHED"], timeout=10)
  306. if ev is None:
  307. raise Exception("CSA finished event timed out")
  308. if "freq=2422" not in ev:
  309. raise Exception("Unexpected cahnnel in CSA finished event")
  310. dev[0].dump_monitor()
  311. dev[1].dump_monitor()
  312. time.sleep(0.1)
  313. hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
  314. dev[0].remove_group()
  315. dev[1].wait_go_ending_session()
  316. def test_autogo_chan_switch_group_iface(dev):
  317. """P2P autonomous GO switching channels (separate group interface)"""
  318. dev[0].global_request("SET p2p_no_group_iface 0")
  319. run_autogo_chan_switch(dev)
  320. @remote_compatible
  321. def test_autogo_extra_cred(dev):
  322. """P2P autonomous GO sending two WPS credentials"""
  323. if "FAIL" in dev[0].request("SET wps_testing_dummy_cred 1"):
  324. raise Exception("Failed to enable test mode")
  325. autogo(dev[0], freq=2412)
  326. connect_cli(dev[0], dev[1], social=True, freq=2412)
  327. dev[0].remove_group()
  328. dev[1].wait_go_ending_session()
  329. def test_autogo_ifdown(dev):
  330. """P2P autonomous GO and external ifdown"""
  331. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  332. wpas.interface_add("wlan5")
  333. res = autogo(wpas)
  334. wpas.dump_monitor()
  335. wpas.interface_remove("wlan5")
  336. wpas.interface_add("wlan5")
  337. res = autogo(wpas)
  338. wpas.dump_monitor()
  339. subprocess.call(['ifconfig', res['ifname'], 'down'])
  340. ev = wpas.wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
  341. if ev is None:
  342. raise Exception("Group removal not reported")
  343. if res['ifname'] not in ev:
  344. raise Exception("Unexpected group removal event: " + ev)
  345. @remote_compatible
  346. def test_autogo_start_during_scan(dev):
  347. """P2P autonomous GO started during ongoing manual scan"""
  348. try:
  349. # use autoscan to set scan_req = MANUAL_SCAN_REQ
  350. if "OK" not in dev[0].request("AUTOSCAN periodic:1"):
  351. raise Exception("Failed to set autoscan")
  352. autogo(dev[0], freq=2462)
  353. connect_cli(dev[0], dev[1], social=True, freq=2462)
  354. dev[0].remove_group()
  355. dev[1].wait_go_ending_session()
  356. finally:
  357. dev[0].request("AUTOSCAN ")
  358. def test_autogo_passphrase_len(dev):
  359. """P2P autonomous GO and longer passphrase"""
  360. try:
  361. if "OK" not in dev[0].request("SET p2p_passphrase_len 13"):
  362. raise Exception("Failed to set passphrase length")
  363. res = autogo(dev[0], freq=2412)
  364. if len(res['passphrase']) != 13:
  365. raise Exception("Unexpected passphrase length")
  366. if dev[0].get_group_status_field("passphrase", extra="WPS") != res['passphrase']:
  367. raise Exception("passphrase mismatch")
  368. logger.info("Connect P2P client")
  369. connect_cli(dev[0], dev[1], social=True, freq=2412)
  370. logger.info("Connect legacy WPS client")
  371. pin = dev[2].wps_read_pin()
  372. dev[0].p2p_go_authorize_client(pin)
  373. dev[2].request("P2P_SET disabled 1")
  374. dev[2].dump_monitor()
  375. dev[2].request("WPS_PIN any " + pin)
  376. dev[2].wait_connected(timeout=30)
  377. status = dev[2].get_status()
  378. if status['wpa_state'] != 'COMPLETED':
  379. raise Exception("Not fully connected")
  380. dev[2].request("DISCONNECT")
  381. logger.info("Connect legacy non-WPS client")
  382. dev[2].request("FLUSH")
  383. dev[2].request("P2P_SET disabled 1")
  384. dev[2].connect(ssid=res['ssid'], psk=res['passphrase'], proto='RSN',
  385. key_mgmt='WPA-PSK', pairwise='CCMP', group='CCMP',
  386. scan_freq=res['freq'])
  387. hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
  388. dev[2].request("DISCONNECT")
  389. dev[0].remove_group()
  390. dev[1].wait_go_ending_session()
  391. finally:
  392. dev[0].request("SET p2p_passphrase_len 8")
  393. @remote_compatible
  394. def test_autogo_bridge(dev):
  395. """P2P autonomous GO in a bridge"""
  396. try:
  397. # use autoscan to set scan_req = MANUAL_SCAN_REQ
  398. if "OK" not in dev[0].request("AUTOSCAN periodic:1"):
  399. raise Exception("Failed to set autoscan")
  400. autogo(dev[0])
  401. ifname = dev[0].get_group_ifname()
  402. dev[0].cmd_execute(['brctl', 'addbr', 'p2p-br0'])
  403. dev[0].cmd_execute(['brctl', 'setfd', 'p2p-br0', '0'])
  404. dev[0].cmd_execute(['brctl', 'addif', 'p2p-br0', ifname])
  405. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'p2p-br0', 'up'])
  406. time.sleep(0.1)
  407. dev[0].cmd_execute(['brctl', 'delif', 'p2p-br0', ifname])
  408. time.sleep(0.1)
  409. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down'])
  410. time.sleep(0.1)
  411. dev[0].cmd_execute(['brctl', 'delbr', 'p2p-br0'])
  412. ev = dev[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout=1)
  413. if ev is not None:
  414. raise Exception("P2P group removed unexpectedly")
  415. if dev[0].get_group_status_field('wpa_state') != "COMPLETED":
  416. raise Exception("Unexpected wpa_state")
  417. dev[0].remove_group()
  418. finally:
  419. dev[0].request("AUTOSCAN ")
  420. dev[0].cmd_execute(['brctl', 'delif', 'p2p-br0', ifname,
  421. '2>', '/dev/null'], shell=True)
  422. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down',
  423. '2>', '/dev/null'], shell=True)
  424. dev[0].cmd_execute(['brctl', 'delbr', 'p2p-br0', '2>', '/dev/null'],
  425. shell=True)
  426. @remote_compatible
  427. def test_presence_req_on_group_interface(dev):
  428. """P2P_PRESENCE_REQ on group interface"""
  429. dev[1].global_request("SET p2p_no_group_iface 0")
  430. res = autogo(dev[0], freq=2437)
  431. res = connect_cli(dev[0], dev[1], social=True, freq=2437)
  432. if "FAIL" in dev[1].group_request("P2P_PRESENCE_REQ 30000 102400"):
  433. raise Exception("Could not send presence request")
  434. ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
  435. if ev is None:
  436. raise Exception("Timeout while waiting for Presence Response")
  437. dev[0].remove_group()
  438. dev[1].wait_go_ending_session()
  439. def test_autogo_join_auto_go_not_found(dev):
  440. """P2P_CONNECT-auto not finding GO"""
  441. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  442. wpas.interface_add("wlan5")
  443. wpas.request("P2P_SET listen_channel 1")
  444. wpas.global_request("SET p2p_no_group_iface 0")
  445. autogo(wpas, freq=2412)
  446. addr = wpas.p2p_dev_addr()
  447. bssid = wpas.p2p_interface_addr()
  448. wpas.dump_monitor()
  449. dev[1].global_request("SET p2p_no_group_iface 0")
  450. dev[1].scan_for_bss(bssid, freq=2412)
  451. # This makes the GO not show up in the scan iteration following the
  452. # P2P_CONNECT command by stopping beaconing and handling Probe Request
  453. # frames externally (but not really replying to them). P2P listen mode is
  454. # needed to keep the GO listening on the operating channel for the PD
  455. # exchange.
  456. if "OK" not in wpas.group_request("STOP_AP"):
  457. raise Exception("STOP_AP failed")
  458. wpas.dump_monitor()
  459. wpas.group_request("SET ext_mgmt_frame_handling 1")
  460. wpas.p2p_listen()
  461. wpas.dump_monitor()
  462. time.sleep(0.02)
  463. dev[1].global_request("P2P_CONNECT " + addr + " pbc auto")
  464. ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG-ENABLED"], 15)
  465. wpas.dump_monitor()
  466. if ev is None:
  467. raise Exception("Could not trigger old-scan-only case")
  468. return
  469. ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], 15)
  470. wpas.remove_group()
  471. if ev is None:
  472. raise Exception("Fallback to GO Negotiation not seen")
  473. if "reason=GO-not-found" not in ev:
  474. raise Exception("Unexpected reason for fallback: " + ev)
  475. wpas.dump_monitor()
  476. def test_autogo_join_auto(dev):
  477. """P2P_CONNECT-auto joining a group"""
  478. autogo(dev[0])
  479. addr = dev[0].p2p_dev_addr()
  480. if "OK" not in dev[1].global_request("P2P_CONNECT " + addr + " pbc auto"):
  481. raise Exception("P2P_CONNECT failed")
  482. ev = dev[0].wait_global_event(["P2P-PROV-DISC-PBC-REQ"], timeout=15)
  483. if ev is None:
  484. raise Exception("Timeout on P2P-PROV-DISC-PBC-REQ")
  485. if "group=" + dev[0].group_ifname not in ev:
  486. raise Exception("Unexpected PD event contents: " + ev)
  487. dev[0].group_request("WPS_PBC")
  488. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  489. if ev is None:
  490. raise Exception("Joining the group timed out")
  491. dev[1].group_form_result(ev)
  492. dev[0].remove_group()
  493. dev[1].wait_go_ending_session()
  494. dev[1].flush_scan_cache()
  495. @remote_compatible
  496. def test_autogo_join_auto_go_neg(dev):
  497. """P2P_CONNECT-auto fallback to GO Neg"""
  498. dev[1].flush_scan_cache()
  499. dev[0].p2p_listen()
  500. addr = dev[0].p2p_dev_addr()
  501. if not dev[1].discover_peer(addr, social=True):
  502. raise Exception("Peer not found")
  503. dev[1].p2p_stop_find()
  504. if "OK" not in dev[1].global_request("P2P_CONNECT " + addr + " pbc auto"):
  505. raise Exception("P2P_CONNECT failed")
  506. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
  507. if ev is None:
  508. raise Exception("Timeout on P2P-GO-NEG-REQUEST")
  509. peer = ev.split(' ')[1]
  510. dev[0].p2p_go_neg_init(peer, None, "pbc", timeout=15, go_intent=15)
  511. ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout=1)
  512. if ev is None:
  513. raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
  514. if "P2P-FALLBACK-TO-GO-NEG-ENABLED" in ev:
  515. ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout=1)
  516. if ev is None:
  517. raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
  518. if "reason=peer-not-running-GO" not in ev:
  519. raise Exception("Unexpected reason: " + ev)
  520. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  521. if ev is None:
  522. raise Exception("Joining the group timed out")
  523. dev[1].group_form_result(ev)
  524. dev[0].remove_group()
  525. dev[1].wait_go_ending_session()
  526. dev[1].flush_scan_cache()
  527. @remote_compatible
  528. def test_autogo_join_auto_go_neg_after_seeing_go(dev):
  529. """P2P_CONNECT-auto fallback to GO Neg after seeing GO"""
  530. autogo(dev[0], freq=2412)
  531. addr = dev[0].p2p_dev_addr()
  532. bssid = dev[0].p2p_interface_addr()
  533. dev[1].scan_for_bss(bssid, freq=2412)
  534. dev[0].remove_group()
  535. dev[0].p2p_listen()
  536. if "OK" not in dev[1].global_request("P2P_CONNECT " + addr + " pbc auto"):
  537. raise Exception("P2P_CONNECT failed")
  538. ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG-ENABLED"],
  539. timeout=15)
  540. if ev is None:
  541. raise Exception("No P2P-FALLBACK-TO-GO-NEG-ENABLED event seen")
  542. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
  543. if ev is None:
  544. raise Exception("Timeout on P2P-GO-NEG-REQUEST")
  545. peer = ev.split(' ')[1]
  546. dev[0].p2p_go_neg_init(peer, None, "pbc", timeout=15, go_intent=15)
  547. ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout=1)
  548. if ev is None:
  549. raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
  550. if "reason=no-ACK-to-PD-Req" not in ev and "reason=PD-failed" not in ev:
  551. raise Exception("Unexpected reason: " + ev)
  552. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  553. if ev is None:
  554. raise Exception("Joining the group timed out")
  555. dev[1].group_form_result(ev)
  556. dev[0].remove_group()
  557. dev[1].wait_go_ending_session()
  558. dev[1].flush_scan_cache()
  559. def test_go_search_non_social(dev):
  560. """P2P_FIND with freq parameter to scan a single channel"""
  561. addr0 = dev[0].p2p_dev_addr()
  562. autogo(dev[0], freq=2422)
  563. dev[1].p2p_find(freq=2422)
  564. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=3.5)
  565. if ev is None:
  566. dev[1].p2p_stop_find()
  567. dev[1].p2p_find(freq=2422)
  568. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=3.5)
  569. if ev is None:
  570. raise Exception("Did not find GO quickly enough")
  571. dev[2].p2p_listen()
  572. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
  573. if ev is None:
  574. raise Exception("Did not find peer")
  575. dev[2].p2p_stop_find()
  576. dev[1].p2p_stop_find()
  577. dev[0].remove_group()
  578. def test_go_search_non_social2(dev):
  579. """P2P_FIND with freq parameter to scan a single channel (2)"""
  580. addr0 = dev[0].p2p_dev_addr()
  581. dev[1].p2p_find(freq=2422)
  582. # Wait for the first p2p_find scan round to complete before starting GO
  583. time.sleep(1)
  584. autogo(dev[0], freq=2422)
  585. # Verify that p2p_find is still scanning the specified frequency
  586. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
  587. if ev is None:
  588. dev[1].p2p_stop_find()
  589. raise Exception("Did not find GO quickly enough")
  590. # Verify that p2p_find is scanning the social channels
  591. dev[2].p2p_listen()
  592. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
  593. if ev is None:
  594. raise Exception("Did not find peer")
  595. dev[2].p2p_stop_find()
  596. dev[1].p2p_stop_find()
  597. dev[0].remove_group()
  598. dev[1].dump_monitor()
  599. # Verify that social channel as the specific channel works
  600. dev[1].p2p_find(freq=2412)
  601. time.sleep(0.5)
  602. dev[2].p2p_listen()
  603. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
  604. if ev is None:
  605. raise Exception("Did not find peer (2)")
  606. def test_autogo_many(dev):
  607. """P2P autonomous GO with large number of GO instances"""
  608. dev[0].global_request("SET p2p_no_group_iface 0")
  609. for i in range(100):
  610. if "OK" not in dev[0].global_request("P2P_GROUP_ADD freq=2412"):
  611. logger.info("Was able to add %d groups" % i)
  612. if i < 5:
  613. raise Exception("P2P_GROUP_ADD failed")
  614. stop_ev = dev[0].wait_global_event(["P2P-GROUP-REMOVE"], timeout=1)
  615. if stop_ev is not None:
  616. raise Exception("Unexpected P2P-GROUP-REMOVE event")
  617. break
  618. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
  619. if ev is None:
  620. raise Exception("GO start up timed out")
  621. dev[0].group_form_result(ev)
  622. for i in dev[0].global_request("INTERFACES").splitlines():
  623. dev[0].request("P2P_GROUP_REMOVE " + i)
  624. dev[0].dump_monitor()
  625. dev[0].request("P2P_GROUP_REMOVE *")
  626. def test_autogo_many_clients(dev):
  627. """P2P autonomous GO and many clients (P2P IE fragmentation)"""
  628. try:
  629. _test_autogo_many_clients(dev)
  630. finally:
  631. dev[0].global_request("SET device_name Device A")
  632. dev[1].global_request("SET device_name Device B")
  633. dev[2].global_request("SET device_name Device C")
  634. def _test_autogo_many_clients(dev):
  635. # These long device names will push the P2P IE contents beyond the limit
  636. # that requires fragmentation.
  637. name0 = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  638. name1 = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
  639. name2 = "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
  640. name3 = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
  641. dev[0].global_request("SET device_name " + name0)
  642. dev[1].global_request("SET device_name " + name1)
  643. dev[2].global_request("SET device_name " + name2)
  644. addr0 = dev[0].p2p_dev_addr()
  645. res = autogo(dev[0], freq=2412)
  646. bssid = dev[0].p2p_interface_addr()
  647. connect_cli(dev[0], dev[1], social=True, freq=2412)
  648. dev[0].dump_monitor()
  649. connect_cli(dev[0], dev[2], social=True, freq=2412)
  650. dev[0].dump_monitor()
  651. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  652. wpas.interface_add("wlan5")
  653. wpas.global_request("SET device_name " + name3)
  654. wpas.global_request("SET sec_device_type 1-11111111-1")
  655. wpas.global_request("SET sec_device_type 2-22222222-2")
  656. wpas.global_request("SET sec_device_type 3-33333333-3")
  657. wpas.global_request("SET sec_device_type 4-44444444-4")
  658. wpas.global_request("SET sec_device_type 5-55555555-5")
  659. connect_cli(dev[0], wpas, social=True, freq=2412)
  660. dev[0].dump_monitor()
  661. dev[1].dump_monitor()
  662. dev[1].p2p_find(freq=2412)
  663. ev1 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  664. if ev1 is None:
  665. raise Exception("Could not find peer (1)")
  666. ev2 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  667. if ev2 is None:
  668. raise Exception("Could not find peer (2)")
  669. ev3 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
  670. if ev3 is None:
  671. raise Exception("Could not find peer (3)")
  672. dev[1].p2p_stop_find()
  673. for i in [ name0, name2, name3 ]:
  674. if i not in ev1 and i not in ev2 and i not in ev3:
  675. raise Exception('name "%s" not found' % i)
  676. def rx_pd_req(dev):
  677. msg = dev.mgmt_rx()
  678. if msg is None:
  679. raise Exception("MGMT-RX timeout")
  680. p2p = parse_p2p_public_action(msg['payload'])
  681. if p2p is None:
  682. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  683. if p2p['subtype'] != P2P_PROV_DISC_REQ:
  684. raise Exception("Unexpected subtype %d" % p2p['subtype'])
  685. p2p['freq'] = msg['freq']
  686. return p2p
  687. @remote_compatible
  688. def test_autogo_scan(dev):
  689. """P2P autonomous GO and no P2P IE in Probe Response scan results"""
  690. addr0 = dev[0].p2p_dev_addr()
  691. addr1 = dev[1].p2p_dev_addr()
  692. dev[0].p2p_start_go(freq=2412, persistent=True)
  693. bssid = dev[0].p2p_interface_addr()
  694. dev[1].discover_peer(addr0)
  695. dev[1].p2p_stop_find()
  696. ev = dev[1].wait_global_event(["P2P-FIND-STOPPED"], timeout=2)
  697. time.sleep(0.1)
  698. dev[1].flush_scan_cache()
  699. pin = dev[1].wps_read_pin()
  700. dev[0].group_request("WPS_PIN any " + pin)
  701. try:
  702. dev[1].request("SET p2p_disabled 1")
  703. dev[1].request("SCAN freq=2412")
  704. ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  705. if ev is None:
  706. raise Exception("Active scan did not complete")
  707. finally:
  708. dev[1].request("SET p2p_disabled 0")
  709. for i in range(2):
  710. dev[1].request("SCAN freq=2412 passive=1")
  711. ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  712. if ev is None:
  713. raise Exception("Scan did not complete")
  714. # Disable management frame processing for a moment to skip Probe Response
  715. # frame with P2P IE.
  716. dev[0].group_request("SET ext_mgmt_frame_handling 1")
  717. dev[1].global_request("P2P_CONNECT " + bssid + " " + pin + " freq=2412 join")
  718. # Skip the first Probe Request frame
  719. ev = dev[0].wait_group_event(["MGMT-RX"], timeout=10)
  720. if ev is None:
  721. raise Exception("No Probe Request frame seen")
  722. if not ev.split(' ')[4].startswith("40"):
  723. raise Exception("Not a Probe Request frame")
  724. # If a P2P Device is not used, the PD Request will be received on the group
  725. # interface (which is actually wlan0, since a separate interface is not
  726. # used), which was set to external management frame handling, so need to
  727. # reply to it manually.
  728. res = dev[0].get_driver_status()
  729. if not (int(res['capa.flags'], 0) & 0x20000000):
  730. # Reply to PD Request while still filtering Probe Request frames
  731. msg = rx_pd_req(dev[0])
  732. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1, addr0, 2412, "0409506f9a0908%02xdd0a0050f204100800020008" % msg['dialog_token']))
  733. # Skip Probe Request frames until something else is received
  734. for i in range(10):
  735. ev = dev[0].wait_group_event(["MGMT-RX"], timeout=10)
  736. if ev is None:
  737. raise Exception("No frame seen")
  738. if not ev.split(' ')[4].startswith("40"):
  739. break
  740. # Allow wpa_supplicant to process authentication and association
  741. dev[0].group_request("SET ext_mgmt_frame_handling 0")
  742. # Joining the group should succeed and indicate persistent group based on
  743. # Beacon frame P2P IE.
  744. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  745. if ev is None:
  746. raise Exception("Failed to join group")
  747. if "[PERSISTENT]" not in ev:
  748. raise Exception("Did not recognize group as persistent")
  749. dev[0].remove_group()
  750. dev[1].wait_go_ending_session()
  751. @remote_compatible
  752. def test_autogo_join_before_found(dev):
  753. """P2P client joining a group before having found GO Device Address"""
  754. dev[0].global_request("SET p2p_no_group_iface 0")
  755. res = autogo(dev[0], freq=2412)
  756. if "p2p-wlan" not in res['ifname']:
  757. raise Exception("Unexpected group interface name on GO")
  758. status = dev[0].get_group_status()
  759. bssid = status['bssid']
  760. pin = dev[1].wps_read_pin()
  761. dev[0].p2p_go_authorize_client(pin)
  762. cmd = "P2P_CONNECT " + bssid + " " + pin + " join freq=2412"
  763. if "OK" not in dev[1].global_request(cmd):
  764. raise Exception("P2P_CONNECT join failed")
  765. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
  766. if ev is None:
  767. raise Exception("Joining the group timed out")
  768. dev[0].remove_group()
  769. dev[1].wait_go_ending_session()
  770. def test_autogo_noa(dev):
  771. """P2P autonomous GO and NoA"""
  772. res = autogo(dev[0])
  773. dev[0].group_request("P2P_SET noa 1,5,20")
  774. dev[0].group_request("P2P_SET noa 255,10,50")
  775. # Connect and disconnect legacy STA to check NoA special cases
  776. try:
  777. dev[1].request("SET p2p_disabled 1")
  778. dev[1].connect(ssid=res['ssid'], psk=res['passphrase'], proto='RSN',
  779. key_mgmt='WPA-PSK', pairwise='CCMP', group='CCMP',
  780. scan_freq=res['freq'])
  781. dev[0].group_request("P2P_SET noa 255,15,55")
  782. dev[1].request("DISCONNECT")
  783. dev[1].wait_disconnected()
  784. finally:
  785. dev[1].request("SET p2p_disabled 0")
  786. dev[0].group_request("P2P_SET noa 0,0,0")
  787. def test_autogo_interworking(dev):
  788. """P2P autonomous GO and Interworking"""
  789. try:
  790. run_autogo_interworking(dev)
  791. finally:
  792. dev[0].set("go_interworking", "0")
  793. def run_autogo_interworking(dev):
  794. dev[0].set("go_interworking", "1")
  795. dev[0].set("go_access_network_type", "1")
  796. dev[0].set("go_internet", "1")
  797. dev[0].set("go_venue_group", "2")
  798. dev[0].set("go_venue_type", "3")
  799. res = autogo(dev[0])
  800. bssid = dev[0].p2p_interface_addr()
  801. dev[1].scan_for_bss(bssid, freq=res['freq'])
  802. bss = dev[1].get_bss(bssid)
  803. dev[0].remove_group()
  804. if '6b03110203' not in bss['ie']:
  805. raise Exception("Interworking element not seen")