test_fst_module.py 85 KB

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