Signed-off-by: neiledgar <neil.edgar@btinternet.com>
This commit is contained in:
parent
9b97f44a70
commit
7e4d9bd150
9 changed files with 122 additions and 69 deletions
6
vendor/github.com/mdlayher/wifi/client.go
generated
vendored
6
vendor/github.com/mdlayher/wifi/client.go
generated
vendored
|
|
@ -45,8 +45,8 @@ func (c *Client) BSS(ifi *Interface) (*BSS, error) {
|
|||
return c.c.BSS(ifi)
|
||||
}
|
||||
|
||||
// StationInfo retrieves station statistics about a WiFi interface.
|
||||
func (c *Client) StationInfo(ifi *Interface) (*StationInfo, error) {
|
||||
// StationInfo retrieves all station statistics about a WiFi interface.
|
||||
func (c *Client) StationInfo(ifi *Interface) ([]*StationInfo, error) {
|
||||
return c.c.StationInfo(ifi)
|
||||
}
|
||||
|
||||
|
|
@ -55,5 +55,5 @@ type osClient interface {
|
|||
Close() error
|
||||
Interfaces() ([]*Interface, error)
|
||||
BSS(ifi *Interface) (*BSS, error)
|
||||
StationInfo(ifi *Interface) (*StationInfo, error)
|
||||
StationInfo(ifi *Interface) ([]*StationInfo, error)
|
||||
}
|
||||
|
|
|
|||
65
vendor/github.com/mdlayher/wifi/client_linux.go
generated
vendored
65
vendor/github.com/mdlayher/wifi/client_linux.go
generated
vendored
|
|
@ -18,7 +18,6 @@ import (
|
|||
|
||||
// Errors which may occur when interacting with generic netlink.
|
||||
var (
|
||||
errMultipleMessages = errors.New("expected only one generic netlink message")
|
||||
errInvalidCommand = errors.New("invalid generic netlink response command")
|
||||
errInvalidFamilyVersion = errors.New("invalid generic netlink response family version")
|
||||
)
|
||||
|
|
@ -120,9 +119,9 @@ func (c *client) BSS(ifi *Interface) (*BSS, error) {
|
|||
return parseBSS(msgs)
|
||||
}
|
||||
|
||||
// StationInfo requests that nl80211 return station info for the specified
|
||||
// StationInfo requests that nl80211 return all station info for the specified
|
||||
// Interface.
|
||||
func (c *client) StationInfo(ifi *Interface) (*StationInfo, error) {
|
||||
func (c *client) StationInfo(ifi *Interface) ([]*StationInfo, error) {
|
||||
b, err := netlink.MarshalAttributes(ifi.idAttrs())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -147,22 +146,25 @@ func (c *client) StationInfo(ifi *Interface) (*StationInfo, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
switch len(msgs) {
|
||||
case 0:
|
||||
if len(msgs) == 0 {
|
||||
return nil, os.ErrNotExist
|
||||
case 1:
|
||||
break
|
||||
default:
|
||||
return nil, errMultipleMessages
|
||||
}
|
||||
|
||||
if err := c.checkMessages(msgs, nl80211.CmdNewStation); err != nil {
|
||||
return nil, err
|
||||
stations := make([]*StationInfo, len(msgs))
|
||||
for i := range msgs {
|
||||
if err := c.checkMessages(msgs, nl80211.CmdNewStation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if stations[i], err = parseStationInfo(msgs[i].Data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return parseStationInfo(msgs[0].Data)
|
||||
return stations, nil
|
||||
}
|
||||
|
||||
|
||||
// checkMessages verifies that response messages from generic netlink contain
|
||||
// the command and family version we expect.
|
||||
func (c *client) checkMessages(msgs []genetlink.Message, command uint8) error {
|
||||
|
|
@ -323,25 +325,32 @@ func parseStationInfo(b []byte) (*StationInfo, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var info StationInfo
|
||||
for _, a := range attrs {
|
||||
// The other attributes that are returned here appear to indicate the
|
||||
// interface index and MAC address, which is information we already
|
||||
// possess. No need to parse them for now.
|
||||
if a.Type != nl80211.AttrStaInfo {
|
||||
|
||||
switch a.Type {
|
||||
case nl80211.AttrMac:
|
||||
info.HardwareAddr = net.HardwareAddr(a.Data)
|
||||
|
||||
case nl80211.AttrStaInfo:
|
||||
nattrs, err := netlink.UnmarshalAttributes(a.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := (&info).parseAttributes(nattrs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// nl80211.AttrStaInfo is last attibute we are interested in
|
||||
return &info, nil
|
||||
|
||||
default:
|
||||
// The other attributes that are returned here appear
|
||||
// nl80211.AttrIfindex, nl80211.AttrGeneration
|
||||
// No need to parse them for now.
|
||||
continue
|
||||
}
|
||||
|
||||
nattrs, err := netlink.UnmarshalAttributes(a.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var info StationInfo
|
||||
if err := (&info).parseAttributes(nattrs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// No station info found
|
||||
|
|
|
|||
2
vendor/github.com/mdlayher/wifi/client_others.go
generated
vendored
2
vendor/github.com/mdlayher/wifi/client_others.go
generated
vendored
|
|
@ -28,6 +28,6 @@ func (c *client) BSS(ifi *Interface) (*BSS, error) {
|
|||
}
|
||||
|
||||
// StationInfo always returns an error.
|
||||
func (c *client) StationInfo(ifi *Interface) (*StationInfo, error) {
|
||||
func (c *client) StationInfo(ifi *Interface) ([]*StationInfo, error) {
|
||||
return nil, errUnimplemented
|
||||
}
|
||||
|
|
|
|||
3
vendor/github.com/mdlayher/wifi/wifi.go
generated
vendored
3
vendor/github.com/mdlayher/wifi/wifi.go
generated
vendored
|
|
@ -128,6 +128,9 @@ type Interface struct {
|
|||
// StationInfo contains statistics about a WiFi interface operating in
|
||||
// station mode.
|
||||
type StationInfo struct {
|
||||
// The hardware address of the station.
|
||||
HardwareAddr net.HardwareAddr
|
||||
|
||||
// The time since the station last connected.
|
||||
Connected time.Duration
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue