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_get_rssi(struct usteer_measurement_report
*report
)
26 /* Apple devices always set the RSNI to 0, while
27 * it should be set to 255 in case RSNI is unavailable.
29 * For them, RCPI seems to be calculated as RCPI = 255 + (RSSI)
33 return report
->rcpi
- 255;
35 return (report
->rcpi
/ 2) - 110;
39 usteer_measurement_report_node_cleanup(struct usteer_node
*node
)
41 struct usteer_measurement_report
*mr
, *tmp
;
43 list_for_each_entry_safe(mr
, tmp
, &node
->measurements
, node_list
)
44 usteer_measurement_report_del(mr
);
48 usteer_measurement_report_sta_cleanup(struct sta
*sta
)
50 struct usteer_measurement_report
*mr
, *tmp
;
52 list_for_each_entry_safe(mr
, tmp
, &sta
->measurements
, sta_list
)
53 usteer_measurement_report_del(mr
);
56 struct usteer_measurement_report
*
57 usteer_measurement_report_get(struct sta
*sta
, struct usteer_node
*node
, bool create
)
59 struct usteer_measurement_report
*mr
;
61 list_for_each_entry(mr
, &sta
->measurements
, sta_list
) {
69 mr
= calloc(1, sizeof(*mr
));
73 /* Set node & add to nodes list */
75 list_add(&mr
->node_list
, &node
->measurements
);
77 /* Set sta & add to STAs list */
79 list_add(&mr
->sta_list
, &sta
->measurements
);
81 /* Add to Measurement list */
82 list_add(&mr
->list
, &measurements
);
84 /* Set measurement expiration */
85 usteer_timeout_set(&tq
, &mr
->timeout
, config
.measurement_report_timeout
);
90 struct usteer_measurement_report
*
91 usteer_measurement_report_add(struct sta
*sta
, struct usteer_node
*node
,
92 uint8_t rcpi
, uint8_t rsni
, uint64_t timestamp
)
94 struct usteer_measurement_report
*mr
= usteer_measurement_report_get(sta
, node
, true);
99 mr
->timestamp
= timestamp
;
104 usteer_timeout_set(&tq
, &mr
->timeout
, config
.measurement_report_timeout
);
110 usteer_measurement_report_del(struct usteer_measurement_report
*mr
)
112 usteer_timeout_cancel(&tq
, &mr
->timeout
);
113 list_del(&mr
->node_list
);
114 list_del(&mr
->sta_list
);
120 usteer_measurement_timeout(struct usteer_timeout_queue
*q
, struct usteer_timeout
*t
)
122 struct usteer_measurement_report
*mr
= container_of(t
, struct usteer_measurement_report
, timeout
);
124 usteer_measurement_report_del(mr
);
127 static void __usteer_init
usteer_measurement_init(void)
129 usteer_timeout_init(&tq
);
130 tq
.cb
= usteer_measurement_timeout
;