test_fst_module.py 85 KB

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