xref: /freebsd/contrib/wpa/src/fst/fst_iface.c (revision a90b9d0159070121c221b966469c3e36d912bf82)
1325151a3SRui Paulo /*
2325151a3SRui Paulo  * FST module - FST interface object implementation
3325151a3SRui Paulo  * Copyright (c) 2014, Qualcomm Atheros, Inc.
4325151a3SRui Paulo  *
5325151a3SRui Paulo  * This software may be distributed under the terms of the BSD license.
6325151a3SRui Paulo  * See README for more details.
7325151a3SRui Paulo  */
8325151a3SRui Paulo 
9325151a3SRui Paulo #include "utils/includes.h"
10325151a3SRui Paulo #include "utils/common.h"
11325151a3SRui Paulo #include "fst/fst_internal.h"
12325151a3SRui Paulo #include "fst/fst_defs.h"
13325151a3SRui Paulo 
14325151a3SRui Paulo 
fst_iface_create(struct fst_group * g,const char * ifname,const u8 * own_addr,const struct fst_wpa_obj * iface_obj,const struct fst_iface_cfg * cfg)15325151a3SRui Paulo struct fst_iface * fst_iface_create(struct fst_group *g, const char *ifname,
16325151a3SRui Paulo 				    const u8 *own_addr,
17325151a3SRui Paulo 				    const struct fst_wpa_obj *iface_obj,
18325151a3SRui Paulo 				    const struct fst_iface_cfg *cfg)
19325151a3SRui Paulo {
20325151a3SRui Paulo 	struct fst_iface *i;
21325151a3SRui Paulo 
22325151a3SRui Paulo 	i = os_zalloc(sizeof(*i));
23325151a3SRui Paulo 	if (!i) {
24325151a3SRui Paulo 		fst_printf_group(g, MSG_ERROR, "cannot allocate iface for %s",
25325151a3SRui Paulo 				ifname);
26325151a3SRui Paulo 		return NULL;
27325151a3SRui Paulo 	}
28325151a3SRui Paulo 
29325151a3SRui Paulo 	i->cfg = *cfg;
30325151a3SRui Paulo 	i->iface_obj = *iface_obj;
31325151a3SRui Paulo 	i->group = g;
32325151a3SRui Paulo 	os_strlcpy(i->ifname, ifname, sizeof(i->ifname));
33325151a3SRui Paulo 	os_memcpy(i->own_addr, own_addr, sizeof(i->own_addr));
34325151a3SRui Paulo 
35325151a3SRui Paulo 	if (!i->cfg.llt) {
36325151a3SRui Paulo 		fst_printf_iface(i, MSG_WARNING, "Zero llt adjusted");
37325151a3SRui Paulo 		i->cfg.llt = FST_DEFAULT_LLT_CFG_VALUE;
38325151a3SRui Paulo 	}
39325151a3SRui Paulo 
40325151a3SRui Paulo 	return i;
41325151a3SRui Paulo }
42325151a3SRui Paulo 
43325151a3SRui Paulo 
fst_iface_delete(struct fst_iface * i)44325151a3SRui Paulo void fst_iface_delete(struct fst_iface *i)
45325151a3SRui Paulo {
46325151a3SRui Paulo 	fst_iface_set_ies(i, NULL);
47325151a3SRui Paulo 	wpabuf_free(i->mb_ie);
48325151a3SRui Paulo 	os_free(i);
49325151a3SRui Paulo }
50325151a3SRui Paulo 
51325151a3SRui Paulo 
fst_iface_is_connected(struct fst_iface * iface,const u8 * addr,bool mb_only)52c1d255d3SCy Schubert bool fst_iface_is_connected(struct fst_iface *iface, const u8 *addr,
53c1d255d3SCy Schubert 			    bool mb_only)
54325151a3SRui Paulo {
55325151a3SRui Paulo 	struct fst_get_peer_ctx *ctx;
56780fb4a2SCy Schubert 	const u8 *a = fst_iface_get_peer_first(iface, &ctx, mb_only);
57325151a3SRui Paulo 
58780fb4a2SCy Schubert 	for (; a != NULL; a = fst_iface_get_peer_next(iface, &ctx, mb_only))
59*a90b9d01SCy Schubert 		if (ether_addr_equal(addr, a))
60c1d255d3SCy Schubert 			return true;
61325151a3SRui Paulo 
62c1d255d3SCy Schubert 	return false;
63325151a3SRui Paulo }
64325151a3SRui Paulo 
65325151a3SRui Paulo 
fst_iface_attach_mbie(struct fst_iface * i,struct wpabuf * mbie)66325151a3SRui Paulo void fst_iface_attach_mbie(struct fst_iface *i, struct wpabuf *mbie)
67325151a3SRui Paulo {
68325151a3SRui Paulo 	wpabuf_free(i->mb_ie);
69325151a3SRui Paulo 	i->mb_ie = mbie;
70325151a3SRui Paulo }
71325151a3SRui Paulo 
72325151a3SRui Paulo 
fst_iface_get_band_id(struct fst_iface * i)73325151a3SRui Paulo enum mb_band_id fst_iface_get_band_id(struct fst_iface *i)
74325151a3SRui Paulo {
75325151a3SRui Paulo 	enum hostapd_hw_mode hw_mode;
76325151a3SRui Paulo 	u8 channel;
77325151a3SRui Paulo 
78325151a3SRui Paulo 	fst_iface_get_channel_info(i, &hw_mode, &channel);
79325151a3SRui Paulo 	return fst_hw_mode_to_band(hw_mode);
80325151a3SRui Paulo }
81