From 6a316c53eef5bcd8f0c4723144776fb4dc7ce765 Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Mon, 24 Sep 2018 17:38:17 +0200 Subject: [PATCH] Begin of json rpc API and ... making openwrt module work Openwrt module was broken reworking all module ! --- cmd/server/rpc/server.go | 49 +- openwrt/executor.go | 21 +- openwrt/network.go | 18 +- openwrt/network_test.go | 6 +- .../0000:02:00.0/net/wlan1/address | 1 + openwrt/testdata/uci_show_wireless.txt | 24 + .../testdata/uci_show_wireless_2_cards.txt | 30 + openwrt/testdata/wifi_cells_output_1.txt | 31 + openwrt/testdata/wifi_cells_output_3.txt | 105 +- openwrt/testdata/wifi_cells_output_large.txt | 1445 +++++++++++++---- openwrt/uci.go | 54 +- openwrt/uci_wireless_conf.go | 177 ++ openwrt/uci_wireless_conf_test.go | 30 + openwrt/uci_wireless_interface.go | 185 +++ openwrt/uci_wireless_interface_test.go | 115 ++ openwrt/wifi.go | 91 -- openwrt/wifi_cell.go | 80 +- openwrt/wifi_cell_test.go | 21 - openwrt/wifi_scanner.go | 126 ++ .../{wifi_test.go => wifi_scanner_test.go} | 16 +- use.go | 57 + 21 files changed, 2128 insertions(+), 554 deletions(-) create mode 100644 openwrt/testdata/sys/devices/platform/soc/soc:pcie/pci0000:00/0000:00:02.0/0000:02:00.0/net/wlan1/address create mode 100644 openwrt/testdata/uci_show_wireless.txt create mode 100644 openwrt/testdata/uci_show_wireless_2_cards.txt create mode 100644 openwrt/testdata/wifi_cells_output_1.txt create mode 100644 openwrt/uci_wireless_conf.go create mode 100644 openwrt/uci_wireless_conf_test.go create mode 100644 openwrt/uci_wireless_interface.go create mode 100644 openwrt/uci_wireless_interface_test.go delete mode 100644 openwrt/wifi.go delete mode 100644 openwrt/wifi_cell_test.go create mode 100644 openwrt/wifi_scanner.go rename openwrt/{wifi_test.go => wifi_scanner_test.go} (76%) create mode 100644 use.go diff --git a/cmd/server/rpc/server.go b/cmd/server/rpc/server.go index 92673c3..98a14e9 100644 --- a/cmd/server/rpc/server.go +++ b/cmd/server/rpc/server.go @@ -1,29 +1,54 @@ package rpc import ( - "fmt" "net/http" + "forge.cadoles.com/Pyxis/orion/openwrt" "github.com/gorilla/rpc" "github.com/gorilla/rpc/json" ) // OrionService is the JSON-RPC API -type OrionService struct{} - -// HelloArgs is the arguments expected by the Hello method -type HelloArgs struct { - Who string +type OrionService struct { + UCI *openwrt.UCI } -// HelloResponse is the response returned from the Hello method -type HelloResponse struct { - Message string +// NewOrionService create a new OrionService ! +func NewOrionService() *OrionService { + uci := openwrt.NewUCI() + return &OrionService{ + UCI: uci, + } } -// Hello is a demo RPC method fro the OrionService -func (o *OrionService) Hello(r *http.Request, args *HelloArgs, reply *HelloResponse) error { - reply.Message = fmt.Sprintf("hello %s", args.Who) +// UCIArgs argument structure for exported method OwrtListWifiDevices +type UCIArgs struct{} + +// UCIResponse is the response structure for exposed method OwrtListWifiDevices +type UCIResponse struct { + Devices []map[string]string +} + +// OwrtListWifiDevices offers an RPC Method to list Wifi nics in a OpenWRT device. +func (o *OrionService) OwrtListWifiDevices(r *http.Request, args *UCIArgs, reply *UCIResponse) error { + o.UCI.LoadWirelessConf() + devs := o.UCI.GetWifiDevices() + reply.Devices = devs + return nil +} + +// ListIfaceArgs argument structure for exported method OwrtListWifiDevices +type ListIfaceArgs struct{} + +// ListIfaceResponse is the response structure for exposed method OwrtListWifiDevices +type ListIfaceResponse struct { + Interfaces []*openwrt.UCIWirelessInterface +} + +// OwrtListWifiInterfaces offers an RPC Method to list wifi interfaces in a OpenWRT device. +func (o *OrionService) OwrtListWifiInterfaces(r *http.Request, args *ListIfaceArgs, reply *ListIfaceResponse) error { + o.UCI.LoadWirelessConf() + reply.Interfaces = o.UCI.GetWifiIfaces() return nil } diff --git a/openwrt/executor.go b/openwrt/executor.go index bdd4275..8d9a4c8 100644 --- a/openwrt/executor.go +++ b/openwrt/executor.go @@ -2,7 +2,6 @@ package openwrt import ( "bytes" - "fmt" "log" "os/exec" "syscall" @@ -25,34 +24,22 @@ type localExecutor struct{} func (e *localExecutor) Run(command string, params ...string) *CommandResult { var out bytes.Buffer - var stderr bytes.Buffer + var outerr bytes.Buffer var exitCode int - defaultFailedCode := 255 - exe := exec.Command(command, params...) exe.Stdout = &out - exe.Stderr = &stderr + exe.Stderr = &outerr err := exe.Run() if err != nil { + // try to get the exit code if exitError, ok := err.(*exec.ExitError); ok { ws := exitError.Sys().(syscall.WaitStatus) exitCode = ws.ExitStatus() } else { - // This will happen (in OSX) if `name` is not available in $PATH, - // in this situation, exit code could not be get, and stderr will be - // empty string very likely, so we use the default fail code, and format err - // to string and set to stderr log.Printf("Could not get exit code for failed program: %v, %v", command, params) - exitCode = defaultFailedCode } - fmt.Println(fmt.Sprint(err) + ": " + stderr.String()) - log.Fatal(err) - } - - if err != nil { - // try to get the exit code } else { // success, exitCode should be 0 if go is ok ws := exe.ProcessState.Sys().(syscall.WaitStatus) @@ -61,7 +48,7 @@ func (e *localExecutor) Run(command string, params ...string) *CommandResult { return &CommandResult{ Stdout: out.String(), - Stderr: stderr.String(), + Stderr: outerr.String(), ReturnCode: exitCode, } } diff --git a/openwrt/network.go b/openwrt/network.go index dc3d449..c7deea8 100644 --- a/openwrt/network.go +++ b/openwrt/network.go @@ -12,7 +12,7 @@ type Network struct { exec Executor } -// NewNetwork return an UCI instance to interact with UCI +// NewNetwork return an Network instance to interact with OpenWRT Network components func NewNetwork() *Network { exec := &localExecutor{} return &Network{exec} @@ -57,7 +57,11 @@ func (n *Network) ListWirelessInterfaces(wifiFile string) []net.Interface { continue } else { name := strings.Split(line, ":")[0] - ifaceNames = append(ifaceNames, name) + if name != "" { + // remove damened whitespaces + name = strings.Replace(name, " ", "", -1) + ifaceNames = append(ifaceNames, name) + } } } @@ -66,12 +70,14 @@ func (n *Network) ListWirelessInterfaces(wifiFile string) []net.Interface { fmt.Print(fmt.Errorf("error listing network interfaces : %+v", err.Error())) return nil } - for _, i := range ifaces { - for _, name := range ifaceNames { - if name == i.Name { - result = append(result, i) + + for _, name := range ifaceNames { + for _, iface := range ifaces { + if name == iface.Name { + result = append(result, iface) } } } + return result } diff --git a/openwrt/network_test.go b/openwrt/network_test.go index bac8574..f10f87c 100644 --- a/openwrt/network_test.go +++ b/openwrt/network_test.go @@ -16,7 +16,11 @@ func TestNetworkListInterfaces(t *testing.T) { func TestListWirelessInterfaces(t *testing.T) { net := NewNetwork() res := net.ListWirelessInterfaces("./testdata/proc_net_wireless.txt") + + if len(res) != 0 { + t.Error("The wireless interfaces list is not empty !!") + } for _, el := range res { - fmt.Printf("%s\n", el.Name) + fmt.Printf("[%s]\n", el.Name) } } diff --git a/openwrt/testdata/sys/devices/platform/soc/soc:pcie/pci0000:00/0000:00:02.0/0000:02:00.0/net/wlan1/address b/openwrt/testdata/sys/devices/platform/soc/soc:pcie/pci0000:00/0000:00:02.0/0000:02:00.0/net/wlan1/address new file mode 100644 index 0000000..8113f4e --- /dev/null +++ b/openwrt/testdata/sys/devices/platform/soc/soc:pcie/pci0000:00/0000:00:02.0/0000:02:00.0/net/wlan1/address @@ -0,0 +1 @@ +00:25:9c:14:59:6d diff --git a/openwrt/testdata/uci_show_wireless.txt b/openwrt/testdata/uci_show_wireless.txt new file mode 100644 index 0000000..c9b7431 --- /dev/null +++ b/openwrt/testdata/uci_show_wireless.txt @@ -0,0 +1,24 @@ +wireless.radio0=wifi-device +wireless.radio0.type='mac80211' +wireless.radio0.channel='36' +wireless.radio0.hwmode='11a' +wireless.radio0.htmode='VHT80' +wireless.radio0.country='DE' +wireless.radio0.path='soc/soc:pcie/pci0000:00/0000:00:01.0/0000:01:00.0' +wireless.default_radio0=wifi-iface +wireless.default_radio0.device='radio0' +wireless.default_radio0.network='lan' +wireless.default_radio0.mode='ap' +wireless.default_radio0.macaddr='5a:ef:68:b5:f5:1a' +wireless.default_radio0.ssid='DonDuSang' +wireless.default_radio0.encryption='psk2' +wireless.default_radio0.key='cadoles;21' +wireless.radio1=wifi-device +wireless.radio1.type='mac80211' +wireless.radio1.hwmode='11g' +wireless.radio1.htmode='HT20' +wireless.radio1.country='FR' +wireless.radio1.path='soc/soc:pcie/pci0000:00/0000:00:02.0/0000:02:00.0' +wireless.radio1.channel='1' +wireless.radio1.legacy_rates='1' +wireless.radio1.disabled='0' \ No newline at end of file diff --git a/openwrt/testdata/uci_show_wireless_2_cards.txt b/openwrt/testdata/uci_show_wireless_2_cards.txt new file mode 100644 index 0000000..961b866 --- /dev/null +++ b/openwrt/testdata/uci_show_wireless_2_cards.txt @@ -0,0 +1,30 @@ +wireless.radio0=wifi-device +wireless.radio0.type='mac80211' +wireless.radio0.channel='36' +wireless.radio0.hwmode='11a' +wireless.radio0.htmode='VHT80' +wireless.radio0.country='DE' +wireless.radio0.path='soc/soc:pcie/pci0000:00/0000:00:01.0/0000:01:00.0' +wireless.default_radio0=wifi-iface +wireless.default_radio0.device='radio0' +wireless.default_radio0.network='lan' +wireless.default_radio0.mode='ap' +wireless.default_radio0.macaddr='5a:ef:68:b5:f5:1a' +wireless.default_radio0.ssid='DonDuSang' +wireless.default_radio0.encryption='psk2' +wireless.default_radio0.key='free_wifi!' +wireless.radio1=wifi-device +wireless.radio1.type='mac80211' +wireless.radio1.hwmode='11g' +wireless.radio1.htmode='HT20' +wireless.radio1.country='FR' +wireless.radio1.path='soc/soc:pcie/pci0000:00/0000:00:02.0/0000:02:00.0' +wireless.radio1.channel='1' +wireless.radio1.legacy_rates='1' +wireless.radio1.disabled='0' +wireless.@wifi-iface[1]=wifi-iface +wireless.@wifi-iface[1].device='radio1' +wireless.@wifi-iface[1].mode='ap' +wireless.@wifi-iface[1].ssid='Pyxis2' +wireless.@wifi-iface[1].encryption='psk2' +wireless.@wifi-iface[1].key='free_wifi!' \ No newline at end of file diff --git a/openwrt/testdata/wifi_cells_output_1.txt b/openwrt/testdata/wifi_cells_output_1.txt new file mode 100644 index 0000000..e6aedcb --- /dev/null +++ b/openwrt/testdata/wifi_cells_output_1.txt @@ -0,0 +1,31 @@ +BSS 7c:26:64:66:cc:44(on wlan1) + TSF: 85238642066 usec (0d, 23:40:38) + freq: 2412 + beacon interval: 100 TUs + capability: ESS (0x0431) + signal: -63.00 dBm + last seen: 1500 ms ago + Information elements from Probe Response frame: + SSID: Livebox-32c8 + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT TX/RX MCS rate indexes supported: 0-23 + HT operation: + * primary channel: 1 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) \ No newline at end of file diff --git a/openwrt/testdata/wifi_cells_output_3.txt b/openwrt/testdata/wifi_cells_output_3.txt index cb9b12e..1c89dcd 100644 --- a/openwrt/testdata/wifi_cells_output_3.txt +++ b/openwrt/testdata/wifi_cells_output_3.txt @@ -1,17 +1,88 @@ -Cell 40 - Address: 68:A3:78:6E:D9:24 - ESSID: "PyxisWifi" - Mode: Master Channel: 3 - Signal: -90 dBm Quality: 20/70 - Encryption: none - -Cell 41 - Address: B0:39:56:92:59:E2 - ESSID: "NET17" - Mode: Master Channel: 4 - Signal: -88 dBm Quality: 22/70 - Encryption: WPA2 PSK (CCMP) - -Cell 42 - Address: 0C:F4:D5:16:AA:18 - ESSID: "DIJON-METROPOLE-WIFI" - Mode: Master Channel: 13 - Signal: -90 dBm Quality: 20/70 - Encryption: none \ No newline at end of file +BSS 74:3e:2b:08:41:1c(on wlan1) + TSF: 85238642066 usec (0d, 23:40:38) + freq: 2412 + beacon interval: 100 TUs + capability: ESS (0x0431) + signal: -63.00 dBm + last seen: 1500 ms ago + Information elements from Probe Response frame: + SSID: PyxisWifi + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT TX/RX MCS rate indexes supported: 0-23 + HT operation: + * primary channel: 1 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) +BSS 7e:26:64:66:cc:44(on wlan1) + TSF: 85238646001 usec (0d, 23:40:38) + freq: 2412 + beacon interval: 100 TUs + capability: ESS (0x0421) + signal: -66.00 dBm + last seen: 1500 ms ago + Information elements from Probe Response frame: + SSID: orange + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT TX/RX MCS rate indexes supported: 0-23 + HT operation: + * primary channel: 1 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 20:47:da:b7:0e:5c(on wlan1) + TSF: 2161066518436 usec (25d, 00:17:46) + freq: 2412 + beacon interval: 100 TUs + capability: ESS (0x0431) + signal: -58.00 dBm + last seen: 1640 ms ago + Information elements from Probe Response frame: + SSID: Livebox-596a + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT TX/RX MCS rate indexes supported: 0-23 + HT operation: + * primary channel: 1 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) \ No newline at end of file diff --git a/openwrt/testdata/wifi_cells_output_large.txt b/openwrt/testdata/wifi_cells_output_large.txt index e4ee5ed..675aab2 100644 --- a/openwrt/testdata/wifi_cells_output_large.txt +++ b/openwrt/testdata/wifi_cells_output_large.txt @@ -1,293 +1,1152 @@ -Cell 01 - Address: 0C:8D:DB:C4:A0:34 - ESSID: "pfPauvres" - Mode: Master Channel: 11 - Signal: -50 dBm Quality: 60/70 - Encryption: mixed WPA/WPA2 PSK (TKIP, CCMP) - -Cell 02 - Address: 40:5A:9B:ED:BA:F0 - ESSID: "Cadoles" - Mode: Master Channel: 6 - Signal: -36 dBm Quality: 70/70 - Encryption: mixed WPA/WPA2 PSK (TKIP, CCMP) - -Cell 03 - Address: A0:04:60:B2:8A:C8 - ESSID: "Cadoles Formations (N)" - Mode: Master Channel: 13 - Signal: -32 dBm Quality: 70/70 - Encryption: WPA2 PSK (CCMP) - -Cell 04 - Address: B0:39:56:D8:38:ED - ESSID: "Frate Dijon EXT" - Mode: Master Channel: 11 - Signal: -57 dBm Quality: 53/70 - Encryption: WPA2 PSK (CCMP) - -Cell 05 - Address: 00:A6:CA:10:DF:00 - ESSID: unknown - Mode: Master Channel: 6 - Signal: -80 dBm Quality: 30/70 - Encryption: WPA2 802.1X (CCMP) - -Cell 06 - Address: AC:84:C9:2F:59:6E - ESSID: "Livebox-596a" - Mode: Master Channel: 1 - Signal: -62 dBm Quality: 48/70 - Encryption: mixed WPA/WPA2 PSK (TKIP, CCMP) - -Cell 07 - Address: 00:A6:CA:10:DF:01 - ESSID: "EFF-Mobility" - Mode: Master Channel: 6 - Signal: -74 dBm Quality: 36/70 - Encryption: WPA2 PSK (CCMP) - -Cell 08 - Address: A0:1B:29:BE:98:26 - ESSID: "Livebox-9822" - Mode: Master Channel: 6 - Signal: -81 dBm Quality: 29/70 - Encryption: mixed WPA/WPA2 PSK (TKIP, CCMP) - -Cell 09 - Address: 7C:26:64:66:CC:44 - ESSID: "Livebox-32c8" - Mode: Master Channel: 1 - Signal: -74 dBm Quality: 36/70 - Encryption: mixed WPA/WPA2 PSK (TKIP, CCMP) - -Cell 10 - Address: 00:A6:CA:10:DF:02 - ESSID: "Keo-HotSpot" - Mode: Master Channel: 6 - Signal: -79 dBm Quality: 31/70 - Encryption: none - -Cell 11 - Address: 7E:26:64:66:CC:44 - ESSID: "orange" - Mode: Master Channel: 1 - Signal: -73 dBm Quality: 37/70 - Encryption: none - -Cell 12 - Address: 3C:52:82:FC:5E:21 - ESSID: "DIRECT-20-HP DeskJet 3630 series" - Mode: Master Channel: 6 - Signal: -78 dBm Quality: 32/70 - Encryption: WPA2 PSK (CCMP) - -Cell 13 - Address: E4:9E:12:8B:EF:73 - ESSID: "Freebox-8BEF72" - Mode: Master Channel: 9 - Signal: -79 dBm Quality: 31/70 - Encryption: WPA2 PSK (CCMP) - -Cell 14 - Address: 40:4A:03:05:D2:68 - ESSID: "ZyXEL" - Mode: Master Channel: 11 - Signal: -71 dBm Quality: 39/70 - Encryption: WPA2 PSK (CCMP) - -Cell 15 - Address: 5C:C3:07:7E:39:D4 - ESSID: "pfP Xa" - Mode: Master Channel: 1 - Signal: -65 dBm Quality: 45/70 - Encryption: WPA2 PSK (CCMP) - -Cell 16 - Address: AC:84:C9:1D:C6:7C - ESSID: "Frate Djon" - Mode: Master Channel: 1 - Signal: -79 dBm Quality: 31/70 - Encryption: mixed WPA/WPA2 PSK (TKIP, CCMP) - -Cell 17 - Address: 00:17:33:9F:4D:80 - ESSID: "NEUF_4D7C" - Mode: Master Channel: 11 - Signal: -83 dBm Quality: 27/70 - Encryption: WPA PSK (TKIP, CCMP) - -Cell 18 - Address: A2:17:33:9F:4D:81 - ESSID: "SFR WiFi FON" - Mode: Master Channel: 11 - Signal: -85 dBm Quality: 25/70 - Encryption: none - -Cell 19 - Address: BC:F6:85:FE:6D:46 - ESSID: "Dlink" - Mode: Master Channel: 12 - Signal: -70 dBm Quality: 40/70 - Encryption: WPA2 PSK (CCMP) - -Cell 20 - Address: 30:7C:B2:D1:0B:0D - ESSID: "Livebox-0b09" - Mode: Master Channel: 11 - Signal: -81 dBm Quality: 29/70 - Encryption: mixed WPA/WPA2 PSK (TKIP, CCMP) - -Cell 21 - Address: A2:17:33:9F:4D:83 - ESSID: "SFR WiFi Mobile" - Mode: Master Channel: 11 - Signal: -85 dBm Quality: 25/70 - Encryption: WPA2 802.1X (CCMP) - -Cell 22 - Address: 90:4D:4A:F7:B9:70 - ESSID: "Livebox-B970" - Mode: Master Channel: 11 - Signal: -84 dBm Quality: 26/70 - Encryption: WPA2 PSK (CCMP) - -Cell 23 - Address: 90:4D:4A:F7:B9:71 - ESSID: "orange" - Mode: Master Channel: 11 - Signal: -89 dBm Quality: 21/70 - Encryption: none - -Cell 24 - Address: 00:22:6B:86:5B:71 - ESSID: "linksys" - Mode: Master Channel: 11 - Signal: -86 dBm Quality: 24/70 - Encryption: mixed WPA/WPA2 PSK (TKIP, CCMP) - -Cell 25 - Address: 68:A3:78:6E:D9:25 - ESSID: "FreeWifi_secure" - Mode: Master Channel: 3 - Signal: -86 dBm Quality: 24/70 - Encryption: WPA2 802.1X (TKIP, CCMP) - -Cell 26 - Address: 6C:38:A1:62:1B:28 - ESSID: "Bbox-1B7889A9" - Mode: Master Channel: 1 - Signal: -90 dBm Quality: 20/70 - Encryption: mixed WPA/WPA2 PSK (CCMP) - -Cell 27 - Address: 78:81:02:5E:B7:14 - ESSID: "Livebox-B714" - Mode: Master Channel: 6 - Signal: -86 dBm Quality: 24/70 - Encryption: WPA2 PSK (CCMP) - -Cell 28 - Address: F4:CA:E5:98:3B:DC - ESSID: "Freebox-5D2400" - Mode: Master Channel: 11 - Signal: -84 dBm Quality: 26/70 - Encryption: WPA PSK (CCMP) - -Cell 29 - Address: 8C:DC:D4:93:69:17 - ESSID: "HP-Print-17-Photosmart 5520" - Mode: Master Channel: 11 - Signal: -87 dBm Quality: 23/70 - Encryption: none - -Cell 30 - Address: 44:CE:7D:20:5C:A4 - ESSID: "SFR_5CA0" - Mode: Master Channel: 6 - Signal: -86 dBm Quality: 24/70 - Encryption: WPA PSK (TKIP, CCMP) - -Cell 31 - Address: F4:CA:E5:98:3B:DE - ESSID: "FreeWifi_secure" - Mode: Master Channel: 11 - Signal: -72 dBm Quality: 38/70 - Encryption: WPA2 802.1X (TKIP, CCMP) - -Cell 32 - Address: 70:0B:01:C0:B3:E0 - ESSID: "Livebox-B3E0" - Mode: Master Channel: 11 - Signal: -80 dBm Quality: 30/70 - Encryption: WPA2 PSK (CCMP) - -Cell 33 - Address: D2:CE:7D:20:5C:A7 - ESSID: "SFR WiFi Mobile" - Mode: Master Channel: 6 - Signal: -85 dBm Quality: 25/70 - Encryption: WPA2 802.1X (CCMP) - -Cell 34 - Address: 68:A3:78:0D:B6:51 - ESSID: "Freebox-0DB650" - Mode: Master Channel: 1 - Signal: -92 dBm Quality: 18/70 - Encryption: WPA2 PSK (CCMP) - -Cell 35 - Address: F8:AB:05:1D:6A:E0 - ESSID: "Bbox-8CE43C68" - Mode: Master Channel: 6 - Signal: -88 dBm Quality: 22/70 - Encryption: mixed WPA/WPA2 PSK (CCMP) - -Cell 36 - Address: F4:CA:E5:98:3B:DD - ESSID: "FreeWifi" - Mode: Master Channel: 11 - Signal: -87 dBm Quality: 23/70 - Encryption: none - -Cell 37 - Address: 14:0C:76:79:C0:D9 - ESSID: "freebox_ZFSFUA" - Mode: Master Channel: 4 - Signal: -88 dBm Quality: 22/70 - Encryption: WPA PSK (TKIP, CCMP) - -Cell 38 - Address: 68:15:90:36:63:60 - ESSID: "Livebox-6360" - Mode: Master Channel: 1 - Signal: -81 dBm Quality: 29/70 - Encryption: mixed WPA/WPA2 PSK (TKIP, CCMP) - -Cell 39 - Address: 64:7C:34:29:2B:7C - ESSID: "Bbox-D646CB51" - Mode: Master Channel: 1 - Signal: -90 dBm Quality: 20/70 - Encryption: mixed WPA/WPA2 PSK (CCMP) - -Cell 40 - Address: 68:A3:78:6E:D9:24 - ESSID: "FreeWifi" - Mode: Master Channel: 3 - Signal: -90 dBm Quality: 20/70 - Encryption: none - -Cell 41 - Address: B0:39:56:92:59:E2 - ESSID: "NETGEAR17" - Mode: Master Channel: 4 - Signal: -88 dBm Quality: 22/70 - Encryption: WPA2 PSK (CCMP) - -Cell 42 - Address: 0C:F4:D5:16:AA:18 - ESSID: "DIJON-METROPOLE-WIFI" - Mode: Master Channel: 13 - Signal: -90 dBm Quality: 20/70 - Encryption: none - -Cell 43 - Address: D2:CE:7D:20:5C:A5 - ESSID: "SFR WiFi FON" - Mode: Master Channel: 6 - Signal: -81 dBm Quality: 29/70 - Encryption: none - -Cell 44 - Address: 34:27:92:42:CD:72 - ESSID: "Freebox-42CD71" - Mode: Master Channel: 8 - Signal: -88 dBm Quality: 22/70 - Encryption: WPA2 PSK (CCMP) - -Cell 45 - Address: 72:5D:51:78:4C:87 - ESSID: "SFR WiFi FON" - Mode: Master Channel: 11 - Signal: -87 dBm Quality: 23/70 - Encryption: none - -Cell 46 - Address: 68:A3:78:6E:D9:23 - ESSID: "Freebox-6ED922" - Mode: Master Channel: 3 - Signal: -76 dBm Quality: 34/70 - Encryption: WPA2 PSK (CCMP) - -Cell 47 - Address: 00:19:70:4F:DE:F2 - ESSID: "Livebox-45cc" - Mode: Master Channel: 6 - Signal: -78 dBm Quality: 32/70 - Encryption: mixed WPA/WPA2 PSK (TKIP, CCMP) - -Cell 48 - Address: AC:84:C9:CC:AE:90 - ESSID: "Livebox-AE90" - Mode: Master Channel: 11 - Signal: -81 dBm Quality: 29/70 - Encryption: WPA2 PSK (CCMP) - -Cell 49 - Address: 00:07:7D:89:81:B0 - ESSID: "orange" - Mode: Master Channel: 6 - Signal: -85 dBm Quality: 25/70 - Encryption: none \ No newline at end of file +BSS 7c:26:64:66:cc:44(on wlan1) + TSF: 85238642066 usec (0d, 23:40:38) + freq: 2412 + beacon interval: 100 TUs + capability: ESS (0x0431) + signal: -63.00 dBm + last seen: 1500 ms ago + Information elements from Probe Response frame: + SSID: Livebox-32c8 + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT TX/RX MCS rate indexes supported: 0-23 + HT operation: + * primary channel: 1 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) +BSS 7e:26:64:66:cc:44(on wlan1) + TSF: 85238646001 usec (0d, 23:40:38) + freq: 2412 + beacon interval: 100 TUs + capability: ESS (0x0421) + signal: -66.00 dBm + last seen: 1500 ms ago + Information elements from Probe Response frame: + SSID: orange + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT TX/RX MCS rate indexes supported: 0-23 + HT operation: + * primary channel: 1 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS ac:84:c9:2f:59:6e(on wlan1) + TSF: 2161066518436 usec (25d, 00:17:46) + freq: 2412 + beacon interval: 100 TUs + capability: ESS (0x0431) + signal: -58.00 dBm + last seen: 1640 ms ago + Information elements from Probe Response frame: + SSID: Livebox-596a + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT TX/RX MCS rate indexes supported: 0-23 + HT operation: + * primary channel: 1 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) +BSS b0:39:56:d8:38:ed(on wlan1) + TSF: 1037415177423 usec (12d, 00:10:15) + freq: 2422 + beacon interval: 100 TUs + capability: ESS (0x0c11) + signal: -51.00 dBm + last seen: 1220 ms ago + Information elements from Probe Response frame: + SSID: Frate Dijon EXT + HT capabilities: + Capabilities: 0x11ee + HT20/HT40 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 4 usec (0x05) + HT RX MCS rate indexes supported: 0-15, 32 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 3 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) +BSS 40:5a:9b:ed:ba:f0(on wlan1) + TSF: 3568958658654 usec (41d, 07:22:38) + freq: 2437 + beacon interval: 100 TUs + capability: ESS (0x0431) + signal: -46.00 dBm + last seen: 740 ms ago + Information elements from Probe Response frame: + SSID: Cadoles + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT TX/RX MCS rate indexes supported: 0-15 + HT operation: + * primary channel: 6 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) +BSS 00:a6:ca:10:df:01(on wlan1) + TSF: 1018905678733 usec (11d, 19:01:45) + freq: 2437 + beacon interval: 102 TUs + capability: ESS (0x1431) + signal: -80.00 dBm + last seen: 820 ms ago + Information elements from Probe Response frame: + SSID: EFF-Mobility + HT capabilities: + Capabilities: 0x19ac + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 7935 bytes + DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT RX MCS rate indexes supported: 0-23 + HT TX MCS rate indexes are undefined + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 4-PTKSA-RC 4-GTKSA-RC (0x0028) + HT operation: + * primary channel: 6 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS a0:04:60:b2:8a:c8(on wlan1) + TSF: 23484334090837 usec (271d, 19:25:34) + freq: 2472 + beacon interval: 100 TUs + capability: ESS (0x0411) + signal: -44.00 dBm + last seen: 40 ms ago + Information elements from Probe Response frame: + SSID: Cadoles Formations (N) + HT capabilities: + Capabilities: 0x11ec + HT20 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 4 usec (0x05) + HT RX MCS rate indexes supported: 0-15, 32 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 13 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) +BSS bc:f6:85:fe:6d:46(on wlan1) + TSF: 5185428505884 usec (60d, 00:23:48) + freq: 2467 + beacon interval: 100 TUs + capability: ESS (0x0c11) + signal: -76.00 dBm + last seen: 30 ms ago + Information elements from Probe Response frame: + SSID: Dlink + HT capabilities: + Capabilities: 0x11ee + HT20/HT40 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 2 usec (0x04) + HT RX MCS rate indexes supported: 0-15, 32 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 12 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + Secondary Channel Offset: no secondary (0) + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) +BSS 90:4d:4a:f7:b9:71(on wlan1) + TSF: 4721041865203 usec (54d, 15:24:01) + freq: 2462 + beacon interval: 100 TUs + capability: ESS (0x0001) + signal: -82.00 dBm + last seen: 300 ms ago + Information elements from Probe Response frame: + SSID: orange + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 4 usec (0x05) + HT Max RX data rate: 384 Mbps + HT RX MCS rate indexes supported: 0-23 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 11 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS e4:9e:12:8b:ef:73(on wlan1) + TSF: 7952485362135 usec (92d, 01:01:25) + freq: 2452 + beacon interval: 96 TUs + capability: ESS (0x0411) + signal: -80.00 dBm + last seen: 430 ms ago + Information elements from Probe Response frame: + SSID: Freebox-8BEF72 + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 16-PTKSA-RC 1-GTKSA-RC (0x000c) + HT capabilities: + Capabilities: 0xec + HT20 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + TX STBC + No RX STBC + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: No restriction (0x00) + HT TX/RX MCS rate indexes supported: 0-23, 32 + HT operation: + * primary channel: 9 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 90:4d:4a:f7:b9:70(on wlan1) + TSF: 4721041856992 usec (54d, 15:24:01) + freq: 2462 + beacon interval: 100 TUs + capability: ESS (0x0011) + signal: -78.00 dBm + last seen: 310 ms ago + Information elements from Probe Response frame: + SSID: Livebox-B970 + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 16-PTKSA-RC 1-GTKSA-RC (0x000c) + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 4 usec (0x05) + HT Max RX data rate: 384 Mbps + HT RX MCS rate indexes supported: 0-23 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 11 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 3c:52:82:fc:5e:21(on wlan1) + TSF: 6735883434375 usec (77d, 23:04:43) + freq: 2437 + beacon interval: 100 TUs + capability: ESS (0x0511) + signal: -79.00 dBm + last seen: 970 ms ago + Information elements from Probe Response frame: + SSID: DIRECT-20-HP DeskJet 3630 series + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 16-PTKSA-RC 1-GTKSA-RC (0x000c) + HT capabilities: + Capabilities: 0x20 + HT20 + Static SM Power Save + RX HT20 SGI + No RX STBC + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 32767 bytes (exponent: 0x002) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT RX MCS rate indexes supported: 0-7 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 6 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 00:a6:ca:10:df:02(on wlan1) + TSF: 1018894510847 usec (11d, 19:01:34) + freq: 2437 + beacon interval: 102 TUs + capability: ESS (0x1421) + signal: -73.00 dBm + last seen: 1040 ms ago + Information elements from Probe Response frame: + SSID: Keo-HotSpot + HT capabilities: + Capabilities: 0x19ac + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 7935 bytes + DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT RX MCS rate indexes supported: 0-23 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 6 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS a2:17:33:9f:4d:81(on wlan1) + TSF: 3050426691569 usec (35d, 07:20:26) + freq: 2462 + beacon interval: 100 TUs + capability: ESS (0x0401) + signal: -82.00 dBm + last seen: 310 ms ago + Information elements from Probe Response frame: + SSID: SFR WiFi FON +BSS ac:84:c9:1d:c6:7c(on wlan1) + TSF: 2491424200041 usec (28d, 20:03:44) + freq: 2412 + beacon interval: 100 TUs + capability: ESS (0x0431) + signal: -80.00 dBm + last seen: 1480 ms ago + Information elements from Probe Response frame: + SSID: Frate Djon + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) +BSS 78:81:02:5e:b7:15(on wlan1) + TSF: 4786879928619 usec (55d, 09:41:19) + freq: 2437 + beacon interval: 100 TUs + capability: ESS (0x0401) + signal: -83.00 dBm + last seen: 950 ms ago + Information elements from Probe Response frame: + SSID: orange + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 4 usec (0x05) + HT Max RX data rate: 384 Mbps + HT RX MCS rate indexes supported: 0-23 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 6 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 00:a6:ca:10:df:00(on wlan1) + TSF: 1018905280864 usec (11d, 19:01:45) + freq: 2437 + beacon interval: 102 TUs + capability: ESS (0x1431) + signal: -76.00 dBm + last seen: 1170 ms ago + Information elements from Probe Response frame: + SSID: \x00 + HT capabilities: + Capabilities: 0x19ac + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 7935 bytes + DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT RX MCS rate indexes supported: 0-23 + HT TX MCS rate indexes are undefined + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: IEEE 802.1X + * Capabilities: 4-PTKSA-RC 4-GTKSA-RC (0x0028) + HT operation: + * primary channel: 6 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS a0:1b:29:be:98:26(on wlan1) + TSF: 2931892990829 usec (33d, 22:24:52) + freq: 2437 + beacon interval: 100 TUs + capability: ESS (0x0431) + signal: -64.00 dBm + last seen: 970 ms ago + Information elements from Probe Response frame: + SSID: Livebox-9822 + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT TX/RX MCS rate indexes supported: 0-15 + HT operation: + * primary channel: 6 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) +BSS 40:4a:03:05:d2:68(on wlan1) + TSF: 57377785 usec (0d, 00:00:57) + freq: 2462 + beacon interval: 100 TUs + capability: ESS (0x0431) + signal: -76.00 dBm + last seen: 240 ms ago + Information elements from Probe Response frame: + SSID: ZyXEL + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) + HT capabilities: + Capabilities: 0x104e + HT20/HT40 + SM Power Save disabled + RX HT40 SGI + No RX STBC + Max AMSDU length: 3839 bytes + DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT RX MCS rate indexes supported: 0-15 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 11 + * secondary channel offset: below + * STA channel width: any +BSS f4:ca:e5:98:3b:de(on wlan1) + TSF: 502449932512 usec (5d, 19:34:09) + freq: 2462 + beacon interval: 96 TUs + capability: ESS (0x0411) + signal: -86.00 dBm + last seen: 11400 ms ago + Information elements from Probe Response frame: + SSID: FreeWifi_secure + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: IEEE 802.1X + * Capabilities: 16-PTKSA-RC 1-GTKSA-RC (0x000c) + HT capabilities: + Capabilities: 0x6c + HT20 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + No RX STBC + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: No restriction (0x00) + HT TX/RX MCS rate indexes supported: 0-23, 32 + HT operation: + * primary channel: 11 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 00:17:33:9f:4d:80(on wlan1) + TSF: 3050426716298 usec (35d, 07:20:26) + freq: 2462 + beacon interval: 100 TUs + capability: ESS (0x0411) + signal: -79.00 dBm + last seen: 290 ms ago + Information elements from Probe Response frame: + SSID: NEUF_4D7C +BSS a2:17:33:9f:4d:83(on wlan1) + TSF: 3050426718113 usec (35d, 07:20:26) + freq: 2462 + beacon interval: 100 TUs + capability: ESS (0x0411) + signal: -80.00 dBm + last seen: 290 ms ago + Information elements from Probe Response frame: + SSID: SFR WiFi Mobile + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: IEEE 802.1X + * Capabilities: 16-PTKSA-RC 1-GTKSA-RC (0x000c) +BSS 30:7c:b2:d1:0b:0d(on wlan1) + TSF: 1059959180138 usec (12d, 06:25:59) + freq: 2462 + beacon interval: 100 TUs + capability: ESS (0x0431) + signal: -80.00 dBm + last seen: 11200 ms ago + Information elements from Probe Response frame: + SSID: Livebox-0b09 + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT TX/RX MCS rate indexes supported: 0-15 + HT operation: + * primary channel: 11 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) +BSS 68:a3:78:0d:b6:51(on wlan1) + TSF: 136373797215 usec (1d, 13:52:53) + freq: 2462 + beacon interval: 96 TUs + capability: ESS (0x0411) + signal: -88.00 dBm + last seen: 11230 ms ago + Information elements from Probe Response frame: + SSID: Freebox-0DB650 + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 16-PTKSA-RC 1-GTKSA-RC (0x000c) + HT capabilities: + Capabilities: 0xec + HT20 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + TX STBC + No RX STBC + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: No restriction (0x00) + HT TX/RX MCS rate indexes supported: 0-23, 32 + HT operation: + * primary channel: 11 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 68:15:90:36:63:60(on wlan1) + TSF: 308936601984 usec (3d, 13:48:56) + freq: 2412 + beacon interval: 100 TUs + capability: ESS (0x0431) + signal: -88.00 dBm + last seen: 12650 ms ago + Information elements from Probe Response frame: + SSID: Livebox-6360 + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT RX MCS rate indexes supported: 0-15 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 1 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: PSK + * Capabilities: 16-PTKSA-RC 1-GTKSA-RC (0x000c) +BSS 0c:8d:db:c4:a0:34(on wlan1) + TSF: 372485216298 usec (4d, 07:28:05) + freq: 2412 + beacon interval: 100 TUs + capability: ESS (0x1431) + signal: -56.00 dBm + last seen: 1540 ms ago + Information elements from Probe Response frame: + SSID: pfPauvres + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) + HT capabilities: + Capabilities: 0x9ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 7935 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: No restriction (0x00) + HT TX/RX MCS rate indexes supported: 0-15 + HT operation: + * primary channel: 1 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + VHT capabilities: + VHT Capabilities (0x338959b2): + Max MPDU length: 11454 + Supported Channel Width: neither 160 nor 80+80 + RX LDPC + short GI (80 MHz) + TX STBC + SU Beamformer + SU Beamformee + MU Beamformer + RX antenna pattern consistency + TX antenna pattern consistency + VHT RX MCS set: + 1 streams: MCS 0-9 + 2 streams: MCS 0-9 + 3 streams: not supported + 4 streams: not supported + 5 streams: not supported + 6 streams: not supported + 7 streams: not supported + 8 streams: not supported + VHT RX highest supported: 0 Mbps + VHT TX MCS set: + 1 streams: MCS 0-9 + 2 streams: MCS 0-9 + 3 streams: not supported + 4 streams: not supported + 5 streams: not supported + 6 streams: not supported + 7 streams: not supported + 8 streams: not supported + VHT TX highest supported: 0 Mbps + VHT operation: + * channel width: 0 (20 or 40 MHz) + * center freq segment 1: 0 + * center freq segment 2: 0 + * VHT basic MCS set: 0xfffc +BSS ac:3b:77:6a:24:e0(on wlan1) + TSF: 741652789170 usec (8d, 14:00:52) + freq: 2412 + beacon interval: 100 TUs + capability: ESS (0x0411) + signal: -87.00 dBm + last seen: 1700 ms ago + Information elements from Probe Response frame: + SSID: Grosorboul + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 16-PTKSA-RC 1-GTKSA-RC (0x000c) + HT capabilities: + Capabilities: 0x18fc + HT20 + SM Power Save disabled + RX Greenfield + RX HT20 SGI + RX HT40 SGI + TX STBC + No RX STBC + Max AMSDU length: 7935 bytes + DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT RX MCS rate indexes supported: 0-15 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 1 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 68:a3:78:6e:d9:24(on wlan1) + TSF: 85494694239 usec (0d, 23:44:54) + freq: 2422 + beacon interval: 96 TUs + capability: ESS (0x0401) + signal: -87.00 dBm + last seen: 1340 ms ago + Information elements from Probe Response frame: + SSID: FreeWifi + HT capabilities: + Capabilities: 0xec + HT20 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + TX STBC + No RX STBC + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: No restriction (0x00) + HT TX/RX MCS rate indexes supported: 0-23, 32 + HT operation: + * primary channel: 3 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 14:0c:76:79:c0:d9(on wlan1) + TSF: 572290498911 usec (6d, 14:58:10) + freq: 2427 + beacon interval: 96 TUs + capability: ESS (0x0411) + signal: -86.00 dBm + last seen: 1300 ms ago + Information elements from Probe Response frame: + SSID: freebox_ZFSFUA + HT capabilities: + Capabilities: 0x6c + HT20 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + No RX STBC + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: No restriction (0x00) + HT TX/RX MCS rate indexes supported: 0-23, 32 + HT operation: + * primary channel: 4 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 78:81:02:5e:b7:14(on wlan1) + TSF: 4786879917067 usec (55d, 09:41:19) + freq: 2437 + beacon interval: 100 TUs + capability: ESS (0x0411) + signal: -84.00 dBm + last seen: 960 ms ago + SSID: Livebox-B714 + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 16-PTKSA-RC 1-GTKSA-RC (0x000c) + HT capabilities: + Capabilities: 0x1ad + RX LDPC + HT20 + SM Power Save disabled + RX HT20 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 4 usec (0x05) + HT Max RX data rate: 384 Mbps + HT RX MCS rate indexes supported: 0-23 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 6 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS d6:38:9c:67:00:7a(on wlan1) + TSF: 52271652256 usec (0d, 14:31:11) + freq: 2442 + beacon interval: 100 TUs + capability: ESS (0x0411) + signal: -75.00 dBm + last seen: 680 ms ago + Information elements from Probe Response frame: + SSID: \xc5\xa4\xc3\xa3h\xc3\xae\xc5\x99 + HT capabilities: + Capabilities: 0x130 + HT20 + Static SM Power Save + RX Greenfield + RX HT20 SGI + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: No restriction (0x00) + HT TX/RX MCS rate indexes supported: 0-7 + HT operation: + * primary channel: 7 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 16-PTKSA-RC 1-GTKSA-RC (0x000c) +BSS 00:19:70:4f:de:f2(on wlan1) + TSF: 223832269184 usec (2d, 14:10:32) + freq: 2462 + beacon interval: 100 TUs + capability: ESS (0x0431) + signal: -86.00 dBm + last seen: 11260 ms ago + Information elements from Probe Response frame: + SSID: Livebox-45cc + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) + HT capabilities: + Capabilities: 0x100c + HT20 + SM Power Save disabled + No RX STBC + Max AMSDU length: 3839 bytes + DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT RX MCS rate indexes supported: 0-15 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 11 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 6c:38:a1:62:1b:28(on wlan1) + TSF: 2704292761929 usec (31d, 07:11:32) + freq: 2412 + beacon interval: 100 TUs + capability: ESS (0x0c11) + signal: -86.00 dBm + last seen: 1660 ms ago + Information elements from Probe Response frame: + SSID: Bbox-1B7889A9 + HT capabilities: + Capabilities: 0x1ec + HT20 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + TX STBC + RX STBC 1-stream + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: No restriction (0x00) + HT RX MCS rate indexes supported: 0-23 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 1 + * secondary channel offset: above + * STA channel width: 20 MHz + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) +BSS 68:a3:78:6e:d9:25(on wlan1) + TSF: 85494497631 usec (0d, 23:44:54) + freq: 2422 + beacon interval: 96 TUs + capability: ESS (0x0411) + signal: -85.00 dBm + last seen: 1500 ms ago + Information elements from Probe Response frame: + SSID: FreeWifi_secure + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: IEEE 802.1X + * Capabilities: 16-PTKSA-RC 1-GTKSA-RC (0x000c) + HT capabilities: + Capabilities: 0xec + HT20 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + TX STBC + No RX STBC + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: No restriction (0x00) + HT TX/RX MCS rate indexes supported: 0-23, 32 + HT operation: + * primary channel: 3 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 56:62:21:de:de:70(on wlan1) + TSF: 5762545254750 usec (66d, 16:42:25) + freq: 2422 + beacon interval: 100 TUs + capability: ESS (0x0411) + signal: -88.00 dBm + last seen: 1430 ms ago + Information elements from Probe Response frame: + SSID: FREEBOX_JOSIANNE_46 + HT capabilities: + Capabilities: 0x106e + HT20/HT40 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + No RX STBC + Max AMSDU length: 3839 bytes + DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 4 usec (0x05) + HT RX MCS rate indexes supported: 0-15, 32 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 3 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 56:62:21:de:de:71(on wlan1) + TSF: 5762545257087 usec (66d, 16:42:25) + freq: 2422 + beacon interval: 100 TUs + capability: ESS (0x0411) + signal: -86.00 dBm + last seen: 1430 ms ago + Information elements from Probe Response frame: + SSID: + HT capabilities: + Capabilities: 0x106e + HT20/HT40 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + No RX STBC + Max AMSDU length: 3839 bytes + DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 4 usec (0x05) + HT RX MCS rate indexes supported: 0-15, 32 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 3 + * secondary channel offset: no secondary + * STA channel width: 20 MHz + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) +BSS 68:a3:78:6e:d9:23(on wlan1) + TSF: 85494792543 usec (0d, 23:44:54) + freq: 2422 + beacon interval: 96 TUs + capability: ESS (0x0411) + signal: -86.00 dBm + last seen: 1270 ms ago + Information elements from Probe Response frame: + SSID: Freebox-6ED922 + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: PSK + * Capabilities: 16-PTKSA-RC 1-GTKSA-RC (0x000c) + HT capabilities: + Capabilities: 0xec + HT20 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + TX STBC + No RX STBC + Max AMSDU length: 3839 bytes + No DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: No restriction (0x00) + HT TX/RX MCS rate indexes supported: 0-23, 32 + HT operation: + * primary channel: 3 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 44:ce:7d:20:5c:a4(on wlan1) + TSF: 2322036531897 usec (26d, 21:00:36) + freq: 2437 + beacon interval: 100 TUs + capability: ESS (0x0411) + signal: -82.00 dBm + last seen: 1030 ms ago + Information elements from Probe Response frame: + SSID: SFR_5CA0 + HT capabilities: + Capabilities: 0x18ec + HT20 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + TX STBC + No RX STBC + Max AMSDU length: 7935 bytes + DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT RX MCS rate indexes supported: 0-15 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 6 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS d2:ce:7d:20:5c:a7(on wlan1) + TSF: 2322036535330 usec (26d, 21:00:36) + freq: 2437 + beacon interval: 100 TUs + capability: ESS (0x0411) + signal: -87.00 dBm + last seen: 1030 ms ago + Information elements from Probe Response frame: + SSID: SFR WiFi Mobile + RSN: * Version: 1 + * Group cipher: CCMP + * Pairwise ciphers: CCMP + * Authentication suites: IEEE 802.1X + * Capabilities: 16-PTKSA-RC 1-GTKSA-RC (0x000c) + HT capabilities: + Capabilities: 0x18ec + HT20 + SM Power Save disabled + RX HT20 SGI + RX HT40 SGI + TX STBC + No RX STBC + Max AMSDU length: 7935 bytes + DSSS/CCK HT40 + Maximum RX AMPDU length 65535 bytes (exponent: 0x003) + Minimum RX AMPDU time spacing: 8 usec (0x06) + HT RX MCS rate indexes supported: 0-15 + HT TX MCS rate indexes are undefined + HT operation: + * primary channel: 6 + * secondary channel offset: no secondary + * STA channel width: 20 MHz +BSS 00:22:6b:86:5b:71(on wlan1) + TSF: 13910494312595 usec (161d, 00:01:34) + freq: 2462 + beacon interval: 100 TUs + capability: ESS (0x0411) + signal: -88.00 dBm + last seen: 350 ms ago + Information elements from Probe Response frame: + SSID: linksys + RSN: * Version: 1 + * Group cipher: TKIP + * Pairwise ciphers: CCMP TKIP + * Authentication suites: PSK + * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) diff --git a/openwrt/uci.go b/openwrt/uci.go index 0613643..6aff080 100644 --- a/openwrt/uci.go +++ b/openwrt/uci.go @@ -12,26 +12,28 @@ type Action struct { // UCI "Object" type UCI struct { - exec Executor + exec Executor + Wireless *UCIWirelessConf } // NewUCI return an UCI instance to interact with UCI func NewUCI() *UCI { exec := &localExecutor{} - return &UCI{exec} + wireless := &UCIWirelessConf{} + return &UCI{exec, wireless} } // NewUCIWithExecutor returns a UCI Instance an gives you the ability to provide // a different command executor than the default one. func NewUCIWithExecutor(exec Executor) *UCI { - return &UCI{exec} + wireless := &UCIWirelessConf{} + return &UCI{exec, wireless} } // uciRun, private method to run the UCI command -func (u *UCI) uciRun(uciAction string, param string) *Action { - cmd := "uci" - - res := u.exec.Run(cmd, uciAction, param) +func (u *UCI) uciRun(param ...string) *Action { + cmd := "/sbin/uci" + res := u.exec.Run(cmd, param...) return &Action{res} } @@ -53,7 +55,8 @@ func (u *UCI) Set(entry string, value string) *Action { // Commit the recent actions to UCI func (u *UCI) Commit() *Action { - return u.uciRun("commit", "") + res := u.uciRun("commit") + return res } // Reload reload uci configuration @@ -65,8 +68,39 @@ func (u *UCI) Reload() *Action { return &Action{cmdResult} } +// Show returns the output of uci show command +func (u *UCI) Show(target string) *Action { + cmdRes := u.uciRun("show", target) + return cmdRes +} + // AddWireless Create a new Wireless entry in UCI configuration -func (u *UCI) AddWireless(name string) *Action { - res := u.Add("wireless", name) +func (u *UCI) AddWireless() *Action { + res := u.uciRun("add", "wireless", "wifi-iface") return res } + +// LoadWirelessConf scan UCI configuration and loads saved Wireless configuration +func (u *UCI) LoadWirelessConf() { + u.Wireless = NewUCIWirelessConf(u) + u.Wireless.Load() +} + +// GetWifiIface returns the system name of the Interface +func (u *UCI) GetWifiIface(idx int) *UCIWirelessInterface { + ifaces := u.Wireless.Interfaces + if len(ifaces) < idx { + return nil + } + return ifaces[idx] +} + +// GetWifiIfaces wifi interfaces in configuration +func (u *UCI) GetWifiIfaces() []*UCIWirelessInterface { + return u.Wireless.Interfaces +} + +// GetWifiDevices returns the wifi devices in configuration +func (u *UCI) GetWifiDevices() []map[string]string { + return u.Wireless.Devices +} diff --git a/openwrt/uci_wireless_conf.go b/openwrt/uci_wireless_conf.go new file mode 100644 index 0000000..a91b8b6 --- /dev/null +++ b/openwrt/uci_wireless_conf.go @@ -0,0 +1,177 @@ +package openwrt + +import ( + "fmt" + "regexp" + "strconv" + "strings" +) + +// UCIWirelessConf is the representation of UCI Wireless Configuration +type UCIWirelessConf struct { + uciClient *UCI + Devices []map[string]string + DefaultInterface map[string]string + Interfaces []*UCIWirelessInterface +} + +// NewUCIWirelessConf builds a new UCIWirelessConf instance +func NewUCIWirelessConf(uci *UCI) *UCIWirelessConf { + return &UCIWirelessConf{ + uciClient: uci, + Devices: []map[string]string{}, //, 10), + DefaultInterface: map[string]string{}, + Interfaces: []*UCIWirelessInterface{}, //, 10), + } +} + +// parse wireless.default_radio[0-9] section of UCI Configuration +func (wc *UCIWirelessConf) parseDefaultInterface(lines []string) int { + matches := map[string]string{ + "Name": "default_radio0=", + "Type": "default_radio0.type=", + "Channel": "default_radio0.channel=", + "Hwmode": "default_radio0.hwmode=", + "Htmode": "default_radio0.htmode=", + "Country": "default_radio0.country=", + "Path": "default_radio0.path=", + } + + for _, line := range lines { + for key, value := range matches { + if strings.Contains(line, value) { + wc.DefaultInterface[key] = strings.Split(line, "=")[1] + } + } + } + return 0 +} + +func (wc *UCIWirelessConf) parseInterfaces(lines []string) int { + matches := map[string]*regexp.Regexp{ + "Name": regexp.MustCompile(`@wifi-iface\[[0-9]\]=`), + "Device": regexp.MustCompile(`@wifi-iface\[[0-9]\].device=`), + "Mode": regexp.MustCompile(`@wifi-iface\[[0-9]\].mode=`), + "Ssid": regexp.MustCompile(`@wifi-iface\[[0-9]\].ssid=`), + "Encryption": regexp.MustCompile(`@wifi-iface\[[0-9]\].encryption=`), + "Key": regexp.MustCompile(`@wifi-iface\[[0-9]\].key=`), + } + + for _, li := range lines { + var idx int + sIdx := strings.Split(li, "[")[1] + sIdx = strings.Split(sIdx, "]")[0] + if s, err := strconv.ParseInt(sIdx, 10, 32); err == nil { + idx = int(s) + } + + if idx >= len(wc.Interfaces) { + for i := 0; i <= idx; i++ { + wc.Interfaces = append(wc.Interfaces, NewUCIWirelessInterface()) + } + } + + if wc.Interfaces[idx] == nil { + wc.Interfaces[idx] = NewUCIWirelessInterface() + wc.Interfaces[idx].Index = idx + } + + for key, expr := range matches { + if expr.MatchString(li) { + value := strings.Split(li, "=")[1] + if key == "Name" { + wc.Interfaces[idx].Name = value + } + if key == "Device" { + wc.Interfaces[idx].Device = value + } + if key == "Mode" { + wc.Interfaces[idx].Mode = value + } + if key == "Ssid" { + wc.Interfaces[idx].Ssid = value + } + if key == "Encryption" { + wc.Interfaces[idx].Encryption = value + } + if key == "Key" { + wc.Interfaces[idx].Key = value + } + } + } + } + return 0 +} + +func (wc *UCIWirelessConf) parseDevicesConf(lines []string) int { + + matches := map[string]string{ + "Name": "radio[0-9]=", + "Type": "radio[0-9].type=", + "Channel": "radio[0-9].channel=", + "Hwmode": "radio[0-9].hwmode=", + "Htmode": "radio[0-9].htmode=", + "Country": "radio[0-9].country=", + "Path": "radio[0-9].path=", + } + + for _, line := range lines { + var idx int + re := regexp.MustCompile("[0-9]") + rIdx := re.FindString(line) + if s, err := strconv.ParseInt(rIdx, 10, 32); err == nil { + idx = int(s) + } + + if len(wc.Devices) == 0 { + wc.Devices = append(wc.Devices, make(map[string]string)) + } + + if idx >= len(wc.Devices) { + for i := 0; i < idx; i++ { + wc.Devices = append(wc.Devices, make(map[string]string)) + } + } + + if wc.Devices[idx] == nil { + wc.Devices[idx] = make(map[string]string) + } + for key, expr := range matches { + re := regexp.MustCompile(expr) + if re.MatchString(line) { + value := strings.Split(line, "=")[1] + value = strings.Trim(value, "'") + if key == "Name" { + wc.Devices[idx]["Device"] = fmt.Sprintf("radio%d", idx) + } + wc.Devices[idx][key] = value + } + } + + } + return 0 +} + +func grep(lines string, pattern string) []string { + var res []string + for _, line := range strings.Split(strings.TrimSuffix(lines, "\n"), "\n") { + re := regexp.MustCompile(pattern) + if re.MatchString(line) { + res = append(res, line) + } + } + return res +} + +// Load return the Wireless Configuration +func (wc *UCIWirelessConf) Load() *UCIWirelessConf { + conf := wc.uciClient.Show("wireless") + + fmt.Println(conf.Stdout) + wc.parseDevicesConf(grep(conf.Stdout, "wireless.radio")) + wc.parseDefaultInterface(grep(conf.Stdout, "wireless.default_radio0")) + fmt.Println(grep(conf.Stdout, "wireless.@wifi-iface")) + wc.parseInterfaces(grep(conf.Stdout, "wireless.@wifi-iface")) + + return wc +} diff --git a/openwrt/uci_wireless_conf_test.go b/openwrt/uci_wireless_conf_test.go new file mode 100644 index 0000000..fc73eef --- /dev/null +++ b/openwrt/uci_wireless_conf_test.go @@ -0,0 +1,30 @@ +package openwrt + +import ( + "io/ioutil" + "testing" +) + +func TestUCIGetWirelessConf(t *testing.T) { + config, err := ioutil.ReadFile("./testdata/uci_show_wireless.txt") + if err != nil { + t.Fatal(err) + } + exec := createMockExecutor(string(config), "", 0) + uci := NewUCIWithExecutor(exec) + uci.LoadWirelessConf() + if g, e := uci.Wireless.DefaultInterface["Name"], "wifi-iface"; g != e { + t.Fatalf("DefaultDevice.Name is expected to be [%s] and we have [%s]", e, g) + } + + config, err = ioutil.ReadFile("./testdata/uci_show_wireless_2_cards.txt") + if err != nil { + t.Fatal(err) + } + exec = createMockExecutor(string(config), "", 0) + uci = NewUCIWithExecutor(exec) + uci.LoadWirelessConf() + if g, e := uci.Wireless.Interfaces[1].Name, "wifi-iface"; g != e { + t.Fatalf("DefaultDevice.Name is expected to be [%s] and we have [%s]", e, g) + } +} diff --git a/openwrt/uci_wireless_interface.go b/openwrt/uci_wireless_interface.go new file mode 100644 index 0000000..eef77a8 --- /dev/null +++ b/openwrt/uci_wireless_interface.go @@ -0,0 +1,185 @@ +package openwrt + +import ( + "fmt" + "os" + "path/filepath" + "regexp" + "strings" +) + +// UCIWirelessInterface is the description of an Wireless interface (cf Openwrt doc) on top of an Wireless Device +type UCIWirelessInterface struct { + Name string + Index int + Device string + DevicePath string + SysDevName string + Mode string + Disabled bool + Ssid string + Bssid string + Network string + Encryption string + Key string +} + +// NewUCIWirelessInterface builds a new UCIWirelessInterface instance +func NewUCIWirelessInterface() *UCIWirelessInterface { + return &UCIWirelessInterface{} +} + +// GetSysDevName looks for the system name of Wireless Interface +func (wi *UCIWirelessInterface) GetSysDevName(sysDir string) string { + var found string + + if wi.SysDevName != "" { + return wi.SysDevName + } + + if sysDir == "" { + sysDir = "/sys/devices/platform" + } + + if _, err := os.Stat(sysDir); os.IsNotExist(err) { + return "ERROR123-FILE-DONES-NOT-EXIST" + } + + filepath.Walk(sysDir, func(path string, f os.FileInfo, _ error) error { + patt := fmt.Sprintf("%s/%s/.*/address", wi.DevicePath, "net") + fmt.Println(wi.DevicePath) + fmt.Println(patt) + r, err := regexp.MatchString(patt, path) + if err == nil && r { + fmt.Println(path) + res := strings.Split(path, "/") + idx := len(res) - 2 + found = res[idx] + } + return nil + }) + fmt.Println(found) + wi.SysDevName = found + return found +} + +// Create add a new entry for wifi interface in UCI Configuration +func (wi *UCIWirelessInterface) Create(uci *UCI) *Action { + addRes := uci.AddWireless() + if addRes.ReturnCode != 0 { + return addRes + } + confPrefix := fmt.Sprintf("wireless.@wifi-iface[%d]", wi.Index) + conf := make(map[string][]string) + + conf["network"] = append(conf["network"], fmt.Sprintf("%s.network", confPrefix), wi.Network) + conf["ssid"] = append(conf["ssid"], fmt.Sprintf("%s.ssid", confPrefix), wi.Ssid) + conf["enc"] = append(conf["enc"], fmt.Sprintf("%s.encryption", confPrefix), wi.Encryption) + conf["device"] = append(conf["device"], fmt.Sprintf("%s.device", confPrefix), wi.Device) + conf["mode"] = append(conf["mode"], fmt.Sprintf("%s.mode", confPrefix), wi.Mode) + conf["bssid"] = append(conf["bssid"], fmt.Sprintf("%s.bssid", confPrefix), wi.Bssid) + conf["key"] = append(conf["key"], fmt.Sprintf("%s.key", confPrefix), wi.Key) + + for _, value := range conf { + if value[1] != "" { + result := uci.Set(value[0], value[1]) + if result.ReturnCode != 0 { + return result + } + } + } + + return &Action{ + CommandResult: &CommandResult{ + Stdout: "", + Stderr: "", + ReturnCode: 0, + }, + } +} + +// Save commit and relaod configuration (writes it to files !) +func (wi *UCIWirelessInterface) Save(uci *UCI) *Action { + commitRes := uci.Commit() + if commitRes.ReturnCode != 0 { + return commitRes + } + + reload := uci.Reload() + return reload +} + +// SysAdd creates the interface in the system using iw command +func (wi *UCIWirelessInterface) SysAdd(uci *UCI) *Action { + cmd := "iw" + opt := "phy" + phydev := fmt.Sprintf("phy%d", wi.Index) + what := "interface" + act := "add" + tpe := "managed" + + if wi.SysDevName == "" { + wi.SysDevName = fmt.Sprintf("tmp.radio%d", wi.Index) + } + + res := uci.exec.Run(cmd, opt, phydev, what, act, wi.SysDevName, "type", tpe) + return &Action{ + CommandResult: res, + } +} + +// Up brings the interface up in the system using ip command +func (wi *UCIWirelessInterface) Up(uci *UCI) *Action { + cmd := "ip" + opt := "link" + act := "set" + wht := "dev" + + res := uci.exec.Run(cmd, opt, act, wht, wi.SysDevName, "up") + return &Action{ + CommandResult: res, + } +} + +// Delete remove wifi interface from UCI Configuration +func (wi *UCIWirelessInterface) Delete(uci *UCI) *Action { + toDelete := fmt.Sprintf("wireless.@wifi-iface[%d]", wi.Index) + del := uci.Delete(toDelete) + if del.ReturnCode != 0 { + return del + } + return uci.Commit() +} + +// Update add a new entry for wifi interface in UCI Configuration +func (wi *UCIWirelessInterface) Update(uci *UCI) *Action { + wi.Delete(uci) + create := wi.Create(uci) + if create.ReturnCode != 0 { + return create + } + return uci.Commit() +} + +// Scan starts a scan for wifi networks with this device +func (wi *UCIWirelessInterface) Scan() []*WifiCell { + var devName string + devName = wi.GetSysDevName("") + + wifi := NewWifiScanner(devName) + return wifi.Scan() +} + +// Connect updates configuration to connect to the WifiCell +func (wi *UCIWirelessInterface) Connect(uci *UCI, cell *WifiCell, secret string) *Action { + wi.Ssid = cell.Ssid + wi.Bssid = cell.MacAddress + wi.Encryption = cell.Encryption + wi.Mode = "sta" + wi.Key = secret + res := wi.Update(uci) + if res.ReturnCode != 0 { + return res + } + return wi.Save(uci) +} diff --git a/openwrt/uci_wireless_interface_test.go b/openwrt/uci_wireless_interface_test.go new file mode 100644 index 0000000..ff68798 --- /dev/null +++ b/openwrt/uci_wireless_interface_test.go @@ -0,0 +1,115 @@ +package openwrt + +import ( + "testing" +) + +func TestGetSysDevName(t *testing.T) { + iface := NewUCIWirelessInterface() + iface.Name = "Test" + iface.Index = 1 + iface.Device = "radioX" + iface.DevicePath = "soc/soc:pcie/pci0000:00/0000:00:02.0/0000:02:00.0" + iface.SysDevName = "wlanX" + iface.Mode = "ap" + iface.Ssid = "PyxisWifi" + iface.Bssid = "00:00:00:00:00" + iface.Network = "Pyxis" + iface.Encryption = "psk" + iface.Key = "qsmdflkjqslmdfkjqslmfkdj" + + if iface.GetSysDevName("testdata/sys/") != "wlan1" { + t.Fatalf("UCIWirelessInterface.GetDeviceSysName() failed !") + } +} + +func TestCreate(t *testing.T) { + exec := createMockExecutor("", "", 0) + uci := NewUCIWithExecutor(exec) + + iface := NewUCIWirelessInterface() + iface.Name = "Test" + iface.Device = "radioX" + iface.Mode = "ap" + iface.Ssid = "PyxisWifi" + iface.Bssid = "00:00:00:00:00" + iface.Network = "Pyxis" + iface.Encryption = "psk" + iface.Key = "qsmdflkjqslmdfkjqslmfkdj" + + if iface.Create(uci).ReturnCode != 0 { + t.Fatalf("UCIWirelessInterface.Create() failed !") + } +} + +func TestUpdate(t *testing.T) { + exec := createMockExecutor("", "", 0) + uci := NewUCIWithExecutor(exec) + + iface := NewUCIWirelessInterface() + iface.Name = "Test" + iface.Index = 1 + iface.Device = "radioX" + iface.SysDevName = "wlanX" + iface.Mode = "ap" + iface.Ssid = "PyxisWifi" + iface.Bssid = "00:00:00:00:00" + iface.Network = "Pyxis" + iface.Encryption = "psk" + iface.Key = "qsmdflkjqslmdfkjqslmfkdj" + + if iface.Create(uci).ReturnCode != 0 { + t.Fatalf("UCIWirelessInterface.Create() failed !") + } + + iface.Name = "Tutu" + + if iface.Update(uci).ReturnCode != 0 { + t.Fatalf("UCIWirelessInterface.Update() failed !") + } +} + +func TestDelete(t *testing.T) { + exec := createMockExecutor("", "", 0) + uci := NewUCIWithExecutor(exec) + + iface := NewUCIWirelessInterface() + iface.Name = "Test" + iface.Index = 1 + iface.Device = "radioX" + iface.SysDevName = "wlanX" + iface.Mode = "ap" + iface.Ssid = "PyxisWifi" + iface.Bssid = "00:00:00:00:00" + iface.Network = "Pyxis" + iface.Encryption = "psk" + iface.Key = "qsmdflkjqslmdfkjqslmfkdj" + + if iface.Delete(uci).ReturnCode != 0 { + t.Fatalf("UCIWirelessInterface.Delete() failed !") + } +} + +func TestConnect(t *testing.T) { + + exec := createMockExecutor("", "", 0) + uci := NewUCIWithExecutor(exec) + + iface := NewUCIWirelessInterface() + iface.Name = "Test" + iface.Index = 1 + iface.Device = "radioX" + iface.SysDevName = "wlanX" + iface.Mode = "ap" + iface.Ssid = "PyxisWifi" + iface.Bssid = "00:00:00:00:00" + iface.Network = "Pyxis" + iface.Encryption = "psk" + iface.Key = "qsmdflkjqslmdfkjqslmfkdj" + + wifiCell := NewWifiCell("PyxisWifi", "01:01:01:01:01", "psk") + + if iface.Connect(uci, wifiCell, "Toto").ReturnCode != 0 { + t.Fatalf("UCIWirelessInterface.Delete() failed !") + } +} diff --git a/openwrt/wifi.go b/openwrt/wifi.go deleted file mode 100644 index c884f14..0000000 --- a/openwrt/wifi.go +++ /dev/null @@ -1,91 +0,0 @@ -package openwrt - -import ( - "log" - "strings" - "time" -) - -// Wifi gives access to al OpenWRT Wifi operations -type Wifi struct { - exec Executor - iface string - Cells []*WifiCell -} - -// NewWifi return an UCI instance to interact with UCI -func NewWifi(wIface string) *Wifi { - exec := &localExecutor{} - iface := wIface - return &Wifi{exec, iface, nil} -} - -// NewWifiWithExecutor returns a Wifi Instance an gives you the ability to provide -// a different command executor than the default one. -func NewWifiWithExecutor(exec Executor, wIface string) *Wifi { - return &Wifi{exec, wIface, nil} -} - -func (w *Wifi) getEncryption(line string) string { - enc := "unkn" - if strings.Contains(line, "WPA2 PSK") { - enc = "psk" - } else if strings.Contains(line, "none") { - enc = "none" - } - return enc -} - -func (w *Wifi) parseWifiCells(stdout string) int { - new := false - mac, ssid, enc := "", "", "" - for _, line := range strings.Split(strings.TrimSuffix(stdout, "\n"), "\n") { - if strings.HasPrefix(line, "Cell") && new == false { - new = true - mac = strings.Split(line, " ")[4] - } - if strings.Contains(line, "ESSID:") { - ssid = strings.Split(line, " ")[1] - ssid = strings.Trim(ssid, "\"") - } - if strings.Contains(line, "Encryption:") { - enc = w.getEncryption(line) - } - if len(mac) > 0 && len(ssid) > 0 && len(enc) > 0 { - cell := NewWifiCell(ssid, mac, enc) - w.Cells = append(w.Cells, cell) - ssid, mac, enc = "", "", "" - new = false - } - } - return 0 -} - -// GetWifiCells retrieves all available wifi cells for a card ! -func (w *Wifi) GetWifiCells() int { - res := w.exec.Run("iwinfo", w.iface, "scan") - if res.ReturnCode != 0 { - log.Fatal(res.Stderr) - return res.ReturnCode - } - - for res.Stdout == "Scanning not possible" { - time.Sleep(time.Second) - res = w.exec.Run("iwinfo", w.iface, "scan") - if res.ReturnCode != 0 { - log.Fatal(res.Stderr) - return res.ReturnCode - } - } - return w.parseWifiCells(res.Stdout) -} - -// GetCell retreives an WifiCell by SSID provided in parameter -func (w *Wifi) GetCell(ssid string) *WifiCell { - for _, v := range w.Cells { - if v.Ssid == ssid { - return v - } - } - return nil -} diff --git a/openwrt/wifi_cell.go b/openwrt/wifi_cell.go index 3ce823e..b5129e3 100644 --- a/openwrt/wifi_cell.go +++ b/openwrt/wifi_cell.go @@ -1,11 +1,9 @@ package openwrt -import "time" - // WifiCell reprensents wifi network Cell type WifiCell struct { Ssid string - MacAdress string + MacAddress string Encryption string } @@ -13,81 +11,7 @@ type WifiCell struct { func NewWifiCell(ssid string, mac string, encrypt string) *WifiCell { return &WifiCell{ Ssid: ssid, - MacAdress: mac, + MacAddress: mac, Encryption: encrypt, } } - -func (cell *WifiCell) uciWifiConfigure(uci *UCI, secret string) *Action { - setRes := uci.Set("wireless.@wifi-iface[1].network", "PyxisNetwork") - if setRes.ReturnCode != 0 { - return setRes - } - - setRes = uci.Set("wireless.@wifi-iface[1].ssid", cell.Ssid) - if setRes.ReturnCode != 0 { - return setRes - } - setRes = uci.Set("wireless.@wifi-iface[1].encryption", cell.Encryption) - if setRes.ReturnCode != 0 { - return setRes - } - setRes = uci.Set("wireless.@wifi-iface[1].device", "radio1") - if setRes.ReturnCode != 0 { - return setRes - } - setRes = uci.Set("wireless.@wifi-iface[1].mode", "sta") - if setRes.ReturnCode != 0 { - return setRes - } - setRes = uci.Set("wireless.@wifi-iface[1].bssid", cell.MacAdress) - if setRes.ReturnCode != 0 { - return setRes - } - setRes = uci.Set("wireless.@wifi-iface[1].key", secret) - if setRes.ReturnCode != 0 { - return setRes - } - - return &Action{ - &CommandResult{ - Stdout: "", - Stderr: "", - ReturnCode: 0, - }, - } -} - -// Connect to wifi Cell -func (cell *WifiCell) Connect(uci *UCI, secret string) *Action { - delRes := uci.Delete("wireless.@wifi-iface[1]") - if delRes.ReturnCode != 0 { - return delRes - } - addRes := uci.AddWireless("wifi-iface") - if addRes.ReturnCode != 0 { - return addRes - } - - setRes := cell.uciWifiConfigure(uci, secret) - if setRes.ReturnCode != 0 { - return setRes - } - - setRes = uci.Commit() - if setRes.ReturnCode != 0 { - return setRes - } - setRes = uci.Reload() - if setRes.ReturnCode != 0 { - return setRes - } - time.Sleep(20 * time.Second) - return &Action{ - &CommandResult{ - Stdout: "", - Stderr: "", - ReturnCode: 0, - }, - } -} diff --git a/openwrt/wifi_cell_test.go b/openwrt/wifi_cell_test.go deleted file mode 100644 index c54da57..0000000 --- a/openwrt/wifi_cell_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package openwrt - -import "testing" - -func TestWifiCellConnection(t *testing.T) { - uexec := createMockExecutor("", "", 0) - uci := NewUCIWithExecutor(uexec) - - cellList := `Cell 40 - Address: 68:A3:78:6E:D9:24 - ESSID: "PyxisWifi" - Mode: Master Channel: 3 - Signal: -90 dBm Quality: 20/70 - Encryption: WPA2 PSK (CCMP)` - - exec := createMockExecutor(cellList, "", 0) - wifi := NewWifiWithExecutor(exec, "wlan1") - _ = wifi.GetWifiCells() - - cell := wifi.GetCell("PyxisWifi") - cell.Connect(uci, "secret") -} diff --git a/openwrt/wifi_scanner.go b/openwrt/wifi_scanner.go new file mode 100644 index 0000000..fc9a406 --- /dev/null +++ b/openwrt/wifi_scanner.go @@ -0,0 +1,126 @@ +package openwrt + +import ( + "regexp" + "strings" + "time" +) + +// NONE contains the string for "none" +const NONE = "none" + +// WifiScanner gives access to al OpenWRT Wifi Scan operations +type WifiScanner struct { + exec Executor + iface string + Cells []*WifiCell +} + +// NewWifiScanner return an UCI instance to interact with UCI +func NewWifiScanner(wIface string) *WifiScanner { + exec := &localExecutor{} + iface := wIface + Cells := []*WifiCell{} + return &WifiScanner{exec, iface, Cells} +} + +// NewWifiWithExecutor returns a Wifi Instance an gives you the ability to provide +// a different command executor than the default one. +func NewWifiWithExecutor(exec Executor, wIface string) *WifiScanner { + return &WifiScanner{exec, wIface, nil} +} + +func (w *WifiScanner) getEncryption(line string) string { + var enc string + if strings.Contains(line, "PSK") { + enc = "psk" + } else if strings.Contains(line, NONE) { + enc = NONE + } else { + enc = "unkn" + } + return enc +} + +func (w *WifiScanner) parseWifiCells(stdout string) int { + mac, ssid, enc := "", "", "" + encOff := false + macExpr := `([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])` + + for _, line := range strings.Split(strings.TrimSuffix(stdout, "\n"), "\n") { + expr := regexp.MustCompile("^BSS") + if expr.MatchString(line) { + if len(mac) != 0 && len(ssid) != 0 && len(enc) == 0 { + enc = NONE + cell := NewWifiCell(ssid, mac, enc) + w.Cells = append(w.Cells, cell) + ssid, mac, enc = "", "", "" + } + macRegexp := regexp.MustCompile(macExpr) + mac = macRegexp.FindString(line) + } + + if strings.Contains(line, "SSID:") { + ssid = strings.Split(line, ":")[1] + ssid = strings.Trim(ssid, "\"") + ssid = strings.Trim(ssid, " ") + if ssid == "" { + ssid = " " + } + } + + if strings.Contains(line, "Encryption key:off") { + encOff = true + } + + if strings.Contains(line, "Authentication suites") { + enc = w.getEncryption(line) + } + + if len(mac) > 0 && len(ssid) > 0 && (len(enc) > 0 || encOff) { + if encOff { + enc = NONE + encOff = false + } + cell := NewWifiCell(ssid, mac, enc) + w.Cells = append(w.Cells, cell) + ssid, mac, enc = "", "", "" + } + } + return 0 +} + +// GetWifiCells retrieves all available wifi cells for a card ! +func (w *WifiScanner) GetWifiCells() int { + var res *CommandResult + for try := 0; try != 20; try++ { + res = w.exec.Run("iw", w.iface, "scan") + if res.ReturnCode == 0 { + parsing := w.parseWifiCells(res.Stdout) + if parsing == 0 { + if len(w.Cells) == 0 { + return 242 + } + } + return parsing + } + time.Sleep(time.Second * 2) + } + return res.ReturnCode +} + +// GetCell retreives an WifiCell by SSID provided in parameter +func (w *WifiScanner) GetCell(ssid string) *WifiCell { + for _, v := range w.Cells { + if v.Ssid == ssid { + return v + } + } + return nil +} + +// Scan retreives a list of available wifi cells +func (w *WifiScanner) Scan() []*WifiCell { + _ = w.GetWifiCells() + return w.Cells +} diff --git a/openwrt/wifi_test.go b/openwrt/wifi_scanner_test.go similarity index 76% rename from openwrt/wifi_test.go rename to openwrt/wifi_scanner_test.go index a168c7f..3c93af2 100644 --- a/openwrt/wifi_test.go +++ b/openwrt/wifi_scanner_test.go @@ -25,19 +25,19 @@ func TestGetWifiCells(t *testing.T) { t.Errorf("The first Cell have a bad SSID !\n %s is expected and we have %s", e, g) } - if g, e := wifi.Cells[0].MacAdress, "68:A3:78:6E:D9:24"; g != e { - t.Errorf("The first Cell have a bad MAC !\n %s is expected and we have %s", e, g) + if g, e := wifi.Cells[0].MacAddress, "74:3e:2b:08:41:1c"; g != e { + t.Errorf("The first Cell have a bad MAC !\n [%s] is expected and we have [%s]", e, g) } - if g, e := wifi.Cells[0].Encryption, "none"; g != e { + if g, e := wifi.Cells[1].Encryption, "none"; g != e { t.Errorf("The first Cell have a bad Encryption!\n %s is expected and we have %s", e, g) } - if g, e := wifi.Cells[1].Encryption, "psk"; g != e { - t.Errorf("The second Cell have a bad Encryption!\n %s is expected and we have %s", e, g) + if g, e := wifi.Cells[2].Encryption, "psk"; g != e { + t.Errorf("The last Cell have a bad Encryption!\n %s is expected and we have %s", e, g) } - if g, e := wifi.Cells[2].MacAdress, "0C:F4:D5:16:AA:18"; g != e { + if g, e := wifi.Cells[2].MacAddress, "20:47:da:b7:0e:5c"; g != e { t.Errorf("The last Cell have a bad MAC !\n %s is expected and we have %s", e, g) } } @@ -64,8 +64,8 @@ func TestGetWifiCellsLarge(t *testing.T) { exec := createMockExecutor(string(cellList), "", 0) wifi := NewWifiWithExecutor(exec, "wlan1") _ = wifi.GetWifiCells() - if len(wifi.Cells) != 49 { - fmt.Printf("Size of wifi.Cells is %d and not 49 !!!\n", len(wifi.Cells)) + if len(wifi.Cells) != 40 { + fmt.Printf("Size of wifi.Cells is %d and not 40 !!!\n", len(wifi.Cells)) t.Error("Cell list is empty ... This can not append !! Fix your code Dummy !") } } diff --git a/use.go b/use.go new file mode 100644 index 0000000..b7e0643 --- /dev/null +++ b/use.go @@ -0,0 +1,57 @@ +package main + +import ( + "forge.cadoles.com/Pyxis/orion/openwrt" +) + +func main() { + uci := openwrt.NewUCI() + uci.LoadWirelessConf() + wifaces := uci.GetWifiIfaces() + wDevices := uci.GetWifiDevices() + + PyxisDevice := wDevices[0] + ClientDevice := wDevices[1] + + for _, iface := range wifaces { + iface.Delete(uci) + } + + // Main Pyxis Interface + pyxis := openwrt.NewUCIWirelessInterface() + pyxis.Name = "Pyxis-Network" + pyxis.Network = "pyxis" + pyxis.Index = 0 + pyxis.Ssid = "Pyxis" + pyxis.SysDevName = "wlan0" + pyxis.Encryption = "psk2" + pyxis.Key = "xxxxxxxxx" + pyxis.Device = PyxisDevice["Device"] + pyxis.DevicePath = PyxisDevice["Path"] + pyxis.Mode = "ap" + _ = pyxis.Create(uci) + _ = pyxis.Save(uci) + + // Client Interface + client := openwrt.NewUCIWirelessInterface() + client.Name = "Client-Network" + client.Index = 1 + client.SysDevName = "wlan1" + client.Device = ClientDevice["Device"] + client.DevicePath = ClientDevice["Path"] + client.Mode = "sta" + _ = client.Create(uci) + _ = client.SysAdd(uci) + _ = client.Up(uci) + + scan := client.Scan() + for _, elm := range scan { + if elm.Ssid == "Cadoles" { + client.Connect(uci, elm, "xxxxxx") + } + } + + dhcp := openwrt.NewDhcpClient(client.SysDevName) + dhcp.AskForIP() + return +}