Documentation
¶
Overview ¶
Package wpa_supplicant provides a control interface to a wpa_supplicant/hostapd daemon.
The Connect function connects to a daemon:
ctrlIface, err := wpa_supplicant.Connect("/run/wpa_supplicant/wlan0") if err != nil { // handle err }
The SendRequest method sends request to the daemon:
res, err := ctrlIface.SendRequest(context.TODO(), "PING") if err != nil { // handle err } fmt.Println(res) // PONG
The control interface can listen to daemon events:
err := ctrlIface.Listen(context.TODO(), func (event wpa_supplicant.Event) { fmt.Println(event) // {Priority: wpa_supplicant.EventPriorityInfo, Data: "CTRL-EVENT-SCAN-STARTED"} }) if err != nil { // handle err }
Refer to wpa_supplicant/hostapd documentation for available requests, responses and events on this interface.
Index ¶
Constants ¶
const ( EventPriorityMsgDump = EventPriority(iota) EventPriorityDebug EventPriorityInfo EventPriorityWarning EventPriorityError )
Variables ¶
var (
DefaultConnectionOptions = ConnectionOptions{
TemporaryFilePattern: "wpa_supplicant-go-ctrl",
}
)
Functions ¶
This section is empty.
Types ¶
type Connection ¶
A Connection is a connection to the wpa_supplicant/hostapd control interface socket.
func (*Connection) SendRequest ¶
SendRequest sends a request to wpa_supplicant.
res, err := conn.SendRequest(ctx, "PING") if err != nil { // handle err } fmt.Println(res) // PONG
type ConnectionOptions ¶
type ConnectionOptions struct { // TemporaryFilePattern is the file name pattern used to generate local socket addresses in os.TempDir(). TemporaryFilePattern string }
A ConnectionOptions holds options to construct a ControlInterface.
type ControlInterface ¶
type ControlInterface struct {
// contains filtered or unexported fields
}
A ControlInterface is a control interface to a wpa_supplicant/hostapd daemon.
https://w1.fi/wpa_supplicant/devel/ctrl_iface_page.html
func Connect ¶
func Connect(controlInterfacePath string) (*ControlInterface, error)
Connect connects to wpa_supplicant/hostapd via the control interface in controlInterfacePath.
func ConnectWithOptions ¶
func ConnectWithOptions(controlInterfacePath string, opts ConnectionOptions) (*ControlInterface, error)
ConnectWithOptions connects to wpa_supplicant/hostapd via the control interface in controlInterfacePath.
func (*ControlInterface) Close ¶
func (ctrlIface *ControlInterface) Close() error
Close closes the connection to wpa_supplicant.
func (*ControlInterface) Listen ¶
func (ctrlIface *ControlInterface) Listen(ctx context.Context, handler UnsolicitedEventHandler) error
Listen listens to control interface events.
The function blocks while listening to events, it returns if an error occurs while reading the remote connection or if ctx is canceled. When an event is received, handler is called on the caller goroutine.
Listen opens a separate connection to handle events only, not interfering with the solicited requests/reply exchanges occurring on this ControlInterface.
func (*ControlInterface) SendRequest ¶
SendRequest sends a request to wpa_supplicant.
res, err := conn.SendRequest(ctx, "PING") if err != nil { // handle err } fmt.Println(res) // PONG
type Event ¶
type Event struct { Priority EventPriority Data string }
Event is an unsolicited message from wpa_supplicant.
type EventPriority ¶
type EventPriority int
A EventPriority is a value indicating the priority of an event received via the control interface.
type UnsolicitedEventHandler ¶
type UnsolicitedEventHandler func(Event)
A UnsolicitedEventHandler handles events received in via the control interface.