Skip to content

feat: add channel width to interface info #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions client_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ func (ifi *Interface) parseAttributes(attrs []netlink.Attribute) error {
ifi.Device = int(nlenc.Uint64(a.Data))
case unix.NL80211_ATTR_WIPHY_FREQ:
ifi.Frequency = int(nlenc.Uint32(a.Data))
case unix.NL80211_ATTR_CHANNEL_WIDTH:
// NOTE: ChannelWidth copies the ordering of nl80211's channel width
// constants. This may not be the case on other operating systems.
ifi.ChannelWidth = ChannelWidth(nlenc.Uint32(a.Data))
}
}

Expand Down
41 changes: 41 additions & 0 deletions wifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,44 @@ func (t InterfaceType) String() string {
}
}

// A ChannelWidth is the width of a WiFi channel.
type ChannelWidth int

const (
ChannelWidth20NoHT ChannelWidth = iota
ChannelWidth20
ChannelWidth40
ChannelWidth80
ChannelWidth80P80
ChannelWidth160
ChannelWidth5
ChannelWidth10
)

// String returns the string representation of an InterfaceType.
func (t ChannelWidth) String() string {
switch t {
case ChannelWidth20NoHT:
return "20 MHz (no HT)"
case ChannelWidth20:
return "20 MHz"
case ChannelWidth40:
return "40 MHz"
case ChannelWidth80:
return "80 MHz"
case ChannelWidth80P80:
return "80+80 MHz"
case ChannelWidth160:
return "160 MHz"
case ChannelWidth5:
return "5 MHz"
case ChannelWidth10:
return "10 MHz"
default:
return fmt.Sprintf("unknown(%d)", t)
}
}

// An Interface is a WiFi network interface.
type Interface struct {
// The index of the interface.
Expand All @@ -124,6 +162,9 @@ type Interface struct {

// The interface's wireless frequency in MHz.
Frequency int

// The interface's wireless channel width.
ChannelWidth ChannelWidth
}

// StationInfo contains statistics about a WiFi interface operating in
Expand Down
Loading