Skip to content

Commit

Permalink
feat: IsWirelessSynchronized is optional in wireless configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
madhavilosetty-intel committed Nov 6, 2024
1 parent 8937ac1 commit 0847817
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enterpriseAssistant:
eaAddress: '' # Address of the EA server (example: https://<your EA Address>: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'
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions internal/config/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions internal/flags/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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}
Expand Down
14 changes: 10 additions & 4 deletions internal/local/amt/wsman.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions internal/local/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/local/lps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion internal/local/wifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions internal/local/wifi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down

0 comments on commit 0847817

Please sign in to comment.