diff mbox series

Possible problem in ucode wifi scripts

Message ID 905326f6-0304-4c8e-b4cb-c7f608eb48fc@gmail.com
State New
Headers show
Series Possible problem in ucode wifi scripts | expand

Commit Message

e9hack Dec. 14, 2024, 10:47 a.m. UTC
Hi,

it looks like that data.macaddr_base is always true even if no macaddr_base is set:

Using of 'data.macaddr_base ?? 0' doesn't seem to work.
   
Regards,
Hartmut

Comments

Felix Fietkau Dec. 14, 2024, 11:02 a.m. UTC | #1
On 14.12.24 11:47, e9hack wrote:
> Hi,
> 
> it looks like that data.macaddr_base is always true even if no macaddr_base is set:

Which context does this happen in - hostapd, wpa_supplicant, wdev.uc or 
all of the above?

- Felix
e9hack Dec. 14, 2024, 7:56 p.m. UTC | #2
Am 14.12.2024 um 12:02 schrieb Felix Fietkau:
> On 14.12.24 11:47, e9hack wrote:
>> Hi,
>>
>> it looks like that data.macaddr_base is always true even if no macaddr_base is set:
> 
> Which context does this happen in - hostapd, wpa_supplicant, wdev.uc or all of the above?
> 
> - Felix

It occurs with hostapd. The mac addresses are set correctly, but the config file contains something like this:

# Setup interface: 2G-ap0
bss=2G-ap0
bssid=null
...

# Setup interface: 2G-ap1
bss=2G-ap1
bssid=00:00:00:00:00:01
...

# Setup interface: 2G-ap2
bss=2G-ap2
bssid=00:00:00:00:00:02
...

# Setup interface: 2G-ap3
bss=2G-ap3
bssid=00:00:00:00:00:03
...


Regards,
Hartmut
e9hack Dec. 15, 2024, 10:11 a.m. UTC | #3
Am 14.12.2024 um 12:02 schrieb Felix Fietkau:
> On 14.12.24 11:47, e9hack wrote:
>> Hi,
>>
>> it looks like that data.macaddr_base is always true even if no macaddr_base is set:
> 
> Which context does this happen in - hostapd, wpa_supplicant, wdev.uc or all of the above?
> 
> - Felix

The issue comes from iface.uc line no 183:

let pipe = fs.popen(`ucode /usr/share/hostap/wdev.uc ${phy} get_macaddr id=${mac_idx} num_global=${num_global_macaddr} mbssid=${data.mbssid ?? 0} macaddr_base=${macaddr_base}`);

It looks like that it isn't possible to send a null pointer through a pipe. Anything is converted to a string.

Regards,
Hartmut
Felix Fietkau Dec. 15, 2024, 3:01 p.m. UTC | #4
On 14.12.24 20:56, e9hack wrote:
> Am 14.12.2024 um 12:02 schrieb Felix Fietkau:
>> On 14.12.24 11:47, e9hack wrote:
>>> Hi,
>>>
>>> it looks like that data.macaddr_base is always true even if no macaddr_base is set:
>> 
>> Which context does this happen in - hostapd, wpa_supplicant, wdev.uc or all of the above?
>> 
>> - Felix
> 
> It occurs with hostapd. The mac addresses are set correctly, but the config file contains something like this:

Does this help? https://nbd.name/p/9c3a2a8f

- Felix
e9hack Dec. 15, 2024, 3:57 p.m. UTC | #5
Am 15.12.2024 um 16:01 schrieb Felix Fietkau:
> On 14.12.24 20:56, e9hack wrote:
>> Am 14.12.2024 um 12:02 schrieb Felix Fietkau:
>>> On 14.12.24 11:47, e9hack wrote:
>>>> Hi,
>>>>
>>>> it looks like that data.macaddr_base is always true even if no macaddr_base is set:
>>>
>>> Which context does this happen in - hostapd, wpa_supplicant, wdev.uc or all of the above?
>>>
>>> - Felix
>>
>> It occurs with hostapd. The mac addresses are set correctly, but the config file contains something like this:
> 
> Does this help? https://nbd.name/p/9c3a2a8f

