test_p2p_messages.py 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951
  1. # P2P protocol tests for various messages
  2. # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import binascii
  7. import struct
  8. import time
  9. import logging
  10. logger = logging.getLogger()
  11. import hostapd
  12. from test_p2p_persistent import form
  13. from test_p2p_persistent import invite
  14. MGMT_SUBTYPE_PROBE_REQ = 4
  15. MGMT_SUBTYPE_ACTION = 13
  16. ACTION_CATEG_PUBLIC = 4
  17. P2P_GO_NEG_REQ = 0
  18. P2P_GO_NEG_RESP = 1
  19. P2P_GO_NEG_CONF = 2
  20. P2P_INVITATION_REQ = 3
  21. P2P_INVITATION_RESP = 4
  22. P2P_DEV_DISC_REQ = 5
  23. P2P_DEV_DISC_RESP = 6
  24. P2P_PROV_DISC_REQ = 7
  25. P2P_PROV_DISC_RESP = 8
  26. P2P_ATTR_STATUS = 0
  27. P2P_ATTR_MINOR_REASON_CODE = 1
  28. P2P_ATTR_CAPABILITY = 2
  29. P2P_ATTR_DEVICE_ID = 3
  30. P2P_ATTR_GROUP_OWNER_INTENT = 4
  31. P2P_ATTR_CONFIGURATION_TIMEOUT = 5
  32. P2P_ATTR_LISTEN_CHANNEL = 6
  33. P2P_ATTR_GROUP_BSSID = 7
  34. P2P_ATTR_EXT_LISTEN_TIMING = 8
  35. P2P_ATTR_INTENDED_INTERFACE_ADDR = 9
  36. P2P_ATTR_MANAGEABILITY = 10
  37. P2P_ATTR_CHANNEL_LIST = 11
  38. P2P_ATTR_NOTICE_OF_ABSENCE = 12
  39. P2P_ATTR_DEVICE_INFO = 13
  40. P2P_ATTR_GROUP_INFO = 14
  41. P2P_ATTR_GROUP_ID = 15
  42. P2P_ATTR_INTERFACE = 16
  43. P2P_ATTR_OPERATING_CHANNEL = 17
  44. P2P_ATTR_INVITATION_FLAGS = 18
  45. P2P_ATTR_OOB_GO_NEG_CHANNEL = 19
  46. P2P_ATTR_SERVICE_HASH = 21
  47. P2P_ATTR_SESSION_INFORMATION_DATA = 22
  48. P2P_ATTR_CONNECTION_CAPABILITY = 23
  49. P2P_ATTR_ADVERTISEMENT_ID = 24
  50. P2P_ATTR_ADVERTISED_SERVICE = 25
  51. P2P_ATTR_SESSION_ID = 26
  52. P2P_ATTR_FEATURE_CAPABILITY = 27
  53. P2P_ATTR_PERSISTENT_GROUP = 28
  54. P2P_ATTR_VENDOR_SPECIFIC = 221
  55. P2P_SC_SUCCESS = 0
  56. P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE = 1
  57. P2P_SC_FAIL_INCOMPATIBLE_PARAMS = 2
  58. P2P_SC_FAIL_LIMIT_REACHED = 3
  59. P2P_SC_FAIL_INVALID_PARAMS = 4
  60. P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE = 5
  61. P2P_SC_FAIL_PREV_PROTOCOL_ERROR = 6
  62. P2P_SC_FAIL_NO_COMMON_CHANNELS = 7
  63. P2P_SC_FAIL_UNKNOWN_GROUP = 8
  64. P2P_SC_FAIL_BOTH_GO_INTENT_15 = 9
  65. P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD = 10
  66. P2P_SC_FAIL_REJECTED_BY_USER = 11
  67. WSC_ATTR_CONFIG_METHODS = 0x1008
  68. WLAN_EID_SSID = 0
  69. WLAN_EID_SUPP_RATES = 1
  70. WLAN_EID_VENDOR_SPECIFIC = 221
  71. def ie_ssid(ssid):
  72. return struct.pack("<BB", WLAN_EID_SSID, len(ssid)) + ssid
  73. def ie_supp_rates():
  74. return struct.pack("<BBBBBBBBBB", WLAN_EID_SUPP_RATES, 8,
  75. 2*6, 2*9, 2*12, 2*18, 2*24, 2*36, 2*48, 2*54)
  76. def ie_p2p(attrs):
  77. return struct.pack("<BBBBBB", WLAN_EID_VENDOR_SPECIFIC, 4 + len(attrs),
  78. 0x50, 0x6f, 0x9a, 9) + attrs
  79. def ie_wsc(attrs):
  80. return struct.pack("<BBBBBB", WLAN_EID_VENDOR_SPECIFIC, 4 + len(attrs),
  81. 0x00, 0x50, 0xf2, 4) + attrs
  82. def wsc_attr_config_methods(methods=0):
  83. return struct.pack(">HHH", WSC_ATTR_CONFIG_METHODS, 2, methods)
  84. def p2p_attr_status(status=P2P_SC_SUCCESS):
  85. return struct.pack("<BHB", P2P_ATTR_STATUS, 1, status)
  86. def p2p_attr_minor_reason_code(code=0):
  87. return struct.pack("<BHB", P2P_ATTR_MINOR_REASON_CODE, 1, code)
  88. def p2p_attr_capability(dev_capab=0, group_capab=0):
  89. return struct.pack("<BHBB", P2P_ATTR_CAPABILITY, 2, dev_capab, group_capab)
  90. def p2p_attr_device_id(addr):
  91. val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
  92. t = (P2P_ATTR_DEVICE_ID, 6) + val
  93. return struct.pack('<BH6B', *t)
  94. def p2p_attr_go_intent(go_intent=0, tie_breaker=0):
  95. return struct.pack("<BHB", P2P_ATTR_GROUP_OWNER_INTENT, 1,
  96. (go_intent << 1) | (tie_breaker & 0x01))
  97. def p2p_attr_config_timeout(go_config_timeout=0, client_config_timeout=0):
  98. return struct.pack("<BHBB", P2P_ATTR_CONFIGURATION_TIMEOUT, 2,
  99. go_config_timeout, client_config_timeout)
  100. def p2p_attr_listen_channel(op_class=81, chan=1):
  101. return struct.pack("<BHBBBBB", P2P_ATTR_LISTEN_CHANNEL, 5,
  102. 0x58, 0x58, 0x04, op_class, chan)
  103. def p2p_attr_group_bssid(addr):
  104. val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
  105. t = (P2P_ATTR_GROUP_BSSID, 6) + val
  106. return struct.pack('<BH6B', *t)
  107. def p2p_attr_ext_listen_timing(period=0, interval=0):
  108. return struct.pack("<BHHH", P2P_ATTR_EXT_LISTEN_TIMING, 4, period, interval)
  109. def p2p_attr_intended_interface_addr(addr):
  110. val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
  111. t = (P2P_ATTR_INTENDED_INTERFACE_ADDR, 6) + val
  112. return struct.pack('<BH6B', *t)
  113. def p2p_attr_manageability(bitmap=0):
  114. return struct.pack("<BHB", P2P_ATTR_MANAGEABILITY, 1, bitmap)
  115. def p2p_attr_channel_list():
  116. return struct.pack("<BH3BBB11B", P2P_ATTR_CHANNEL_LIST, 16,
  117. 0x58, 0x58, 0x04,
  118. 81, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
  119. def p2p_attr_device_info(addr, name="Test", config_methods=0, dev_type="00010050F2040001"):
  120. val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
  121. val2 = struct.unpack('8B', binascii.unhexlify(dev_type))
  122. t = (P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 4 + len(name)) + val + (config_methods,) + val2 + (0,)
  123. return struct.pack("<BH6BH8BB", *t) + struct.pack('>HH', 0x1011, len(name)) +name
  124. def p2p_attr_group_id(addr, ssid):
  125. val = struct.unpack('6B', binascii.unhexlify(addr.replace(':','')))
  126. t = (P2P_ATTR_GROUP_ID, 6 + len(ssid)) + val
  127. return struct.pack('<BH6B', *t) + ssid
  128. def p2p_attr_operating_channel(op_class=81, chan=1):
  129. return struct.pack("<BHBBBBB", P2P_ATTR_OPERATING_CHANNEL, 5,
  130. 0x58, 0x58, 0x04, op_class, chan)
  131. def p2p_attr_invitation_flags(bitmap=0):
  132. return struct.pack("<BHB", P2P_ATTR_INVITATION_FLAGS, 1, bitmap)
  133. def p2p_hdr_helper(dst, src, type=None, dialog_token=1, req=True):
  134. msg = {}
  135. msg['fc'] = MGMT_SUBTYPE_ACTION << 4
  136. msg['da'] = dst
  137. msg['sa'] = src
  138. if req:
  139. msg['bssid'] = dst
  140. else:
  141. msg['bssid'] = src
  142. msg['payload'] = struct.pack("<BBBBBB",
  143. ACTION_CATEG_PUBLIC, 9, 0x50, 0x6f, 0x9a, 9)
  144. if type is not None:
  145. msg['payload'] += struct.pack("<B", type)
  146. if dialog_token:
  147. msg['payload'] += struct.pack("<B", dialog_token)
  148. return msg
  149. def p2p_hdr(dst, src, type=None, dialog_token=1):
  150. return p2p_hdr_helper(dst, src, type, dialog_token, True)
  151. def p2p_hdr_resp(dst, src, type=None, dialog_token=1):
  152. return p2p_hdr_helper(dst, src, type, dialog_token, False)
  153. def start_p2p(dev, apdev):
  154. addr0 = dev[0].p2p_dev_addr()
  155. dev[0].p2p_listen()
  156. dev[1].p2p_find(social=True)
  157. ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
  158. if ev is None:
  159. raise Exception("Device discovery timed out")
  160. dev[1].p2p_stop_find()
  161. peer = dev[1].get_peer(addr0)
  162. bssid = apdev[0]['bssid']
  163. params = { 'ssid': "test", 'beacon_int': "2000" }
  164. if peer['listen_freq'] == "2412":
  165. params['channel'] = '1'
  166. elif peer['listen_freq'] == "2437":
  167. params['channel'] = '6'
  168. elif peer['listen_freq'] == "2462":
  169. params['channel'] = '11'
  170. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  171. hapd.set("ext_mgmt_frame_handling", "1")
  172. return addr0, bssid, hapd, int(params['channel'])
  173. def p2p_probe(hapd, src, chan=1):
  174. msg = {}
  175. msg['fc'] = MGMT_SUBTYPE_PROBE_REQ << 4
  176. msg['da'] = "ff:ff:ff:ff:ff:ff"
  177. msg['sa'] = src
  178. msg['bssid'] = "ff:ff:ff:ff:ff:ff"
  179. attrs = p2p_attr_listen_channel(chan=chan)
  180. msg['payload'] = ie_ssid("DIRECT-") + ie_supp_rates() + ie_p2p(attrs)
  181. hapd.mgmt_tx(msg)
  182. def parse_p2p_public_action(payload):
  183. pos = payload
  184. (category, action) = struct.unpack('BB', pos[0:2])
  185. if category != ACTION_CATEG_PUBLIC:
  186. return None
  187. if action != 9:
  188. return None
  189. pos = pos[2:]
  190. (oui1,oui2,oui3,subtype) = struct.unpack('BBBB', pos[0:4])
  191. if oui1 != 0x50 or oui2 != 0x6f or oui3 != 0x9a or subtype != 9:
  192. return None
  193. pos = pos[4:]
  194. (subtype,dialog_token) = struct.unpack('BB', pos[0:2])
  195. p2p = {}
  196. p2p['subtype'] = subtype
  197. p2p['dialog_token'] = dialog_token
  198. pos = pos[2:]
  199. p2p['elements'] = pos
  200. while len(pos) > 2:
  201. (id,elen) = struct.unpack('BB', pos[0:2])
  202. pos = pos[2:]
  203. if elen > len(pos):
  204. raise Exception("Truncated IE in P2P Public Action frame (elen=%d left=%d)" % (elen, len(pos)))
  205. if id == WLAN_EID_VENDOR_SPECIFIC:
  206. if elen < 4:
  207. raise Exception("Too short vendor specific IE in P2P Public Action frame (elen=%d)" % elen)
  208. (oui1,oui2,oui3,subtype) = struct.unpack('BBBB', pos[0:4])
  209. if oui1 == 0x50 and oui2 == 0x6f and oui3 == 0x9a and subtype == 9:
  210. if 'p2p' in p2p:
  211. p2p['p2p'] += pos[4:elen]
  212. else:
  213. p2p['p2p'] = pos[4:elen]
  214. if oui1 == 0x00 and oui2 == 0x50 and oui3 == 0xf2 and subtype == 4:
  215. p2p['wsc'] = pos[4:elen]
  216. pos = pos[elen:]
  217. if len(pos) > 0:
  218. raise Exception("Invalid element in P2P Public Action frame")
  219. if 'p2p' in p2p:
  220. p2p['p2p_attrs'] = {}
  221. pos = p2p['p2p']
  222. while len(pos) >= 3:
  223. (id,alen) = struct.unpack('<BH', pos[0:3])
  224. pos = pos[3:]
  225. if alen > len(pos):
  226. logger.info("P2P payload: " + binascii.hexlify(p2p['p2p']))
  227. raise Exception("Truncated P2P attribute in P2P Public Action frame (alen=%d left=%d p2p-payload=%d)" % (alen, len(pos), len(p2p['p2p'])))
  228. p2p['p2p_attrs'][id] = pos[0:alen]
  229. pos = pos[alen:]
  230. if P2P_ATTR_STATUS in p2p['p2p_attrs']:
  231. p2p['p2p_status'] = struct.unpack('B', p2p['p2p_attrs'][P2P_ATTR_STATUS])[0]
  232. if 'wsc' in p2p:
  233. p2p['wsc_attrs'] = {}
  234. pos = p2p['wsc']
  235. while len(pos) >= 4:
  236. (id,alen) = struct.unpack('>HH', pos[0:4])
  237. pos = pos[4:]
  238. if alen > len(pos):
  239. logger.info("WSC payload: " + binascii.hexlify(p2p['wsc']))
  240. raise Exception("Truncated WSC attribute in P2P Public Action frame (alen=%d left=%d wsc-payload=%d)" % (alen, len(pos), len(p2p['wsc'])))
  241. p2p['wsc_attrs'][id] = pos[0:alen]
  242. pos = pos[alen:]
  243. return p2p
  244. def test_p2p_msg_empty(dev, apdev):
  245. """P2P protocol test: empty P2P Public Action frame"""
  246. dst, src, hapd, channel = start_p2p(dev, apdev)
  247. msg = p2p_hdr(dst, src)
  248. hapd.mgmt_tx(msg)
  249. def test_p2p_msg_long_ssid(dev, apdev):
  250. """P2P protocol test: Too long SSID in P2P Public Action frame"""
  251. dst, src, hapd, channel = start_p2p(dev, apdev)
  252. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=1)
  253. attrs = p2p_attr_config_timeout()
  254. attrs += p2p_attr_invitation_flags()
  255. attrs += p2p_attr_operating_channel()
  256. attrs += p2p_attr_group_bssid(src)
  257. attrs += p2p_attr_channel_list()
  258. attrs += p2p_attr_group_id(src, 'DIRECT-foo')
  259. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  260. msg['payload'] += ie_p2p(attrs)
  261. msg['payload'] += ie_ssid(255 * 'A')
  262. hapd.mgmt_tx(msg)
  263. ev = dev[0].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
  264. if ev is None:
  265. raise Exception("Timeout on device found event")
  266. def test_p2p_msg_long_dev_name(dev, apdev):
  267. """P2P protocol test: Too long Device Name in P2P Public Action frame"""
  268. dst, src, hapd, channel = start_p2p(dev, apdev)
  269. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=1)
  270. attrs = p2p_attr_config_timeout()
  271. attrs += p2p_attr_invitation_flags()
  272. attrs += p2p_attr_operating_channel()
  273. attrs += p2p_attr_group_bssid(src)
  274. attrs += p2p_attr_channel_list()
  275. attrs += p2p_attr_group_id(src, 'DIRECT-foo')
  276. attrs += p2p_attr_device_info(src, config_methods=0x0108,
  277. name="123456789012345678901234567890123")
  278. msg['payload'] += ie_p2p(attrs)
  279. hapd.mgmt_tx(msg)
  280. ev = dev[0].wait_event(["P2P-DEVICE-FOUND"], timeout=0.1)
  281. if ev is not None:
  282. raise Exception("Unexpected device found event")
  283. def test_p2p_msg_invitation_req(dev, apdev):
  284. """P2P protocol tests for invitation request processing"""
  285. dst, src, hapd, channel = start_p2p(dev, apdev)
  286. # Empty P2P Invitation Request (missing dialog token)
  287. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=None)
  288. hapd.mgmt_tx(msg)
  289. dialog_token = 0
  290. # Various p2p_parse() failure cases due to invalid attributes
  291. # Too short attribute header
  292. dialog_token += 1
  293. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  294. attrs = struct.pack("<BB", P2P_ATTR_CAPABILITY, 0)
  295. msg['payload'] += ie_p2p(attrs)
  296. hapd.mgmt_tx(msg)
  297. # Minimal attribute underflow
  298. dialog_token += 1
  299. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  300. attrs = struct.pack("<BH", P2P_ATTR_CAPABILITY, 1)
  301. msg['payload'] += ie_p2p(attrs)
  302. hapd.mgmt_tx(msg)
  303. # Large attribute underflow
  304. dialog_token += 1
  305. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  306. attrs = struct.pack("<BHB", P2P_ATTR_CAPABILITY, 0xffff, 1)
  307. msg['payload'] += ie_p2p(attrs)
  308. hapd.mgmt_tx(msg)
  309. # Too short Capability attribute
  310. dialog_token += 1
  311. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  312. attrs = struct.pack("<BHB", P2P_ATTR_CAPABILITY, 1, 0)
  313. msg['payload'] += ie_p2p(attrs)
  314. hapd.mgmt_tx(msg)
  315. # Too short Device ID attribute
  316. dialog_token += 1
  317. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  318. val = struct.unpack('5B', binascii.unhexlify("1122334455"))
  319. t = (P2P_ATTR_DEVICE_ID, 5) + val
  320. attrs = struct.pack('<BH5B', *t)
  321. msg['payload'] += ie_p2p(attrs)
  322. hapd.mgmt_tx(msg)
  323. # Too short GO Intent attribute
  324. dialog_token += 1
  325. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  326. attrs = struct.pack("<BH", P2P_ATTR_GROUP_OWNER_INTENT, 0)
  327. msg['payload'] += ie_p2p(attrs)
  328. hapd.mgmt_tx(msg)
  329. # Too short Status attribute
  330. dialog_token += 1
  331. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  332. attrs = struct.pack("<BH", P2P_ATTR_STATUS, 0)
  333. msg['payload'] += ie_p2p(attrs)
  334. hapd.mgmt_tx(msg)
  335. # null Listen channel and too short Listen Channel attribute
  336. dialog_token += 1
  337. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  338. attrs = struct.pack("<BH", P2P_ATTR_LISTEN_CHANNEL, 0)
  339. attrs += struct.pack("<BHB", P2P_ATTR_LISTEN_CHANNEL, 1, 0)
  340. msg['payload'] += ie_p2p(attrs)
  341. hapd.mgmt_tx(msg)
  342. # null Operating channel and too short Operating Channel attribute
  343. dialog_token += 1
  344. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  345. attrs = struct.pack("<BH", P2P_ATTR_OPERATING_CHANNEL, 0)
  346. attrs += struct.pack("<BHB", P2P_ATTR_OPERATING_CHANNEL, 1, 0)
  347. msg['payload'] += ie_p2p(attrs)
  348. hapd.mgmt_tx(msg)
  349. # Too short Channel List attribute
  350. dialog_token += 1
  351. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  352. attrs = struct.pack("<BHBB", P2P_ATTR_CHANNEL_LIST, 2, 1, 2)
  353. msg['payload'] += ie_p2p(attrs)
  354. hapd.mgmt_tx(msg)
  355. # Too short Device Info attribute
  356. dialog_token += 1
  357. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  358. attrs = struct.pack("<BHBB", P2P_ATTR_DEVICE_INFO, 2, 1, 2)
  359. msg['payload'] += ie_p2p(attrs)
  360. hapd.mgmt_tx(msg)
  361. # Truncated Secondary Device Types in Device Info attribute
  362. dialog_token += 1
  363. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  364. attrs = struct.pack("<BH6BH8BB", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1,
  365. 0, 0, 0, 0, 0, 0,
  366. 0,
  367. 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x11, 0x22,
  368. 255)
  369. msg['payload'] += ie_p2p(attrs)
  370. hapd.mgmt_tx(msg)
  371. # Missing Device Name in Device Info attribute
  372. dialog_token += 1
  373. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  374. attrs = struct.pack("<BH6BH8BB8B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8,
  375. 0, 0, 0, 0, 0, 0,
  376. 0,
  377. 0, 0, 0, 0, 0, 0, 0, 0,
  378. 1,
  379. 1, 2, 3, 4, 5, 6, 7, 8)
  380. msg['payload'] += ie_p2p(attrs)
  381. hapd.mgmt_tx(msg)
  382. # Invalid Device Name header in Device Info attribute
  383. dialog_token += 1
  384. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  385. attrs = struct.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4,
  386. 0, 0, 0, 0, 0, 0,
  387. 0,
  388. 0, 0, 0, 0, 0, 0, 0, 0,
  389. 1,
  390. 1, 2, 3, 4, 5, 6, 7, 8,
  391. 0x11, 0x12, 0, 0)
  392. msg['payload'] += ie_p2p(attrs)
  393. hapd.mgmt_tx(msg)
  394. # Invalid Device Name header length in Device Info attribute
  395. dialog_token += 1
  396. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  397. attrs = struct.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4,
  398. 0, 0, 0, 0, 0, 0,
  399. 0,
  400. 0, 0, 0, 0, 0, 0, 0, 0,
  401. 1,
  402. 1, 2, 3, 4, 5, 6, 7, 8,
  403. 0x10, 0x11, 0xff, 0xff)
  404. msg['payload'] += ie_p2p(attrs)
  405. hapd.mgmt_tx(msg)
  406. # Invalid Device Name header length in Device Info attribute
  407. dialog_token += 1
  408. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  409. devname = 'A'
  410. attrs = struct.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4 + len(devname),
  411. 0, 0, 0, 0, 0, 0,
  412. 0,
  413. 0, 0, 0, 0, 0, 0, 0, 0,
  414. 1,
  415. 1, 2, 3, 4, 5, 6, 7, 8,
  416. 0x10, 0x11, 0, len(devname) + 1) + devname
  417. msg['payload'] += ie_p2p(attrs)
  418. hapd.mgmt_tx(msg)
  419. # Device Name filtering and too long Device Name in Device Info attribute
  420. dialog_token += 1
  421. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  422. attrs = struct.pack("<BH6BH8BB8B4B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4 + 4,
  423. 0, 0, 0, 0, 0, 0,
  424. 0,
  425. 0, 0, 0, 0, 0, 0, 0, 0,
  426. 1,
  427. 1, 2, 3, 4, 5, 6, 7, 8,
  428. 0x10, 0x11, 0, 4,
  429. 64, 9, 0, 64)
  430. devname = '123456789012345678901234567890123'
  431. attrs += struct.pack("<BH6BH8BB8B4B", P2P_ATTR_DEVICE_INFO, 6 + 2 + 8 + 1 + 8 + 4 + len(devname),
  432. 0, 0, 0, 0, 0, 0,
  433. 0,
  434. 0, 0, 0, 0, 0, 0, 0, 0,
  435. 1,
  436. 1, 2, 3, 4, 5, 6, 7, 8,
  437. 0x10, 0x11, 0, len(devname)) + devname
  438. msg['payload'] += ie_p2p(attrs)
  439. hapd.mgmt_tx(msg)
  440. # Too short Configuration Timeout attribute
  441. dialog_token += 1
  442. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  443. attrs = struct.pack("<BHB", P2P_ATTR_CONFIGURATION_TIMEOUT, 1, 1)
  444. msg['payload'] += ie_p2p(attrs)
  445. hapd.mgmt_tx(msg)
  446. # Too short Intended P2P Interface Address attribute
  447. dialog_token += 1
  448. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  449. attrs = struct.pack("<BHB", P2P_ATTR_INTENDED_INTERFACE_ADDR, 1, 1)
  450. msg['payload'] += ie_p2p(attrs)
  451. hapd.mgmt_tx(msg)
  452. # Too short P2P Group BSSID attribute
  453. dialog_token += 1
  454. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  455. attrs = struct.pack("<BHB", P2P_ATTR_GROUP_BSSID, 1, 1)
  456. msg['payload'] += ie_p2p(attrs)
  457. hapd.mgmt_tx(msg)
  458. # Too short P2P Group ID attribute
  459. dialog_token += 1
  460. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  461. attrs = struct.pack("<BHB", P2P_ATTR_GROUP_ID, 1, 1)
  462. msg['payload'] += ie_p2p(attrs)
  463. hapd.mgmt_tx(msg)
  464. # Too long P2P Group ID attribute
  465. dialog_token += 1
  466. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  467. attrs = struct.pack("<BH6B", P2P_ATTR_GROUP_ID, 6 + 33, 0, 0, 0, 0, 0, 0) + "123456789012345678901234567890123"
  468. msg['payload'] += ie_p2p(attrs)
  469. hapd.mgmt_tx(msg)
  470. # Too short Invitation Flags attribute
  471. dialog_token += 1
  472. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  473. attrs = struct.pack("<BH", P2P_ATTR_INVITATION_FLAGS, 0)
  474. msg['payload'] += ie_p2p(attrs)
  475. hapd.mgmt_tx(msg)
  476. # Valid and too short Manageability attribute
  477. dialog_token += 1
  478. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  479. attrs = p2p_attr_manageability()
  480. attrs += struct.pack("<BH", P2P_ATTR_MANAGEABILITY, 0)
  481. msg['payload'] += ie_p2p(attrs)
  482. hapd.mgmt_tx(msg)
  483. # Too short NoA attribute
  484. dialog_token += 1
  485. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  486. attrs = struct.pack("<BHB", P2P_ATTR_NOTICE_OF_ABSENCE, 1, 1)
  487. msg['payload'] += ie_p2p(attrs)
  488. hapd.mgmt_tx(msg)
  489. # Valid and too short Extended Listen Timing attributes
  490. dialog_token += 1
  491. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  492. attrs = p2p_attr_ext_listen_timing(period=100, interval=50)
  493. attrs += struct.pack("<BHBBB", P2P_ATTR_EXT_LISTEN_TIMING, 3, 0, 0, 0)
  494. msg['payload'] += ie_p2p(attrs)
  495. hapd.mgmt_tx(msg)
  496. # Valid and too short Minor Reason Code attributes
  497. dialog_token += 1
  498. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  499. attrs = p2p_attr_minor_reason_code(code=2)
  500. attrs += struct.pack("<BH", P2P_ATTR_MINOR_REASON_CODE, 0)
  501. msg['payload'] += ie_p2p(attrs)
  502. hapd.mgmt_tx(msg)
  503. # Unknown attribute and too short OOB GO Negotiation Channel attribute
  504. dialog_token += 1
  505. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  506. attrs = struct.pack("<BHB", 99, 1, 1)
  507. attrs += struct.pack("<BHB", P2P_ATTR_OOB_GO_NEG_CHANNEL, 1, 1)
  508. msg['payload'] += ie_p2p(attrs)
  509. hapd.mgmt_tx(msg)
  510. # Too short Service Hash attribute
  511. dialog_token += 1
  512. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  513. attrs = struct.pack("<BH5B", P2P_ATTR_SERVICE_HASH, 5, 1, 2, 3, 4, 5)
  514. msg['payload'] += ie_p2p(attrs)
  515. hapd.mgmt_tx(msg)
  516. # Too short Connection Capability attribute
  517. dialog_token += 1
  518. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  519. attrs = struct.pack("<BH", P2P_ATTR_CONNECTION_CAPABILITY, 0)
  520. msg['payload'] += ie_p2p(attrs)
  521. hapd.mgmt_tx(msg)
  522. # Too short Advertisement ID attribute
  523. dialog_token += 1
  524. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  525. attrs = struct.pack("<BH9B", P2P_ATTR_ADVERTISEMENT_ID, 9, 1, 2, 3, 4, 5,
  526. 6, 7, 8, 9)
  527. msg['payload'] += ie_p2p(attrs)
  528. hapd.mgmt_tx(msg)
  529. # Truncated and too short Service Instance attributes
  530. dialog_token += 1
  531. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  532. attrs = struct.pack("<BH8B", P2P_ATTR_ADVERTISED_SERVICE, 8, 1, 2, 3, 4, 5,
  533. 6, 2, 8)
  534. attrs += struct.pack("<BH7B", P2P_ATTR_ADVERTISED_SERVICE, 7, 1, 2, 3, 4, 5,
  535. 6, 7)
  536. msg['payload'] += ie_p2p(attrs)
  537. hapd.mgmt_tx(msg)
  538. # Too short Session ID attribute
  539. dialog_token += 1
  540. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  541. attrs = struct.pack("<BH4B", P2P_ATTR_SESSION_ID, 4, 1, 2, 3, 4)
  542. msg['payload'] += ie_p2p(attrs)
  543. hapd.mgmt_tx(msg)
  544. # Too short Feature Capability attribute
  545. dialog_token += 1
  546. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  547. attrs = struct.pack("<BH", P2P_ATTR_FEATURE_CAPABILITY, 0)
  548. msg['payload'] += ie_p2p(attrs)
  549. hapd.mgmt_tx(msg)
  550. # Too short Persistent Group attribute
  551. dialog_token += 1
  552. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  553. attrs = struct.pack("<BH5B", P2P_ATTR_PERSISTENT_GROUP, 5, 1, 2, 3, 4, 5)
  554. msg['payload'] += ie_p2p(attrs)
  555. hapd.mgmt_tx(msg)
  556. # Too long Persistent Group attribute
  557. dialog_token += 1
  558. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  559. attrs = struct.pack("<BH9L3B", P2P_ATTR_PERSISTENT_GROUP, 6 + 32 + 1,
  560. 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3)
  561. msg['payload'] += ie_p2p(attrs)
  562. hapd.mgmt_tx(msg)
  563. if hapd.mgmt_rx(timeout=0.5) is not None:
  564. raise Exception("Unexpected management frame received")
  565. dev[0].dump_monitor()
  566. dialog_token += 1
  567. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  568. attrs = p2p_attr_config_timeout()
  569. attrs += p2p_attr_invitation_flags()
  570. attrs += p2p_attr_operating_channel()
  571. attrs += p2p_attr_group_bssid(src)
  572. attrs += p2p_attr_channel_list()
  573. attrs += p2p_attr_group_id(src, "DIRECT-foo")
  574. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  575. msg['payload'] += ie_p2p(attrs)
  576. hapd.mgmt_tx(msg)
  577. ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
  578. if ev is None:
  579. raise Exception("Timeout on device found event")
  580. ev = dev[0].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=5)
  581. if ev is None:
  582. raise Exception("Timeout on invitation event " + str(dialog_token))
  583. if hapd.mgmt_rx(timeout=1) is None:
  584. raise Exception("No invitation response " + str(dialog_token))
  585. time.sleep(0.1)
  586. dev[0].dump_monitor()
  587. dialog_token += 1
  588. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  589. attrs = p2p_attr_config_timeout()
  590. attrs += p2p_attr_invitation_flags()
  591. attrs += p2p_attr_operating_channel()
  592. attrs += p2p_attr_group_bssid(src)
  593. attrs += p2p_attr_channel_list()
  594. attrs += p2p_attr_group_id(src, "DIRECT-foo")
  595. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  596. msg['payload'] += ie_p2p(attrs)
  597. hapd.mgmt_tx(msg)
  598. ev = dev[0].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=5)
  599. if ev is None:
  600. raise Exception("Timeout on invitation event " + str(dialog_token))
  601. if hapd.mgmt_rx(timeout=1) is None:
  602. raise Exception("No invitation response " + str(dialog_token))
  603. time.sleep(0.1)
  604. dev[0].dump_monitor()
  605. dialog_token += 1
  606. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  607. #attrs = p2p_attr_config_timeout()
  608. attrs = p2p_attr_invitation_flags()
  609. attrs += p2p_attr_operating_channel()
  610. attrs += p2p_attr_group_bssid(src)
  611. attrs += p2p_attr_channel_list()
  612. attrs += p2p_attr_group_id(src, "DIRECT-foo")
  613. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  614. msg['payload'] += ie_p2p(attrs)
  615. hapd.mgmt_tx(msg)
  616. if hapd.mgmt_rx(timeout=1) is None:
  617. raise Exception("No invitation response " + str(dialog_token))
  618. time.sleep(0.1)
  619. dev[0].dump_monitor()
  620. dialog_token += 1
  621. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  622. attrs = p2p_attr_config_timeout()
  623. #attrs = p2p_attr_invitation_flags()
  624. attrs += p2p_attr_operating_channel()
  625. attrs += p2p_attr_group_bssid(src)
  626. attrs += p2p_attr_channel_list()
  627. attrs += p2p_attr_group_id(src, "DIRECT-foo")
  628. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  629. msg['payload'] += ie_p2p(attrs)
  630. hapd.mgmt_tx(msg)
  631. if hapd.mgmt_rx(timeout=1) is None:
  632. raise Exception("No invitation response " + str(dialog_token))
  633. time.sleep(0.1)
  634. dev[0].dump_monitor()
  635. dialog_token += 1
  636. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  637. attrs = p2p_attr_config_timeout()
  638. attrs = p2p_attr_invitation_flags()
  639. #attrs += p2p_attr_operating_channel()
  640. attrs += p2p_attr_group_bssid(src)
  641. attrs += p2p_attr_channel_list()
  642. attrs += p2p_attr_group_id(src, "DIRECT-foo")
  643. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  644. msg['payload'] += ie_p2p(attrs)
  645. hapd.mgmt_tx(msg)
  646. if hapd.mgmt_rx(timeout=1) is None:
  647. raise Exception("No invitation response " + str(dialog_token))
  648. time.sleep(0.1)
  649. dev[0].dump_monitor()
  650. dialog_token += 1
  651. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  652. attrs = p2p_attr_config_timeout()
  653. attrs = p2p_attr_invitation_flags()
  654. attrs += p2p_attr_operating_channel()
  655. #attrs += p2p_attr_group_bssid(src)
  656. attrs += p2p_attr_channel_list()
  657. attrs += p2p_attr_group_id(src, "DIRECT-foo")
  658. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  659. msg['payload'] += ie_p2p(attrs)
  660. hapd.mgmt_tx(msg)
  661. if hapd.mgmt_rx(timeout=1) is None:
  662. raise Exception("No invitation response " + str(dialog_token))
  663. time.sleep(0.1)
  664. dev[0].dump_monitor()
  665. dialog_token += 1
  666. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  667. attrs = p2p_attr_config_timeout()
  668. attrs = p2p_attr_invitation_flags()
  669. attrs += p2p_attr_operating_channel()
  670. attrs += p2p_attr_group_bssid(src)
  671. #attrs += p2p_attr_channel_list()
  672. attrs += p2p_attr_group_id(src, "DIRECT-foo")
  673. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  674. msg['payload'] += ie_p2p(attrs)
  675. hapd.mgmt_tx(msg)
  676. if hapd.mgmt_rx(timeout=1) is None:
  677. raise Exception("No invitation response " + str(dialog_token))
  678. time.sleep(0.1)
  679. dev[0].dump_monitor()
  680. dialog_token += 1
  681. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  682. attrs = p2p_attr_config_timeout()
  683. attrs = p2p_attr_invitation_flags()
  684. attrs += p2p_attr_operating_channel()
  685. attrs += p2p_attr_group_bssid(src)
  686. attrs += p2p_attr_channel_list()
  687. #attrs += p2p_attr_group_id(src, "DIRECT-foo")
  688. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  689. msg['payload'] += ie_p2p(attrs)
  690. hapd.mgmt_tx(msg)
  691. if hapd.mgmt_rx(timeout=1) is None:
  692. raise Exception("No invitation response " + str(dialog_token))
  693. time.sleep(0.1)
  694. dev[0].dump_monitor()
  695. dialog_token += 1
  696. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  697. attrs = p2p_attr_config_timeout()
  698. attrs = p2p_attr_invitation_flags()
  699. attrs += p2p_attr_operating_channel()
  700. attrs += p2p_attr_group_bssid(src)
  701. attrs += p2p_attr_channel_list()
  702. attrs += p2p_attr_group_id(src, "DIRECT-foo")
  703. #attrs += p2p_attr_device_info(src, config_methods=0x0108)
  704. msg['payload'] += ie_p2p(attrs)
  705. hapd.mgmt_tx(msg)
  706. if hapd.mgmt_rx(timeout=1) is None:
  707. raise Exception("No invitation response " + str(dialog_token))
  708. time.sleep(0.1)
  709. dev[0].dump_monitor()
  710. dialog_token += 1
  711. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  712. hapd.mgmt_tx(msg)
  713. if hapd.mgmt_rx(timeout=1) is None:
  714. raise Exception("No invitation response " + str(dialog_token))
  715. # Unusable peer operating channel preference
  716. time.sleep(0.1)
  717. dev[0].dump_monitor()
  718. dialog_token += 1
  719. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  720. attrs = p2p_attr_config_timeout()
  721. attrs = p2p_attr_invitation_flags()
  722. attrs += p2p_attr_operating_channel(chan=15)
  723. attrs += p2p_attr_group_bssid(src)
  724. attrs += p2p_attr_channel_list()
  725. attrs += p2p_attr_group_id(src, "DIRECT-foo")
  726. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  727. msg['payload'] += ie_p2p(attrs)
  728. hapd.mgmt_tx(msg)
  729. if hapd.mgmt_rx(timeout=1) is None:
  730. raise Exception("No invitation response " + str(dialog_token))
  731. def test_p2p_msg_invitation_req_to_go(dev, apdev):
  732. """P2P protocol tests for invitation request processing on GO device"""
  733. res = form(dev[0], dev[1])
  734. dev[0].dump_monitor()
  735. dev[1].dump_monitor()
  736. addr0 = dev[0].p2p_dev_addr()
  737. addr1 = dev[1].p2p_dev_addr()
  738. peer = dev[1].get_peer(addr0)
  739. listen_freq = peer['listen_freq']
  740. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
  741. raise Exception("Failed to enable external management frame handling")
  742. networks = dev[0].list_networks()
  743. if len(networks) != 1:
  744. raise Exception("Unexpected number of networks")
  745. if "[P2P-PERSISTENT]" not in networks[0]['flags']:
  746. raise Exception("Not the persistent group data")
  747. dev[0].p2p_start_go(persistent=networks[0]['id'], freq=listen_freq)
  748. dialog_token = 0
  749. # Unusable peer operating channel preference
  750. dialog_token += 1
  751. msg = p2p_hdr(addr0, addr1, type=P2P_INVITATION_REQ,
  752. dialog_token=dialog_token)
  753. attrs = p2p_attr_config_timeout()
  754. attrs = p2p_attr_invitation_flags(bitmap=1)
  755. attrs += p2p_attr_operating_channel(chan=15)
  756. attrs += p2p_attr_channel_list()
  757. attrs += p2p_attr_group_id(res['go_dev_addr'], res['ssid'])
  758. attrs += p2p_attr_device_info(addr1, config_methods=0x0108)
  759. msg['payload'] += ie_p2p(attrs)
  760. mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0, addr0, peer['listen_freq'], binascii.hexlify(msg['payload'])))
  761. rx_msg = dev[1].mgmt_rx()
  762. if rx_msg is None:
  763. raise Exception("MGMT-RX timeout")
  764. p2p = parse_p2p_public_action(rx_msg['payload'])
  765. if p2p is None:
  766. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  767. if p2p['subtype'] != P2P_INVITATION_RESP:
  768. raise Exception("Unexpected subtype %d" % p2p['subtype'])
  769. if p2p['p2p_status'] != 0:
  770. raise Exception("Unexpected status %d" % p2p['p2p_status'])
  771. # Forced channel re-selection due to channel list
  772. dialog_token += 1
  773. msg = p2p_hdr(addr0, addr1, type=P2P_INVITATION_REQ,
  774. dialog_token=dialog_token)
  775. attrs = p2p_attr_config_timeout()
  776. attrs = p2p_attr_invitation_flags(bitmap=1)
  777. attrs += struct.pack("<BH3BBBB", P2P_ATTR_CHANNEL_LIST, 6,
  778. 0x58, 0x58, 0x04,
  779. 81, 1, 3)
  780. attrs += p2p_attr_group_id(res['go_dev_addr'], res['ssid'])
  781. attrs += p2p_attr_device_info(addr1, config_methods=0x0108)
  782. msg['payload'] += ie_p2p(attrs)
  783. mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0, addr0, peer['listen_freq'], binascii.hexlify(msg['payload'])))
  784. rx_msg = dev[1].mgmt_rx()
  785. if rx_msg is None:
  786. raise Exception("MGMT-RX timeout")
  787. p2p = parse_p2p_public_action(rx_msg['payload'])
  788. if p2p is None:
  789. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  790. if p2p['subtype'] != P2P_INVITATION_RESP:
  791. raise Exception("Unexpected subtype %d" % p2p['subtype'])
  792. if p2p['p2p_status'] != 7 and dev[1].get_mcc() <= 1:
  793. raise Exception("Unexpected status %d" % p2p['p2p_status'])
  794. def test_p2p_msg_invitation_req_unknown(dev, apdev):
  795. """P2P protocol tests for invitation request from unknown peer"""
  796. dst, src, hapd, channel = start_p2p(dev, apdev)
  797. dialog_token = 0
  798. dialog_token += 1
  799. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  800. attrs = p2p_attr_config_timeout()
  801. attrs += p2p_attr_invitation_flags()
  802. attrs += p2p_attr_operating_channel()
  803. attrs += p2p_attr_group_bssid(src)
  804. attrs += p2p_attr_channel_list()
  805. #attrs += p2p_attr_group_id(src, "DIRECT-foo")
  806. #attrs += p2p_attr_device_info(src, config_methods=0x0108)
  807. msg['payload'] += ie_p2p(attrs)
  808. hapd.mgmt_tx(msg)
  809. ev = dev[0].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=5)
  810. if ev is None:
  811. raise Exception("Timeout on invitation event " + str(dialog_token))
  812. if hapd.mgmt_rx(timeout=1) is None:
  813. raise Exception("No invitation response " + str(dialog_token))
  814. def test_p2p_msg_invitation_no_common_channels(dev, apdev):
  815. """P2P protocol tests for invitation request without common channels"""
  816. dst, src, hapd, channel = start_p2p(dev, apdev)
  817. dialog_token = 0
  818. dialog_token += 1
  819. msg = p2p_hdr(dst, src, type=P2P_INVITATION_REQ, dialog_token=dialog_token)
  820. attrs = p2p_attr_config_timeout()
  821. attrs += p2p_attr_invitation_flags()
  822. attrs += p2p_attr_operating_channel()
  823. attrs += p2p_attr_group_bssid(src)
  824. attrs += struct.pack("<BH3BBB", P2P_ATTR_CHANNEL_LIST, 5,
  825. 0x58, 0x58, 0x04,
  826. 81, 0)
  827. attrs += p2p_attr_group_id(src, "DIRECT-foo")
  828. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  829. msg['payload'] += ie_p2p(attrs)
  830. hapd.mgmt_tx(msg)
  831. if hapd.mgmt_rx(timeout=1) is None:
  832. raise Exception("No invitation response " + str(dialog_token))
  833. ev = dev[0].wait_event(["P2P-INVITATION-RECEIVED"], timeout=0.1)
  834. if ev is not None:
  835. raise Exception("Unexpected invitation event")
  836. def test_p2p_msg_invitation_resp(dev, apdev):
  837. """P2P protocol tests for invitation response processing"""
  838. form(dev[0], dev[1])
  839. dev[0].dump_monitor()
  840. dev[1].dump_monitor()
  841. dst, src, hapd, channel = start_p2p(dev, apdev)
  842. addr0 = dev[0].p2p_dev_addr()
  843. addr1 = dev[1].p2p_dev_addr()
  844. peer = dev[1].get_peer(addr0)
  845. # P2P Invitation Response from unknown peer
  846. msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=1)
  847. hapd.mgmt_tx(msg)
  848. # P2P Invitation Response from peer that is not in invitation
  849. msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=2)
  850. attrs = p2p_attr_status()
  851. msg['payload'] += ie_p2p(attrs)
  852. mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0, addr0, peer['listen_freq'], binascii.hexlify(msg['payload'])))
  853. time.sleep(0.25)
  854. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
  855. raise Exception("Failed to enable external management frame handling")
  856. invite(dev[0], dev[1])
  857. rx_msg = dev[1].mgmt_rx()
  858. if rx_msg is None:
  859. raise Exception("MGMT-RX timeout")
  860. p2p = parse_p2p_public_action(rx_msg['payload'])
  861. if p2p is None:
  862. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  863. if p2p['subtype'] != P2P_INVITATION_REQ:
  864. raise Exception("Unexpected subtype %d" % p2p['subtype'])
  865. # Invalid attribute to cause p2p_parse() failure
  866. msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=p2p['dialog_token'])
  867. attrs = struct.pack("<BB", P2P_ATTR_CAPABILITY, 0)
  868. msg['payload'] += ie_p2p(attrs)
  869. mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload'])))
  870. invite(dev[0], dev[1])
  871. rx_msg = dev[1].mgmt_rx()
  872. if rx_msg is None:
  873. raise Exception("MGMT-RX timeout")
  874. p2p = parse_p2p_public_action(rx_msg['payload'])
  875. if p2p is None:
  876. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  877. if p2p['subtype'] != P2P_INVITATION_REQ:
  878. raise Exception("Unexpected subtype %d" % p2p['subtype'])
  879. # missing mandatory Status attribute
  880. msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=p2p['dialog_token'])
  881. attrs = p2p_attr_channel_list()
  882. msg['payload'] += ie_p2p(attrs)
  883. mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload'])))
  884. invite(dev[0], dev[1])
  885. rx_msg = dev[1].mgmt_rx()
  886. if rx_msg is None:
  887. raise Exception("MGMT-RX timeout")
  888. p2p = parse_p2p_public_action(rx_msg['payload'])
  889. if p2p is None:
  890. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  891. if p2p['subtype'] != P2P_INVITATION_REQ:
  892. raise Exception("Unexpected subtype %d" % p2p['subtype'])
  893. # no channel match (no common channel found at all)
  894. msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=p2p['dialog_token'])
  895. attrs = p2p_attr_status()
  896. attrs += struct.pack("<BH3BBBB", P2P_ATTR_CHANNEL_LIST, 6,
  897. 0x58, 0x58, 0x04,
  898. 81, 1, 15)
  899. msg['payload'] += ie_p2p(attrs)
  900. mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload'])))
  901. invite(dev[0], dev[1])
  902. rx_msg = dev[1].mgmt_rx()
  903. if rx_msg is None:
  904. raise Exception("MGMT-RX timeout")
  905. p2p = parse_p2p_public_action(rx_msg['payload'])
  906. if p2p is None:
  907. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  908. if p2p['subtype'] != P2P_INVITATION_REQ:
  909. raise Exception("Unexpected subtype %d" % p2p['subtype'])
  910. # no channel match (no acceptable P2P channel)
  911. msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=p2p['dialog_token'])
  912. attrs = p2p_attr_status()
  913. attrs += struct.pack("<BH3BBBB", P2P_ATTR_CHANNEL_LIST, 6,
  914. 0x58, 0x58, 0x04,
  915. 81, 1, 12)
  916. msg['payload'] += ie_p2p(attrs)
  917. mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload'])))
  918. invite(dev[0], dev[1])
  919. rx_msg = dev[1].mgmt_rx()
  920. if rx_msg is None:
  921. raise Exception("MGMT-RX timeout")
  922. p2p = parse_p2p_public_action(rx_msg['payload'])
  923. if p2p is None:
  924. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  925. if p2p['subtype'] != P2P_INVITATION_REQ:
  926. raise Exception("Unexpected subtype %d" % p2p['subtype'])
  927. # missing mandatory Channel List attribute (ignored as a workaround)
  928. msg = p2p_hdr(dst, src, type=P2P_INVITATION_RESP, dialog_token=p2p['dialog_token'])
  929. attrs = p2p_attr_status()
  930. msg['payload'] += ie_p2p(attrs)
  931. mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload'])))
  932. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15);
  933. if ev is None:
  934. raise Exception("Group was not started")
  935. def test_p2p_msg_invitation_resend(dev, apdev):
  936. """P2P protocol tests for invitation resending on no-common-channels"""
  937. form(dev[0], dev[1])
  938. dev[0].dump_monitor()
  939. dev[1].dump_monitor()
  940. addr0 = dev[0].p2p_dev_addr()
  941. addr1 = dev[1].p2p_dev_addr()
  942. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
  943. raise Exception("Failed to enable external management frame handling")
  944. logger.info("Forced channel in invitation")
  945. invite(dev[0], dev[1], extra="freq=2422")
  946. rx_msg = dev[1].mgmt_rx()
  947. if rx_msg is None:
  948. raise Exception("MGMT-RX timeout")
  949. p2p = parse_p2p_public_action(rx_msg['payload'])
  950. if p2p is None:
  951. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  952. if p2p['subtype'] != P2P_INVITATION_REQ:
  953. raise Exception("Unexpected subtype %d" % p2p['subtype'])
  954. msg = p2p_hdr(addr0, addr1, type=P2P_INVITATION_RESP,
  955. dialog_token=p2p['dialog_token'])
  956. attrs = p2p_attr_status(status=P2P_SC_FAIL_NO_COMMON_CHANNELS)
  957. msg['payload'] += ie_p2p(attrs)
  958. mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload'])))
  959. ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
  960. if ev is None:
  961. raise Exception("Timeout on invitation result");
  962. if "status=7" not in ev:
  963. raise Exception("Unexpected invitation result: " + ev)
  964. logger.info("Any channel allowed, only preference provided in invitation");
  965. invite(dev[0], dev[1], extra="pref=2422")
  966. rx_msg = dev[1].mgmt_rx()
  967. if rx_msg is None:
  968. raise Exception("MGMT-RX timeout")
  969. p2p = parse_p2p_public_action(rx_msg['payload'])
  970. if p2p is None:
  971. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  972. if p2p['subtype'] != P2P_INVITATION_REQ:
  973. raise Exception("Unexpected subtype %d" % p2p['subtype'])
  974. msg = p2p_hdr(addr0, addr1, type=P2P_INVITATION_RESP,
  975. dialog_token=p2p['dialog_token'])
  976. attrs = p2p_attr_status(status=P2P_SC_FAIL_NO_COMMON_CHANNELS)
  977. msg['payload'] += ie_p2p(attrs)
  978. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 0"):
  979. raise Exception("Failed to disable external management frame handling")
  980. mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload'])))
  981. ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
  982. if ev is None:
  983. raise Exception("Timeout on invitation result");
  984. if "status=0" not in ev:
  985. raise Exception("Unexpected invitation result: " + ev)
  986. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15);
  987. if ev is None:
  988. raise Exception("Group was not started on dev0")
  989. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15);
  990. if ev is None:
  991. raise Exception("Group was not started on dev1")
  992. def test_p2p_msg_invitation_resend_duplicate(dev, apdev):
  993. """P2P protocol tests for invitation resending on no-common-channels and duplicated response"""
  994. form(dev[0], dev[1])
  995. dev[0].dump_monitor()
  996. dev[1].dump_monitor()
  997. addr0 = dev[0].p2p_dev_addr()
  998. addr1 = dev[1].p2p_dev_addr()
  999. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
  1000. raise Exception("Failed to enable external management frame handling")
  1001. logger.info("Any channel allowed, only preference provided in invitation");
  1002. invite(dev[0], dev[1], extra="pref=2422")
  1003. rx_msg = dev[1].mgmt_rx()
  1004. if rx_msg is None:
  1005. raise Exception("MGMT-RX timeout")
  1006. p2p = parse_p2p_public_action(rx_msg['payload'])
  1007. if p2p is None:
  1008. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  1009. if p2p['subtype'] != P2P_INVITATION_REQ:
  1010. raise Exception("Unexpected subtype %d" % p2p['subtype'])
  1011. msg = p2p_hdr(addr0, addr1, type=P2P_INVITATION_RESP,
  1012. dialog_token=p2p['dialog_token'])
  1013. attrs = p2p_attr_status(status=P2P_SC_FAIL_NO_COMMON_CHANNELS)
  1014. msg['payload'] += ie_p2p(attrs)
  1015. mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload'])))
  1016. rx_msg = dev[1].mgmt_rx()
  1017. if rx_msg is None:
  1018. raise Exception("MGMT-RX timeout")
  1019. p2p = parse_p2p_public_action(rx_msg['payload'])
  1020. if p2p is None:
  1021. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  1022. if p2p['subtype'] != P2P_INVITATION_REQ:
  1023. raise Exception("Unexpected subtype %d" % p2p['subtype'])
  1024. logger.info("Retransmit duplicate of previous response")
  1025. mgmt_tx(dev[1], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload'])))
  1026. logger.info("Transmit real response")
  1027. msg = p2p_hdr(addr0, addr1, type=P2P_INVITATION_RESP,
  1028. dialog_token=p2p['dialog_token'])
  1029. attrs = p2p_attr_status(status=P2P_SC_SUCCESS)
  1030. attrs += p2p_attr_channel_list()
  1031. msg['payload'] += ie_p2p(attrs)
  1032. if "FAIL" in dev[1].request("MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr0, addr0, rx_msg['freq'], binascii.hexlify(msg['payload']))):
  1033. raise Exception("Failed to transmit real response")
  1034. dev[1].request("SET ext_mgmt_frame_handling 0")
  1035. ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
  1036. if ev is None:
  1037. raise Exception("Timeout on invitation result");
  1038. if "status=0" not in ev:
  1039. raise Exception("Unexpected invitation result: " + ev)
  1040. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
  1041. if ev is None:
  1042. raise Exception("Group formation timed out")
  1043. dev[0].group_form_result(ev)
  1044. dev[0].remove_group()
  1045. def test_p2p_msg_pd_req(dev, apdev):
  1046. """P2P protocol tests for provision discovery request processing"""
  1047. dst, src, hapd, channel = start_p2p(dev, apdev)
  1048. dialog_token = 0
  1049. # Too short attribute header
  1050. dialog_token += 1
  1051. msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
  1052. attrs = struct.pack("<BB", P2P_ATTR_CAPABILITY, 0)
  1053. msg['payload'] += ie_p2p(attrs)
  1054. hapd.mgmt_tx(msg)
  1055. if hapd.mgmt_rx(timeout=0.5) is not None:
  1056. raise Exception("Unexpected management frame received")
  1057. # No attributes
  1058. dialog_token += 1
  1059. msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
  1060. attrs = ""
  1061. msg['payload'] += ie_p2p(attrs)
  1062. hapd.mgmt_tx(msg)
  1063. if hapd.mgmt_rx(timeout=1) is None:
  1064. raise Exception("No PD response " + str(dialog_token))
  1065. # Valid request
  1066. time.sleep(0.1)
  1067. dialog_token += 1
  1068. msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
  1069. attrs = wsc_attr_config_methods(methods=0x1008)
  1070. msg['payload'] += ie_wsc(attrs)
  1071. attrs = p2p_attr_capability()
  1072. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  1073. msg['payload'] += ie_p2p(attrs)
  1074. hapd.mgmt_tx(msg)
  1075. ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
  1076. if ev is None:
  1077. raise Exception("Timeout on device found event")
  1078. ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
  1079. if ev is None:
  1080. raise Exception("Timeout on PD event")
  1081. if hapd.mgmt_rx(timeout=1) is None:
  1082. raise Exception("No PD response " + str(dialog_token))
  1083. # Unknown group
  1084. time.sleep(0.1)
  1085. dialog_token += 1
  1086. msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
  1087. attrs = wsc_attr_config_methods(methods=0x1008)
  1088. msg['payload'] += ie_wsc(attrs)
  1089. attrs = p2p_attr_capability()
  1090. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  1091. attrs += p2p_attr_group_id("02:02:02:02:02:02", "DIRECT-foo")
  1092. msg['payload'] += ie_p2p(attrs)
  1093. hapd.mgmt_tx(msg)
  1094. if hapd.mgmt_rx(timeout=1) is None:
  1095. raise Exception("No PD response " + str(dialog_token))
  1096. ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=1)
  1097. if ev is not None:
  1098. raise Exception("Unexpected PD event")
  1099. # Listen channel is not yet known
  1100. if "FAIL" not in dev[0].global_request("P2P_PROV_DISC " + src + " display"):
  1101. raise Exception("Unexpected P2P_PROV_DISC success")
  1102. # Unknown peer
  1103. if "FAIL" not in dev[0].global_request("P2P_PROV_DISC 02:03:04:05:06:07 display"):
  1104. raise Exception("Unexpected P2P_PROV_DISC success (2)")
  1105. def test_p2p_msg_pd(dev, apdev):
  1106. """P2P protocol tests for provision discovery request processing (known)"""
  1107. dst, src, hapd, channel = start_p2p(dev, apdev)
  1108. dialog_token = 0
  1109. p2p_probe(hapd, src, chan=channel)
  1110. time.sleep(0.1)
  1111. # Valid request
  1112. dialog_token += 1
  1113. msg = p2p_hdr(dst, src, type=P2P_PROV_DISC_REQ, dialog_token=dialog_token)
  1114. attrs = wsc_attr_config_methods(methods=0x1008)
  1115. msg['payload'] += ie_wsc(attrs)
  1116. attrs = p2p_attr_capability()
  1117. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  1118. msg['payload'] += ie_p2p(attrs)
  1119. hapd.mgmt_tx(msg)
  1120. ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
  1121. if ev is None:
  1122. raise Exception("Timeout on device found event")
  1123. ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
  1124. if ev is None:
  1125. raise Exception("Timeout on PD event")
  1126. if hapd.mgmt_rx(timeout=1) is None:
  1127. raise Exception("No PD response " + str(dialog_token))
  1128. if "FAIL" in dev[0].global_request("P2P_PROV_DISC " + src + " display"):
  1129. raise Exception("Unexpected P2P_PROV_DISC failure")
  1130. frame = hapd.mgmt_rx(timeout=1)
  1131. if frame is None:
  1132. raise Exception("No PD request " + str(dialog_token))
  1133. p2p = parse_p2p_public_action(frame['payload'])
  1134. if p2p is None:
  1135. raise Exception("Failed to parse PD request")
  1136. # invalid dialog token
  1137. msg = p2p_hdr_resp(dst, src, type=P2P_PROV_DISC_RESP,
  1138. dialog_token=p2p['dialog_token'] + 1)
  1139. hapd.mgmt_tx(msg)
  1140. ev = dev[0].wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout=0.1)
  1141. if ev is not None:
  1142. raise Exception("Unexpected PD result event")
  1143. # valid dialog token
  1144. msg = p2p_hdr_resp(dst, src, type=P2P_PROV_DISC_RESP,
  1145. dialog_token=p2p['dialog_token'])
  1146. hapd.mgmt_tx(msg)
  1147. ev = dev[0].wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout=5)
  1148. if ev is None:
  1149. raise Exception("Timeout on PD result event")
  1150. # valid dialog token
  1151. msg = p2p_hdr_resp(dst, src, type=P2P_PROV_DISC_RESP,
  1152. dialog_token=p2p['dialog_token'])
  1153. hapd.mgmt_tx(msg)
  1154. ev = dev[0].wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout=0.1)
  1155. if ev is not None:
  1156. raise Exception("Unexpected PD result event")
  1157. def check_p2p_response(hapd, dialog_token, status):
  1158. resp = hapd.mgmt_rx(timeout=2)
  1159. if resp is None:
  1160. raise Exception("No GO Neg Response " + str(dialog_token))
  1161. p2p = parse_p2p_public_action(resp['payload'])
  1162. if p2p is None:
  1163. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  1164. if dialog_token != p2p['dialog_token']:
  1165. raise Exception("Unexpected dialog token in response")
  1166. if p2p['p2p_status'] != status:
  1167. raise Exception("Unexpected status code %s in response (expected %d)" % (p2p['p2p_status'], status))
  1168. def test_p2p_msg_go_neg_both_start(dev, apdev):
  1169. """P2P protocol test for simultaneous GO Neg initiation"""
  1170. addr0 = dev[0].p2p_dev_addr()
  1171. addr1 = dev[1].p2p_dev_addr()
  1172. dev[0].p2p_listen()
  1173. dev[1].discover_peer(addr0)
  1174. dev[1].p2p_listen()
  1175. dev[0].discover_peer(addr1)
  1176. dev[0].p2p_listen()
  1177. if "FAIL" in dev[0].request("SET ext_mgmt_frame_handling 1"):
  1178. raise Exception("Failed to enable external management frame handling")
  1179. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 1"):
  1180. raise Exception("Failed to enable external management frame handling")
  1181. dev[0].request("P2P_CONNECT {} pbc".format(addr1))
  1182. dev[1].request("P2P_CONNECT {} pbc".format(addr0))
  1183. msg = dev[0].mgmt_rx()
  1184. if msg is None:
  1185. raise Exception("MGMT-RX timeout")
  1186. msg = dev[1].mgmt_rx()
  1187. if msg is None:
  1188. raise Exception("MGMT-RX timeout(2)")
  1189. if "FAIL" in dev[0].request("SET ext_mgmt_frame_handling 0"):
  1190. raise Exception("Failed to disable external management frame handling")
  1191. ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=2)
  1192. if ev is not None:
  1193. raise Exception("Unexpected GO Neg success")
  1194. if "FAIL" in dev[1].request("SET ext_mgmt_frame_handling 0"):
  1195. raise Exception("Failed to disable external management frame handling")
  1196. ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10)
  1197. if ev is None:
  1198. raise Exception("GO Neg did not succeed")
  1199. ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5);
  1200. if ev is None:
  1201. raise Exception("Group formation not succeed")
  1202. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=5);
  1203. if ev is None:
  1204. raise Exception("Group formation not succeed")
  1205. def test_p2p_msg_go_neg_req(dev, apdev):
  1206. """P2P protocol tests for invitation request from unknown peer"""
  1207. dst, src, hapd, channel = start_p2p(dev, apdev)
  1208. dialog_token = 0
  1209. # invalid attribute
  1210. dialog_token += 1
  1211. msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
  1212. attrs = struct.pack("<BB", P2P_ATTR_CAPABILITY, 0)
  1213. msg['payload'] += ie_p2p(attrs)
  1214. hapd.mgmt_tx(msg)
  1215. frame = hapd.mgmt_rx(timeout=0.1)
  1216. if frame is not None:
  1217. print frame
  1218. raise Exception("Unexpected GO Neg Response")
  1219. # missing atributes
  1220. dialog_token += 1
  1221. msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
  1222. attrs = p2p_attr_capability()
  1223. attrs += p2p_attr_go_intent()
  1224. attrs += p2p_attr_config_timeout()
  1225. #attrs += p2p_attr_listen_channel()
  1226. attrs += p2p_attr_ext_listen_timing()
  1227. attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
  1228. attrs += p2p_attr_channel_list()
  1229. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  1230. attrs += p2p_attr_operating_channel()
  1231. msg['payload'] += ie_p2p(attrs)
  1232. hapd.mgmt_tx(msg)
  1233. if hapd.mgmt_rx(timeout=2) is None:
  1234. raise Exception("No GO Neg Response " + str(dialog_token))
  1235. time.sleep(0.1)
  1236. dialog_token += 1
  1237. msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
  1238. attrs = p2p_attr_capability()
  1239. attrs += p2p_attr_go_intent()
  1240. attrs += p2p_attr_config_timeout()
  1241. attrs += p2p_attr_listen_channel()
  1242. attrs += p2p_attr_ext_listen_timing()
  1243. attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
  1244. attrs += p2p_attr_channel_list()
  1245. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  1246. #attrs += p2p_attr_operating_channel()
  1247. msg['payload'] += ie_p2p(attrs)
  1248. hapd.mgmt_tx(msg)
  1249. if hapd.mgmt_rx(timeout=2) is None:
  1250. raise Exception("No GO Neg Response " + str(dialog_token))
  1251. time.sleep(0.1)
  1252. dialog_token += 1
  1253. msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
  1254. attrs = p2p_attr_capability()
  1255. attrs += p2p_attr_go_intent()
  1256. attrs += p2p_attr_config_timeout()
  1257. attrs += p2p_attr_listen_channel()
  1258. attrs += p2p_attr_ext_listen_timing()
  1259. attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
  1260. #attrs += p2p_attr_channel_list()
  1261. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  1262. attrs += p2p_attr_operating_channel()
  1263. msg['payload'] += ie_p2p(attrs)
  1264. hapd.mgmt_tx(msg)
  1265. if hapd.mgmt_rx(timeout=2) is None:
  1266. raise Exception("No GO Neg Response " + str(dialog_token))
  1267. time.sleep(0.1)
  1268. dialog_token += 1
  1269. msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
  1270. attrs = p2p_attr_capability()
  1271. attrs += p2p_attr_go_intent()
  1272. attrs += p2p_attr_config_timeout()
  1273. attrs += p2p_attr_listen_channel()
  1274. attrs += p2p_attr_ext_listen_timing()
  1275. #attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
  1276. attrs += p2p_attr_channel_list()
  1277. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  1278. attrs += p2p_attr_operating_channel()
  1279. msg['payload'] += ie_p2p(attrs)
  1280. hapd.mgmt_tx(msg)
  1281. if hapd.mgmt_rx(timeout=2) is None:
  1282. raise Exception("No GO Neg Response " + str(dialog_token))
  1283. time.sleep(0.1)
  1284. dialog_token += 1
  1285. msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
  1286. attrs = p2p_attr_capability()
  1287. attrs += p2p_attr_go_intent()
  1288. attrs += p2p_attr_config_timeout()
  1289. attrs += p2p_attr_listen_channel()
  1290. attrs += p2p_attr_ext_listen_timing()
  1291. attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
  1292. attrs += p2p_attr_channel_list()
  1293. #attrs += p2p_attr_device_info(src, config_methods=0x0108)
  1294. attrs += p2p_attr_operating_channel()
  1295. msg['payload'] += ie_p2p(attrs)
  1296. hapd.mgmt_tx(msg)
  1297. if hapd.mgmt_rx(timeout=2) is None:
  1298. raise Exception("No GO Neg Response " + str(dialog_token))
  1299. time.sleep(0.1)
  1300. # SA != P2P Device address
  1301. dialog_token += 1
  1302. msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
  1303. attrs = p2p_attr_capability()
  1304. attrs += p2p_attr_go_intent()
  1305. attrs += p2p_attr_config_timeout()
  1306. attrs += p2p_attr_listen_channel()
  1307. attrs += p2p_attr_ext_listen_timing()
  1308. attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
  1309. attrs += p2p_attr_channel_list()
  1310. attrs += p2p_attr_device_info("02:02:02:02:02:02", config_methods=0x0108)
  1311. attrs += p2p_attr_operating_channel()
  1312. msg['payload'] += ie_p2p(attrs)
  1313. hapd.mgmt_tx(msg)
  1314. if hapd.mgmt_rx(timeout=2) is None:
  1315. raise Exception("No GO Neg Response " + str(dialog_token))
  1316. time.sleep(0.1)
  1317. # unexpected Status attribute
  1318. dialog_token += 1
  1319. msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
  1320. attrs = p2p_attr_capability()
  1321. attrs += p2p_attr_go_intent()
  1322. attrs += p2p_attr_config_timeout()
  1323. attrs += p2p_attr_listen_channel()
  1324. attrs += p2p_attr_ext_listen_timing()
  1325. attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
  1326. attrs += p2p_attr_channel_list()
  1327. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  1328. attrs += p2p_attr_operating_channel()
  1329. attrs += p2p_attr_status(status=P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE)
  1330. msg['payload'] += ie_p2p(attrs)
  1331. hapd.mgmt_tx(msg)
  1332. if hapd.mgmt_rx(timeout=2) is None:
  1333. raise Exception("No GO Neg Response(1) " + str(dialog_token))
  1334. time.sleep(0.1)
  1335. # valid (with workarounds) GO Neg Req
  1336. dialog_token += 1
  1337. msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
  1338. #attrs = p2p_attr_capability()
  1339. #attrs += p2p_attr_go_intent()
  1340. #attrs += p2p_attr_config_timeout()
  1341. attrs = p2p_attr_listen_channel()
  1342. attrs += p2p_attr_ext_listen_timing()
  1343. attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
  1344. attrs += p2p_attr_channel_list()
  1345. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  1346. attrs += p2p_attr_operating_channel()
  1347. msg['payload'] += ie_p2p(attrs)
  1348. hapd.mgmt_tx(msg)
  1349. check_p2p_response(hapd, dialog_token,
  1350. P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE)
  1351. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=2)
  1352. if ev is None:
  1353. raise Exception("Timeout on GO Neg event " + str(dialog_token))
  1354. dev[0].request("P2P_CONNECT " + src + " 12345670 display auth")
  1355. # ready - missing attributes (with workarounds) GO Neg Req
  1356. time.sleep(0.1)
  1357. dialog_token += 1
  1358. msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
  1359. #attrs = p2p_attr_capability()
  1360. #attrs += p2p_attr_go_intent()
  1361. #attrs += p2p_attr_config_timeout()
  1362. attrs = p2p_attr_listen_channel()
  1363. attrs += p2p_attr_ext_listen_timing()
  1364. attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
  1365. attrs += p2p_attr_channel_list()
  1366. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  1367. attrs += p2p_attr_operating_channel()
  1368. msg['payload'] += ie_p2p(attrs)
  1369. hapd.mgmt_tx(msg)
  1370. if hapd.mgmt_rx(timeout=2) is None:
  1371. raise Exception("No GO Neg Response " + str(dialog_token))
  1372. # ready - invalid GO Intent GO Neg Req
  1373. time.sleep(0.1)
  1374. dialog_token += 1
  1375. msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
  1376. #attrs = p2p_attr_capability()
  1377. attrs = p2p_attr_go_intent(go_intent=16)
  1378. #attrs += p2p_attr_config_timeout()
  1379. attrs += p2p_attr_listen_channel()
  1380. attrs += p2p_attr_ext_listen_timing()
  1381. attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
  1382. attrs += p2p_attr_channel_list()
  1383. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  1384. attrs += p2p_attr_operating_channel()
  1385. msg['payload'] += ie_p2p(attrs)
  1386. hapd.mgmt_tx(msg)
  1387. check_p2p_response(hapd, dialog_token, P2P_SC_FAIL_INVALID_PARAMS)
  1388. # ready - invalid Channel List
  1389. time.sleep(0.1)
  1390. dialog_token += 1
  1391. msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
  1392. attrs = p2p_attr_capability()
  1393. attrs += p2p_attr_go_intent()
  1394. attrs += p2p_attr_config_timeout()
  1395. attrs += p2p_attr_listen_channel()
  1396. attrs += p2p_attr_ext_listen_timing()
  1397. attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
  1398. attrs += struct.pack("<BH3BBB11B", P2P_ATTR_CHANNEL_LIST, 16,
  1399. 0x58, 0x58, 0x04,
  1400. 81, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
  1401. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  1402. attrs += p2p_attr_operating_channel()
  1403. msg['payload'] += ie_p2p(attrs)
  1404. hapd.mgmt_tx(msg)
  1405. check_p2p_response(hapd, dialog_token, P2P_SC_FAIL_NO_COMMON_CHANNELS)
  1406. # ready - invalid GO Neg Req (unsupported Device Password ID)
  1407. time.sleep(0.1)
  1408. dialog_token += 1
  1409. msg = p2p_hdr(dst, src, type=P2P_GO_NEG_REQ, dialog_token=dialog_token)
  1410. attrs = p2p_attr_capability()
  1411. attrs += p2p_attr_go_intent()
  1412. attrs += p2p_attr_config_timeout()
  1413. attrs += p2p_attr_listen_channel()
  1414. attrs += p2p_attr_ext_listen_timing()
  1415. attrs += p2p_attr_intended_interface_addr("02:02:02:02:02:02")
  1416. # very long channel list
  1417. attrs += struct.pack("<BH3BBB11B30B", P2P_ATTR_CHANNEL_LIST, 46,
  1418. 0x58, 0x58, 0x04,
  1419. 81, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
  1420. 1, 1, 1, 2, 1, 2, 3, 1, 3, 4, 1, 4, 5, 1, 5,
  1421. 6, 1, 6, 7, 1, 7, 8, 1, 8, 9, 1, 9, 10, 1, 10)
  1422. attrs += p2p_attr_device_info(src, config_methods=0x0108)
  1423. attrs += p2p_attr_operating_channel()
  1424. msg['payload'] += ie_p2p(attrs)
  1425. hapd.mgmt_tx(msg)
  1426. check_p2p_response(hapd, dialog_token, P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD)
  1427. def mgmt_tx(dev, msg):
  1428. for i in range(0, 20):
  1429. if "FAIL" in dev.request(msg):
  1430. raise Exception("Failed to send Action frame")
  1431. ev = dev.wait_event(["MGMT-TX-STATUS"], timeout=10)
  1432. if ev is None:
  1433. raise Exception("Timeout on MGMT-TX-STATUS")
  1434. if "result=SUCCESS" in ev:
  1435. break
  1436. time.sleep(0.01)
  1437. if "result=SUCCESS" not in ev:
  1438. raise Exception("Peer did not ack Action frame")
  1439. def rx_go_neg_req(dev):
  1440. msg = dev.mgmt_rx()
  1441. if msg is None:
  1442. raise Exception("MGMT-RX timeout")
  1443. p2p = parse_p2p_public_action(msg['payload'])
  1444. if p2p is None:
  1445. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  1446. if p2p['subtype'] != P2P_GO_NEG_REQ:
  1447. raise Exception("Unexpected subtype %d" % p2p['subtype'])
  1448. p2p['freq'] = msg['freq']
  1449. return p2p
  1450. def rx_go_neg_conf(dev, status=None, dialog_token=None):
  1451. msg = dev.mgmt_rx()
  1452. if msg is None:
  1453. raise Exception("MGMT-RX timeout")
  1454. p2p = parse_p2p_public_action(msg['payload'])
  1455. if p2p is None:
  1456. raise Exception("Not a P2P Public Action frame " + str(dialog_token))
  1457. if p2p['subtype'] != P2P_GO_NEG_CONF:
  1458. raise Exception("Unexpected subtype %d" % p2p['subtype'])
  1459. if dialog_token is not None and dialog_token != p2p['dialog_token']:
  1460. raise Exception("Unexpected dialog token")
  1461. if status is not None and p2p['p2p_status'] != status:
  1462. raise Exception("Unexpected status %d" % p2p['p2p_status'])
  1463. def check_p2p_go_neg_fail_event(dev, status):
  1464. ev = dev.wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=5)
  1465. if ev is None:
  1466. raise Exception("GO Negotiation failure not reported")
  1467. if "status=%d" % status not in ev:
  1468. raise Exception("Unexpected failure reason: " + ev)
  1469. def test_p2p_msg_go_neg_req_reject(dev, apdev):
  1470. """P2P protocol tests for user reject incorrectly in GO Neg Req"""
  1471. addr0 = dev[0].p2p_dev_addr()
  1472. addr1 = dev[1].p2p_dev_addr()
  1473. dev[0].p2p_listen()
  1474. dev[1].discover_peer(addr0)
  1475. dev[1].group_request("P2P_CONNECT " + addr0 + " pbc")
  1476. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
  1477. if ev is None:
  1478. raise Exception("Timeout on GO Neg Req")
  1479. peer = dev[0].get_peer(addr1)
  1480. dev[0].p2p_stop_find()
  1481. msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_REQ, dialog_token=123)
  1482. attrs = p2p_attr_capability()
  1483. attrs += p2p_attr_status(status=P2P_SC_FAIL_REJECTED_BY_USER)
  1484. attrs += p2p_attr_go_intent()
  1485. attrs += p2p_attr_config_timeout()
  1486. attrs += p2p_attr_listen_channel()
  1487. attrs += p2p_attr_ext_listen_timing()
  1488. attrs += p2p_attr_intended_interface_addr(addr0)
  1489. attrs += p2p_attr_channel_list()
  1490. attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
  1491. attrs += p2p_attr_operating_channel()
  1492. msg['payload'] += ie_p2p(attrs)
  1493. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1, addr1, peer['listen_freq'], binascii.hexlify(msg['payload'])))
  1494. ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=5)
  1495. if ev is None:
  1496. raise Exception("GO Negotiation failure not reported")
  1497. if "status=%d" % P2P_SC_FAIL_REJECTED_BY_USER not in ev:
  1498. raise Exception("Unexpected failure reason: " + ev)
  1499. def test_p2p_msg_unexpected_go_neg_resp(dev, apdev):
  1500. """P2P protocol tests for unexpected GO Neg Resp"""
  1501. addr0 = dev[0].p2p_dev_addr()
  1502. addr1 = dev[1].p2p_dev_addr()
  1503. dev[1].p2p_listen()
  1504. dev[0].discover_peer(addr1)
  1505. dev[0].p2p_stop_find()
  1506. peer = dev[0].get_peer(addr1)
  1507. logger.debug("GO Neg Resp without GO Neg session")
  1508. msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=123)
  1509. attrs = p2p_attr_status()
  1510. attrs += p2p_attr_capability()
  1511. attrs += p2p_attr_go_intent()
  1512. attrs += p2p_attr_config_timeout()
  1513. attrs += p2p_attr_intended_interface_addr(addr0)
  1514. attrs += p2p_attr_channel_list()
  1515. attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
  1516. attrs += p2p_attr_operating_channel()
  1517. msg['payload'] += ie_p2p(attrs)
  1518. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1, addr1, peer['listen_freq'], binascii.hexlify(msg['payload'])))
  1519. dev[0].p2p_listen()
  1520. dev[1].discover_peer(addr0)
  1521. logger.debug("Unexpected GO Neg Resp while waiting for new GO Neg session")
  1522. if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc"):
  1523. raise Exception("P2P_CONNECT failed")
  1524. ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
  1525. if ev is None:
  1526. raise Exception("Timeout on GO Neg Req")
  1527. dev[0].p2p_stop_find()
  1528. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1, addr1, peer['listen_freq'], binascii.hexlify(msg['payload'])))
  1529. logger.debug("Invalid attribute in GO Neg Response")
  1530. msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=197)
  1531. attrs = struct.pack("<BB", P2P_ATTR_CAPABILITY, 0)
  1532. msg['payload'] += ie_p2p(attrs)
  1533. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1, addr1, peer['listen_freq'], binascii.hexlify(msg['payload'])))
  1534. frame = dev[0].mgmt_rx(timeout=0.1)
  1535. if frame is not None:
  1536. raise Exception("Unexpected GO Neg Confirm")
  1537. logger.debug("GO Neg Resp with unexpected dialog token")
  1538. dev[1].p2p_stop_find()
  1539. if "FAIL" in dev[0].request("SET ext_mgmt_frame_handling 1"):
  1540. raise Exception("Failed to enable external management frame handling")
  1541. dev[0].p2p_listen()
  1542. if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc"):
  1543. raise Exception("P2P_CONNECT failed(2)")
  1544. p2p = rx_go_neg_req(dev[0])
  1545. dev[0].p2p_stop_find()
  1546. dialog_token = p2p['dialog_token']
  1547. if dialog_token < 255:
  1548. dialog_token += 1
  1549. else:
  1550. dialog_token = 1
  1551. msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
  1552. attrs = p2p_attr_status()
  1553. attrs += p2p_attr_capability()
  1554. attrs += p2p_attr_go_intent()
  1555. attrs += p2p_attr_config_timeout()
  1556. attrs += p2p_attr_intended_interface_addr(addr0)
  1557. attrs += p2p_attr_channel_list()
  1558. attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
  1559. attrs += p2p_attr_operating_channel()
  1560. msg['payload'] += ie_p2p(attrs)
  1561. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
  1562. logger.debug("GO Neg Resp without Status")
  1563. dev[1].p2p_stop_find()
  1564. dev[0].p2p_listen()
  1565. if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc"):
  1566. raise Exception("P2P_CONNECT failed(2)")
  1567. p2p = rx_go_neg_req(dev[0])
  1568. dev[0].p2p_stop_find()
  1569. dialog_token = p2p['dialog_token']
  1570. msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
  1571. #attrs = p2p_attr_status()
  1572. attrs = p2p_attr_capability()
  1573. attrs += p2p_attr_go_intent()
  1574. attrs += p2p_attr_config_timeout()
  1575. attrs += p2p_attr_intended_interface_addr(addr0)
  1576. attrs += p2p_attr_channel_list()
  1577. attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
  1578. attrs += p2p_attr_operating_channel()
  1579. msg['payload'] += ie_p2p(attrs)
  1580. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
  1581. check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INVALID_PARAMS)
  1582. rx_go_neg_conf(dev[0], P2P_SC_FAIL_INVALID_PARAMS, dialog_token)
  1583. logger.debug("GO Neg Resp without Intended Address")
  1584. dev[1].p2p_stop_find()
  1585. dev[0].p2p_listen()
  1586. if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc"):
  1587. raise Exception("P2P_CONNECT failed(2)")
  1588. p2p = rx_go_neg_req(dev[0])
  1589. dev[0].p2p_stop_find()
  1590. dialog_token = p2p['dialog_token']
  1591. msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
  1592. attrs = p2p_attr_status()
  1593. #attrs += p2p_attr_capability()
  1594. attrs += p2p_attr_go_intent()
  1595. attrs += p2p_attr_config_timeout()
  1596. #attrs += p2p_attr_intended_interface_addr(addr0)
  1597. attrs += p2p_attr_channel_list()
  1598. #attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
  1599. attrs += p2p_attr_operating_channel()
  1600. msg['payload'] += ie_p2p(attrs)
  1601. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
  1602. check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INVALID_PARAMS)
  1603. rx_go_neg_conf(dev[0], P2P_SC_FAIL_INVALID_PARAMS, dialog_token)
  1604. logger.debug("GO Neg Resp without GO Intent")
  1605. dev[1].p2p_stop_find()
  1606. dev[0].p2p_listen()
  1607. if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc"):
  1608. raise Exception("P2P_CONNECT failed(2)")
  1609. p2p = rx_go_neg_req(dev[0])
  1610. dev[0].p2p_stop_find()
  1611. dialog_token = p2p['dialog_token']
  1612. msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
  1613. attrs = p2p_attr_status()
  1614. attrs += p2p_attr_capability()
  1615. #attrs += p2p_attr_go_intent()
  1616. attrs += p2p_attr_config_timeout()
  1617. attrs += p2p_attr_intended_interface_addr(addr0)
  1618. attrs += p2p_attr_channel_list()
  1619. attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
  1620. attrs += p2p_attr_operating_channel()
  1621. msg['payload'] += ie_p2p(attrs)
  1622. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
  1623. check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INVALID_PARAMS)
  1624. rx_go_neg_conf(dev[0], P2P_SC_FAIL_INVALID_PARAMS, dialog_token)
  1625. logger.debug("GO Neg Resp with invalid GO Intent")
  1626. dev[1].p2p_stop_find()
  1627. dev[0].p2p_listen()
  1628. if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc"):
  1629. raise Exception("P2P_CONNECT failed(2)")
  1630. p2p = rx_go_neg_req(dev[0])
  1631. dev[0].p2p_stop_find()
  1632. dialog_token = p2p['dialog_token']
  1633. msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
  1634. attrs = p2p_attr_status()
  1635. attrs += p2p_attr_capability()
  1636. attrs += p2p_attr_go_intent(go_intent=16)
  1637. attrs += p2p_attr_config_timeout()
  1638. attrs += p2p_attr_intended_interface_addr(addr0)
  1639. attrs += p2p_attr_channel_list()
  1640. attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
  1641. attrs += p2p_attr_operating_channel()
  1642. msg['payload'] += ie_p2p(attrs)
  1643. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
  1644. check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INVALID_PARAMS)
  1645. rx_go_neg_conf(dev[0], P2P_SC_FAIL_INVALID_PARAMS, dialog_token)
  1646. logger.debug("GO Neg Resp with incompatible GO Intent")
  1647. dev[1].p2p_stop_find()
  1648. dev[0].p2p_listen()
  1649. if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=15"):
  1650. raise Exception("P2P_CONNECT failed(2)")
  1651. p2p = rx_go_neg_req(dev[0])
  1652. dev[0].p2p_stop_find()
  1653. dialog_token = p2p['dialog_token']
  1654. msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
  1655. attrs = p2p_attr_status()
  1656. attrs += p2p_attr_capability()
  1657. attrs += p2p_attr_go_intent(go_intent=15)
  1658. attrs += p2p_attr_config_timeout()
  1659. attrs += p2p_attr_intended_interface_addr(addr0)
  1660. attrs += p2p_attr_channel_list()
  1661. attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
  1662. attrs += p2p_attr_operating_channel()
  1663. msg['payload'] += ie_p2p(attrs)
  1664. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
  1665. check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INCOMPATIBLE_PARAMS)
  1666. rx_go_neg_conf(dev[0], P2P_SC_FAIL_INCOMPATIBLE_PARAMS, dialog_token)
  1667. logger.debug("GO Neg Resp without P2P Group ID")
  1668. dev[1].p2p_stop_find()
  1669. dev[0].p2p_listen()
  1670. if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=0"):
  1671. raise Exception("P2P_CONNECT failed(2)")
  1672. p2p = rx_go_neg_req(dev[0])
  1673. dev[0].p2p_stop_find()
  1674. dialog_token = p2p['dialog_token']
  1675. msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
  1676. attrs = p2p_attr_status()
  1677. attrs += p2p_attr_capability()
  1678. attrs += p2p_attr_go_intent(go_intent=15)
  1679. attrs += p2p_attr_config_timeout()
  1680. attrs += p2p_attr_intended_interface_addr(addr0)
  1681. attrs += p2p_attr_channel_list()
  1682. attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
  1683. attrs += p2p_attr_operating_channel()
  1684. #attrs += p2p_attr_group_id(src, "DIRECT-foo")
  1685. msg['payload'] += ie_p2p(attrs)
  1686. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
  1687. check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INVALID_PARAMS)
  1688. rx_go_neg_conf(dev[0], P2P_SC_FAIL_INVALID_PARAMS, dialog_token)
  1689. logger.debug("GO Neg Resp without Operating Channel")
  1690. dev[1].p2p_stop_find()
  1691. dev[0].p2p_listen()
  1692. if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=0"):
  1693. raise Exception("P2P_CONNECT failed(2)")
  1694. p2p = rx_go_neg_req(dev[0])
  1695. dev[0].p2p_stop_find()
  1696. dialog_token = p2p['dialog_token']
  1697. msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
  1698. attrs = p2p_attr_status()
  1699. attrs += p2p_attr_capability()
  1700. attrs += p2p_attr_go_intent(go_intent=15)
  1701. #attrs += p2p_attr_config_timeout()
  1702. attrs += p2p_attr_intended_interface_addr(addr0)
  1703. attrs += p2p_attr_channel_list()
  1704. attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
  1705. #attrs += p2p_attr_operating_channel()
  1706. attrs += p2p_attr_group_id(addr0, "DIRECT-foo")
  1707. msg['payload'] += ie_p2p(attrs)
  1708. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
  1709. check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INVALID_PARAMS)
  1710. rx_go_neg_conf(dev[0], P2P_SC_FAIL_INVALID_PARAMS, dialog_token)
  1711. logger.debug("GO Neg Resp without Channel List")
  1712. dev[1].p2p_stop_find()
  1713. dev[0].p2p_listen()
  1714. if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=0"):
  1715. raise Exception("P2P_CONNECT failed(2)")
  1716. p2p = rx_go_neg_req(dev[0])
  1717. dev[0].p2p_stop_find()
  1718. dialog_token = p2p['dialog_token']
  1719. msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
  1720. attrs = p2p_attr_status()
  1721. attrs += p2p_attr_capability()
  1722. attrs += p2p_attr_go_intent(go_intent=15)
  1723. attrs += p2p_attr_config_timeout()
  1724. attrs += p2p_attr_intended_interface_addr(addr0)
  1725. #attrs += p2p_attr_channel_list()
  1726. attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
  1727. attrs += p2p_attr_operating_channel()
  1728. attrs += p2p_attr_group_id(addr0, "DIRECT-foo")
  1729. msg['payload'] += ie_p2p(attrs)
  1730. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
  1731. check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_INVALID_PARAMS)
  1732. rx_go_neg_conf(dev[0], P2P_SC_FAIL_INVALID_PARAMS, dialog_token)
  1733. logger.debug("GO Neg Resp without common channels")
  1734. dev[1].p2p_stop_find()
  1735. dev[0].p2p_listen()
  1736. if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=0"):
  1737. raise Exception("P2P_CONNECT failed(2)")
  1738. p2p = rx_go_neg_req(dev[0])
  1739. dev[0].p2p_stop_find()
  1740. dialog_token = p2p['dialog_token']
  1741. msg = p2p_hdr(addr1, addr0, type=P2P_GO_NEG_RESP, dialog_token=dialog_token)
  1742. attrs = p2p_attr_status()
  1743. attrs += p2p_attr_capability()
  1744. attrs += p2p_attr_go_intent(go_intent=15)
  1745. attrs += p2p_attr_config_timeout()
  1746. attrs += p2p_attr_intended_interface_addr(addr0)
  1747. attrs += struct.pack("<BH3BBB", P2P_ATTR_CHANNEL_LIST, 5,
  1748. 0x58, 0x58, 0x04,
  1749. 81, 0)
  1750. attrs += p2p_attr_device_info(addr0, config_methods=0x0108)
  1751. attrs += p2p_attr_operating_channel()
  1752. attrs += p2p_attr_group_id(addr0, "DIRECT-foo")
  1753. msg['payload'] += ie_p2p(attrs)
  1754. mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr1, addr1, p2p['freq'], binascii.hexlify(msg['payload'])))
  1755. check_p2p_go_neg_fail_event(dev[1], P2P_SC_FAIL_NO_COMMON_CHANNELS)
  1756. rx_go_neg_conf(dev[0], P2P_SC_FAIL_NO_COMMON_CHANNELS, dialog_token)