test_ap_hs20.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/python
  2. #
  3. # Hotspot 2.0 tests
  4. # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import time
  9. import subprocess
  10. import logging
  11. logger = logging.getLogger(__name__)
  12. import hostapd
  13. def hs20_ap_params():
  14. params = hostapd.wpa2_params(ssid="test-hs20")
  15. params['wpa_key_mgmt'] = "WPA-EAP"
  16. params['ieee80211w'] = "1"
  17. params['ieee8021x'] = "1"
  18. params['auth_server_addr'] = "127.0.0.1"
  19. params['auth_server_port'] = "1812"
  20. params['auth_server_shared_secret'] = "radius"
  21. params['interworking'] = "1"
  22. params['access_network_type'] = "14"
  23. params['internet'] = "1"
  24. params['asra'] = "0"
  25. params['esr'] = "0"
  26. params['uesa'] = "0"
  27. params['venue_group'] = "7"
  28. params['venue_type'] = "1"
  29. params['venue_name'] = [ "eng:Example venue", "fin:Esimerkkipaikka" ]
  30. params['roaming_consortium'] = [ "112233", "1020304050", "010203040506",
  31. "fedcba" ]
  32. params['domain_name'] = "example.com,another.example.com"
  33. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]",
  34. "0,another.example.com" ]
  35. params['hs20'] = "1"
  36. params['hs20_wan_metrics'] = "01:8000:1000:80:240:3000"
  37. params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0" ]
  38. params['hs20_operating_class'] = "5173"
  39. params['anqp_3gpp_cell_net'] = "244,91"
  40. return params
  41. def test_ap_hs20_select(dev, apdev):
  42. """Hotspot 2.0 network selection"""
  43. bssid = apdev[0]['bssid']
  44. params = hs20_ap_params()
  45. params['hessid'] = bssid
  46. hostapd.add_ap(apdev[0]['ifname'], params)
  47. dev[0].request("SET interworking 1")
  48. dev[0].request("SET hs20 1")
  49. id = dev[0].add_cred()
  50. dev[0].set_cred_quoted(id, "realm", "example.com");
  51. dev[0].set_cred_quoted(id, "username", "test");
  52. dev[0].set_cred_quoted(id, "password", "secret");
  53. dev[0].set_cred_quoted(id, "domain", "example.com");
  54. dev[0].dump_monitor()
  55. dev[0].request("INTERWORKING_SELECT")
  56. ev = dev[0].wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
  57. timeout=15)
  58. if ev is None:
  59. raise Exception("Network selection timed out");
  60. if "INTERWORKING-NO-MATCH" in ev:
  61. raise Exception("Matching network not found")
  62. if bssid not in ev:
  63. raise Exception("Unexpected BSSID in match")
  64. if "type=home" not in ev:
  65. raise Exception("Home network not recognized")
  66. dev[0].set_cred_quoted(id, "domain", "no.match.example.com");
  67. dev[0].dump_monitor()
  68. dev[0].request("INTERWORKING_SELECT")
  69. ev = dev[0].wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
  70. timeout=15)
  71. if ev is None:
  72. raise Exception("Network selection timed out");
  73. if "INTERWORKING-NO-MATCH" in ev:
  74. raise Exception("Matching network not found")
  75. if bssid not in ev:
  76. raise Exception("Unexpected BSSID in match")
  77. if "type=roaming" not in ev:
  78. raise Exception("Roaming network not recognized")
  79. dev[0].set_cred_quoted(id, "realm", "no.match.example.com");
  80. dev[0].dump_monitor()
  81. dev[0].request("INTERWORKING_SELECT")
  82. ev = dev[0].wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"],
  83. timeout=15)
  84. if ev is None:
  85. raise Exception("Network selection timed out");
  86. if "INTERWORKING-NO-MATCH" not in ev:
  87. raise Exception("Unexpected network match")