forked from plorefice/gonnman
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtechnology.go
76 lines (65 loc) · 1.74 KB
/
technology.go
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
package connman
import (
"fmt"
"log"
"github.com/godbus/dbus"
)
type Technology struct {
Path dbus.ObjectPath `json:"path"`
Name string `json:"name"`
Type string `json:"type"`
Powered bool `json:"powered"`
Connected bool `json:"connected"`
Tethering bool `json:"tethering"`
TetheringIdentifier string `json:"tethering_identifier,omitempty"`
TetheringPassphrase string `json:"tethering_passphrase,omitempty"`
}
func (t *Technology) Enable() error {
db, err := DBusTechnology(t.Path)
if err != nil {
return err
}
return db.Set("Powered", true)
}
func (t *Technology) Disable() error {
db, err := DBusTechnology(t.Path)
if err != nil {
return err
}
return db.Set("Powered", false)
}
func (t *Technology) Scan() error {
db, err := DBusTechnology(t.Path)
if err != nil {
return err
}
_, err = db.Call("Scan")
return err
}
func (t *Technology) EnableTethering(ssid string, psk string) error {
db, err := DBusTechnology(t.Path)
if err != nil {
return err
}
if len(ssid) > 0 {
log.Printf("Setting up TetheringIdentifier: %v\n", ssid)
db.Set("TetheringIdentifier", ssid)
}
if len(psk) > 8 && len(psk) < 64 {
log.Printf("Setting up TetheringPassphrase: %v\n", psk)
db.Set("TetheringPassphrase", psk)
} else {
return fmt.Errorf("Passphrase too short or too long: %v", psk)
}
log.Printf("Enabling tethering: %v - %v\n", ssid, psk)
return db.Set("Tethering", true)
}
func (t *Technology) DisableTethering() error {
db, err := DBusTechnology(t.Path)
if err != nil {
log.Printf("Error: %v\n", err)
return err
}
log.Println("Disabling tethering!")
return db.Set("Tethering", false)
}