Update App version to 0.1.2

Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
This commit is contained in:
luckfox-eng29
2026-03-16 21:49:37 +08:00
parent 9a4e604c61
commit d5bfaffd86
32 changed files with 4064 additions and 229 deletions

View File

@@ -176,6 +176,49 @@ func (s *NetworkInterfaceState) MACString() string {
return s.macAddr.String()
}
func (s *NetworkInterfaceState) SetMACAddress(macAddress string) (string, error) {
macAddress = strings.TrimSpace(macAddress)
if macAddress == "" {
return "", fmt.Errorf("mac address is empty")
}
hw, err := net.ParseMAC(macAddress)
if err != nil {
return "", fmt.Errorf("invalid mac address")
}
if len(hw) != 6 {
return "", fmt.Errorf("invalid mac address length")
}
normalized := strings.ToLower(hw.String())
s.stateLock.Lock()
iface, err := netlink.LinkByName(s.interfaceName)
if err != nil {
s.stateLock.Unlock()
return "", err
}
if err := netlink.LinkSetDown(iface); err != nil {
s.stateLock.Unlock()
return "", err
}
if err := netlink.LinkSetHardwareAddr(iface, hw); err != nil {
s.stateLock.Unlock()
return "", err
}
if err := netlink.LinkSetUp(iface); err != nil {
s.stateLock.Unlock()
return "", err
}
s.stateLock.Unlock()
if s.dhcpClient != nil && strings.TrimSpace(s.config.IPv4Mode.String) == "dhcp" {
_ = s.dhcpClient.Renew()
}
if _, err := s.update(); err != nil {
return normalized, err
}
return normalized, nil
}
func (s *NetworkInterfaceState) update() (DhcpTargetState, error) {
s.stateLock.Lock()
defer s.stateLock.Unlock()

View File

@@ -51,14 +51,15 @@ func (u *UsbGadget) RebindUsb(ignoreUnbindError bool) error {
}
// GetUsbState returns the current state of the USB gadget
func (u *UsbGadget) GetUsbState() (state string) {
// Check the auxiliary disc node first
discFile := "/sys/devices/platform/ff3e0000.usb2-phy/disc"
discBytes, err := os.ReadFile(discFile)
if err == nil {
discState := strings.TrimSpace(string(discBytes))
if discState == "DISCONNECTED" {
return "not attached"
func (u *UsbGadget) GetUsbState(enhancedDetection bool) (state string) {
if enhancedDetection {
discFile := "/sys/devices/platform/ff3e0000.usb2-phy/disc"
discBytes, err := os.ReadFile(discFile)
if err == nil {
discState := strings.TrimSpace(string(discBytes))
if discState == "DISCONNECTED" {
return "not attached"
}
}
}