mirror of
https://github.com/taigrr/golang-wpasupplicant
synced 2025-01-18 04:43:18 -08:00
Expose more control interface commands
This commit is contained in:
parent
3d367e7a27
commit
b70264bcf8
41
unixgram.go
41
unixgram.go
@ -211,6 +211,32 @@ func (uc *unixgramConn) Ping() error {
|
|||||||
return &ParseError{Line: string(resp)}
|
return &ParseError{Line: string(resp)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (uc *unixgramConn) AddNetwork() (int, error) {
|
||||||
|
resp, err := uc.cmd("ADD_NETWORK")
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
|
||||||
|
b := bytes.NewBuffer(resp)
|
||||||
|
return strconv.Atoi(strings.Trim(b.String(), "\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (uc *unixgramConn) EnableNetwork(networkID int) error {
|
||||||
|
return uc.runCommand(fmt.Sprintf("ENABLE_NETWORK %d", networkID))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (uc *unixgramConn) SetNetwork(networkID int, variable string, value string) error {
|
||||||
|
return uc.runCommand(fmt.Sprintf("SET_NETWORK %d %s \"%s\"", networkID, variable, value))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (uc *unixgramConn) SaveConfig() error {
|
||||||
|
return uc.runCommand("SAVE_CONFIG")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (uc *unixgramConn) Scan() error {
|
||||||
|
return uc.runCommand("SCAN")
|
||||||
|
}
|
||||||
|
|
||||||
func (uc *unixgramConn) ScanResults() ([]ScanResult, []error) {
|
func (uc *unixgramConn) ScanResults() ([]ScanResult, []error) {
|
||||||
resp, err := uc.cmd("SCAN_RESULTS")
|
resp, err := uc.cmd("SCAN_RESULTS")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -220,6 +246,21 @@ func (uc *unixgramConn) ScanResults() ([]ScanResult, []error) {
|
|||||||
return parseScanResults(bytes.NewBuffer(resp))
|
return parseScanResults(bytes.NewBuffer(resp))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// runCommand is a wrapper around the uc.cmd command which makes sure the
|
||||||
|
// command returned a successful (OK) response.
|
||||||
|
func (uc *unixgramConn) runCommand(cmd string) error {
|
||||||
|
resp, err := uc.cmd(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if bytes.Compare(resp, []byte("OK\n")) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ParseError{Line: string(resp)}
|
||||||
|
}
|
||||||
|
|
||||||
// parseScanResults parses the SCAN_RESULTS output from wpa_supplicant. This
|
// parseScanResults parses the SCAN_RESULTS output from wpa_supplicant. This
|
||||||
// is split out from ScanResults() to make testing easier.
|
// is split out from ScanResults() to make testing easier.
|
||||||
func parseScanResults(resp io.Reader) (res []ScanResult, errs []error) {
|
func parseScanResults(resp io.Reader) (res []ScanResult, errs []error) {
|
||||||
|
@ -127,6 +127,24 @@ type Conn interface {
|
|||||||
// responding.
|
// responding.
|
||||||
Ping() error
|
Ping() error
|
||||||
|
|
||||||
|
// AddNetwork creates an empty network configuration. Returns the network
|
||||||
|
// ID.
|
||||||
|
AddNetwork() (int, error)
|
||||||
|
|
||||||
|
// SetNetwork configures a network property. Returns error if the property
|
||||||
|
// configuration failed.
|
||||||
|
SetNetwork(int, string, string) error
|
||||||
|
|
||||||
|
// EnableNetwork enables a network. Returns error if the command fails.
|
||||||
|
EnableNetwork(int) error
|
||||||
|
|
||||||
|
// SaveConfig stores the current network configuration to disk.
|
||||||
|
SaveConfig() error
|
||||||
|
|
||||||
|
// Scan triggers a new scan. Returns error if the wpa_supplicant does not
|
||||||
|
// return OK.
|
||||||
|
Scan() error
|
||||||
|
|
||||||
// ScanResult returns the latest scanning results. It returns a slice
|
// ScanResult returns the latest scanning results. It returns a slice
|
||||||
// of scanned BSSs, and/or a slice of errors representing problems
|
// of scanned BSSs, and/or a slice of errors representing problems
|
||||||
// communicating with wpa_supplicant or parsing its output.
|
// communicating with wpa_supplicant or parsing its output.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user