From 0847817d4bdb53751429a957d3b619a665a4fe01 Mon Sep 17 00:00:00 2001 From: madhavilosetty-intel Date: Tue, 5 Nov 2024 11:58:09 -0700 Subject: [PATCH] feat: IsWirelessSynchronized is optional in wireless configuration --- config.yaml | 1 + go.mod | 2 +- go.sum | 2 ++ internal/config/local.go | 1 + internal/flags/configure.go | 2 ++ internal/local/amt/wsman.go | 14 ++++++++++---- internal/local/configure.go | 6 +++--- internal/local/lps_test.go | 2 +- internal/local/wifi.go | 2 +- internal/local/wifi_test.go | 4 ++-- 10 files changed, 24 insertions(+), 12 deletions(-) diff --git a/config.yaml b/config.yaml index 5982c44d..76797209 100644 --- a/config.yaml +++ b/config.yaml @@ -11,6 +11,7 @@ enterpriseAssistant: eaAddress: '' # Address of the EA server (example: https://:8000) eaUsername: '' # Username for the EA server given in EA Settings eaPassword: '' # Password for the EA server given in EA Settings +wifiSyncEnabled: true wifiConfigs: - profileName: 'exampleWifiWPA2' # friendly name, alphanumeric only ssid: 'exampleSSID' diff --git a/go.mod b/go.mod index 272652a9..302a4a4b 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/gorilla/websocket v1.5.3 github.com/hirochachacha/go-smb2 v1.1.0 github.com/ilyakaznacheev/cleanenv v1.5.0 - github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.16.7 + github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.17.0 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.9.0 golang.org/x/sys v0.26.0 diff --git a/go.sum b/go.sum index cade7d54..cffd1641 100644 --- a/go.sum +++ b/go.sum @@ -36,6 +36,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.16.7 h1:fgztTxllw7+GvSj6KZ9m41g0M8n81/NP4zjPr6IrBCI= github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.16.7/go.mod h1:ZFZRyYEYWs2ngCuwzK+n+vc0ga1Hh4BRJYBiwXxDTD0= +github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.17.0 h1:2iDhRp5Td6aeCNjCPg6tJrtn2pcdjOhrXv/JV7CwfTM= +github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.17.0/go.mod h1:ZFZRyYEYWs2ngCuwzK+n+vc0ga1Hh4BRJYBiwXxDTD0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= diff --git a/internal/config/local.go b/internal/config/local.go index 8159b63d..e647d829 100644 --- a/internal/config/local.go +++ b/internal/config/local.go @@ -11,6 +11,7 @@ type ( TlsConfig TlsConfig `yaml:"tlsConfig"` WiredConfig EthernetConfig `yaml:"wiredConfig"` WifiConfigs []WifiConfig `yaml:"wifiConfigs"` + WiFiSyncEnabled bool `yaml:"wifiSyncEnabled"` Ieee8021xConfigs []Ieee8021xConfig `yaml:"ieee8021xConfigs"` ACMSettings ACMSettings `yaml:"acmactivate"` EnterpriseAssistant EnterpriseAssistant `yaml:"enterpriseAssistant"` diff --git a/internal/flags/configure.go b/internal/flags/configure.go index 6dcd45e0..d44b8cbb 100644 --- a/internal/flags/configure.go +++ b/internal/flags/configure.go @@ -685,6 +685,7 @@ func (f *Flags) handleAddWifiSettings() error { ieee8021xCfg := config.Ieee8021xConfig{} eaSettings := config.EnterpriseAssistant{} + f.flagSetAddWifiSettings.BoolVar(&f.LocalConfig.WiFiSyncEnabled, "wifiSyncEnabled", false, "Enable WiFi synchronization") f.flagSetAddWifiSettings.StringVar(&wifiCfg.ProfileName, "profileName", "", "specify wifi profile name name") f.flagSetAddWifiSettings.IntVar(&wifiCfg.AuthenticationMethod, "authenticationMethod", 0, "specify authentication method") f.flagSetAddWifiSettings.IntVar(&wifiCfg.EncryptionMethod, "encryptionMethod", 0, "specify encryption method") @@ -733,6 +734,7 @@ func (f *Flags) handleAddWifiSettings() error { eaSettings.EAConfigured = false if f.configContentV2 != "" && f.configV2Key != "" { + f.LocalConfig.WiFiSyncEnabled = f.LocalConfigV2.Configuration.Network.Wireless.WiFiSyncEnabled f.LocalConfig.WifiConfigs = []config.WifiConfig{} f.LocalConfig.Ieee8021xConfigs = []config.Ieee8021xConfig{} f.LocalConfig.EnterpriseAssistant = config.EnterpriseAssistant{EAConfigured: false} diff --git a/internal/local/amt/wsman.go b/internal/local/amt/wsman.go index 82b72bf7..5bdfda85 100644 --- a/internal/local/amt/wsman.go +++ b/internal/local/amt/wsman.go @@ -59,7 +59,7 @@ type WSMANer interface { // WiFi GetWiFiSettings() ([]wifi.WiFiEndpointSettingsResponse, error) DeleteWiFiSetting(instanceId string) error - EnableWiFi() error + EnableWiFi(enableSync bool) error AddWiFiSettings(wifiEndpointSettings wifi.WiFiEndpointSettingsRequest, ieee8021xSettings models.IEEE8021xSettings, wifiEndpoint, clientCredential, caCredential string) (wifiportconfiguration.Response, error) // Wired GetEthernetSettings() ([]ethernetport.SettingsResponse, error) @@ -289,14 +289,20 @@ func (g *GoWSMANMessages) DeleteKeyPair(instanceID string) error { _, err := g.wsmanMessages.AMT.PublicKeyManagementService.Delete(instanceID) return err } -func (g *GoWSMANMessages) EnableWiFi() error { +func (g *GoWSMANMessages) EnableWiFi(enableSync bool) error { response, err := g.wsmanMessages.AMT.WiFiPortConfigurationService.Get() if err != nil { return err } + // Determine the sync state based on input parameter + syncState := wifiportconfiguration.LocalSyncDisabled + if enableSync { + syncState = wifiportconfiguration.UnrestrictedSync + } + // if local sync not enable, enable it - if response.Body.WiFiPortConfigurationService.LocalProfileSynchronizationEnabled == wifiportconfiguration.LocalSyncDisabled { + if response.Body.WiFiPortConfigurationService.LocalProfileSynchronizationEnabled != syncState { putRequest := wifiportconfiguration.WiFiPortConfigurationServiceRequest{ RequestedState: response.Body.WiFiPortConfigurationService.RequestedState, EnabledState: response.Body.WiFiPortConfigurationService.EnabledState, @@ -306,7 +312,7 @@ func (g *GoWSMANMessages) EnableWiFi() error { SystemName: response.Body.WiFiPortConfigurationService.SystemName, CreationClassName: response.Body.WiFiPortConfigurationService.CreationClassName, Name: response.Body.WiFiPortConfigurationService.Name, - LocalProfileSynchronizationEnabled: wifiportconfiguration.UnrestrictedSync, + LocalProfileSynchronizationEnabled: syncState, LastConnectedSsidUnderMeControl: response.Body.WiFiPortConfigurationService.LastConnectedSsidUnderMeControl, NoHostCsmeSoftwarePolicy: response.Body.WiFiPortConfigurationService.NoHostCsmeSoftwarePolicy, UEFIWiFiProfileShareEnabled: response.Body.WiFiPortConfigurationService.UEFIWiFiProfileShareEnabled, diff --git a/internal/local/configure.go b/internal/local/configure.go index a8b4b16e..f572ea12 100644 --- a/internal/local/configure.go +++ b/internal/local/configure.go @@ -32,7 +32,7 @@ func (service *ProvisioningService) Configure() (err error) { case utils.SubCommandAddWifiSettings, utils.SubCommandWireless: return service.AddWifiSettings() case utils.SubCommandEnableWifiPort: - return service.EnableWifiPort() + return service.EnableWifiPort(true) case utils.SubCommandSetMEBx: if controlMode != 2 { log.Error("Device needs to be in admin control mode to set MEBx password.") @@ -56,8 +56,8 @@ func (service *ProvisioningService) Configure() (err error) { return utils.IncorrectCommandLineParameters } -func (service *ProvisioningService) EnableWifiPort() (err error) { - err = service.interfacedWsmanMessage.EnableWiFi() +func (service *ProvisioningService) EnableWifiPort(enableSync bool) (err error) { + err = service.interfacedWsmanMessage.EnableWiFi(enableSync) if err != nil { log.Error("Failed to enable wifi port and local profile synchronization.") return diff --git a/internal/local/lps_test.go b/internal/local/lps_test.go index 74f61048..69615a40 100644 --- a/internal/local/lps_test.go +++ b/internal/local/lps_test.go @@ -607,7 +607,7 @@ func (m MockWSMAN) AddPrivateKey(privateKey string) (string, error) { var errEnableWiFi error = nil -func (m MockWSMAN) EnableWiFi() error { +func (m MockWSMAN) EnableWiFi(enableSync bool) error { return errEnableWiFi } diff --git a/internal/local/wifi.go b/internal/local/wifi.go index c3f1c8e7..4beb82fb 100644 --- a/internal/local/wifi.go +++ b/internal/local/wifi.go @@ -59,7 +59,7 @@ func (service *ProvisioningService) AddWifiSettings() (err error) { return utils.WiFiConfigurationFailed } - err = service.EnableWifiPort() + err = service.EnableWifiPort(service.flags.LocalConfig.WiFiSyncEnabled) if err != nil { return err } diff --git a/internal/local/wifi_test.go b/internal/local/wifi_test.go index 859c3a73..4e45a407 100644 --- a/internal/local/wifi_test.go +++ b/internal/local/wifi_test.go @@ -127,13 +127,13 @@ func TestEnableWifiErrors(t *testing.T) { f := &flags.Flags{} t.Run("expect success for EnableWifi", func(t *testing.T) { lps := setupService(f) - err := lps.EnableWifiPort() + err := lps.EnableWifiPort(false) assert.NoError(t, err) }) t.Run("expect failure for EnableWifi", func(t *testing.T) { errEnableWiFi = errTestError lps := setupService(f) - err := lps.EnableWifiPort() + err := lps.EnableWifiPort(true) assert.Error(t, err) errEnableWiFi = nil })