From 6d2fd1de0dcf3c9562aff87620f3ef4f850bb1ec Mon Sep 17 00:00:00 2001 From: Tanya Singh Date: Wed, 30 Jul 2025 14:39:02 +0800 Subject: [PATCH] afc: Use curl instead of uclient to send/receive AFC request/response using hostapd Fixes: WIFI-14427 Signed-off-by: Tanya Singh --- .../hostapd/files/afc_location.uc | 14 ++++++------ feeds/ipq807x_v5.4/hostapd/files/hostapd.uc | 22 ++++++++++++++----- .../qca-wifi-7/hostapd/files/afc_location.uc | 14 ++++++------ 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/feeds/ipq807x_v5.4/hostapd/files/afc_location.uc b/feeds/ipq807x_v5.4/hostapd/files/afc_location.uc index 17cf425fc..c3f079624 100644 --- a/feeds/ipq807x_v5.4/hostapd/files/afc_location.uc +++ b/feeds/ipq807x_v5.4/hostapd/files/afc_location.uc @@ -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); diff --git a/feeds/ipq807x_v5.4/hostapd/files/hostapd.uc b/feeds/ipq807x_v5.4/hostapd/files/hostapd.uc index b755fbd57..055cfb272 100644 --- a/feeds/ipq807x_v5.4/hostapd/files/hostapd.uc +++ b/feeds/ipq807x_v5.4/hostapd/files/hostapd.uc @@ -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); diff --git a/feeds/qca-wifi-7/hostapd/files/afc_location.uc b/feeds/qca-wifi-7/hostapd/files/afc_location.uc index 17cf425fc..c3f079624 100644 --- a/feeds/qca-wifi-7/hostapd/files/afc_location.uc +++ b/feeds/qca-wifi-7/hostapd/files/afc_location.uc @@ -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);