xref: /freebsd/contrib/wpa/src/fst/fst_iface.c (revision 3750ccefb8629a08890bfbae894dd6bc6a7483b4)
1 /*
2  * FST module - FST interface object implementation
3  * Copyright (c) 2014, Qualcomm Atheros, Inc.
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #include "utils/includes.h"
10 #include "utils/common.h"
11 #include "fst/fst_internal.h"
12 #include "fst/fst_defs.h"
13 
14 
15 struct fst_iface * fst_iface_create(struct fst_group *g, const char *ifname,
16 				    const u8 *own_addr,
17 				    const struct fst_wpa_obj *iface_obj,
18 				    const struct fst_iface_cfg *cfg)
19 {
20 	struct fst_iface *i;
21 
22 	i = os_zalloc(sizeof(*i));
23 	if (!i) {
24 		fst_printf_group(g, MSG_ERROR, "cannot allocate iface for %s",
25 				ifname);
26 		return NULL;
27 	}
28 
29 	i->cfg = *cfg;
30 	i->iface_obj = *iface_obj;
31 	i->group = g;
32 	os_strlcpy(i->ifname, ifname, sizeof(i->ifname));
33 	os_memcpy(i->own_addr, own_addr, sizeof(i->own_addr));
34 
35 	if (!i->cfg.llt) {
36 		fst_printf_iface(i, MSG_WARNING, "Zero llt adjusted");
37 		i->cfg.llt = FST_DEFAULT_LLT_CFG_VALUE;
38 	}
39 
40 	return i;
41 }
42 
43 
44 void fst_iface_delete(struct fst_iface *i)
45 {
46 	fst_iface_set_ies(i, NULL);
47 	wpabuf_free(i->mb_ie);
48 	os_free(i);
49 }
50 
51 
52 bool fst_iface_is_connected(struct fst_iface *iface, const u8 *addr,
53 			    bool mb_only)
54 {
55 	struct fst_get_peer_ctx *ctx;
56 	const u8 *a = fst_iface_get_peer_first(iface, &ctx, mb_only);
57 
58 	for (; a != NULL; a = fst_iface_get_peer_next(iface, &ctx, mb_only))
59 		if (ether_addr_equal(addr, a))
60 			return true;
61 
62 	return false;
63 }
64 
65 
66 void fst_iface_attach_mbie(struct fst_iface *i, struct wpabuf *mbie)
67 {
68 	wpabuf_free(i->mb_ie);
69 	i->mb_ie = mbie;
70 }
71 
72 
73 enum mb_band_id fst_iface_get_band_id(struct fst_iface *i)
74 {
75 	enum hostapd_hw_mode hw_mode;
76 	u8 channel;
77 
78 	fst_iface_get_channel_info(i, &hw_mode, &channel);
79 	return fst_hw_mode_to_band(hw_mode);
80 }
81