From 54e40e09fbe1a889caec22aa87d8565ef7b98191 Mon Sep 17 00:00:00 2001 From: Janusz Dziedzic <janusz.dziedzic@iopsys.eu> Date: Fri, 13 May 2022 12:56:46 +0200 Subject: [PATCH] add generic opclass functions: - opclass_expired - opclass_get_if Signed-off-by: Janusz Dziedzic <janusz.dziedzic@iopsys.eu> --- src/cntlr.c | 2 +- src/cntlr_map.c | 24 ++---------------------- src/utils/opclass.c | 28 ++++++++++++++++++++++++++++ src/utils/opclass.h | 3 +++ 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/cntlr.c b/src/cntlr.c index 46ab1cf2..d957ac12 100644 --- a/src/cntlr.c +++ b/src/cntlr.c @@ -1203,7 +1203,7 @@ static bool cntlr_radio_opclass_expired(struct netif_radio *radio) if (!radio->opclass.entry_num) return true; - if (timestamp_expired(&radio->opclass.entry_time, 120000)) + if (opclass_expired(&radio->opclass, 120)) return true; return false; diff --git a/src/cntlr_map.c b/src/cntlr_map.c index 0f24e09c..086b8ab0 100644 --- a/src/cntlr_map.c +++ b/src/cntlr_map.c @@ -1273,26 +1273,6 @@ static void cntlr_request_bcn_metrics_bsta(struct controller *c, struct sta *s) } } -static uint8_t cntlr_get_opclass_ht20(struct netif_radio *nr, uint8_t channel) -{ - int i, j; - struct opclass_entry *entry; - - for (i = 0; i < nr->opclass.entry_num; i++) { - entry = &nr->opclass.entry[i]; - - if (entry->bandwidth != 20) - continue; - - for (j = 0; j < entry->channel_num; j++) { - if (entry->channel[j].channel == channel) - return entry->id; - } - } - - return 0; /* Not found */ -} - static int cntlr_request_bcn_metrics_sta(struct controller *c, struct sta *s) { struct cmdu_buff *bcn_cmdu; @@ -1325,7 +1305,7 @@ static int cntlr_request_bcn_metrics_sta(struct controller *c, struct sta *s) if (sp->channels_num == 1) { /* won't use channel report */ - opclass = cntlr_get_opclass_ht20(nr, sp->channels[0]); /* /20 */ + opclass = opclass_get_id(&nr->opclass, sp->channels[0], 20); if (!opclass) return -1; channel = sp->channels[0]; @@ -1334,7 +1314,7 @@ static int cntlr_request_bcn_metrics_sta(struct controller *c, struct sta *s) opclass = 0; channel = 255; /* use channel report */ for (i = 0; i < sp->channels_num; i++) { - opc = cntlr_get_opclass_ht20(nr, sp->channels[i]); + opc = opclass_get_id(&nr->opclass, sp->channels[i], 20); if (!opc) continue; op_ch[num_report].opclass = opc; diff --git a/src/utils/opclass.c b/src/utils/opclass.c index 913fec61..55191f93 100644 --- a/src/utils/opclass.c +++ b/src/utils/opclass.c @@ -104,6 +104,14 @@ int opclass_add_entry(struct opclass *opclass, struct opclass_entry *new) return ret; } +bool opclass_expired(struct opclass *opclass, uint32_t seconds) +{ + if (timestamp_expired(&opclass->entry_time, seconds * 1000)) + return true; + + return false; +} + void opclass_reset(struct opclass *opclass) { opclass->entry_num = 0; @@ -129,3 +137,23 @@ void opclass_dump(struct opclass *opclass) dbg("<<<\n"); } +uint8_t opclass_get_id(struct opclass *opclass, uint8_t channel, int bandwidth) +{ + struct opclass_entry *entry; + int i, j; + + for (i = 0; i < opclass->entry_num; i++) { + entry = &opclass->entry[i]; + + if (entry->bandwidth != bandwidth) + continue; + + for (j = 0; j < entry->channel_num; j++) { + if (entry->channel[j].channel == channel) + return entry->id; + } + } + + return 0; /* Not found */ +} + diff --git a/src/utils/opclass.h b/src/utils/opclass.h index 35b0586e..85e52935 100644 --- a/src/utils/opclass.h +++ b/src/utils/opclass.h @@ -43,7 +43,10 @@ struct opclass_channel *opclass_new_channel(struct opclass_entry *entry); int opclass_add_channel(struct opclass_entry *entry, struct opclass_channel *new); int opclass_add_entry(struct opclass *opclass, struct opclass_entry *new); +bool opclass_expired(struct opclass *opclass, uint32_t seconds); void opclass_reset(struct opclass *opclass); void opclass_dump(struct opclass *opclass); +uint8_t opclass_get_id(struct opclass *opclass, uint8_t channel, int bandwidth); + #endif /* _OPCLASS_H_ */ -- GitLab