blob: b1ebf6e3a375e15909cec470bc1e55f6d36017d2 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / IEEE 802.11 Management: Beacon and Probe Request/Response
3 * Copyright (c) 2002-2004, Instant802 Networks, Inc.
4 * Copyright (c) 2005-2006, Devicescape Software, Inc.
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005 * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006 *
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009 */
10
11#include "utils/includes.h"
12
13#ifndef CONFIG_NATIVE_WINDOWS
14
15#include "utils/common.h"
16#include "common/ieee802_11_defs.h"
17#include "common/ieee802_11_common.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018#include "wps/wps_defs.h"
19#include "p2p/p2p.h"
20#include "hostapd.h"
21#include "ieee802_11.h"
22#include "wpa_auth.h"
23#include "wmm.h"
24#include "ap_config.h"
25#include "sta_info.h"
26#include "p2p_hostapd.h"
27#include "ap_drv_ops.h"
28#include "beacon.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070029#include "hs20.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030
31
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080032#ifdef NEED_AP_MLME
33
Dmitry Shmidt051af732013-10-22 13:52:46 -070034static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
35{
36#ifdef CONFIG_TESTING_OPTIONS
37 if (hapd->conf->bss_load_test_set) {
38 if (2 + 5 > len)
39 return eid;
40 *eid++ = WLAN_EID_BSS_LOAD;
41 *eid++ = 5;
42 os_memcpy(eid, hapd->conf->bss_load_test, 5);
43 eid += 5;
44 }
45#endif /* CONFIG_TESTING_OPTIONS */
46 return eid;
47}
48
49
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070050static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
51{
52 u8 erp = 0;
53
54 if (hapd->iface->current_mode == NULL ||
55 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
56 return 0;
57
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080058 if (hapd->iface->olbc)
59 erp |= ERP_INFO_USE_PROTECTION;
60 if (hapd->iface->num_sta_non_erp > 0) {
61 erp |= ERP_INFO_NON_ERP_PRESENT |
62 ERP_INFO_USE_PROTECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070063 }
64 if (hapd->iface->num_sta_no_short_preamble > 0 ||
65 hapd->iconf->preamble == LONG_PREAMBLE)
66 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
67
68 return erp;
69}
70
71
72static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
73{
74 *eid++ = WLAN_EID_DS_PARAMS;
75 *eid++ = 1;
76 *eid++ = hapd->iconf->channel;
77 return eid;
78}
79
80
81static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
82{
83 if (hapd->iface->current_mode == NULL ||
84 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
85 return eid;
86
87 /* Set NonERP_present and use_protection bits if there
88 * are any associated NonERP stations. */
89 /* TODO: use_protection bit can be set to zero even if
90 * there are NonERP stations present. This optimization
91 * might be useful if NonERP stations are "quiet".
92 * See 802.11g/D6 E-1 for recommended practice.
93 * In addition, Non ERP present might be set, if AP detects Non ERP
94 * operation on other APs. */
95
96 /* Add ERP Information element */
97 *eid++ = WLAN_EID_ERP_INFO;
98 *eid++ = 1;
99 *eid++ = ieee802_11_erp_info(hapd);
100
101 return eid;
102}
103
104
105static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
106 struct hostapd_channel_data *start,
107 struct hostapd_channel_data *prev)
108{
109 if (end - pos < 3)
110 return pos;
111
112 /* first channel number */
113 *pos++ = start->chan;
114 /* number of channels */
115 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
116 /* maximum transmit power level */
117 *pos++ = start->max_tx_power;
118
119 return pos;
120}
121
122
123static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
124 int max_len)
125{
126 u8 *pos = eid;
127 u8 *end = eid + max_len;
128 int i;
129 struct hostapd_hw_modes *mode;
130 struct hostapd_channel_data *start, *prev;
131 int chan_spacing = 1;
132
133 if (!hapd->iconf->ieee80211d || max_len < 6 ||
134 hapd->iface->current_mode == NULL)
135 return eid;
136
137 *pos++ = WLAN_EID_COUNTRY;
138 pos++; /* length will be set later */
139 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
140 pos += 3;
141
142 mode = hapd->iface->current_mode;
143 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
144 chan_spacing = 4;
145
146 start = prev = NULL;
147 for (i = 0; i < mode->num_channels; i++) {
148 struct hostapd_channel_data *chan = &mode->channels[i];
149 if (chan->flag & HOSTAPD_CHAN_DISABLED)
150 continue;
151 if (start && prev &&
152 prev->chan + chan_spacing == chan->chan &&
153 start->max_tx_power == chan->max_tx_power) {
154 prev = chan;
155 continue; /* can use same entry */
156 }
157
158 if (start) {
159 pos = hostapd_eid_country_add(pos, end, chan_spacing,
160 start, prev);
161 start = NULL;
162 }
163
164 /* Start new group */
165 start = prev = chan;
166 }
167
168 if (start) {
169 pos = hostapd_eid_country_add(pos, end, chan_spacing,
170 start, prev);
171 }
172
173 if ((pos - eid) & 1) {
174 if (end - pos < 1)
175 return eid;
176 *pos++ = 0; /* pad for 16-bit alignment */
177 }
178
179 eid[1] = (pos - eid) - 2;
180
181 return pos;
182}
183
184
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800185static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700186{
187 const u8 *ie;
188 size_t ielen;
189
190 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
191 if (ie == NULL || ielen > len)
192 return eid;
193
194 os_memcpy(eid, ie, ielen);
195 return eid + ielen;
196}
197
198
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800199static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
200{
201 u8 chan;
202
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800203 if (!hapd->iface->cs_freq_params.freq)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800204 return eid;
205
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800206 if (ieee80211_freq_to_chan(hapd->iface->cs_freq_params.freq, &chan) ==
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800207 NUM_HOSTAPD_MODES)
208 return eid;
209
210 *eid++ = WLAN_EID_CHANNEL_SWITCH;
211 *eid++ = 3;
212 *eid++ = hapd->iface->cs_block_tx;
213 *eid++ = chan;
214 *eid++ = hapd->iface->cs_count;
215
216 return eid;
217}
218
219
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800220static u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid)
221{
222 u8 sec_ch;
223
224 if (!hapd->iface->cs_freq_params.sec_channel_offset)
225 return eid;
226
227 if (hapd->iface->cs_freq_params.sec_channel_offset == -1)
228 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
229 else if (hapd->iface->cs_freq_params.sec_channel_offset == 1)
230 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
231 else
232 return eid;
233
234 *eid++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET;
235 *eid++ = 1;
236 *eid++ = sec_ch;
237
238 return eid;
239}
240
241
242static u8 * hostapd_add_csa_elems(struct hostapd_data *hapd, u8 *pos,
243 u8 *start, unsigned int *csa_counter_off)
244{
245 u8 *old_pos = pos;
246
247 if (!csa_counter_off)
248 return pos;
249
250 *csa_counter_off = 0;
251 pos = hostapd_eid_csa(hapd, pos);
252
253 if (pos != old_pos) {
254 /* save an offset to the counter - should be last byte */
255 *csa_counter_off = pos - start - 1;
256 pos = hostapd_eid_secondary_channel(hapd, pos);
257 }
258
259 return pos;
260}
261
262
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800263static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
264 struct sta_info *sta,
265 const struct ieee80211_mgmt *req,
266 int is_p2p, size_t *resp_len)
267{
268 struct ieee80211_mgmt *resp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800269 u8 *pos, *epos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800270 size_t buflen;
271
272#define MAX_PROBERESP_LEN 768
273 buflen = MAX_PROBERESP_LEN;
274#ifdef CONFIG_WPS
275 if (hapd->wps_probe_resp_ie)
276 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
277#endif /* CONFIG_WPS */
278#ifdef CONFIG_P2P
279 if (hapd->p2p_probe_resp_ie)
280 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
281#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700282 if (hapd->conf->vendor_elements)
283 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800284 resp = os_zalloc(buflen);
285 if (resp == NULL)
286 return NULL;
287
288 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
289
290 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
291 WLAN_FC_STYPE_PROBE_RESP);
292 if (req)
293 os_memcpy(resp->da, req->sa, ETH_ALEN);
294 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
295
296 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
297 resp->u.probe_resp.beacon_int =
298 host_to_le16(hapd->iconf->beacon_int);
299
300 /* hardware or low-level driver will setup seq_ctrl and timestamp */
301 resp->u.probe_resp.capab_info =
302 host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
303
304 pos = resp->u.probe_resp.variable;
305 *pos++ = WLAN_EID_SSID;
306 *pos++ = hapd->conf->ssid.ssid_len;
307 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
308 pos += hapd->conf->ssid.ssid_len;
309
310 /* Supported rates */
311 pos = hostapd_eid_supp_rates(hapd, pos);
312
313 /* DS Params */
314 pos = hostapd_eid_ds_params(hapd, pos);
315
316 pos = hostapd_eid_country(hapd, pos, epos - pos);
317
318 /* ERP Information element */
319 pos = hostapd_eid_erp_info(hapd, pos);
320
321 /* Extended supported rates */
322 pos = hostapd_eid_ext_supp_rates(hapd, pos);
323
324 /* RSN, MDIE, WPA */
325 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
326
Dmitry Shmidt051af732013-10-22 13:52:46 -0700327 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
328
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800329#ifdef CONFIG_IEEE80211N
330 pos = hostapd_eid_ht_capabilities(hapd, pos);
331 pos = hostapd_eid_ht_operation(hapd, pos);
332#endif /* CONFIG_IEEE80211N */
333
334 pos = hostapd_eid_ext_capab(hapd, pos);
335
336 pos = hostapd_eid_time_adv(hapd, pos);
337 pos = hostapd_eid_time_zone(hapd, pos);
338
339 pos = hostapd_eid_interworking(hapd, pos);
340 pos = hostapd_eid_adv_proto(hapd, pos);
341 pos = hostapd_eid_roaming_consortium(hapd, pos);
342
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800343 pos = hostapd_add_csa_elems(hapd, pos, (u8 *)resp,
344 &hapd->iface->cs_c_off_proberesp);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700345#ifdef CONFIG_IEEE80211AC
346 pos = hostapd_eid_vht_capabilities(hapd, pos);
347 pos = hostapd_eid_vht_operation(hapd, pos);
348#endif /* CONFIG_IEEE80211AC */
349
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800350 /* Wi-Fi Alliance WMM */
351 pos = hostapd_eid_wmm(hapd, pos);
352
353#ifdef CONFIG_WPS
354 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
355 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
356 wpabuf_len(hapd->wps_probe_resp_ie));
357 pos += wpabuf_len(hapd->wps_probe_resp_ie);
358 }
359#endif /* CONFIG_WPS */
360
361#ifdef CONFIG_P2P
362 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
363 hapd->p2p_probe_resp_ie) {
364 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
365 wpabuf_len(hapd->p2p_probe_resp_ie));
366 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
367 }
368#endif /* CONFIG_P2P */
369#ifdef CONFIG_P2P_MANAGER
370 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
371 P2P_MANAGE)
372 pos = hostapd_eid_p2p_manage(hapd, pos);
373#endif /* CONFIG_P2P_MANAGER */
374
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700375#ifdef CONFIG_HS20
376 pos = hostapd_eid_hs20_indication(hapd, pos);
377#endif /* CONFIG_HS20 */
378
379 if (hapd->conf->vendor_elements) {
380 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
381 wpabuf_len(hapd->conf->vendor_elements));
382 pos += wpabuf_len(hapd->conf->vendor_elements);
383 }
384
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800385 *resp_len = pos - (u8 *) resp;
386 return (u8 *) resp;
387}
388
389
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800390enum ssid_match_result {
391 NO_SSID_MATCH,
392 EXACT_SSID_MATCH,
393 WILDCARD_SSID_MATCH
394};
395
396static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
397 const u8 *ssid, size_t ssid_len,
398 const u8 *ssid_list,
399 size_t ssid_list_len)
400{
401 const u8 *pos, *end;
402 int wildcard = 0;
403
404 if (ssid_len == 0)
405 wildcard = 1;
406 if (ssid_len == hapd->conf->ssid.ssid_len &&
407 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
408 return EXACT_SSID_MATCH;
409
410 if (ssid_list == NULL)
411 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
412
413 pos = ssid_list;
414 end = ssid_list + ssid_list_len;
415 while (pos + 1 <= end) {
416 if (pos + 2 + pos[1] > end)
417 break;
418 if (pos[1] == 0)
419 wildcard = 1;
420 if (pos[1] == hapd->conf->ssid.ssid_len &&
421 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
422 return EXACT_SSID_MATCH;
423 pos += 2 + pos[1];
424 }
425
426 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
427}
428
429
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700430void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700431 const struct ieee80211_mgmt *mgmt, size_t len,
432 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700433{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800434 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700435 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700436 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800437 size_t ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700438 struct sta_info *sta = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800439 size_t i, resp_len;
440 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800441 enum ssid_match_result res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700442
443 ie = mgmt->u.probe_req.variable;
444 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
445 return;
446 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
447
448 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
449 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800450 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700451 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700452 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800453
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700454 if (!hapd->iconf->send_probe_response)
455 return;
456
457 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
458 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
459 MAC2STR(mgmt->sa));
460 return;
461 }
462
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700463 if ((!elems.ssid || !elems.supp_rates)) {
464 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
465 "without SSID or supported rates element",
466 MAC2STR(mgmt->sa));
467 return;
468 }
469
470#ifdef CONFIG_P2P
471 if (hapd->p2p && elems.wps_ie) {
472 struct wpabuf *wps;
473 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
474 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
475 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
476 "due to mismatch with Requested Device "
477 "Type");
478 wpabuf_free(wps);
479 return;
480 }
481 wpabuf_free(wps);
482 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800483
484 if (hapd->p2p && elems.p2p) {
485 struct wpabuf *p2p;
486 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
487 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
488 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
489 "due to mismatch with Device ID");
490 wpabuf_free(p2p);
491 return;
492 }
493 wpabuf_free(p2p);
494 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700495#endif /* CONFIG_P2P */
496
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800497 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
498 elems.ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700499 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
500 "broadcast SSID ignored", MAC2STR(mgmt->sa));
501 return;
502 }
503
504 sta = ap_get_sta(hapd, mgmt->sa);
505
506#ifdef CONFIG_P2P
507 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
508 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
509 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
510 P2P_WILDCARD_SSID_LEN) == 0) {
511 /* Process P2P Wildcard SSID like Wildcard SSID */
512 elems.ssid_len = 0;
513 }
514#endif /* CONFIG_P2P */
515
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800516 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
517 elems.ssid_list, elems.ssid_list_len);
518 if (res != NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700519 if (sta)
520 sta->ssid_probe = &hapd->conf->ssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800521 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700522 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700523 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800524 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800525 MAC2STR(mgmt->sa),
526 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800527 MAC2STR(mgmt->da),
528 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529 }
530 return;
531 }
532
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800533#ifdef CONFIG_INTERWORKING
534 if (elems.interworking && elems.interworking_len >= 1) {
535 u8 ant = elems.interworking[0] & 0x0f;
536 if (ant != INTERWORKING_ANT_WILDCARD &&
537 ant != hapd->conf->access_network_type) {
538 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
539 " for mismatching ANT %u ignored",
540 MAC2STR(mgmt->sa), ant);
541 return;
542 }
543 }
544
545 if (elems.interworking &&
546 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
547 const u8 *hessid;
548 if (elems.interworking_len == 7)
549 hessid = elems.interworking + 1;
550 else
551 hessid = elems.interworking + 1 + 2;
552 if (!is_broadcast_ether_addr(hessid) &&
553 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
554 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
555 " for mismatching HESSID " MACSTR
556 " ignored",
557 MAC2STR(mgmt->sa), MAC2STR(hessid));
558 return;
559 }
560 }
561#endif /* CONFIG_INTERWORKING */
562
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700563#ifdef CONFIG_P2P
564 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
565 supp_rates_11b_only(&elems)) {
566 /* Indicates support for 11b rates only */
567 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
568 MACSTR " with only 802.11b rates",
569 MAC2STR(mgmt->sa));
570 return;
571 }
572#endif /* CONFIG_P2P */
573
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700574 /* TODO: verify that supp_rates contains at least one matching rate
575 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800576
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700577#ifdef CONFIG_TESTING_OPTIONS
578 if (hapd->iconf->ignore_probe_probability > 0.0d &&
579 drand48() < hapd->iconf->ignore_probe_probability) {
580 wpa_printf(MSG_INFO,
581 "TESTING: ignoring probe request from " MACSTR,
582 MAC2STR(mgmt->sa));
583 return;
584 }
585#endif /* CONFIG_TESTING_OPTIONS */
586
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800587 resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
588 &resp_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700589 if (resp == NULL)
590 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700591
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800592 /*
593 * If this is a broadcast probe request, apply no ack policy to avoid
594 * excessive retries.
595 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800596 noack = !!(res == WILDCARD_SSID_MATCH &&
597 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700598
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800599 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800600 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700601
602 os_free(resp);
603
604 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
605 "SSID", MAC2STR(mgmt->sa),
606 elems.ssid_len == 0 ? "broadcast" : "our");
607}
608
609
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800610static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
611 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700612{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800613 /* check probe response offloading caps and print warnings */
614 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
615 return NULL;
616
617#ifdef CONFIG_WPS
618 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
619 (!(hapd->iface->probe_resp_offloads &
620 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
621 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
622 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
623 "Probe Response while not supporting this");
624#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700625
626#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800627 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
628 !(hapd->iface->probe_resp_offloads &
629 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
630 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
631 "Probe Response while not supporting this");
632#endif /* CONFIG_P2P */
633
634 if (hapd->conf->interworking &&
635 !(hapd->iface->probe_resp_offloads &
636 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
637 wpa_printf(MSG_WARNING, "Device is trying to offload "
638 "Interworking Probe Response while not supporting "
639 "this");
640
641 /* Generate a Probe Response template for the non-P2P case */
642 return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
643}
644
645#endif /* NEED_AP_MLME */
646
647
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800648int ieee802_11_build_ap_params(struct hostapd_data *hapd,
649 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800650{
651 struct ieee80211_mgmt *head = NULL;
652 u8 *tail = NULL;
653 size_t head_len = 0, tail_len = 0;
654 u8 *resp = NULL;
655 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800656#ifdef NEED_AP_MLME
657 u16 capab_info;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800658 u8 *pos, *tailpos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700659
660#define BEACON_HEAD_BUF_SIZE 256
661#define BEACON_TAIL_BUF_SIZE 512
662 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
663 tail_len = BEACON_TAIL_BUF_SIZE;
664#ifdef CONFIG_WPS
665 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
666 tail_len += wpabuf_len(hapd->wps_beacon_ie);
667#endif /* CONFIG_WPS */
668#ifdef CONFIG_P2P
669 if (hapd->p2p_beacon_ie)
670 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
671#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700672 if (hapd->conf->vendor_elements)
673 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700674 tailpos = tail = os_malloc(tail_len);
675 if (head == NULL || tail == NULL) {
676 wpa_printf(MSG_ERROR, "Failed to set beacon data");
677 os_free(head);
678 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800679 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700680 }
681
682 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
683 WLAN_FC_STYPE_BEACON);
684 head->duration = host_to_le16(0);
685 os_memset(head->da, 0xff, ETH_ALEN);
686
687 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
688 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
689 head->u.beacon.beacon_int =
690 host_to_le16(hapd->iconf->beacon_int);
691
692 /* hardware or low-level driver will setup seq_ctrl and timestamp */
693 capab_info = hostapd_own_capab_info(hapd, NULL, 0);
694 head->u.beacon.capab_info = host_to_le16(capab_info);
695 pos = &head->u.beacon.variable[0];
696
697 /* SSID */
698 *pos++ = WLAN_EID_SSID;
699 if (hapd->conf->ignore_broadcast_ssid == 2) {
700 /* clear the data, but keep the correct length of the SSID */
701 *pos++ = hapd->conf->ssid.ssid_len;
702 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
703 pos += hapd->conf->ssid.ssid_len;
704 } else if (hapd->conf->ignore_broadcast_ssid) {
705 *pos++ = 0; /* empty SSID */
706 } else {
707 *pos++ = hapd->conf->ssid.ssid_len;
708 os_memcpy(pos, hapd->conf->ssid.ssid,
709 hapd->conf->ssid.ssid_len);
710 pos += hapd->conf->ssid.ssid_len;
711 }
712
713 /* Supported rates */
714 pos = hostapd_eid_supp_rates(hapd, pos);
715
716 /* DS Params */
717 pos = hostapd_eid_ds_params(hapd, pos);
718
719 head_len = pos - (u8 *) head;
720
721 tailpos = hostapd_eid_country(hapd, tailpos,
722 tail + BEACON_TAIL_BUF_SIZE - tailpos);
723
724 /* ERP Information element */
725 tailpos = hostapd_eid_erp_info(hapd, tailpos);
726
727 /* Extended supported rates */
728 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
729
730 /* RSN, MDIE, WPA */
731 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800732 tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733
Dmitry Shmidt051af732013-10-22 13:52:46 -0700734 tailpos = hostapd_eid_bss_load(hapd, tailpos,
735 tail + BEACON_TAIL_BUF_SIZE - tailpos);
736
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700737#ifdef CONFIG_IEEE80211N
738 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
739 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
740#endif /* CONFIG_IEEE80211N */
741
742 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
743
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800744 /*
745 * TODO: Time Advertisement element should only be included in some
746 * DTIM Beacon frames.
747 */
748 tailpos = hostapd_eid_time_adv(hapd, tailpos);
749
750 tailpos = hostapd_eid_interworking(hapd, tailpos);
751 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
752 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800753 tailpos = hostapd_add_csa_elems(hapd, tailpos, tail,
754 &hapd->iface->cs_c_off_beacon);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700755#ifdef CONFIG_IEEE80211AC
756 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
757 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
758#endif /* CONFIG_IEEE80211AC */
759
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700760 /* Wi-Fi Alliance WMM */
761 tailpos = hostapd_eid_wmm(hapd, tailpos);
762
763#ifdef CONFIG_WPS
764 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
765 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
766 wpabuf_len(hapd->wps_beacon_ie));
767 tailpos += wpabuf_len(hapd->wps_beacon_ie);
768 }
769#endif /* CONFIG_WPS */
770
771#ifdef CONFIG_P2P
772 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
773 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
774 wpabuf_len(hapd->p2p_beacon_ie));
775 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
776 }
777#endif /* CONFIG_P2P */
778#ifdef CONFIG_P2P_MANAGER
779 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
780 P2P_MANAGE)
781 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
782#endif /* CONFIG_P2P_MANAGER */
783
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700784#ifdef CONFIG_HS20
785 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
786#endif /* CONFIG_HS20 */
787
788 if (hapd->conf->vendor_elements) {
789 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
790 wpabuf_len(hapd->conf->vendor_elements));
791 tailpos += wpabuf_len(hapd->conf->vendor_elements);
792 }
793
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700794 tail_len = tailpos > tail ? tailpos - tail : 0;
795
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800796 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
797#endif /* NEED_AP_MLME */
798
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800799 os_memset(params, 0, sizeof(*params));
800 params->head = (u8 *) head;
801 params->head_len = head_len;
802 params->tail = tail;
803 params->tail_len = tail_len;
804 params->proberesp = resp;
805 params->proberesp_len = resp_len;
806 params->dtim_period = hapd->conf->dtim_period;
807 params->beacon_int = hapd->iconf->beacon_int;
808 params->basic_rates = hapd->iface->basic_rates;
809 params->ssid = hapd->conf->ssid.ssid;
810 params->ssid_len = hapd->conf->ssid.ssid_len;
811 params->pairwise_ciphers = hapd->conf->rsn_pairwise ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800812 hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800813 params->group_cipher = hapd->conf->wpa_group;
814 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
815 params->auth_algs = hapd->conf->auth_algs;
816 params->wpa_version = hapd->conf->wpa;
817 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800818 (hapd->conf->ieee802_1x &&
819 (hapd->conf->default_wep_key_len ||
820 hapd->conf->individual_wep_key_len));
821 switch (hapd->conf->ignore_broadcast_ssid) {
822 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800823 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800824 break;
825 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800826 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800827 break;
828 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800829 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800830 break;
831 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800832 params->isolate = hapd->conf->isolate;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800833#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800834 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800835 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800836 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800837 hapd->iconf->preamble == SHORT_PREAMBLE;
838 if (hapd->iface->current_mode &&
839 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800840 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800841 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
842 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800843 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800844 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800845 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800846 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800847 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800848#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800849 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800850 if (hapd->conf->interworking &&
851 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800852 params->hessid = hapd->conf->hessid;
853 params->access_network_type = hapd->conf->access_network_type;
854 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700855#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800856 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700857#endif /* CONFIG_HS20 */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800858 return 0;
859}
860
861
862void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
863{
864 os_free(params->tail);
865 params->tail = NULL;
866 os_free(params->head);
867 params->head = NULL;
868 os_free(params->proberesp);
869 params->proberesp = NULL;
870}
871
872
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800873int ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800874{
875 struct wpa_driver_ap_params params;
876 struct wpabuf *beacon, *proberesp, *assocresp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800877 int res, ret = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800878
879 if (hapd->iface->csa_in_progress) {
880 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800881 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800882 }
883
884 hapd->beacon_set_done = 1;
885
886 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800887 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800888
889 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
890 0)
891 goto fail;
892
893 params.beacon_ies = beacon;
894 params.proberesp_ies = proberesp;
895 params.assocresp_ies = assocresp;
896
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800897 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800898 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800899 if (res)
900 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
901 else
902 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800903fail:
904 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800905 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700906}
907
908
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800909int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700910{
911 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800912 int ret = 0;
913
Dmitry Shmidt292b0c32013-11-22 12:54:42 -0800914 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800915 if (iface->bss[i]->started &&
916 ieee802_11_set_beacon(iface->bss[i]) < 0)
917 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -0800918 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800919
920 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700921}
922
Dmitry Shmidt04949592012-07-19 12:16:46 -0700923
924/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800925int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700926{
927 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800928 int ret = 0;
929
930 for (i = 0; i < iface->num_bss; i++) {
931 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
932 ieee802_11_set_beacon(iface->bss[i]) < 0)
933 ret = -1;
934 }
935
936 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700937}
938
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700939#endif /* CONFIG_NATIVE_WINDOWS */