xref: /freebsd/contrib/wpa/src/ap/bss_load.c (revision f4b37ed0f8b307b1f3f0f630ca725d68f1dff30d)
1 /*
2  * BSS Load Element / Channel Utilization
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 
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "hostapd.h"
14 #include "bss_load.h"
15 #include "ap_drv_ops.h"
16 #include "beacon.h"
17 
18 
19 static void update_channel_utilization(void *eloop_data, void *user_data)
20 {
21 	struct hostapd_data *hapd = eloop_data;
22 	unsigned int sec, usec;
23 	int err;
24 
25 	if (!(hapd->beacon_set_done && hapd->started))
26 		return;
27 
28 	err = hostapd_drv_get_survey(hapd, hapd->iface->freq);
29 	if (err) {
30 		wpa_printf(MSG_ERROR, "BSS Load: Failed to get survey data");
31 		return;
32 	}
33 
34 	ieee802_11_set_beacon(hapd);
35 
36 	sec = ((hapd->bss_load_update_timeout / 1000) * 1024) / 1000;
37 	usec = (hapd->bss_load_update_timeout % 1000) * 1024;
38 	eloop_register_timeout(sec, usec, update_channel_utilization, hapd,
39 			       NULL);
40 }
41 
42 
43 int bss_load_update_init(struct hostapd_data *hapd)
44 {
45 	struct hostapd_bss_config *conf = hapd->conf;
46 	struct hostapd_config *iconf = hapd->iconf;
47 	unsigned int sec, usec;
48 
49 	if (!conf->bss_load_update_period || !iconf->beacon_int)
50 		return -1;
51 
52 	hapd->bss_load_update_timeout = conf->bss_load_update_period *
53 					iconf->beacon_int;
54 	sec = ((hapd->bss_load_update_timeout / 1000) * 1024) / 1000;
55 	usec = (hapd->bss_load_update_timeout % 1000) * 1024;
56 	eloop_register_timeout(sec, usec, update_channel_utilization, hapd,
57 			       NULL);
58 	return 0;
59 }
60 
61 
62 void bss_load_update_deinit(struct hostapd_data *hapd)
63 {
64 	eloop_cancel_timeout(update_channel_utilization, hapd, NULL);
65 }
66