test_p2p_messages.py 87 KB

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