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
Expand ▾ Collapse ▴

Documentation

Overview

Package wireless provides a connection to WPA Supplicant and a client for ease of use

Index

Constants

const (
	CmdStatus               = "STATUS"
	CmdIfname               = "IFNAME"
	CmdPing                 = "PING"
	CmdRelog                = "RELOG"
	CmdNote                 = "NOTE"
	CmdMib                  = "MIB"
	CmdHelp                 = "HELP"
	CmdInterface            = "INTERFACE"
	CmdLevel                = "LEVEL"
	CmdLicense              = "LICENSE"
	CmdQuit                 = "QUIT"
	CmdSet                  = "SET"
	CmdDump                 = "DUMP"
	CmdGet                  = "GET"
	CmdDriverFlags          = "DRIVER_FLAGS"
	CmdLogon                = "LOGON"
	CmdLogoff               = "LOGOFF"
	CmdPmksa                = "PMKSA"
	CmdPmksaFlush           = "PMKSA_FLUSH"
	CmdReassociate          = "REASSOCIATE"
	CmdReattach             = "REATTACH"
	CmdPreauthenticate      = "PREAUTHENTICATE"
	CmdIdentity             = "IDENTITY"
	CmdPassword             = "PASSWORD"
	CmdNewPassword          = "NEW_PASSWORD"
	CmdPin                  = "PIN"
	CmdOtp                  = "OTP"
	CmdPassphrase           = "PASSPHRASE"
	CmdSim                  = "SIM"
	CmdBssid                = "BSSID"
	CmdBlacklist            = "BLACKLIST"
	CmdLogLevel             = "LOG_LEVEL"
	CmdListNetworks         = "LIST_NETWORKS"
	CmdSelectNetwork        = "SELECT_NETWORK"
	CmdEnableNetwork        = "ENABLE_NETWORK"
	CmdDisableNetwork       = "DISABLE_NETWORK"
	CmdAddNetwork           = "ADD_NETWORK"
	CmdRemoveNetwork        = "REMOVE_NETWORK"
	CmdSetNetwork           = "SET_NETWORK"
	CmdGetNetwork           = "GET_NETWORK"
	CmdDupNetwork           = "DUP_NETWORK"
	CmdListCreds            = "LIST_CREDS"
	CmdAddCred              = "ADD_CRED"
	CmdRemoveCred           = "REMOVE_CRED"
	CmdSetCred              = "SET_CRED"
	CmdGetCred              = "GET_CRED"
	CmdSaveConfig           = "SAVE_CONFIG"
	CmdDisconnect           = "DISCONNECT"
	CmdReconnect            = "RECONNECT"
	CmdScan                 = "SCAN"
	CmdScanResults          = "SCAN_RESULTS"
	CmdAbortScan            = "ABORT_SCAN"
	CmdBss                  = "BSS"
	CmdGetCapability        = "GET_CAPABILITY"
	CmdReconfigure          = "RECONFIGURE"
	CmdTerminate            = "TERMINATE"
	CmdInterfaceAdd         = "InterfaceAdd"
	CmdInterfaceRemove      = "INTERFACE_REMOVE"
	CmdInterfaceList        = "INTERFACE_LIST"
	CmdApScan               = "AP_SCAN"
	CmdScanInterval         = "SCAN_INTERVAL"
	CmdBssExpireAge         = "BSS_EXPIRE_AGE"
	CmdBssExpireCount       = "BSS_EXPIRE_COUNT"
	CmdBssFlush             = "BSS_FLUSH"
	CmdStkstart             = "STKSTART"
	CmdFtDs                 = "FT_DS"
	CmdWpsPbc               = "WPS_PBC"
	CmdWpsPin               = "WPS_PIN"
	CmdWpsCheckPin          = "WPS_CHECK_PIN"
	CmdWpsReg               = "WPS_REG"
	CmdWpsApPin             = "WPS_AP_PIN"
	CmdWpsErStart           = "WPS_ER_START"
	CmdWpsErStop            = "WPS_ER_STOP"
	CmdWpsErPin             = "WPS_ER_PIN"
	CmdWpsErPbc             = "WPS_ER_PBC"
	CmdWpsErLearn           = "WPS_ER_LEARN"
	CmdWpsErSetConfig       = "WPS_ER_SET_CONFIG"
	CmdWpsErConfig          = "WPS_ER_CONFIG"
	CmdIbssRsn              = "IBSS_RSN"
	CmdSta                  = "STA"
	CmdAllSta               = "ALL_STA"
	CmdDeauthenticate       = "DEAUTHENTICATE"
	CmdDisassociate         = "DISASSOCIATE"
	CmdChanSwitch           = "CHAN_SWITCH"
	CmdSuspend              = "SUSPEND"
	CmdResume               = "RESUME"
	CmdRoam                 = "ROAM"
	CmdP2pFind              = "P2P_FIND"
	CmdP2pStopFind          = "P2P_STOP_FIND"
	CmdP2pAspProvision      = "P2P_ASP_PROVISION"
	CmdP2pAspProvisionResp  = "P2P_ASP_PROVISION_RESP"
	CmdP2pConnect           = "P2P_CONNECT"
	CmdP2pListen            = "P2P_LISTEN"
	CmdP2pGroupRemove       = "P2P_GROUP_REMOVE"
	CmdP2pGroupAdd          = "P2P_GROUP_ADD"
	CmdP2pGroupMember       = "P2P_GROUP_MEMBER"
	CmdP2pProvDisc          = "P2P_PROV_DISC"
	CmdP2pGetPassphrase     = "P2P_GET_PASSPHRASE"
	CmdP2pServDiscReq       = "P2P_SERV_DISC_REQ"
	CmdP2pServDiscCancelReq = "P2P_SERV_DISC_CANCEL_REQ"
	CmdP2pServDiscResp      = "P2P_SERV_DISC_RESP"
	CmdP2pServiceUpdate     = "P2P_SERVICE_UPDATE"
	CmdP2pServDiscExternal  = "P2P_SERV_DISC_EXTERNAL"
	CmdP2pServiceFlush      = "P2P_SERVICE_FLUSH"
	CmdP2pServiceAdd        = "P2P_SERVICE_ADD"
	CmdP2pServiceRep        = "P2P_SERVICE_REP"
	CmdP2pServiceDel        = "P2P_SERVICE_DEL"
	CmdP2pReject            = "P2P_REJECT"
	CmdP2pInvite            = "P2P_INVITE"
	CmdP2pPeers             = "P2P_PEERS"
	CmdP2pPeer              = "P2P_PEER"
	CmdP2pSet               = "P2P_SET"
	CmdP2pFlush             = "P2P_FLUSH"
	CmdP2pCancel            = "P2P_CANCEL"
	CmdP2pUnauthorize       = "P2P_UNAUTHORIZE"
	CmdP2pPresenceReq       = "P2P_PRESENCE_REQ"
	CmdP2pExtListen         = "P2P_EXT_LISTEN"
	CmdP2pRemoveClient      = "P2P_REMOVE_CLIENT"
	CmdVendorElemAdd        = "VENDOR_ELEM_ADD"
	CmdVendorElemGet        = "VENDOR_ELEM_GET"
	CmdVendorElemRemove     = "VENDOR_ELEM_REMOVE"
	CmdStaAutoconnect       = "STA_AUTOCONNECT"
	CmdTdlsDiscover         = "TDLS_DISCOVER"
	CmdTdlsSetup            = "TDLS_SETUP"
	CmdTdlsTeardown         = "TDLS_TEARDOWN"
	CmdTdlsLinkStatus       = "TDLS_LINK_STATUS"
	CmdWmmAcAddts           = "WMM_AC_ADDTS"
	CmdWmmAcDelts           = "WMM_AC_DELTS"
	CmdWmmAcStatus          = "WMM_AC_STATUS"
	CmdTdlsChanSwitch       = "TDLS_CHAN_SWITCH"
	CmdTdlsCancelChanSwitch = "TDLS_CANCEL_CHAN_SWITCH"
	CmdSignalPoll           = "SIGNAL_POLL"
	CmdSignalMonitor        = "SIGNAL_MONITOR"
	CmdPktcntPoll           = "PKTCNT_POLL"
	CmdReauthenticate       = "REAUTHENTICATE"
	CmdRaw                  = "RAW"
	CmdFlush                = "FLUSH"
	CmdRadioWork            = "RADIO_WORK"
	CmdVendor               = "VENDOR"
	CmdNeighborRepRequest   = "NEIGHBOR_REP_REQUEST"
	CmdErpFlush             = "ERP_FLUSH"
	CmdMacRandScan          = "MAC_RAND_SCAN"
	CmdGetPrefFreqList      = "GET_PREF_FREQ_LIST"
	CmdP2pLoStart           = "P2P_LO_START"
	CmdP2pLoStop            = "P2P_LO_STOP"
)

