make the country code a fixed configuration option

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2023-11-07 18:31:41 +01:00
parent ab52fb543a
commit a2ac5514cf
10 changed files with 71 additions and 67 deletions

View File

@@ -60,6 +60,7 @@ let scope = {
ctx,
fs,
restrict,
capab,
/* log helper */
log,

View File

@@ -0,0 +1,26 @@
if (!args.country) {
result(2, 'Country code is missing.');
return;
}
if (capab.country_code && !(args.country in capab.country_code)) {
result(2, 'Country code "%s" is not allowed.', args.country);
return;
}
if (fs.stat('/tmp/squashfs')) {
system('fw_setenv country ' + args.country);
} else {
system('mount_certs');
fs.writefile('/certificates/ucentral.defaults', args);
}
fs.writefile('/etc/modules.conf', 'options cfg80211 ieee80211_regdom=' + args.country);
include('reboot_cause.uc', { reason: 'fixedconfig' });
result(0, "Applied fixed config, rebooting");
sleep(5);
system('umount /certificates');
system('ubidetach -d 3');
system("(sleep 10; jffs2reset -r -y)&");
system("/etc/init.d/ucentral stop");

View File

@@ -21,6 +21,12 @@ if (developer != 'developer=1') {
restrict = restrictfile ? json(restrictfile.read("all")) : {};
}
let default_config = fs.readfile('/etc/ucentral/ucentral.defaults');
default_config = default_config ? json(default_config) : {};
default_config.country ??= 'US';
system('iw reg set ' + default_config.country);
let serial = cursor.get("ucentral", "config", "serial");
assert(cursor, "Unable to instantiate uci");
@@ -1126,6 +1132,7 @@ return /** @lends uCentral.prototype */ {
cursor,
capab,
restrict,
default_config,
/** @member {uCentral.files} */
files,

View File

@@ -53,10 +53,7 @@
145, 149, 153, 157, 161, 165, 169, 173, 177, 181, 185, 189, 193, 197, 201, 205,
209, 213, 217, 221, 225, 229, 233 ];
if (capab.country_code && !(radio.country in capab.country_code)) {
warn("Overriding country code to %s", capab.country_code[0]);
radio.country = capab.country_code[0];
}
radio.country = default_config.country;
if (length(restrict.country) && !(radio.country in restrict.country)) {
warn("Country code is restricted");

View File

@@ -42,15 +42,6 @@ properties:
type: integer
maximum: 196
minimum: 1
country:
description:
Specifies the country code, affects the available channels and
transmission powers.
type: string
maxLength: 2
minLength: 2
examples:
- US
allow-dfs:
description:
This property defines whether a radio may use DFS channels.

View File

@@ -981,26 +981,6 @@ function instantiateRadio(location, value, errors) {
obj.valid_channels = parseValidChannels(location + "/valid-channels", value["valid-channels"], errors);
}
function parseCountry(location, value, errors) {
if (type(value) == "string") {
if (length(value) > 2)
push(errors, [ location, "must be at most 2 characters long" ]);
if (length(value) < 2)
push(errors, [ location, "must be at least 2 characters long" ]);
}
if (type(value) != "string")
push(errors, [ location, "must be of type string" ]);
return value;
}
if (exists(value, "country")) {
obj.country = parseCountry(location + "/country", value["country"], errors);
}
function parseAllowDfs(location, value, errors) {
if (type(value) != "bool")
push(errors, [ location, "must be of type boolean" ]);

View File

@@ -5,14 +5,17 @@ push(REQUIRE_SEARCH_PATH,
let ubus = require("ubus");
let fs = require("fs");
let default_config = {
country: 'US'
};
let boardfile = fs.open("/etc/board.json", "r");
let board = json(boardfile.read("all"));
boardfile.close();
let restrictfile = fs.open("/etc/ucentral/restrictions.json", "r");
capa = {
'secure-rtty': true
'secure-rtty': true,
'default-config': true,
};
if (restrictfile) {
capa.restrictions = json(restrictfile.read("all")) || {};
@@ -25,7 +28,36 @@ if (restrictfile) {
capa.developer = false;
}
ctx = ubus.connect();
if (board.wifi?.country) {
default_config.country = split(board.wifi.country, ' ');
capa.country_codes = board.wifi.country;
}
if (fs.stat('/tmp/squashfs')) {
let pipe = fs.popen('fw_printenv country');
let country = replace(pipe.read("all"), '\n', '');
pipe.close();
if (country)
default_config.country = country;
else
system('fw_setenv country ' + default_config.country);
fs.writefile('/etc/ucentral/ucentral.defaults', default_config);
} else {
if (!fs.stat('/certificates/ucentral.defaults')) {
fs.writefile('/certificates/ucentral.defaults', default_config);
}
if (fs.stat('/certificates/ucentral.defaults')) {
let defaults = fs.readfile('/certificates/ucentral.defaults');
if (json(defaults))
default_config = json(defaults);
}
fs.writefile('/etc/ucentral/ucentral.defaults', default_config);
}
capa.country = default_config.country || 'US';
let wifi = require("wifi.phy");
capa.compatible = replace(board.model.id, ',', '_');
capa.model = board.model.name;
@@ -87,15 +119,11 @@ for (let k, v in board.network) {
if (length(macs))
capa.macaddr = macs;
if (board.wifi?.country)
capa.country_code = split(board.wifi.country, ' ');
if (board.system?.label_macaddr)
capa.label_macaddr = board.system?.label_macaddr;
if (length(wifi))
capa.wifi = wifi;
capafile = fs.open("/etc/ucentral/capabilities.json", "w");
capafile.write(capa);
capafile.close();
fs.writefile('/etc/ucentral/capabilities.json', capa);

View File

@@ -594,15 +594,6 @@
"minimum": 1
}
},
"country": {
"description": "Specifies the country code, affects the available channels and transmission powers.",
"type": "string",
"maxLength": 2,
"minLength": 2,
"examples": [
"US"
]
},
"allow-dfs": {
"description": "This property defines whether a radio may use DFS channels.",
"type": "boolean",

View File

@@ -459,14 +459,6 @@
"minimum": 1
}
},
"country": {
"type": "string",
"maxLength": 2,
"minLength": 2,
"examples": [
"US"
]
},
"allow-dfs": {
"type": "boolean",
"default": true

View File

@@ -510,15 +510,6 @@
"minimum": 1
}
},
"country": {
"description": "Specifies the country code, affects the available channels and transmission powers.",
"type": "string",
"maxLength": 2,
"minLength": 2,
"examples": [
"US"
]
},
"allow-dfs": {
"description": "This property defines whether a radio may use DFS channels.",
"type": "boolean",