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