const (
	// CtrlReq as defined in wpactrl/wpa_ctrl.h:19
	CtrlReq = "CTRL-REQ-"
	// CtrlRsp as defined in wpactrl/wpa_ctrl.h:22
	CtrlRsp = "CTRL-RSP-"
	// EventConnected as defined in wpactrl/wpa_ctrl.h:26
	EventConnected = "CTRL-EVENT-CONNECTED "
	// EventDisconnected as defined in wpactrl/wpa_ctrl.h:28
	EventDisconnected = "CTRL-EVENT-DISCONNECTED "
	// EventAssocReject as defined in wpactrl/wpa_ctrl.h:30
	EventAssocReject = "CTRL-EVENT-ASSOC-REJECT "
	// EventAuthReject as defined in wpactrl/wpa_ctrl.h:32
	EventAuthReject = "CTRL-EVENT-AUTH-REJECT "
	// EventTerminating as defined in wpactrl/wpa_ctrl.h:34
	EventTerminating = "CTRL-EVENT-TERMINATING "
	// EventPasswordChanged as defined in wpactrl/wpa_ctrl.h:36
	EventPasswordChanged = "CTRL-EVENT-PASSWORD-CHANGED "
	// EventEapNotification as defined in wpactrl/wpa_ctrl.h:38
	EventEapNotification = "CTRL-EVENT-EAP-NOTIFICATION "
	// EventEapStarted as defined in wpactrl/wpa_ctrl.h:40
	EventEapStarted = "CTRL-EVENT-EAP-STARTED "
	// EventEapProposedMethod as defined in wpactrl/wpa_ctrl.h:42
	EventEapProposedMethod = "CTRL-EVENT-EAP-PROPOSED-METHOD "
	// EventEapMethod as defined in wpactrl/wpa_ctrl.h:44
	EventEapMethod = "CTRL-EVENT-EAP-METHOD "
	// EventEapPeerCert as defined in wpactrl/wpa_ctrl.h:46
	EventEapPeerCert = "CTRL-EVENT-EAP-PEER-CERT "
	// EventEapPeerAlt as defined in wpactrl/wpa_ctrl.h:48
	EventEapPeerAlt = "CTRL-EVENT-EAP-PEER-ALT "
	// EventEapTLSCertError as defined in wpactrl/wpa_ctrl.h:50
	EventEapTLSCertError = "CTRL-EVENT-EAP-TLS-CERT-ERROR "
	// EventEapStatus as defined in wpactrl/wpa_ctrl.h:52
	EventEapStatus = "CTRL-EVENT-EAP-STATUS "
	// EventEapRetransmit as defined in wpactrl/wpa_ctrl.h:54
	EventEapRetransmit = "CTRL-EVENT-EAP-RETRANSMIT "
	// EventEapRetransmit2 as defined in wpactrl/wpa_ctrl.h:55
	EventEapRetransmit2 = "CTRL-EVENT-EAP-RETRANSMIT2 "
	// EventEapSuccess as defined in wpactrl/wpa_ctrl.h:57
	EventEapSuccess = "CTRL-EVENT-EAP-SUCCESS "
	// EventEapSuccess2 as defined in wpactrl/wpa_ctrl.h:58
	EventEapSuccess2 = "CTRL-EVENT-EAP-SUCCESS2 "
	// EventEapFailure as defined in wpactrl/wpa_ctrl.h:60
	EventEapFailure = "CTRL-EVENT-EAP-FAILURE "
	// EventEapFailure2 as defined in wpactrl/wpa_ctrl.h:61
	EventEapFailure2 = "CTRL-EVENT-EAP-FAILURE2 "
	// EventEapTimeoutFailure as defined in wpactrl/wpa_ctrl.h:63
	EventEapTimeoutFailure = "CTRL-EVENT-EAP-TIMEOUT-FAILURE "
	// EventEapTimeoutFailure2 as defined in wpactrl/wpa_ctrl.h:64
	EventEapTimeoutFailure2 = "CTRL-EVENT-EAP-TIMEOUT-FAILURE2 "
	// EventTempDisabled as defined in wpactrl/wpa_ctrl.h:66
	EventTempDisabled = "CTRL-EVENT-SSID-TEMP-DISABLED "
	// EventReenabled as defined in wpactrl/wpa_ctrl.h:68
	EventReenabled = "CTRL-EVENT-SSID-REENABLED "
	// EventScanStarted as defined in wpactrl/wpa_ctrl.h:70
	EventScanStarted = "CTRL-EVENT-SCAN-STARTED "
	// EventScanResults as defined in wpactrl/wpa_ctrl.h:72
	EventScanResults = "CTRL-EVENT-SCAN-RESULTS "
	// EventScanFailed as defined in wpactrl/wpa_ctrl.h:74
	EventScanFailed = "CTRL-EVENT-SCAN-FAILED "
	// EventStateChange as defined in wpactrl/wpa_ctrl.h:76
	EventStateChange = "CTRL-EVENT-STATE-CHANGE "
	// EventBssAdded as defined in wpactrl/wpa_ctrl.h:78
	EventBssAdded = "CTRL-EVENT-BSS-ADDED "
	// EventBssRemoved as defined in wpactrl/wpa_ctrl.h:80
	EventBssRemoved = "CTRL-EVENT-BSS-REMOVED "
	// EventNetworkNotFound as defined in wpactrl/wpa_ctrl.h:82
	EventNetworkNotFound = "CTRL-EVENT-NETWORK-NOT-FOUND "
	// EventSignalChange as defined in wpactrl/wpa_ctrl.h:84
	EventSignalChange = "CTRL-EVENT-SIGNAL-CHANGE "
	// EventBeaconLoss as defined in wpactrl/wpa_ctrl.h:86
	EventBeaconLoss = "CTRL-EVENT-BEACON-LOSS "
	// EventRegdomChange as defined in wpactrl/wpa_ctrl.h:88
	EventRegdomChange = "CTRL-EVENT-REGDOM-CHANGE "
	// EventChannelSwitch as defined in wpactrl/wpa_ctrl.h:90
	EventChannelSwitch = "CTRL-EVENT-CHANNEL-SWITCH "
	// EventSubnetStatusUpdate as defined in wpactrl/wpa_ctrl.h:103
	EventSubnetStatusUpdate = "CTRL-EVENT-SUBNET-STATUS-UPDATE "
	// IbssRsnCompleted as defined in wpactrl/wpa_ctrl.h:106
	IbssRsnCompleted = "IBSS-RSN-COMPLETED "
	// EventFreqConflict as defined in wpactrl/wpa_ctrl.h:113
	EventFreqConflict = "CTRL-EVENT-FREQ-CONFLICT "
	// EventAvoidFreq as defined in wpactrl/wpa_ctrl.h:115
	EventAvoidFreq = "CTRL-EVENT-AVOID-FREQ "
	// WpsEventOverlap as defined in wpactrl/wpa_ctrl.h:117
	WpsEventOverlap = "WPS-OVERLAP-DETECTED "
	// WpsEventApAvailablePbc as defined in wpactrl/wpa_ctrl.h:119
	WpsEventApAvailablePbc = "WPS-AP-AVAILABLE-PBC "
	// WpsEventApAvailableAuth as defined in wpactrl/wpa_ctrl.h:121
	WpsEventApAvailableAuth = "WPS-AP-AVAILABLE-AUTH "
	// WpsEventApAvailablePin as defined in wpactrl/wpa_ctrl.h:124
	WpsEventApAvailablePin = "WPS-AP-AVAILABLE-PIN "
	// WpsEventApAvailable as defined in wpactrl/wpa_ctrl.h:126
	WpsEventApAvailable = "WPS-AP-AVAILABLE "
	// WpsEventCredReceived as defined in wpactrl/wpa_ctrl.h:128
	WpsEventCredReceived = "WPS-CRED-RECEIVED "
	// WpsEventM2d as defined in wpactrl/wpa_ctrl.h:130
	WpsEventM2d = "WPS-M2D "
	// WpsEventFail as defined in wpactrl/wpa_ctrl.h:132
	WpsEventFail = "WPS-FAIL "
	// WpsEventSuccess as defined in wpactrl/wpa_ctrl.h:134
	WpsEventSuccess = "WPS-SUCCESS "
	// WpsEventTimeout as defined in wpactrl/wpa_ctrl.h:136
	WpsEventTimeout = "WPS-TIMEOUT "
	// WpsEventActive as defined in wpactrl/wpa_ctrl.h:138
	WpsEventActive = "WPS-PBC-ACTIVE "
	// WpsEventDisable as defined in wpactrl/wpa_ctrl.h:140
	WpsEventDisable = "WPS-PBC-DISABLE "
	// WpsEventEnrolleeSeen as defined in wpactrl/wpa_ctrl.h:142
	WpsEventEnrolleeSeen = "WPS-ENROLLEE-SEEN "
	// WpsEventOpenNetwork as defined in wpactrl/wpa_ctrl.h:144
	WpsEventOpenNetwork = "WPS-OPEN-NETWORK "
	// WpsEventErApAdd as defined in wpactrl/wpa_ctrl.h:147
	WpsEventErApAdd = "WPS-ER-AP-ADD "
	// WpsEventErApRemove as defined in wpactrl/wpa_ctrl.h:148
	WpsEventErApRemove = "WPS-ER-AP-REMOVE "
	// WpsEventErEnrolleeAdd as defined in wpactrl/wpa_ctrl.h:149
	WpsEventErEnrolleeAdd = "WPS-ER-ENROLLEE-ADD "
	// WpsEventErEnrolleeRemove as defined in wpactrl/wpa_ctrl.h:150
	WpsEventErEnrolleeRemove = "WPS-ER-ENROLLEE-REMOVE "
	// WpsEventErApSettings as defined in wpactrl/wpa_ctrl.h:151
	WpsEventErApSettings = "WPS-ER-AP-SETTINGS "
	// WpsEventErSetSelReg as defined in wpactrl/wpa_ctrl.h:152
	WpsEventErSetSelReg = "WPS-ER-AP-SET-SEL-REG "
	// DppEventAuthSuccess as defined in wpactrl/wpa_ctrl.h:155
	DppEventAuthSuccess = "DPP-AUTH-SUCCESS "
	// DppEventNotCompatible as defined in wpactrl/wpa_ctrl.h:156
	DppEventNotCompatible = "DPP-NOT-COMPATIBLE "
	// DppEventResponsePending as defined in wpactrl/wpa_ctrl.h:157
	DppEventResponsePending = "DPP-RESPONSE-PENDING "
	// DppEventScanPeerQrCode as defined in wpactrl/wpa_ctrl.h:158
	DppEventScanPeerQrCode = "DPP-SCAN-PEER-QR-CODE "
	// DppEventConfReceived as defined in wpactrl/wpa_ctrl.h:159
	DppEventConfReceived = "DPP-CONF-RECEIVED "
	// DppEventConfSent as defined in wpactrl/wpa_ctrl.h:160
	DppEventConfSent = "DPP-CONF-SENT "
	// DppEventConfFailed as defined in wpactrl/wpa_ctrl.h:161
	DppEventConfFailed = "DPP-CONF-FAILED "
	// DppEventConfobjSsid as defined in wpactrl/wpa_ctrl.h:162
	DppEventConfobjSsid = "DPP-CONFOBJ-SSID "
	// DppEventConfobjPass as defined in wpactrl/wpa_ctrl.h:163
	DppEventConfobjPass = "DPP-CONFOBJ-PASS "
	// DppEventConfobjPsk as defined in wpactrl/wpa_ctrl.h:164
	DppEventConfobjPsk = "DPP-CONFOBJ-PSK "
	// DppEventConnector as defined in wpactrl/wpa_ctrl.h:165
	DppEventConnector = "DPP-CONNECTOR "
	// DppEventCSignKey as defined in wpactrl/wpa_ctrl.h:166
	DppEventCSignKey = "DPP-C-SIGN-KEY "
	// DppEventNetAccessKey as defined in wpactrl/wpa_ctrl.h:167
	DppEventNetAccessKey = "DPP-NET-ACCESS-KEY "
	// DppEventMissingConnector as defined in wpactrl/wpa_ctrl.h:168
	DppEventMissingConnector = "DPP-MISSING-CONNECTOR "
	// DppEventNetworkID as defined in wpactrl/wpa_ctrl.h:169
	DppEventNetworkID = "DPP-NETWORK-ID "
	// DppEventRx as defined in wpactrl/wpa_ctrl.h:170
	DppEventRx = "DPP-RX "
	// DppEventTx as defined in wpactrl/wpa_ctrl.h:171
	DppEventTx = "DPP-TX "
	// DppEventTxStatus as defined in wpactrl/wpa_ctrl.h:172
	DppEventTxStatus = "DPP-TX-STATUS "
	// DppEventFail as defined in wpactrl/wpa_ctrl.h:173
	DppEventFail = "DPP-FAIL "
	// MeshGroupStarted as defined in wpactrl/wpa_ctrl.h:176
	MeshGroupStarted = "MESH-GROUP-STARTED "
	// MeshGroupRemoved as defined in wpactrl/wpa_ctrl.h:177
	MeshGroupRemoved = "MESH-GROUP-REMOVED "
	// MeshPeerConnected as defined in wpactrl/wpa_ctrl.h:178
	MeshPeerConnected = "MESH-PEER-CONNECTED "
	// MeshPeerDisconnected as defined in wpactrl/wpa_ctrl.h:179
	MeshPeerDisconnected = "MESH-PEER-DISCONNECTED "
	// MeshSaeAuthFailure as defined in wpactrl/wpa_ctrl.h:181
	MeshSaeAuthFailure = "MESH-SAE-AUTH-FAILURE "
	// MeshSaeAuthBlocked as defined in wpactrl/wpa_ctrl.h:182
	MeshSaeAuthBlocked = "MESH-SAE-AUTH-BLOCKED "
	// P2pEventDeviceFound as defined in wpactrl/wpa_ctrl.h:190
	P2pEventDeviceFound = "P2P-DEVICE-FOUND "
	// P2pEventDeviceLost as defined in wpactrl/wpa_ctrl.h:193
	P2pEventDeviceLost = "P2P-DEVICE-LOST "
	// P2pEventGoNegRequest as defined in wpactrl/wpa_ctrl.h:197
	P2pEventGoNegRequest = "P2P-GO-NEG-REQUEST "
	// P2pEventGoNegSuccess as defined in wpactrl/wpa_ctrl.h:198
	P2pEventGoNegSuccess = "P2P-GO-NEG-SUCCESS "
	// P2pEventGoNegFailure as defined in wpactrl/wpa_ctrl.h:199
	P2pEventGoNegFailure = "P2P-GO-NEG-FAILURE "
	// P2pEventGroupFormationSuccess as defined in wpactrl/wpa_ctrl.h:200
	P2pEventGroupFormationSuccess = "P2P-GROUP-FORMATION-SUCCESS "
	// P2pEventGroupFormationFailure as defined in wpactrl/wpa_ctrl.h:201
	P2pEventGroupFormationFailure = "P2P-GROUP-FORMATION-FAILURE "
	// P2pEventGroupStarted as defined in wpactrl/wpa_ctrl.h:202
	P2pEventGroupStarted = "P2P-GROUP-STARTED "
	// P2pEventGroupRemoved as defined in wpactrl/wpa_ctrl.h:203
	P2pEventGroupRemoved = "P2P-GROUP-REMOVED "
	// P2pEventCrossConnectEnable as defined in wpactrl/wpa_ctrl.h:204
	P2pEventCrossConnectEnable = "P2P-CROSS-CONNECT-ENABLE "
	// P2pEventCrossConnectDisable as defined in wpactrl/wpa_ctrl.h:205
	P2pEventCrossConnectDisable = "P2P-CROSS-CONNECT-DISABLE "
	// P2pEventProvDiscShowPin as defined in wpactrl/wpa_ctrl.h:207
	P2pEventProvDiscShowPin = "P2P-PROV-DISC-SHOW-PIN "
	// P2pEventProvDiscEnterPin as defined in wpactrl/wpa_ctrl.h:209
	P2pEventProvDiscEnterPin = "P2P-PROV-DISC-ENTER-PIN "
	// P2pEventProvDiscPbcReq as defined in wpactrl/wpa_ctrl.h:211
	P2pEventProvDiscPbcReq = "P2P-PROV-DISC-PBC-REQ "
	// P2pEventProvDiscPbcResp as defined in wpactrl/wpa_ctrl.h:213
	P2pEventProvDiscPbcResp = "P2P-PROV-DISC-PBC-RESP "
	// P2pEventProvDiscFailure as defined in wpactrl/wpa_ctrl.h:215
	P2pEventProvDiscFailure = "P2P-PROV-DISC-FAILURE"
	// P2pEventServDiscReq as defined in wpactrl/wpa_ctrl.h:217
	P2pEventServDiscReq = "P2P-SERV-DISC-REQ "
	// P2pEventServDiscResp as defined in wpactrl/wpa_ctrl.h:219
	P2pEventServDiscResp = "P2P-SERV-DISC-RESP "
	// P2pEventServAspResp as defined in wpactrl/wpa_ctrl.h:220
	P2pEventServAspResp = "P2P-SERV-ASP-RESP "
	// P2pEventInvitationReceived as defined in wpactrl/wpa_ctrl.h:221
	P2pEventInvitationReceived = "P2P-INVITATION-RECEIVED "
	// P2pEventInvitationResult as defined in wpactrl/wpa_ctrl.h:222
	P2pEventInvitationResult = "P2P-INVITATION-RESULT "
	// P2pEventInvitationAccepted as defined in wpactrl/wpa_ctrl.h:223
	P2pEventInvitationAccepted = "P2P-INVITATION-ACCEPTED "
	// P2pEventFindStopped as defined in wpactrl/wpa_ctrl.h:224
	P2pEventFindStopped = "P2P-FIND-STOPPED "
	// P2pEventPersistentPskFail as defined in wpactrl/wpa_ctrl.h:225
	P2pEventPersistentPskFail = "P2P-PERSISTENT-PSK-FAIL id="
	// P2pEventPresenceResponse as defined in wpactrl/wpa_ctrl.h:226
	P2pEventPresenceResponse = "P2P-PRESENCE-RESPONSE "
	// P2pEventNfcBothGo as defined in wpactrl/wpa_ctrl.h:227
	P2pEventNfcBothGo = "P2P-NFC-BOTH-GO "
	// P2pEventNfcPeerClient as defined in wpactrl/wpa_ctrl.h:228
	P2pEventNfcPeerClient = "P2P-NFC-PEER-CLIENT "
	// P2pEventNfcWhileClient as defined in wpactrl/wpa_ctrl.h:229
	P2pEventNfcWhileClient = "P2P-NFC-WHILE-CLIENT "
	// P2pEventFallbackToGoNeg as defined in wpactrl/wpa_ctrl.h:230
	P2pEventFallbackToGoNeg = "P2P-FALLBACK-TO-GO-NEG "
	// P2pEventFallbackToGoNegEnabled as defined in wpactrl/wpa_ctrl.h:231
	P2pEventFallbackToGoNegEnabled = "P2P-FALLBACK-TO-GO-NEG-ENABLED "
	// EssDisassocImminent as defined in wpactrl/wpa_ctrl.h:234
	EssDisassocImminent = "ESS-DISASSOC-IMMINENT "
	// P2pEventRemoveAndReformGroup as defined in wpactrl/wpa_ctrl.h:235
	P2pEventRemoveAndReformGroup = "P2P-REMOVE-AND-REFORM-GROUP "
	// P2pEventP2psProvisionStart as defined in wpactrl/wpa_ctrl.h:237
	P2pEventP2psProvisionStart = "P2PS-PROV-START "
	// P2pEventP2psProvisionDone as defined in wpactrl/wpa_ctrl.h:238
	P2pEventP2psProvisionDone = "P2PS-PROV-DONE "
	// InterworkingAp as defined in wpactrl/wpa_ctrl.h:240
	InterworkingAp = "INTERWORKING-AP "
	// InterworkingBlacklisted as defined in wpactrl/wpa_ctrl.h:241
	InterworkingBlacklisted = "INTERWORKING-BLACKLISTED "
	// InterworkingNoMatch as defined in wpactrl/wpa_ctrl.h:242
	InterworkingNoMatch = "INTERWORKING-NO-MATCH "
	// InterworkingAlreadyConnected as defined in wpactrl/wpa_ctrl.h:243
	InterworkingAlreadyConnected = "INTERWORKING-ALREADY-CONNECTED "
	// InterworkingSelected as defined in wpactrl/wpa_ctrl.h:244
	InterworkingSelected = "INTERWORKING-SELECTED "
	// CredAdded as defined in wpactrl/wpa_ctrl.h:247
	CredAdded = "CRED-ADDED "
	// CredModified as defined in wpactrl/wpa_ctrl.h:249
	CredModified = "CRED-MODIFIED "
	// CredRemoved as defined in wpactrl/wpa_ctrl.h:251
	CredRemoved = "CRED-REMOVED "
	// GasResponseInfo as defined in wpactrl/wpa_ctrl.h:253
	GasResponseInfo = "GAS-RESPONSE-INFO "
	// GasQueryStart as defined in wpactrl/wpa_ctrl.h:255
	GasQueryStart = "GAS-QUERY-START "
	// GasQueryDone as defined in wpactrl/wpa_ctrl.h:257
	GasQueryDone = "GAS-QUERY-DONE "
	// RxAnqp as defined in wpactrl/wpa_ctrl.h:262
	RxAnqp = "RX-ANQP "
	// RxHs20Anqp as defined in wpactrl/wpa_ctrl.h:263
	RxHs20Anqp = "RX-HS20-ANQP "
	// RxHs20AnqpIcon as defined in wpactrl/wpa_ctrl.h:264
	RxHs20AnqpIcon = "RX-HS20-ANQP-ICON "
	// RxHs20Icon as defined in wpactrl/wpa_ctrl.h:265
	RxHs20Icon = "RX-HS20-ICON "
	// RxMboAnqp as defined in wpactrl/wpa_ctrl.h:266
	RxMboAnqp = "RX-MBO-ANQP "
	// Hs20SubscriptionRemediation as defined in wpactrl/wpa_ctrl.h:268
	Hs20SubscriptionRemediation = "HS20-SUBSCRIPTION-REMEDIATION "
	// Hs20DeauthImminentNotice as defined in wpactrl/wpa_ctrl.h:269
	Hs20DeauthImminentNotice = "HS20-DEAUTH-IMMINENT-NOTICE "
	// RrmEventNeighborRepRxed as defined in wpactrl/wpa_ctrl.h:274
	RrmEventNeighborRepRxed = "RRM-NEIGHBOR-REP-RECEIVED "
	// RrmEventNeighborRepFailed as defined in wpactrl/wpa_ctrl.h:275
	RrmEventNeighborRepFailed = "RRM-NEIGHBOR-REP-REQUEST-FAILED "
	// WpsEventPinNeeded as defined in wpactrl/wpa_ctrl.h:278
	WpsEventPinNeeded = "WPS-PIN-NEEDED "
	// WpsEventNewApSettings as defined in wpactrl/wpa_ctrl.h:279
	WpsEventNewApSettings = "WPS-NEW-AP-SETTINGS "
	// WpsEventRegSuccess as defined in wpactrl/wpa_ctrl.h:280
	WpsEventRegSuccess = "WPS-REG-SUCCESS "
	// WpsEventApSetupLocked as defined in wpactrl/wpa_ctrl.h:281
	WpsEventApSetupLocked = "WPS-AP-SETUP-LOCKED "
	// WpsEventApSetupUnlocked as defined in wpactrl/wpa_ctrl.h:282
	WpsEventApSetupUnlocked = "WPS-AP-SETUP-UNLOCKED "
	// WpsEventApPinEnabled as defined in wpactrl/wpa_ctrl.h:283
	WpsEventApPinEnabled = "WPS-AP-PIN-ENABLED "
	// WpsEventApPinDisabled as defined in wpactrl/wpa_ctrl.h:284
	WpsEventApPinDisabled = "WPS-AP-PIN-DISABLED "
	// ApStaConnected as defined in wpactrl/wpa_ctrl.h:285
	ApStaConnected = "AP-STA-CONNECTED "
	// ApStaDisconnected as defined in wpactrl/wpa_ctrl.h:286
	ApStaDisconnected = "AP-STA-DISCONNECTED "
	// ApStaPossiblePskMismatch as defined in wpactrl/wpa_ctrl.h:287
	ApStaPossiblePskMismatch = "AP-STA-POSSIBLE-PSK-MISMATCH "
	// ApStaPollOk as defined in wpactrl/wpa_ctrl.h:288
	ApStaPollOk = "AP-STA-POLL-OK "
	// ApRejectedMaxSta as defined in wpactrl/wpa_ctrl.h:290
	ApRejectedMaxSta = "AP-REJECTED-MAX-STA "
	// ApRejectedBlockedSta as defined in wpactrl/wpa_ctrl.h:291
	ApRejectedBlockedSta = "AP-REJECTED-BLOCKED-STA "
	// ApEventEnabled as defined in wpactrl/wpa_ctrl.h:293
	ApEventEnabled = "AP-ENABLED "
	// ApEventDisabled as defined in wpactrl/wpa_ctrl.h:294
	ApEventDisabled = "AP-DISABLED "
	// InterfaceEnabled as defined in wpactrl/wpa_ctrl.h:296
	InterfaceEnabled = "INTERFACE-ENABLED "
	// InterfaceDisabled as defined in wpactrl/wpa_ctrl.h:297
	InterfaceDisabled = "INTERFACE-DISABLED "
	// AcsEventStarted as defined in wpactrl/wpa_ctrl.h:299
	AcsEventStarted = "ACS-STARTED "
	// AcsEventCompleted as defined in wpactrl/wpa_ctrl.h:300
	AcsEventCompleted = "ACS-COMPLETED "
	// AcsEventFailed as defined in wpactrl/wpa_ctrl.h:301
	AcsEventFailed = "ACS-FAILED "
	// DfsEventRadarDetected as defined in wpactrl/wpa_ctrl.h:303
	DfsEventRadarDetected = "DFS-RADAR-DETECTED "
	// DfsEventNewChannel as defined in wpactrl/wpa_ctrl.h:304
	DfsEventNewChannel = "DFS-NEW-CHANNEL "
	// DfsEventCacStart as defined in wpactrl/wpa_ctrl.h:305
	DfsEventCacStart = "DFS-CAC-START "
	// DfsEventCacCompleted as defined in wpactrl/wpa_ctrl.h:306
	DfsEventCacCompleted = "DFS-CAC-COMPLETED "
	// DfsEventNopFinished as defined in wpactrl/wpa_ctrl.h:307
	DfsEventNopFinished = "DFS-NOP-FINISHED "
	// DfsEventPreCacExpired as defined in wpactrl/wpa_ctrl.h:308
	DfsEventPreCacExpired = "DFS-PRE-CAC-EXPIRED "
	// ApCsaFinished as defined in wpactrl/wpa_ctrl.h:310
	ApCsaFinished = "AP-CSA-FINISHED "
	// P2pEventListenOffloadStop as defined in wpactrl/wpa_ctrl.h:312
	P2pEventListenOffloadStop = "P2P-LISTEN-OFFLOAD-STOPPED "
	// P2pListenOffloadStopReason as defined in wpactrl/wpa_ctrl.h:313
	P2pListenOffloadStopReason = "P2P-LISTEN-OFFLOAD-STOP-REASON "
	// BssTmResp as defined in wpactrl/wpa_ctrl.h:316
	BssTmResp = "BSS-TM-RESP "
	// MboCellPreference as defined in wpactrl/wpa_ctrl.h:319
	MboCellPreference = "MBO-CELL-PREFERENCE "
	// MboTransitionReason as defined in wpactrl/wpa_ctrl.h:322
	MboTransitionReason = "MBO-TRANSITION-REASON "
	// PmksaCacheAdded as defined in wpactrl/wpa_ctrl.h:330
	PmksaCacheAdded = "PMKSA-CACHE-ADDED "
	// PmksaCacheRemoved as defined in wpactrl/wpa_ctrl.h:332
	PmksaCacheRemoved = "PMKSA-CACHE-REMOVED "
	// FilsHlpRx as defined in wpactrl/wpa_ctrl.h:336
	FilsHlpRx = "FILS-HLP-RX "
	// BssMaskAll as defined in wpactrl/wpa_ctrl.h:340
	BssMaskAll = 0xFFFDFFFF
	// CtrlIfacePort as defined in wpactrl/wpa_ctrl.h:541
	CtrlIfacePort = 9877
	// CtrlIfacePortLimit as defined in wpactrl/wpa_ctrl.h:542
	CtrlIfacePortLimit = 50
	// GlobalCtrlIfacePort as defined in wpactrl/wpa_ctrl.h:543
	GlobalCtrlIfacePort = 9878
	// GlobalCtrlIfacePortLimit as defined in wpactrl/wpa_ctrl.h:544
	GlobalCtrlIfacePortLimit = 20
)

Variables

var (

	// ErrCmdTimeout is an error that happens when the command times out
	ErrCmdTimeout = errors.New("timeout while waiting for command response")

	// ErrScanFailed is an error that happens when scanning for wifi networks fails
	ErrScanFailed = errors.New("scan failed")
)

var Interfaces = SysFSInterfaces

Interfaces is a shortcut to the best known method for gathering the wireless interfaces from the current system


Functions

func IsUseOfClosedNetworkConnectionError

func IsUseOfClosedNetworkConnectionError(err error) bool

IsUseOfClosedNetworkConnectionError will return true if the error is about use of closed network connection

func SysFSInterfaces

func SysFSInterfaces() []string

SysFSInterfaces returns the wireless interfaces found in the SysFS (/sys)

Types

type AP

type AP struct {
	ID             int
	Freq           int
	RSSI           int
	BSSID          net.HardwareAddr
	SSID           string
	ESSID          string
	Flags          []string
	SignalStrength int
	Frequency      int
}

AP represents an access point seen by the scan networks command

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a wireless client

func NewClient

func NewClient(iface string) (c *Client, err error)

NewClient will create a new client by connecting to the given interface in WPA

func NewClientFromConn

func NewClientFromConn(conn *Conn) (c *Client)

NewClientFromConn returns a new client from an already established connection

