Categorygithub.com/basilfx/go-wireless
modulepackage
1.0.0
Repository: https://github.com/basilfx/go-wireless.git
Documentation: pkg.go.dev

# README

go-wireless

A way to interact with the Wireless interfaces on a Linux machine using WPA Supplicant.

Requirements

Requires a running wpa_supplicant with control interface at /var/run/wpa_supplicant.

Usage

go.dev reference

Get a list of wifi cards attached:

ifaces := wireless.Interfaces()

From there you can use the client:

wc, err := wireless.NewClient("wlan0")
defer wc.Close()

Get a list of APs that are in range:

aps, err := wc.Scan()
fmt.Println(aps, err)

Get a list of known networks:

nets, err := wc.Networks()
fmt.Println(nets, err)

Connect to networks:

net := NewNetwork("FBI Surveillance Van #4", "secretpass")
net, err := wc.Connect(net)

Disable networks:

nets, err:= wc.Networks()
net, err := nets.Find("FBI Surveillance Van #4")
net.Disable(true)
net, err := wc.UpdateNetwork(net)

Subscribe to events:

sub := wc.Subscribe(wireless.EventConnected, wireless.EventAuthReject, wireless.EventDisconnected)

ev := <-sub.Next()
switch ev.Name {
	case wireless.EventConnected:
		fmt.Println(ev.Arguments)
	case wireless.EventAuthReject:
		fmt.Println(ev.Arguments)
	case wireless.EventDisconnected:
		fmt.Println(ev.Arguments)
}

Check the status of the connection:

st, err := wc.Status()
fmt.Printf("%+v\n", st)

API

There is an API that can be used with gin:

r := gin.Default()
api.SetupRoutes(r)
r,Serve(":8080")

Endpoints

  • GET /interfaces
  • GET /interfaces/:iface
  • PUT /interfaces/:iface
  • GET /interfaces/:iface/aps
  • GET /interfaces/:iface/networks
  • POST /interfaces/:iface/networks
  • PUT /interfaces/:iface/networks/:id_or_idstr
  • GET /interfaces/:iface/networks/:id_or_idstr
  • DELETE /interfaces/:iface/networks/:id_or_idstr

# Packages

No description provided by the author
No description provided by the author

# Functions

Dial will dial the WPA control interface with the given interface name.
IsUseOfClosedNetworkConnectionError will return true if the error is about use of closed network connection.
NewClient will create a new client by connecting to the given interface in WPA.
NewClientFromConn returns a new client from an already established connection.
NewDisabledNetwork will create a new disabled network with the given parameters.
NewEventFromMsg will create a new event from the given message.
NewNamedNetwork will create a new network with the given parameters.
NewNetwork will create a new network with the given parameters.
NewState will return the state of the WPA.
SysFSInterfaces returns the wireless interfaces found in the SysFS (/sys).

# Constants

