Skip to main content
Sign in
Snippets Groups Projects
Commit 88f8ff1d authored by Janusz Dziedzic's avatar Janusz Dziedzic
Browse files

refactor opclass structure


After that we can use it for both
agent and controller.

Signed-off-by: default avatarJanusz Dziedzic <janusz.dziedzic@iopsys.eu>
parent a3884728
No related branches found
No related tags found
No related merge requests found
...@@ -1139,9 +1139,9 @@ static struct opclass_entry *cntlr_radio_opclass_find_entry(struct opclass *opcl ...@@ -1139,9 +1139,9 @@ static struct opclass_entry *cntlr_radio_opclass_find_entry(struct opclass *opcl
struct opclass_entry *entry; struct opclass_entry *entry;
int i; int i;
for (i = 0; i < opclass->opclass_entry_num; i++) { for (i = 0; i < opclass->entry_num; i++) {
entry = &opclass->opclass_entry[i]; entry = &opclass->entry[i];
if (entry->opclass != id) if (entry->id != id)
continue; continue;
return entry; return entry;
...@@ -1154,12 +1154,12 @@ static struct opclass_entry *cntlr_radio_opclass_new_entry(struct opclass *opcla ...@@ -1154,12 +1154,12 @@ static struct opclass_entry *cntlr_radio_opclass_new_entry(struct opclass *opcla
{ {
struct opclass_entry *entry; struct opclass_entry *entry;
if (opclass->opclass_entry_num >= ARRAY_SIZE(opclass->opclass_entry)) if (opclass->entry_num >= ARRAY_SIZE(opclass->entry))
return NULL; return NULL;
entry = &opclass->opclass_entry[opclass->opclass_entry_num]; entry = &opclass->entry[opclass->entry_num];
opclass->opclass_entry_num++; opclass->entry_num++;
opclass->opclass_entry_time = time(NULL); opclass->entry_time = time(NULL);
return entry; return entry;
} }
...@@ -1189,8 +1189,8 @@ static int cntlr_radio_opclass_add_channel(struct opclass_entry *entry, uint8_t ...@@ -1189,8 +1189,8 @@ static int cntlr_radio_opclass_add_channel(struct opclass_entry *entry, uint8_t
static void _cntlr_radio_opclass_reset(struct opclass *opclass) static void _cntlr_radio_opclass_reset(struct opclass *opclass)
{ {
opclass->opclass_entry_num = 0; opclass->entry_num = 0;
memset(opclass->opclass_entry, 0, sizeof(opclass->opclass_entry)); memset(opclass->entry, 0, sizeof(opclass->entry));
} }
static void _cntlr_radio_opclass_dump(struct opclass *opclass) static void _cntlr_radio_opclass_dump(struct opclass *opclass)
...@@ -1198,10 +1198,10 @@ static void _cntlr_radio_opclass_dump(struct opclass *opclass) ...@@ -1198,10 +1198,10 @@ static void _cntlr_radio_opclass_dump(struct opclass *opclass)
struct opclass_entry *entry; struct opclass_entry *entry;
int i, j; int i, j;
dbg(">>> opclass num: %d\n", opclass->opclass_entry_num); dbg(">>> opclass num: %d\n", opclass->entry_num);
for (i = 0; i < opclass->opclass_entry_num; i++) { for (i = 0; i < opclass->entry_num; i++) {
entry = &opclass->opclass_entry[i]; entry = &opclass->entry[i];
dbg("opclass: %u\n", entry->opclass); dbg("opclass: %u\n", entry->id);
for (j = 0; j < entry->channels_num; j++) { for (j = 0; j < entry->channels_num; j++) {
dbg("\tchan %u pref %u reason %u\n", dbg("\tchan %u pref %u reason %u\n",
entry->channels[j].channel, entry->channels[j].channel,
...@@ -1217,19 +1217,19 @@ void cntlr_radio_opclass_reset(struct netif_radio *radio) ...@@ -1217,19 +1217,19 @@ void cntlr_radio_opclass_reset(struct netif_radio *radio)
_cntlr_radio_opclass_reset(&radio->opclass); _cntlr_radio_opclass_reset(&radio->opclass);
} }
int cntlr_radio_opclass_add(struct netif_radio *radio, uint8_t opclass, int cntlr_radio_opclass_add(struct netif_radio *radio, uint8_t id,
uint8_t channel, uint8_t preference) uint8_t channel, uint8_t preference)
{ {
struct opclass_entry *entry; struct opclass_entry *entry;
entry = cntlr_radio_opclass_find_entry(&radio->opclass, opclass); entry = cntlr_radio_opclass_find_entry(&radio->opclass, id);
if (!entry) if (!entry)
entry = cntlr_radio_opclass_new_entry(&radio->opclass); entry = cntlr_radio_opclass_new_entry(&radio->opclass);
if (!entry) if (!entry)
return -1; return -1;
entry->opclass = opclass; entry->id = id;
entry->bw = get_op_class_bw(opclass); entry->bandwidth = get_op_class_bw(id);
return cntlr_radio_opclass_add_channel(entry, channel, preference); return cntlr_radio_opclass_add_channel(entry, channel, preference);
} }
...@@ -1243,20 +1243,20 @@ void cntlr_radio_cur_opclass_reset(struct netif_radio *radio) ...@@ -1243,20 +1243,20 @@ void cntlr_radio_cur_opclass_reset(struct netif_radio *radio)
_cntlr_radio_opclass_reset(&radio->cur_opclass); _cntlr_radio_opclass_reset(&radio->cur_opclass);
} }
int cntlr_radio_cur_opclass_add(struct netif_radio *radio, uint8_t opclass, int cntlr_radio_cur_opclass_add(struct netif_radio *radio, uint8_t id,
uint8_t channel, uint8_t txpower) uint8_t channel, uint8_t txpower)
{ {
struct opclass_entry *entry; struct opclass_entry *entry;
entry = cntlr_radio_opclass_find_entry(&radio->cur_opclass, opclass); entry = cntlr_radio_opclass_find_entry(&radio->cur_opclass, id);
if (!entry) if (!entry)
entry = cntlr_radio_opclass_new_entry(&radio->cur_opclass); entry = cntlr_radio_opclass_new_entry(&radio->cur_opclass);
if (!entry) if (!entry)
return -1; return -1;
entry->opclass = opclass; entry->id = id;
entry->bw = get_op_class_bw(opclass); entry->bandwidth = get_op_class_bw(id);
entry->txpower = txpower; entry->max_txpower = txpower;
return cntlr_radio_opclass_add_channel(entry, channel, 15 << 4); return cntlr_radio_opclass_add_channel(entry, channel, 15 << 4);
} }
...@@ -1269,10 +1269,10 @@ static bool cntlr_radio_opclass_expired(struct netif_radio *radio) ...@@ -1269,10 +1269,10 @@ static bool cntlr_radio_opclass_expired(struct netif_radio *radio)
{ {
time_t age; time_t age;
if (!radio->opclass.opclass_entry_num) if (!radio->opclass.entry_num)
return true; return true;
age = time(NULL) - radio->opclass.opclass_entry_time; age = time(NULL) - radio->opclass.entry_time;
if (((unsigned int) age) > 120) if (((unsigned int) age) > 120)
return true; return true;
...@@ -1297,8 +1297,8 @@ static enum wifi_freqband cntlr_radio_opclass_get_band(struct opclass *opclass) ...@@ -1297,8 +1297,8 @@ static enum wifi_freqband cntlr_radio_opclass_get_band(struct opclass *opclass)
enum wifi_freqband ret = 0; enum wifi_freqband ret = 0;
int i; int i;
for (i = 0; i < opclass->opclass_entry_num; i++) { for (i = 0; i < opclass->entry_num; i++) {
band = get_op_class_band(opclass->opclass_entry[i].opclass); band = get_op_class_band(opclass->entry[i].id);
if (band == BAND_UNKNOWN) if (band == BAND_UNKNOWN)
continue; continue;
ret |= band; ret |= band;
... ...
......
...@@ -251,22 +251,34 @@ struct netif_link { ...@@ -251,22 +251,34 @@ struct netif_link {
struct list_head list; struct list_head list;
}; };
enum opclass_dfs {
OPCLASS_CHANNEL_DFS_NONE,
OPCLASS_CHANNEL_DFS_USABLE,
OPCLASS_CHANNEL_DFS_AVAILABLE,
OPCLASS_CHANNEL_DFS_NOP,
OPCLASS_CHANNEL_DFS_CAC,
};
struct opclass_entry { struct opclass_entry {
uint8_t opclass; uint8_t id;
int bw; int bandwidth;
int txpower; int max_txpower;
int channels_num; int channels_num;
struct { struct {
uint8_t channel; uint8_t channel;
uint8_t preference; uint8_t preference;
enum opclass_dfs dfs;
uint32_t cac_time;
uint32_t nop_time;
} channels[64]; } channels[64];
}; };
struct opclass { struct opclass {
struct opclass_entry opclass_entry[64]; struct opclass_entry entry[64];
int opclass_entry_num; int entry_num;
time_t opclass_entry_time; time_t entry_time;
}; };
/* TODO - fill this structure */ /* TODO - fill this structure */
... ...
......
...@@ -53,15 +53,15 @@ int cntlr_acs_radio_channel_recalc(struct netif_radio *radio, struct acs_params ...@@ -53,15 +53,15 @@ int cntlr_acs_radio_channel_recalc(struct netif_radio *radio, struct acs_params
dbg("acs radio channel recalc " MACFMT " opclass %d bw %d skip_dfs %d\n", MAC2STR(radio->macaddr), dbg("acs radio channel recalc " MACFMT " opclass %d bw %d skip_dfs %d\n", MAC2STR(radio->macaddr),
params->opclass, params->bw, params->skip_dfs); params->opclass, params->bw, params->skip_dfs);
for (i = 0; i < opclass->opclass_entry_num; i++) { for (i = 0; i < opclass->entry_num; i++) {
entry = &opclass->opclass_entry[i]; entry = &opclass->entry[i];
/* First check if opclass set */ /* First check if opclass set */
if (params->opclass && params->opclass != entry->opclass) if (params->opclass && params->opclass != entry->id)
continue; continue;
/* Next check if bandwidth set */ /* Next check if bandwidth set */
if (params->bw && params->bw != entry->bw) if (params->bw && params->bw != entry->bandwidth)
continue; continue;
for (j = 0; j < entry->channels_num; j++) { for (j = 0; j < entry->channels_num; j++) {
...@@ -100,8 +100,8 @@ int cntlr_acs_radio_channel_recalc(struct netif_radio *radio, struct acs_params ...@@ -100,8 +100,8 @@ int cntlr_acs_radio_channel_recalc(struct netif_radio *radio, struct acs_params
pref_best = pref; pref_best = pref;
acs_params[acs_params_num].best_channel = chan; acs_params[acs_params_num].best_channel = chan;
acs_params[acs_params_num].best_opclass = entry->opclass; acs_params[acs_params_num].best_opclass = entry->id;
acs_params[acs_params_num].best_bw = entry->bw; acs_params[acs_params_num].best_bw = entry->bandwidth;
acs_params[acs_params_num].best_pref = pref; acs_params[acs_params_num].best_pref = pref;
acs_params_num++; acs_params_num++;
...@@ -175,13 +175,13 @@ static int cntlr_get_current_acs_params(struct netif_radio *radio, struct acs_pa ...@@ -175,13 +175,13 @@ static int cntlr_get_current_acs_params(struct netif_radio *radio, struct acs_pa
{ {
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
if (!radio->cur_opclass.opclass_entry_num) if (!radio->cur_opclass.entry_num)
return -1; return -1;
params->opclass = radio->cur_opclass.opclass_entry[0].opclass; params->opclass = radio->cur_opclass.entry[0].id;
params->bw = radio->cur_opclass.opclass_entry[0].bw; params->bw = radio->cur_opclass.entry[0].bandwidth;
params->best_channel = radio->cur_opclass.opclass_entry[0].channels[0].channel; params->best_channel = radio->cur_opclass.entry[0].channels[0].channel;
params->best_bw = params->bw; params->best_bw = params->bw;
params->best_opclass = params->opclass; params->best_opclass = params->opclass;
...@@ -251,7 +251,7 @@ static bool cntlr_dfs_get_usable(struct opclass_entry *entry, struct cac_data *c ...@@ -251,7 +251,7 @@ static bool cntlr_dfs_get_usable(struct opclass_entry *entry, struct cac_data *c
/* Usable - we can run CAC */ /* Usable - we can run CAC */
if (reas == CHANNEL_PREF_REASON_DFS_USABLE) { if (reas == CHANNEL_PREF_REASON_DFS_USABLE) {
cac_data->channel = entry->channels[i].channel; cac_data->channel = entry->channels[i].channel;
cac_data->opclass = entry->opclass; cac_data->opclass = entry->id;
return true; return true;
} }
} }
...@@ -286,17 +286,17 @@ static bool cntlr_dfs_get_cac_data(struct netif_radio *radio, struct cac_data *c ...@@ -286,17 +286,17 @@ static bool cntlr_dfs_get_cac_data(struct netif_radio *radio, struct cac_data *c
opclass = &radio->opclass; opclass = &radio->opclass;
cur_opclass = &radio->cur_opclass; cur_opclass = &radio->cur_opclass;
for (i = 0; i < opclass->opclass_entry_num; i++) { for (i = 0; i < opclass->entry_num; i++) {
entry = &opclass->opclass_entry[i]; entry = &opclass->entry[i];
if (entry->bw != cur_opclass->opclass_entry[0].bw) if (entry->bandwidth != cur_opclass->entry[0].bandwidth)
continue; continue;
if (!cntlr_dfs_get_usable(entry, cac_data)) if (!cntlr_dfs_get_usable(entry, cac_data))
continue; continue;
/* TODO check chan/bw - not only control channel */ /* TODO check chan/bw - not only control channel */
if (cac_data->channel == cur_opclass->opclass_entry[0].channels[0].channel) if (cac_data->channel == cur_opclass->entry[0].channels[0].channel)
continue; continue;
/* TODO define this in ieee1905 */ /* TODO define this in ieee1905 */
... ...
......
...@@ -73,8 +73,8 @@ static void _cntlr_update_steer_params(struct controller *c, struct opclass *op) ...@@ -73,8 +73,8 @@ static void _cntlr_update_steer_params(struct controller *c, struct opclass *op)
struct opclass_entry *oe; struct opclass_entry *oe;
struct steering *sp; struct steering *sp;
for (i = 0; i < op->opclass_entry_num; i++) { for (i = 0; i < op->entry_num; i++) {
oe = &op->opclass_entry[i]; oe = &op->entry[i];
for (j = 0; j < oe->channels_num; j++) { for (j = 0; j < oe->channels_num; j++) {
sp = &c->steer_params; sp = &c->steer_params;
found = false; found = false;
...@@ -1234,13 +1234,13 @@ static int cntlr_request_usta_metrics(struct controller *c, ...@@ -1234,13 +1234,13 @@ static int cntlr_request_usta_metrics(struct controller *c,
if (!r || !fh) if (!r || !fh)
return -1; return -1;
for (j = 0; j < r->cur_opclass.opclass_entry_num; j++) { for (j = 0; j < r->cur_opclass.entry_num; j++) {
metrics[0].channel = fh->channel; metrics[0].channel = fh->channel;
metrics[0].num_sta = 1; metrics[0].num_sta = 1;
memcpy(metrics[0].sta[0].macaddr, s->macaddr, 6); memcpy(metrics[0].sta[0].macaddr, s->macaddr, 6);
usta_cmdu = cntlr_gen_unassoc_sta_metric_query(c, usta_cmdu = cntlr_gen_unassoc_sta_metric_query(c,
n->alid, r->cur_opclass.opclass_entry[j].opclass, 1, metrics); n->alid, r->cur_opclass.entry[j].id, 1, metrics);
if (usta_cmdu) { if (usta_cmdu) {
send_cmdu(c, usta_cmdu); send_cmdu(c, usta_cmdu);
...@@ -1278,15 +1278,15 @@ static uint8_t cntlr_get_opclass_ht20(struct netif_radio *nr, uint8_t channel) ...@@ -1278,15 +1278,15 @@ static uint8_t cntlr_get_opclass_ht20(struct netif_radio *nr, uint8_t channel)
int i, j; int i, j;
struct opclass_entry *entry; struct opclass_entry *entry;
for (i = 0; i < nr->opclass.opclass_entry_num; i++) { for (i = 0; i < nr->opclass.entry_num; i++) {
entry = &nr->opclass.opclass_entry[i]; entry = &nr->opclass.entry[i];
if (entry->bw != 20) if (entry->bandwidth != 20)
continue; continue;
for (j = 0; j < entry->channels_num; j++) { for (j = 0; j < entry->channels_num; j++) {
if (entry->channels[j].channel == channel) if (entry->channels[j].channel == channel)
return entry->opclass; return entry->id;
} }
} }
... ...
......
...@@ -438,24 +438,24 @@ static void cntlr_status_add_opclass(struct blob_buf *bb, struct opclass *opclas ...@@ -438,24 +438,24 @@ static void cntlr_status_add_opclass(struct blob_buf *bb, struct opclass *opclas
/* Add age */ /* Add age */
snprintf(age, sizeof(age), "%s_age", name); snprintf(age, sizeof(age), "%s_age", name);
blobmsg_add_u32(bb, age, (uint32_t) (time(NULL) - opclass->opclass_entry_time)); blobmsg_add_u32(bb, age, (uint32_t) (time(NULL) - opclass->entry_time));
a = blobmsg_open_array(bb, name); a = blobmsg_open_array(bb, name);
for (j = 0; j < opclass->opclass_entry_num; j++) { for (j = 0; j < opclass->entry_num; j++) {
if (opclass->opclass_entry[j].bw < bw_higher) if (opclass->entry[j].bandwidth < bw_higher)
continue; continue;
t = blobmsg_open_table(bb, ""); t = blobmsg_open_table(bb, "");
blobmsg_add_u32(bb, "opclass", opclass->opclass_entry[j].opclass); blobmsg_add_u32(bb, "opclass", opclass->entry[j].id);
blobmsg_add_u32(bb, "bandwidth", opclass->opclass_entry[j].bw); blobmsg_add_u32(bb, "bandwidth", opclass->entry[j].bandwidth);
if (strstr(name, "cur")) if (strstr(name, "cur"))
blobmsg_add_u32(bb, "txpower", opclass->opclass_entry[j].txpower); blobmsg_add_u32(bb, "txpower", opclass->entry[j].max_txpower);
aa = blobmsg_open_array(bb, "channels"); aa = blobmsg_open_array(bb, "channels");
for (k = 0; k < opclass->opclass_entry[j].channels_num; k++) { for (k = 0; k < opclass->entry[j].channels_num; k++) {
tt = blobmsg_open_table(bb, ""); tt = blobmsg_open_table(bb, "");
blobmsg_add_u32(bb, "channel", opclass->opclass_entry[j].channels[k].channel); blobmsg_add_u32(bb, "channel", opclass->entry[j].channels[k].channel);
if (!strstr(name, "cur")) { if (!strstr(name, "cur")) {
pref = (opclass->opclass_entry[j].channels[k].preference & CHANNEL_PREF_MASK) >> 4; pref = (opclass->entry[j].channels[k].preference & CHANNEL_PREF_MASK) >> 4;
reas = opclass->opclass_entry[j].channels[k].preference & CHANNEL_PREF_REASON; reas = opclass->entry[j].channels[k].preference & CHANNEL_PREF_REASON;
blobmsg_add_u32(bb, "preference", pref); blobmsg_add_u32(bb, "preference", pref);
blobmsg_add_string(bb, "reason", cntrl_status_reason(reas)); blobmsg_add_string(bb, "reason", cntrl_status_reason(reas));
} }
...@@ -521,8 +521,8 @@ static int cntlr_status(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -521,8 +521,8 @@ static int cntlr_status(struct ubus_context *ctx, struct ubus_object *obj,
cntlr_status_add_opclass(&bb, &p->cur_opclass, "cur_opclass", 20); cntlr_status_add_opclass(&bb, &p->cur_opclass, "cur_opclass", 20);
/* Limit opclass output if possible */ /* Limit opclass output if possible */
if (p->cur_opclass.opclass_entry_num) if (p->cur_opclass.entry_num)
limit_bw = p->cur_opclass.opclass_entry[0].bw; limit_bw = p->cur_opclass.entry[0].bandwidth;
cntlr_status_add_opclass(&bb, &p->opclass, "opclass", limit_bw); cntlr_status_add_opclass(&bb, &p->opclass, "opclass", limit_bw);
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment