-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
126 lines (110 loc) · 3.56 KB
/
main.go
File metadata and controls
126 lines (110 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Query WiFi information from the wificond system service.
//
// Uses IWificond via the "wifinl80211" service to list WiFi interfaces,
// available channels per band, and PHY capabilities.
//
// Build:
//
// GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o build/softap_wifi_hal ./examples/softap_wifi_hal/
// adb push softap_wifi_hal /data/local/tmp/ && adb shell /data/local/tmp/softap_wifi_hal
package main
import (
"context"
"fmt"
"os"
"github.com/AndroidGoLab/binder/android/net/wifi/nl80211"
"github.com/AndroidGoLab/binder/binder"
"github.com/AndroidGoLab/binder/binder/versionaware"
"github.com/AndroidGoLab/binder/kernelbinder"
"github.com/AndroidGoLab/binder/servicemanager"
)
func main() {
ctx := context.Background()
driver, err := kernelbinder.Open(ctx, binder.WithMapSize(128*1024))
if err != nil {
fmt.Fprintf(os.Stderr, "open binder: %v\n", err)
os.Exit(1)
}
defer driver.Close(ctx)
transport, err := versionaware.NewTransport(ctx, driver, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "version-aware transport: %v\n", err)
os.Exit(1)
}
sm := servicemanager.New(transport)
svc, err := sm.GetService(ctx, servicemanager.WifiNl80211Service)
if err != nil {
fmt.Fprintf(os.Stderr, "get wifinl80211 service: %v\n", err)
fmt.Fprintf(os.Stderr, "(wificond not available or access denied by SELinux)\n")
os.Exit(1)
}
wificond := nl80211.NewWificondProxy(svc)
// List client (STA) interfaces.
clientIfaces, err := wificond.GetClientInterfaces(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "GetClientInterfaces: %v\n", err)
} else {
fmt.Printf("Client interfaces: %d\n", len(clientIfaces))
for i, iface := range clientIfaces {
fmt.Printf(" [%d] binder handle present\n", i)
_ = iface // IBinder handles
}
}
// List AP interfaces.
apIfaces, err := wificond.GetApInterfaces(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "GetApInterfaces: %v\n", err)
} else {
fmt.Printf("AP interfaces: %d\n", len(apIfaces))
for i, iface := range apIfaces {
fmt.Printf(" [%d] binder handle present\n", i)
_ = iface
}
}
// Available 2.4 GHz channels.
fmt.Println()
ch2g, err := wificond.GetAvailable2gChannels(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "GetAvailable2gChannels: %v\n", err)
} else {
fmt.Printf("Available 2.4 GHz channels: %v\n", ch2g)
}
// Available 5 GHz non-DFS channels.
ch5g, err := wificond.GetAvailable5gNonDFSChannels(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "GetAvailable5gNonDFSChannels: %v\n", err)
} else {
fmt.Printf("Available 5 GHz (non-DFS) channels: %v\n", ch5g)
}
// Available DFS channels.
chDFS, err := wificond.GetAvailableDFSChannels(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "GetAvailableDFSChannels: %v\n", err)
} else {
fmt.Printf("Available DFS channels: %v\n", chDFS)
}
// Available 6 GHz channels.
ch6g, err := wificond.GetAvailable6gChannels(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "GetAvailable6gChannels: %v\n", err)
} else {
fmt.Printf("Available 6 GHz channels: %v\n", ch6g)
}
// Available 60 GHz channels.
ch60g, err := wificond.GetAvailable60gChannels(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "GetAvailable60gChannels: %v\n", err)
} else {
fmt.Printf("Available 60 GHz channels: %v\n", ch60g)
}
// PHY capabilities for common interface names.
fmt.Println()
for _, ifName := range []string{"wlan0", "wlan1", "wlan2"} {
caps, err := wificond.GetDeviceWiphyCapabilities(ctx, ifName)
if err != nil {
fmt.Fprintf(os.Stderr, "GetDeviceWiphyCapabilities(%s): %v\n", ifName, err)
continue
}
fmt.Printf("PHY capabilities for %s: %+v\n", ifName, caps)
}
}