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 4755 : u8 * hostapd_eid_hs20_indication(struct hostapd_data *hapd, u8 *eid)
21 : {
22 : u8 conf;
23 4755 : if (!hapd->conf->hs20)
24 4288 : return eid;
25 467 : *eid++ = WLAN_EID_VENDOR_SPECIFIC;
26 467 : *eid++ = 7;
27 467 : WPA_PUT_BE24(eid, OUI_WFA);
28 467 : eid += 3;
29 467 : *eid++ = HS20_INDICATION_OUI_TYPE;
30 467 : conf = HS20_VERSION; /* Release Number */
31 467 : conf |= HS20_ANQP_DOMAIN_ID_PRESENT;
32 467 : if (hapd->conf->disable_dgaf)
33 12 : conf |= HS20_DGAF_DISABLED;
34 467 : *eid++ = conf;
35 467 : WPA_PUT_LE16(eid, hapd->conf->anqp_domain_id);
36 467 : eid += 2;
37 :
38 467 : return eid;
39 : }
40 :
41 :
42 4755 : u8 * hostapd_eid_osen(struct hostapd_data *hapd, u8 *eid)
43 : {
44 : u8 *len;
45 : u16 capab;
46 :
47 4755 : if (!hapd->conf->osen)
48 4748 : return eid;
49 :
50 7 : *eid++ = WLAN_EID_VENDOR_SPECIFIC;
51 7 : len = eid++; /* to be filled */
52 7 : WPA_PUT_BE24(eid, OUI_WFA);
53 7 : eid += 3;
54 7 : *eid++ = HS20_OSEN_OUI_TYPE;
55 :
56 : /* Group Data Cipher Suite */
57 7 : RSN_SELECTOR_PUT(eid, RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED);
58 7 : eid += RSN_SELECTOR_LEN;
59 :
60 : /* Pairwise Cipher Suite Count and List */
61 7 : WPA_PUT_LE16(eid, 1);
62 7 : eid += 2;
63 7 : RSN_SELECTOR_PUT(eid, RSN_CIPHER_SUITE_CCMP);
64 7 : eid += RSN_SELECTOR_LEN;
65 :
66 : /* AKM Suite Count and List */
67 7 : WPA_PUT_LE16(eid, 1);
68 7 : eid += 2;
69 7 : RSN_SELECTOR_PUT(eid, RSN_AUTH_KEY_MGMT_OSEN);
70 7 : eid += RSN_SELECTOR_LEN;
71 :
72 : /* RSN Capabilities */
73 7 : capab = 0;
74 7 : if (hapd->conf->wmm_enabled) {
75 : /* 4 PTKSA replay counters when using WMM */
76 7 : capab |= (RSN_NUM_REPLAY_COUNTERS_16 << 2);
77 : }
78 : #ifdef CONFIG_IEEE80211W
79 7 : 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 7 : WPA_PUT_LE16(eid, capab);
86 7 : eid += 2;
87 :
88 7 : *len = eid - len - 1;
89 :
90 7 : 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 : }
|