2 * FST module - FST group object implementation
3 * Copyright (c) 2014, Qualcomm Atheros, Inc.
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
10 #include "utils/common.h"
11 #include "common/defs.h"
12 #include "common/ieee802_11_defs.h"
13 #include "common/ieee802_11_common.h"
14 #include "drivers/driver.h"
15 #include "fst/fst_internal.h"
16 #include "fst/fst_defs.h"
19 struct dl_list fst_global_groups_list;
22 static Boolean fst_has_fst_peer(struct fst_iface *iface, Boolean *has_peer)
26 bssid = fst_iface_get_bssid(iface);
33 return fst_iface_get_peer_mb_ie(iface, bssid) != NULL;
38 static void fst_dump_mb_ies(const char *group_id, const char *ifname,
41 const u8 *p = wpabuf_head(mbies);
42 size_t s = wpabuf_len(mbies);
44 while (s >= offsetof(struct multi_band_ie, mb_ctrl)) {
45 const struct multi_band_ie *mbie =
46 (const struct multi_band_ie *) p;
47 WPA_ASSERT(mbie->eid == WLAN_EID_MULTI_BAND);
48 WPA_ASSERT(IE_BUFFER_LENGTH(mbie->len) >= sizeof(*mbie));
50 fst_printf(MSG_WARNING,
51 "%s: %s: mb_ctrl=%u band_id=%u op_class=%u chan=%u bssid="
53 " beacon_int=%u tsf_offs=[%u %u %u %u %u %u %u %u] mb_cc=0x%02x tmout=%u",
55 mbie->mb_ctrl, mbie->band_id, mbie->op_class,
56 mbie->chan, MAC2STR(mbie->bssid), mbie->beacon_int,
57 mbie->tsf_offs[0], mbie->tsf_offs[1],
58 mbie->tsf_offs[2], mbie->tsf_offs[3],
59 mbie->tsf_offs[4], mbie->tsf_offs[5],
60 mbie->tsf_offs[6], mbie->tsf_offs[7],
61 mbie->mb_connection_capability,
62 mbie->fst_session_tmout);
64 p += IE_BUFFER_LENGTH(mbie->len);
65 s -= IE_BUFFER_LENGTH(mbie->len);
70 static void fst_fill_mb_ie(struct wpabuf *buf, const u8 *bssid,
71 const u8 *own_addr, enum mb_band_id band, u8 channel)
73 struct multi_band_ie *mbie;
74 size_t len = sizeof(*mbie);
79 mbie = wpabuf_put(buf, len);
81 os_memset(mbie, 0, len);
83 mbie->eid = WLAN_EID_MULTI_BAND;
84 mbie->len = len - IE_HEADER_SIZE;
86 mbie->mb_ctrl = MB_STA_ROLE_AP;
87 mbie->mb_connection_capability = MB_CONNECTION_CAPABILITY_AP;
89 mbie->mb_ctrl = MB_STA_ROLE_NON_PCP_NON_AP;
90 mbie->mb_connection_capability = 0;
93 os_memcpy(mbie->bssid, bssid, ETH_ALEN);
95 mbie->op_class = 0; /* means all */
97 mbie->fst_session_tmout = FST_DEFAULT_SESSION_TIMEOUT_TU;
100 mbie->mb_ctrl |= MB_CTRL_STA_MAC_PRESENT;
101 os_memcpy(&mbie[1], own_addr, ETH_ALEN);
106 static unsigned fst_fill_iface_mb_ies(struct fst_iface *f, struct wpabuf *buf)
110 bssid = fst_iface_get_bssid(f);
112 enum hostapd_hw_mode hw_mode;
116 fst_iface_get_channel_info(f, &hw_mode, &channel);
117 fst_fill_mb_ie(buf, bssid, fst_iface_get_addr(f),
118 fst_hw_mode_to_band(hw_mode), channel);
122 unsigned bands[MB_BAND_ID_WIFI_60GHZ + 1] = {};
123 struct hostapd_hw_modes *modes;
125 int num_modes = fst_iface_get_hw_modes(f, &modes);
128 while (num_modes--) {
129 b = fst_hw_mode_to_band(modes->mode);
131 if (b >= ARRAY_SIZE(bands) || bands[b]++)
135 fst_fill_mb_ie(buf, NULL, fst_iface_get_addr(f),
136 b, MB_STA_CHANNEL_ALL);
143 static struct wpabuf * fst_group_create_mb_ie(struct fst_group *g,
148 unsigned int nof_mbies = 0;
149 unsigned int nof_ifaces_added = 0;
152 Boolean has_fst_peer;
154 foreach_fst_group_iface(g, f) {
155 has_fst_peer = fst_has_fst_peer(f, &has_peer);
156 if (has_peer && !has_fst_peer)
161 foreach_fst_group_iface(g, f) {
164 nof_mbies += fst_fill_iface_mb_ies(f, NULL);
167 buf = wpabuf_alloc(nof_mbies *
168 (sizeof(struct multi_band_ie) + ETH_ALEN));
170 fst_printf_iface(i, MSG_ERROR,
171 "cannot allocate mem for %u MB IEs",
176 /* The list is sorted in descending order by priorities, so MB IEs will
177 * be arranged in the same order, as required by spec (see corresponding
178 * comment in.fst_attach().
180 foreach_fst_group_iface(g, f) {
184 fst_fill_iface_mb_ies(f, buf);
187 fst_printf_iface(i, MSG_DEBUG, "added to MB IE");
190 if (!nof_ifaces_added) {
193 fst_printf_iface(i, MSG_INFO,
194 "cannot add MB IE: no backup ifaces");
196 fst_dump_mb_ies(fst_group_get_id(g), fst_iface_get_name(i),
204 static struct fst_iface *
205 fst_group_get_new_iface_by_mbie_and_band_id(struct fst_group *g,
206 const u8 *mb_ies_buff,
211 while (mb_ies_size >= offsetof(struct multi_band_ie, mb_ctrl)) {
212 const struct multi_band_ie *mbie =
213 (const struct multi_band_ie *) mb_ies_buff;
215 if (mbie->eid != WLAN_EID_MULTI_BAND ||
216 IE_BUFFER_LENGTH(mbie->len) < sizeof(*mbie))
219 if (mbie->band_id == band_id) {
220 struct fst_iface *iface;
222 foreach_fst_group_iface(g, iface) {
223 const u8 *peer_addr =
224 fst_mbie_get_peer_addr(mbie);
227 fst_iface_is_connected(iface, peer_addr) &&
228 band_id == fst_iface_get_band_id(iface)) {
229 os_memcpy(iface_peer_addr, peer_addr,
237 mb_ies_buff += IE_BUFFER_LENGTH(mbie->len);
238 mb_ies_size -= IE_BUFFER_LENGTH(mbie->len);
245 struct fst_iface * fst_group_get_iface_by_name(struct fst_group *g,
250 foreach_fst_group_iface(g, f) {
251 const char *in = fst_iface_get_name(f);
253 if (os_strncmp(in, ifname, os_strlen(in)) == 0)
261 u8 fst_group_assign_dialog_token(struct fst_group *g)
264 if (g->dialog_token == 0)
266 return g->dialog_token;
270 u32 fst_group_assign_fsts_id(struct fst_group *g)
278 fst_group_does_iface_appear_in_other_mbies(struct fst_group *g,
279 struct fst_iface *iface,
280 struct fst_iface *other,
283 struct fst_get_peer_ctx *ctx;
285 const u8 *iface_addr;
286 enum mb_band_id iface_band_id;
288 WPA_ASSERT(g == fst_iface_get_group(iface));
289 WPA_ASSERT(g == fst_iface_get_group(other));
291 iface_addr = fst_iface_get_addr(iface);
292 iface_band_id = fst_iface_get_band_id(iface);
294 addr = fst_iface_get_peer_first(other, &ctx, TRUE);
295 for (; addr; addr = fst_iface_get_peer_next(other, &ctx, TRUE)) {
296 struct wpabuf *mbies = fst_iface_get_peer_mb_ie(other, addr);
299 u8 other_iface_peer_addr[ETH_ALEN];
300 struct fst_iface *other_new_iface =
301 fst_group_get_new_iface_by_mbie_and_band_id(
303 wpabuf_head(mbies), wpabuf_len(mbies),
304 iface_band_id, other_iface_peer_addr);
305 if (other_new_iface == iface &&
306 os_memcmp(iface_addr, other_iface_peer_addr,
308 os_memcpy(peer_addr, addr, ETH_ALEN);
319 fst_group_find_new_iface_by_stie(struct fst_group *g,
320 struct fst_iface *iface,
322 const struct session_transition_ie *stie,
327 foreach_fst_group_iface(g, i) {
329 stie->new_band_id != fst_iface_get_band_id(i))
331 if (fst_group_does_iface_appear_in_other_mbies(g, iface, i,
341 fst_group_get_new_iface_by_stie_and_mbie(
342 struct fst_group *g, const u8 *mb_ies_buff, size_t mb_ies_size,
343 const struct session_transition_ie *stie, u8 *iface_peer_addr)
345 return fst_group_get_new_iface_by_mbie_and_band_id(
346 g, mb_ies_buff, mb_ies_size, stie->new_band_id,
351 struct fst_group * fst_group_create(const char *group_id)
355 g = os_zalloc(sizeof(*g));
357 fst_printf(MSG_ERROR, "%s: Cannot alloc group", group_id);
361 dl_list_init(&g->ifaces);
362 os_strlcpy(g->group_id, group_id, sizeof(g->group_id));
364 dl_list_add_tail(&fst_global_groups_list, &g->global_groups_lentry);
365 fst_printf_group(g, MSG_DEBUG, "instance created");
367 foreach_fst_ctrl_call(on_group_created, g);
373 void fst_group_attach_iface(struct fst_group *g, struct fst_iface *i)
375 struct dl_list *list = &g->ifaces;
379 * Add new interface to the list.
380 * The list is sorted in descending order by priority to allow
381 * multiple MB IEs creation according to the spec (see 10.32 Multi-band
382 * operation, 10.32.1 General), as they should be ordered according to
385 foreach_fst_group_iface(g, f) {
386 if (fst_iface_get_priority(f) < fst_iface_get_priority(i))
388 list = &f->group_lentry;
390 dl_list_add(list, &i->group_lentry);
394 void fst_group_detach_iface(struct fst_group *g, struct fst_iface *i)
396 dl_list_del(&i->group_lentry);
400 void fst_group_delete(struct fst_group *group)
402 struct fst_session *s;
404 dl_list_del(&group->global_groups_lentry);
405 WPA_ASSERT(dl_list_empty(&group->ifaces));
406 foreach_fst_ctrl_call(on_group_deleted, group);
407 fst_printf_group(group, MSG_DEBUG, "instance deleted");
408 while ((s = fst_session_global_get_first_by_group(group)) != NULL)
409 fst_session_delete(s);
414 Boolean fst_group_delete_if_empty(struct fst_group *group)
416 Boolean is_empty = !fst_group_has_ifaces(group) &&
417 !fst_session_global_get_first_by_group(group);
420 fst_group_delete(group);
426 void fst_group_update_ie(struct fst_group *g, Boolean cleaning_up)
430 foreach_fst_group_iface(g, i) {
432 struct wpabuf *mbie = fst_group_create_mb_ie(g, i);
435 fst_printf_iface(i, MSG_WARNING,
436 "cannot create MB IE");
438 fst_iface_attach_mbie(i, mbie);
439 fst_iface_set_ies(i, mbie);
440 fst_printf_iface(i, MSG_DEBUG,
441 "multi-band IE set to %p", mbie);
443 fst_iface_attach_mbie(i, NULL);
444 fst_iface_set_ies(i, NULL);