func (*Client) AddNetwork

func (cl *Client) AddNetwork(net Network) (Network, error)

AddNetwork will add a new network

func (*Client) AddOrUpdateNetwork

func (cl *Client) AddOrUpdateNetwork(net Network) (Network, error)

AddOrUpdateNetwork will add or, if the network has IDStr set, update it

func (*Client) Close

func (cl *Client) Close()

Close will close the client connection

func (*Client) Connect

func (cl *Client) Connect(net Network) (Network, error)

Connect to a new or existing network

func (*Client) DisableNetwork

func (cl *Client) DisableNetwork(id int) error

DisableNetwork will DisableNetwork

func (*Client) EnableNetwork

func (cl *Client) EnableNetwork(id int) error

EnableNetwork will EnableNetwork

func (*Client) LoadConfig

func (cl *Client) LoadConfig() error

LoadConfig will LoadConfig

func (*Client) Networks

func (cl *Client) Networks() (nets []Network, err error)

Networks lists the known networks

func (*Client) RemoveNetwork

func (cl *Client) RemoveNetwork(id int) error

RemoveNetwork will RemoveNetwork

func (*Client) SaveConfig

func (cl *Client) SaveConfig() error

SaveConfig will SaveConfig

func (*Client) Scan

func (cl *Client) Scan() (nets []AP, err error)

