"README.md" did not exist on "d8672874efc44f2ee4f296efb51eef16151ce6b0"
Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
} else {
dbg("config: del list option: %s\n", (char *)val);
uci_del_list(ctx, &ptr);
}
uci_commit(ctx, &p, false);
}
int config_update(const char *confname, struct agent_config *cfg,
const char *section, 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;
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);
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
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
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);
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
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
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,
Jakob Olsson
committed
struct uci_section *s)
{
enum {
A_ENABLED,
Jakob Olsson
committed
A_BRCM_SETUP,
/*A_CONFIGURED,*/
A_CNTLR_MAC,
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 },
Jakob Olsson
committed
{ .name = "brcm_setup", .type = UCI_TYPE_STRING },
/*{ .name = "configured", .type = UCI_TYPE_STRING },*/
{ .name = "controller_macaddr", .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);
Jakob Olsson
committed
if (tb[A_BRCM_SETUP])
a->brcm_setup = atoi(tb[A_BRCM_SETUP]->v.string);
/*if (tb[A_CONFIGURED])
a->configured = atoi(tb[A_CONFIGURED]->v.string);*/
if (tb[A_CNTLR_MAC])
hwaddr_aton(tb[A_CNTLR_MAC]->v.string, a->cntlr_almac);
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
static int agent_config_get_wifi_radio(struct agent_config *a,
struct uci_section *s)
{
enum {
WIFI_RADIO_DEVICE,
WIFI_RADIO_BAND,
WIFI_RADIO_CONFIGURED,
WIFI_RADIO_ONBOARDED,
NUM_WIFI_RADIO_POLICIES,
};
const struct uci_parse_option opts[] = {
{ .name = "device", .type = UCI_TYPE_STRING },
{ .name = "band", .type = UCI_TYPE_STRING },
{ .name = "configured", .type = UCI_TYPE_STRING },
{ .name = "onboarded", .type = UCI_TYPE_STRING },
};
struct uci_option *tb[NUM_WIFI_RADIO_POLICIES];
const char *ifname = NULL;
uint32_t band = 0;
struct agent_config_radio *n;
uci_parse_section(s, opts, NUM_WIFI_RADIO_POLICIES, tb);
if (!tb[WIFI_RADIO_DEVICE] || !tb[WIFI_RADIO_BAND]) {
warn("No radio name or band option found!\n");
return -1;
}
if (tb[WIFI_RADIO_DEVICE])
ifname = tb[WIFI_RADIO_DEVICE]->v.string;
if (tb[WIFI_RADIO_BAND]) {
band = atoi(tb[WIFI_RADIO_BAND]->v.string);
if (band != 2 && band != 5) {
warn("Incorrect band '%d' in config\n", band);
return -1;
}
}
if (ifname && band) {
n = calloc(1, sizeof(*n));
if (!n) {
warn("-ENOMEM!\n");
return -1;
}
strncpy(n->name, ifname, 16);
n->name[15] = '\0';
n->band = band;
}
if (tb[WIFI_RADIO_CONFIGURED]) {
n->configured = atoi(tb[WIFI_RADIO_CONFIGURED]->v.string) == 1 ?
true : false;
}
if (tb[WIFI_RADIO_ONBOARDED]) {
n->onboarded = atoi(tb[WIFI_RADIO_ONBOARDED]->v.string) == 1 ?
true : false;
}
list_add_tail(&n->list, &a->radiolist);
return 0;
}
static int agent_config_get_bk_iface(struct agent_config *a,
Jakob Olsson
committed
struct uci_section *s)
{
enum {
BK_IFNAME,
Jakob Olsson
committed
BK_DEVICE,
BK_ENABLED,
BK_ONBOARDED,
Jakob Olsson
committed
BK_SSID,
BK_KEY,
BK_ENCRYPTION,
NUM_POLICIES
};
const struct uci_parse_option opts[] = {
{ .name = "ifname", .type = UCI_TYPE_STRING },
Jakob Olsson
committed
{ .name = "device", .type = UCI_TYPE_STRING },
{ .name = "band", .type = UCI_TYPE_STRING },
{ .name = "enabled", .type = UCI_TYPE_STRING },
Jakob Olsson
committed
{ .name = "onboarded", .type = UCI_TYPE_STRING },
{ .name = "ssid", .type = UCI_TYPE_STRING },
{ .name = "key", .type = UCI_TYPE_STRING },
{ .name = "encryption", .type = UCI_TYPE_STRING }
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
};
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;
}
Jakob Olsson
committed
if (tb[BK_DEVICE]) {
const char *device;
device = tb[BK_DEVICE]->v.string;
strncpy(bk->device, device, sizeof(bk->device) - 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;
}
Jakob Olsson
committed
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
if (tb[BK_SSID]) {
const char *ssid;
ssid = tb[BK_SSID]->v.string;
strncpy(bk->ssid, ssid, sizeof(bk->ssid) - 1);
}
if (tb[BK_KEY]) {
const char *key;
key = tb[BK_KEY]->v.string;
strncpy(bk->key, key, sizeof(bk->key) - 1);
}
if (tb[BK_ENCRYPTION]) {
const char *encryption;
encryption = tb[BK_ENCRYPTION]->v.string;
strncpy(bk->encryption, encryption, sizeof(bk->encryption) - 1);
}
static int agent_config_get_fh_iface(struct agent_config *a,
{
enum {
FH_IFNAME,
Jakob Olsson
committed
FH_DEVICE,
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,
Jakob Olsson
committed
FH_SSID,
FH_KEY,
FH_ENCRYPTION,
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 },
Jakob Olsson
committed
{ .name = "device", .type = UCI_TYPE_STRING },
{ .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 },
Jakob Olsson
committed
{ .name = "assoc_ctrl_secs", .type = UCI_TYPE_STRING },
{ .name = "ssid", .type = UCI_TYPE_STRING },
{ .name = "key", .type = UCI_TYPE_STRING },
{ .name = "encryption", .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;
}
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
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");
}
Jakob Olsson
committed
if (tb[FH_DEVICE]) {
const char *device;
device = tb[FH_DEVICE]->v.string;
strncpy(fh->device, device, sizeof(fh->device) - 1);
}
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
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);
Jakob Olsson
committed
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
if (tb[FH_SSID]) {
const char *ssid;
ssid = tb[FH_SSID]->v.string;
strncpy(fh->ssid, ssid, sizeof(fh->ssid) - 1);
}
if (tb[FH_KEY]) {
const char *key;
key = tb[FH_KEY]->v.string;
strncpy(fh->key, key, sizeof(fh->key) - 1);
}
if (tb[FH_ENCRYPTION]) {
const char *encryption;
encryption = tb[FH_ENCRYPTION]->v.string;
strncpy(fh->encryption, encryption, sizeof(fh->encryption) - 1);
}
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;
Jakob Olsson
committed
if (uci_load(ctx, "mapagent", &pkg)) {
uci_free_context(ctx);
return -1;
}
uci_foreach_element(&pkg->sections, e) {
struct uci_section *s = uci_to_section(e);
Jakob Olsson
committed
if (!strcmp(s->type, "agent"))
else if (!strcmp(s->type, "wifi-radio"))
agent_config_get_wifi_radio(cfg, s);
}
uci_free_context(ctx);
return 0;
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
int config_generate_radio(struct agent_config *cfg, struct uci_context *ctx,
char *device, uint8_t band)
{
struct uci_package *pkg;
struct uci_section *s;
int rv;
rv = uci_load(ctx, UCI_AGENT, &pkg);
if (rv)
return -1;
s = config_add_section(ctx, pkg, UCI_AGENT, "wifi-radio", "device",
device);
if (!s)
return -1;
if (band == BAND_2)
set_value(ctx, pkg, s, "band", "2", UCI_TYPE_STRING);
else if (band == BAND_5)
set_value(ctx, pkg, s, "band", "5", UCI_TYPE_STRING);
uci_commit(ctx, &pkg, false);
uci_unload(ctx, pkg);
return 0;
}
int config_generate_bsta_agent(struct agent_config *cfg, struct uci_context *ctx,
char *device, char *ifname,
uint8_t band)
{
struct uci_section *s;
struct uci_package *pkg;
int rv;
rv = uci_load(ctx, UCI_AGENT, &pkg);
if (rv)
return -1;
s = config_add_section(ctx, pkg, UCI_AGENT, UCI_BK_AGENT, "device",
device);
if (!s)
return -1;
if (band == BAND_2)
set_value(ctx, pkg, s, "band", "2", UCI_TYPE_STRING);
else if (band == BAND_5)
set_value(ctx, pkg, s, "band", "5", UCI_TYPE_STRING);
set_value(ctx, pkg, s, "ifname", ifname, UCI_TYPE_STRING);
uci_commit(ctx, &pkg, false);
uci_unload(ctx, pkg);
return 0;
}
int config_find_radio(struct agent_config *cfg, struct uci_context *ctx,
char *radio)
{
struct uci_package *pkg;
struct uci_section *s;
struct uci_element *e;
bool found = false;
int rv;
rv = uci_load(ctx, UCI_AGENT, &pkg);
if (rv)
return found;
s = config_get_section(ctx, pkg, "wifi-radio", "device", radio);
if (s)
found = true;
uci_unload(ctx, pkg);
return found;
}
static void wifi_radio_status_cb(struct ubus_request *req, int type,
struct blob_attr *msg)
{
struct blob_attr *tb[1];
static const struct blobmsg_policy ap_attr[1] = {
[0] = { .name = "band", .type = BLOBMSG_TYPE_STRING },
};
char band_str[8] = {0};
uint8_t *band = req->priv;
blobmsg_parse(ap_attr, 1, tb, blob_data(msg), blob_len(msg));
if (!tb[0])
return;
strncpy(band_str, blobmsg_data(tb[0]), sizeof(band_str));
if (!strncmp(band_str, "5GHz", sizeof(band_str)))
*band = BAND_5;
else if (!strncmp(band_str, "2.4GHz", sizeof(band_str)))
*band = BAND_2;
else
*band = BAND_UNKNOWN;
}
bool config_find_bsta_agent(struct agent_config *cfg, struct uci_context *ctx,
char *device)
{
struct uci_package *pkg;
struct uci_element *e;
struct uci_section *section = NULL;
int rv;
bool found = false;
rv = uci_load(ctx, UCI_AGENT, &pkg);
if (rv)
return found;
uci_foreach_element(&pkg->sections, e) {
struct uci_section *s = uci_to_section(e);
char *c_device;
if (strncmp(s->type, UCI_BK_AGENT, strlen(UCI_BK_AGENT)))
continue;
c_device = uci_lookup_option_string(ctx, s, "device");
if (!c_device)
continue;
if (strncmp(device, c_device, 16))
continue;
found = true;
break;
}
uci_unload(ctx, pkg);
return found;
}
struct uci_section *config_find_bsta_wireless(struct agent_config *cfg,
struct uci_context *ctx, struct uci_package *pkg, char *device)
{
struct uci_element *e;
int rv;
uci_foreach_element(&pkg->sections, e) {
struct uci_section *s = uci_to_section(e);
char *c_device, *mode;
if (strncmp(s->type, UCI_WLAN_IFACE, strlen(UCI_WLAN_IFACE)))
continue;
c_device = uci_lookup_option_string(ctx, s, "device");
if (!c_device || strncmp(device, c_device, 16))
continue;
mode = uci_lookup_option_string(ctx, s, "mode");
if (!mode || strcmp(mode, "sta"))
continue;
return s;
}
return NULL;
}
int agent_config_prepare(struct agent_config *cfg)
{
// TODO: iterate through 'wifi-device' sections in wireless config.
// If corresponding 'wifi-radio <device-name>' section is not available
// in 'mapagent' config, create one. Check supported bands of the new
// wifi-device and add option 'band' to the wifi-radio section.
struct uci_context *ctx = NULL;
struct uci_package *pkg;
struct uci_element *e;
struct blob_buf bb = {0};
pkg = uci_load_pkg(&ctx, UCI_WIRELESS);
if (!pkg)
return -1;
blob_buf_init(&bb, 0);
uci_foreach_element(&pkg->sections, e) {
struct uci_section *s = uci_to_section(e);
struct uci_section *wl_s;
char *device, *ifname;
uint8_t band = 0;
char obj_name[64] = {0};
int rv;
if (strncmp(s->type, UCI_WL_DEVICE, strlen(UCI_WL_DEVICE)))
continue;
device = s->e.name;
snprintf(obj_name, sizeof(obj_name), "wifi.radio.%s",
device);
rv = ubus_call(obj_name, "status", &bb,
wifi_radio_status_cb, &band);
if (rv)
continue;
if (!config_find_radio(cfg, ctx, device))
config_generate_radio(cfg, ctx, device, band);
if (config_find_bsta_agent(cfg, ctx, device))
continue;
wl_s = config_find_bsta_wireless(cfg, ctx, pkg, device);
if (!wl_s)
continue;
ifname = uci_lookup_option_string(ctx, wl_s, "ifname");
if (!ifname)
continue;
config_generate_bsta_agent(cfg, ctx, device, ifname, band);
}
blob_buf_free(&bb);
uci_unload(ctx, pkg);
uci_free_context(ctx);
return 0;
}
int agent_config_init(struct agent_config *cfg)
{
INIT_LIST_HEAD(&cfg->fhlist);
INIT_LIST_HEAD(&cfg->bklist);
INIT_LIST_HEAD(&cfg->radiolist);
agent_config_prepare(cfg);
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
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;
}
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
int wifi_reorder_interfaces_by_device(struct agent_config *a,
struct uci_context *ctx, struct uci_package *pkg, char *device)
{
int i, j = 0;
char ifname[16] = {0};
enum {
W_IFNAME,
NUM_POLICIES
};
const struct uci_parse_option opts[] = {
{ .name = "ifname", .type = UCI_TYPE_STRING }
};
struct uci_option *tb[NUM_POLICIES];
struct uci_element *e;
trace("reordering interfaces for device %s\n", device);
strncpy(ifname, device, sizeof(ifname));
for (i = 1; i < 16; i++) {
trace("iterating in search of %s\n", ifname);
uci_foreach_element(&pkg->sections, e) {
struct uci_section *s = uci_to_section(e);
if (strncmp(s->type, UCI_WLAN_IFACE,
strlen(UCI_WLAN_IFACE)))
continue;
uci_parse_section(s, opts, NUM_POLICIES, tb);
if (!tb[W_IFNAME])
continue;
if (strncmp(tb[W_IFNAME]->v.string, ifname, sizeof(ifname)))
continue;
trace("found interface %s, reordering to %d\n", ifname, j);
uci_reorder_section(ctx, s, j);
j++;
break;
}
snprintf(ifname, sizeof(ifname), "%s%s%d",
device,
(a->brcm_setup ? "." : "_"),
i);
}
return 0;
}
int wifi_reorder_interfaces(struct agent_config *a)
{
struct uci_context *ctx;
struct uci_package *pkg;
struct uci_element *e;
ctx = uci_alloc_context();
if (!ctx)
return -1;
if (uci_load(ctx, UCI_WIRELESS, &pkg)) {
uci_free_context(ctx);
return -1;
}
uci_foreach_element(&pkg->sections, e) {
struct uci_section *s = uci_to_section(e);
if (strncmp(s->type, UCI_WL_DEVICE, strlen(UCI_WL_DEVICE)))
continue;
wifi_reorder_interfaces_by_device(a, ctx, pkg, s->e.name);
}
uci_commit(ctx, &pkg, false);
uci_free_context(ctx);
return 0;
}