@@ -40,6 +40,16 @@ func SystemAccesspointStart() error {
4040 if out , err := sysutils .RunCommand (10 * time .Second , "systemctl" , "disable" , fmt .Sprintf ("wpa_supplicant@%s.service" , wifiIf )); err != nil {
4141 return fmt .Errorf ("failed to disable wpa_supplicant: %w, output: %s" , err , out )
4242 }
43+ wpaService := fmt .Sprintf ("wpa_supplicant@%s.service" , wifiIf )
44+ if out , err := sysutils .RunCommand (10 * time .Second , "systemctl" , "mask" , wpaService ); err != nil {
45+ if strings .Contains (out , "already exists" ) {
46+ sysutils .Warning ("File conflict detected. Forcing mask for %s..." , wpaService )
47+ os .Remove (fmt .Sprintf ("/etc/systemd/system/%s" , wpaService ))
48+ sysutils .RunCommand (10 * time .Second , "systemctl" , "mask" , wpaService )
49+ } else {
50+ return fmt .Errorf ("failed to mask wpa_supplicant: %w, output: %s" , err , out )
51+ }
52+ }
4353
4454 os .Remove (fmt .Sprintf ("%s/20-%s-managed.network" , systemdNetDir , wifiIf ))
4555
@@ -89,8 +99,12 @@ func SystemAccesspointStop() error {
8999 if out , err := sysutils .RunCommand (10 * time .Second , "systemctl" , "disable" , "hostapd" ); err != nil {
90100 return fmt .Errorf ("failed to disable hostapd: %w, output: %s" , err , out )
91101 }
92- if out , err := sysutils .RunCommand (10 * time .Second , "systemctl" , "mask" , "hostapd" ); err != nil {
93- return fmt .Errorf ("failed to mask hostapd: %w, output: %s" , err , out )
102+
103+ out , err := sysutils .RunCommand (10 * time .Second , "systemctl" , "mask" , "hostapd" )
104+ if err != nil && strings .Contains (out , "already exists" ) {
105+ sysutils .Warning ("File conflict detected. Forcing mask for hostapd..." )
106+ os .Remove ("/etc/systemd/system/hostapd.service" )
107+ sysutils .RunCommand (10 * time .Second , "systemctl" , "mask" , "hostapd" )
94108 }
95109
96110 os .Remove (fmt .Sprintf ("%s/40-%s-ap.network" , systemdNetDir , wifiIf ))
@@ -140,12 +154,6 @@ func SystemAccesspointStatus() string {
140154 hostapdActive = true
141155 }
142156
143- out , _ = sysutils .RunCommand (5 * time .Second , "ip" , "-o" , "link" , "show" , wifiIf )
144- if ! strings .Contains (out , "UP" ) {
145- sysutils .Warning ("Interface %s is down, attempting recovery..." , wifiIf )
146- sysutils .RunCommand (10 * time .Second , "ip" , "link" , "set" , wifiIf , "up" )
147- }
148-
149157 if hostapdActive {
150158 sysutils .Success ("Access Point Mode: Enabled" )
151159 return "active"
@@ -179,14 +187,14 @@ func AccesspointStop() error {
179187 return nil
180188}
181189
182- func AccesspointStatus () error {
190+ func AccesspointStatus () ( string , error ) {
183191 binary , err := os .Executable ()
184192 if err != nil {
185193 binary = "VLX_FrameFlow"
186194 }
187195 out , err := sysutils .RunCommand (30 * time .Second , "sudo" , binary , "ap" , "_ap_system_ops" , "status" )
188196 if err != nil {
189- return fmt .Errorf ("failed to get AP status: %w, output: %s" , err , out )
197+ return "error" , fmt .Errorf ("failed to get AP status: %w, output: %s" , err , out )
190198 }
191- return nil
199+ return strings . TrimSpace ( out ), nil
192200}
0 commit comments