AcsEventCompleted as defined in wpactrl/wpa_ctrl.h:300.
AcsEventFailed as defined in wpactrl/wpa_ctrl.h:301.
AcsEventStarted as defined in wpactrl/wpa_ctrl.h:299.
ApCsaFinished as defined in wpactrl/wpa_ctrl.h:310.
ApEventDisabled as defined in wpactrl/wpa_ctrl.h:294.
ApEventEnabled as defined in wpactrl/wpa_ctrl.h:293.
ApRejectedBlockedSta as defined in wpactrl/wpa_ctrl.h:291.
ApRejectedMaxSta as defined in wpactrl/wpa_ctrl.h:290.
ApStaConnected as defined in wpactrl/wpa_ctrl.h:285.
ApStaDisconnected as defined in wpactrl/wpa_ctrl.h:286.
ApStaPollOk as defined in wpactrl/wpa_ctrl.h:288.
ApStaPossiblePskMismatch as defined in wpactrl/wpa_ctrl.h:287.
BssMaskAll as defined in wpactrl/wpa_ctrl.h:340.
BssTmResp as defined in wpactrl/wpa_ctrl.h:316.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
CredAdded as defined in wpactrl/wpa_ctrl.h:247.
CredModified as defined in wpactrl/wpa_ctrl.h:249.
CredRemoved as defined in wpactrl/wpa_ctrl.h:251.
CtrlIfacePort as defined in wpactrl/wpa_ctrl.h:541.
CtrlIfacePortLimit as defined in wpactrl/wpa_ctrl.h:542.
CtrlReq as defined in wpactrl/wpa_ctrl.h:19.
CtrlRsp as defined in wpactrl/wpa_ctrl.h:22.
DfsEventCacCompleted as defined in wpactrl/wpa_ctrl.h:306.
DfsEventCacStart as defined in wpactrl/wpa_ctrl.h:305.
DfsEventNewChannel as defined in wpactrl/wpa_ctrl.h:304.
DfsEventNopFinished as defined in wpactrl/wpa_ctrl.h:307.
DfsEventPreCacExpired as defined in wpactrl/wpa_ctrl.h:308.
DfsEventRadarDetected as defined in wpactrl/wpa_ctrl.h:303.
DppEventAuthSuccess as defined in wpactrl/wpa_ctrl.h:155.
DppEventConfFailed as defined in wpactrl/wpa_ctrl.h:161.
DppEventConfobjPass as defined in wpactrl/wpa_ctrl.h:163.
DppEventConfobjPsk as defined in wpactrl/wpa_ctrl.h:164.
DppEventConfobjSsid as defined in wpactrl/wpa_ctrl.h:162.
DppEventConfReceived as defined in wpactrl/wpa_ctrl.h:159.
DppEventConfSent as defined in wpactrl/wpa_ctrl.h:160.
DppEventConnector as defined in wpactrl/wpa_ctrl.h:165.
DppEventCSignKey as defined in wpactrl/wpa_ctrl.h:166.
DppEventFail as defined in wpactrl/wpa_ctrl.h:173.
DppEventMissingConnector as defined in wpactrl/wpa_ctrl.h:168.
DppEventNetAccessKey as defined in wpactrl/wpa_ctrl.h:167.
DppEventNetworkID as defined in wpactrl/wpa_ctrl.h:169.
DppEventNotCompatible as defined in wpactrl/wpa_ctrl.h:156.
DppEventResponsePending as defined in wpactrl/wpa_ctrl.h:157.
DppEventRx as defined in wpactrl/wpa_ctrl.h:170.
DppEventScanPeerQrCode as defined in wpactrl/wpa_ctrl.h:158.
DppEventTx as defined in wpactrl/wpa_ctrl.h:171.
DppEventTxStatus as defined in wpactrl/wpa_ctrl.h:172.
EssDisassocImminent as defined in wpactrl/wpa_ctrl.h:234.
EventAssocReject as defined in wpactrl/wpa_ctrl.h:30.
EventAuthReject as defined in wpactrl/wpa_ctrl.h:32.
EventAvoidFreq as defined in wpactrl/wpa_ctrl.h:115.
EventBeaconLoss as defined in wpactrl/wpa_ctrl.h:86.
EventBssAdded as defined in wpactrl/wpa_ctrl.h:78.
EventBssRemoved as defined in wpactrl/wpa_ctrl.h:80.
EventChannelSwitch as defined in wpactrl/wpa_ctrl.h:90.
EventConnected as defined in wpactrl/wpa_ctrl.h:26.
EventDisconnected as defined in wpactrl/wpa_ctrl.h:28.
EventEapFailure as defined in wpactrl/wpa_ctrl.h:60.
EventEapFailure2 as defined in wpactrl/wpa_ctrl.h:61.
EventEapMethod as defined in wpactrl/wpa_ctrl.h:44.
EventEapNotification as defined in wpactrl/wpa_ctrl.h:38.
EventEapPeerAlt as defined in wpactrl/wpa_ctrl.h:48.
EventEapPeerCert as defined in wpactrl/wpa_ctrl.h:46.
EventEapProposedMethod as defined in wpactrl/wpa_ctrl.h:42.
EventEapRetransmit as defined in wpactrl/wpa_ctrl.h:54.
EventEapRetransmit2 as defined in wpactrl/wpa_ctrl.h:55.
EventEapStarted as defined in wpactrl/wpa_ctrl.h:40.
EventEapStatus as defined in wpactrl/wpa_ctrl.h:52.
EventEapSuccess as defined in wpactrl/wpa_ctrl.h:57.
EventEapSuccess2 as defined in wpactrl/wpa_ctrl.h:58.
EventEapTimeoutFailure as defined in wpactrl/wpa_ctrl.h:63.
EventEapTimeoutFailure2 as defined in wpactrl/wpa_ctrl.h:64.
EventEapTLSCertError as defined in wpactrl/wpa_ctrl.h:50.
EventFreqConflict as defined in wpactrl/wpa_ctrl.h:113.
EventNetworkNotFound as defined in wpactrl/wpa_ctrl.h:82.
EventPasswordChanged as defined in wpactrl/wpa_ctrl.h:36.
EventReenabled as defined in wpactrl/wpa_ctrl.h:68.
EventRegdomChange as defined in wpactrl/wpa_ctrl.h:88.
EventScanFailed as defined in wpactrl/wpa_ctrl.h:74.
EventScanResults as defined in wpactrl/wpa_ctrl.h:72.
EventScanStarted as defined in wpactrl/wpa_ctrl.h:70.
EventSignalChange as defined in wpactrl/wpa_ctrl.h:84.
EventStateChange as defined in wpactrl/wpa_ctrl.h:76.
EventSubnetStatusUpdate as defined in wpactrl/wpa_ctrl.h:103.
EventTempDisabled as defined in wpactrl/wpa_ctrl.h:66.
EventTerminating as defined in wpactrl/wpa_ctrl.h:34.
FilsHlpRx as defined in wpactrl/wpa_ctrl.h:336.
GasQueryDone as defined in wpactrl/wpa_ctrl.h:257.
GasQueryStart as defined in wpactrl/wpa_ctrl.h:255.
GasResponseInfo as defined in wpactrl/wpa_ctrl.h:253.
GlobalCtrlIfacePort as defined in wpactrl/wpa_ctrl.h:543.
GlobalCtrlIfacePortLimit as defined in wpactrl/wpa_ctrl.h:544.
Hs20DeauthImminentNotice as defined in wpactrl/wpa_ctrl.h:269.
Hs20SubscriptionRemediation as defined in wpactrl/wpa_ctrl.h:268.
IbssRsnCompleted as defined in wpactrl/wpa_ctrl.h:106.
InterfaceDisabled as defined in wpactrl/wpa_ctrl.h:297.
InterfaceEnabled as defined in wpactrl/wpa_ctrl.h:296.
InterworkingAlreadyConnected as defined in wpactrl/wpa_ctrl.h:243.
InterworkingAp as defined in wpactrl/wpa_ctrl.h:240.
InterworkingBlacklisted as defined in wpactrl/wpa_ctrl.h:241.
InterworkingNoMatch as defined in wpactrl/wpa_ctrl.h:242.
InterworkingSelected as defined in wpactrl/wpa_ctrl.h:244.
MboCellPreference as defined in wpactrl/wpa_ctrl.h:319.
MboTransitionReason as defined in wpactrl/wpa_ctrl.h:322.
MeshGroupRemoved as defined in wpactrl/wpa_ctrl.h:177.
MeshGroupStarted as defined in wpactrl/wpa_ctrl.h:176.
MeshPeerConnected as defined in wpactrl/wpa_ctrl.h:178.
MeshPeerDisconnected as defined in wpactrl/wpa_ctrl.h:179.
MeshSaeAuthBlocked as defined in wpactrl/wpa_ctrl.h:182.
MeshSaeAuthFailure as defined in wpactrl/wpa_ctrl.h:181.
P2pEventCrossConnectDisable as defined in wpactrl/wpa_ctrl.h:205.
P2pEventCrossConnectEnable as defined in wpactrl/wpa_ctrl.h:204.
P2pEventDeviceFound as defined in wpactrl/wpa_ctrl.h:190.
P2pEventDeviceLost as defined in wpactrl/wpa_ctrl.h:193.
P2pEventFallbackToGoNeg as defined in wpactrl/wpa_ctrl.h:230.
P2pEventFallbackToGoNegEnabled as defined in wpactrl/wpa_ctrl.h:231.
P2pEventFindStopped as defined in wpactrl/wpa_ctrl.h:224.
P2pEventGoNegFailure as defined in wpactrl/wpa_ctrl.h:199.
P2pEventGoNegRequest as defined in wpactrl/wpa_ctrl.h:197.
P2pEventGoNegSuccess as defined in wpactrl/wpa_ctrl.h:198.
P2pEventGroupFormationFailure as defined in wpactrl/wpa_ctrl.h:201.
P2pEventGroupFormationSuccess as defined in wpactrl/wpa_ctrl.h:200.
P2pEventGroupRemoved as defined in wpactrl/wpa_ctrl.h:203.
P2pEventGroupStarted as defined in wpactrl/wpa_ctrl.h:202.
P2pEventInvitationAccepted as defined in wpactrl/wpa_ctrl.h:223.
P2pEventInvitationReceived as defined in wpactrl/wpa_ctrl.h:221.
P2pEventInvitationResult as defined in wpactrl/wpa_ctrl.h:222.
P2pEventListenOffloadStop as defined in wpactrl/wpa_ctrl.h:312.
P2pEventNfcBothGo as defined in wpactrl/wpa_ctrl.h:227.
P2pEventNfcPeerClient as defined in wpactrl/wpa_ctrl.h:228.
P2pEventNfcWhileClient as defined in wpactrl/wpa_ctrl.h:229.
P2pEventP2psProvisionDone as defined in wpactrl/wpa_ctrl.h:238.
P2pEventP2psProvisionStart as defined in wpactrl/wpa_ctrl.h:237.
P2pEventPersistentPskFail as defined in wpactrl/wpa_ctrl.h:225.
P2pEventPresenceResponse as defined in wpactrl/wpa_ctrl.h:226.
P2pEventProvDiscEnterPin as defined in wpactrl/wpa_ctrl.h:209.
P2pEventProvDiscFailure as defined in wpactrl/wpa_ctrl.h:215.
P2pEventProvDiscPbcReq as defined in wpactrl/wpa_ctrl.h:211.
P2pEventProvDiscPbcResp as defined in wpactrl/wpa_ctrl.h:213.
P2pEventProvDiscShowPin as defined in wpactrl/wpa_ctrl.h:207.
P2pEventRemoveAndReformGroup as defined in wpactrl/wpa_ctrl.h:235.
P2pEventServAspResp as defined in wpactrl/wpa_ctrl.h:220.
P2pEventServDiscReq as defined in wpactrl/wpa_ctrl.h:217.
P2pEventServDiscResp as defined in wpactrl/wpa_ctrl.h:219.
P2pListenOffloadStopReason as defined in wpactrl/wpa_ctrl.h:313.
PmksaCacheAdded as defined in wpactrl/wpa_ctrl.h:330.
PmksaCacheRemoved as defined in wpactrl/wpa_ctrl.h:332.
RrmEventNeighborRepFailed as defined in wpactrl/wpa_ctrl.h:275.
RrmEventNeighborRepRxed as defined in wpactrl/wpa_ctrl.h:274.
RxAnqp as defined in wpactrl/wpa_ctrl.h:262.
RxHs20Anqp as defined in wpactrl/wpa_ctrl.h:263.
RxHs20AnqpIcon as defined in wpactrl/wpa_ctrl.h:264.
RxHs20Icon as defined in wpactrl/wpa_ctrl.h:265.
RxMboAnqp as defined in wpactrl/wpa_ctrl.h:266.
WpsEventActive as defined in wpactrl/wpa_ctrl.h:138.
WpsEventApAvailable as defined in wpactrl/wpa_ctrl.h:126.
WpsEventApAvailableAuth as defined in wpactrl/wpa_ctrl.h:121.
WpsEventApAvailablePbc as defined in wpactrl/wpa_ctrl.h:119.
WpsEventApAvailablePin as defined in wpactrl/wpa_ctrl.h:124.
WpsEventApPinDisabled as defined in wpactrl/wpa_ctrl.h:284.
WpsEventApPinEnabled as defined in wpactrl/wpa_ctrl.h:283.
WpsEventApSetupLocked as defined in wpactrl/wpa_ctrl.h:281.
WpsEventApSetupUnlocked as defined in wpactrl/wpa_ctrl.h:282.
WpsEventCredReceived as defined in wpactrl/wpa_ctrl.h:128.
WpsEventDisable as defined in wpactrl/wpa_ctrl.h:140.
WpsEventEnrolleeSeen as defined in wpactrl/wpa_ctrl.h:142.
WpsEventErApAdd as defined in wpactrl/wpa_ctrl.h:147.
WpsEventErApRemove as defined in wpactrl/wpa_ctrl.h:148.
WpsEventErApSettings as defined in wpactrl/wpa_ctrl.h:151.
WpsEventErEnrolleeAdd as defined in wpactrl/wpa_ctrl.h:149.
WpsEventErEnrolleeRemove as defined in wpactrl/wpa_ctrl.h:150.
WpsEventErSetSelReg as defined in wpactrl/wpa_ctrl.h:152.
WpsEventFail as defined in wpactrl/wpa_ctrl.h:132.
WpsEventM2d as defined in wpactrl/wpa_ctrl.h:130.
WpsEventNewApSettings as defined in wpactrl/wpa_ctrl.h:279.
WpsEventOpenNetwork as defined in wpactrl/wpa_ctrl.h:144.
WpsEventOverlap as defined in wpactrl/wpa_ctrl.h:117.
WpsEventPinNeeded as defined in wpactrl/wpa_ctrl.h:278.
WpsEventRegSuccess as defined in wpactrl/wpa_ctrl.h:280.
WpsEventSuccess as defined in wpactrl/wpa_ctrl.h:134.
WpsEventTimeout as defined in wpactrl/wpa_ctrl.h:136.

# Variables

ErrCmdTimeout is an error that happens when the command times out.
ErrScanFailed is an error that happens when scanning for wifi networks fails.
Interfaces is a shortcut to the best known method for gathering the wireless interfaces from the current system.

# Structs

AP represents an access point seen by the scan networks command.
Client represents a wireless client.
Conn represents a connection to a WPA supplicant control interface.
Event is an event that happens in the WPA supplicant.
Network represents a known network.
State represents the current status of WPA.
Subscription represents a subscription to one or events.

# Interfaces

No description provided by the author
Connector is interfce than can connect a network.