Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/config/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type IEEE8021x struct {
}

type TLS struct {
SigningAuthority string `yaml:"signingAuthority"`
MutualAuthentication bool `yaml:"mutualAuthentication"`
Enabled bool `yaml:"enabled"`
TrustedCN []string `yaml:"trustedCN"`
Expand Down
208 changes: 198 additions & 10 deletions pkg/wsman/cim/wifi/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package wifi

import "strings"

const (
CIMWiFiEndpoint string = "CIM_WiFiEndpoint"
CIMWiFiEndpointSettings string = "CIM_WiFiEndpointSettings"
Expand Down Expand Up @@ -37,6 +39,19 @@ var authenticationMethodMap = map[AuthenticationMethod]string{
AuthenticationMethodWPA3OWE: "WPA3OWE",
}

// authenticationMethodReverseMap is a reverse lookup map for AuthenticationMethod enumeration.
var authenticationMethodReverseMap = map[string]AuthenticationMethod{
"OTHER": AuthenticationMethodOther,
"OPENSYSTEM": AuthenticationMethodOpenSystem,
"SHAREDKEY": AuthenticationMethodSharedKey,
"WPAPSK": AuthenticationMethodWPAPSK,
"WPAIEEE8021X": AuthenticationMethodWPAIEEE8021x,
"WPA2PSK": AuthenticationMethodWPA2PSK,
"WPA2IEEE8021X": AuthenticationMethodWPA2IEEE8021x,
"WPA3SAE": AuthenticationMethodWPA3SAE,
"WPA3OWE": AuthenticationMethodWPA3OWE,
}

// String returns a human-readable string representation of the AuthenticationMethod enumeration.
func (e AuthenticationMethod) String() string {
if s, ok := authenticationMethodMap[e]; ok {
Expand All @@ -46,6 +61,16 @@ func (e AuthenticationMethod) String() string {
return ValueNotFound
}

// ParseAuthenticationMethod returns the AuthenticationMethod enumeration value for a given string.
// The comparison is case-insensitive.
func ParseAuthenticationMethod(s string) (AuthenticationMethod, bool) {
if method, ok := authenticationMethodReverseMap[strings.ToUpper(s)]; ok {
return method, true
}

return 0, false
}

const (
BSSTypeUnknown BSSType = 0
BSSTypeIndependent BSSType = 2
Expand All @@ -59,6 +84,13 @@ var bssTypeMap = map[BSSType]string{
BSSTypeInfrastructure: "Infrastructure",
}

// bssTypeReverseMap is a reverse lookup map for BSSType enumeration.
var bssTypeReverseMap = map[string]BSSType{
"UNKNOWN": BSSTypeUnknown,
"INDEPENDENT": BSSTypeIndependent,
"INFRASTRUCTURE": BSSTypeInfrastructure,
}

// String returns a human-readable string representation of the BSSType enumeration.
func (e BSSType) String() string {
if s, ok := bssTypeMap[e]; ok {
Expand All @@ -68,6 +100,16 @@ func (e BSSType) String() string {
return ValueNotFound
}

// ParseBSSType returns the BSSType enumeration value for a given string.
// The comparison is case-insensitive.
func ParseBSSType(s string) (BSSType, bool) {
if bssType, ok := bssTypeReverseMap[strings.ToUpper(s)]; ok {
return bssType, true
}

return 0, false
}

const (
EnabledStateWifiDisabled EnabledState = 3
EnabledStateWifiEnabledS0 EnabledState = 32768
Expand All @@ -81,6 +123,13 @@ var enabledStateMap = map[EnabledState]string{
EnabledStateWifiEnabledS0SxAC: "WifiEnabledS0SxAC",
}

// enabledStateReverseMap is a reverse lookup map for EnabledState enumeration.
var enabledStateReverseMap = map[string]EnabledState{
"WIFIDISABLED": EnabledStateWifiDisabled,
"WIFIENABLEDS0": EnabledStateWifiEnabledS0,
"WIFIENABLEDS0SXAC": EnabledStateWifiEnabledS0SxAC,
}

// String returns a human-readable string representation of the EnabledState enumeration.
func (e EnabledState) String() string {
if s, ok := enabledStateMap[e]; ok {
Expand All @@ -90,21 +139,40 @@ func (e EnabledState) String() string {
return ValueNotFound
}

// ParseEnabledState returns the EnabledState enumeration value for a given string.
// The comparison is case-insensitive.
func ParseEnabledState(s string) (EnabledState, bool) {
if state, ok := enabledStateReverseMap[strings.ToUpper(s)]; ok {
return state, true
}

return 0, false
}

const (
EncryptionMethod_Other EncryptionMethod = iota + 1
EncryptionMethod_WEP
EncryptionMethod_TKIP
EncryptionMethod_CCMP
EncryptionMethod_None
EncryptionMethodOther EncryptionMethod = iota + 1
EncryptionMethodWEP
EncryptionMethodTKIP
EncryptionMethodCCMP
EncryptionMethodNone
)

// encryptionMethodMap is a map of the EncryptionMethod enumeration.
var encryptionMethodMap = map[EncryptionMethod]string{
EncryptionMethod_Other: "Other",
EncryptionMethod_WEP: "WEP",
EncryptionMethod_TKIP: "TKIP",
EncryptionMethod_CCMP: "CCMP",
EncryptionMethod_None: "None",
EncryptionMethodOther: "Other",
EncryptionMethodWEP: "WEP",
EncryptionMethodTKIP: "TKIP",
EncryptionMethodCCMP: "CCMP",
EncryptionMethodNone: "None",
}

// encryptionMethodReverseMap is a reverse lookup map for EncryptionMethod enumeration.
var encryptionMethodReverseMap = map[string]EncryptionMethod{
"OTHER": EncryptionMethodOther,
"WEP": EncryptionMethodWEP,
"TKIP": EncryptionMethodTKIP,
"CCMP": EncryptionMethodCCMP,
"NONE": EncryptionMethodNone,
}

// String returns a human-readable string representation of the EncryptionMethod enumeration.
Expand All @@ -116,6 +184,16 @@ func (e EncryptionMethod) String() string {
return ValueNotFound
}

// ParseEncryptionMethod returns the EncryptionMethod enumeration value for a given string.
// The comparison is case-insensitive.
func ParseEncryptionMethod(s string) (EncryptionMethod, bool) {
if method, ok := encryptionMethodReverseMap[strings.ToUpper(s)]; ok {
return method, true
}

return 0, false
}

const (
HealthStateUnknown HealthState = 0
HealthStateOK HealthState = 5
Expand All @@ -128,6 +206,7 @@ const (

// healthStateMap is a map of the HealthState enumeration.
var healthStateMap = map[HealthState]string{
HealthStateUnknown: "Unknown",
HealthStateOK: "OK",
HealthStateDegraded: "Degraded",
HealthStateMinorFailure: "MinorFailure",
Expand All @@ -136,6 +215,17 @@ var healthStateMap = map[HealthState]string{
HealthStateNonRecoverableError: "NonRecoverableError",
}

// healthStateReverseMap is a reverse lookup map for HealthState enumeration.
var healthStateReverseMap = map[string]HealthState{
"UNKNOWN": HealthStateUnknown,
"OK": HealthStateOK,
"DEGRADED": HealthStateDegraded,
"MINORFAILURE": HealthStateMinorFailure,
"MAJORFAILURE": HealthStateMajorFailure,
"CRITICALFAILURE": HealthStateCriticalFailure,
"NONRECOVERABLEERROR": HealthStateNonRecoverableError,
}

// String returns a human-readable string representation of the HealthState enumeration.
func (e HealthState) String() string {
if s, ok := healthStateMap[e]; ok {
Expand All @@ -145,6 +235,16 @@ func (e HealthState) String() string {
return ValueNotFound
}

// ParseHealthState returns the HealthState enumeration value for a given string.
// The comparison is case-insensitive.
func ParseHealthState(s string) (HealthState, bool) {
if state, ok := healthStateReverseMap[strings.ToUpper(s)]; ok {
return state, true
}

return 0, false
}

const (
LinkTechnologyUnknown LinkTechnology = iota
LinkTechnologyOther
Expand Down Expand Up @@ -176,6 +276,22 @@ var linkTechnologyMap = map[LinkTechnology]string{
LinkTechnologyWirelessLAN: "WirelessLAN",
}

// linkTechnologyReverseMap is a reverse lookup map for LinkTechnology enumeration.
var linkTechnologyReverseMap = map[string]LinkTechnology{
"UNKNOWN": LinkTechnologyUnknown,
"OTHER": LinkTechnologyOther,
"ETHERNET": LinkTechnologyEthernet,
"IB": LinkTechnologyIB,
"FC": LinkTechnologyFC,
"FDDI": LinkTechnologyFDDI,
"ATM": LinkTechnologyATM,
"TOKENRING": LinkTechnologyTokenRing,
"FRAMERELAY": LinkTechnologyFrameRelay,
"INFRARED": LinkTechnologyInfrared,
"BLUETOOTH": LinkTechnologyBlueTooth,
"WIRELESSLAN": LinkTechnologyWirelessLAN,
}

// String returns a human-readable string representation of the LinkTechnology enumeration.
func (e LinkTechnology) String() string {
if s, ok := linkTechnologyMap[e]; ok {
Expand All @@ -185,6 +301,16 @@ func (e LinkTechnology) String() string {
return ValueNotFound
}

// ParseLinkTechnology returns the LinkTechnology enumeration value for a given string.
// The comparison is case-insensitive.
func ParseLinkTechnology(s string) (LinkTechnology, bool) {
if tech, ok := linkTechnologyReverseMap[strings.ToUpper(s)]; ok {
return tech, true
}

return 0, false
}

const (
RequestedStateWifiDisabled RequestedState = 3
RequestedStateWifiEnabledS0 RequestedState = 32768
Expand All @@ -198,6 +324,13 @@ var requestedStateMap = map[RequestedState]string{
RequestedStateWifiEnabledS0SxAC: "WifiEnabledS0SxAC",
}

// requestedStateReverseMap is a reverse lookup map for RequestedState enumeration.
var requestedStateReverseMap = map[string]RequestedState{
"WIFIDISABLED": RequestedStateWifiDisabled,
"WIFIENABLEDS0": RequestedStateWifiEnabledS0,
"WIFIENABLEDS0SXAC": RequestedStateWifiEnabledS0SxAC,
}

// String returns a human-readable string representation of the RequestedState enumeration.
func (e RequestedState) String() string {
if s, ok := requestedStateMap[e]; ok {
Expand All @@ -207,6 +340,16 @@ func (e RequestedState) String() string {
return ValueNotFound
}

// ParseRequestedState returns the RequestedState enumeration value for a given string.
// The comparison is case-insensitive.
func ParseRequestedState(s string) (RequestedState, bool) {
if state, ok := requestedStateReverseMap[strings.ToUpper(s)]; ok {
return state, true
}

return 0, false
}

const (
CompletedWithNoError ReturnValue = iota
NotSupported
Expand Down Expand Up @@ -236,6 +379,21 @@ var returnValueMap = map[ReturnValue]string{
Busy: "Busy",
}

// returnValueReverseMap is a reverse lookup map for ReturnValue enumeration.
var returnValueReverseMap = map[string]ReturnValue{
"COMPLETEDWITHNOERROR": CompletedWithNoError,
"NOTSUPPORTED": NotSupported,
"UNKNOWNORUNSPECIFIEDERROR": UnknownOrUnspecifiedError,
"CANNOTCOMPLETEWITHINTIMEOUTPERIOD": CannotCompleteWithinTimeoutPeriod,
"FAILED": Failed,
"INVALIDPARAMETER": InvalidParameter,
"INUSE": InUse,
"METHODPARAMETERSCHECKEDJOBSTARTED": MethodParametersCheckedJobStarted,
"INVALIDSTATETRANSITION": InvalidStateTransition,
"USEOFTIMEOUTPARAMETERNOTSUPPORTED": UseOfTimeoutParameterNotSupported,
"BUSY": Busy,
}

// String returns a human-readable string representation of the ReturnValue enumeration.
func (e ReturnValue) String() string {
if s, ok := returnValueMap[e]; ok {
Expand All @@ -245,6 +403,16 @@ func (e ReturnValue) String() string {
return ValueNotFound
}

// ParseReturnValue returns the ReturnValue enumeration value for a given string.
// The comparison is case-insensitive.
func ParseReturnValue(s string) (ReturnValue, bool) {
if value, ok := returnValueReverseMap[strings.ToUpper(s)]; ok {
return value, true
}

return 0, false
}

const (
PortTypeUnknown PortType = 0
PortTypeOther PortType = 1
Expand All @@ -264,6 +432,16 @@ var portTypeMap = map[PortType]string{
PortType80211n: "802.11n",
}

// portTypeReverseMap is a reverse lookup map for PortType enumeration.
var portTypeReverseMap = map[string]PortType{
"UNKNOWN": PortTypeUnknown,
"OTHER": PortTypeOther,
"802.11A": PortType80211a,
"802.11B": PortType80211b,
"802.11G": PortType80211g,
"802.11N": PortType80211n,
}

// String returns a human-readable string representation of the PortType enumeration.
func (e PortType) String() string {
if s, ok := portTypeMap[e]; ok {
Expand All @@ -272,3 +450,13 @@ func (e PortType) String() string {

return ValueNotFound
}

// ParsePortType returns the PortType enumeration value for a given string.
// The comparison is case-insensitive.
func ParsePortType(s string) (PortType, bool) {
if portType, ok := portTypeReverseMap[strings.ToUpper(s)]; ok {
return portType, true
}

return 0, false
}
38 changes: 33 additions & 5 deletions pkg/wsman/cim/wifi/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ func TestEncryptionMethod_String(t *testing.T) {
state EncryptionMethod
expected string
}{
{EncryptionMethod_Other, "Other"},
{EncryptionMethod_WEP, "WEP"},
{EncryptionMethod_TKIP, "TKIP"},
{EncryptionMethod_CCMP, "CCMP"},
{EncryptionMethod_None, "None"},
{EncryptionMethodOther, "Other"},
{EncryptionMethodWEP, "WEP"},
{EncryptionMethodTKIP, "TKIP"},
{EncryptionMethodCCMP, "CCMP"},
{EncryptionMethodNone, "None"},
{EncryptionMethod(999), "Value not found in map"},
}

Expand Down Expand Up @@ -208,3 +208,31 @@ func TestPortType_String(t *testing.T) {
}
}
}

func TestParseEncryptionMethod(t *testing.T) {
tests := []struct {
input string
expected EncryptionMethod
success bool
}{
{"Other", EncryptionMethodOther, true},
{"WEP", EncryptionMethodWEP, true},
{"TKIP", EncryptionMethodTKIP, true},
{"CCMP", EncryptionMethodCCMP, true},
{"None", EncryptionMethodNone, true},
{"wep", EncryptionMethodWEP, true}, // case insensitive
{"tkip", EncryptionMethodTKIP, true}, // case insensitive
{"invalid", EncryptionMethod(0), false}, // invalid
}

for _, test := range tests {
result, ok := ParseEncryptionMethod(test.input)
if ok != test.success {
t.Errorf("For input %s, expected success %v but got %v", test.input, test.success, ok)
}

if result != test.expected {
t.Errorf("For input %s, expected %v but got %v", test.input, test.expected, result)
}
}
}
Loading