Scan will scan for networks and return the APs it finds

func (*Client) Status

func (cl *Client) Status() (State, error)

Status will return the current state of the WPA

func (*Client) UpdateNetwork

func (cl *Client) UpdateNetwork(net Network) (Network, error)

UpdateNetwork will update the given network, an error will be thrown if the network doesn't have IDStr specified

type Conn

type Conn struct {
	Interface string
	// contains filtered or unexported fields
}

Conn represents a connection to a WPA supplicant control interface

func Dial

func Dial(iface string) (*Conn, error)

Dial will dial the WPA control interface with the given interface name

func (*Conn) Close

func (c *Conn) Close()

Close will close the connection to the WPA control interface

func (*Conn) SendCommand

func (c *Conn) SendCommand(command ...string) (string, error)

SendCommand will call SendCommandWithContext with a 2 second timeout

func (*Conn) SendCommandBool

func (c *Conn) SendCommandBool(command ...string) error

SendCommandBool will send a command and return an error if the response was not OK

func (*Conn) SendCommandInt

func (c *Conn) SendCommandInt(command ...string) (int, error)

SendCommandInt will send a command where the response is expected to be an integer

func (*Conn) SendCommandWithContext

func (c *Conn) SendCommandWithContext(ctx context.Context, command ...string) (string, error)