It doesn't help. It looks like that the pipe must be create without parameter macaddr_base if it is not set:

$ diff -u iface.uc.bak iface.uc
--- iface.uc.bak        2024-12-15 16:20:43.000000000 +0100
+++ iface.uc    2024-12-15 16:32:25.657917200 +0100
@@ -180,7 +180,10 @@
  let mac_idx = 0;
  export function prepare(data, phy, num_global_macaddr, macaddr_base) {
         if (!data.macaddr) {
-               let pipe = fs.popen(`ucode /usr/share/hostap/wdev.uc ${phy} get_macaddr id=${mac_idx} num_global=${num_global_macaddr} mbssid=${data.mbssid ?? 0} macaddr_base=${macaddr_base}`);
+               let cmd = `ucode /usr/share/hostap/wdev.uc ${phy} get_macaddr id=${mac_idx} num_global=${num_global_macaddr} mbssid=${data.mbssid ?? 0}`;
+               if (macaddr_base)
+                       cmd += ` macaddr_base=${macaddr_base}`;
+               let pipe = fs.popen(cmd);

                 data.macaddr = trim(pipe.read("all"), '\n');
                 pipe.close();

  
I add some test code to common.uc:

$ diff -u common.uc.bak common.uc
--- common.uc.bak       2024-12-14 20:32:53.000000000 +0100
+++ common.uc   2024-12-15 16:18:04.000000000 +0100
@@ -204,6 +204,9 @@
                 let mbssid = int(data.mbssid ?? 0) > 0;
                 let num_global = int(data.num_global ?? 1);
                 let use_global = !mbssid && idx < num_global;
+               let len = length(data.macaddr_base);
+
+               system(`logger "====> macaddr_generate: data=${data} data.macaddr_base=${data.macaddr_base} len=${len} <===="`);

                 let base_addr = phy_sysfs_file(phy, "macaddress");
                 if (!base_addr)

iface.uc unmodified:

Sun Dec 15 16:49:06 2024 user.notice root: ====> macaddr_generate: data={ id: 0, num_global: 1, mbssid: 0, macaddr_base: null } data.macaddr_base=null len=4 <====

your proposal:

Sun Dec 15 16:50:50 2024 user.notice root: ====> macaddr_generate: data={ id: 0, num_global: 1, mbssid: 0, macaddr_base:  } data.macaddr_base= len=0 <====

my proposal:

Sun Dec 15 16:51:46 2024 user.notice root: ====> macaddr_generate: data={ id: 0, num_global: 1, mbssid: 0 } data.macaddr_base=null len=null <====

In the last one is the null a real null and not a string.

Regards,
Hartmut
diff mbox series

Patch

--- a/package/network/config/wifi-scripts/files/usr/share/hostap/common.uc
+++ b/package/network/config/wifi-scripts/files/usr/share/hostap/common.uc
@@ -213,7 +213,9 @@  const phy_proto = {
  		if (!base_mask)
  			return null;
  
-		if (base_mask == "00:00:00:00:00:00" &&
+		if (data.macaddr_base)
+			base_addr = data.macaddr_base;
+		else if (base_mask == "00:00:00:00:00:00" &&
  		    (radio_idx > 0 || idx >= num_global)) {
  			let addrs = split(phy_sysfs_file(phy, "addresses"), "\n");
  
Currently I'm using the following workaround:

--- a/package/network/config/wifi-scripts/files/usr/share/hostap/common.uc
+++ b/package/network/config/wifi-scripts/files/usr/share/hostap/common.uc
@@ -213,7 +213,9 @@  const phy_proto = {
  		if (!base_mask)
  			return null;
  
-		if (base_mask == "00:00:00:00:00:00" &&
+		if (data.macaddr_base != "null")
+			base_addr = data.macaddr_base;
+		else if (base_mask == "00:00:00:00:00:00" &&
  		    (radio_idx > 0 || idx >= num_global)) {
  			let addrs = split(phy_sysfs_file(phy, "addresses"), "\n");