2 * FST module 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"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
14 #include "fst/fst_internal.h"
15 #include "fst/fst_defs.h"
16 #include "fst/fst_ctrl_iface.h"
18 static int fst_global_initialized = 0;
19 struct dl_list fst_global_ctrls_list;
22 static void fst_ctrl_iface_notify_peer_state_change(struct fst_iface *iface,
26 union fst_event_extra extra;
28 extra.peer_state.connected = connected;
29 os_strlcpy(extra.peer_state.ifname, fst_iface_get_name(iface),
30 sizeof(extra.peer_state.ifname));
31 os_memcpy(extra.peer_state.addr, peer_addr, ETH_ALEN);
33 foreach_fst_ctrl_call(on_event, EVENT_PEER_STATE_CHANGED,
38 struct fst_iface * fst_attach(const char *ifname, const u8 *own_addr,
39 const struct fst_wpa_obj *iface_obj,
40 const struct fst_iface_cfg *cfg)
43 struct fst_group *group = NULL;
44 struct fst_iface *iface = NULL;
45 Boolean new_group = FALSE;
47 WPA_ASSERT(ifname != NULL);
48 WPA_ASSERT(iface_obj != NULL);
49 WPA_ASSERT(cfg != NULL);
51 foreach_fst_group(g) {
52 if (os_strcmp(cfg->group_id, fst_group_get_id(g)) == 0) {
59 group = fst_group_create(cfg->group_id);
61 fst_printf(MSG_ERROR, "%s: FST group cannot be created",
68 iface = fst_iface_create(group, ifname, own_addr, iface_obj, cfg);
70 fst_printf_group(group, MSG_ERROR, "cannot create iface for %s",
73 fst_group_delete(group);
77 fst_group_attach_iface(group, iface);
78 fst_group_update_ie(group);
80 foreach_fst_ctrl_call(on_iface_added, iface);
82 fst_printf_iface(iface, MSG_DEBUG,
83 "iface attached to group %s (prio=%d, llt=%d)",
84 cfg->group_id, cfg->priority, cfg->llt);
90 void fst_detach(struct fst_iface *iface)
92 struct fst_group *group = fst_iface_get_group(iface);
94 fst_printf_iface(iface, MSG_DEBUG, "iface detached from group %s",
95 fst_group_get_id(group));
96 fst_session_global_on_iface_detached(iface);
97 foreach_fst_ctrl_call(on_iface_removed, iface);
98 fst_group_detach_iface(group, iface);
99 fst_iface_delete(iface);
100 fst_group_update_ie(group);
101 fst_group_delete_if_empty(group);
105 int fst_global_init(void)
107 dl_list_init(&fst_global_groups_list);
108 dl_list_init(&fst_global_ctrls_list);
109 fst_session_global_init();
110 fst_global_initialized = 1;
115 void fst_global_deinit(void)
117 struct fst_group *group;
118 struct fst_ctrl_handle *h;
120 if (!fst_global_initialized)
123 fst_session_global_deinit();
124 while ((group = fst_first_group()) != NULL)
125 fst_group_delete(group);
126 while ((h = dl_list_first(&fst_global_ctrls_list,
127 struct fst_ctrl_handle,
128 global_ctrls_lentry)))
129 fst_global_del_ctrl(h);
130 fst_global_initialized = 0;
134 struct fst_ctrl_handle * fst_global_add_ctrl(const struct fst_ctrl *ctrl)
136 struct fst_ctrl_handle *h;
141 h = os_zalloc(sizeof(*h));
145 if (ctrl->init && ctrl->init()) {
151 dl_list_add_tail(&fst_global_ctrls_list, &h->global_ctrls_lentry);
157 void fst_global_del_ctrl(struct fst_ctrl_handle *h)
159 dl_list_del(&h->global_ctrls_lentry);
166 void fst_rx_action(struct fst_iface *iface, const struct ieee80211_mgmt *mgmt,
169 if (fst_iface_is_connected(iface, mgmt->sa, FALSE))
170 fst_session_on_action_rx(iface, mgmt, len);
172 wpa_printf(MSG_DEBUG,
173 "FST: Ignore FST Action frame - no FST connection with "
174 MACSTR, MAC2STR(mgmt->sa));
178 void fst_notify_peer_connected(struct fst_iface *iface, const u8 *addr)
180 if (is_zero_ether_addr(addr))
184 fst_group_update_ie(fst_iface_get_group(iface));
187 fst_printf_iface(iface, MSG_DEBUG, MACSTR " became connected",
190 fst_ctrl_iface_notify_peer_state_change(iface, TRUE, addr);
194 void fst_notify_peer_disconnected(struct fst_iface *iface, const u8 *addr)
196 if (is_zero_ether_addr(addr))
200 fst_group_update_ie(fst_iface_get_group(iface));
203 fst_printf_iface(iface, MSG_DEBUG, MACSTR " became disconnected",
206 fst_ctrl_iface_notify_peer_state_change(iface, FALSE, addr);
210 Boolean fst_are_ifaces_aggregated(struct fst_iface *iface1,
211 struct fst_iface *iface2)
213 return fst_iface_get_group(iface1) == fst_iface_get_group(iface2);
217 enum mb_band_id fst_hw_mode_to_band(enum hostapd_hw_mode mode)
220 case HOSTAPD_MODE_IEEE80211B:
221 case HOSTAPD_MODE_IEEE80211G:
222 return MB_BAND_ID_WIFI_2_4GHZ;
223 case HOSTAPD_MODE_IEEE80211A:
224 return MB_BAND_ID_WIFI_5GHZ;
225 case HOSTAPD_MODE_IEEE80211AD:
226 return MB_BAND_ID_WIFI_60GHZ;
229 return MB_BAND_ID_WIFI_2_4GHZ;