test_fst_module.py 128 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823
  1. # FST functionality tests
  2. # Copyright (c) 2015, Qualcomm Atheros, Inc.
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import logging
  7. logger = logging.getLogger()
  8. import struct
  9. import subprocess
  10. import time
  11. import os
  12. import re
  13. import hwsim_utils
  14. from hwsim import HWSimRadio
  15. import hostapd
  16. from wpasupplicant import WpaSupplicant
  17. import fst_test_common
  18. import fst_module_aux
  19. from utils import alloc_fail, HwsimSkip
  20. #enum - bad parameter types
  21. bad_param_none = 0
  22. bad_param_session_add_no_params = 1
  23. bad_param_group_id = 2
  24. bad_param_session_set_no_params = 3
  25. bad_param_session_set_unknown_param = 4
  26. bad_param_session_id = 5
  27. bad_param_old_iface = 6
  28. bad_param_new_iface = 7
  29. bad_param_negative_llt = 8
  30. bad_param_zero_llt = 9
  31. bad_param_llt_too_big = 10
  32. bad_param_llt_nan = 11
  33. bad_param_peer_addr = 12
  34. bad_param_session_initiate_no_params = 13
  35. bad_param_session_initiate_bad_session_id = 14
  36. bad_param_session_initiate_with_no_new_iface_set = 15
  37. bad_param_session_initiate_with_bad_peer_addr_set = 16
  38. bad_param_session_initiate_request_with_bad_stie = 17
  39. bad_param_session_initiate_response_with_reject = 18
  40. bad_param_session_initiate_response_with_bad_stie = 19
  41. bad_param_session_initiate_response_with_zero_llt = 20
  42. bad_param_session_initiate_stt_no_response = 21
  43. bad_param_session_initiate_concurrent_setup_request = 22
  44. bad_param_session_transfer_no_params = 23
  45. bad_param_session_transfer_bad_session_id = 24
  46. bad_param_session_transfer_setup_skipped = 25
  47. bad_param_session_teardown_no_params = 26
  48. bad_param_session_teardown_bad_session_id = 27
  49. bad_param_session_teardown_setup_skipped = 28
  50. bad_param_session_teardown_bad_fsts_id = 29
  51. bad_param_names = ("None",
  52. "No params passed to session add",
  53. "Group ID",
  54. "No params passed to session set",
  55. "Unknown param passed to session set",
  56. "Session ID",
  57. "Old interface name",
  58. "New interface name",
  59. "Negative LLT",
  60. "Zero LLT",
  61. "LLT too big",
  62. "LLT is not a number",
  63. "Peer address",
  64. "No params passed to session initiate",
  65. "Session ID",
  66. "No new_iface was set",
  67. "Peer address",
  68. "Request with bad st ie",
  69. "Response with reject",
  70. "Response with bad st ie",
  71. "Response with zero llt",
  72. "No response, STT",
  73. "Concurrent setup request",
  74. "No params passed to session transfer",
  75. "Session ID",
  76. "Session setup skipped",
  77. "No params passed to session teardown",
  78. "Bad session",
  79. "Session setup skipped",
  80. "Bad fsts_id")
  81. def fst_start_session(apdev, test_params, bad_param_type, start_on_ap,
  82. peer_addr = None):
  83. """This function makes the necessary preparations and the adds and sets a
  84. session using either correct or incorrect parameters depending on the value
  85. of bad_param_type. If the call ends as expected (with session being
  86. successfully added and set in case of correct parameters or with the
  87. expected exception in case of incorrect parameters), the function silently
  88. exits. Otherwise, it throws an exception thus failing the test."""
  89. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  90. bad_parameter_detected = False
  91. exception_already_raised = False
  92. try:
  93. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  94. if start_on_ap:
  95. initiator = ap1
  96. responder = sta1
  97. new_iface = ap2.ifname()
  98. new_peer_addr = ap2.get_actual_peer_addr()
  99. else:
  100. initiator = sta1
  101. responder = ap1
  102. new_iface = sta2.ifname()
  103. new_peer_addr = sta2.get_actual_peer_addr()
  104. initiator.add_peer(responder, peer_addr, new_peer_addr)
  105. group_id = None
  106. if bad_param_type == bad_param_group_id:
  107. group_id = '-1'
  108. elif bad_param_type == bad_param_session_add_no_params:
  109. group_id = ''
  110. initiator.set_fst_parameters(group_id=group_id)
  111. sid = initiator.add_session()
  112. if bad_param_type == bad_param_session_set_no_params:
  113. res = initiator.set_session_param(None)
  114. if not res.startswith("OK"):
  115. raise Exception("Session set operation failed")
  116. elif bad_param_type == bad_param_session_set_unknown_param:
  117. res = initiator.set_session_param("bad_param=1")
  118. if not res.startswith("OK"):
  119. raise Exception("Session set operation failed")
  120. else:
  121. if bad_param_type == bad_param_session_initiate_with_no_new_iface_set:
  122. new_iface = None
  123. elif bad_param_type == bad_param_new_iface:
  124. new_iface = 'wlan12'
  125. old_iface = None if bad_param_type != bad_param_old_iface else 'wlan12'
  126. llt = None
  127. if bad_param_type == bad_param_negative_llt:
  128. llt = '-1'
  129. elif bad_param_type == bad_param_zero_llt:
  130. llt = '0'
  131. elif bad_param_type == bad_param_llt_too_big:
  132. llt = '4294967296' #0x100000000
  133. elif bad_param_type == bad_param_llt_nan:
  134. llt = 'nan'
  135. elif bad_param_type == bad_param_session_id:
  136. sid = '-1'
  137. initiator.set_fst_parameters(llt=llt)
  138. initiator.configure_session(sid, new_iface, old_iface)
  139. except Exception, e:
  140. if e.args[0].startswith("Cannot add FST session with groupid"):
  141. if bad_param_type == bad_param_group_id or bad_param_type == bad_param_session_add_no_params:
  142. bad_parameter_detected = True
  143. elif e.args[0].startswith("Cannot set FST session new_ifname:"):
  144. if bad_param_type == bad_param_new_iface:
  145. bad_parameter_detected = True
  146. elif e.args[0].startswith("Session set operation failed"):
  147. if (bad_param_type == bad_param_session_set_no_params or
  148. bad_param_type == bad_param_session_set_unknown_param):
  149. bad_parameter_detected = True
  150. elif e.args[0].startswith("Cannot set FST session old_ifname:"):
  151. if (bad_param_type == bad_param_old_iface or
  152. bad_param_type == bad_param_session_id or
  153. bad_param_type == bad_param_session_set_no_params):
  154. bad_parameter_detected = True
  155. elif e.args[0].startswith("Cannot set FST session llt:"):
  156. if (bad_param_type == bad_param_negative_llt or
  157. bad_param_type == bad_param_llt_too_big or
  158. bad_param_type == bad_param_llt_nan):
  159. bad_parameter_detected = True
  160. elif e.args[0].startswith("Cannot set FST session peer address:"):
  161. if bad_param_type == bad_param_peer_addr:
  162. bad_parameter_detected = True
  163. if not bad_parameter_detected:
  164. # The exception was unexpected
  165. logger.info(e)
  166. exception_already_raised = True
  167. raise
  168. finally:
  169. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  170. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  171. if not exception_already_raised:
  172. if bad_parameter_detected:
  173. logger.info("Success. Bad parameter was detected (%s)" % bad_param_names[bad_param_type])
  174. else:
  175. if bad_param_type == bad_param_none or bad_param_type == bad_param_zero_llt:
  176. logger.info("Success. Session added and set")
  177. else:
  178. exception_text = ""
  179. if bad_param_type == bad_param_peer_addr:
  180. exception_text = "Failure. Bad parameter was not detected (Peer address == %s)" % ap1.get_new_peer_addr()
  181. else:
  182. exception_text = "Failure. Bad parameter was not detected (%s)" % bad_param_names[bad_param_type]
  183. raise Exception(exception_text)
  184. else:
  185. logger.info("Failure. Unexpected exception")
  186. def fst_initiate_session(apdev, test_params, bad_param_type, init_on_ap):
  187. """This function makes the necessary preparations and then adds, sets and
  188. initiates a session using either correct or incorrect parameters at each
  189. stage depending on the value of bad_param_type. If the call ends as expected
  190. (with session being successfully added, set and initiated in case of correct
  191. parameters or with the expected exception in case of incorrect parameters),
  192. the function silently exits. Otherwise it throws an exception thus failing
  193. the test."""
  194. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  195. bad_parameter_detected = False
  196. exception_already_raised = False
  197. try:
  198. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  199. # This call makes sure FstHostapd singleton object is created and, as a
  200. # result, the global control interface is registered (this is done from
  201. # the constructor).
  202. ap1.get_global_instance()
  203. if init_on_ap:
  204. initiator = ap1
  205. responder = sta1
  206. new_iface = ap2.ifname() if bad_param_type != bad_param_session_initiate_with_no_new_iface_set else None
  207. new_peer_addr = ap2.get_actual_peer_addr()
  208. resp_newif = sta2.ifname()
  209. else:
  210. initiator = sta1
  211. responder = ap1
  212. new_iface = sta2.ifname() if bad_param_type != bad_param_session_initiate_with_no_new_iface_set else None
  213. new_peer_addr = sta2.get_actual_peer_addr()
  214. resp_newif = ap2.ifname()
  215. peeraddr = None if bad_param_type != bad_param_session_initiate_with_bad_peer_addr_set else '10:DE:AD:DE:AD:11'
  216. initiator.add_peer(responder, peeraddr, new_peer_addr)
  217. if bad_param_type == bad_param_session_initiate_response_with_zero_llt:
  218. initiator.set_fst_parameters(llt='0')
  219. sid = initiator.add_session()
  220. initiator.configure_session(sid, new_iface)
  221. if bad_param_type == bad_param_session_initiate_no_params:
  222. sid = ''
  223. elif bad_param_type == bad_param_session_initiate_bad_session_id:
  224. sid = '-1'
  225. if bad_param_type == bad_param_session_initiate_request_with_bad_stie:
  226. actual_fsts_id = initiator.get_fsts_id_by_sid(sid)
  227. initiator.send_test_session_setup_request(str(actual_fsts_id), "bad_new_band")
  228. responder.wait_for_session_event(5)
  229. elif bad_param_type == bad_param_session_initiate_response_with_reject:
  230. initiator.send_session_setup_request(sid)
  231. initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  232. setup_event = responder.wait_for_session_event(5, [],
  233. ['EVENT_FST_SETUP'])
  234. if not 'id' in setup_event:
  235. raise Exception("No session id in FST setup event")
  236. responder.send_session_setup_response(str(setup_event['id']),
  237. "reject")
  238. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  239. if event['new_state'] != "INITIAL" or event['reason'] != "REASON_REJECT":
  240. raise Exception("Response with reject not handled as expected")
  241. bad_parameter_detected = True
  242. elif bad_param_type == bad_param_session_initiate_response_with_bad_stie:
  243. initiator.send_session_setup_request(sid)
  244. initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  245. responder.wait_for_session_event(5, [], ['EVENT_FST_SETUP'])
  246. actual_fsts_id = initiator.get_fsts_id_by_sid(sid)
  247. responder.send_test_session_setup_response(str(actual_fsts_id),
  248. "accept", "bad_new_band")
  249. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  250. if event['new_state'] != "INITIAL" or event['reason'] != "REASON_ERROR_PARAMS":
  251. raise Exception("Response with bad STIE not handled as expected")
  252. bad_parameter_detected = True
  253. elif bad_param_type == bad_param_session_initiate_response_with_zero_llt:
  254. initiator.initiate_session(sid, "accept")
  255. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  256. if event['new_state'] != "TRANSITION_DONE":
  257. raise Exception("Response reception for a session with llt=0 not handled as expected")
  258. bad_parameter_detected = True
  259. elif bad_param_type == bad_param_session_initiate_stt_no_response:
  260. initiator.send_session_setup_request(sid)
  261. initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  262. responder.wait_for_session_event(5, [], ['EVENT_FST_SETUP'])
  263. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  264. if event['new_state'] != "INITIAL" or event['reason'] != "REASON_STT":
  265. raise Exception("No response scenario not handled as expected")
  266. bad_parameter_detected = True
  267. elif bad_param_type == bad_param_session_initiate_concurrent_setup_request:
  268. responder.add_peer(initiator)
  269. resp_sid = responder.add_session()
  270. responder.configure_session(resp_sid, resp_newif)
  271. initiator.send_session_setup_request(sid)
  272. actual_fsts_id = initiator.get_fsts_id_by_sid(sid)
  273. responder.send_test_session_setup_request(str(actual_fsts_id))
  274. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  275. initiator_addr = initiator.get_own_mac_address()
  276. responder_addr = responder.get_own_mac_address()
  277. if initiator_addr < responder_addr:
  278. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  279. if event['new_state'] != "INITIAL" or event['reason'] != "REASON_SETUP":
  280. raise Exception("Concurrent setup scenario not handled as expected")
  281. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SETUP"])
  282. # The incoming setup request received by the initiator has
  283. # priority over the one sent previously by the initiator itself
  284. # because the initiator's MAC address is numerically lower than
  285. # the one of the responder. Thus, the initiator should generate
  286. # an FST_SETUP event.
  287. else:
  288. event = initiator.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  289. if event['new_state'] != "INITIAL" or event['reason'] != "REASON_STT":
  290. raise Exception("Concurrent setup scenario not handled as expected")
  291. # The incoming setup request was dropped at the initiator
  292. # because its MAC address is numerically bigger than the one of
  293. # the responder. Thus, the initiator continue to wait for a
  294. # setup response until the STT event fires.
  295. bad_parameter_detected = True
  296. else:
  297. initiator.initiate_session(sid, "accept")
  298. except Exception, e:
  299. if e.args[0].startswith("Cannot initiate fst session"):
  300. if bad_param_type != bad_param_none:
  301. bad_parameter_detected = True
  302. elif e.args[0].startswith("No FST-EVENT-SESSION received"):
  303. if bad_param_type == bad_param_session_initiate_request_with_bad_stie:
  304. bad_parameter_detected = True
  305. if not bad_parameter_detected:
  306. #The exception was unexpected
  307. logger.info(e)
  308. exception_already_raised = True
  309. raise
  310. finally:
  311. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  312. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  313. if not exception_already_raised:
  314. if bad_parameter_detected:
  315. logger.info("Success. Bad parameter was detected (%s)" % bad_param_names[bad_param_type])
  316. else:
  317. if bad_param_type == bad_param_none:
  318. logger.info("Success. Session initiated")
  319. else:
  320. raise Exception("Failure. Bad parameter was not detected (%s)" % bad_param_names[bad_param_type])
  321. else:
  322. logger.info("Failure. Unexpected exception")
  323. def fst_transfer_session(apdev, test_params, bad_param_type, init_on_ap,
  324. rsn=False):
  325. """This function makes the necessary preparations and then adds, sets,
  326. initiates and attempts to transfer a session using either correct or
  327. incorrect parameters at each stage depending on the value of bad_param_type.
  328. If the call ends as expected the function silently exits. Otherwise, it
  329. throws an exception thus failing the test."""
  330. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev, rsn=rsn)
  331. bad_parameter_detected = False
  332. exception_already_raised = False
  333. try:
  334. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2, rsn=rsn)
  335. # This call makes sure FstHostapd singleton object is created and, as a
  336. # result, the global control interface is registered (this is done from
  337. # the constructor).
  338. ap1.get_global_instance()
  339. if init_on_ap:
  340. initiator = ap1
  341. responder = sta1
  342. new_iface = ap2.ifname()
  343. new_peer_addr = ap2.get_actual_peer_addr()
  344. else:
  345. initiator = sta1
  346. responder = ap1
  347. new_iface = sta2.ifname()
  348. new_peer_addr = sta2.get_actual_peer_addr()
  349. initiator.add_peer(responder, new_peer_addr = new_peer_addr)
  350. sid = initiator.add_session()
  351. initiator.configure_session(sid, new_iface)
  352. if bad_param_type != bad_param_session_transfer_setup_skipped:
  353. initiator.initiate_session(sid, "accept")
  354. if bad_param_type == bad_param_session_transfer_no_params:
  355. sid = ''
  356. elif bad_param_type == bad_param_session_transfer_bad_session_id:
  357. sid = '-1'
  358. initiator.transfer_session(sid)
  359. except Exception, e:
  360. if e.args[0].startswith("Cannot transfer fst session"):
  361. if bad_param_type != bad_param_none:
  362. bad_parameter_detected = True
  363. if not bad_parameter_detected:
  364. # The exception was unexpected
  365. logger.info(e)
  366. exception_already_raised = True
  367. raise
  368. finally:
  369. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  370. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  371. if not exception_already_raised:
  372. if bad_parameter_detected:
  373. logger.info("Success. Bad parameter was detected (%s)" % bad_param_names[bad_param_type])
  374. else:
  375. if bad_param_type == bad_param_none:
  376. logger.info("Success. Session transferred")
  377. else:
  378. raise Exception("Failure. Bad parameter was not detected (%s)" % bad_param_names[bad_param_type])
  379. else:
  380. logger.info("Failure. Unexpected exception")
  381. def fst_tear_down_session(apdev, test_params, bad_param_type, init_on_ap):
  382. """This function makes the necessary preparations and then adds, sets, and
  383. initiates a session. It then issues a tear down command using either
  384. correct or incorrect parameters at each stage. If the call ends as expected,
  385. the function silently exits. Otherwise, it throws an exception thus failing
  386. the test."""
  387. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  388. bad_parameter_detected = False
  389. exception_already_raised = False
  390. try:
  391. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  392. # This call makes sure FstHostapd singleton object is created and, as a
  393. # result, the global control interface is registered (this is done from
  394. # the constructor).
  395. ap1.get_global_instance()
  396. if init_on_ap:
  397. initiator = ap1
  398. responder = sta1
  399. new_iface = ap2.ifname()
  400. new_peer_addr = ap2.get_actual_peer_addr()
  401. else:
  402. initiator = sta1
  403. responder = ap1
  404. new_iface = sta2.ifname()
  405. new_peer_addr = sta2.get_actual_peer_addr()
  406. initiator.add_peer(responder, new_peer_addr = new_peer_addr)
  407. sid = initiator.add_session()
  408. initiator.configure_session(sid, new_iface)
  409. if bad_param_type != bad_param_session_teardown_setup_skipped:
  410. initiator.initiate_session(sid, "accept")
  411. if bad_param_type == bad_param_session_teardown_bad_fsts_id:
  412. initiator.send_test_tear_down('-1')
  413. responder.wait_for_session_event(5)
  414. else:
  415. if bad_param_type == bad_param_session_teardown_no_params:
  416. sid = ''
  417. elif bad_param_type == bad_param_session_teardown_bad_session_id:
  418. sid = '-1'
  419. initiator.teardown_session(sid)
  420. except Exception, e:
  421. if e.args[0].startswith("Cannot tear down fst session"):
  422. if (bad_param_type == bad_param_session_teardown_no_params or
  423. bad_param_type == bad_param_session_teardown_bad_session_id or
  424. bad_param_type == bad_param_session_teardown_setup_skipped):
  425. bad_parameter_detected = True
  426. elif e.args[0].startswith("No FST-EVENT-SESSION received"):
  427. if bad_param_type == bad_param_session_teardown_bad_fsts_id:
  428. bad_parameter_detected = True
  429. if not bad_parameter_detected:
  430. # The exception was unexpected
  431. logger.info(e)
  432. exception_already_raised = True
  433. raise
  434. finally:
  435. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  436. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  437. if not exception_already_raised:
  438. if bad_parameter_detected:
  439. logger.info("Success. Bad parameter was detected (%s)" % bad_param_names[bad_param_type])
  440. else:
  441. if bad_param_type == bad_param_none:
  442. logger.info("Success. Session torn down")
  443. else:
  444. raise Exception("Failure. Bad parameter was not detected (%s)" % bad_param_names[bad_param_type])
  445. else:
  446. logger.info("Failure. Unexpected exception")
  447. #enum - remove session scenarios
  448. remove_scenario_no_params = 0
  449. remove_scenario_bad_session_id = 1
  450. remove_scenario_non_established_session = 2
  451. remove_scenario_established_session = 3
  452. remove_scenario_names = ("No params",
  453. "Bad session id",
  454. "Remove non-established session",
  455. "Remove established session")
  456. def fst_remove_session(apdev, test_params, remove_session_scenario, init_on_ap):
  457. """This function attempts to remove a session at various stages of its
  458. formation, depending on the value of remove_session_scenario. If the call
  459. ends as expected, the function silently exits. Otherwise, it throws an
  460. exception thus failing the test."""
  461. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  462. bad_parameter_detected = False
  463. exception_already_raised = False
  464. try:
  465. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  466. # This call makes sure FstHostapd singleton object is created and, as a
  467. # result, the global control interface is registered (this is done from
  468. # the constructor).
  469. ap1.get_global_instance()
  470. if init_on_ap:
  471. initiator = ap1
  472. responder = sta1
  473. new_iface = ap2.ifname()
  474. new_peer_addr = ap2.get_actual_peer_addr()
  475. else:
  476. initiator = sta1
  477. responder = ap1
  478. new_iface = sta2.ifname()
  479. new_peer_addr = sta2.get_actual_peer_addr()
  480. initiator.add_peer(responder, new_peer_addr = new_peer_addr)
  481. sid = initiator.add_session()
  482. initiator.configure_session(sid, new_iface)
  483. if remove_session_scenario != remove_scenario_no_params:
  484. if remove_session_scenario != remove_scenario_non_established_session:
  485. initiator.initiate_session(sid, "accept")
  486. if remove_session_scenario == remove_scenario_no_params:
  487. sid = ''
  488. elif remove_session_scenario == remove_scenario_bad_session_id:
  489. sid = '-1'
  490. initiator.remove_session(sid)
  491. except Exception, e:
  492. if e.args[0].startswith("Cannot remove fst session"):
  493. if (remove_session_scenario == remove_scenario_no_params or
  494. remove_session_scenario == remove_scenario_bad_session_id):
  495. bad_parameter_detected = True
  496. elif e.args[0].startswith("No FST-EVENT-SESSION received"):
  497. if remove_session_scenario == remove_scenario_non_established_session:
  498. bad_parameter_detected = True
  499. if not bad_parameter_detected:
  500. #The exception was unexpected
  501. logger.info(e)
  502. exception_already_raised = True
  503. raise
  504. finally:
  505. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  506. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  507. if not exception_already_raised:
  508. if bad_parameter_detected:
  509. logger.info("Success. Remove scenario ended as expected (%s)" % remove_scenario_names[remove_session_scenario])
  510. else:
  511. if remove_session_scenario == remove_scenario_established_session:
  512. logger.info("Success. Session removed")
  513. else:
  514. raise Exception("Failure. Remove scenario ended in an unexpected way (%s)" % remove_scenario_names[remove_session_scenario])
  515. else:
  516. logger.info("Failure. Unexpected exception")
  517. #enum - frame types
  518. frame_type_session_request = 0
  519. frame_type_session_response = 1
  520. frame_type_ack_request = 2
  521. frame_type_ack_response = 3
  522. frame_type_tear_down = 4
  523. frame_type_names = ("Session request",
  524. "Session Response",
  525. "Ack request",
  526. "Ack response",
  527. "Tear down")
  528. def fst_send_unexpected_frame(apdev, test_params, frame_type, send_from_ap, additional_param = ''):
  529. """This function creates two pairs of APs and stations, makes them connect
  530. and then causes one side to send an unexpected FST frame of the specified
  531. type to the other. The other side should then identify and ignore the
  532. frame."""
  533. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  534. exception_already_raised = False
  535. frame_receive_timeout = False
  536. try:
  537. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  538. # This call makes sure FstHostapd singleton object is created and, as a
  539. # result, the global control interface is registered (this is done from
  540. # the constructor).
  541. ap1.get_global_instance()
  542. if send_from_ap:
  543. sender = ap1
  544. receiver = sta1
  545. new_iface = ap2.ifname()
  546. new_peer_addr = ap2.get_actual_peer_addr()
  547. else:
  548. sender = sta1
  549. receiver = ap1
  550. new_iface = sta2.ifname()
  551. new_peer_addr = sta2.get_actual_peer_addr()
  552. sender.add_peer(receiver, new_peer_addr = new_peer_addr)
  553. sid=sender.add_session()
  554. sender.configure_session(sid, new_iface)
  555. if frame_type == frame_type_session_request:
  556. sender.send_session_setup_request(sid)
  557. event = receiver.wait_for_session_event(5)
  558. if event['type'] != 'EVENT_FST_SETUP':
  559. raise Exception("Unexpected indication: " + event['type'])
  560. elif frame_type == frame_type_session_response:
  561. #fsts_id doesn't matter, no actual session exists
  562. sender.send_test_session_setup_response('0', additional_param)
  563. receiver.wait_for_session_event(5)
  564. elif frame_type == frame_type_ack_request:
  565. #fsts_id doesn't matter, no actual session exists
  566. sender.send_test_ack_request('0')
  567. receiver.wait_for_session_event(5)
  568. elif frame_type == frame_type_ack_response:
  569. #fsts_id doesn't matter, no actual session exists
  570. sender.send_test_ack_response('0')
  571. receiver.wait_for_session_event(5)
  572. elif frame_type == frame_type_tear_down:
  573. #fsts_id doesn't matter, no actual session exists
  574. sender.send_test_tear_down('0')
  575. receiver.wait_for_session_event(5)
  576. except Exception, e:
  577. if e.args[0].startswith("No FST-EVENT-SESSION received"):
  578. if frame_type != frame_type_session_request:
  579. frame_receive_timeout = True
  580. else:
  581. logger.info(e)
  582. exception_already_raised = True
  583. raise
  584. finally:
  585. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  586. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  587. if not exception_already_raised:
  588. if frame_receive_timeout:
  589. logger.info("Success. Frame was ignored (%s)" % frame_type_names[frame_type])
  590. else:
  591. if frame_type == frame_type_session_request:
  592. logger.info("Success. Frame received, session created")
  593. else:
  594. raise Exception("Failure. Frame was not ignored (%s)" % frame_type_names[frame_type])
  595. else:
  596. logger.info("Failure. Unexpected exception")
  597. #enum - bad session transfer scenarios
  598. bad_scenario_none = 0
  599. bad_scenario_ack_req_session_not_set_up = 1
  600. bad_scenario_ack_req_session_not_established_init_side = 2
  601. bad_scenario_ack_req_session_not_established_resp_side = 3
  602. bad_scenario_ack_req_bad_fsts_id = 4
  603. bad_scenario_ack_resp_session_not_set_up = 5
  604. bad_scenario_ack_resp_session_not_established_init_side = 6
  605. bad_scenario_ack_resp_session_not_established_resp_side = 7
  606. bad_scenario_ack_resp_no_ack_req = 8
  607. bad_scenario_ack_resp_bad_fsts_id = 9
  608. bad_scenario_names = ("None",
  609. "Ack request received before the session was set up",
  610. "Ack request received on the initiator side before session was established",
  611. "Ack request received on the responder side before session was established",
  612. "Ack request received with bad fsts_id",
  613. "Ack response received before the session was set up",
  614. "Ack response received on the initiator side before session was established",
  615. "Ack response received on the responder side before session was established",
  616. "Ack response received before ack request was sent",
  617. "Ack response received with bad fsts_id")
  618. def fst_bad_transfer(apdev, test_params, bad_scenario_type, init_on_ap):
  619. """This function makes the necessary preparations and then adds and sets a
  620. session. It then initiates and it unless instructed otherwise) and attempts
  621. to send one of the frames involved in the session transfer protocol,
  622. skipping or distorting one of the stages according to the value of
  623. bad_scenario_type parameter."""
  624. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  625. bad_parameter_detected = False
  626. exception_already_raised = False
  627. try:
  628. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  629. # This call makes sure FstHostapd singleton object is created and, as a
  630. # result, the global control interface is registered (this is done from
  631. # the constructor).
  632. ap1.get_global_instance()
  633. if init_on_ap:
  634. initiator = ap1
  635. responder = sta1
  636. new_iface = ap2.ifname()
  637. new_peer_addr = ap2.get_actual_peer_addr()
  638. else:
  639. initiator = sta1
  640. responder = ap1
  641. new_iface = sta2.ifname()
  642. new_peer_addr = sta2.get_actual_peer_addr()
  643. initiator.add_peer(responder, new_peer_addr = new_peer_addr)
  644. sid = initiator.add_session()
  645. initiator.configure_session(sid, new_iface)
  646. if (bad_scenario_type != bad_scenario_ack_req_session_not_set_up and
  647. bad_scenario_type != bad_scenario_ack_resp_session_not_set_up):
  648. if (bad_scenario_type != bad_scenario_ack_req_session_not_established_init_side and
  649. bad_scenario_type != bad_scenario_ack_resp_session_not_established_init_side and
  650. bad_scenario_type != bad_scenario_ack_req_session_not_established_resp_side and
  651. bad_scenario_type != bad_scenario_ack_resp_session_not_established_resp_side):
  652. response = "accept"
  653. else:
  654. response = ''
  655. initiator.initiate_session(sid, response)
  656. if bad_scenario_type == bad_scenario_ack_req_session_not_set_up:
  657. #fsts_id doesn't matter, no actual session exists
  658. responder.send_test_ack_request('0')
  659. initiator.wait_for_session_event(5)
  660. # We want to send the unexpected frame to the side that already has
  661. # a session created
  662. elif bad_scenario_type == bad_scenario_ack_resp_session_not_set_up:
  663. #fsts_id doesn't matter, no actual session exists
  664. responder.send_test_ack_response('0')
  665. initiator.wait_for_session_event(5)
  666. # We want to send the unexpected frame to the side that already has
  667. # a session created
  668. elif bad_scenario_type == bad_scenario_ack_req_session_not_established_init_side:
  669. #fsts_id doesn't matter, no actual session exists
  670. initiator.send_test_ack_request('0')
  671. responder.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
  672. elif bad_scenario_type == bad_scenario_ack_req_session_not_established_resp_side:
  673. #fsts_id doesn't matter, no actual session exists
  674. responder.send_test_ack_request('0')
  675. initiator.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
  676. elif bad_scenario_type == bad_scenario_ack_resp_session_not_established_init_side:
  677. #fsts_id doesn't matter, no actual session exists
  678. initiator.send_test_ack_response('0')
  679. responder.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
  680. elif bad_scenario_type == bad_scenario_ack_resp_session_not_established_resp_side:
  681. #fsts_id doesn't matter, no actual session exists
  682. responder.send_test_ack_response('0')
  683. initiator.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
  684. elif bad_scenario_type == bad_scenario_ack_req_bad_fsts_id:
  685. initiator.send_test_ack_request('-1')
  686. responder.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
  687. elif bad_scenario_type == bad_scenario_ack_resp_bad_fsts_id:
  688. initiator.send_test_ack_response('-1')
  689. responder.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
  690. elif bad_scenario_type == bad_scenario_ack_resp_no_ack_req:
  691. actual_fsts_id = initiator.get_fsts_id_by_sid(sid)
  692. initiator.send_test_ack_response(str(actual_fsts_id))
  693. responder.wait_for_session_event(5, ["EVENT_FST_SESSION_STATE"])
  694. else:
  695. raise Exception("Unknown bad scenario identifier")
  696. except Exception, e:
  697. if e.args[0].startswith("No FST-EVENT-SESSION received"):
  698. bad_parameter_detected = True
  699. if not bad_parameter_detected:
  700. # The exception was unexpected
  701. logger.info(e)
  702. exception_already_raised = True
  703. raise
  704. finally:
  705. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  706. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  707. if not exception_already_raised:
  708. if bad_parameter_detected:
  709. logger.info("Success. Bad scenario was handled correctly (%s)" % bad_scenario_names[bad_scenario_type])
  710. else:
  711. raise Exception("Failure. Bad scenario was handled incorrectly (%s)" % bad_scenario_names[bad_scenario_type])
  712. else:
  713. logger.info("Failure. Unexpected exception")
  714. def test_fst_sta_connect_to_non_fst_ap(dev, apdev, test_params):
  715. """FST STA connecting to non-FST AP"""
  716. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  717. with HWSimRadio() as (radio, iface):
  718. non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
  719. try:
  720. orig_sta1_mbies = sta1.get_local_mbies()
  721. orig_sta2_mbies = sta2.get_local_mbies()
  722. sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
  723. key_mgmt="NONE", scan_freq='2412')
  724. time.sleep(2)
  725. res_sta1_mbies = sta1.get_local_mbies()
  726. res_sta2_mbies = sta2.get_local_mbies()
  727. if (orig_sta1_mbies.startswith("FAIL") or
  728. orig_sta2_mbies.startswith("FAIL") or
  729. res_sta1_mbies.startswith("FAIL") or
  730. res_sta2_mbies.startswith("FAIL")):
  731. raise Exception("Failure. MB IEs must be present on the stations")
  732. except Exception, e:
  733. logger.info(e)
  734. raise
  735. finally:
  736. sta2.disconnect_from_external_ap()
  737. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  738. hostapd.HostapdGlobal().remove(iface)
  739. def test_fst_sta_connect_to_fst_ap(dev, apdev, test_params):
  740. """FST STA connecting to FST AP"""
  741. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  742. try:
  743. orig_sta2_mbies = sta2.get_local_mbies()
  744. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  745. sta1.connect(ap1, key_mgmt="NONE",
  746. scan_freq=fst_test_common.fst_test_def_freq_a)
  747. time.sleep(2)
  748. res_sta2_mbies = sta2.get_local_mbies()
  749. if res_sta2_mbies == orig_sta2_mbies:
  750. raise Exception("Failure. MB IEs have not been updated")
  751. except Exception, e:
  752. logger.info(e)
  753. raise
  754. finally:
  755. sta1.disconnect()
  756. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  757. def test_fst_ap_connect_to_fst_sta(dev, apdev, test_params):
  758. """FST AP connecting to FST STA"""
  759. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  760. try:
  761. orig_ap_mbies = ap1.get_local_mbies()
  762. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  763. sta1.connect(ap1, key_mgmt="NONE",
  764. scan_freq=fst_test_common.fst_test_def_freq_a)
  765. time.sleep(2)
  766. res_ap_mbies = ap1.get_local_mbies()
  767. if res_ap_mbies != orig_ap_mbies:
  768. raise Exception("Failure. MB IEs have been unexpectedly updated on the AP")
  769. except Exception, e:
  770. logger.info(e)
  771. raise
  772. finally:
  773. sta1.disconnect()
  774. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  775. def test_fst_ap_connect_to_non_fst_sta(dev, apdev, test_params):
  776. """FST AP connecting to non-FST STA"""
  777. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  778. try:
  779. orig_ap_mbies = ap2.get_local_mbies()
  780. vals = dev[0].scan(None, fst_test_common.fst_test_def_freq_g)
  781. fst_module_aux.external_sta_connect(dev[0], ap2, key_mgmt="NONE",
  782. scan_freq=fst_test_common.fst_test_def_freq_g)
  783. time.sleep(2)
  784. res_ap_mbies = ap2.get_local_mbies()
  785. if res_ap_mbies != orig_ap_mbies:
  786. raise Exception("Failure. MB IEs have been unexpectedly updated on the AP")
  787. except Exception, e:
  788. logger.info(e)
  789. raise
  790. finally:
  791. fst_module_aux.disconnect_external_sta(dev[0], ap2)
  792. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  793. def test_fst_second_sta_connect_to_non_fst_ap(dev, apdev, test_params):
  794. """FST STA 2nd connecting to non-FST AP"""
  795. fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  796. with HWSimRadio() as (radio, iface):
  797. non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
  798. try:
  799. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  800. sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
  801. time.sleep(2)
  802. orig_sta1_mbies = sta1.get_local_mbies()
  803. orig_sta2_mbies = sta2.get_local_mbies()
  804. sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
  805. key_mgmt="NONE", scan_freq='2412')
  806. time.sleep(2)
  807. res_sta1_mbies = sta1.get_local_mbies()
  808. res_sta2_mbies = sta2.get_local_mbies()
  809. if (orig_sta1_mbies.startswith("FAIL") or
  810. orig_sta2_mbies.startswith("FAIL") or
  811. res_sta1_mbies.startswith("FAIL") or
  812. res_sta2_mbies.startswith("FAIL")):
  813. raise Exception("Failure. MB IEs must be present on the stations")
  814. except Exception, e:
  815. logger.info(e)
  816. raise
  817. finally:
  818. sta1.disconnect()
  819. sta2.disconnect_from_external_ap()
  820. fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
  821. hostapd.HostapdGlobal().remove(iface)
  822. def test_fst_second_sta_connect_to_fst_ap(dev, apdev, test_params):
  823. """FST STA 2nd connecting to FST AP"""
  824. fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  825. with HWSimRadio() as (radio, iface):
  826. non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
  827. try:
  828. sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
  829. key_mgmt="NONE", scan_freq='2412')
  830. time.sleep(2)
  831. orig_sta1_mbies = sta1.get_local_mbies()
  832. orig_sta2_mbies = sta2.get_local_mbies()
  833. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  834. sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
  835. time.sleep(2)
  836. res_sta1_mbies = sta1.get_local_mbies()
  837. res_sta2_mbies = sta2.get_local_mbies()
  838. if (orig_sta1_mbies.startswith("FAIL") or
  839. orig_sta2_mbies.startswith("FAIL") or
  840. res_sta1_mbies.startswith("FAIL") or
  841. res_sta2_mbies.startswith("FAIL")):
  842. raise Exception("Failure. MB IEs must be present on the stations")
  843. except Exception, e:
  844. logger.info(e)
  845. raise
  846. finally:
  847. sta1.disconnect()
  848. sta2.disconnect_from_external_ap()
  849. fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
  850. hostapd.HostapdGlobal().remove(iface)
  851. def test_fst_disconnect_1_of_2_stas_from_non_fst_ap(dev, apdev, test_params):
  852. """FST disconnect 1 of 2 STAs from non-FST AP"""
  853. fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  854. with HWSimRadio() as (radio, iface):
  855. non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
  856. try:
  857. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  858. sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
  859. sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
  860. key_mgmt="NONE", scan_freq='2412')
  861. time.sleep(2)
  862. orig_sta1_mbies = sta1.get_local_mbies()
  863. orig_sta2_mbies = sta2.get_local_mbies()
  864. sta2.disconnect_from_external_ap()
  865. time.sleep(2)
  866. res_sta1_mbies = sta1.get_local_mbies()
  867. res_sta2_mbies = sta2.get_local_mbies()
  868. if (orig_sta1_mbies.startswith("FAIL") or
  869. orig_sta2_mbies.startswith("FAIL") or
  870. res_sta1_mbies.startswith("FAIL") or
  871. res_sta2_mbies.startswith("FAIL")):
  872. raise Exception("Failure. MB IEs must be present on the stations")
  873. except Exception, e:
  874. logger.info(e)
  875. raise
  876. finally:
  877. sta1.disconnect()
  878. sta2.disconnect_from_external_ap()
  879. fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
  880. hostapd.HostapdGlobal().remove(iface)
  881. def test_fst_disconnect_1_of_2_stas_from_fst_ap(dev, apdev, test_params):
  882. """FST disconnect 1 of 2 STAs from FST AP"""
  883. fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  884. with HWSimRadio() as (radio, iface):
  885. non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
  886. try:
  887. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  888. sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
  889. sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
  890. key_mgmt="NONE", scan_freq='2412')
  891. time.sleep(2)
  892. orig_sta1_mbies = sta1.get_local_mbies()
  893. orig_sta2_mbies = sta2.get_local_mbies()
  894. sta1.disconnect()
  895. time.sleep(2)
  896. res_sta1_mbies = sta1.get_local_mbies()
  897. res_sta2_mbies = sta2.get_local_mbies()
  898. if (orig_sta1_mbies.startswith("FAIL") or
  899. orig_sta2_mbies.startswith("FAIL") or
  900. res_sta1_mbies.startswith("FAIL") or
  901. res_sta2_mbies.startswith("FAIL")):
  902. raise Exception("Failure. MB IEs must be present on the stations")
  903. except Exception, e:
  904. logger.info(e)
  905. raise
  906. finally:
  907. sta1.disconnect()
  908. sta2.disconnect_from_external_ap()
  909. fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
  910. hostapd.HostapdGlobal().remove(iface)
  911. def test_fst_disconnect_2_of_2_stas_from_non_fst_ap(dev, apdev, test_params):
  912. """FST disconnect 2 of 2 STAs from non-FST AP"""
  913. fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  914. with HWSimRadio() as (radio, iface):
  915. non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g" })
  916. try:
  917. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  918. sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
  919. sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
  920. key_mgmt="NONE", scan_freq='2412')
  921. time.sleep(2)
  922. sta1.disconnect()
  923. time.sleep(2)
  924. orig_sta1_mbies = sta1.get_local_mbies()
  925. orig_sta2_mbies = sta2.get_local_mbies()
  926. sta2.disconnect_from_external_ap()
  927. time.sleep(2)
  928. res_sta1_mbies = sta1.get_local_mbies()
  929. res_sta2_mbies = sta2.get_local_mbies()
  930. if (orig_sta1_mbies.startswith("FAIL") or
  931. orig_sta2_mbies.startswith("FAIL") or
  932. res_sta1_mbies.startswith("FAIL") or
  933. res_sta2_mbies.startswith("FAIL")):
  934. raise Exception("Failure. MB IEs must be present on the stations")
  935. except Exception, e:
  936. logger.info(e)
  937. raise
  938. finally:
  939. sta1.disconnect()
  940. sta2.disconnect_from_external_ap()
  941. fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
  942. hostapd.HostapdGlobal().remove(iface)
  943. def test_fst_disconnect_2_of_2_stas_from_fst_ap(dev, apdev, test_params):
  944. """FST disconnect 2 of 2 STAs from FST AP"""
  945. fst_ap1, fst_ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  946. with HWSimRadio() as (radio, iface):
  947. non_fst_ap = hostapd.add_ap(iface, { "ssid": "non_fst_11g"})
  948. try:
  949. vals = sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  950. sta1.connect(fst_ap1, key_mgmt="NONE", scan_freq=fst_test_common.fst_test_def_freq_a)
  951. sta2.connect_to_external_ap(non_fst_ap, ssid="non_fst_11g",
  952. key_mgmt="NONE", scan_freq='2412')
  953. time.sleep(2)
  954. sta2.disconnect_from_external_ap()
  955. time.sleep(2)
  956. orig_sta1_mbies = sta1.get_local_mbies()
  957. orig_sta2_mbies = sta2.get_local_mbies()
  958. sta1.disconnect()
  959. time.sleep(2)
  960. res_sta1_mbies = sta1.get_local_mbies()
  961. res_sta2_mbies = sta2.get_local_mbies()
  962. if (orig_sta1_mbies.startswith("FAIL") or
  963. orig_sta2_mbies.startswith("FAIL") or
  964. res_sta1_mbies.startswith("FAIL") or
  965. res_sta2_mbies.startswith("FAIL")):
  966. raise Exception("Failure. MB IEs should have stayed present on both stations")
  967. # Mandatory part of 8.4.2.140 Multi-band element is 24 bytes = 48 hex chars
  968. basic_sta1_mbies = res_sta1_mbies[0:48] + res_sta1_mbies[60:108]
  969. basic_sta2_mbies = res_sta2_mbies[0:48] + res_sta2_mbies[60:108]
  970. if (basic_sta1_mbies != basic_sta2_mbies):
  971. raise Exception("Failure. Basic MB IEs should have become identical on both stations")
  972. addr_sta1_str = sta1.get_own_mac_address().replace(":", "")
  973. addr_sta2_str = sta2.get_own_mac_address().replace(":", "")
  974. # Mandatory part of 8.4.2.140 Multi-band element is followed by STA MAC Address field (6 bytes = 12 hex chars)
  975. addr_sta1_mbie1 = res_sta1_mbies[48:60]
  976. addr_sta1_mbie2 = res_sta1_mbies[108:120]
  977. addr_sta2_mbie1 = res_sta2_mbies[48:60]
  978. addr_sta2_mbie2 = res_sta2_mbies[108:120]
  979. if (addr_sta1_mbie1 != addr_sta1_mbie2 or
  980. addr_sta1_mbie1 != addr_sta2_str or
  981. addr_sta2_mbie1 != addr_sta2_mbie2 or
  982. addr_sta2_mbie1 != addr_sta1_str):
  983. raise Exception("Failure. STA Address in MB IEs should have been same as the other STA's")
  984. except Exception, e:
  985. logger.info(e)
  986. raise
  987. finally:
  988. sta1.disconnect()
  989. sta2.disconnect_from_external_ap()
  990. fst_module_aux.stop_two_ap_sta_pairs(fst_ap1, fst_ap2, sta1, sta2)
  991. hostapd.HostapdGlobal().remove(iface)
  992. def test_fst_disconnect_non_fst_sta(dev, apdev, test_params):
  993. """FST disconnect non-FST STA"""
  994. ap1, ap2, fst_sta1, fst_sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  995. external_sta_connected = False
  996. try:
  997. vals = fst_sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  998. fst_sta1.connect(ap1, key_mgmt="NONE",
  999. scan_freq=fst_test_common.fst_test_def_freq_a)
  1000. vals = dev[0].scan(None, fst_test_common.fst_test_def_freq_g)
  1001. fst_module_aux.external_sta_connect(dev[0], ap2, key_mgmt="NONE",
  1002. scan_freq=fst_test_common.fst_test_def_freq_g)
  1003. external_sta_connected = True
  1004. time.sleep(2)
  1005. fst_sta1.disconnect()
  1006. time.sleep(2)
  1007. orig_ap_mbies = ap2.get_local_mbies()
  1008. fst_module_aux.disconnect_external_sta(dev[0], ap2)
  1009. external_sta_connected = False
  1010. time.sleep(2)
  1011. res_ap_mbies = ap2.get_local_mbies()
  1012. if res_ap_mbies != orig_ap_mbies:
  1013. raise Exception("Failure. MB IEs have been unexpectedly updated on the AP")
  1014. except Exception, e:
  1015. logger.info(e)
  1016. raise
  1017. finally:
  1018. fst_sta1.disconnect()
  1019. if external_sta_connected:
  1020. fst_module_aux.disconnect_external_sta(dev[0], ap2)
  1021. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, fst_sta1, fst_sta2)
  1022. def test_fst_disconnect_fst_sta(dev, apdev, test_params):
  1023. """FST disconnect FST STA"""
  1024. ap1, ap2, fst_sta1, fst_sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  1025. external_sta_connected = False
  1026. try:
  1027. vals = fst_sta1.scan(freq=fst_test_common.fst_test_def_freq_a)
  1028. fst_sta1.connect(ap1, key_mgmt="NONE",
  1029. scan_freq=fst_test_common.fst_test_def_freq_a)
  1030. vals = dev[0].scan(None, fst_test_common.fst_test_def_freq_g)
  1031. fst_module_aux.external_sta_connect(dev[0], ap2, key_mgmt="NONE",
  1032. scan_freq=fst_test_common.fst_test_def_freq_g)
  1033. external_sta_connected = True
  1034. time.sleep(2)
  1035. fst_module_aux.disconnect_external_sta(dev[0], ap2)
  1036. external_sta_connected = False
  1037. time.sleep(2)
  1038. orig_ap_mbies = ap2.get_local_mbies()
  1039. fst_sta1.disconnect()
  1040. time.sleep(2)
  1041. res_ap_mbies = ap2.get_local_mbies()
  1042. if res_ap_mbies != orig_ap_mbies:
  1043. raise Exception("Failure. MB IEs have been unexpectedly updated on the AP")
  1044. except Exception, e:
  1045. logger.info(e)
  1046. raise
  1047. finally:
  1048. fst_sta1.disconnect()
  1049. if external_sta_connected:
  1050. fst_module_aux.disconnect_external_sta(dev[0], ap2)
  1051. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, fst_sta1, fst_sta2)
  1052. def test_fst_dynamic_iface_attach(dev, apdev, test_params):
  1053. """FST dynamic interface attach"""
  1054. ap1 = fst_module_aux.FstAP(apdev[0]['ifname'], 'fst_11a', 'a',
  1055. fst_test_common.fst_test_def_chan_a,
  1056. fst_test_common.fst_test_def_group,
  1057. fst_test_common.fst_test_def_prio_low,
  1058. fst_test_common.fst_test_def_llt)
  1059. ap1.start()
  1060. ap2 = fst_module_aux.FstAP(apdev[1]['ifname'], 'fst_11g', 'b',
  1061. fst_test_common.fst_test_def_chan_g,
  1062. '', '', '')
  1063. ap2.start()
  1064. sta1 = fst_module_aux.FstSTA('wlan5',
  1065. fst_test_common.fst_test_def_group,
  1066. fst_test_common.fst_test_def_prio_low,
  1067. fst_test_common.fst_test_def_llt)
  1068. sta1.start()
  1069. sta2 = fst_module_aux.FstSTA('wlan6', '', '', '')
  1070. sta2.start()
  1071. try:
  1072. orig_sta2_mbies = sta2.get_local_mbies()
  1073. orig_ap2_mbies = ap2.get_local_mbies()
  1074. sta2.send_iface_attach_request(sta2.ifname(),
  1075. fst_test_common.fst_test_def_group,
  1076. '52', '27')
  1077. event = sta2.wait_for_iface_event(5)
  1078. if event['event_type'] != 'attached':
  1079. raise Exception("Failure. Iface was not properly attached")
  1080. ap2.send_iface_attach_request(ap2.ifname(),
  1081. fst_test_common.fst_test_def_group,
  1082. '102', '77')
  1083. event = ap2.wait_for_iface_event(5)
  1084. if event['event_type'] != 'attached':
  1085. raise Exception("Failure. Iface was not properly attached")
  1086. time.sleep(2)
  1087. res_sta2_mbies = sta2.get_local_mbies()
  1088. res_ap2_mbies = ap2.get_local_mbies()
  1089. sta2.send_iface_detach_request(sta2.ifname())
  1090. event = sta2.wait_for_iface_event(5)
  1091. if event['event_type'] != 'detached':
  1092. raise Exception("Failure. Iface was not properly detached")
  1093. ap2.send_iface_detach_request(ap2.ifname())
  1094. event = ap2.wait_for_iface_event(5)
  1095. if event['event_type'] != 'detached':
  1096. raise Exception("Failure. Iface was not properly detached")
  1097. if (not orig_sta2_mbies.startswith("FAIL") or
  1098. not orig_ap2_mbies.startswith("FAIL") or
  1099. res_sta2_mbies.startswith("FAIL") or
  1100. res_ap2_mbies.startswith("FAIL")):
  1101. raise Exception("Failure. MB IEs should have appeared on the station and on the AP")
  1102. except Exception, e:
  1103. logger.info(e)
  1104. raise
  1105. finally:
  1106. ap1.stop()
  1107. ap2.stop()
  1108. sta1.stop()
  1109. sta2.stop()
  1110. # AP side FST module tests
  1111. def test_fst_ap_start_session(dev, apdev, test_params):
  1112. """FST AP start session"""
  1113. fst_start_session(apdev, test_params, bad_param_none, True)
  1114. def test_fst_ap_start_session_no_add_params(dev, apdev, test_params):
  1115. """FST AP start session - no add params"""
  1116. fst_start_session(apdev, test_params, bad_param_session_add_no_params, True)
  1117. def test_fst_ap_start_session_bad_group_id(dev, apdev, test_params):
  1118. """FST AP start session - bad group id"""
  1119. fst_start_session(apdev, test_params, bad_param_group_id, True)
  1120. def test_fst_ap_start_session_no_set_params(dev, apdev, test_params):
  1121. """FST AP start session - no set params"""
  1122. fst_start_session(apdev, test_params, bad_param_session_set_no_params, True)
  1123. def test_fst_ap_start_session_set_unknown_param(dev, apdev, test_params):
  1124. """FST AP start session - set unknown param"""
  1125. fst_start_session(apdev, test_params, bad_param_session_set_unknown_param,
  1126. True)
  1127. def test_fst_ap_start_session_bad_session_id(dev, apdev, test_params):
  1128. """FST AP start session - bad session id"""
  1129. fst_start_session(apdev, test_params, bad_param_session_id, True)
  1130. def test_fst_ap_start_session_bad_new_iface(dev, apdev, test_params):
  1131. """FST AP start session - bad new iface"""
  1132. fst_start_session(apdev, test_params, bad_param_new_iface, True)
  1133. def test_fst_ap_start_session_bad_old_iface(dev, apdev, test_params):
  1134. """FST AP start session - bad old iface"""
  1135. fst_start_session(apdev, test_params, bad_param_old_iface, True)
  1136. def test_fst_ap_start_session_negative_llt(dev, apdev, test_params):
  1137. """FST AP start session - negative llt"""
  1138. fst_start_session(apdev, test_params, bad_param_negative_llt, True)
  1139. def test_fst_ap_start_session_zero_llt(dev, apdev, test_params):
  1140. """FST AP start session - zero llt"""
  1141. fst_start_session(apdev, test_params, bad_param_zero_llt, True)
  1142. def test_fst_ap_start_session_llt_too_big(dev, apdev, test_params):
  1143. """FST AP start session - llt too large"""
  1144. fst_start_session(apdev, test_params, bad_param_llt_too_big, True)
  1145. def test_fst_ap_start_session_invalid_peer_addr(dev, apdev, test_params):
  1146. """FST AP start session - invalid peer address"""
  1147. fst_start_session(apdev, test_params, bad_param_peer_addr, True,
  1148. 'GG:GG:GG:GG:GG:GG')
  1149. def test_fst_ap_start_session_multicast_peer_addr(dev, apdev, test_params):
  1150. """FST AP start session - multicast peer address"""
  1151. fst_start_session(apdev, test_params, bad_param_peer_addr, True,
  1152. '01:00:11:22:33:44')
  1153. def test_fst_ap_start_session_broadcast_peer_addr(dev, apdev, test_params):
  1154. """FST AP start session - broadcast peer address"""
  1155. fst_start_session(apdev, test_params, bad_param_peer_addr, True,
  1156. 'FF:FF:FF:FF:FF:FF')
  1157. def test_fst_ap_initiate_session(dev, apdev, test_params):
  1158. """FST AP initiate session"""
  1159. fst_initiate_session(apdev, test_params, bad_param_none, True)
  1160. def test_fst_ap_initiate_session_no_params(dev, apdev, test_params):
  1161. """FST AP initiate session - no params"""
  1162. fst_initiate_session(apdev, test_params,
  1163. bad_param_session_initiate_no_params, True)
  1164. def test_fst_ap_initiate_session_invalid_session_id(dev, apdev, test_params):
  1165. """FST AP initiate session - invalid session id"""
  1166. fst_initiate_session(apdev, test_params,
  1167. bad_param_session_initiate_bad_session_id, True)
  1168. def test_fst_ap_initiate_session_no_new_iface(dev, apdev, test_params):
  1169. """FST AP initiate session - no new iface"""
  1170. fst_initiate_session(apdev, test_params,
  1171. bad_param_session_initiate_with_no_new_iface_set, True)
  1172. def test_fst_ap_initiate_session_bad_peer_addr(dev, apdev, test_params):
  1173. """FST AP initiate session - bad peer address"""
  1174. fst_initiate_session(apdev, test_params,
  1175. bad_param_session_initiate_with_bad_peer_addr_set,
  1176. True)
  1177. def test_fst_ap_initiate_session_request_with_bad_stie(dev, apdev, test_params):
  1178. """FST AP initiate session - request with bad stie"""
  1179. fst_initiate_session(apdev, test_params,
  1180. bad_param_session_initiate_request_with_bad_stie, True)
  1181. def test_fst_ap_initiate_session_response_with_reject(dev, apdev, test_params):
  1182. """FST AP initiate session - response with reject"""
  1183. fst_initiate_session(apdev, test_params,
  1184. bad_param_session_initiate_response_with_reject, True)
  1185. def test_fst_ap_initiate_session_response_with_bad_stie(dev, apdev,
  1186. test_params):
  1187. """FST AP initiate session - response with bad stie"""
  1188. fst_initiate_session(apdev, test_params,
  1189. bad_param_session_initiate_response_with_bad_stie,
  1190. True)
  1191. def test_fst_ap_initiate_session_response_with_zero_llt(dev, apdev,
  1192. test_params):
  1193. """FST AP initiate session - zero llt"""
  1194. fst_initiate_session(apdev, test_params,
  1195. bad_param_session_initiate_response_with_zero_llt,
  1196. True)
  1197. def test_fst_ap_initiate_session_stt_no_response(dev, apdev, test_params):
  1198. """FST AP initiate session - stt no response"""
  1199. fst_initiate_session(apdev, test_params,
  1200. bad_param_session_initiate_stt_no_response, True)
  1201. def test_fst_ap_initiate_session_concurrent_setup_request(dev, apdev,
  1202. test_params):
  1203. """FST AP initiate session - concurrent setup request"""
  1204. fst_initiate_session(apdev, test_params,
  1205. bad_param_session_initiate_concurrent_setup_request,
  1206. True)
  1207. def test_fst_ap_session_request_with_no_session(dev, apdev, test_params):
  1208. """FST AP session request with no session"""
  1209. fst_send_unexpected_frame(apdev, test_params, frame_type_session_request,
  1210. True)
  1211. def test_fst_ap_session_response_accept_with_no_session(dev, apdev,
  1212. test_params):
  1213. """FST AP session response accept with no session"""
  1214. fst_send_unexpected_frame(apdev, test_params, frame_type_session_response,
  1215. True, "accept")
  1216. def test_fst_ap_session_response_reject_with_no_session(dev, apdev,
  1217. test_params):
  1218. """FST AP session response reject with no session"""
  1219. fst_send_unexpected_frame(apdev, test_params, frame_type_session_response,
  1220. True, "reject")
  1221. def test_fst_ap_ack_request_with_no_session(dev, apdev, test_params):
  1222. """FST AP ack request with no session"""
  1223. fst_send_unexpected_frame(apdev, test_params, frame_type_ack_request, True)
  1224. def test_fst_ap_ack_response_with_no_session(dev, apdev, test_params):
  1225. """FST AP ack response with no session"""
  1226. fst_send_unexpected_frame(apdev, test_params, frame_type_ack_response, True)
  1227. def test_fst_ap_tear_down_response_with_no_session(dev, apdev, test_params):
  1228. """FST AP tear down response with no session"""
  1229. fst_send_unexpected_frame(apdev, test_params, frame_type_tear_down, True)
  1230. def test_fst_ap_transfer_session(dev, apdev, test_params):
  1231. """FST AP transfer session"""
  1232. fst_transfer_session(apdev, test_params, bad_param_none, True)
  1233. def test_fst_ap_transfer_session_no_params(dev, apdev, test_params):
  1234. """FST AP transfer session - no params"""
  1235. fst_transfer_session(apdev, test_params,
  1236. bad_param_session_transfer_no_params, True)
  1237. def test_fst_ap_transfer_session_bad_session_id(dev, apdev, test_params):
  1238. """FST AP transfer session - bad session id"""
  1239. fst_transfer_session(apdev, test_params,
  1240. bad_param_session_transfer_bad_session_id, True)
  1241. def test_fst_ap_transfer_session_setup_skipped(dev, apdev, test_params):
  1242. """FST AP transfer session - setup skipped"""
  1243. fst_transfer_session(apdev, test_params,
  1244. bad_param_session_transfer_setup_skipped, True)
  1245. def test_fst_ap_ack_request_with_session_not_set_up(dev, apdev, test_params):
  1246. """FST AP ack request with session not set up"""
  1247. fst_bad_transfer(apdev, test_params,
  1248. bad_scenario_ack_req_session_not_set_up, True)
  1249. def test_fst_ap_ack_request_with_session_not_established_init_side(dev, apdev,
  1250. test_params):
  1251. """FST AP ack request with session not established init side"""
  1252. fst_bad_transfer(apdev, test_params,
  1253. bad_scenario_ack_req_session_not_established_init_side,
  1254. True)
  1255. def test_fst_ap_ack_request_with_session_not_established_resp_side(dev, apdev,
  1256. test_params):
  1257. """FST AP ack request with session not established resp side"""
  1258. fst_bad_transfer(apdev, test_params,
  1259. bad_scenario_ack_req_session_not_established_resp_side,
  1260. True)
  1261. def test_fst_ap_ack_request_with_bad_fsts_id(dev, apdev, test_params):
  1262. """FST AP ack request with bad fsts id"""
  1263. fst_bad_transfer(apdev, test_params, bad_scenario_ack_req_bad_fsts_id, True)
  1264. def test_fst_ap_ack_response_with_session_not_set_up(dev, apdev, test_params):
  1265. """FST AP ack response with session not set up"""
  1266. fst_bad_transfer(apdev, test_params,
  1267. bad_scenario_ack_resp_session_not_set_up, True)
  1268. def test_fst_ap_ack_response_with_session_not_established_init_side(dev, apdev, test_params):
  1269. """FST AP ack response with session not established init side"""
  1270. fst_bad_transfer(apdev, test_params,
  1271. bad_scenario_ack_resp_session_not_established_init_side,
  1272. True)
  1273. def test_fst_ap_ack_response_with_session_not_established_resp_side(dev, apdev, test_params):
  1274. """FST AP ack response with session not established resp side"""
  1275. fst_bad_transfer(apdev, test_params,
  1276. bad_scenario_ack_resp_session_not_established_resp_side,
  1277. True)
  1278. def test_fst_ap_ack_response_with_no_ack_request(dev, apdev, test_params):
  1279. """FST AP ack response with no ack request"""
  1280. fst_bad_transfer(apdev, test_params, bad_scenario_ack_resp_no_ack_req, True)
  1281. def test_fst_ap_tear_down_session(dev, apdev, test_params):
  1282. """FST AP tear down session"""
  1283. fst_tear_down_session(apdev, test_params, bad_param_none, True)
  1284. def test_fst_ap_tear_down_session_no_params(dev, apdev, test_params):
  1285. """FST AP tear down session - no params"""
  1286. fst_tear_down_session(apdev, test_params,
  1287. bad_param_session_teardown_no_params, True)
  1288. def test_fst_ap_tear_down_session_bad_session_id(dev, apdev, test_params):
  1289. """FST AP tear down session - bad session id"""
  1290. fst_tear_down_session(apdev, test_params,
  1291. bad_param_session_teardown_bad_session_id, True)
  1292. def test_fst_ap_tear_down_session_setup_skipped(dev, apdev, test_params):
  1293. """FST AP tear down session - setup skipped"""
  1294. fst_tear_down_session(apdev, test_params,
  1295. bad_param_session_teardown_setup_skipped, True)
  1296. def test_fst_ap_tear_down_session_bad_fsts_id(dev, apdev, test_params):
  1297. """FST AP tear down session - bad fsts id"""
  1298. fst_tear_down_session(apdev, test_params,
  1299. bad_param_session_teardown_bad_fsts_id, True)
  1300. def test_fst_ap_remove_session_not_established(dev, apdev, test_params):
  1301. """FST AP remove session - not established"""
  1302. fst_remove_session(apdev, test_params,
  1303. remove_scenario_non_established_session, True)
  1304. def test_fst_ap_remove_session_established(dev, apdev, test_params):
  1305. """FST AP remove session - established"""
  1306. fst_remove_session(apdev, test_params,
  1307. remove_scenario_established_session, True)
  1308. def test_fst_ap_remove_session_no_params(dev, apdev, test_params):
  1309. """FST AP remove session - no params"""
  1310. fst_remove_session(apdev, test_params, remove_scenario_no_params, True)
  1311. def test_fst_ap_remove_session_bad_session_id(dev, apdev, test_params):
  1312. """FST AP remove session - bad session id"""
  1313. fst_remove_session(apdev, test_params, remove_scenario_bad_session_id, True)
  1314. def test_fst_ap_ctrl_iface(dev, apdev, test_params):
  1315. """FST control interface behavior"""
  1316. hglobal = hostapd.HostapdGlobal()
  1317. start_num_groups = 0
  1318. res = hglobal.request("FST-MANAGER LIST_GROUPS")
  1319. del hglobal
  1320. if "FAIL" not in res:
  1321. start_num_groups = len(res.splitlines())
  1322. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  1323. try:
  1324. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1325. initiator = ap1
  1326. responder = sta1
  1327. initiator.add_peer(responder, None)
  1328. initiator.set_fst_parameters(group_id=None)
  1329. sid = initiator.add_session()
  1330. res = initiator.get_session_params(sid)
  1331. logger.info("Initial session params:\n" + str(res))
  1332. if res['state'] != 'INITIAL':
  1333. raise Exception("Unexpected state: " + res['state'])
  1334. initiator.set_fst_parameters(llt=None)
  1335. initiator.configure_session(sid, ap2.ifname(), None)
  1336. res = initiator.get_session_params(sid)
  1337. logger.info("Session params after configuration:\n" + str(res))
  1338. res = initiator.iface_peers(initiator.ifname())
  1339. logger.info("Interface peers: " + str(res))
  1340. if len(res) != 1:
  1341. raise Exception("Unexpected number of peers")
  1342. res = initiator.get_peer_mbies(initiator.ifname(),
  1343. initiator.get_new_peer_addr())
  1344. logger.info("Peer MB IEs: " + str(res))
  1345. res = initiator.list_ifaces()
  1346. logger.info("Interfaces: " + str(res))
  1347. if len(res) != 2:
  1348. raise Exception("Unexpected number of interfaces")
  1349. res = initiator.list_groups()
  1350. logger.info("Groups: " + str(res))
  1351. if len(res) != 1 + start_num_groups:
  1352. raise Exception("Unexpected number of groups")
  1353. tests = [ "LIST_IFACES unknown",
  1354. "LIST_IFACES unknown2",
  1355. "SESSION_GET 12345678",
  1356. "SESSION_SET " + sid + " unknown=foo",
  1357. "SESSION_RESPOND 12345678 foo",
  1358. "SESSION_RESPOND " + sid,
  1359. "SESSION_RESPOND " + sid + " foo",
  1360. "TEST_REQUEST foo",
  1361. "TEST_REQUEST SEND_SETUP_REQUEST",
  1362. "TEST_REQUEST SEND_SETUP_REQUEST foo",
  1363. "TEST_REQUEST SEND_SETUP_RESPONSE",
  1364. "TEST_REQUEST SEND_SETUP_RESPONSE foo",
  1365. "TEST_REQUEST SEND_ACK_REQUEST",
  1366. "TEST_REQUEST SEND_ACK_REQUEST foo",
  1367. "TEST_REQUEST SEND_ACK_RESPONSE",
  1368. "TEST_REQUEST SEND_ACK_RESPONSE foo",
  1369. "TEST_REQUEST SEND_TEAR_DOWN",
  1370. "TEST_REQUEST SEND_TEAR_DOWN foo",
  1371. "TEST_REQUEST GET_FSTS_ID",
  1372. "TEST_REQUEST GET_FSTS_ID foo",
  1373. "TEST_REQUEST GET_LOCAL_MBIES",
  1374. "TEST_REQUEST GET_LOCAL_MBIES foo",
  1375. "GET_PEER_MBIES",
  1376. "GET_PEER_MBIES ",
  1377. "GET_PEER_MBIES unknown",
  1378. "GET_PEER_MBIES unknown unknown",
  1379. "GET_PEER_MBIES unknown " + initiator.get_new_peer_addr(),
  1380. "GET_PEER_MBIES " + initiator.ifname() + " 01:ff:ff:ff:ff:ff",
  1381. "GET_PEER_MBIES " + initiator.ifname() + " 00:ff:ff:ff:ff:ff",
  1382. "GET_PEER_MBIES " + initiator.ifname() + " 00:00:00:00:00:00",
  1383. "IFACE_PEERS",
  1384. "IFACE_PEERS ",
  1385. "IFACE_PEERS unknown",
  1386. "IFACE_PEERS unknown unknown",
  1387. "IFACE_PEERS " + initiator.fst_group,
  1388. "IFACE_PEERS " + initiator.fst_group + " unknown" ]
  1389. for t in tests:
  1390. if "FAIL" not in initiator.grequest("FST-MANAGER " + t):
  1391. raise Exception("Unexpected response for invalid FST-MANAGER command " + t)
  1392. if "UNKNOWN FST COMMAND" not in initiator.grequest("FST-MANAGER unknown"):
  1393. raise Exception("Unexpected response for unknown FST-MANAGER command")
  1394. tests = [ "FST-DETACH", "FST-DETACH ", "FST-DETACH unknown",
  1395. "FST-ATTACH", "FST-ATTACH ", "FST-ATTACH unknown",
  1396. "FST-ATTACH unknown unknown" ]
  1397. for t in tests:
  1398. if "FAIL" not in initiator.grequest(t):
  1399. raise Exception("Unexpected response for invalid command " + t)
  1400. try:
  1401. # Trying to add same interface again needs to fail.
  1402. ap1.send_iface_attach_request(ap1.iface, ap1.fst_group,
  1403. ap1.fst_llt, ap1.fst_pri)
  1404. raise Exception("Duplicate FST-ATTACH succeeded")
  1405. except Exception, e:
  1406. if not str(e).startswith("Cannot attach"):
  1407. raise
  1408. try:
  1409. ap1.get_fsts_id_by_sid("123")
  1410. except Exception, e:
  1411. if not str(e).startswith("Cannot get fsts_id for sid"):
  1412. raise
  1413. finally:
  1414. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1415. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1416. def test_fst_ap_start_session_oom(dev, apdev, test_params):
  1417. """FST AP setup failing due to OOM"""
  1418. ap1 = fst_module_aux.FstAP(apdev[0]['ifname'], 'fst_11a', 'a',
  1419. fst_test_common.fst_test_def_chan_a,
  1420. fst_test_common.fst_test_def_group,
  1421. fst_test_common.fst_test_def_prio_low,
  1422. fst_test_common.fst_test_def_llt)
  1423. ap1.start()
  1424. try:
  1425. run_fst_ap_start_session_oom(apdev, ap1)
  1426. finally:
  1427. ap1.stop()
  1428. def run_fst_ap_start_session_oom(apdev, ap1):
  1429. with alloc_fail(ap1, 1, "fst_iface_create"):
  1430. ap2_started = False
  1431. try:
  1432. ap2 = fst_module_aux.FstAP(apdev[1]['ifname'], 'fst_11g', 'b',
  1433. fst_test_common.fst_test_def_chan_g,
  1434. fst_test_common.fst_test_def_group,
  1435. fst_test_common.fst_test_def_prio_high,
  1436. fst_test_common.fst_test_def_llt)
  1437. try:
  1438. # This will fail in fst_iface_create() OOM
  1439. ap2.start()
  1440. except:
  1441. pass
  1442. finally:
  1443. try:
  1444. ap2.stop()
  1445. except:
  1446. pass
  1447. # STA side FST module tests
  1448. def test_fst_sta_start_session(dev, apdev, test_params):
  1449. """FST STA start session"""
  1450. fst_start_session(apdev, test_params, bad_param_none, False)
  1451. def test_fst_sta_start_session_no_add_params(dev, apdev, test_params):
  1452. """FST STA start session - no add params"""
  1453. fst_start_session(apdev, test_params, bad_param_session_add_no_params,
  1454. False)
  1455. def test_fst_sta_start_session_bad_group_id(dev, apdev, test_params):
  1456. """FST STA start session - bad group id"""
  1457. fst_start_session(apdev, test_params, bad_param_group_id, False)
  1458. def test_fst_sta_start_session_no_set_params(dev, apdev, test_params):
  1459. """FST STA start session - no set params"""
  1460. fst_start_session(apdev, test_params, bad_param_session_set_no_params,
  1461. False)
  1462. def test_fst_sta_start_session_set_unknown_param(dev, apdev, test_params):
  1463. """FST STA start session - set unknown param"""
  1464. fst_start_session(apdev, test_params, bad_param_session_set_unknown_param,
  1465. False)
  1466. def test_fst_sta_start_session_bad_session_id(dev, apdev, test_params):
  1467. """FST STA start session - bad session id"""
  1468. fst_start_session(apdev, test_params, bad_param_session_id, False)
  1469. def test_fst_sta_start_session_bad_new_iface(dev, apdev, test_params):
  1470. """FST STA start session - bad new iface"""
  1471. fst_start_session(apdev, test_params, bad_param_new_iface, False)
  1472. def test_fst_sta_start_session_bad_old_iface(dev, apdev, test_params):
  1473. """FST STA start session - bad old iface"""
  1474. fst_start_session(apdev, test_params, bad_param_old_iface, False)
  1475. def test_fst_sta_start_session_negative_llt(dev, apdev, test_params):
  1476. """FST STA start session - negative llt"""
  1477. fst_start_session(apdev, test_params, bad_param_negative_llt, False)
  1478. def test_fst_sta_start_session_zero_llt(dev, apdev, test_params):
  1479. """FST STA start session - zero llt"""
  1480. fst_start_session(apdev, test_params, bad_param_zero_llt, False)
  1481. def test_fst_sta_start_session_llt_too_big(dev, apdev, test_params):
  1482. """FST STA start session - llt too large"""
  1483. fst_start_session(apdev, test_params, bad_param_llt_too_big, False)
  1484. def test_fst_sta_start_session_invalid_peer_addr(dev, apdev, test_params):
  1485. """FST STA start session - invalid peer address"""
  1486. fst_start_session(apdev, test_params, bad_param_peer_addr, False,
  1487. 'GG:GG:GG:GG:GG:GG')
  1488. def test_fst_sta_start_session_multicast_peer_addr(dev, apdev, test_params):
  1489. """FST STA start session - multicast peer address"""
  1490. fst_start_session(apdev, test_params, bad_param_peer_addr, False,
  1491. '11:00:11:22:33:44')
  1492. def test_fst_sta_start_session_broadcast_peer_addr(dev, apdev, test_params):
  1493. """FST STA start session - broadcast peer addr"""
  1494. fst_start_session(apdev, test_params, bad_param_peer_addr, False,
  1495. 'FF:FF:FF:FF:FF:FF')
  1496. def test_fst_sta_initiate_session(dev, apdev, test_params):
  1497. """FST STA initiate session"""
  1498. fst_initiate_session(apdev, test_params, bad_param_none, False)
  1499. def test_fst_sta_initiate_session_no_params(dev, apdev, test_params):
  1500. """FST STA initiate session - no params"""
  1501. fst_initiate_session(apdev, test_params,
  1502. bad_param_session_initiate_no_params, False)
  1503. def test_fst_sta_initiate_session_invalid_session_id(dev, apdev, test_params):
  1504. """FST STA initiate session - invalid session id"""
  1505. fst_initiate_session(apdev, test_params,
  1506. bad_param_session_initiate_bad_session_id, False)
  1507. def test_fst_sta_initiate_session_no_new_iface(dev, apdev, test_params):
  1508. """FST STA initiate session - no new iface"""
  1509. fst_initiate_session(apdev, test_params,
  1510. bad_param_session_initiate_with_no_new_iface_set,
  1511. False)
  1512. def test_fst_sta_initiate_session_bad_peer_addr(dev, apdev, test_params):
  1513. """FST STA initiate session - bad peer address"""
  1514. fst_initiate_session(apdev, test_params,
  1515. bad_param_session_initiate_with_bad_peer_addr_set,
  1516. False)
  1517. def test_fst_sta_initiate_session_request_with_bad_stie(dev, apdev,
  1518. test_params):
  1519. """FST STA initiate session - request with bad stie"""
  1520. fst_initiate_session(apdev, test_params,
  1521. bad_param_session_initiate_request_with_bad_stie,
  1522. False)
  1523. def test_fst_sta_initiate_session_response_with_reject(dev, apdev, test_params):
  1524. """FST STA initiate session - response with reject"""
  1525. fst_initiate_session(apdev, test_params, bad_param_session_initiate_response_with_reject, False)
  1526. def test_fst_sta_initiate_session_response_with_bad_stie(dev, apdev, test_params):
  1527. """FST STA initiate session - response with bad stie"""
  1528. fst_initiate_session(apdev, test_params,
  1529. bad_param_session_initiate_response_with_bad_stie,
  1530. False)
  1531. def test_fst_sta_initiate_session_response_with_zero_llt(dev, apdev,
  1532. test_params):
  1533. """FST STA initiate session - response with zero llt"""
  1534. fst_initiate_session(apdev, test_params,
  1535. bad_param_session_initiate_response_with_zero_llt,
  1536. False)
  1537. def test_fst_sta_initiate_session_stt_no_response(dev, apdev, test_params):
  1538. """FST STA initiate session - stt no response"""
  1539. fst_initiate_session(apdev, test_params,
  1540. bad_param_session_initiate_stt_no_response, False)
  1541. def test_fst_sta_initiate_session_concurrent_setup_request(dev, apdev,
  1542. test_params):
  1543. """FST STA initiate session - concurrent setup request"""
  1544. fst_initiate_session(apdev, test_params,
  1545. bad_param_session_initiate_concurrent_setup_request,
  1546. False)
  1547. def test_fst_sta_session_request_with_no_session(dev, apdev, test_params):
  1548. """FST STA session request with no session"""
  1549. fst_send_unexpected_frame(apdev, test_params, frame_type_session_request,
  1550. False)
  1551. def test_fst_sta_session_response_accept_with_no_session(dev, apdev,
  1552. test_params):
  1553. """FST STA session response accept with no session"""
  1554. fst_send_unexpected_frame(apdev, test_params, frame_type_session_response,
  1555. False, "accept")
  1556. def test_fst_sta_session_response_reject_with_no_session(dev, apdev,
  1557. test_params):
  1558. """FST STA session response reject with no session"""
  1559. fst_send_unexpected_frame(apdev, test_params, frame_type_session_response,
  1560. False, "reject")
  1561. def test_fst_sta_ack_request_with_no_session(dev, apdev, test_params):
  1562. """FST STA ack request with no session"""
  1563. fst_send_unexpected_frame(apdev, test_params, frame_type_ack_request, False)
  1564. def test_fst_sta_ack_response_with_no_session(dev, apdev, test_params):
  1565. """FST STA ack response with no session"""
  1566. fst_send_unexpected_frame(apdev, test_params, frame_type_ack_response,
  1567. False)
  1568. def test_fst_sta_tear_down_response_with_no_session(dev, apdev, test_params):
  1569. """FST STA tear down response with no session"""
  1570. fst_send_unexpected_frame(apdev, test_params, frame_type_tear_down, False)
  1571. def test_fst_sta_transfer_session(dev, apdev, test_params):
  1572. """FST STA transfer session"""
  1573. fst_transfer_session(apdev, test_params, bad_param_none, False)
  1574. def test_fst_sta_transfer_session_no_params(dev, apdev, test_params):
  1575. """FST STA transfer session - no params"""
  1576. fst_transfer_session(apdev, test_params,
  1577. bad_param_session_transfer_no_params, False)
  1578. def test_fst_sta_transfer_session_bad_session_id(dev, apdev, test_params):
  1579. """FST STA transfer session - bad session id"""
  1580. fst_transfer_session(apdev, test_params,
  1581. bad_param_session_transfer_bad_session_id, False)
  1582. def test_fst_sta_transfer_session_setup_skipped(dev, apdev, test_params):
  1583. """FST STA transfer session - setup skipped"""
  1584. fst_transfer_session(apdev, test_params,
  1585. bad_param_session_transfer_setup_skipped, False)
  1586. def test_fst_sta_ack_request_with_session_not_set_up(dev, apdev, test_params):
  1587. """FST STA ack request with session not set up"""
  1588. fst_bad_transfer(apdev, test_params,
  1589. bad_scenario_ack_req_session_not_set_up, False)
  1590. def test_fst_sta_ack_request_with_session_not_established_init_side(dev, apdev, test_params):
  1591. """FST STA ack request with session not established init side"""
  1592. fst_bad_transfer(apdev, test_params,
  1593. bad_scenario_ack_req_session_not_established_init_side,
  1594. False)
  1595. def test_fst_sta_ack_request_with_session_not_established_resp_side(dev, apdev, test_params):
  1596. """FST STA ack request with session not established resp side"""
  1597. fst_bad_transfer(apdev, test_params,
  1598. bad_scenario_ack_req_session_not_established_resp_side,
  1599. False)
  1600. def test_fst_sta_ack_request_with_bad_fsts_id(dev, apdev, test_params):
  1601. """FST STA ack request with bad fsts id"""
  1602. fst_bad_transfer(apdev, test_params, bad_scenario_ack_req_bad_fsts_id,
  1603. False)
  1604. def test_fst_sta_ack_response_with_session_not_set_up(dev, apdev, test_params):
  1605. """FST STA ack response with session not set up"""
  1606. fst_bad_transfer(apdev, test_params,
  1607. bad_scenario_ack_resp_session_not_set_up, False)
  1608. def test_fst_sta_ack_response_with_session_not_established_init_side(dev, apdev, test_params):
  1609. """FST STA ack response with session not established init side"""
  1610. fst_bad_transfer(apdev, test_params,
  1611. bad_scenario_ack_resp_session_not_established_init_side,
  1612. False)
  1613. def test_fst_sta_ack_response_with_session_not_established_resp_side(dev, apdev, test_params):
  1614. """FST STA ack response with session not established resp side"""
  1615. fst_bad_transfer(apdev, test_params,
  1616. bad_scenario_ack_resp_session_not_established_resp_side,
  1617. False)
  1618. def test_fst_sta_ack_response_with_no_ack_request(dev, apdev, test_params):
  1619. """FST STA ack response with no ack request"""
  1620. fst_bad_transfer(apdev, test_params, bad_scenario_ack_resp_no_ack_req,
  1621. False)
  1622. def test_fst_sta_tear_down_session(dev, apdev, test_params):
  1623. """FST STA tear down session"""
  1624. fst_tear_down_session(apdev, test_params, bad_param_none, False)
  1625. def test_fst_sta_tear_down_session_no_params(dev, apdev, test_params):
  1626. """FST STA tear down session - no params"""
  1627. fst_tear_down_session(apdev, test_params,
  1628. bad_param_session_teardown_no_params, False)
  1629. def test_fst_sta_tear_down_session_bad_session_id(dev, apdev, test_params):
  1630. """FST STA tear down session - bad session id"""
  1631. fst_tear_down_session(apdev, test_params,
  1632. bad_param_session_teardown_bad_session_id, False)
  1633. def test_fst_sta_tear_down_session_setup_skipped(dev, apdev, test_params):
  1634. """FST STA tear down session - setup skipped"""
  1635. fst_tear_down_session(apdev, test_params,
  1636. bad_param_session_teardown_setup_skipped, False)
  1637. def test_fst_sta_tear_down_session_bad_fsts_id(dev, apdev, test_params):
  1638. """FST STA tear down session - bad fsts id"""
  1639. fst_tear_down_session(apdev, test_params,
  1640. bad_param_session_teardown_bad_fsts_id, False)
  1641. def test_fst_sta_remove_session_not_established(dev, apdev, test_params):
  1642. """FST STA tear down session - not established"""
  1643. fst_remove_session(apdev, test_params,
  1644. remove_scenario_non_established_session, False)
  1645. def test_fst_sta_remove_session_established(dev, apdev, test_params):
  1646. """FST STA remove session - established"""
  1647. fst_remove_session(apdev, test_params,
  1648. remove_scenario_established_session, False)
  1649. def test_fst_sta_remove_session_no_params(dev, apdev, test_params):
  1650. """FST STA remove session - no params"""
  1651. fst_remove_session(apdev, test_params, remove_scenario_no_params, False)
  1652. def test_fst_sta_remove_session_bad_session_id(dev, apdev, test_params):
  1653. """FST STA remove session - bad session id"""
  1654. fst_remove_session(apdev, test_params, remove_scenario_bad_session_id,
  1655. False)
  1656. def test_fst_rsn_ap_transfer_session(dev, apdev, test_params):
  1657. """FST RSN AP transfer session"""
  1658. fst_transfer_session(apdev, test_params, bad_param_none, True, rsn=True)
  1659. MGMT_SUBTYPE_ACTION = 13
  1660. ACTION_CATEG_FST = 18
  1661. FST_ACTION_SETUP_REQUEST = 0
  1662. FST_ACTION_SETUP_RESPONSE = 1
  1663. FST_ACTION_TEAR_DOWN = 2
  1664. FST_ACTION_ACK_REQUEST = 3
  1665. FST_ACTION_ACK_RESPONSE = 4
  1666. FST_ACTION_ON_CHANNEL_TUNNEL = 5
  1667. def hostapd_tx_and_status(hapd, msg):
  1668. hapd.set("ext_mgmt_frame_handling", "1")
  1669. hapd.mgmt_tx(msg)
  1670. ev = hapd.wait_event([ "MGMT-TX-STATUS" ], timeout=1)
  1671. if ev is None or "ok=1" not in ev:
  1672. raise Exception("No ACK")
  1673. hapd.set("ext_mgmt_frame_handling", "0")
  1674. def test_fst_proto(dev, apdev, test_params):
  1675. """FST protocol testing"""
  1676. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  1677. try:
  1678. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1679. hapd = ap1.get_instance()
  1680. sta = sta1.get_instance()
  1681. dst = sta.own_addr()
  1682. src = apdev[0]['bssid']
  1683. msg = {}
  1684. msg['fc'] = MGMT_SUBTYPE_ACTION << 4
  1685. msg['da'] = dst
  1686. msg['sa'] = src
  1687. msg['bssid'] = src
  1688. # unknown FST Action (255) received!
  1689. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST, 255)
  1690. hostapd_tx_and_status(hapd, msg)
  1691. # FST Request dropped: too short
  1692. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1693. FST_ACTION_SETUP_REQUEST)
  1694. hostapd_tx_and_status(hapd, msg)
  1695. # FST Request dropped: invalid STIE (EID)
  1696. msg['payload'] = struct.pack("<BBBLBBLBBBBBBB", ACTION_CATEG_FST,
  1697. FST_ACTION_SETUP_REQUEST, 0, 0,
  1698. 163, 11, 0, 0, 0, 0, 0, 0, 0, 0)
  1699. hostapd_tx_and_status(hapd, msg)
  1700. # FST Request dropped: invalid STIE (Len)
  1701. msg['payload'] = struct.pack("<BBBLBBLBBBBBBB", ACTION_CATEG_FST,
  1702. FST_ACTION_SETUP_REQUEST, 0, 0,
  1703. 164, 10, 0, 0, 0, 0, 0, 0, 0, 0)
  1704. hostapd_tx_and_status(hapd, msg)
  1705. # FST Request dropped: new and old band IDs are the same
  1706. msg['payload'] = struct.pack("<BBBLBBLBBBBBBB", ACTION_CATEG_FST,
  1707. FST_ACTION_SETUP_REQUEST, 0, 0,
  1708. 164, 11, 0, 0, 0, 0, 0, 0, 0, 0)
  1709. hostapd_tx_and_status(hapd, msg)
  1710. ifaces = sta1.list_ifaces()
  1711. id = int(ifaces[0]['name'].split('|')[1])
  1712. # FST Request dropped: new iface not found (new_band_id mismatch)
  1713. msg['payload'] = struct.pack("<BBBLBBLBBBBBBB", ACTION_CATEG_FST,
  1714. FST_ACTION_SETUP_REQUEST, 0, 0,
  1715. 164, 11, 0, 0, id + 1, 0, 0, 0, 0, 0)
  1716. hostapd_tx_and_status(hapd, msg)
  1717. # FST Action 'Setup Response' dropped: no session in progress found
  1718. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1719. FST_ACTION_SETUP_RESPONSE)
  1720. hostapd_tx_and_status(hapd, msg)
  1721. # Create session
  1722. initiator = ap1
  1723. responder = sta1
  1724. new_iface = ap2.ifname()
  1725. new_peer_addr = ap2.get_actual_peer_addr()
  1726. resp_newif = sta2.ifname()
  1727. peeraddr = None
  1728. initiator.add_peer(responder, peeraddr, new_peer_addr)
  1729. sid = initiator.add_session()
  1730. initiator.configure_session(sid, new_iface)
  1731. initiator.initiate_session(sid, "accept")
  1732. # FST Response dropped due to wrong state: SETUP_COMPLETION
  1733. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1734. FST_ACTION_SETUP_RESPONSE)
  1735. hostapd_tx_and_status(hapd, msg)
  1736. # Too short FST Tear Down dropped
  1737. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1738. FST_ACTION_TEAR_DOWN)
  1739. hostapd_tx_and_status(hapd, msg)
  1740. # tear down for wrong FST Setup ID (0)
  1741. msg['payload'] = struct.pack("<BBL", ACTION_CATEG_FST,
  1742. FST_ACTION_TEAR_DOWN, 0)
  1743. hostapd_tx_and_status(hapd, msg)
  1744. # Ack received on wrong interface
  1745. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1746. FST_ACTION_ACK_REQUEST)
  1747. hostapd_tx_and_status(hapd, msg)
  1748. # Ack Response in inappropriate session state (SETUP_COMPLETION)
  1749. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1750. FST_ACTION_ACK_RESPONSE)
  1751. hostapd_tx_and_status(hapd, msg)
  1752. # Unsupported FST Action frame (On channel tunnel)
  1753. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1754. FST_ACTION_ON_CHANNEL_TUNNEL)
  1755. hostapd_tx_and_status(hapd, msg)
  1756. # FST Request dropped: new iface not found (new_band_id match)
  1757. # FST Request dropped due to MAC comparison
  1758. msg['payload'] = struct.pack("<BBBLBBLBBBBBBB", ACTION_CATEG_FST,
  1759. FST_ACTION_SETUP_REQUEST, 0, 0,
  1760. 164, 11, 0, 0, id, 0, 0, 0, 0, 0)
  1761. hostapd_tx_and_status(hapd, msg)
  1762. hapd2 = ap2.get_instance()
  1763. dst2 = sta2.get_instance().own_addr()
  1764. src2 = apdev[1]['bssid']
  1765. msg2 = {}
  1766. msg2['fc'] = MGMT_SUBTYPE_ACTION << 4
  1767. msg2['da'] = dst2
  1768. msg2['sa'] = src2
  1769. msg2['bssid'] = src2
  1770. # FST Response dropped: wlan6 is not the old iface
  1771. msg2['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1772. FST_ACTION_SETUP_RESPONSE)
  1773. hostapd_tx_and_status(hapd2, msg2)
  1774. sta.dump_monitor()
  1775. group = ap1.fst_group
  1776. ap1.send_iface_detach_request(ap1.iface)
  1777. sta.flush_scan_cache()
  1778. sta.request("REASSOCIATE")
  1779. sta.wait_connected()
  1780. # FST Request dropped due to no interface connection
  1781. msg['payload'] = struct.pack("<BBBLBBLBBBBBBB", ACTION_CATEG_FST,
  1782. FST_ACTION_SETUP_REQUEST, 0, 0,
  1783. 164, 11, 0, 0, id, 0, 0, 0, 0, 0)
  1784. hostapd_tx_and_status(hapd, msg)
  1785. finally:
  1786. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1787. try:
  1788. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1789. except:
  1790. pass
  1791. def test_fst_setup_response_proto(dev, apdev, test_params):
  1792. """FST protocol testing for Setup Response"""
  1793. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  1794. try:
  1795. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1796. hapd = ap1.get_instance()
  1797. sta = sta1.get_instance()
  1798. dst = sta.own_addr()
  1799. src = apdev[0]['bssid']
  1800. sta1.add_peer(ap1, None, sta2.get_actual_peer_addr())
  1801. sta1.set_fst_parameters(llt='0')
  1802. sid = sta1.add_session()
  1803. sta1.configure_session(sid, sta2.ifname())
  1804. sta1.initiate_session(sid, "")
  1805. msg = {}
  1806. msg['fc'] = MGMT_SUBTYPE_ACTION << 4
  1807. msg['da'] = dst
  1808. msg['sa'] = src
  1809. msg['bssid'] = src
  1810. # Too short FST Response dropped
  1811. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1812. FST_ACTION_SETUP_RESPONSE)
  1813. hostapd_tx_and_status(hapd, msg)
  1814. # FST Response dropped: invalid STIE (EID)
  1815. dialog_token = 1
  1816. status_code = 0
  1817. id = 0
  1818. msg['payload'] = struct.pack("<BBBBBBLBBBBBBB", ACTION_CATEG_FST,
  1819. FST_ACTION_SETUP_RESPONSE, dialog_token,
  1820. status_code,
  1821. 163, 11, 0, 0, id, 0, 0, 0, 0, 0)
  1822. hostapd_tx_and_status(hapd, msg)
  1823. # FST Response dropped: invalid STIE (Len)
  1824. dialog_token = 1
  1825. status_code = 0
  1826. id = 0
  1827. msg['payload'] = struct.pack("<BBBBBBLBBBBBBB", ACTION_CATEG_FST,
  1828. FST_ACTION_SETUP_RESPONSE, dialog_token,
  1829. status_code,
  1830. 164, 10, 0, 0, id, 0, 0, 0, 0, 0)
  1831. hostapd_tx_and_status(hapd, msg)
  1832. # FST Response dropped due to wrong dialog token
  1833. dialog_token = 123
  1834. status_code = 0
  1835. id = 0
  1836. msg['payload'] = struct.pack("<BBBBBBLBBBBBBB", ACTION_CATEG_FST,
  1837. FST_ACTION_SETUP_RESPONSE, dialog_token,
  1838. status_code,
  1839. 164, 11, 0, 0, id, 0, 0, 0, 0, 0)
  1840. hostapd_tx_and_status(hapd, msg)
  1841. # FST Response dropped due to wrong FST Session ID
  1842. dialog_token = 1
  1843. status_code = 0
  1844. id = 1
  1845. msg['payload'] = struct.pack("<BBBBBBLBBBBBBB", ACTION_CATEG_FST,
  1846. FST_ACTION_SETUP_RESPONSE, dialog_token,
  1847. status_code,
  1848. 164, 11, int(sid) + 123456,
  1849. 0, id, 0, 0, 0, 0, 0)
  1850. hostapd_tx_and_status(hapd, msg)
  1851. # FST Response with non-zero status code
  1852. dialog_token = 1
  1853. status_code = 1
  1854. id = 1
  1855. msg['payload'] = struct.pack("<BBBBBBLBBBBBBB", ACTION_CATEG_FST,
  1856. FST_ACTION_SETUP_RESPONSE, dialog_token,
  1857. status_code,
  1858. 164, 11, int(sid), 0, id, 0, 0, 0, 0, 0)
  1859. hostapd_tx_and_status(hapd, msg)
  1860. finally:
  1861. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1862. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1863. def test_fst_ack_response_proto(dev, apdev, test_params):
  1864. """FST protocol testing for Ack Response"""
  1865. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  1866. try:
  1867. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1868. hapd = ap2.get_instance()
  1869. sta = sta2.get_instance()
  1870. dst = sta.own_addr()
  1871. src = apdev[1]['bssid']
  1872. sta1.add_peer(ap1, None, sta2.get_actual_peer_addr())
  1873. sta1.set_fst_parameters(llt='0')
  1874. sid = sta1.add_session()
  1875. sta1.configure_session(sid, sta2.ifname())
  1876. s = sta1.grequest("FST-MANAGER SESSION_INITIATE "+ sid)
  1877. if not s.startswith('OK'):
  1878. raise Exception("Cannot initiate fst session: %s" % s)
  1879. ev = sta1.peer_obj.wait_gevent([ "FST-EVENT-SESSION" ], timeout=5)
  1880. if ev is None:
  1881. raise Exception("No FST-EVENT-SESSION received")
  1882. event = fst_module_aux.parse_fst_session_event(ev)
  1883. if event == None:
  1884. raise Exception("Unrecognized FST event: " % ev)
  1885. if event['type'] != 'EVENT_FST_SETUP':
  1886. raise Exception("Expected FST_SETUP event, got: " + event['type'])
  1887. ev = sta1.peer_obj.wait_gevent(["FST-EVENT-SESSION"], timeout=5)
  1888. if ev is None:
  1889. raise Exception("No FST-EVENT-SESSION received")
  1890. event = fst_module_aux.parse_fst_session_event(ev)
  1891. if event == None:
  1892. raise Exception("Unrecognized FST event: " % ev)
  1893. if event['type'] != 'EVENT_FST_SESSION_STATE':
  1894. raise Exception("Expected EVENT_FST_SESSION_STATE event, got: " + event['type'])
  1895. if event['new_state'] != "SETUP_COMPLETION":
  1896. raise Exception("Expected new state SETUP_COMPLETION, got: " + event['new_state'])
  1897. hapd.set("ext_mgmt_frame_handling", "1")
  1898. s = sta1.peer_obj.grequest("FST-MANAGER SESSION_RESPOND "+ event['id'] + " accept")
  1899. if not s.startswith('OK'):
  1900. raise Exception("Error session_respond: %s" % s)
  1901. req = hapd.mgmt_rx()
  1902. if req is None:
  1903. raise Exception("No Ack Request seen")
  1904. msg = {}
  1905. msg['fc'] = MGMT_SUBTYPE_ACTION << 4
  1906. msg['da'] = dst
  1907. msg['sa'] = src
  1908. msg['bssid'] = src
  1909. # Too short FST Ack Response dropped
  1910. msg['payload'] = struct.pack("<BB", ACTION_CATEG_FST,
  1911. FST_ACTION_ACK_RESPONSE)
  1912. hapd.mgmt_tx(msg)
  1913. ev = hapd.wait_event([ "MGMT-TX-STATUS" ], timeout=1)
  1914. if ev is None or "ok=1" not in ev:
  1915. raise Exception("No ACK")
  1916. # Ack Response for wrong FSt Setup ID
  1917. msg['payload'] = struct.pack("<BBBL", ACTION_CATEG_FST,
  1918. FST_ACTION_ACK_RESPONSE,
  1919. 0, int(sid) + 123456)
  1920. hostapd_tx_and_status(hapd, msg)
  1921. finally:
  1922. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1923. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1924. def test_fst_ap_config_oom(dev, apdev, test_params):
  1925. """FST AP configuration and OOM"""
  1926. ap1 = fst_module_aux.FstAP(apdev[0]['ifname'], 'fst_11a', 'a',
  1927. fst_test_common.fst_test_def_chan_a,
  1928. fst_test_common.fst_test_def_group,
  1929. fst_test_common.fst_test_def_prio_low)
  1930. hapd = ap1.start(return_early=True)
  1931. with alloc_fail(hapd, 1, "fst_group_create"):
  1932. res = ap1.grequest("FST-ATTACH %s %s" % (ap1.iface, ap1.fst_group))
  1933. if not res.startswith("FAIL"):
  1934. raise Exception("FST-ATTACH succeeded unexpectedly")
  1935. with alloc_fail(hapd, 1, "fst_iface_create"):
  1936. res = ap1.grequest("FST-ATTACH %s %s" % (ap1.iface, ap1.fst_group))
  1937. if not res.startswith("FAIL"):
  1938. raise Exception("FST-ATTACH succeeded unexpectedly")
  1939. with alloc_fail(hapd, 1, "fst_group_create_mb_ie"):
  1940. res = ap1.grequest("FST-ATTACH %s %s" % (ap1.iface, ap1.fst_group))
  1941. # This is allowed to complete currently
  1942. ap1.stop()
  1943. def test_fst_send_oom(dev, apdev, test_params):
  1944. """FST send action OOM"""
  1945. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  1946. try:
  1947. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1948. hapd = ap1.get_instance()
  1949. sta = sta1.get_instance()
  1950. dst = sta.own_addr()
  1951. src = apdev[0]['bssid']
  1952. # Create session
  1953. initiator = ap1
  1954. responder = sta1
  1955. new_iface = ap2.ifname()
  1956. new_peer_addr = ap2.get_actual_peer_addr()
  1957. resp_newif = sta2.ifname()
  1958. peeraddr = None
  1959. initiator.add_peer(responder, peeraddr, new_peer_addr)
  1960. sid = initiator.add_session()
  1961. initiator.configure_session(sid, new_iface)
  1962. with alloc_fail(hapd, 1, "fst_session_send_action"):
  1963. res = initiator.grequest("FST-MANAGER SESSION_INITIATE " + sid)
  1964. if not res.startswith("FAIL"):
  1965. raise Exception("Unexpected SESSION_INITIATE result")
  1966. res = initiator.grequest("FST-MANAGER SESSION_INITIATE " + sid)
  1967. if not res.startswith("OK"):
  1968. raise Exception("SESSION_INITIATE failed")
  1969. tests = [ "", "foo", sid, sid + " foo", sid + " foo=bar" ]
  1970. for t in tests:
  1971. res = initiator.grequest("FST-MANAGER SESSION_SET " + t)
  1972. if not res.startswith("FAIL"):
  1973. raise Exception("Invalid SESSION_SET accepted")
  1974. with alloc_fail(hapd, 1, "fst_session_send_action"):
  1975. res = initiator.grequest("FST-MANAGER SESSION_TEARDOWN " + sid)
  1976. if not res.startswith("FAIL"):
  1977. raise Exception("Unexpected SESSION_TEARDOWN result")
  1978. finally:
  1979. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1980. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1981. def test_fst_session_oom(dev, apdev, test_params):
  1982. """FST session create OOM"""
  1983. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  1984. try:
  1985. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  1986. hapd = ap1.get_instance()
  1987. sta = sta1.get_instance()
  1988. dst = sta.own_addr()
  1989. src = apdev[0]['bssid']
  1990. # Create session
  1991. initiator = ap1
  1992. responder = sta1
  1993. new_iface = ap2.ifname()
  1994. new_peer_addr = ap2.get_actual_peer_addr()
  1995. resp_newif = sta2.ifname()
  1996. peeraddr = None
  1997. initiator.add_peer(responder, peeraddr, new_peer_addr)
  1998. with alloc_fail(hapd, 1, "fst_session_create"):
  1999. sid = initiator.grequest("FST-MANAGER SESSION_ADD " + initiator.fst_group)
  2000. if not sid.startswith("FAIL"):
  2001. raise Exception("Unexpected SESSION_ADD success")
  2002. sid = initiator.add_session()
  2003. initiator.configure_session(sid, new_iface)
  2004. with alloc_fail(sta, 1, "fst_session_create"):
  2005. res = initiator.grequest("FST-MANAGER SESSION_INITIATE " + sid)
  2006. if not res.startswith("OK"):
  2007. raise Exception("Unexpected SESSION_INITIATE result")
  2008. finally:
  2009. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  2010. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  2011. def test_fst_attach_zero_llt(dev, apdev):
  2012. """FST attach with llt=0"""
  2013. sta1 = fst_module_aux.FstSTA('wlan5', fst_test_common.fst_test_def_group,
  2014. "100", "0")
  2015. sta1.start()
  2016. sta1.stop()
  2017. def test_fst_session_respond_fail(dev, apdev, test_params):
  2018. """FST-MANAGER SESSION_RESPOND failure"""
  2019. ap1, ap2, sta1, sta2 = fst_module_aux.start_two_ap_sta_pairs(apdev)
  2020. try:
  2021. fst_module_aux.connect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  2022. sta1.add_peer(ap1, None, sta2.get_actual_peer_addr())
  2023. sid = sta1.add_session()
  2024. sta1.configure_session(sid, sta2.ifname())
  2025. sta1.send_session_setup_request(sid)
  2026. sta1.wait_for_session_event(5, [], ["EVENT_FST_SESSION_STATE"])
  2027. ev = ap1.wait_for_session_event(5, [], ['EVENT_FST_SETUP'])
  2028. if not 'id' in ev:
  2029. raise Exception("No session id in FST setup event")
  2030. # Disconnect STA to make SESSION_RESPOND fail due to no peer found
  2031. sta = sta1.get_instance()
  2032. sta.request("DISCONNECT")
  2033. sta.wait_disconnected()
  2034. req = "FST-MANAGER SESSION_RESPOND %s reject" % ev['id']
  2035. s = ap1.grequest(req)
  2036. if not s.startswith("FAIL"):
  2037. raise Exception("SESSION_RESPOND succeeded unexpectedly")
  2038. finally:
  2039. fst_module_aux.disconnect_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  2040. fst_module_aux.stop_two_ap_sta_pairs(ap1, ap2, sta1, sta2)
  2041. def fst_session_set(dev, sid, param, value):
  2042. cmd = "FST-MANAGER SESSION_SET %s %s=%s" % (sid, param, value)
  2043. if "OK" not in dev.global_request(cmd):
  2044. raise Exception(cmd + " failed")
  2045. def fst_session_set_ap(dev, sid, param, value):
  2046. cmd = "FST-MANAGER SESSION_SET %s %s=%s" % (sid, param, value)
  2047. if "OK" not in dev.request(cmd):
  2048. raise Exception(cmd + " failed")
  2049. def fst_attach_ap(dev, ifname, group):
  2050. cmd = "FST-ATTACH %s %s" % (ifname, group)
  2051. if "OK" not in dev.request(cmd):
  2052. raise Exception("FST-ATTACH (AP) failed")
  2053. ev = dev.wait_event(['FST-EVENT-IFACE'], timeout=5)
  2054. if ev is None:
  2055. raise Exception("No FST-EVENT-IFACE attached (AP)")
  2056. for t in [ "attached", "ifname=" + ifname, "group=" + group ]:
  2057. if t not in ev:
  2058. raise Exception("Unexpected FST-EVENT-IFACE data (AP): " + ev)
  2059. def fst_attach_sta(dev, ifname, group):
  2060. if "OK" not in dev.global_request("FST-ATTACH %s %s" % (ifname, group)):
  2061. raise Exception("FST-ATTACH (STA) failed")
  2062. ev = dev.wait_global_event(['FST-EVENT-IFACE'], timeout=5)
  2063. if ev is None:
  2064. raise Exception("No FST-EVENT-IFACE attached (STA)")
  2065. for t in [ "attached", "ifname=" + ifname, "group=" + group ]:
  2066. if t not in ev:
  2067. raise Exception("Unexpected FST-EVENT-IFACE data (STA): " + ev)
  2068. def fst_detach_ap(dev, ifname, group):
  2069. if "OK" not in dev.request("FST-DETACH " + ifname):
  2070. raise Exception("FST-DETACH (AP) failed for " + ifname)
  2071. ev = dev.wait_event(['FST-EVENT-IFACE'], timeout=5)
  2072. if ev is None:
  2073. raise Exception("No FST-EVENT-IFACE detached (AP) for " + ifname)
  2074. for t in [ "detached", "ifname=" + ifname, "group=" + group ]:
  2075. if t not in ev:
  2076. raise Exception("Unexpected FST-EVENT-IFACE data (AP): " + ev)
  2077. def fst_detach_sta(dev, ifname, group):
  2078. dev.dump_monitor()
  2079. if "OK" not in dev.global_request("FST-DETACH " + ifname):
  2080. raise Exception("FST-DETACH (STA) failed for " + ifname)
  2081. ev = dev.wait_global_event(['FST-EVENT-IFACE'], timeout=5)
  2082. if ev is None:
  2083. raise Exception("No FST-EVENT-IFACE detached (STA) for " + ifname)
  2084. for t in [ "detached", "ifname=" + ifname, "group=" + group ]:
  2085. if t not in ev:
  2086. raise Exception("Unexpected FST-EVENT-IFACE data (STA): " + ev)
  2087. def fst_wait_event_peer_ap(dev, event, ifname, addr):
  2088. ev = dev.wait_event(['FST-EVENT-PEER'], timeout=5)
  2089. if ev is None:
  2090. raise Exception("No FST-EVENT-PEER connected (AP)")
  2091. for t in [ " " + event + " ", "ifname=" + ifname, "peer_addr=" + addr ]:
  2092. if t not in ev:
  2093. raise Exception("Unexpected FST-EVENT-PEER data (AP): " + ev)
  2094. def fst_wait_event_peer_sta(dev, event, ifname, addr):
  2095. ev = dev.wait_global_event(['FST-EVENT-PEER'], timeout=5)
  2096. if ev is None:
  2097. raise Exception("No FST-EVENT-PEER connected (STA)")
  2098. for t in [ " " + event + " ", "ifname=" + ifname, "peer_addr=" + addr ]:
  2099. if t not in ev:
  2100. raise Exception("Unexpected FST-EVENT-PEER data (STA): " + ev)
  2101. def fst_setup_req(dev, hglobal, freq, dst, req, stie, mbie="", no_wait=False):
  2102. act = req + stie + mbie
  2103. dev.request("MGMT_TX %s %s freq=%d action=%s" % (dst, dst, freq, act))
  2104. ev = dev.wait_event(['MGMT-TX-STATUS'], timeout=5)
  2105. if ev is None or "result=SUCCESS" not in ev:
  2106. raise Exception("FST Action frame not ACKed")
  2107. if no_wait:
  2108. return
  2109. while True:
  2110. ev = hglobal.wait_event(['FST-EVENT-SESSION'], timeout=5)
  2111. if ev is None:
  2112. raise Exception("No FST-EVENT-SESSION (AP)")
  2113. if "new_state=SETUP_COMPLETION" in ev:
  2114. break
  2115. def fst_start_and_connect(apdev, group, sgroup):
  2116. hglobal = hostapd.HostapdGlobal()
  2117. if "OK" not in hglobal.request("FST-MANAGER TEST_REQUEST IS_SUPPORTED"):
  2118. raise HwsimSkip("No FST testing support")
  2119. params = { "ssid": "fst_11a", "hw_mode": "a", "channel": "36",
  2120. "country_code": "US" }
  2121. hapd = hostapd.add_ap(apdev[0], params)
  2122. fst_attach_ap(hglobal, apdev[0]['ifname'], group)
  2123. cmd = "FST-ATTACH %s %s" % (apdev[0]['ifname'], group)
  2124. if "FAIL" not in hglobal.request(cmd):
  2125. raise Exception("Duplicated FST-ATTACH (AP) accepted")
  2126. params = { "ssid": "fst_11g", "hw_mode": "g", "channel": "1",
  2127. "country_code": "US" }
  2128. hapd2 = hostapd.add_ap(apdev[1], params)
  2129. fst_attach_ap(hglobal, apdev[1]['ifname'], group)
  2130. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  2131. wpas.interface_add("wlan5")
  2132. fst_attach_sta(wpas, wpas.ifname, sgroup)
  2133. wpas.interface_add("wlan6", set_ifname=False)
  2134. wpas2 = WpaSupplicant(ifname="wlan6")
  2135. fst_attach_sta(wpas, wpas2.ifname, sgroup)
  2136. wpas.connect("fst_11a", key_mgmt="NONE", scan_freq="5180",
  2137. wait_connect=False)
  2138. wpas.wait_connected()
  2139. fst_wait_event_peer_sta(wpas, "connected", wpas.ifname, apdev[0]['bssid'])
  2140. fst_wait_event_peer_ap(hglobal, "connected", apdev[0]['ifname'],
  2141. wpas.own_addr())
  2142. wpas2.connect("fst_11g", key_mgmt="NONE", scan_freq="2412",
  2143. wait_connect=False)
  2144. wpas2.wait_connected()
  2145. fst_wait_event_peer_sta(wpas, "connected", wpas2.ifname, apdev[1]['bssid'])
  2146. fst_wait_event_peer_ap(hglobal, "connected", apdev[1]['ifname'],
  2147. wpas2.own_addr())
  2148. return hglobal, wpas, wpas2, hapd, hapd2
  2149. def test_fst_test_setup(dev, apdev, test_params):
  2150. """FST setup using separate commands"""
  2151. try:
  2152. _test_fst_test_setup(dev, apdev, test_params)
  2153. finally:
  2154. subprocess.call(['iw', 'reg', 'set', '00'])
  2155. dev[0].flush_scan_cache()
  2156. dev[1].flush_scan_cache()
  2157. def _test_fst_test_setup(dev, apdev, test_params):
  2158. group = "fstg0b"
  2159. sgroup = "fstg1b"
  2160. hglobal, wpas, wpas2, hapd, hapd2 = fst_start_and_connect(apdev, group, sgroup)
  2161. sid = wpas.global_request("FST-MANAGER SESSION_ADD " + sgroup).strip()
  2162. if "FAIL" in sid:
  2163. raise Exception("FST-MANAGER SESSION_ADD (STA) failed")
  2164. fst_session_set(wpas, sid, "old_ifname", wpas.ifname)
  2165. fst_session_set(wpas, sid, "old_peer_addr", apdev[0]['bssid'])
  2166. fst_session_set(wpas, sid, "new_ifname", wpas2.ifname)
  2167. fst_session_set(wpas, sid, "new_peer_addr", apdev[1]['bssid'])
  2168. if "OK" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
  2169. raise Exception("FST-MANAGER SESSION_INITIATE failed")
  2170. while True:
  2171. ev = hglobal.wait_event(['FST-EVENT-SESSION'], timeout=5)
  2172. if ev is None:
  2173. raise Exception("No FST-EVENT-SESSION (AP)")
  2174. if "new_state=SETUP_COMPLETION" in ev:
  2175. f = re.search("session_id=(\d+)", ev)
  2176. if f is None:
  2177. raise Exception("No session_id in FST-EVENT-SESSION")
  2178. sid_ap = f.group(1)
  2179. cmd = "FST-MANAGER SESSION_RESPOND %s accept" % sid_ap
  2180. if "OK" not in hglobal.request(cmd):
  2181. raise Exception("FST-MANAGER SESSION_RESPOND failed on AP")
  2182. break
  2183. ev = wpas.wait_global_event(["FST-EVENT-SESSION"], timeout=5)
  2184. if ev is None:
  2185. raise Exception("No FST-EVENT-SESSION")
  2186. if "new_state=SETUP_COMPLETION" not in ev:
  2187. raise Exception("Unexpected FST-EVENT-SESSION data: " + ev)
  2188. ev = wpas.wait_global_event(["FST-EVENT-SESSION"], timeout=5)
  2189. if ev is None:
  2190. raise Exception("No FST-EVENT-SESSION")
  2191. if "event_type=EVENT_FST_ESTABLISHED" not in ev:
  2192. raise Exception("Unexpected FST-EVENT-SESSION data: " + ev)
  2193. cmd = "FST-MANAGER SESSION_REMOVE " + sid
  2194. if "OK" not in wpas.global_request(cmd):
  2195. raise Exception("FST-MANAGER SESSION_REMOVE failed")
  2196. ev = wpas.wait_global_event(["FST-EVENT-SESSION"], timeout=5)
  2197. if ev is None:
  2198. raise Exception("No FST-EVENT-SESSION")
  2199. if "new_state=INITIAL" not in ev:
  2200. raise Exception("Unexpected FST-EVENT-SESSION data (STA): " + ev)
  2201. ev = hglobal.wait_event(['FST-EVENT-SESSION'], timeout=5)
  2202. if ev is None:
  2203. raise Exception("No FST-EVENT-SESSION (AP)")
  2204. if "new_state=INITIAL" not in ev:
  2205. raise Exception("Unexpected FST-EVENT-SESSION data (AP): " + ev)
  2206. if "FAIL" not in wpas.global_request(cmd):
  2207. raise Exception("Duplicated FST-MANAGER SESSION_REMOVE accepted")
  2208. hglobal.request("FST-MANAGER SESSION_REMOVE " + sid_ap)
  2209. wpas.request("DISCONNECT")
  2210. wpas.wait_disconnected()
  2211. fst_wait_event_peer_sta(wpas, "disconnected", wpas.ifname,
  2212. apdev[0]['bssid'])
  2213. fst_wait_event_peer_ap(hglobal, "disconnected", apdev[0]['ifname'],
  2214. wpas.own_addr())
  2215. wpas2.request("DISCONNECT")
  2216. wpas2.wait_disconnected()
  2217. fst_wait_event_peer_sta(wpas, "disconnected", wpas2.ifname,
  2218. apdev[1]['bssid'])
  2219. fst_wait_event_peer_ap(hglobal, "disconnected", apdev[1]['ifname'],
  2220. wpas2.own_addr())
  2221. fst_detach_ap(hglobal, apdev[0]['ifname'], group)
  2222. if "FAIL" not in hglobal.request("FST-DETACH " + apdev[0]['ifname']):
  2223. raise Exception("Duplicated FST-DETACH (AP) accepted")
  2224. hapd.disable()
  2225. fst_detach_ap(hglobal, apdev[1]['ifname'], group)
  2226. hapd2.disable()
  2227. fst_detach_sta(wpas, wpas.ifname, sgroup)
  2228. fst_detach_sta(wpas, wpas2.ifname, sgroup)
  2229. def test_fst_setup_mbie_diff(dev, apdev, test_params):
  2230. """FST setup and different MBIE in FST Setup Request"""
  2231. try:
  2232. _test_fst_setup_mbie_diff(dev, apdev, test_params)
  2233. finally:
  2234. subprocess.call(['iw', 'reg', 'set', '00'])
  2235. dev[0].flush_scan_cache()
  2236. dev[1].flush_scan_cache()
  2237. def _test_fst_setup_mbie_diff(dev, apdev, test_params):
  2238. group = "fstg0c"
  2239. sgroup = "fstg1c"
  2240. hglobal, wpas, wpas2, hapd, hapd2 = fst_start_and_connect(apdev, group, sgroup)
  2241. # FST Setup Request: Category, FST Action, Dialog Token (non-zero),
  2242. # LLT (32 bits, see 10.32), Session Transition (see 8.4.2.147),
  2243. # Multi-band element (optional, see 8.4.2.140)
  2244. # Session Transition: EID, Len, FSTS ID(4), Session Control,
  2245. # New Band (Band ID, Setup, Operation), Old Band (Band ID, Setup, Operation)
  2246. # Multi-band element: EID, Len, Multi-band Control, Band ID,
  2247. # Operating Class, Channel Number, BSSID (6), Beacon Interval (2),
  2248. # TSF Offset (8), Multi-band Connection Capability, FSTSessionTimeOut,
  2249. # STA MAC Address (6, optional), Pairwise Cipher Suite Count (2, optional),
  2250. # Pairwise Cipher Suite List (4xm, optional)
  2251. # MBIE with the non-matching STA MAC Address:
  2252. req = "1200011a060000"
  2253. stie = "a40b0100000000020001040001"
  2254. mbie = "9e1c0c0200010200000004000000000000000000000000ff0200000006ff"
  2255. fst_setup_req(wpas, hglobal, 5180, apdev[0]['bssid'], req, stie, mbie)
  2256. # MBIE without the STA MAC Address:
  2257. req = "1200011a060000"
  2258. stie = "a40b0100000000020001040001"
  2259. mbie = "9e16040200010200000004000000000000000000000000ff"
  2260. fst_setup_req(wpas, hglobal, 5180, apdev[0]['bssid'], req, stie, mbie)
  2261. # MBIE with unsupported STA Role:
  2262. req = "1200011a060000"
  2263. stie = "a40b0100000000020001040001"
  2264. mbie = "9e16070200010200000004000000000000000000000000ff"
  2265. fst_setup_req(wpas, hglobal, 5180, apdev[0]['bssid'], req, stie, mbie)
  2266. # MBIE with unsupported Band ID:
  2267. req = "1200011a060000"
  2268. stie = "a40b0100000000020001040001"
  2269. mbie = "9e1604ff00010200000004000000000000000000000000ff"
  2270. fst_setup_req(wpas, hglobal, 5180, apdev[0]['bssid'], req, stie, mbie)
  2271. # FST Setup Request without MBIE (different FSTS ID):
  2272. req = "1200011a060000"
  2273. stie = "a40b0200000000020001040001"
  2274. fst_setup_req(wpas, hglobal, 5180, apdev[0]['bssid'], req, stie)
  2275. # MBIE update OOM on AP
  2276. req = "1200011a060000"
  2277. stie = "a40b0100000000020001040001"
  2278. mbie = "9e16040200010200000004000000000000000000000000ff"
  2279. try:
  2280. with alloc_fail(hapd, 1, "mb_ies_by_info"):
  2281. fst_setup_req(wpas, hglobal, 5180, apdev[0]['bssid'], req, stie,
  2282. mbie, no_wait=True)
  2283. except HwsimSkip, e:
  2284. # Skip exception to allow proper cleanup
  2285. pass
  2286. # Remove sessions to avoid causing issues to following test ases
  2287. s = hglobal.request("FST-MANAGER LIST_SESSIONS " + group)
  2288. if not s.startswith("FAIL"):
  2289. for sid in s.split(' '):
  2290. if len(sid):
  2291. hglobal.request("FST-MANAGER SESSION_REMOVE " + sid)
  2292. def test_fst_many_setup(dev, apdev, test_params):
  2293. """FST setup multiple times"""
  2294. try:
  2295. _test_fst_many_setup(dev, apdev, test_params)
  2296. finally:
  2297. subprocess.call(['iw', 'reg', 'set', '00'])
  2298. dev[0].flush_scan_cache()
  2299. dev[1].flush_scan_cache()
  2300. def _test_fst_many_setup(dev, apdev, test_params):
  2301. group = "fstg0d"
  2302. sgroup = "fstg1d"
  2303. hglobal, wpas, wpas2, hapd, hapd2 = fst_start_and_connect(apdev, group, sgroup)
  2304. sid = wpas.global_request("FST-MANAGER SESSION_ADD " + sgroup).strip()
  2305. if "FAIL" in sid:
  2306. raise Exception("FST-MANAGER SESSION_ADD (STA) failed")
  2307. fst_session_set(wpas, sid, "old_ifname", wpas.ifname)
  2308. fst_session_set(wpas, sid, "old_peer_addr", apdev[0]['bssid'])
  2309. fst_session_set(wpas, sid, "new_ifname", wpas2.ifname)
  2310. fst_session_set(wpas, sid, "new_peer_addr", apdev[1]['bssid'])
  2311. for i in range(257):
  2312. if "OK" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
  2313. raise Exception("FST-MANAGER SESSION_INITIATE failed")
  2314. while True:
  2315. ev = hglobal.wait_event(['FST-EVENT-SESSION'], timeout=5)
  2316. if ev is None:
  2317. raise Exception("No FST-EVENT-SESSION (AP)")
  2318. if "new_state=SETUP_COMPLETION" in ev:
  2319. f = re.search("session_id=(\d+)", ev)
  2320. if f is None:
  2321. raise Exception("No session_id in FST-EVENT-SESSION")
  2322. sid_ap = f.group(1)
  2323. cmd = "FST-MANAGER SESSION_RESPOND %s accept" % sid_ap
  2324. if "OK" not in hglobal.request(cmd):
  2325. raise Exception("FST-MANAGER SESSION_RESPOND failed on AP")
  2326. break
  2327. ev = wpas.wait_global_event(["FST-EVENT-SESSION"], timeout=5)
  2328. if ev is None:
  2329. raise Exception("No FST-EVENT-SESSION (STA)")
  2330. if "new_state=SETUP_COMPLETION" not in ev:
  2331. raise Exception("Unexpected FST-EVENT-SESSION data: " + ev)
  2332. ev = wpas.wait_global_event(["FST-EVENT-SESSION"], timeout=5)
  2333. if ev is None:
  2334. raise Exception("No FST-EVENT-SESSION (STA)")
  2335. if "event_type=EVENT_FST_ESTABLISHED" not in ev:
  2336. raise Exception("Unexpected FST-EVENT-SESSION data: " + ev)
  2337. if "OK" not in wpas.global_request("FST-MANAGER SESSION_TEARDOWN " + sid):
  2338. raise Exception("FST-MANAGER SESSION_INITIATE failed")
  2339. if i == 0:
  2340. if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_TEARDOWN " + sid):
  2341. raise Exception("Duplicate FST-MANAGER SESSION_TEARDOWN accepted")
  2342. ev = wpas.wait_global_event(["FST-EVENT-SESSION"], timeout=5)
  2343. if ev is None:
  2344. raise Exception("No FST-EVENT-SESSION (STA teardown -->initial)")
  2345. if "new_state=INITIAL" not in ev:
  2346. raise Exception("Unexpected FST-EVENT-SESSION data (STA): " + ev)
  2347. ev = hglobal.wait_event(['FST-EVENT-SESSION'], timeout=5)
  2348. if ev is None:
  2349. raise Exception("No FST-EVENT-SESSION (AP teardown -->initial)")
  2350. if "new_state=INITIAL" not in ev:
  2351. raise Exception("Unexpected FST-EVENT-SESSION data (AP): " + ev)
  2352. if "OK" not in hglobal.request("FST-MANAGER SESSION_REMOVE " + sid_ap):
  2353. raise Exception("FST-MANAGER SESSION_REMOVE (AP) failed")
  2354. if "OK" not in wpas.global_request("FST-MANAGER SESSION_REMOVE " + sid):
  2355. raise Exception("FST-MANAGER SESSION_REMOVE failed")
  2356. wpas.request("DISCONNECT")
  2357. wpas.wait_disconnected()
  2358. fst_wait_event_peer_sta(wpas, "disconnected", wpas.ifname,
  2359. apdev[0]['bssid'])
  2360. fst_wait_event_peer_ap(hglobal, "disconnected", apdev[0]['ifname'],
  2361. wpas.own_addr())
  2362. wpas2.request("DISCONNECT")
  2363. wpas2.wait_disconnected()
  2364. fst_wait_event_peer_sta(wpas, "disconnected", wpas2.ifname,
  2365. apdev[1]['bssid'])
  2366. fst_wait_event_peer_ap(hglobal, "disconnected", apdev[1]['ifname'],
  2367. wpas2.own_addr())
  2368. fst_detach_ap(hglobal, apdev[0]['ifname'], group)
  2369. fst_detach_ap(hglobal, apdev[1]['ifname'], group)
  2370. hapd.disable()
  2371. hapd2.disable()
  2372. fst_detach_sta(wpas, wpas.ifname, sgroup)
  2373. fst_detach_sta(wpas, wpas2.ifname, sgroup)
  2374. def test_fst_attach_wpas_error(dev, apdev, test_params):
  2375. """FST attach errors in wpa_supplicant"""
  2376. if "OK" not in dev[0].global_request("FST-MANAGER TEST_REQUEST IS_SUPPORTED"):
  2377. raise HwsimSkip("No FST testing support")
  2378. group = "fstg0"
  2379. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  2380. wpas.interface_add("wlan5")
  2381. fst_attach_sta(wpas, wpas.ifname, group)
  2382. if "FAIL" not in wpas.global_request("FST-ATTACH %s %s" % (wpas.ifname,
  2383. group)):
  2384. raise Exception("Duplicated FST-ATTACH accepted")
  2385. if "FAIL" not in wpas.global_request("FST-ATTACH %s %s" % ("foofoo",
  2386. group)):
  2387. raise Exception("FST-ATTACH for unknown interface accepted")
  2388. def test_fst_session_initiate_errors(dev, apdev, test_params):
  2389. """FST SESSION_INITIATE error cases"""
  2390. try:
  2391. _test_fst_session_initiate_errors(dev, apdev, test_params)
  2392. finally:
  2393. subprocess.call(['iw', 'reg', 'set', '00'])
  2394. dev[0].flush_scan_cache()
  2395. dev[1].flush_scan_cache()
  2396. def _test_fst_session_initiate_errors(dev, apdev, test_params):
  2397. group = "fstg0"
  2398. sgroup = "fstg1"
  2399. hglobal, wpas, wpas2, hapd, hapd2 = fst_start_and_connect(apdev, group, sgroup)
  2400. sid = wpas.global_request("FST-MANAGER SESSION_ADD " + sgroup).strip()
  2401. if "FAIL" in sid:
  2402. raise Exception("FST-MANAGER SESSION_ADD (STA) failed")
  2403. # No old peer MAC address
  2404. if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
  2405. raise Exception("Invalid FST-MANAGER SESSION_INITIATE accepted")
  2406. fst_session_set(wpas, sid, "old_peer_addr", "00:ff:ff:ff:ff:ff")
  2407. # No new peer MAC address
  2408. if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
  2409. raise Exception("Invalid FST-MANAGER SESSION_INITIATE accepted")
  2410. fst_session_set(wpas, sid, "new_peer_addr", "00:ff:ff:ff:ff:fe")
  2411. # No old interface defined
  2412. if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
  2413. raise Exception("Invalid FST-MANAGER SESSION_INITIATE accepted")
  2414. fst_session_set(wpas, sid, "old_ifname", wpas.ifname)
  2415. # No new interface defined
  2416. if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
  2417. raise Exception("Invalid FST-MANAGER SESSION_INITIATE accepted")
  2418. fst_session_set(wpas, sid, "new_ifname", wpas.ifname)
  2419. # Same interface set as old and new
  2420. if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
  2421. raise Exception("Invalid FST-MANAGER SESSION_INITIATE accepted")
  2422. fst_session_set(wpas, sid, "new_ifname", wpas2.ifname)
  2423. # The preset old peer address is not connected
  2424. if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
  2425. raise Exception("Invalid FST-MANAGER SESSION_INITIATE accepted")
  2426. fst_session_set(wpas, sid, "old_peer_addr", apdev[0]['bssid'])
  2427. # The preset new peer address is not connected
  2428. if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
  2429. raise Exception("Invalid FST-MANAGER SESSION_INITIATE accepted")
  2430. fst_session_set(wpas, sid, "new_peer_addr", apdev[1]['bssid'])
  2431. # Initiate session setup
  2432. if "OK" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
  2433. raise Exception("FST-MANAGER SESSION_INITIATE failed")
  2434. # Session in progress
  2435. if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
  2436. raise Exception("Duplicated FST-MANAGER SESSION_INITIATE accepted")
  2437. sid2 = wpas.global_request("FST-MANAGER SESSION_ADD " + sgroup).strip()
  2438. if "FAIL" in sid:
  2439. raise Exception("FST-MANAGER SESSION_ADD (STA) failed")
  2440. fst_session_set(wpas, sid2, "old_ifname", wpas.ifname)
  2441. fst_session_set(wpas, sid2, "old_peer_addr", apdev[0]['bssid'])
  2442. fst_session_set(wpas, sid2, "new_ifname", wpas2.ifname)
  2443. fst_session_set(wpas, sid2, "new_peer_addr", apdev[1]['bssid'])
  2444. # There is another session in progress (old)
  2445. if "FAIL" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid2):
  2446. raise Exception("Duplicated FST-MANAGER SESSION_INITIATE accepted")
  2447. if "OK" not in wpas.global_request("FST-MANAGER SESSION_REMOVE " + sid):
  2448. raise Exception("FST-MANAGER SESSION_REMOVE failed")
  2449. while True:
  2450. ev = hglobal.wait_event(['FST-EVENT-SESSION'], timeout=5)
  2451. if ev is None:
  2452. raise Exception("No FST-EVENT-SESSION (AP)")
  2453. if "new_state=SETUP_COMPLETION" in ev:
  2454. f = re.search("session_id=(\d+)", ev)
  2455. if f is None:
  2456. raise Exception("No session_id in FST-EVENT-SESSION")
  2457. sid_ap = f.group(1)
  2458. break
  2459. if "OK" not in hglobal.request("FST-MANAGER SESSION_REMOVE " + sid_ap):
  2460. raise Exception("FST-MANAGER SESSION_REMOVE (AP) failed")
  2461. if "OK" not in wpas.global_request("FST-MANAGER SESSION_REMOVE " + sid2):
  2462. raise Exception("FST-MANAGER SESSION_REMOVE failed")
  2463. def test_fst_session_respond_errors(dev, apdev, test_params):
  2464. """FST SESSION_RESPOND error cases"""
  2465. try:
  2466. _test_fst_session_respond_errors(dev, apdev, test_params)
  2467. finally:
  2468. subprocess.call(['iw', 'reg', 'set', '00'])
  2469. dev[0].flush_scan_cache()
  2470. dev[1].flush_scan_cache()
  2471. def _test_fst_session_respond_errors(dev, apdev, test_params):
  2472. group = "fstg0b"
  2473. sgroup = "fstg1b"
  2474. hglobal, wpas, wpas2, hapd, hapd2 = fst_start_and_connect(apdev, group, sgroup)
  2475. sid = wpas.global_request("FST-MANAGER SESSION_ADD " + sgroup).strip()
  2476. if "FAIL" in sid:
  2477. raise Exception("FST-MANAGER SESSION_ADD (STA) failed")
  2478. fst_session_set(wpas, sid, "old_ifname", wpas.ifname)
  2479. fst_session_set(wpas, sid, "old_peer_addr", apdev[0]['bssid'])
  2480. fst_session_set(wpas, sid, "new_ifname", wpas2.ifname)
  2481. fst_session_set(wpas, sid, "new_peer_addr", apdev[1]['bssid'])
  2482. if "OK" not in wpas.global_request("FST-MANAGER SESSION_INITIATE " + sid):
  2483. raise Exception("FST-MANAGER SESSION_INITIATE failed")
  2484. while True:
  2485. ev = hglobal.wait_event(['FST-EVENT-SESSION'], timeout=5)
  2486. if ev is None:
  2487. raise Exception("No FST-EVENT-SESSION (AP)")
  2488. if "new_state=SETUP_COMPLETION" in ev:
  2489. f = re.search("session_id=(\d+)", ev)
  2490. if f is None:
  2491. raise Exception("No session_id in FST-EVENT-SESSION")
  2492. sid_ap = f.group(1)
  2493. break
  2494. # The preset peer address is not in the peer list
  2495. fst_session_set_ap(hglobal, sid_ap, "old_peer_addr", "00:00:00:00:00:01")
  2496. cmd = "FST-MANAGER SESSION_RESPOND %s accept" % sid_ap
  2497. if "FAIL" not in hglobal.request(cmd):
  2498. raise Exception("Invalid FST-MANAGER SESSION_RESPOND accepted")
  2499. # Same interface set as old and new
  2500. fst_session_set_ap(hglobal, sid_ap, "old_peer_addr", wpas.own_addr())
  2501. fst_session_set_ap(hglobal, sid_ap, "old_ifname", apdev[1]['ifname'])
  2502. cmd = "FST-MANAGER SESSION_RESPOND %s accept" % sid_ap
  2503. if "FAIL" not in hglobal.request(cmd):
  2504. raise Exception("Invalid FST-MANAGER SESSION_RESPOND accepted")
  2505. # valid command
  2506. fst_session_set_ap(hglobal, sid_ap, "old_ifname", apdev[0]['ifname'])
  2507. cmd = "FST-MANAGER SESSION_RESPOND %s accept" % sid_ap
  2508. if "OK" not in hglobal.request(cmd):
  2509. raise Exception("FST-MANAGER SESSION_RESPOND failed")
  2510. # incorrect state
  2511. cmd = "FST-MANAGER SESSION_RESPOND %s accept" % sid_ap
  2512. if "FAIL" not in hglobal.request(cmd):
  2513. raise Exception("Invalid FST-MANAGER SESSION_RESPOND accepted")
  2514. cmd = "FST-MANAGER SESSION_REMOVE " + sid
  2515. if "OK" not in wpas.global_request(cmd):
  2516. raise Exception("FST-MANAGER SESSION_REMOVE (STA) failed")
  2517. cmd = "FST-MANAGER SESSION_REMOVE %s" % sid_ap
  2518. if "OK" not in hglobal.request(cmd):
  2519. raise Exception("FST-MANAGER SESSION_REMOVE (AP) failed")