test_fst_module.py 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063
  1. # FST functionality tests
  2. # Copyright (c) 2015, Qualcomm Atheros, Inc.
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import logging
  7. logger = logging.getLogger()
  8. import struct
  9. import subprocess
  10. import time
  11. import os
  12. import hwsim_utils
  13. from hwsim import HWSimRadio
  14. import hostapd
  15. import fst_test_common
  16. import fst_module_aux
  17. from utils import alloc_fail
  18. #enum - bad parameter types
  19. bad_param_none = 0
  20. bad_param_session_add_no_params = 1
  21. bad_param_group_id = 2
  22. bad_param_session_set_no_params = 3
  23. bad_param_session_set_unknown_param = 4
  24. bad_param_session_id = 5
  25. bad_param_old_iface = 6
  26. bad_param_new_iface = 7
  27. bad_param_negative_llt = 8
  28. bad_param_zero_llt = 9
  29. bad_param_llt_too_big = 10
  30. bad_param_llt_nan = 11
  31. bad_param_peer_addr = 12
  32. bad_param_session_initiate_no_params = 13
  33. bad_param_session_initiate_bad_session_id = 14
  34. bad_param_session_initiate_with_no_new_iface_set = 15
  35. bad_param_session_initiate_with_bad_peer_addr_set = 16
  36. bad_param_session_initiate_request_with_bad_stie = 17
  37. bad_param_session_initiate_response_with_reject = 18
  38. bad_param_session_initiate_response_with_bad_stie = 19
  39. bad_param_session_initiate_response_with_zero_llt = 20
  40. bad_param_session_initiate_stt_no_response = 21
  41. bad_param_session_initiate_concurrent_setup_request = 22
  42. bad_param_session_transfer_no_params = 23
  43. bad_param_session_transfer_bad_session_id = 24
  44. bad_param_session_transfer_setup_skipped = 25
  45. bad_param_session_teardown_no_params = 26
  46. bad_param_session_teardown_bad_session_id = 27
  47. bad_param_session_teardown_setup_skipped = 28
  48. bad_param_session_teardown_bad_fsts_id = 29
  49. bad_param_names = ("None",
  50. "No params passed to session add",
  51. "Group ID",
  52. "No params passed to session set",
  53. "Unknown param passed to session set",
  54. "Session ID",
  55. "Old interface name",
  56. "New interface name",
  57. "Negative LLT",
  58. "Zero LLT",
  59. "LLT too big",
  60. "LLT is not a number",
  61. "Peer address",
  62. "No params passed to session initiate",
  63. "Session ID",
  64. "No new_iface was set",
  65. "Peer address",
  66. "Request with bad st ie",
  67. "Response with reject",
  68. "Response with bad st ie",
  69. "Response with zero llt",
  70. "No response, STT",
  71. "Concurrent setup request",
  72. "No params passed to session transfer",
  73. "Session ID",
  74. "Session setup skipped",
  75. "No params passed to session teardown",
  76. "Bad session",
  77. "Session setup skipped",
  78. "Bad fsts_id")
  79. def fst_start_session(apdev, test_params, bad_param_type, start_on_ap,
  80. peer_addr = None):
  81. """This function makes the necessary preparations and the adds and sets a
  82. session using either correct or incorrect parameters depending on the value
  83. of bad_param_type. If the call ends as expected (with session being
  84. successfully added and set in case of correct parameters or with the
  85. expected exception in case of incorrect parameters), the function silently
  86. exits. Otherwise, it throws an exception thus failing the test."""
  87. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  88. bad_parameter_detected = False
  89. exception_already_raised = False
  90. try:
  91. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  92. if start_on_ap:
  93. initiator = ap1
  94. responder = sta1
  95. new_iface = ap2.ifname()
  96. new_peer_addr = ap2.get_actual_peer_addr()
  97. else:
  98. initiator = sta1
  99. responder = ap1
  100. new_iface = sta2.ifname()
  101. new_peer_addr = sta2.get_actual_peer_addr()
  102. initiator.add_peer(responder, peer_addr, new_peer_addr)
  103. group_id = None
  104. if bad_param_type == bad_param_group_id:
  105. group_id = '-1'
  106. elif bad_param_type == bad_param_session_add_no_params:
  107. group_id = ''
  108. initiator.set_fst_parameters(group_id=group_id)
  109. sid = initiator.add_session()
  110. if bad_param_type == bad_param_session_set_no_params:
  111. res = initiator.set_session_param(None)
  112. if not res.startswith("OK"):
  113. raise Exception("Session set operation failed")
  114. elif bad_param_type == bad_param_session_set_unknown_param:
  115. res = initiator.set_session_param("bad_param=1")
  116. if not res.startswith("OK"):
  117. raise Exception("Session set operation failed")
  118. else:
  119. if bad_param_type == bad_param_session_initiate_with_no_new_iface_set:
  120. new_iface = None
  121. elif bad_param_type == bad_param_new_iface:
  122. new_iface = 'wlan12'
  123. old_iface = None if bad_param_type != bad_param_old_iface else 'wlan12'
  124. llt = None
  125. if bad_param_type == bad_param_negative_llt:
  126. llt = '-1'
  127. elif bad_param_type == bad_param_zero_llt:
  128. llt = '0'
  129. elif bad_param_type == bad_param_llt_too_big:
  130. llt = '4294967296' #0x100000000
  131. elif bad_param_type == bad_param_llt_nan:
  132. llt = 'nan'
  133. elif bad_param_type == bad_param_session_id:
  134. sid = '-1'
  135. initiator.set_fst_parameters(llt=llt)
  136. initiator.configure_session(sid, new_iface, old_iface)
  137. except Exception, e:
  138. if e.args[0].startswith("Cannot add FST session with groupid"):
  139. if bad_param_type == bad_param_group_id or bad_param_type == bad_param_session_add_no_params:
  140. bad_parameter_detected = True
  141. elif e.args[0].startswith("Cannot set FST session new_ifname:"):
  142. if bad_param_type == bad_param_new_iface:
  143. bad_parameter_detected = True
  144. elif e.args[0].startswith("Session set operation failed"):
  145. if (bad_param_type == bad_param_session_set_no_params or
  146. bad_param_type == bad_param_session_set_unknown_param):
  147. bad_parameter_detected = True
  148. elif e.args[0].startswith("Cannot set FST session old_ifname:"):
  149. if (bad_param_type == bad_param_old_iface or
  150. bad_param_type == bad_param_session_id or
  151. bad_param_type == bad_param_session_set_no_params):
  152. bad_parameter_detected = True
  153. elif e.args[0].startswith("Cannot set FST session llt:"):
  154. if (bad_param_type == bad_param_negative_llt or
  155. bad_param_type == bad_param_llt_too_big or
  156. bad_param_type == bad_param_llt_nan):
  157. bad_parameter_detected = True
  158. elif e.args[0].startswith("Cannot set FST session peer address:"):
  159. if bad_param_type == bad_param_peer_addr:
  160. bad_parameter_detected = True
  161. if not bad_parameter_detected:
  162. # The exception was unexpected
  163. logger.info(e)
  164. exception_already_raised = True
  165. raise
  166. finally:
  167. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  168. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  169. if not exception_already_raised:
  170. if bad_parameter_detected:
  171. logger.info("Success. Bad parameter was detected (%s)" % bad_param_names[bad_param_type])
  172. else:
  173. if bad_param_type == bad_param_none or bad_param_type == bad_param_zero_llt:
  174. logger.info("Success. Session added and set")
  175. else:
  176. exception_text = ""
  177. if bad_param_type == bad_param_peer_addr:
  178. exception_text = "Failure. Bad parameter was not detected (Peer address == %s)" % ap1.get_new_peer_addr()
  179. else:
  180. exception_text = "Failure. Bad parameter was not detected (%s)" % bad_param_names[bad_param_type]
  181. raise Exception(exception_text)
  182. else:
  183. print "Failure. Unexpected exception"
  184. def fst_initiate_session(apdev, test_params, bad_param_type, init_on_ap):
  185. """This function makes the necessary preparations and then adds, sets and
  186. initiates a session using either correct or incorrect parameters at each
  187. stage depending on the value of bad_param_type. If the call ends as expected
  188. (with session being successfully added, set and initiated in case of correct
  189. parameters or with the expected exception in case of incorrect parameters),
  190. the function silently exits. Otherwise it throws an exception thus failing
  191. the test."""
  192. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  193. bad_parameter_detected = False
  194. exception_already_raised = False
  195. try:
  196. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  197. # This call makes sure FstHostapd singleton object is created and, as a
  198. # result, the global control interface is registered (this is done from
  199. # the constructor).
  200. ap1.get_global_instance()
  201. if init_on_ap:
  202. initiator = ap1
  203. responder = sta1
  204. new_iface = ap2.ifname() if bad_param_type != bad_param_session_initiate_with_no_new_iface_set else None
  205. new_peer_addr = ap2.get_actual_peer_addr()
  206. resp_newif = sta2.ifname()
  207. else:
  208. initiator = sta1
  209. responder = ap1
  210. new_iface = sta2.ifname() if bad_param_type != bad_param_session_initiate_with_no_new_iface_set else None
  211. new_peer_addr = sta2.get_actual_peer_addr()
  212. resp_newif = ap2.ifname()
  213. peeraddr = None if bad_param_type != bad_param_session_initiate_with_bad_peer_addr_set else '10:DE:AD:DE:AD:11'
  214. initiator.add_peer(responder, peeraddr, new_peer_addr)
  215. if bad_param_type == bad_param_session_initiate_response_with_zero_llt:
  216. initiator.set_fst_parameters(llt='0')
  217. sid = initiator.add_session()
  218. initiator.configure_session(sid, new_iface)
  219. if bad_param_type == bad_param_session_initiate_no_params:
  220. sid = ''
  221. elif bad_param_type == bad_param_session_initiate_bad_session_id:
  222. sid = '-1'
  223. if bad_param_type == bad_param_session_initiate_request_with_bad_stie:
  224. actual_fsts_id = initiator.get_fsts_id_by_sid(sid)
  225. initiator.send_test_session_setup_request(str(actual_fsts_id), "bad_new_band")
  226. responder.wait_for_session_event(5)
  227. elif bad_param_type == bad_param_session_initiate_response_with_reject:
  228. initiator.send_session_setup_request(sid)
  229. initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  230. setup_event = responder.wait_for_session_event(5, [],
  231. ['EVENT_FST_SETUP'])
  232. if not 'id' in setup_event:
  233. raise Exception("No session id in FST setup event")
  234. responder.send_session_setup_response(str(setup_event['id']),
  235. "reject")
  236. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  237. if event['new_state'] != "INITIAL" or event['reason'] != "REASON_REJECT":
  238. raise Exception("Response with reject not handled as expected")
  239. bad_parameter_detected = True
  240. elif bad_param_type == bad_param_session_initiate_response_with_bad_stie:
  241. initiator.send_session_setup_request(sid)
  242. initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  243. responder.wait_for_session_event(5, [], ['EVENT_FST_SETUP'])
  244. actual_fsts_id = initiator.get_fsts_id_by_sid(sid)
  245. responder.send_test_session_setup_response(str(actual_fsts_id),
  246. "accept", "bad_new_band")
  247. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  248. if event['new_state'] != "INITIAL" or event['reason'] != "REASON_ERROR_PARAMS":
  249. raise Exception("Response with bad STIE not handled as expected")
  250. bad_parameter_detected = True
  251. elif bad_param_type == bad_param_session_initiate_response_with_zero_llt:
  252. initiator.initiate_session(sid, "accept")
  253. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  254. if event['new_state'] != "TRANSITION_DONE":
  255. raise Exception("Response reception for a session with llt=0 not handled as expected")
  256. bad_parameter_detected = True
  257. elif bad_param_type == bad_param_session_initiate_stt_no_response:
  258. initiator.send_session_setup_request(sid)
  259. initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  260. responder.wait_for_session_event(5, [], ['EVENT_FST_SETUP'])
  261. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  262. if event['new_state'] != "INITIAL" or event['reason'] != "REASON_STT":
  263. raise Exception("No response scenario not handled as expected")
  264. bad_parameter_detected = True
  265. elif bad_param_type == bad_param_session_initiate_concurrent_setup_request:
  266. responder.add_peer(initiator)
  267. resp_sid = responder.add_session()
  268. responder.configure_session(resp_sid, resp_newif)
  269. initiator.send_session_setup_request(sid)
  270. actual_fsts_id = initiator.get_fsts_id_by_sid(sid)
  271. responder.send_test_session_setup_request(str(actual_fsts_id))
  272. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  273. initiator_addr = initiator.get_own_mac_address()
  274. responder_addr = responder.get_own_mac_address()
  275. if initiator_addr < responder_addr:
  276. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  277. if event['new_state'] != "INITIAL" or event['reason'] != "REASON_SETUP":
  278. raise Exception("Concurrent setup scenario not handled as expected")
  279. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SETUP"])
  280. # The incoming setup request received by the initiator has
  281. # priority over the one sent previously by the initiator itself
  282. # because the initiator's MAC address is numerically lower than
  283. # the one of the responder. Thus, the initiator should generate
  284. # an FST_SETUP event.
  285. else:
  286. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  287. if event['new_state'] != "INITIAL" or event['reason'] != "REASON_STT":
  288. raise Exception("Concurrent setup scenario not handled as expected")
  289. # The incoming setup request was dropped at the initiator
  290. # because its MAC address is numerically bigger than the one of
  291. # the responder. Thus, the initiator continue to wait for a
  292. # setup response until the STT event fires.
  293. bad_parameter_detected = True
  294. else:
  295. initiator.initiate_session(sid, "accept")
  296. except Exception, e:
  297. if e.args[0].startswith("Cannot initiate fst session"):
  298. if bad_param_type != bad_param_none:
  299. bad_parameter_detected = True
  300. elif e.args[0].startswith("No FST-EVENT-SESSION received"):
  301. if bad_param_type == bad_param_session_initiate_request_with_bad_stie:
  302. bad_parameter_detected = True
  303. if not bad_parameter_detected:
  304. #The exception was unexpected
  305. logger.info(e)
  306. exception_already_raised = True
  307. raise
  308. finally:
  309. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  310. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  311. if not exception_already_raised:
  312. if bad_parameter_detected:
  313. logger.info("Success. Bad parameter was detected (%s)" % bad_param_names[bad_param_type])
  314. else:
  315. if bad_param_type == bad_param_none:
  316. logger.info("Success. Session initiated")
  317. else:
  318. raise Exception("Failure. Bad parameter was not detected (%s)" % bad_param_names[bad_param_type])
  319. else:
  320. print "Failure. Unexpected exception"
  321. def fst_transfer_session(apdev, test_params, bad_param_type, init_on_ap,
  322. rsn=False):
  323. """This function makes the necessary preparations and then adds, sets,
  324. initiates and attempts to transfer a session using either correct or
  325. incorrect parameters at each stage depending on the value of bad_param_type.
  326. If the call ends as expected the function silently exits. Otherwise, it
  327. throws an exception thus failing the test."""
  328. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev, rsn=rsn)
  329. bad_parameter_detected = False
  330. exception_already_raised = False
  331. try:
  332. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2, rsn=rsn)
  333. # This call makes sure FstHostapd singleton object is created and, as a
  334. # result, the global control interface is registered (this is done from
  335. # the constructor).
  336. ap1.get_global_instance()
  337. if init_on_ap:
  338. initiator = ap1
  339. responder = sta1
  340. new_iface = ap2.ifname()
  341. new_peer_addr = ap2.get_actual_peer_addr()
  342. else:
  343. initiator = sta1
  344. responder = ap1
  345. new_iface = sta2.ifname()
  346. new_peer_addr = sta2.get_actual_peer_addr()
  347. initiator.add_peer(responder, new_peer_addr = new_peer_addr)
  348. sid = initiator.add_session()
  349. initiator.configure_session(sid, new_iface)
  350. if bad_param_type != bad_param_session_transfer_setup_skipped:
  351. initiator.initiate_session(sid, "accept")
  352. if bad_param_type == bad_param_session_transfer_no_params:
  353. sid = ''
  354. elif bad_param_type == bad_param_session_transfer_bad_session_id:
  355. sid = '-1'
  356. initiator.transfer_session(sid)
  357. except Exception, e:
  358. if e.args[0].startswith("Cannot transfer fst session"):
  359. if bad_param_type != bad_param_none:
  360. bad_parameter_detected = True
  361. if not bad_parameter_detected:
  362. # The exception was unexpected
  363. logger.info(e)
  364. exception_already_raised = True
  365. raise
  366. finally:
  367. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  368. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  369. if not exception_already_raised:
  370. if bad_parameter_detected:
  371. logger.info("Success. Bad parameter was detected (%s)" % bad_param_names[bad_param_type])
  372. else:
  373. if bad_param_type == bad_param_none:
  374. logger.info("Success. Session transferred")
  375. else:
  376. raise Exception("Failure. Bad parameter was not detected (%s)" % bad_param_names[bad_param_type])
  377. else:
  378. print "Failure. Unexpected exception"
  379. def fst_tear_down_session(apdev, test_params, bad_param_type, init_on_ap):
  380. """This function makes the necessary preparations and then adds, sets, and
  381. initiates a session. It then issues a tear down command using either
  382. correct or incorrect parameters at each stage. If the call ends as expected,
  383. the function silently exits. Otherwise, it throws an exception thus failing
  384. the test."""
  385. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  386. bad_parameter_detected = False
  387. exception_already_raised = False
  388. try:
  389. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  390. # This call makes sure FstHostapd singleton object is created and, as a
  391. # result, the global control interface is registered (this is done from
  392. # the constructor).
  393. ap1.get_global_instance()
  394. if init_on_ap:
  395. initiator = ap1
  396. responder = sta1
  397. new_iface = ap2.ifname()
  398. new_peer_addr = ap2.get_actual_peer_addr()
  399. else:
  400. initiator = sta1
  401. responder = ap1
  402. new_iface = sta2.ifname()
  403. new_peer_addr = sta2.get_actual_peer_addr()
  404. initiator.add_peer(responder, new_peer_addr = new_peer_addr)
  405. sid = initiator.add_session()
  406. initiator.configure_session(sid, new_iface)
  407. if bad_param_type != bad_param_session_teardown_setup_skipped:
  408. initiator.initiate_session(sid, "accept")
  409. if bad_param_type == bad_param_session_teardown_bad_fsts_id:
  410. initiator.send_test_tear_down('-1')
  411. responder.wait_for_session_event(5)
  412. else:
  413. if bad_param_type == bad_param_session_teardown_no_params:
  414. sid = ''
  415. elif bad_param_type == bad_param_session_teardown_bad_session_id:
  416. sid = '-1'
  417. initiator.teardown_session(sid)
  418. except Exception, e:
  419. if e.args[0].startswith("Cannot tear down fst session"):
  420. if (bad_param_type == bad_param_session_teardown_no_params or
  421. bad_param_type == bad_param_session_teardown_bad_session_id or
  422. bad_param_type == bad_param_session_teardown_setup_skipped):
  423. bad_parameter_detected = True
  424. elif e.args[0].startswith("No FST-EVENT-SESSION received"):
  425. if bad_param_type == bad_param_session_teardown_bad_fsts_id:
  426. bad_parameter_detected = True
  427. if not bad_parameter_detected:
  428. # The exception was unexpected
  429. logger.info(e)
  430. exception_already_raised = True
  431. raise
  432. finally:
  433. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  434. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  435. if not exception_already_raised:
  436. if bad_parameter_detected:
  437. logger.info("Success. Bad parameter was detected (%s)" % bad_param_names[bad_param_type])
  438. else:
  439. if bad_param_type == bad_param_none:
  440. logger.info("Success. Session torn down")
  441. else:
  442. raise Exception("Failure. Bad parameter was not detected (%s)" % bad_param_names[bad_param_type])
  443. else:
  444. print "Failure. Unexpected exception"
  445. #enum - remove session scenarios
  446. remove_scenario_no_params = 0
  447. remove_scenario_bad_session_id = 1
  448. remove_scenario_non_established_session = 2
  449. remove_scenario_established_session = 3
  450. remove_scenario_names = ("No params",
  451. "Bad session id",
  452. "Remove non-established session",
  453. "Remove established session")
  454. def fst_remove_session(apdev, test_params, remove_session_scenario, init_on_ap):
  455. """This function attempts to remove a session at various stages of its
  456. formation, depending on the value of remove_session_scenario. If the call
  457. ends as expected, the function silently exits. Otherwise, it throws an
  458. exception thus failing the test."""
  459. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  460. bad_parameter_detected = False
  461. exception_already_raised = False
  462. try:
  463. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  464. # This call makes sure FstHostapd singleton object is created and, as a
  465. # result, the global control interface is registered (this is done from
  466. # the constructor).
  467. ap1.get_global_instance()
  468. if init_on_ap:
  469. initiator = ap1
  470. responder = sta1
  471. new_iface = ap2.ifname()
  472. new_peer_addr = ap2.get_actual_peer_addr()
  473. else:
  474. initiator = sta1
  475. responder = ap1
  476. new_iface = sta2.ifname()
  477. new_peer_addr = sta2.get_actual_peer_addr()
  478. initiator.add_peer(responder, new_peer_addr = new_peer_addr)
  479. sid = initiator.add_session()
  480. initiator.configure_session(sid, new_iface)
  481. if remove_session_scenario != remove_scenario_no_params:
  482. if remove_session_scenario != remove_scenario_non_established_session:
  483. initiator.initiate_session(sid, "accept")
  484. if remove_session_scenario == remove_scenario_no_params:
  485. sid = ''
  486. elif remove_session_scenario == remove_scenario_bad_session_id:
  487. sid = '-1'
  488. initiator.remove_session(sid)
  489. except Exception, e:
  490. if e.args[0].startswith("Cannot remove fst session"):
  491. if (remove_session_scenario == remove_scenario_no_params or
  492. remove_session_scenario == remove_scenario_bad_session_id):
  493. bad_parameter_detected = True
  494. elif e.args[0].startswith("No FST-EVENT-SESSION received"):
  495. if remove_session_scenario == remove_scenario_non_established_session:
  496. bad_parameter_detected = True
  497. if not bad_parameter_detected:
  498. #The exception was unexpected
  499. logger.info(e)
  500. exception_already_raised = True
  501. raise
  502. finally:
  503. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  504. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  505. if not exception_already_raised:
  506. if bad_parameter_detected:
  507. logger.info("Success. Remove scenario ended as expected (%s)" % remove_scenario_names[remove_session_scenario])
  508. else:
  509. if remove_session_scenario == remove_scenario_established_session:
  510. logger.info("Success. Session removed")
  511. else:
  512. raise Exception("Failure. Remove scenario ended in an unexpected way (%s)" % remove_scenario_names[remove_session_scenario])
  513. else:
  514. print "Failure. Unexpected exception"
  515. #enum - frame types
  516. frame_type_session_request = 0
  517. frame_type_session_response = 1
  518. frame_type_ack_request = 2
  519. frame_type_ack_response = 3
  520. frame_type_tear_down = 4
  521. frame_type_names = ("Session request",
  522. "Session Response",
  523. "Ack request",
  524. "Ack response",
  525. "Tear down")
  526. def fst_send_unexpected_frame(apdev, test_params, frame_type, send_from_ap, additional_param = ''):
  527. """This function creates two pairs of APs and stations, makes them connect
  528. and then causes one side to send an unexpected FST frame of the specified
  529. type to the other. The other side should then identify and ignore the
  530. frame."""
  531. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  532. exception_already_raised = False
  533. frame_receive_timeout = False
  534. try:
  535. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  536. # This call makes sure FstHostapd singleton object is created and, as a
  537. # result, the global control interface is registered (this is done from
  538. # the constructor).
  539. ap1.get_global_instance()
  540. if send_from_ap:
  541. sender = ap1
  542. receiver = sta1
  543. new_iface = ap2.ifname()
  544. new_peer_addr = ap2.get_actual_peer_addr()
  545. else:
  546. sender = sta1
  547. receiver = ap1
  548. new_iface = sta2.ifname()
  549. new_peer_addr = sta2.get_actual_peer_addr()
  550. sender.add_peer(receiver, new_peer_addr = new_peer_addr)
  551. sid=sender.add_session()
  552. sender.configure_session(sid, new_iface)
  553. if frame_type == frame_type_session_request:
  554. sender.send_session_setup_request(sid)
  555. event = receiver.wait_for_session_event(5)
  556. if event['type'] != 'EVENT_FST_SETUP':
  557. raise Exception("Unexpected indication: " + event['type'])
  558. elif frame_type == frame_type_session_response:
  559. #fsts_id doesn't matter, no actual session exists
  560. sender.send_test_session_setup_response('0', additional_param)
  561. receiver.wait_for_session_event(5)
  562. elif frame_type == frame_type_ack_request:
  563. #fsts_id doesn't matter, no actual session exists
  564. sender.send_test_ack_request('0')
  565. receiver.wait_for_session_event(5)
  566. elif frame_type == frame_type_ack_response:
  567. #fsts_id doesn't matter, no actual session exists
  568. sender.send_test_ack_response('0')
  569. receiver.wait_for_session_event(5)
  570. elif frame_type == frame_type_tear_down:
  571. #fsts_id doesn't matter, no actual session exists
  572. sender.send_test_tear_down('0')
  573. receiver.wait_for_session_event(5)
  574. except Exception, e:
  575. if e.args[0].startswith("No FST-EVENT-SESSION received"):
  576. if frame_type != frame_type_session_request:
  577. frame_receive_timeout = True
  578. else:
  579. logger.info(e)
  580. exception_already_raised = True
  581. raise
  582. finally:
  583. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  584. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  585. if not exception_already_raised:
  586. if frame_receive_timeout:
  587. logger.info("Success. Frame was ignored (%s)" % frame_type_names[frame_type])
  588. else:
  589. if frame_type == frame_type_session_request:
  590. logger.info("Success. Frame received, session created")
  591. else:
  592. raise Exception("Failure. Frame was not ignored (%s)" % frame_type_names[frame_type])
  593. else:
  594. print "Failure. Unexpected exception"
  595. #enum - bad session transfer scenarios
  596. bad_scenario_none = 0
  597. bad_scenario_ack_req_session_not_set_up = 1
  598. bad_scenario_ack_req_session_not_established_init_side = 2
  599. bad_scenario_ack_req_session_not_established_resp_side = 3
  600. bad_scenario_ack_req_bad_fsts_id = 4
  601. bad_scenario_ack_resp_session_not_set_up = 5
  602. bad_scenario_ack_resp_session_not_established_init_side = 6
  603. bad_scenario_ack_resp_session_not_established_resp_side = 7
  604. bad_scenario_ack_resp_no_ack_req = 8
  605. bad_scenario_ack_resp_bad_fsts_id = 9
  606. bad_scenario_names = ("None",
  607. "Ack request received before the session was set up",
  608. "Ack request received on the initiator side before session was established",
  609. "Ack request received on the responder side before session was established",
  610. "Ack request received with bad fsts_id",
  611. "Ack response received before the session was set up",
  612. "Ack response received on the initiator side before session was established",
  613. "Ack response received on the responder side before session was established",
  614. "Ack response received before ack request was sent",
  615. "Ack response received with bad fsts_id")
  616. def fst_bad_transfer(apdev, test_params, bad_scenario_type, init_on_ap):
  617. """This function makes the necessary preparations and then adds and sets a
  618. session. It then initiates and it unless instructed otherwise) and attempts
  619. to send one of the frames involved in the session transfer protocol,
  620. skipping or distorting one of the stages according to the value of
  621. bad_scenario_type parameter."""
  622. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  623. bad_parameter_detected = False
  624. exception_already_raised = False
  625. try:
  626. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  627. # This call makes sure FstHostapd singleton object is created and, as a
  628. # result, the global control interface is registered (this is done from
  629. # the constructor).
  630. ap1.get_global_instance()
  631. if init_on_ap:
  632. initiator = ap1
  633. responder = sta1
  634. new_iface = ap2.ifname()
  635. new_peer_addr = ap2.get_actual_peer_addr()
  636. else:
  637. initiator = sta1
  638. responder = ap1
  639. new_iface = sta2.ifname()
  640. new_peer_addr = sta2.get_actual_peer_addr()
  641. initiator.add_peer(responder, new_peer_addr = new_peer_addr)
  642. sid = initiator.add_session()
  643. initiator.configure_session(sid, new_iface)
  644. if (bad_scenario_type != bad_scenario_ack_req_session_not_set_up and
  645. bad_scenario_type != bad_scenario_ack_resp_session_not_set_up):
  646. if (bad_scenario_type != bad_scenario_ack_req_session_not_established_init_side and
  647. bad_scenario_type != bad_scenario_ack_resp_session_not_established_init_side and
  648. bad_scenario_type != bad_scenario_ack_req_session_not_established_resp_side and
  649. bad_scenario_type != bad_scenario_ack_resp_session_not_established_resp_side):
  650. response = "accept"
  651. else:
  652. response = ''
  653. initiator.initiate_session(sid, response)
  654. if bad_scenario_type == bad_scenario_ack_req_session_not_set_up:
  655. #fsts_id doesn't matter, no actual session exists
  656. responder.send_test_ack_request('0')
  657. initiator.wait_for_session_event(5)
  658. # We want to send the unexpected frame to the side that already has
  659. # a session created
  660. elif bad_scenario_type == bad_scenario_ack_resp_session_not_set_up:
  661. #fsts_id doesn't matter, no actual session exists
  662. responder.send_test_ack_response('0')
  663. initiator.wait_for_session_event(5)
  664. # We want to send the unexpected frame to the side that already has
  665. # a session created
  666. elif bad_scenario_type == bad_scenario_ack_req_session_not_established_init_side:
  667. #fsts_id doesn't matter, no actual session exists
  668. initiator.send_test_ack_request('0')
  669. responder.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
  670. elif bad_scenario_type == bad_scenario_ack_req_session_not_established_resp_side:
  671. #fsts_id doesn't matter, no actual session exists
  672. responder.send_test_ack_request('0')
  673. initiator.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
  674. elif bad_scenario_type == bad_scenario_ack_resp_session_not_established_init_side:
  675. #fsts_id doesn't matter, no actual session exists
  676. initiator.send_test_ack_response('0')
  677. responder.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
  678. elif bad_scenario_type == bad_scenario_ack_resp_session_not_established_resp_side:
  679. #fsts_id doesn't matter, no actual session exists
  680. responder.send_test_ack_response('0')
  681. initiator.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
  682. elif bad_scenario_type == bad_scenario_ack_req_bad_fsts_id:
  683. initiator.send_test_ack_request('-1')
  684. responder.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
  685. elif bad_scenario_type == bad_scenario_ack_resp_bad_fsts_id:
  686. initiator.send_test_ack_response('-1')
  687. responder.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
  688. elif bad_scenario_type == bad_scenario_ack_resp_no_ack_req:
  689. actual_fsts_id = initiator.get_fsts_id_by_sid(sid)
  690. initiator.send_test_ack_response(str(actual_fsts_id))
  691. responder.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
  692. else:
  693. raise Exception("Unknown bad scenario identifier")
  694. except Exception, e:
  695. if e.args[0].startswith("No FST-EVENT-SESSION received"):
  696. bad_parameter_detected = True
  697. if not bad_parameter_detected:
  698. # The exception was unexpected
  699. logger.info(e)
  700. exception_already_raised = True
  701. raise
  702. finally:
  703. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  704. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  705. if not exception_already_raised:
  706. if bad_parameter_detected:
  707. logger.info("Success. Bad scenario was handled correctly (%s)" % bad_scenario_names[bad_scenario_type])
  708. else:
  709. raise Exception("Failure. Bad scenario was handled incorrectly (%s)" % bad_scenario_names[bad_scenario_type])
  710. else:
  711. print "Failure. Unexpected exception"
  712. def test_fst_sta_connect_to_non_fst_ap(dev, apdev, test_params):
  713. """FST STA connecting to non-FST AP"""
  714. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  715. with HWSimRadio() as (radio, iface):
  716. non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
  717. try:
  718. orig_sta1_mbies = sta1.get_local_mbies()
  719. orig_sta2_mbies = sta2.get_local_mbies()
  720. vals = sta2.scan()
  721. freq = vals['freq']
  722. sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
  723. key_mgmt="NONE", scan_freq=freq)
  724. time.sleep(2)
  725. res_sta1_mbies = sta1.get_local_mbies()
  726. res_sta2_mbies = sta2.get_local_mbies()
  727. if (orig_sta1_mbies.startswith("FAIL") or
  728. orig_sta2_mbies.startswith("FAIL") or
  729. not res_sta1_mbies.startswith("FAIL") or
  730. not res_sta2_mbies.startswith("FAIL")):
  731. raise Exception("Failure. MB IEs have not been removed on the stations")
  732. except Exception, e:
  733. logger.info(e)
  734. raise
  735. finally:
  736. sta2.disconnect_from_external_ap()
  737. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  738. def test_fst_sta_connect_to_fst_ap(dev, apdev, test_params):
  739. """FST STA connecting to FST AP"""
  740. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  741. try:
  742. orig_sta2_mbies = sta2.get_local_mbies()
  743. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  744. sta1.connect(ap1, key_mgmt="NONE",
  745. scan_freq=fst_test_common.fst_test_def_freq_a)
  746. time.sleep(2)
  747. res_sta2_mbies = sta2.get_local_mbies()
  748. if res_sta2_mbies == orig_sta2_mbies:
  749. raise Exception("Failure. MB IEs have not been updated")
  750. except Exception, e:
  751. logger.info(e)
  752. raise
  753. finally:
  754. sta1.disconnect()
  755. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  756. def test_fst_ap_connect_to_fst_sta(dev, apdev, test_params):
  757. """FST AP connecting to FST STA"""
  758. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  759. try:
  760. orig_ap_mbies = ap1.get_local_mbies()
  761. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  762. sta1.connect(ap1, key_mgmt="NONE",
  763. scan_freq=fst_test_common.fst_test_def_freq_a)
  764. time.sleep(2)
  765. res_ap_mbies = ap1.get_local_mbies()
  766. if res_ap_mbies != orig_ap_mbies:
  767. raise Exception("Failure. MB IEs have been unexpectedly updated on the AP")
  768. except Exception, e:
  769. logger.info(e)
  770. raise
  771. finally:
  772. sta1.disconnect()
  773. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  774. def test_fst_ap_connect_to_non_fst_sta(dev, apdev, test_params):
  775. """FST AP connecting to non-FST STA"""
  776. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  777. try:
  778. orig_ap_mbies = ap2.get_local_mbies()
  779. vals = dev[0].scan(None, fst_test_common.fst_test_def_freq_g)
  780. fst_module_aux.external_sta_connect(dev[0], ap2, key_mgmt="NONE",
  781. scan_freq=fst_test_common.fst_test_def_freq_g)
  782. time.sleep(2)
  783. res_ap_mbies = ap2.get_local_mbies()
  784. if res_ap_mbies != orig_ap_mbies:
  785. raise Exception("Failure. MB IEs have been unexpectedly updated on the AP")
  786. except Exception, e:
  787. logger.info(e)
  788. raise
  789. finally:
  790. fst_module_aux.disconnect_external_sta(dev[0], ap2)
  791. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  792. def test_fst_second_sta_connect_to_non_fst_ap(dev, apdev, test_params):
  793. """FST STA 2nd connecting to non-FST AP"""
  794. fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  795. with HWSimRadio() as (radio, iface):
  796. non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
  797. try:
  798. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  799. sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
  800. time.sleep(2)
  801. orig_sta1_mbies = sta1.get_local_mbies()
  802. orig_sta2_mbies = sta2.get_local_mbies()
  803. vals = sta2.scan()
  804. freq = vals['freq']
  805. sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g", key_mgmt="NONE", scan_freq=freq)
  806. time.sleep(2)
  807. res_sta1_mbies = sta1.get_local_mbies()
  808. res_sta2_mbies = sta2.get_local_mbies()
  809. if (orig_sta1_mbies.startswith("FAIL") or
  810. orig_sta2_mbies.startswith("FAIL") or
  811. not res_sta1_mbies.startswith("FAIL") or
  812. not res_sta2_mbies.startswith("FAIL")):
  813. raise Exception("Failure. MB IEs have not been removed on the stations")
  814. except Exception, e:
  815. logger.info(e)
  816. raise
  817. finally:
  818. sta1.disconnect()
  819. sta2.disconnect_from_external_ap()
  820. fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
  821. def test_fst_second_sta_connect_to_fst_ap(dev, apdev, test_params):
  822. """FST STA 2nd connecting to FST AP"""
  823. fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  824. with HWSimRadio() as (radio, iface):
  825. non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
  826. try:
  827. vals = sta2.scan()
  828. freq = vals['freq']
  829. sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g", key_mgmt="NONE", scan_freq=freq)
  830. time.sleep(2)
  831. orig_sta1_mbies = sta1.get_local_mbies()
  832. orig_sta2_mbies = sta2.get_local_mbies()
  833. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  834. sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
  835. time.sleep(2)
  836. res_sta1_mbies = sta1.get_local_mbies()
  837. res_sta2_mbies = sta2.get_local_mbies()
  838. if (not orig_sta1_mbies.startswith("FAIL") or
  839. not orig_sta2_mbies.startswith("FAIL") or
  840. not res_sta1_mbies.startswith("FAIL") or
  841. not res_sta2_mbies.startswith("FAIL")):
  842. raise Exception("Failure. MB IEs should have stayed non-present on the stations")
  843. except Exception, e:
  844. logger.info(e)
  845. raise
  846. finally:
  847. sta1.disconnect()
  848. sta2.disconnect_from_external_ap()
  849. fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
  850. def test_fst_disconnect_1_of_2_stas_from_non_fst_ap(dev, apdev, test_params):
  851. """FST disconnect 1 of 2 STAs from non-FST AP"""
  852. fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  853. with HWSimRadio() as (radio, iface):
  854. non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
  855. try:
  856. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  857. sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
  858. vals = sta2.scan()
  859. freq = vals['freq']
  860. sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g", key_mgmt="NONE", scan_freq=freq)
  861. time.sleep(2)
  862. orig_sta1_mbies = sta1.get_local_mbies()
  863. orig_sta2_mbies = sta2.get_local_mbies()
  864. sta2.disconnect_from_external_ap()
  865. time.sleep(2)
  866. res_sta1_mbies = sta1.get_local_mbies()
  867. res_sta2_mbies = sta2.get_local_mbies()
  868. if (not orig_sta1_mbies.startswith("FAIL") or
  869. not orig_sta2_mbies.startswith("FAIL") or
  870. res_sta1_mbies.startswith("FAIL") or
  871. res_sta2_mbies.startswith("FAIL")):
  872. raise Exception("Failure. MB IEs haven't reappeared on the stations")
  873. except Exception, e:
  874. logger.info(e)
  875. raise
  876. finally:
  877. sta1.disconnect()
  878. sta2.disconnect_from_external_ap()
  879. fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
  880. def test_fst_disconnect_1_of_2_stas_from_fst_ap(dev, apdev, test_params):
  881. """FST disconnect 1 of 2 STAs from FST AP"""
  882. fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  883. with HWSimRadio() as (radio, iface):
  884. non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
  885. try:
  886. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  887. sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
  888. vals = sta2.scan()
  889. freq = vals['freq']
  890. sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g", key_mgmt="NONE", scan_freq=freq)
  891. time.sleep(2)
  892. orig_sta1_mbies = sta1.get_local_mbies()
  893. orig_sta2_mbies = sta2.get_local_mbies()
  894. sta1.disconnect()
  895. time.sleep(2)
  896. res_sta1_mbies = sta1.get_local_mbies()
  897. res_sta2_mbies = sta2.get_local_mbies()
  898. if (not orig_sta1_mbies.startswith("FAIL") or
  899. not orig_sta2_mbies.startswith("FAIL") or
  900. not res_sta1_mbies.startswith("FAIL") or
  901. not res_sta2_mbies.startswith("FAIL")):
  902. raise Exception("Failure. MB IEs should have stayed non-present on the stations")
  903. except Exception, e:
  904. logger.info(e)
  905. raise
  906. finally:
  907. sta1.disconnect()
  908. sta2.disconnect_from_external_ap()
  909. fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
  910. def test_fst_disconnect_2_of_2_stas_from_non_fst_ap(dev, apdev, test_params):
  911. """FST disconnect 2 of 2 STAs from non-FST AP"""
  912. fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  913. with HWSimRadio() as (radio, iface):
  914. non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
  915. try:
  916. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  917. sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
  918. vals = sta2.scan()
  919. freq = vals['freq']
  920. sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g", key_mgmt="NONE", scan_freq=freq)
  921. time.sleep(2)
  922. sta1.disconnect()
  923. time.sleep(2)
  924. orig_sta1_mbies = sta1.get_local_mbies()
  925. orig_sta2_mbies = sta2.get_local_mbies()
  926. sta2.disconnect_from_external_ap()
  927. time.sleep(2)
  928. res_sta1_mbies = sta1.get_local_mbies()
  929. res_sta2_mbies = sta2.get_local_mbies()
  930. if (not orig_sta1_mbies.startswith("FAIL") or
  931. not orig_sta2_mbies.startswith("FAIL") or
  932. res_sta1_mbies.startswith("FAIL") or
  933. res_sta2_mbies.startswith("FAIL")):
  934. raise Exception("Failure. MB IEs haven't reappeared on the stations")
  935. except Exception, e:
  936. logger.info(e)
  937. raise
  938. finally:
  939. sta1.disconnect()
  940. sta2.disconnect_from_external_ap()
  941. fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
  942. def test_fst_disconnect_2_of_2_stas_from_fst_ap(dev, apdev, test_params):
  943. """FST disconnect 2 of 2 STAs from FST AP"""
  944. fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  945. with HWSimRadio() as (radio, iface):
  946. non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g"})
  947. try:
  948. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  949. sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
  950. vals = sta2.scan()
  951. freq = vals['freq']
  952. sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g", key_mgmt="NONE", scan_freq=freq)
  953. time.sleep(2)
  954. sta2.disconnect_from_external_ap()
  955. time.sleep(2)
  956. orig_sta1_mbies = sta1.get_local_mbies()
  957. orig_sta2_mbies = sta2.get_local_mbies()
  958. sta1.disconnect()
  959. time.sleep(2)
  960. res_sta1_mbies = sta1.get_local_mbies()
  961. res_sta2_mbies = sta2.get_local_mbies()
  962. if (orig_sta1_mbies.startswith("FAIL") or
  963. orig_sta2_mbies.startswith("FAIL") or
  964. res_sta1_mbies.startswith("FAIL") or
  965. res_sta2_mbies.startswith("FAIL")):
  966. raise Exception("Failure. MB IEs should have stayed present on both stations")
  967. # Mandatory part of 8.4.2.140 Multi-band element is 24 bytes = 48 hex chars
  968. basic_sta1_mbies = res_sta1_mbies[0:48] + res_sta1_mbies[60:108]
  969. basic_sta2_mbies = res_sta2_mbies[0:48] + res_sta2_mbies[60:108]
  970. if (basic_sta1_mbies != basic_sta2_mbies):
  971. raise Exception("Failure. Basic MB IEs should have become identical on both stations")
  972. addr_sta1_str = sta1.get_own_mac_address().replace(":", "")
  973. addr_sta2_str = sta2.get_own_mac_address().replace(":", "")
  974. # Mandatory part of 8.4.2.140 Multi-band element is followed by STA MAC Address field (6 bytes = 12 hex chars)
  975. addr_sta1_mbie1 = res_sta1_mbies[48:60]
  976. addr_sta1_mbie2 = res_sta1_mbies[108:120]
  977. addr_sta2_mbie1 = res_sta2_mbies[48:60]
  978. addr_sta2_mbie2 = res_sta2_mbies[108:120]
  979. if (addr_sta1_mbie1 != addr_sta1_mbie2 or
  980. addr_sta1_mbie1 != addr_sta2_str or
  981. addr_sta2_mbie1 != addr_sta2_mbie2 or
  982. addr_sta2_mbie1 != addr_sta1_str):
  983. raise Exception("Failure. STA Address in MB IEs should have been same as the other STA's")
  984. except Exception, e:
  985. logger.info(e)
  986. raise
  987. finally:
  988. sta1.disconnect()
  989. sta2.disconnect_from_external_ap()
  990. fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
  991. def test_fst_disconnect_non_fst_sta(dev, apdev, test_params):
  992. """FST disconnect non-FST STA"""
  993. ap1, ap2, fst_sta1, fst_sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  994. external_sta_connected = False
  995. try:
  996. vals = fst_sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  997. fst_sta1.connect(ap1, key_mgmt="NONE",
  998. scan_freq=fst_test_common.fst_test_def_freq_a)
  999. vals = dev[0].scan(None, fst_test_common.fst_test_def_freq_g)
  1000. fst_module_aux.external_sta_connect(dev[0], ap2, key_mgmt="NONE",
  1001. scan_freq=fst_test_common.fst_test_def_freq_g)
  1002. external_sta_connected = True
  1003. time.sleep(2)
  1004. fst_sta1.disconnect()
  1005. time.sleep(2)
  1006. orig_ap_mbies = ap2.get_local_mbies()
  1007. fst_module_aux.disconnect_external_sta(dev[0], ap2)
  1008. external_sta_connected = False
  1009. time.sleep(2)
  1010. res_ap_mbies = ap2.get_local_mbies()
  1011. if res_ap_mbies != orig_ap_mbies:
  1012. raise Exception("Failure. MB IEs have been unexpectedly updated on the AP")
  1013. except Exception, e:
  1014. logger.info(e)
  1015. raise
  1016. finally:
  1017. fst_sta1.disconnect()
  1018. if external_sta_connected:
  1019. fst_module_aux.disconnect_external_sta(dev[0], ap2)
  1020. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, fst_sta1, fst_sta2)
  1021. def test_fst_disconnect_fst_sta(dev, apdev, test_params):
  1022. """FST disconnect FST STA"""
  1023. ap1, ap2, fst_sta1, fst_sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  1024. external_sta_connected = False;
  1025. try:
  1026. vals = fst_sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  1027. fst_sta1.connect(ap1, key_mgmt="NONE",
  1028. scan_freq=fst_test_common.fst_test_def_freq_a)
  1029. vals = dev[0].scan(None, fst_test_common.fst_test_def_freq_g)
  1030. fst_module_aux.external_sta_connect(dev[0], ap2, key_mgmt="NONE",
  1031. scan_freq=fst_test_common.fst_test_def_freq_g)
  1032. external_sta_connected = True
  1033. time.sleep(2)
  1034. fst_module_aux.disconnect_external_sta(dev[0], ap2)
  1035. external_sta_connected = False
  1036. time.sleep(2)
  1037. orig_ap_mbies = ap2.get_local_mbies()
  1038. fst_sta1.disconnect()
  1039. time.sleep(2)
  1040. res_ap_mbies = ap2.get_local_mbies()
  1041. if res_ap_mbies != orig_ap_mbies:
  1042. raise Exception("Failure. MB IEs have been unexpectedly updated on the AP")
  1043. except Exception, e:
  1044. logger.info(e)
  1045. raise
  1046. finally:
  1047. fst_sta1.disconnect()
  1048. if external_sta_connected:
  1049. fst_module_aux.disconnect_external_sta(dev[0], ap2)
  1050. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, fst_sta1, fst_sta2)
  1051. def test_fst_dynamic_iface_attach(dev, apdev, test_params):
  1052. """FST dynamic interface attach"""
  1053. ap1 = fst_module_aux.FstAP(apdev[0]['ifname'], 'fst_11a', 'a',
  1054. fst_test_common.fst_test_def_chan_a,
  1055. fst_test_common.fst_test_def_group,
  1056. fst_test_common.fst_test_def_prio_low,
  1057. fst_test_common.fst_test_def_llt)
  1058. ap1.start()
  1059. ap2 = fst_module_aux.FstAP(apdev[1]['ifname'], 'fst_11g', 'b',
  1060. fst_test_common.fst_test_def_chan_g,
  1061. '', '', '')
  1062. ap2.start()
  1063. sta1 = fst_module_aux.FstSTA('wlan5',
  1064. fst_test_common.fst_test_def_group,
  1065. fst_test_common.fst_test_def_prio_low,
  1066. fst_test_common.fst_test_def_llt)
  1067. sta1.start()
  1068. sta2 = fst_module_aux.FstSTA('wlan6', '', '', '')
  1069. sta2.start()
  1070. try:
  1071. orig_sta2_mbies = sta2.get_local_mbies()
  1072. orig_ap2_mbies = ap2.get_local_mbies()
  1073. sta2.send_iface_attach_request(sta2.ifname(),
  1074. fst_test_common.fst_test_def_group,
  1075. '52', '27')
  1076. event = sta2.wait_for_iface_event(5)
  1077. if event['event_type'] != 'attached':
  1078. raise Exception("Failure. Iface was not properly attached")
  1079. ap2.send_iface_attach_request(ap2.ifname(),
  1080. fst_test_common.fst_test_def_group,
  1081. '102', '77')
  1082. event = ap2.wait_for_iface_event(5)
  1083. if event['event_type'] != 'attached':
  1084. raise Exception("Failure. Iface was not properly attached")
  1085. time.sleep(2)
  1086. res_sta2_mbies = sta2.get_local_mbies()
  1087. res_ap2_mbies = ap2.get_local_mbies()
  1088. sta2.send_iface_detach_request(sta2.ifname())
  1089. event = sta2.wait_for_iface_event(5)
  1090. if event['event_type'] != 'detached':
  1091. raise Exception("Failure. Iface was not properly detached")
  1092. ap2.send_iface_detach_request(ap2.ifname())
  1093. event = ap2.wait_for_iface_event(5)
  1094. if event['event_type'] != 'detached':
  1095. raise Exception("Failure. Iface was not properly detached")
  1096. if (not orig_sta2_mbies.startswith("FAIL") or
  1097. not orig_ap2_mbies.startswith("FAIL") or
  1098. res_sta2_mbies.startswith("FAIL") or
  1099. res_ap2_mbies.startswith("FAIL")):
  1100. raise Exception("Failure. MB IEs should have appeared on the station and on the AP")
  1101. except Exception, e:
  1102. logger.info(e)
  1103. raise
  1104. finally:
  1105. ap1.stop()
  1106. ap2.stop()
  1107. sta1.stop()
  1108. sta2.stop()
  1109. # AP side FST module tests
  1110. def test_fst_ap_start_session(dev, apdev, test_params):
  1111. """FST AP start session"""
  1112. fst_start_session(apdev, test_params, bad_param_none, True)
  1113. def test_fst_ap_start_session_no_add_params(dev, apdev, test_params):
  1114. """FST AP start session - no add params"""
  1115. fst_start_session(apdev, test_params, bad_param_session_add_no_params, True)
  1116. def test_fst_ap_start_session_bad_group_id(dev, apdev, test_params):
  1117. """FST AP start session - bad group id"""
  1118. fst_start_session(apdev, test_params, bad_param_group_id, True)
  1119. def test_fst_ap_start_session_no_set_params(dev, apdev, test_params):
  1120. """FST AP start session - no set params"""
  1121. fst_start_session(apdev, test_params, bad_param_session_set_no_params, True)
  1122. def test_fst_ap_start_session_set_unknown_param(dev, apdev, test_params):
  1123. """FST AP start session - set unknown param"""
  1124. fst_start_session(apdev, test_params, bad_param_session_set_unknown_param,
  1125. True)
  1126. def test_fst_ap_start_session_bad_session_id(dev, apdev, test_params):
  1127. """FST AP start session - bad session id"""
  1128. fst_start_session(apdev, test_params, bad_param_session_id, True)
  1129. def test_fst_ap_start_session_bad_new_iface(dev, apdev, test_params):
  1130. """FST AP start session - bad new iface"""
  1131. fst_start_session(apdev, test_params, bad_param_new_iface, True)
  1132. def test_fst_ap_start_session_bad_old_iface(dev, apdev, test_params):
  1133. """FST AP start session - bad old iface"""
  1134. fst_start_session(apdev, test_params, bad_param_old_iface, True)
  1135. def test_fst_ap_start_session_negative_llt(dev, apdev, test_params):
  1136. """FST AP start session - negative llt"""
  1137. fst_start_session(apdev, test_params, bad_param_negative_llt, True)
  1138. def test_fst_ap_start_session_zero_llt(dev, apdev, test_params):
  1139. """FST AP start session - zero llt"""
  1140. fst_start_session(apdev, test_params, bad_param_zero_llt, True)
  1141. def test_fst_ap_start_session_llt_too_big(dev, apdev, test_params):
  1142. """FST AP start session - llt too large"""
  1143. fst_start_session(apdev, test_params, bad_param_llt_too_big, True)
  1144. def test_fst_ap_start_session_invalid_peer_addr(dev, apdev, test_params):
  1145. """FST AP start session - invalid peer address"""
  1146. fst_start_session(apdev, test_params, bad_param_peer_addr, True,
  1147. 'GG:GG:GG:GG:GG:GG')
  1148. def test_fst_ap_start_session_multicast_peer_addr(dev, apdev, test_params):
  1149. """FST AP start session - multicast peer address"""
  1150. fst_start_session(apdev, test_params, bad_param_peer_addr, True,
  1151. '01:00:11:22:33:44')
  1152. def test_fst_ap_start_session_broadcast_peer_addr(dev, apdev, test_params):
  1153. """FST AP start session - broadcast peer address"""
  1154. fst_start_session(apdev, test_params, bad_param_peer_addr, True,
  1155. 'FF:FF:FF:FF:FF:FF')
  1156. def test_fst_ap_initiate_session(dev, apdev, test_params):
  1157. """FST AP initiate session"""
  1158. fst_initiate_session(apdev, test_params, bad_param_none, True)
  1159. def test_fst_ap_initiate_session_no_params(dev, apdev, test_params):
  1160. """FST AP initiate session - no params"""
  1161. fst_initiate_session(apdev, test_params,
  1162. bad_param_session_initiate_no_params, True)
  1163. def test_fst_ap_initiate_session_invalid_session_id(dev, apdev, test_params):
  1164. """FST AP initiate session - invalid session id"""
  1165. fst_initiate_session(apdev, test_params,
  1166. bad_param_session_initiate_bad_session_id, True)
  1167. def test_fst_ap_initiate_session_no_new_iface(dev, apdev, test_params):
  1168. """FST AP initiate session - no new iface"""
  1169. fst_initiate_session(apdev, test_params,
  1170. bad_param_session_initiate_with_no_new_iface_set, True)
  1171. def test_fst_ap_initiate_session_bad_peer_addr(dev, apdev, test_params):
  1172. """FST AP initiate session - bad peer address"""
  1173. fst_initiate_session(apdev, test_params,
  1174. bad_param_session_initiate_with_bad_peer_addr_set,
  1175. True)
  1176. def test_fst_ap_initiate_session_request_with_bad_stie(dev, apdev, test_params):
  1177. """FST AP initiate session - request with bad stie"""
  1178. fst_initiate_session(apdev, test_params,
  1179. bad_param_session_initiate_request_with_bad_stie, True)
  1180. def test_fst_ap_initiate_session_response_with_reject(dev, apdev, test_params):
  1181. """FST AP initiate session - response with reject"""
  1182. fst_initiate_session(apdev, test_params,
  1183. bad_param_session_initiate_response_with_reject, True)
  1184. def test_fst_ap_initiate_session_response_with_bad_stie(dev, apdev,
  1185. test_params):
  1186. """FST AP initiate session - response with bad stie"""
  1187. fst_initiate_session(apdev, test_params,
  1188. bad_param_session_initiate_response_with_bad_stie,
  1189. True)
  1190. def test_fst_ap_initiate_session_response_with_zero_llt(dev, apdev,
  1191. test_params):
  1192. """FST AP initiate session - zero llt"""
  1193. fst_initiate_session(apdev, test_params,
  1194. bad_param_session_initiate_response_with_zero_llt,
  1195. True)
  1196. def test_fst_ap_initiate_session_stt_no_response(dev, apdev, test_params):
  1197. """FST AP initiate session - stt no response"""
  1198. fst_initiate_session(apdev, test_params,
  1199. bad_param_session_initiate_stt_no_response, True)
  1200. def test_fst_ap_initiate_session_concurrent_setup_request(dev, apdev,
  1201. test_params):
  1202. """FST AP initiate session - concurrent setup request"""
  1203. fst_initiate_session(apdev, test_params,
  1204. bad_param_session_initiate_concurrent_setup_request,
  1205. True)
  1206. def test_fst_ap_session_request_with_no_session(dev, apdev, test_params):
  1207. """FST AP session request with no session"""
  1208. fst_send_unexpected_frame(apdev, test_params, frame_type_session_request,
  1209. True)
  1210. def test_fst_ap_session_response_accept_with_no_session(dev, apdev,
  1211. test_params):
  1212. """FST AP session response accept with no session"""
  1213. fst_send_unexpected_frame(apdev, test_params, frame_type_session_response,
  1214. True, "accept")
  1215. def test_fst_ap_session_response_reject_with_no_session(dev, apdev,
  1216. test_params):
  1217. """FST AP session response reject with no session"""
  1218. fst_send_unexpected_frame(apdev, test_params, frame_type_session_response,
  1219. True, "reject")
  1220. def test_fst_ap_ack_request_with_no_session(dev, apdev, test_params):
  1221. """FST AP ack request with no session"""
  1222. fst_send_unexpected_frame(apdev, test_params, frame_type_ack_request, True)
  1223. def test_fst_ap_ack_response_with_no_session(dev, apdev, test_params):
  1224. """FST AP ack response with no session"""
  1225. fst_send_unexpected_frame(apdev, test_params, frame_type_ack_response, True)
  1226. def test_fst_ap_tear_down_response_with_no_session(dev, apdev, test_params):
  1227. """FST AP tear down response with no session"""
  1228. fst_send_unexpected_frame(apdev, test_params, frame_type_tear_down, True)
  1229. def test_fst_ap_transfer_session(dev, apdev, test_params):
  1230. """FST AP transfer session"""
  1231. fst_transfer_session(apdev, test_params, bad_param_none, True)
  1232. def test_fst_ap_transfer_session_no_params(dev, apdev, test_params):
  1233. """FST AP transfer session - no params"""
  1234. fst_transfer_session(apdev, test_params,
  1235. bad_param_session_transfer_no_params, True)
  1236. def test_fst_ap_transfer_session_bad_session_id(dev, apdev, test_params):
  1237. """FST AP transfer session - bad session id"""
  1238. fst_transfer_session(apdev, test_params,
  1239. bad_param_session_transfer_bad_session_id, True)
  1240. def test_fst_ap_transfer_session_setup_skipped(dev, apdev, test_params):
  1241. """FST AP transfer session - setup skipped"""
  1242. fst_transfer_session(apdev, test_params,
  1243. bad_param_session_transfer_setup_skipped, True)
  1244. def test_fst_ap_ack_request_with_session_not_set_up(dev, apdev, test_params):
  1245. """FST AP ack request with session not set up"""
  1246. fst_bad_transfer(apdev, test_params,
  1247. bad_scenario_ack_req_session_not_set_up, True)
  1248. def test_fst_ap_ack_request_with_session_not_established_init_side(dev, apdev,
  1249. test_params):
  1250. """FST AP ack request with session not established init side"""
  1251. fst_bad_transfer(apdev, test_params,
  1252. bad_scenario_ack_req_session_not_established_init_side,
  1253. True)
  1254. def test_fst_ap_ack_request_with_session_not_established_resp_side(dev, apdev,
  1255. test_params):
  1256. """FST AP ack request with session not established resp side"""
  1257. fst_bad_transfer(apdev, test_params,
  1258. bad_scenario_ack_req_session_not_established_resp_side,
  1259. True)
  1260. def test_fst_ap_ack_request_with_bad_fsts_id(dev, apdev, test_params):
  1261. """FST AP ack request with bad fsts id"""
  1262. fst_bad_transfer(apdev, test_params, bad_scenario_ack_req_bad_fsts_id, True)
  1263. def test_fst_ap_ack_response_with_session_not_set_up(dev, apdev, test_params):
  1264. """FST AP ack response with session not set up"""
  1265. fst_bad_transfer(apdev, test_params,
  1266. bad_scenario_ack_resp_session_not_set_up, True)
  1267. def test_fst_ap_ack_response_with_session_not_established_init_side(dev, apdev, test_params):
  1268. """FST AP ack response with session not established init side"""
  1269. fst_bad_transfer(apdev, test_params,
  1270. bad_scenario_ack_resp_session_not_established_init_side,
  1271. True)
  1272. def test_fst_ap_ack_response_with_session_not_established_resp_side(dev, apdev, test_params):
  1273. """FST AP ack response with session not established resp side"""
  1274. fst_bad_transfer(apdev, test_params,
  1275. bad_scenario_ack_resp_session_not_established_resp_side,
  1276. True)
  1277. def test_fst_ap_ack_response_with_no_ack_request(dev, apdev, test_params):
  1278. """FST AP ack response with no ack request"""
  1279. fst_bad_transfer(apdev, test_params, bad_scenario_ack_resp_no_ack_req, True)
  1280. def test_fst_ap_tear_down_session(dev, apdev, test_params):
  1281. """FST AP tear down session"""
  1282. fst_tear_down_session(apdev, test_params, bad_param_none, True)
  1283. def test_fst_ap_tear_down_session_no_params(dev, apdev, test_params):
  1284. """FST AP tear down session - no params"""
  1285. fst_tear_down_session(apdev, test_params,
  1286. bad_param_session_teardown_no_params, True)
  1287. def test_fst_ap_tear_down_session_bad_session_id(dev, apdev, test_params):
  1288. """FST AP tear down session - bad session id"""
  1289. fst_tear_down_session(apdev, test_params,
  1290. bad_param_session_teardown_bad_session_id, True)
  1291. def test_fst_ap_tear_down_session_setup_skipped(dev, apdev, test_params):
  1292. """FST AP tear down session - setup skipped"""
  1293. fst_tear_down_session(apdev, test_params,
  1294. bad_param_session_teardown_setup_skipped, True)
  1295. def test_fst_ap_tear_down_session_bad_fsts_id(dev, apdev, test_params):
  1296. """FST AP tear down session - bad fsts id"""
  1297. fst_tear_down_session(apdev, test_params,
  1298. bad_param_session_teardown_bad_fsts_id, True)
  1299. def test_fst_ap_remove_session_not_established(dev, apdev, test_params):
  1300. """FST AP remove session - not established"""
  1301. fst_remove_session(apdev, test_params,
  1302. remove_scenario_non_established_session, True)
  1303. def test_fst_ap_remove_session_established(dev, apdev, test_params):
  1304. """FST AP remove session - established"""
  1305. fst_remove_session(apdev, test_params,
  1306. remove_scenario_established_session, True)
  1307. def test_fst_ap_remove_session_no_params(dev, apdev, test_params):
  1308. """FST AP remove session - no params"""
  1309. fst_remove_session(apdev, test_params, remove_scenario_no_params, True)
  1310. def test_fst_ap_remove_session_bad_session_id(dev, apdev, test_params):
  1311. """FST AP remove session - bad session id"""
  1312. fst_remove_session(apdev, test_params, remove_scenario_bad_session_id, True)
  1313. def test_fst_ap_ctrl_iface(dev, apdev, test_params):
  1314. """FST control interface behavior"""
  1315. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  1316. try:
  1317. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1318. initiator = ap1
  1319. responder = sta1
  1320. initiator.add_peer(responder, None)
  1321. initiator.set_fst_parameters(group_id=None)
  1322. sid = initiator.add_session()
  1323. res = initiator.get_session_params(sid)
  1324. logger.info("Initial session params:\n" + str(res))
  1325. if res['state'] != 'INITIAL':
  1326. raise Exception("Unexpected state: " + res['state'])
  1327. initiator.set_fst_parameters(llt=None)
  1328. initiator.configure_session(sid, ap2.ifname(), None)
  1329. res = initiator.get_session_params(sid)
  1330. logger.info("Session params after configuration:\n" + str(res))
  1331. res = initiator.iface_peers(initiator.ifname())
  1332. logger.info("Interface peers: " + str(res))
  1333. if len(res) != 1:
  1334. raise Exception("Unexpected number of peers")
  1335. res = initiator.get_peer_mbies(initiator.ifname(),
  1336. initiator.get_new_peer_addr())
  1337. logger.info("Peer MB IEs: " + str(res))
  1338. res = initiator.list_ifaces()
  1339. logger.info("Interfaces: " + str(res))
  1340. if len(res) != 2:
  1341. raise Exception("Unexpected number of interfaces")
  1342. res = initiator.list_groups()
  1343. logger.info("Groups: " + str(res))
  1344. if len(res) != 1:
  1345. raise Exception("Unexpected number of groups")
  1346. tests = [ "LIST_IFACES unknown",
  1347. "LIST_IFACES unknown2",
  1348. "SESSION_GET 12345678",
  1349. "SESSION_SET " + sid + " unknown=foo",
  1350. "SESSION_RESPOND 12345678 foo",
  1351. "SESSION_RESPOND " + sid,
  1352. "SESSION_RESPOND " + sid + " foo",
  1353. "TEST_REQUEST foo",
  1354. "GET_PEER_MBIES",
  1355. "GET_PEER_MBIES ",
  1356. "GET_PEER_MBIES unknown",
  1357. "GET_PEER_MBIES unknown unknown",
  1358. "GET_PEER_MBIES unknown " + initiator.get_new_peer_addr(),
  1359. "GET_PEER_MBIES " + initiator.ifname() + " 01:ff:ff:ff:ff:ff",
  1360. "IFACE_PEERS",
  1361. "IFACE_PEERS ",
  1362. "IFACE_PEERS unknown",
  1363. "IFACE_PEERS unknown unknown",
  1364. "IFACE_PEERS " + initiator.fst_group,
  1365. "IFACE_PEERS " + initiator.fst_group + " unknown" ]
  1366. for t in tests:
  1367. if "FAIL" not in initiator.grequest("FST-MANAGER " + t):
  1368. raise Exception("Unexpected response for invalid FST-MANAGER command " + t)
  1369. if "UNKNOWN FST COMMAND" not in initiator.grequest("FST-MANAGER unknown"):
  1370. raise Exception("Unexpected response for unknown FST-MANAGER command")
  1371. tests = [ "FST-DETACH", "FST-DETACH ", "FST-DETACH unknown",
  1372. "FST-ATTACH", "FST-ATTACH ", "FST-ATTACH unknown",
  1373. "FST-ATTACH unknown unknown" ]
  1374. for t in tests:
  1375. if "FAIL" not in initiator.grequest(t):
  1376. raise Exception("Unexpected response for invalid command " + t)
  1377. try:
  1378. # Trying to add same interface again needs to fail.
  1379. ap1.send_iface_attach_request(ap1.iface, ap1.fst_group,
  1380. ap1.fst_llt, ap1.fst_pri)
  1381. raise Exception("Duplicate FST-ATTACH succeeded")
  1382. except Exception, e:
  1383. if not str(e).startswith("Cannot attach"):
  1384. raise
  1385. try:
  1386. ap1.get_fsts_id_by_sid("123")
  1387. except Exception, e:
  1388. if not str(e).startswith("Cannot get fsts_id for sid"):
  1389. raise
  1390. finally:
  1391. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1392. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1393. def test_fst_ap_start_session_oom(dev, apdev, test_params):
  1394. """FST AP setup failing due to OOM"""
  1395. ap1 = fst_module_aux.FstAP(apdev[0]['ifname'], 'fst_11a', 'a',
  1396. fst_test_common.fst_test_def_chan_a,
  1397. fst_test_common.fst_test_def_group,
  1398. fst_test_common.fst_test_def_prio_low,
  1399. fst_test_common.fst_test_def_llt)
  1400. ap1.start()
  1401. with alloc_fail(ap1, 1, "fst_iface_create"):
  1402. ap2_started = False
  1403. try:
  1404. ap2 = fst_module_aux.FstAP(apdev[1]['ifname'], 'fst_11g', 'b',
  1405. fst_test_common.fst_test_def_chan_g,
  1406. fst_test_common.fst_test_def_group,
  1407. fst_test_common.fst_test_def_prio_high,
  1408. fst_test_common.fst_test_def_llt)
  1409. try:
  1410. # This will fail in fst_iface_create() OOM
  1411. ap2.start()
  1412. except:
  1413. pass
  1414. finally:
  1415. ap1.stop()
  1416. try:
  1417. ap2.stop()
  1418. except:
  1419. pass
  1420. # STA side FST module tests
  1421. def test_fst_sta_start_session(dev, apdev, test_params):
  1422. """FST STA start session"""
  1423. fst_start_session(apdev, test_params, bad_param_none, False)
  1424. def test_fst_sta_start_session_no_add_params(dev, apdev, test_params):
  1425. """FST STA start session - no add params"""
  1426. fst_start_session(apdev, test_params, bad_param_session_add_no_params,
  1427. False)
  1428. def test_fst_sta_start_session_bad_group_id(dev, apdev, test_params):
  1429. """FST STA start session - bad group id"""
  1430. fst_start_session(apdev, test_params, bad_param_group_id, False)
  1431. def test_fst_sta_start_session_no_set_params(dev, apdev, test_params):
  1432. """FST STA start session - no set params"""
  1433. fst_start_session(apdev, test_params, bad_param_session_set_no_params,
  1434. False)
  1435. def test_fst_sta_start_session_set_unknown_param(dev, apdev, test_params):
  1436. """FST STA start session - set unknown param"""
  1437. fst_start_session(apdev, test_params, bad_param_session_set_unknown_param,
  1438. False)
  1439. def test_fst_sta_start_session_bad_session_id(dev, apdev, test_params):
  1440. """FST STA start session - bad session id"""
  1441. fst_start_session(apdev, test_params, bad_param_session_id, False)
  1442. def test_fst_sta_start_session_bad_new_iface(dev, apdev, test_params):
  1443. """FST STA start session - bad new iface"""
  1444. fst_start_session(apdev, test_params, bad_param_new_iface, False)
  1445. def test_fst_sta_start_session_bad_old_iface(dev, apdev, test_params):
  1446. """FST STA start session - bad old iface"""
  1447. fst_start_session(apdev, test_params, bad_param_old_iface, False)
  1448. def test_fst_sta_start_session_negative_llt(dev, apdev, test_params):
  1449. """FST STA start session - negative llt"""
  1450. fst_start_session(apdev, test_params, bad_param_negative_llt, False)
  1451. def test_fst_sta_start_session_zero_llt(dev, apdev, test_params):
  1452. """FST STA start session - zero llt"""
  1453. fst_start_session(apdev, test_params, bad_param_zero_llt, False)
  1454. def test_fst_sta_start_session_llt_too_big(dev, apdev, test_params):
  1455. """FST STA start session - llt too large"""
  1456. fst_start_session(apdev, test_params, bad_param_llt_too_big, False)
  1457. def test_fst_sta_start_session_invalid_peer_addr(dev, apdev, test_params):
  1458. """FST STA start session - invalid peer address"""
  1459. fst_start_session(apdev, test_params, bad_param_peer_addr, False,
  1460. 'GG:GG:GG:GG:GG:GG')
  1461. def test_fst_sta_start_session_multicast_peer_addr(dev, apdev, test_params):
  1462. """FST STA start session - multicast peer address"""
  1463. fst_start_session(apdev, test_params, bad_param_peer_addr, False,
  1464. '11:00:11:22:33:44')
  1465. def test_fst_sta_start_session_broadcast_peer_addr(dev, apdev, test_params):
  1466. """FST STA start session - broadcast peer addr"""
  1467. fst_start_session(apdev, test_params, bad_param_peer_addr, False,
  1468. 'FF:FF:FF:FF:FF:FF')
  1469. def test_fst_sta_initiate_session(dev, apdev, test_params):
  1470. """FST STA initiate session"""
  1471. fst_initiate_session(apdev, test_params, bad_param_none, False)
  1472. def test_fst_sta_initiate_session_no_params(dev, apdev, test_params):
  1473. """FST STA initiate session - no params"""
  1474. fst_initiate_session(apdev, test_params,
  1475. bad_param_session_initiate_no_params, False)
  1476. def test_fst_sta_initiate_session_invalid_session_id(dev, apdev, test_params):
  1477. """FST STA initiate session - invalid session id"""
  1478. fst_initiate_session(apdev, test_params,
  1479. bad_param_session_initiate_bad_session_id, False)
  1480. def test_fst_sta_initiate_session_no_new_iface(dev, apdev, test_params):
  1481. """FST STA initiate session - no new iface"""
  1482. fst_initiate_session(apdev, test_params,
  1483. bad_param_session_initiate_with_no_new_iface_set,
  1484. False)
  1485. def test_fst_sta_initiate_session_bad_peer_addr(dev, apdev, test_params):
  1486. """FST STA initiate session - bad peer address"""
  1487. fst_initiate_session(apdev, test_params,
  1488. bad_param_session_initiate_with_bad_peer_addr_set,
  1489. False)
  1490. def test_fst_sta_initiate_session_request_with_bad_stie(dev, apdev,
  1491. test_params):
  1492. """FST STA initiate session - request with bad stie"""
  1493. fst_initiate_session(apdev, test_params,
  1494. bad_param_session_initiate_request_with_bad_stie,
  1495. False)
  1496. def test_fst_sta_initiate_session_response_with_reject(dev, apdev, test_params):
  1497. """FST STA initiate session - response with reject"""
  1498. fst_initiate_session(apdev, test_params, bad_param_session_initiate_response_with_reject, False)
  1499. def test_fst_sta_initiate_session_response_with_bad_stie(dev, apdev, test_params):
  1500. """FST STA initiate session - response with bad stie"""
  1501. fst_initiate_session(apdev, test_params,
  1502. bad_param_session_initiate_response_with_bad_stie,
  1503. False)
  1504. def test_fst_sta_initiate_session_response_with_zero_llt(dev, apdev,
  1505. test_params):
  1506. """FST STA initiate session - response with zero llt"""
  1507. fst_initiate_session(apdev, test_params,
  1508. bad_param_session_initiate_response_with_zero_llt,
  1509. False)
  1510. def test_fst_sta_initiate_session_stt_no_response(dev, apdev, test_params):
  1511. """FST STA initiate session - stt no response"""
  1512. fst_initiate_session(apdev, test_params,
  1513. bad_param_session_initiate_stt_no_response, False)
  1514. def test_fst_sta_initiate_session_concurrent_setup_request(dev, apdev,
  1515. test_params):
  1516. """FST STA initiate session - concurrent setup request"""
  1517. fst_initiate_session(apdev, test_params,
  1518. bad_param_session_initiate_concurrent_setup_request,
  1519. False)
  1520. def test_fst_sta_session_request_with_no_session(dev, apdev, test_params):
  1521. """FST STA session request with no session"""
  1522. fst_send_unexpected_frame(apdev, test_params, frame_type_session_request,
  1523. False)
  1524. def test_fst_sta_session_response_accept_with_no_session(dev, apdev,
  1525. test_params):
  1526. """FST STA session response accept with no session"""
  1527. fst_send_unexpected_frame(apdev, test_params, frame_type_session_response,
  1528. False, "accept")
  1529. def test_fst_sta_session_response_reject_with_no_session(dev, apdev,
  1530. test_params):
  1531. """FST STA session response reject with no session"""
  1532. fst_send_unexpected_frame(apdev, test_params, frame_type_session_response,
  1533. False, "reject")
  1534. def test_fst_sta_ack_request_with_no_session(dev, apdev, test_params):
  1535. """FST STA ack request with no session"""
  1536. fst_send_unexpected_frame(apdev, test_params, frame_type_ack_request, False)
  1537. def test_fst_sta_ack_response_with_no_session(dev, apdev, test_params):
  1538. """FST STA ack response with no session"""
  1539. fst_send_unexpected_frame(apdev, test_params, frame_type_ack_response,
  1540. False)
  1541. def test_fst_sta_tear_down_response_with_no_session(dev, apdev, test_params):
  1542. """FST STA tear down response with no session"""
  1543. fst_send_unexpected_frame(apdev, test_params, frame_type_tear_down, False)
  1544. def test_fst_sta_transfer_session(dev, apdev, test_params):
  1545. """FST STA transfer session"""
  1546. fst_transfer_session(apdev, test_params, bad_param_none, False)
  1547. def test_fst_sta_transfer_session_no_params(dev, apdev, test_params):
  1548. """FST STA transfer session - no params"""
  1549. fst_transfer_session(apdev, test_params,
  1550. bad_param_session_transfer_no_params, False)
  1551. def test_fst_sta_transfer_session_bad_session_id(dev, apdev, test_params):
  1552. """FST STA transfer session - bad session id"""
  1553. fst_transfer_session(apdev, test_params,
  1554. bad_param_session_transfer_bad_session_id, False)
  1555. def test_fst_sta_transfer_session_setup_skipped(dev, apdev, test_params):
  1556. """FST STA transfer session - setup skipped"""
  1557. fst_transfer_session(apdev, test_params,
  1558. bad_param_session_transfer_setup_skipped, False)
  1559. def test_fst_sta_ack_request_with_session_not_set_up(dev, apdev, test_params):
  1560. """FST STA ack request with session not set up"""
  1561. fst_bad_transfer(apdev, test_params,
  1562. bad_scenario_ack_req_session_not_set_up, False)
  1563. def test_fst_sta_ack_request_with_session_not_established_init_side(dev, apdev, test_params):
  1564. """FST STA ack request with session not established init side"""
  1565. fst_bad_transfer(apdev, test_params,
  1566. bad_scenario_ack_req_session_not_established_init_side,
  1567. False)
  1568. def test_fst_sta_ack_request_with_session_not_established_resp_side(dev, apdev, test_params):
  1569. """FST STA ack request with session not established resp side"""
  1570. fst_bad_transfer(apdev, test_params,
  1571. bad_scenario_ack_req_session_not_established_resp_side,
  1572. False)
  1573. def test_fst_sta_ack_request_with_bad_fsts_id(dev, apdev, test_params):
  1574. """FST STA ack request with bad fsts id"""
  1575. fst_bad_transfer(apdev, test_params, bad_scenario_ack_req_bad_fsts_id,
  1576. False)
  1577. def test_fst_sta_ack_response_with_session_not_set_up(dev, apdev, test_params):
  1578. """FST STA ack response with session not set up"""
  1579. fst_bad_transfer(apdev, test_params,
  1580. bad_scenario_ack_resp_session_not_set_up, False)
  1581. def test_fst_sta_ack_response_with_session_not_established_init_side(dev, apdev, test_params):
  1582. """FST STA ack response with session not established init side"""
  1583. fst_bad_transfer(apdev, test_params,
  1584. bad_scenario_ack_resp_session_not_established_init_side,
  1585. False)
  1586. def test_fst_sta_ack_response_with_session_not_established_resp_side(dev, apdev, test_params):
  1587. """FST STA ack response with session not established resp side"""
  1588. fst_bad_transfer(apdev, test_params,
  1589. bad_scenario_ack_resp_session_not_established_resp_side,
  1590. False)
  1591. def test_fst_sta_ack_response_with_no_ack_request(dev, apdev, test_params):
  1592. """FST STA ack response with no ack request"""
  1593. fst_bad_transfer(apdev, test_params, bad_scenario_ack_resp_no_ack_req,
  1594. False)
  1595. def test_fst_sta_tear_down_session(dev, apdev, test_params):
  1596. """FST STA tear down session"""
  1597. fst_tear_down_session(apdev, test_params, bad_param_none, False)
  1598. def test_fst_sta_tear_down_session_no_params(dev, apdev, test_params):
  1599. """FST STA tear down session - no params"""
  1600. fst_tear_down_session(apdev, test_params,
  1601. bad_param_session_teardown_no_params, False)
  1602. def test_fst_sta_tear_down_session_bad_session_id(dev, apdev, test_params):
  1603. """FST STA tear down session - bad session id"""
  1604. fst_tear_down_session(apdev, test_params,
  1605. bad_param_session_teardown_bad_session_id, False)
  1606. def test_fst_sta_tear_down_session_setup_skipped(dev, apdev, test_params):
  1607. """FST STA tear down session - setup skipped"""
  1608. fst_tear_down_session(apdev, test_params,
  1609. bad_param_session_teardown_setup_skipped, False)
  1610. def test_fst_sta_tear_down_session_bad_fsts_id(dev, apdev, test_params):
  1611. """FST STA tear down session - bad fsts id"""
  1612. fst_tear_down_session(apdev, test_params,
  1613. bad_param_session_teardown_bad_fsts_id, False)
  1614. def test_fst_sta_remove_session_not_established(dev, apdev, test_params):
  1615. """FST STA tear down session - not established"""
  1616. fst_remove_session(apdev, test_params,
  1617. remove_scenario_non_established_session, False)
  1618. def test_fst_sta_remove_session_established(dev, apdev, test_params):
  1619. """FST STA remove session - established"""
  1620. fst_remove_session(apdev, test_params,
  1621. remove_scenario_established_session, False)
  1622. def test_fst_sta_remove_session_no_params(dev, apdev, test_params):
  1623. """FST STA remove session - no params"""
  1624. fst_remove_session(apdev, test_params, remove_scenario_no_params, False)
  1625. def test_fst_sta_remove_session_bad_session_id(dev, apdev, test_params):
  1626. """FST STA remove session - bad session id"""
  1627. fst_remove_session(apdev, test_params, remove_scenario_bad_session_id,
  1628. False)
  1629. def test_fst_rsn_ap_transfer_session(dev, apdev, test_params):
  1630. """FST RSN AP transfer session"""
  1631. fst_transfer_session(apdev, test_params, bad_param_none, True, rsn=True)
  1632. MGMT_SUBTYPE_ACTION = 13
  1633. ACTION_CATEG_FST = 18
  1634. FST_ACTION_SETUP_REQUEST = 0
  1635. FST_ACTION_SETUP_RESPONSE = 1
  1636. FST_ACTION_TEAR_DOWN = 2
  1637. FST_ACTION_ACK_REQUEST = 3
  1638. FST_ACTION_ACK_RESPONSE = 4
  1639. FST_ACTION_ON_CHANNEL_TUNNEL = 5
  1640. def test_fst_proto(dev, apdev, test_params):
  1641. """FST protocol testing"""
  1642. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  1643. try:
  1644. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1645. hapd = ap1.get_instance()
  1646. sta = sta1.get_instance()
  1647. dst = sta.own_addr()
  1648. src = apdev[0]['bssid']
  1649. msg = {}
  1650. msg['fc'] = MGMT_SUBTYPE_ACTION << 4
  1651. msg['da'] = dst
  1652. msg['sa'] = src
  1653. msg['bssid'] = src
  1654. # unknown FST Action (255) received!
  1655. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST, 255)
  1656. hapd.mgmt_tx(msg)
  1657. time.sleep(0.1)
  1658. # FST Request dropped: too short
  1659. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1660. FST_ACTION_SETUP_REQUEST)
  1661. hapd.mgmt_tx(msg)
  1662. time.sleep(0.1)
  1663. # FST Request dropped: new and old band IDs are the same
  1664. msg['payload'] = struct.pack("<BBBLBBLBBBBBBB", ACTION_CATEG_FST,
  1665. FST_ACTION_SETUP_REQUEST, 0, 0,
  1666. 164, 11, 0, 0, 0, 0, 0, 0, 0, 0)
  1667. hapd.mgmt_tx(msg)
  1668. time.sleep(0.1)
  1669. ifaces = sta1.list_ifaces()
  1670. id = int(ifaces[0]['name'].split('|')[1])
  1671. # FST Request dropped: new iface not found (new_band_id mismatch)
  1672. msg['payload'] = struct.pack("<BBBLBBLBBBBBBB", ACTION_CATEG_FST,
  1673. FST_ACTION_SETUP_REQUEST, 0, 0,
  1674. 164, 11, 0, 0, id + 1, 0, 0, 0, 0, 0)
  1675. hapd.mgmt_tx(msg)
  1676. time.sleep(0.1)
  1677. # FST Action 'Setup Response' dropped: no session in progress found
  1678. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1679. FST_ACTION_SETUP_RESPONSE)
  1680. hapd.mgmt_tx(msg)
  1681. # Create session
  1682. initiator = ap1
  1683. responder = sta1
  1684. new_iface = ap2.ifname()
  1685. new_peer_addr = ap2.get_actual_peer_addr()
  1686. resp_newif = sta2.ifname()
  1687. peeraddr = None
  1688. initiator.add_peer(responder, peeraddr, new_peer_addr)
  1689. sid = initiator.add_session()
  1690. initiator.configure_session(sid, new_iface)
  1691. initiator.initiate_session(sid, "accept")
  1692. # FST Response dropped due to wrong state: SETUP_COMPLETION
  1693. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1694. FST_ACTION_SETUP_RESPONSE)
  1695. hapd.mgmt_tx(msg)
  1696. time.sleep(0.1)
  1697. # Too short FST Tear Down dropped
  1698. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1699. FST_ACTION_TEAR_DOWN)
  1700. hapd.mgmt_tx(msg)
  1701. time.sleep(0.1)
  1702. # tear down for wrong FST Setup ID (0)
  1703. msg['payload'] = struct.pack("<BBL", ACTION_CATEG_FST,
  1704. FST_ACTION_TEAR_DOWN, 0)
  1705. hapd.mgmt_tx(msg)
  1706. time.sleep(0.1)
  1707. # Ack received on wrong interface
  1708. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1709. FST_ACTION_ACK_REQUEST)
  1710. hapd.mgmt_tx(msg)
  1711. time.sleep(0.1)
  1712. # Ack Response in inappropriate session state (SETUP_COMPLETION)
  1713. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1714. FST_ACTION_ACK_RESPONSE)
  1715. hapd.mgmt_tx(msg)
  1716. time.sleep(0.1)
  1717. # Unsupported FST Action frame (On channel tunnel)
  1718. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1719. FST_ACTION_ON_CHANNEL_TUNNEL)
  1720. hapd.mgmt_tx(msg)
  1721. time.sleep(0.1)
  1722. # FST Request dropped: new iface not found (new_band_id match)
  1723. # FST Request dropped due to MAC comparison
  1724. msg['payload'] = struct.pack("<BBBLBBLBBBBBBB", ACTION_CATEG_FST,
  1725. FST_ACTION_SETUP_REQUEST, 0, 0,
  1726. 164, 11, 0, 0, id, 0, 0, 0, 0, 0)
  1727. hapd.mgmt_tx(msg)
  1728. time.sleep(0.1)
  1729. hapd2 = ap2.get_instance()
  1730. dst2 = sta2.get_instance().own_addr()
  1731. src2 = apdev[1]['bssid']
  1732. msg2 = {}
  1733. msg2['fc'] = MGMT_SUBTYPE_ACTION << 4
  1734. msg2['da'] = dst2
  1735. msg2['sa'] = src2
  1736. msg2['bssid'] = src2
  1737. # FST Response dropped: wlan6 is not the old iface
  1738. msg2['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1739. FST_ACTION_SETUP_RESPONSE)
  1740. hapd2.mgmt_tx(msg2)
  1741. time.sleep(0.1)
  1742. sta.dump_monitor()
  1743. group = ap1.fst_group
  1744. ap1.send_iface_detach_request(ap1.iface)
  1745. sta.flush_scan_cache()
  1746. sta.request("REASSOCIATE")
  1747. sta.wait_connected()
  1748. # FST Request dropped due to no interface connection
  1749. msg['payload'] = struct.pack("<BBBLBBLBBBBBBB", ACTION_CATEG_FST,
  1750. FST_ACTION_SETUP_REQUEST, 0, 0,
  1751. 164, 11, 0, 0, id, 0, 0, 0, 0, 0)
  1752. hapd.mgmt_tx(msg)
  1753. finally:
  1754. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1755. try:
  1756. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1757. except:
  1758. pass
  1759. def test_fst_ap_config_oom(dev, apdev, test_params):
  1760. """FST AP configuration and OOM"""
  1761. ap1 = fst_module_aux.FstAP(apdev[0]['ifname'], 'fst_11a', 'a',
  1762. fst_test_common.fst_test_def_chan_a,
  1763. fst_test_common.fst_test_def_group,
  1764. fst_test_common.fst_test_def_prio_low)
  1765. hapd = ap1.start(return_early=True)
  1766. with alloc_fail(hapd, 1, "fst_group_create"):
  1767. res = ap1.grequest("FST-ATTACH %s %s" % (ap1.iface, ap1.fst_group))
  1768. if not res.startswith("FAIL"):
  1769. raise Exception("FST-ATTACH succeeded unexpectedly")
  1770. with alloc_fail(hapd, 1, "fst_iface_create"):
  1771. res = ap1.grequest("FST-ATTACH %s %s" % (ap1.iface, ap1.fst_group))
  1772. if not res.startswith("FAIL"):
  1773. raise Exception("FST-ATTACH succeeded unexpectedly")
  1774. with alloc_fail(hapd, 1, "fst_group_create_mb_ie"):
  1775. res = ap1.grequest("FST-ATTACH %s %s" % (ap1.iface, ap1.fst_group))
  1776. # This is allowed to complete currently
  1777. ap1.stop()
  1778. def test_fst_send_oom(dev, apdev, test_params):
  1779. """FST send action OOM"""
  1780. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  1781. try:
  1782. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1783. hapd = ap1.get_instance()
  1784. sta = sta1.get_instance()
  1785. dst = sta.own_addr()
  1786. src = apdev[0]['bssid']
  1787. # Create session
  1788. initiator = ap1
  1789. responder = sta1
  1790. new_iface = ap2.ifname()
  1791. new_peer_addr = ap2.get_actual_peer_addr()
  1792. resp_newif = sta2.ifname()
  1793. peeraddr = None
  1794. initiator.add_peer(responder, peeraddr, new_peer_addr)
  1795. sid = initiator.add_session()
  1796. initiator.configure_session(sid, new_iface)
  1797. with alloc_fail(hapd, 1, "fst_session_send_action"):
  1798. res = initiator.grequest("FST-MANAGER SESSION_INITIATE " + sid)
  1799. if not res.startswith("FAIL"):
  1800. raise Exception("Unexpected SESSION_INITIATE result")
  1801. res = initiator.grequest("FST-MANAGER SESSION_INITIATE " + sid)
  1802. if not res.startswith("OK"):
  1803. raise Exception("SESSION_INITIATE failed")
  1804. tests = [ "", "foo", sid, sid + " foo", sid + " foo=bar" ]
  1805. for t in tests:
  1806. res = initiator.grequest("FST-MANAGER SESSION_SET " + t)
  1807. if not res.startswith("FAIL"):
  1808. raise Exception("Invalid SESSION_SET accepted")
  1809. with alloc_fail(hapd, 1, "fst_session_send_action"):
  1810. res = initiator.grequest("FST-MANAGER SESSION_TEARDOWN " + sid)
  1811. if not res.startswith("FAIL"):
  1812. raise Exception("Unexpected SESSION_TEARDOWN result")
  1813. finally:
  1814. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1815. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1816. def test_fst_session_oom(dev, apdev, test_params):
  1817. """FST session create OOM"""
  1818. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  1819. try:
  1820. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1821. hapd = ap1.get_instance()
  1822. sta = sta1.get_instance()
  1823. dst = sta.own_addr()
  1824. src = apdev[0]['bssid']
  1825. # Create session
  1826. initiator = ap1
  1827. responder = sta1
  1828. new_iface = ap2.ifname()
  1829. new_peer_addr = ap2.get_actual_peer_addr()
  1830. resp_newif = sta2.ifname()
  1831. peeraddr = None
  1832. initiator.add_peer(responder, peeraddr, new_peer_addr)
  1833. with alloc_fail(hapd, 1, "fst_session_create"):
  1834. sid = initiator.grequest("FST-MANAGER SESSION_ADD " + initiator.fst_group)
  1835. if not sid.startswith("FAIL"):
  1836. raise Exception("Unexpected SESSION_ADD success")
  1837. sid = initiator.add_session()
  1838. initiator.configure_session(sid, new_iface)
  1839. with alloc_fail(sta, 1, "fst_session_create"):
  1840. res = initiator.grequest("FST-MANAGER SESSION_INITIATE " + sid)
  1841. if not res.startswith("OK"):
  1842. raise Exception("Unexpected SESSION_INITIATE result")
  1843. finally:
  1844. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1845. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1846. def test_fst_attach_zero_llt(dev, apdev):
  1847. """FST attach with llt=0"""
  1848. sta1 = fst_module_aux.FstSTA('wlan5', fst_test_common.fst_test_def_group,
  1849. "100", "0")
  1850. sta1.start()
  1851. sta1.stop()
  1852. def test_fst_session_respond_fail(dev, apdev, test_params):
  1853. """FST-MANAGER SESSION_RESPOND failure"""
  1854. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  1855. try:
  1856. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1857. sta1.add_peer(ap1, None, sta2.get_actual_peer_addr())
  1858. sid = sta1.add_session()
  1859. sta1.configure_session(sid, sta2.ifname())
  1860. sta1.send_session_setup_request(sid)
  1861. sta1.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  1862. ev = ap1.wait_for_session_event(5, [], ['EVENT_FST_SETUP'])
  1863. if not 'id' in ev:
  1864. raise Exception("No session id in FST setup event")
  1865. # Disconnect STA to make SESSION_RESPOND fail due to no peer found
  1866. sta = sta1.get_instance()
  1867. sta.request("DISCONNECT")
  1868. sta.wait_disconnected()
  1869. req = "FST-MANAGER SESSION_RESPOND %s reject" % ev['id']
  1870. s = ap1.grequest(req)
  1871. if not s.startswith("FAIL"):
  1872. raise Exception("SESSION_RESPOND succeeded unexpectedly")
  1873. finally:
  1874. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1875. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)