Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
}
uci_foreach_element(&pkg->sections, e) {
struct uci_section *s = uci_to_section(e);
struct uci_element *x, *tmp;
struct uci_option *op;
if (strcmp(s->type, section))
continue;
/* iter through matched 'section' for the 'option' */
uci_foreach_element_safe(&s->options, tmp, x) {
if (strcmp(x->name, option))
continue;
op = uci_to_option(x);
if (op->type == UCI_TYPE_LIST) {
uci_foreach_element(&op->v.list, x) {
if (!strncmp(x->name, value, len)) {
if (!add)
config_update_entry(ctx,
goto out_exit;
}
}
/* add new exclude at end of list */
if (add)
config_update_entry(ctx, pkg, s, option,
1, value, len);
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
goto out_exit;
}
}
/* 'option' name not present in 'section'
* Create a new one at end of 'section'.
*/
if (add)
config_update_entry(ctx, pkg, s, option, 1, value, len);
goto out_exit;
}
out_exit:
uci_free_context(ctx);
return 0;
}
int config_update2(const char *confname, struct agent_config *cfg,
const char *section_type,
const char *match_option,
const char *match_option_value,
const char *option,
int add,
void *value, int len)
{
struct uci_context *ctx = NULL;
struct uci_package *pkg = NULL;
struct uci_element *e;
ctx = uci_alloc_context();
if (ctx && uci_load(ctx, confname, &pkg) != UCI_OK) {
dbg("config file '%s' not found!\n", confname);
free(ctx);
return -1;
}
uci_foreach_element(&pkg->sections, e) {
struct uci_section *s = uci_to_section(e);
struct uci_element *x, *tmp;
struct uci_option *op;
const char *optstring;
if (strcmp(s->type, section_type))
continue;
if (match_option && match_option_value) {
optstring = uci_lookup_option_string(ctx, s,
match_option);
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
if (!optstring || strcmp(optstring, match_option_value))
continue;
}
/* iter through matched 'section' for the 'option' */
uci_foreach_element_safe(&s->options, tmp, x) {
if (strcmp(x->name, option))
continue;
op = uci_to_option(x);
if (op->type == UCI_TYPE_LIST) {
uci_foreach_element(&op->v.list, x) {
if (!strncmp(x->name, value, len)) {
if (!add) {
config_update_entry(ctx,
pkg, s, option,
0, value, len);
}
goto out_exit;
}
}
/* add new 'option' at end of list */
if (add) {
config_update_entry(ctx, pkg, s, option,
1, value, len);
}
goto out_exit;
}
}
/* 'option' name not present in 'section'
* Create a new one at end of 'section'.
*/
if (add)
config_update_entry(ctx, pkg, s, option,
1, value, len);
goto out_exit;
}
out_exit:
uci_free_context(ctx);
return 0;
}
#if 0
struct config uci_config = {
.name = "uci",
.priv = uci_ctx;
.get = uci_get_config,
.set = uci_set_config,
.init = uci_setup,
.exit = uci_exit,
};
#define priv_get_config(priv) container_of(priv, struct config, priv)
void register_config(struct config *c)
{
static struct uci_context *ctx;
static struct uci_package *pkg;
struct uci_element *e;
int ret = 0;
if (uci_ctx)
return priv_get_config(uci_ctx);
ctx = uci_alloc_context();
if (ctx) {
uci_ctx = ctx;
memcpy(c, &uci_config, sizeof(*cfg));
}
if (uci_load(ctx, "wifiagent", &pkg))
return -1;
uci_foreach_element(&pkg->sections, e) {
struct uci_section *s = uci_to_section(e);
const char *option_val;
if (strcmp(s->type, "wifiagent"))
continue;
option_val = uci_lookup_option_string(ctx, s, name);
if (option_val)
sprintf(val, "%s", option_val);
else
ret = -1;
}
uci_free_context(ctx);
return ret;
}
#endif
static int agent_config_get_wifi_agent(struct agent_config *a,
struct uci_section *s)
{
enum {
A_ENABLED,
NUM_POLICIES
};
const struct uci_parse_option opts[] = {
{ .name = "enabled", .type = UCI_TYPE_STRING },
{ .name = "debug", .type = UCI_TYPE_STRING },
{ .name = "profile", .type = UCI_TYPE_STRING },
};
struct uci_option *tb[NUM_POLICIES];
uci_parse_section(s, opts, NUM_POLICIES, tb);
if (tb[A_ENABLED])
a->enabled = atoi(tb[A_ENABLED]->v.string) == 1 ? true : false;
if (tb[A_DEBUG]) {
a->debug_level = atoi(tb[A_DEBUG]->v.string);
if (verbose < a->debug_level)
verbose = a->debug_level;
}
if (tb[A_PROFILE])
a->profile = atoi(tb[A_PROFILE]->v.string);
static int agent_config_get_bk_iface(struct agent_config *a,
struct uci_section *s)
{
enum {
BK_IFNAME,
BK_ENABLED,
BK_ONBOARDED,
NUM_POLICIES
};
const struct uci_parse_option opts[] = {
{ .name = "ifname", .type = UCI_TYPE_STRING },
{ .name = "band", .type = UCI_TYPE_STRING },
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
{ .name = "enabled", .type = UCI_TYPE_STRING },
{ .name = "onboarded", .type = UCI_TYPE_STRING }
};
struct uci_option *tb[NUM_POLICIES];
struct netif_bkcfg *bk;
const char *ifname;
uci_parse_section(s, opts, NUM_POLICIES, tb);
if (tb[BK_IFNAME]) {
ifname = tb[BK_IFNAME]->v.string;
bk = get_netif_bkcfg_by_name(a, ifname);
if (!bk) {
bk = create_backhaul_iface_config(a, ifname);
if (!bk) {
warn("%s: OOM!\n", __func__);
return -1;
}
} else {
warn("Duplicate 'bk-iface %s' config!! ignore\n",
ifname);
}
} else {
warn("No ifname in bk-iface section!\n");
return -1;
}
if (tb[BK_ENABLED])
bk->enabled = atoi(tb[BK_ENABLED]->v.string);
if (tb[BK_ONBOARDED])
bk->onboarded = atoi(tb[BK_ONBOARDED]->v.string);
if (tb[BK_BAND]) {
int band = atoi(tb[BK_BAND]->v.string);
if (band == 2)
bk->band = BAND_2;
else if (band == 5)
bk->band = BAND_5;
}
static int agent_config_get_fh_iface(struct agent_config *a,
{
enum {
FH_IFNAME,
FH_STEER,
FH_EXCLUDE,
FH_EXCLUDE_BTM,
FH_ASSOC_CTRL,
FH_BTM_RETRY,
FH_BTM_RETRY_SECS,
FH_FLBK_LEGACY,
FH_STEER_LEGACY_RASSOC_SECS,
FH_STEER_LEGACY_RETRY_SECS,
FH_ASSOC_CTRL_SECS,
NUM_POLICIES,
};
const struct uci_parse_option opts[] = {
{ .name = "ifname", .type = UCI_TYPE_STRING },
{ .name = "band", .type = UCI_TYPE_STRING },
{ .name = "steer", .type = UCI_TYPE_LIST },
{ .name = "exclude", .type = UCI_TYPE_LIST },
{ .name = "exclude_btm", .type = UCI_TYPE_LIST },
{ .name = "assoc_ctrl", .type = UCI_TYPE_LIST },
{ .name = "btm_retry", .type = UCI_TYPE_STRING },
{ .name = "btm_retry_secs", .type = UCI_TYPE_STRING },
{ .name = "fallback_legacy", .type = UCI_TYPE_STRING },
{ .name = "steer_legacy_reassoc_secs", .type = UCI_TYPE_STRING },
{ .name = "steer_legacy_retry_secs", .type = UCI_TYPE_STRING },
{ .name = "assoc_ctrl_secs", .type = UCI_TYPE_STRING }
};
struct uci_option *tb[NUM_POLICIES];
struct netif_fhcfg *fh;
uci_parse_section(s, opts, NUM_POLICIES, tb);
if (tb[FH_IFNAME]) {
ifname = tb[FH_IFNAME]->v.string;
fh = get_netif_fhcfg_by_name(a, ifname);
if (!fh) {
fh = create_fronthaul_iface_config(a, ifname);
if (!fh) {
warn("%s: OOM!\n", __func__);
return -1;
}
} else {
clean_steer_btm_excl(fh);
clean_steer_excl(fh);
warn("Duplicate 'fh-iface %s' config!! ignore\n",
ifname);
}
} else {
warn("No ifname in fh-iface section!\n");
return -1;
}
if (tb[FH_BAND]) {
int band = atoi(tb[FH_BAND]->v.string);
if (band == 2)
fh->band = BAND_2;
else if (band == 5)
fh->band = BAND_5;
}
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
if (tb[FH_STEER]) {
struct uci_element *xi;
dbg("Steer: param: ");
uci_foreach_element(&tb[FH_STEER]->v.list, xi) {
struct steer_policy *p = NULL;
struct steer_rule *r;
dbg("%s ", xi->name);
p = get_steer_policy_by_name(fh, xi->name);
if (!p) {
/* TODO? */
dbg("TODO!! steer before ifname\n");
continue;
}
p->enabled = true;
r = get_steer_rule_by_name(xi->name);
if (r)
r->enabled = true;
}
dbg("\n");
}
if (tb[FH_EXCLUDE]) {
struct uci_element *xi;
dbg("Steer: exclude: ");
uci_foreach_element(&tb[FH_EXCLUDE]->v.list, xi) {
dbg("%s ", xi->name);
stax_add_entry(&fh->steer_excludelist, xi->name);
}
dbg("\n");
}
if (tb[FH_EXCLUDE_BTM]) {
struct uci_element *xi;
dbg("Steer: exclude_btm: ");
uci_foreach_element(&tb[FH_EXCLUDE_BTM]->v.list, xi) {
dbg("%s ", xi->name);
stax_add_entry(&fh->steer_btm_excludelist, xi->name);
}
dbg("\n");
}
if (tb[FH_BTM_RETRY])
fh->steer_btm_retry = atoi(tb[FH_BTM_RETRY]->v.string);
if (tb[FH_BTM_RETRY_SECS])
fh->steer_btm_retry_secs = atoi(tb[FH_BTM_RETRY_SECS]->v.string);
if (tb[FH_FLBK_LEGACY])
fh->fallback_legacy = atoi(tb[FH_FLBK_LEGACY]->v.string);
if (tb[FH_STEER_LEGACY_RASSOC_SECS])
fh->steer_legacy_reassoc_secs =
atoi(tb[FH_STEER_LEGACY_RASSOC_SECS]->v.string);
if (tb[FH_STEER_LEGACY_RETRY_SECS])
fh->steer_legacy_retry_secs =
atoi(tb[FH_STEER_LEGACY_RETRY_SECS]->v.string);
if (tb[FH_ASSOC_CTRL_SECS])
fh->assoc_control_time =
atoi(tb[FH_ASSOC_CTRL_SECS]->v.string);
return 0;
}
static int agent_config_get_steer_param(struct agent_config *a,
struct uci_section *s)
{
struct steer_rule *r;
dbg("Steer-param: %s\n", s->e.name);
r = get_steer_rule_by_name(s->e.name);
if (!r)
return -1;
dbg("Rule to handle steer-param '%s' available\n", s->e.name);
r->config(r, a, s);
return 0;
}
int agent_config_reload(struct agent_config *cfg)
{
struct uci_context *ctx;
struct uci_package *pkg;
struct uci_element *e;
cfg->enabled = false;
cfg->runfreq = AGENT_RUN_AUTO;
ctx = uci_alloc_context();
if (!ctx)
return -1;
if (uci_load(ctx, "agent", &pkg)) {
uci_free_context(ctx);
return -1;
}
uci_foreach_element(&pkg->sections, e) {
struct uci_section *s = uci_to_section(e);
}
uci_free_context(ctx);
return 0;
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
int agent_config_init(struct agent_config *cfg)
{
INIT_LIST_HEAD(&cfg->fhlist);
INIT_LIST_HEAD(&cfg->bklist);
agent_config_reload(cfg);
return 0;
}
void clean_bk(struct netif_bkcfg *p)
{
list_del(&p->list);
free(p);
}
int clean_all_bk(struct agent_config *cfg)
{
struct netif_bkcfg *p, *tmp;
list_for_each_entry_safe(p, tmp, &cfg->bklist, list)
clean_bk(p);
return 0;
}
void clean_fh(struct netif_fhcfg *p)
{
clean_steer_btm_excl(p);
clean_steer_excl(p);
list_del(&p->list);
free(p);
}
int clean_all_fh(struct agent_config *cfg)
{
struct netif_fhcfg *p, *tmp;
list_for_each_entry_safe(p, tmp, &cfg->fhlist, list)
clean_fh(p);
return 0;
}
int agent_config_clean(struct agent_config *cfg)
{
clean_all_fh(cfg);
clean_all_bk(cfg);
return 0;
}