test_ap_track.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. # Test cases for hostapd tracking unconnected stations
  2. # Copyright (c) 2015, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import logging
  7. logger = logging.getLogger()
  8. import subprocess
  9. import time
  10. import hostapd
  11. from wpasupplicant import WpaSupplicant
  12. def test_ap_track_sta(dev, apdev):
  13. """Dualband AP tracking unconnected stations"""
  14. try:
  15. _test_ap_track_sta(dev, apdev)
  16. finally:
  17. subprocess.call(['iw', 'reg', 'set', '00'])
  18. def _test_ap_track_sta(dev, apdev):
  19. params = { "ssid": "track",
  20. "country_code": "US",
  21. "hw_mode": "g",
  22. "channel": "6",
  23. "track_sta_max_num": "2" }
  24. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  25. bssid = apdev[0]['bssid']
  26. params = { "ssid": "track",
  27. "country_code": "US",
  28. "hw_mode": "a",
  29. "channel": "40",
  30. "track_sta_max_num": "100",
  31. "track_sta_max_age": "1" }
  32. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  33. bssid2 = apdev[1]['bssid']
  34. for i in range(2):
  35. dev[0].scan_for_bss(bssid, freq=2437, force_scan=True)
  36. dev[0].scan_for_bss(bssid2, freq=5200, force_scan=True)
  37. dev[1].scan_for_bss(bssid, freq=2437, force_scan=True)
  38. dev[2].scan_for_bss(bssid2, freq=5200, force_scan=True)
  39. addr0 = dev[0].own_addr()
  40. addr1 = dev[1].own_addr()
  41. addr2 = dev[2].own_addr()
  42. track = hapd.request("TRACK_STA_LIST")
  43. if addr0 not in track or addr1 not in track:
  44. raise Exception("Station missing from 2.4 GHz tracking")
  45. if addr2 in track:
  46. raise Exception("Unexpected station included in 2.4 GHz tracking")
  47. track = hapd2.request("TRACK_STA_LIST")
  48. if addr0 not in track or addr2 not in track:
  49. raise Exception("Station missing from 5 GHz tracking")
  50. if addr1 in track:
  51. raise Exception("Unexpected station included in 5 GHz tracking")
  52. # Test expiration
  53. time.sleep(1.1)
  54. track = hapd.request("TRACK_STA_LIST")
  55. if addr0 not in track or addr1 not in track:
  56. raise Exception("Station missing from 2.4 GHz tracking (expiration)")
  57. track = hapd2.request("TRACK_STA_LIST")
  58. if addr0 in track or addr2 in track:
  59. raise Exception("Station not expired from 5 GHz tracking")
  60. # Test maximum list length
  61. dev[0].scan_for_bss(bssid, freq=2437, force_scan=True)
  62. dev[1].scan_for_bss(bssid, freq=2437, force_scan=True)
  63. dev[2].scan_for_bss(bssid, freq=2437, force_scan=True)
  64. track = hapd.request("TRACK_STA_LIST")
  65. if len(track.splitlines()) != 2:
  66. raise Exception("Unexpected number of entries: %d" % len(track.splitlines()))
  67. if addr1 not in track or addr2 not in track:
  68. raise Exception("Station missing from 2.4 GHz tracking (max limit)")
  69. def test_ap_track_sta_no_probe_resp(dev, apdev):
  70. """Dualband AP not replying to probes from dualband STA on 2.4 GHz"""
  71. try:
  72. _test_ap_track_sta_no_probe_resp(dev, apdev)
  73. finally:
  74. subprocess.call(['iw', 'reg', 'set', '00'])
  75. def _test_ap_track_sta_no_probe_resp(dev, apdev):
  76. dev[0].flush_scan_cache()
  77. params = { "ssid": "track",
  78. "country_code": "US",
  79. "hw_mode": "g",
  80. "channel": "6",
  81. "beacon_int": "10000",
  82. "no_probe_resp_if_seen_on": apdev[1]['ifname'] }
  83. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  84. bssid = apdev[0]['bssid']
  85. params = { "ssid": "track",
  86. "country_code": "US",
  87. "hw_mode": "a",
  88. "channel": "40",
  89. "track_sta_max_num": "100" }
  90. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  91. bssid2 = apdev[1]['bssid']
  92. dev[0].scan_for_bss(bssid2, freq=5200, force_scan=True)
  93. dev[1].scan_for_bss(bssid, freq=2437, force_scan=True)
  94. dev[0].scan(freq=2437, type="ONLY")
  95. dev[0].scan(freq=2437, type="ONLY")
  96. if dev[0].get_bss(bssid):
  97. raise Exception("2.4 GHz AP found unexpectedly")
  98. def test_ap_track_sta_no_auth(dev, apdev):
  99. """Dualband AP rejecting authentication from dualband STA on 2.4 GHz"""
  100. try:
  101. _test_ap_track_sta_no_auth(dev, apdev)
  102. finally:
  103. subprocess.call(['iw', 'reg', 'set', '00'])
  104. def _test_ap_track_sta_no_auth(dev, apdev):
  105. params = { "ssid": "track",
  106. "country_code": "US",
  107. "hw_mode": "g",
  108. "channel": "6",
  109. "track_sta_max_num": "100",
  110. "no_auth_if_seen_on": apdev[1]['ifname'] }
  111. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  112. bssid = apdev[0]['bssid']
  113. params = { "ssid": "track",
  114. "country_code": "US",
  115. "hw_mode": "a",
  116. "channel": "40",
  117. "track_sta_max_num": "100" }
  118. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  119. bssid2 = apdev[1]['bssid']
  120. dev[0].scan_for_bss(bssid, freq=2437, force_scan=True)
  121. dev[0].scan_for_bss(bssid2, freq=5200, force_scan=True)
  122. dev[1].scan_for_bss(bssid, freq=2437, force_scan=True)
  123. dev[1].connect("track", key_mgmt="NONE", scan_freq="2437")
  124. dev[0].connect("track", key_mgmt="NONE", scan_freq="2437",
  125. freq_list="2437", wait_connect=False)
  126. dev[1].request("DISCONNECT")
  127. ev = dev[0].wait_event([ "CTRL-EVENT-CONNECTED",
  128. "CTRL-EVENT-AUTH-REJECT" ], timeout=10)
  129. if ev is None:
  130. raise Exception("Unknown connection result")
  131. if "CTRL-EVENT-CONNECTED" in ev:
  132. raise Exception("Unexpected connection")
  133. if "status_code=82" not in ev:
  134. raise Exception("Unexpected rejection reason: " + ev)
  135. if "ie=34" not in ev:
  136. raise Exception("No Neighbor Report element: " + ev)
  137. dev[0].request("DISCONNECT")
  138. def test_ap_track_sta_force_5ghz(dev, apdev):
  139. """Dualband AP forcing dualband STA to connect on 5 GHz"""
  140. try:
  141. _test_ap_track_sta_force_5ghz(dev, apdev)
  142. finally:
  143. subprocess.call(['iw', 'reg', 'set', '00'])
  144. def _test_ap_track_sta_force_5ghz(dev, apdev):
  145. params = { "ssid": "track",
  146. "country_code": "US",
  147. "hw_mode": "g",
  148. "channel": "6",
  149. "no_probe_resp_if_seen_on": apdev[1]['ifname'],
  150. "no_auth_if_seen_on": apdev[1]['ifname'] }
  151. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  152. bssid = apdev[0]['bssid']
  153. params = { "ssid": "track",
  154. "country_code": "US",
  155. "hw_mode": "a",
  156. "channel": "40",
  157. "track_sta_max_num": "100" }
  158. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  159. bssid2 = apdev[1]['bssid']
  160. dev[0].scan_for_bss(bssid, freq=2437, force_scan=True)
  161. dev[0].scan_for_bss(bssid2, freq=5200, force_scan=True)
  162. dev[0].connect("track", key_mgmt="NONE", scan_freq="2437 5200")
  163. freq = dev[0].get_status_field('freq')
  164. if freq != '5200':
  165. raise Exception("Unexpected operating channel")
  166. dev[0].request("DISCONNECT")
  167. def test_ap_track_sta_force_2ghz(dev, apdev):
  168. """Dualband AP forcing dualband STA to connect on 2.4 GHz"""
  169. try:
  170. _test_ap_track_sta_force_2ghz(dev, apdev)
  171. finally:
  172. subprocess.call(['iw', 'reg', 'set', '00'])
  173. def _test_ap_track_sta_force_2ghz(dev, apdev):
  174. params = { "ssid": "track",
  175. "country_code": "US",
  176. "hw_mode": "g",
  177. "channel": "6",
  178. "track_sta_max_num": "100" }
  179. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  180. bssid = apdev[0]['bssid']
  181. params = { "ssid": "track",
  182. "country_code": "US",
  183. "hw_mode": "a",
  184. "channel": "40",
  185. "no_probe_resp_if_seen_on": apdev[0]['ifname'],
  186. "no_auth_if_seen_on": apdev[0]['ifname'] }
  187. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  188. bssid2 = apdev[1]['bssid']
  189. dev[0].scan_for_bss(bssid2, freq=5200, force_scan=True)
  190. dev[0].scan_for_bss(bssid, freq=2437, force_scan=True)
  191. dev[0].connect("track", key_mgmt="NONE", scan_freq="2437 5200")
  192. freq = dev[0].get_status_field('freq')
  193. if freq != '2437':
  194. raise Exception("Unexpected operating channel")
  195. dev[0].request("DISCONNECT")