Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Raffelt <lukas.raffelt@mercedes-benz.com>

reset integration test to default parameters

Signed-off-by: Lukas Raffelt <lukas.raffelt@mercedes-benz.com>
  • Loading branch information
lukas-mbag committed Dec 11, 2023
1 parent 820400a commit 70dc142
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
19 changes: 10 additions & 9 deletions client_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,21 +552,22 @@ func decodeSSID(b []byte) string {
return buf.String()
}

// func decodeBSSLoad(b []byte) (stationCount uint16, channelUtilization uint8, availableAdmissionCapacity uint1) {
// decodeBSSLoad Decodes the BSSLoad IE. Supports Version 1 and Version 2
// values according to https://raw.githubusercontent.com/wireshark/wireshark/master/epan/dissectors/packet-ieee80211.c
func decodeBSSLoad(b []byte) (*BSSLoad, error) {
// values from https://raw.githubusercontent.com/wireshark/wireshark/master/epan/dissectors/packet-ieee80211.c
// TODO(lukas-mbag) add error handling
var load BSSLoad
if len(b) == 5 {
// Wiresahrk calls this "802.11e CCA Version"
load.Version = 2
load.StationCount = binary.LittleEndian.Uint16(b[0:])
load.ChannelUtilization = b[2]
load.AvailableAdmissionCapacity = binary.LittleEndian.Uint16(b[3:])
load.StationCount = binary.LittleEndian.Uint16(b[0:2]) // first 2 bytes
load.ChannelUtilization = b[2] // next 1 byte
load.AvailableAdmissionCapacity = binary.LittleEndian.Uint16(b[3:5]) // last 2 bytes
} else if len(b) == 4 {
// Wiresahrk calls this "Cisco QBSS Version 1 - non CCA"
load.Version = 1
load.StationCount = binary.LittleEndian.Uint16(b[0:])
load.ChannelUtilization = b[2]
load.AvailableAdmissionCapacity = uint16(b[3])
load.StationCount = binary.LittleEndian.Uint16(b[0:2]) // first 2 bytes
load.ChannelUtilization = b[2] // next 1 byte
load.AvailableAdmissionCapacity = uint16(b[3]) // next 1 byte
} else {
err := errInvalidBSSLoad
return nil, err
Expand Down
11 changes: 10 additions & 1 deletion client_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,8 @@ func Test_decodeBSSLoad(t *testing.T) {
wantChannelUtilization uint8
wantAvailableAdmissionCapacity uint16
}{
{name: "Parse BSS Load", args: args{b: []byte{3, 0, 8, 0x8D, 0x5B}}, wantVersion: 2, wantStationCount: 3, wantChannelUtilization: 8, wantAvailableAdmissionCapacity: 23437},
{name: "Parse BSS Load Normal", args: args{b: []byte{3, 0, 8, 0x8D, 0x5B}}, wantVersion: 2, wantStationCount: 3, wantChannelUtilization: 8, wantAvailableAdmissionCapacity: 23437},
{name: "Parse BSS Load Version 1", args: args{b: []byte{9, 0, 8, 0x8D}}, wantVersion: 1, wantStationCount: 9, wantChannelUtilization: 8, wantAvailableAdmissionCapacity: 141},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -591,3 +592,11 @@ func Test_decodeBSSLoad(t *testing.T) {
})
}
}

func Test_decodeBSSLoadError(t *testing.T) {
t.Parallel()
_, err := decodeBSSLoad([]byte{3, 0, 8})
if err == nil {
t.Error("want error on bogus IE with wrong length")
}
}
17 changes: 11 additions & 6 deletions wifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,17 @@ type BSSLoad struct {

// String returns the string representation of a BSSLoad.
func (l BSSLoad) String() string {
return fmt.Sprintf("BSSLoad Version: %d stationCount: %d channelUtilization: %d/255 availableAdmissionCapacity: %d [*32us/s]\n",
l.Version,
l.StationCount,
l.ChannelUtilization,
l.AvailableAdmissionCapacity,
)
if l.Version == 1 {
return fmt.Sprintf("BSSLoad Version: %d stationCount: %d channelUtilization: %d/255 availableAdmissionCapacity: %d\n",
l.Version, l.StationCount, l.ChannelUtilization, l.AvailableAdmissionCapacity,
)
} else if l.Version == 2 {
return fmt.Sprintf("BSSLoad Version: %d stationCount: %d channelUtilization: %d/255 availableAdmissionCapacity: %d [*32us/s]\n",
l.Version, l.StationCount, l.ChannelUtilization, l.AvailableAdmissionCapacity,
)
} else {
return fmt.Sprintf("invalid BSSLoad Version: %d", l.Version)
}
}

// A BSS is an 802.11 basic service set. It contains information about a wireless
Expand Down

0 comments on commit 70dc142

Please sign in to comment.