github.com/dim13/unifi@v0.0.0-20230308161331-9b04946f5e93/sta.go (about) 1 // Copyright (c) 2014 The unifi Authors. All rights reserved. 2 // Use of this source code is governed by ISC-style license 3 // that can be found in the LICENSE file. 4 5 package unifi 6 7 type StaMap map[string]Sta 8 9 // Station data 10 type Sta struct { 11 u *Unifi 12 ID string `json:"_id"` 13 IsGuestByUsw bool `json:"_is_guest_by_usw,omitempty"` 14 LastSeenByUsw int `json:"_last_seen_by_usw,omitempty"` 15 UptimeByUsw int `json:"_uptime_by_usw,omitempty"` 16 AssocTime int `json:"assoc_time"` 17 FirstSeen int64 `json:"first_seen"` 18 IP string `json:"ip"` 19 IsGuest bool `json:"is_guest"` 20 IsWired bool `json:"is_wired"` 21 LastSeen int64 `json:"last_seen"` 22 LatestAssocTime int `json:"latest_assoc_time"` 23 Mac string `json:"mac"` 24 Network string `json:"network,omitempty"` 25 NetworkID string `json:"network_id,omitempty"` 26 Oui string `json:"oui"` 27 SiteID string `json:"site_id"` 28 SwDepth int `json:"sw_depth,omitempty"` 29 SwMac string `json:"sw_mac,omitempty"` 30 SwPort int `json:"sw_port,omitempty"` 31 Uptime int `json:"uptime"` 32 UserID string `json:"user_id"` 33 Hostname string `json:"hostname,omitempty"` 34 IsGuestByUap bool `json:"_is_guest_by_uap,omitempty"` 35 LastSeenByUap int `json:"_last_seen_by_uap,omitempty"` 36 RoamCount int `json:"roam_count,omitempty"` 37 UptimeByUap int `json:"_uptime_by_uap,omitempty"` 38 ApMac string `json:"ap_mac,omitempty"` 39 Authorized bool `json:"authorized,omitempty"` 40 BSSID string `json:"bssid,omitempty"` 41 BytesR int `json:"bytes-r,omitempty"` 42 Ccq int `json:"ccq,omitempty"` 43 Channel int `json:"channel,omitempty"` 44 ESSID string `json:"essid,omitempty"` 45 Idletime int `json:"idletime,omitempty"` 46 Is11R bool `json:"is_11r,omitempty"` 47 Noise int `json:"noise,omitempty"` 48 PowersaveEnabled bool `json:"powersave_enabled,omitempty"` 49 QosPolicyApplied bool `json:"qos_policy_applied,omitempty"` 50 Radio string `json:"radio,omitempty"` 51 RadioProto string `json:"radio_proto,omitempty"` 52 Rssi int `json:"rssi,omitempty"` 53 RxBytes int64 `json:"rx_bytes,omitempty"` 54 RxBytesR int64 `json:"rx_bytes-r,omitempty"` 55 RxPackets int64 `json:"rx_packets,omitempty"` 56 RxRate int64 `json:"rx_rate,omitempty"` 57 Signal int `json:"signal,omitempty"` 58 TxBytes int64 `json:"tx_bytes,omitempty"` 59 TxBytesR int64 `json:"tx_bytes-r,omitempty"` 60 TxPackets int64 `json:"tx_packets,omitempty"` 61 TxPower int64 `json:"tx_power,omitempty"` 62 TxRate int64 `json:"tx_rate,omitempty"` 63 Vlan int `json:"vlan,omitempty"` 64 } 65 66 // Returns a station name 67 func (s Sta) Name() string { 68 if s.Hostname != "" { 69 return s.Hostname 70 } 71 if s.IP != "" { 72 return s.IP 73 } 74 return s.Mac 75 } 76 77 func (s Sta) Block() error { 78 if s.u == nil { 79 return ErrLoginFirst 80 } 81 return s.u.stacmd(s.Mac, "block-sta") 82 } 83 84 func (s Sta) UnBlock() error { 85 if s.u == nil { 86 return ErrLoginFirst 87 } 88 return s.u.stacmd(s.Mac, "unblock-sta") 89 } 90 91 func (s Sta) Disconnect() error { 92 if s.u == nil { 93 return ErrLoginFirst 94 } 95 return s.u.stacmd(s.Mac, "kick-sta") 96 } 97 98 func (s Sta) AuthorizeGuest(minutes int) error { 99 if s.u == nil { 100 return ErrLoginFirst 101 } 102 return s.u.stacmd(s.Mac, "authorize-guest", minutes) 103 } 104 105 func (s Sta) UnauthorizeGuest() error { 106 if s.u == nil { 107 return ErrLoginFirst 108 } 109 return s.u.stacmd(s.Mac, "unauthorize-guest") 110 }