afc: Use curl instead of uclient to send/receive AFC request/response using hostapd

Fixes: WIFI-14427
Signed-off-by: Tanya Singh <tanya_singh@accton.com>
This commit is contained in:
Tanya Singh
2025-07-30 14:39:02 +08:00
committed by John Crispin
parent 1d822a10d2
commit 6d2fd1de0d
3 changed files with 31 additions and 19 deletions

View File

@@ -4,19 +4,19 @@ let fs = require("fs");
let ubus = require('ubus').connect();
let gps_info = ubus.call('gps', 'info');
let latitude = gps_info.latitude ?? 0;
let longitude = gps_info.longitude ?? 0;
let latitude = gps_info.latitude || 0;
let longitude = gps_info.longitude || 0;
// afc-location.json file content
let afc_location = {};
afc_location.location_type = "ellipse";
afc_location.location = longitude + ":" + latitude ;
afc_location.height = gps_info.elevation ?? 0;
afc_location.height = gps_info.elevation || 0;
afc_location.height_type = "AMSL";
afc_location.major_axis = gps_info.major_axis ?? 0;
afc_location.minor_axis = gps_info.minor_axis ?? 0;
afc_location.orientation = gps_info.major_orientation ?? 0;
afc_location.vertical_tolerance = gps_info.vdop ?? 0;
afc_location.major_axis = int(gps_info.major_axis) || 1;
afc_location.minor_axis = int(gps_info.minor_axis) || 1;
afc_location.orientation = gps_info.major_orientation || 0;
afc_location.vertical_tolerance = int(gps_info.vdop) || 1;
let afc_location_json = fs.open("/etc/ucentral/afc-location.json", "w");
afc_location_json.write(afc_location);

View File

@@ -1,7 +1,8 @@
let libubus = require("ubus");
import { open, readfile } from "fs";
import { open, readfile, writefile } from "fs";
import { wdev_create, wdev_remove, is_equal, vlist_new, phy_is_fullmac, phy_open } from "common";
let uci = require('uci').cursor();
let ubus = libubus.connect(null, 60);
hostapd.data.config = {};
@@ -893,10 +894,21 @@ return {
hostapd.ubus.disconnect();
},
afc_request: function(iface, data) {
let ret = ubus.call("afc", "request", { data });
if (type(ret) != "object")
return;
return ret.data;
let wireless_config = uci.get_all('wireless');
for (let l, afc_server in wireless_config) {
if (afc_server['.type'] == 'afc-server' && afc_server.url && data) {
hostapd.printf(`Sending AFC request: ${data}`);
writefile("/tmp/afc-request.json", data);
system(`curl -s -X POST ${afc_server.url} -H \'accept: \*\/\*\' -H \'Authorization: Bearer ${afc_server.access_token}\' -H \'Content-Type: application/json\' -d \'${data}\' --output /tmp/afc-response.json`);
let afc_response = (readfile("/tmp/afc-response.json"));
if (afc_response)
return afc_response;
else
return;
}
}
},
bss_add: function(name, obj) {
bss_event("add", name);

View File

@@ -4,19 +4,19 @@ let fs = require("fs");
let ubus = require('ubus').connect();
let gps_info = ubus.call('gps', 'info');
let latitude = gps_info.latitude ?? 0;
let longitude = gps_info.longitude ?? 0;
let latitude = gps_info.latitude || 0;
let longitude = gps_info.longitude || 0;
// afc-location.json file content
let afc_location = {};
afc_location.location_type = "ellipse";
afc_location.location = longitude + ":" + latitude ;
afc_location.height = gps_info.elevation ?? 0;
afc_location.height = gps_info.elevation || 0;
afc_location.height_type = "AMSL";
afc_location.major_axis = gps_info.major_axis ?? 0;
afc_location.minor_axis = gps_info.minor_axis ?? 0;
afc_location.orientation = gps_info.major_orientation ?? 0;
afc_location.vertical_tolerance = gps_info.vdop ?? 0;
afc_location.major_axis = int(gps_info.major_axis) || 1;
afc_location.minor_axis = int(gps_info.minor_axis) || 1;
afc_location.orientation = gps_info.major_orientation || 0;
afc_location.vertical_tolerance = int(gps_info.vdop) || 1;
let afc_location_json = fs.open("/etc/ucentral/afc-location.json", "w");
afc_location_json.write(afc_location);