use frequency of airtime to get channel
to get real/current used values + fix naming
This commit is contained in:
parent
57955f30e3
commit
88d7e53cdb
|
@ -5,7 +5,7 @@ const (
|
|||
)
|
||||
|
||||
type Channel struct {
|
||||
Frequenz uint32
|
||||
Frequency uint32
|
||||
AllowedInEU bool
|
||||
DFS bool
|
||||
Indoor bool
|
||||
|
@ -16,81 +16,77 @@ var (
|
|||
ChannelEU = true
|
||||
|
||||
ChannelList = map[uint32]*Channel{
|
||||
1: &Channel{Frequenz: 2412, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
//2: &Channel{Frequenz: 2417, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
//3: &Channel{Frequenz: 2422, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
//4: &Channel{Frequenz: 2427, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
5: &Channel{Frequenz: 2432, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
//6: &Channel{Frequenz: 2437, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
//7: &Channel{Frequenz: 2442, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
//8: &Channel{Frequenz: 2447, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
9: &Channel{Frequenz: 2452, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
//10: &Channel{Frequenz: 2457, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
//11: &Channel{Frequenz: 2462, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
//12: &Channel{Frequenz: 2467, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
13: &Channel{Frequenz: 2472, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
//14: &Channel{Frequenz: 2484, AllowedInEU: false, DFS: false, Indoor: false, SDR: false},
|
||||
//32: &Channel{Frequenz: 5160, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
34: &Channel{Frequenz: 5170, AllowedInEU: false, DFS: false, Indoor: true, SDR: false},
|
||||
36: &Channel{Frequenz: 5180, AllowedInEU: true, DFS: false, Indoor: true, SDR: false},
|
||||
38: &Channel{Frequenz: 5190, AllowedInEU: false, DFS: false, Indoor: true, SDR: false},
|
||||
//40 MHz - 40: &Channel{Frequenz: 5200, AllowedInEU: true, DFS: false, Indoor: true, SDR: false},
|
||||
42: &Channel{Frequenz: 5210, AllowedInEU: false, DFS: false, Indoor: true, SDR: false},
|
||||
44: &Channel{Frequenz: 5220, AllowedInEU: true, DFS: false, Indoor: true, SDR: false},
|
||||
46: &Channel{Frequenz: 5230, AllowedInEU: false, DFS: false, Indoor: true, SDR: false},
|
||||
//40 MHz - 48: &Channel{Frequenz: 5240, AllowedInEU: true, DFS: false, Indoor: true, SDR: false},
|
||||
//50: &Channel{Frequenz: 5250, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
52: &Channel{Frequenz: 5260, AllowedInEU: true, DFS: true, Indoor: true, SDR: false},
|
||||
54: &Channel{Frequenz: 5270, AllowedInEU: false, DFS: true, Indoor: true, SDR: false},
|
||||
//40 MHz - 56: &Channel{Frequenz: 5280, AllowedInEU: true, DFS: true, Indoor: true, SDR: false},
|
||||
58: &Channel{Frequenz: 5290, AllowedInEU: false, DFS: true, Indoor: true, SDR: false},
|
||||
60: &Channel{Frequenz: 5300, AllowedInEU: true, DFS: true, Indoor: true, SDR: false},
|
||||
62: &Channel{Frequenz: 5310, AllowedInEU: false, DFS: true, Indoor: true, SDR: false},
|
||||
//40 MHz -64: &Channel{Frequenz: 5320, AllowedInEU: true, DFS: true, Indoor: true, SDR: false},
|
||||
68: &Channel{Frequenz: 5340, AllowedInEU: true, DFS: true, Indoor: true, SDR: false},
|
||||
96: &Channel{Frequenz: 5480, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
100: &Channel{Frequenz: 5500, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
102: &Channel{Frequenz: 5510, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
//40 MHz -104: &Channel{Frequenz: 5520, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
106: &Channel{Frequenz: 5530, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
108: &Channel{Frequenz: 5540, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
110: &Channel{Frequenz: 5550, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
//40 MHz -112: &Channel{Frequenz: 5560, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
114: &Channel{Frequenz: 5570, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
/*
|
||||
116: &Channel{Frequenz: 5580, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
118: &Channel{Frequenz: 5590, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
120: &Channel{Frequenz: 5600, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
122: &Channel{Frequenz: 5610, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
124: &Channel{Frequenz: 5620, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
126: &Channel{Frequenz: 5630, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
128: &Channel{Frequenz: 5640, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
132: &Channel{Frequenz: 5660, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
*/
|
||||
134: &Channel{Frequenz: 5670, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
//40 MHz -136: &Channel{Frequenz: 5680, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
138: &Channel{Frequenz: 5690, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
//40 MHz -140: &Channel{Frequenz: 5700, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
/*
|
||||
142: &Channel{Frequenz: 5710, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
144: &Channel{Frequenz: 5720, AllowedInEU: true, DFS: true, Indoor: false, SDR: true},
|
||||
149: &Channel{Frequenz: 5745, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
151: &Channel{Frequenz: 5755, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
153: &Channel{Frequenz: 5765, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
155: &Channel{Frequenz: 5775, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
157: &Channel{Frequenz: 5785, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
159: &Channel{Frequenz: 5795, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
161: &Channel{Frequenz: 5805, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
165: &Channel{Frequenz: 5825, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
169: &Channel{Frequenz: 5845, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
173: &Channel{Frequenz: 5865, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
*/
|
||||
1: &Channel{Frequency: 2412, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
2: &Channel{Frequency: 2417, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
3: &Channel{Frequency: 2422, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
4: &Channel{Frequency: 2427, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
5: &Channel{Frequency: 2432, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
6: &Channel{Frequency: 2437, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
7: &Channel{Frequency: 2442, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
8: &Channel{Frequency: 2447, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
9: &Channel{Frequency: 2452, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
10: &Channel{Frequency: 2457, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
11: &Channel{Frequency: 2462, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
12: &Channel{Frequency: 2467, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
13: &Channel{Frequency: 2472, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
14: &Channel{Frequency: 2484, AllowedInEU: false, DFS: false, Indoor: false, SDR: false},
|
||||
32: &Channel{Frequency: 5160, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
|
||||
34: &Channel{Frequency: 5170, AllowedInEU: false, DFS: false, Indoor: true, SDR: false},
|
||||
36: &Channel{Frequency: 5180, AllowedInEU: true, DFS: false, Indoor: true, SDR: false},
|
||||
38: &Channel{Frequency: 5190, AllowedInEU: false, DFS: false, Indoor: true, SDR: false},
|
||||
40: &Channel{Frequency: 5200, AllowedInEU: true, DFS: false, Indoor: true, SDR: false},
|
||||
42: &Channel{Frequency: 5210, AllowedInEU: false, DFS: false, Indoor: true, SDR: false},
|
||||
44: &Channel{Frequency: 5220, AllowedInEU: true, DFS: false, Indoor: true, SDR: false},
|
||||
46: &Channel{Frequency: 5230, AllowedInEU: false, DFS: false, Indoor: true, SDR: false},
|
||||
48: &Channel{Frequency: 5240, AllowedInEU: true, DFS: false, Indoor: true, SDR: false},
|
||||
50: &Channel{Frequency: 5250, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
52: &Channel{Frequency: 5260, AllowedInEU: true, DFS: true, Indoor: true, SDR: false},
|
||||
54: &Channel{Frequency: 5270, AllowedInEU: false, DFS: true, Indoor: true, SDR: false},
|
||||
56: &Channel{Frequency: 5280, AllowedInEU: true, DFS: true, Indoor: true, SDR: false},
|
||||
58: &Channel{Frequency: 5290, AllowedInEU: false, DFS: true, Indoor: true, SDR: false},
|
||||
60: &Channel{Frequency: 5300, AllowedInEU: true, DFS: true, Indoor: true, SDR: false},
|
||||
62: &Channel{Frequency: 5310, AllowedInEU: false, DFS: true, Indoor: true, SDR: false},
|
||||
64: &Channel{Frequency: 5320, AllowedInEU: true, DFS: true, Indoor: true, SDR: false},
|
||||
68: &Channel{Frequency: 5340, AllowedInEU: true, DFS: true, Indoor: true, SDR: false},
|
||||
96: &Channel{Frequency: 5480, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
100: &Channel{Frequency: 5500, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
102: &Channel{Frequency: 5510, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
104: &Channel{Frequency: 5520, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
106: &Channel{Frequency: 5530, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
108: &Channel{Frequency: 5540, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
110: &Channel{Frequency: 5550, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
112: &Channel{Frequency: 5560, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
114: &Channel{Frequency: 5570, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
116: &Channel{Frequency: 5580, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
118: &Channel{Frequency: 5590, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
120: &Channel{Frequency: 5600, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
122: &Channel{Frequency: 5610, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
124: &Channel{Frequency: 5620, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
126: &Channel{Frequency: 5630, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
128: &Channel{Frequency: 5640, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
132: &Channel{Frequency: 5660, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
134: &Channel{Frequency: 5670, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
136: &Channel{Frequency: 5680, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
138: &Channel{Frequency: 5690, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
140: &Channel{Frequency: 5700, AllowedInEU: true, DFS: true, Indoor: false, SDR: false},
|
||||
142: &Channel{Frequency: 5710, AllowedInEU: false, DFS: true, Indoor: false, SDR: false},
|
||||
144: &Channel{Frequency: 5720, AllowedInEU: true, DFS: true, Indoor: false, SDR: true},
|
||||
149: &Channel{Frequency: 5745, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
151: &Channel{Frequency: 5755, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
153: &Channel{Frequency: 5765, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
155: &Channel{Frequency: 5775, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
157: &Channel{Frequency: 5785, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
159: &Channel{Frequency: 5795, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
161: &Channel{Frequency: 5805, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
165: &Channel{Frequency: 5825, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
169: &Channel{Frequency: 5845, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
173: &Channel{Frequency: 5865, AllowedInEU: true, DFS: false, Indoor: false, SDR: true},
|
||||
}
|
||||
)
|
||||
|
||||
func ChannelIs5GHz(channel uint32) bool {
|
||||
ch, ok := ChannelList[channel]
|
||||
return ok && (!ChannelEU || ch.AllowedInEU) && ch.Frequenz > FREQ_THREASHOLD
|
||||
return ok && (!ChannelEU || ch.AllowedInEU) && ch.Frequency > FREQ_THREASHOLD
|
||||
}
|
||||
|
||||
func GetChannel(channel uint32) *Channel {
|
||||
|
@ -101,3 +97,11 @@ func GetChannel(channel uint32) *Channel {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
func GetChannelByFrequency(freq uint32) (uint32, *Channel) {
|
||||
for ch, channel := range ChannelList {
|
||||
if channel.Frequency == freq {
|
||||
return ch, channel
|
||||
}
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
|
|
@ -11,6 +11,51 @@ import (
|
|||
yanicRuntime "github.com/FreifunkBremen/yanic/runtime"
|
||||
)
|
||||
|
||||
type WirelessSettings struct {
|
||||
TxPower24 uint32 `json:"txpower24,omitempty"`
|
||||
Channel24 uint32 `json:"channel24,omitempty"`
|
||||
TxPower5 uint32 `json:"txpower5,omitempty"`
|
||||
Channel5 uint32 `json:"channel5,omitempty"`
|
||||
}
|
||||
|
||||
func GetWirelessSettings(node *yanicRuntime.Node) *WirelessSettings {
|
||||
if stats := node.Statistics; stats != nil {
|
||||
|
||||
settings := &WirelessSettings{}
|
||||
for _, wifi := range stats.Wireless {
|
||||
ch, channel := GetChannelByFrequency(wifi.Frequency)
|
||||
if channel == nil || ChannelEU && !channel.AllowedInEU {
|
||||
continue
|
||||
}
|
||||
if channel.Frequency > FREQ_THREASHOLD {
|
||||
settings.Channel5 = ch
|
||||
} else {
|
||||
settings.Channel24 = ch
|
||||
}
|
||||
}
|
||||
if nodeinfo := node.Nodeinfo; nodeinfo != nil {
|
||||
if wifi := nodeinfo.Wireless; wifi != nil {
|
||||
/* skip to only use airtime frequency (current really used - not configurated)
|
||||
if settings.Channel24 == 0 {
|
||||
settings.Channel24 = wifi.Channel24
|
||||
}
|
||||
if settings.Channel5 == 0 {
|
||||
settings.Channel5 = wifi.Channel5
|
||||
}
|
||||
*/
|
||||
if settings.TxPower24 == 0 {
|
||||
settings.TxPower24 = wifi.TxPower24
|
||||
}
|
||||
if settings.TxPower5 == 0 {
|
||||
settings.TxPower5 = wifi.TxPower5
|
||||
}
|
||||
}
|
||||
}
|
||||
return settings
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
Lastseen jsontime.Time `json:"lastseen" mapstructure:"-" gorm:"-"`
|
||||
NodeID string `json:"node_id" gorm:"primary_key" mapstructure:"node_id"`
|
||||
|
@ -23,8 +68,8 @@ type Node struct {
|
|||
OwnerRespondd string `json:"owner_respondd" gorm:"-"`
|
||||
Location yanicData.Location `json:"location" gorm:"embedded;embedded_prefix:location_"`
|
||||
LocationRespondd yanicData.Location `json:"location_respondd" gorm:"-"`
|
||||
Wireless yanicData.Wireless `json:"wireless" gorm:"embedded;embedded_prefix:wireless_"`
|
||||
WirelessRespondd yanicData.Wireless `json:"wireless_respondd" gorm:"-"`
|
||||
Wireless WirelessSettings `json:"wireless" gorm:"embedded;embedded_prefix:wireless_"`
|
||||
WirelessRespondd WirelessSettings `json:"wireless_respondd" gorm:"-"`
|
||||
|
||||
StatisticsRespondd struct {
|
||||
Wireless yanicData.WirelessStatistics `json:"wireless"`
|
||||
|
@ -44,7 +89,7 @@ func NewNode(nodeOrigin *yanicRuntime.Node, ipPrefix string) *Node {
|
|||
if location := nodeinfo.Location; location != nil {
|
||||
node.Location = *location
|
||||
}
|
||||
if wireless := nodeinfo.Wireless; wireless != nil {
|
||||
if wireless := GetWirelessSettings(nodeOrigin); wireless != nil {
|
||||
node.Wireless = *wireless
|
||||
}
|
||||
node.Update(nodeOrigin, ipPrefix)
|
||||
|
@ -79,7 +124,7 @@ func (n *Node) Update(node *yanicRuntime.Node, ipPrefix string) {
|
|||
if location := nodeinfo.Location; location != nil {
|
||||
n.LocationRespondd = *location
|
||||
}
|
||||
if wireless := nodeinfo.Wireless; wireless != nil {
|
||||
if wireless := GetWirelessSettings(node); wireless != nil {
|
||||
n.WirelessRespondd = *wireless
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +166,7 @@ func locationEqual(a, b yanicData.Location) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func wirelessEqual(a, b yanicData.Wireless) bool {
|
||||
func wirelessEqual(a, b WirelessSettings) bool {
|
||||
if a.Channel24 != b.Channel24 {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ func (n *Node) SSHUpdate(sshmgmt *ssh.Manager) bool {
|
|||
ubus call hostapd.%s switch_chan '{"freq":%d}'
|
||||
uci set wireless.%s.channel='%d';
|
||||
uci commit wireless;`,
|
||||
strings.Replace(radio, "radio", "client", 1), ch.Frequenz,
|
||||
strings.Replace(radio, "radio", "client", 1), ch.Frequency,
|
||||
radio, n.Wireless.Channel24))
|
||||
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ func (n *Node) SSHUpdate(sshmgmt *ssh.Manager) bool {
|
|||
ubus call hostapd.%s switch_chan '{"freq":%d}'
|
||||
uci set wireless.%s.channel='%d';
|
||||
uci commit wireless;`,
|
||||
strings.Replace(radio, "radio", "client", 1), ch.Frequenz,
|
||||
strings.Replace(radio, "radio", "client", 1), ch.Frequency,
|
||||
radio, n.Wireless.Channel5))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ func init() {
|
|||
if runtime.ChannelEU && !channel.AllowedInEU {
|
||||
continue
|
||||
}
|
||||
if channel.Frequenz > runtime.FREQ_THREASHOLD {
|
||||
if channel.Frequency > runtime.FREQ_THREASHOLD {
|
||||
wifi5Channels = append(wifi5Channels, ch)
|
||||
} else {
|
||||
wifi24Channels = append(wifi24Channels, ch)
|
||||
|
|
Loading…
Reference in New Issue