SendCommandWithContext will send the command with a context

func (*Conn) Subscribe

func (c *Conn) Subscribe(eventNames ...string) Subscription

Subscribe to one or more events and return the subscription

type Connectable

type Connectable interface {
	SetCmds() []string
}

type Connector

type Connector interface {
	Connect(Network) error
}

Connector is interfce than can connect a network

type Event

type Event struct {
	Name      string
	Arguments map[string]string
}

Event is an event that happens in the WPA supplicant

func NewEventFromMsg

func NewEventFromMsg(msg string) (Event, error)

NewEventFromMsg will create a new event from the given message

type Network

type Network struct {
	ID       int
	IDStr    string
	KeyMgmt  string
	SSID     string
	BSSID    string
	ScanSSID bool
	PSK      string
	Flags    []string
}

Network represents a known network

func NewDisabledNetwork

func NewDisabledNetwork(ssid, psk string) Network

NewDisabledNetwork will create a new disabled network with the given parameters

func NewNamedNetwork

func NewNamedNetwork(name, ssid, psk string) Network

NewNamedNetwork will create a new network with the given parameters

func NewNetwork

func NewNetwork(ssid, psk string) Network

NewNetwork will create a new network with the given parameters

func (Network) Connect

func (net Network) Connect(cl Connector) error

Connect will connect the network to the given connector

func (Network) Disable

func (net Network) Disable(on bool)

Disable or enabled the network

func (Network) IsDisabled

func (net Network) IsDisabled() bool

IsDisabled will return true if the network is disabled

func (Network) SetCmds

func (net Network) SetCmds() [][]string

SetCmds will generate the set_network commands to run to set this network up in

type State

type State struct {
	BSSID          string `json:"bssid"`
	SSID           string `json:"ssid"`
	ID             string `json:"id"`
	Mode           string `json:"mode"`
	KeyManagement  string `json:"key_management"`
	WpaState       string `json:"wpa_state"`
	IPAddress      string `json:"ip_address"`
	Address        string `json:"address"`
	UUID           string `json:"uuid"`
	GroupCipher    string `json:"group_cipher"`
	PairwiseCipher string `json:"pairwise_cipher"`
}

State represents the current status of WPA

func NewState

func NewState(data string) State

NewState will return the state of the WPA

type Subscription

type Subscription struct {
	// contains filtered or unexported fields
}

Subscription represents a subscription to one or events

func (*Subscription) Next

func (s *Subscription) Next() chan Event

Next will return a cahnnel that returns the next event

Directories

Path Synopsis
api
cmd/api
cmd/connectap