2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
15 * Copyright (C) 2021 David Bauer <mail@david-bauer.net>
20 LIST_HEAD(measurements
);
21 static struct usteer_timeout_queue tq
;
24 usteer_measurement_report_node_cleanup(struct usteer_node
*node
)
26 struct usteer_measurement_report
*mr
, *tmp
;
28 list_for_each_entry_safe(mr
, tmp
, &node
->measurements
, node_list
)
29 usteer_measurement_report_del(mr
);
33 usteer_measurement_report_sta_cleanup(struct sta
*sta
)
35 struct usteer_measurement_report
*mr
, *tmp
;
37 list_for_each_entry_safe(mr
, tmp
, &sta
->measurements
, sta_list
)
38 usteer_measurement_report_del(mr
);
41 struct usteer_measurement_report
*
42 usteer_measurement_report_get(struct sta
*sta
, struct usteer_node
*node
, bool create
)
44 struct usteer_measurement_report
*mr
;
46 list_for_each_entry(mr
, &sta
->measurements
, sta_list
) {
54 mr
= calloc(1, sizeof(*mr
));
58 /* Set node & add to nodes list */
60 list_add(&mr
->node_list
, &node
->measurements
);
62 /* Set sta & add to STAs list */
64 list_add(&mr
->sta_list
, &sta
->measurements
);
66 /* Add to Measurement list */
67 list_add(&mr
->list
, &measurements
);
69 /* Set measurement expiration */
70 usteer_timeout_set(&tq
, &mr
->timeout
, config
.measurement_report_timeout
);
75 struct usteer_measurement_report
*
76 usteer_measurement_report_add_beacon_report(struct sta
*sta
, struct usteer_node
*node
,
77 struct usteer_beacon_report
*br
, uint64_t timestamp
)
79 struct usteer_measurement_report
*mr
= usteer_measurement_report_get(sta
, node
, true);
84 mr
->timestamp
= timestamp
;
85 memcpy(&mr
->beacon_report
, br
, sizeof(*br
));
91 usteer_measurement_report_del(struct usteer_measurement_report
*mr
)
93 usteer_timeout_cancel(&tq
, &mr
->timeout
);
94 list_del(&mr
->node_list
);
95 list_del(&mr
->sta_list
);
101 usteer_measurement_timeout(struct usteer_timeout_queue
*q
, struct usteer_timeout
*t
)
103 struct usteer_measurement_report
*mr
= container_of(t
, struct usteer_measurement_report
, timeout
);
105 usteer_measurement_report_del(mr
);
108 static void __usteer_init
usteer_measurement_init(void)
110 usteer_timeout_init(&tq
);
111 tq
.cb
= usteer_measurement_timeout
;