hs20.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Hotspot 2.0 AP ANQP processing
  3. * Copyright (c) 2009, Atheros Communications, Inc.
  4. * Copyright (c) 2011-2013, Qualcomm Atheros, Inc.
  5. *
  6. * This software may be distributed under the terms of the BSD license.
  7. * See README for more details.
  8. */
  9. #include "includes.h"
  10. #include "common.h"
  11. #include "common/ieee802_11_defs.h"
  12. #include "hostapd.h"
  13. #include "ap_config.h"
  14. #include "ap_drv_ops.h"
  15. #include "hs20.h"
  16. u8 * hostapd_eid_hs20_indication(struct hostapd_data *hapd, u8 *eid)
  17. {
  18. u8 conf;
  19. if (!hapd->conf->hs20)
  20. return eid;
  21. *eid++ = WLAN_EID_VENDOR_SPECIFIC;
  22. *eid++ = 7;
  23. WPA_PUT_BE24(eid, OUI_WFA);
  24. eid += 3;
  25. *eid++ = HS20_INDICATION_OUI_TYPE;
  26. conf = HS20_VERSION; /* Release Number */
  27. conf |= HS20_ANQP_DOMAIN_ID_PRESENT;
  28. if (hapd->conf->disable_dgaf)
  29. conf |= HS20_DGAF_DISABLED;
  30. *eid++ = conf;
  31. WPA_PUT_LE16(eid, hapd->conf->anqp_domain_id);
  32. eid += 2;
  33. return eid;
  34. }
  35. u8 * hostapd_eid_osen(struct hostapd_data *hapd, u8 *eid)
  36. {
  37. u8 *len;
  38. u16 capab;
  39. if (!hapd->conf->osen)
  40. return eid;
  41. *eid++ = WLAN_EID_VENDOR_SPECIFIC;
  42. len = eid++; /* to be filled */
  43. WPA_PUT_BE24(eid, OUI_WFA);
  44. eid += 3;
  45. *eid++ = HS20_OSEN_OUI_TYPE;
  46. /* Group Data Cipher Suite */
  47. RSN_SELECTOR_PUT(eid, RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED);
  48. eid += RSN_SELECTOR_LEN;
  49. /* Pairwise Cipher Suite Count and List */
  50. WPA_PUT_LE16(eid, 1);
  51. eid += 2;
  52. RSN_SELECTOR_PUT(eid, RSN_CIPHER_SUITE_CCMP);
  53. eid += RSN_SELECTOR_LEN;
  54. /* AKM Suite Count and List */
  55. WPA_PUT_LE16(eid, 1);
  56. eid += 2;
  57. RSN_SELECTOR_PUT(eid, RSN_AUTH_KEY_MGMT_OSEN);
  58. eid += RSN_SELECTOR_LEN;
  59. /* RSN Capabilities */
  60. capab = 0;
  61. if (hapd->conf->wmm_enabled) {
  62. /* 4 PTKSA replay counters when using WMM */
  63. capab |= (RSN_NUM_REPLAY_COUNTERS_16 << 2);
  64. }
  65. #ifdef CONFIG_IEEE80211W
  66. if (hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
  67. capab |= WPA_CAPABILITY_MFPC;
  68. if (hapd->conf->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED)
  69. capab |= WPA_CAPABILITY_MFPR;
  70. }
  71. #endif /* CONFIG_IEEE80211W */
  72. WPA_PUT_LE16(eid, capab);
  73. eid += 2;
  74. *len = eid - len - 1;
  75. return eid;
  76. }
  77. int hs20_send_wnm_notification(struct hostapd_data *hapd, const u8 *addr,
  78. u8 osu_method, const char *url)
  79. {
  80. struct wpabuf *buf;
  81. size_t len = 0;
  82. int ret;
  83. /* TODO: should refuse to send notification if the STA is not associated
  84. * or if the STA did not indicate support for WNM-Notification */
  85. if (url) {
  86. len = 1 + os_strlen(url);
  87. if (5 + len > 255) {
  88. wpa_printf(MSG_INFO, "HS 2.0: Too long URL for "
  89. "WNM-Notification: '%s'", url);
  90. return -1;
  91. }
  92. }
  93. buf = wpabuf_alloc(4 + 7 + len);
  94. if (buf == NULL)
  95. return -1;
  96. wpabuf_put_u8(buf, WLAN_ACTION_WNM);
  97. wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
  98. wpabuf_put_u8(buf, 1); /* Dialog token */
  99. wpabuf_put_u8(buf, 1); /* Type - 1 reserved for WFA */
  100. /* Subscription Remediation subelement */
  101. wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
  102. wpabuf_put_u8(buf, 5 + len);
  103. wpabuf_put_be24(buf, OUI_WFA);
  104. wpabuf_put_u8(buf, HS20_WNM_SUB_REM_NEEDED);
  105. if (url) {
  106. wpabuf_put_u8(buf, len - 1);
  107. wpabuf_put_data(buf, url, len - 1);
  108. wpabuf_put_u8(buf, osu_method);
  109. } else {
  110. /* Server URL and Server Method fields not included */
  111. wpabuf_put_u8(buf, 0);
  112. }
  113. ret = hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
  114. wpabuf_head(buf), wpabuf_len(buf));
  115. wpabuf_free(buf);
  116. return ret;
  117. }
  118. int hs20_send_wnm_notification_deauth_req(struct hostapd_data *hapd,
  119. const u8 *addr,
  120. const struct wpabuf *payload)
  121. {
  122. struct wpabuf *buf;
  123. int ret;
  124. /* TODO: should refuse to send notification if the STA is not associated
  125. * or if the STA did not indicate support for WNM-Notification */
  126. buf = wpabuf_alloc(4 + 6 + wpabuf_len(payload));
  127. if (buf == NULL)
  128. return -1;
  129. wpabuf_put_u8(buf, WLAN_ACTION_WNM);
  130. wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
  131. wpabuf_put_u8(buf, 1); /* Dialog token */
  132. wpabuf_put_u8(buf, 1); /* Type - 1 reserved for WFA */
  133. /* Deauthentication Imminent Notice subelement */
  134. wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
  135. wpabuf_put_u8(buf, 4 + wpabuf_len(payload));
  136. wpabuf_put_be24(buf, OUI_WFA);
  137. wpabuf_put_u8(buf, HS20_WNM_DEAUTH_IMMINENT_NOTICE);
  138. wpabuf_put_buf(buf, payload);
  139. ret = hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
  140. wpabuf_head(buf), wpabuf_len(buf));
  141. wpabuf_free(buf);
  142. return ret;
  143. }