wpa_supplicant / hostapd 2.0
Defines | Functions

wpa_ctrl.h File Reference

wpa_supplicant/hostapd control interface library More...

Go to the source code of this file.

Defines

#define WPA_CTRL_REQ   "CTRL-REQ-"
#define WPA_CTRL_RSP   "CTRL-RSP-"
#define WPA_EVENT_CONNECTED   "CTRL-EVENT-CONNECTED "
#define WPA_EVENT_DISCONNECTED   "CTRL-EVENT-DISCONNECTED "
#define WPA_EVENT_ASSOC_REJECT   "CTRL-EVENT-ASSOC-REJECT "
#define WPA_EVENT_TERMINATING   "CTRL-EVENT-TERMINATING "
#define WPA_EVENT_PASSWORD_CHANGED   "CTRL-EVENT-PASSWORD-CHANGED "
#define WPA_EVENT_EAP_NOTIFICATION   "CTRL-EVENT-EAP-NOTIFICATION "
#define WPA_EVENT_EAP_STARTED   "CTRL-EVENT-EAP-STARTED "
#define WPA_EVENT_EAP_PROPOSED_METHOD   "CTRL-EVENT-EAP-PROPOSED-METHOD "
#define WPA_EVENT_EAP_METHOD   "CTRL-EVENT-EAP-METHOD "
#define WPA_EVENT_EAP_PEER_CERT   "CTRL-EVENT-EAP-PEER-CERT "
#define WPA_EVENT_EAP_TLS_CERT_ERROR   "CTRL-EVENT-EAP-TLS-CERT-ERROR "
#define WPA_EVENT_EAP_SUCCESS   "CTRL-EVENT-EAP-SUCCESS "
#define WPA_EVENT_EAP_FAILURE   "CTRL-EVENT-EAP-FAILURE "
#define WPA_EVENT_SCAN_RESULTS   "CTRL-EVENT-SCAN-RESULTS "
#define WPA_EVENT_STATE_CHANGE   "CTRL-EVENT-STATE-CHANGE "
#define WPA_EVENT_BSS_ADDED   "CTRL-EVENT-BSS-ADDED "
#define WPA_EVENT_BSS_REMOVED   "CTRL-EVENT-BSS-REMOVED "
#define WPS_EVENT_OVERLAP   "WPS-OVERLAP-DETECTED "
#define WPS_EVENT_AP_AVAILABLE_PBC   "WPS-AP-AVAILABLE-PBC "
#define WPS_EVENT_AP_AVAILABLE_AUTH   "WPS-AP-AVAILABLE-AUTH "
#define WPS_EVENT_AP_AVAILABLE_PIN   "WPS-AP-AVAILABLE-PIN "
#define WPS_EVENT_AP_AVAILABLE   "WPS-AP-AVAILABLE "
#define WPS_EVENT_CRED_RECEIVED   "WPS-CRED-RECEIVED "
#define WPS_EVENT_M2D   "WPS-M2D "
#define WPS_EVENT_FAIL   "WPS-FAIL "
#define WPS_EVENT_SUCCESS   "WPS-SUCCESS "
#define WPS_EVENT_TIMEOUT   "WPS-TIMEOUT "
#define WPS_EVENT_ENROLLEE_SEEN   "WPS-ENROLLEE-SEEN "
#define WPS_EVENT_OPEN_NETWORK   "WPS-OPEN-NETWORK "
#define WPS_EVENT_ER_AP_ADD   "WPS-ER-AP-ADD "
#define WPS_EVENT_ER_AP_REMOVE   "WPS-ER-AP-REMOVE "
#define WPS_EVENT_ER_ENROLLEE_ADD   "WPS-ER-ENROLLEE-ADD "
#define WPS_EVENT_ER_ENROLLEE_REMOVE   "WPS-ER-ENROLLEE-REMOVE "
#define WPS_EVENT_ER_AP_SETTINGS   "WPS-ER-AP-SETTINGS "
#define WPS_EVENT_ER_SET_SEL_REG   "WPS-ER-AP-SET-SEL-REG "
#define P2P_EVENT_DEVICE_FOUND   "P2P-DEVICE-FOUND "
#define P2P_EVENT_DEVICE_LOST   "P2P-DEVICE-LOST "
#define P2P_EVENT_GO_NEG_REQUEST   "P2P-GO-NEG-REQUEST "
#define P2P_EVENT_GO_NEG_SUCCESS   "P2P-GO-NEG-SUCCESS "
#define P2P_EVENT_GO_NEG_FAILURE   "P2P-GO-NEG-FAILURE "
#define P2P_EVENT_GROUP_FORMATION_SUCCESS   "P2P-GROUP-FORMATION-SUCCESS "
#define P2P_EVENT_GROUP_FORMATION_FAILURE   "P2P-GROUP-FORMATION-FAILURE "
#define P2P_EVENT_GROUP_STARTED   "P2P-GROUP-STARTED "
#define P2P_EVENT_GROUP_REMOVED   "P2P-GROUP-REMOVED "
#define P2P_EVENT_CROSS_CONNECT_ENABLE   "P2P-CROSS-CONNECT-ENABLE "
#define P2P_EVENT_CROSS_CONNECT_DISABLE   "P2P-CROSS-CONNECT-DISABLE "
#define P2P_EVENT_PROV_DISC_SHOW_PIN   "P2P-PROV-DISC-SHOW-PIN "
#define P2P_EVENT_PROV_DISC_ENTER_PIN   "P2P-PROV-DISC-ENTER-PIN "
#define P2P_EVENT_PROV_DISC_PBC_REQ   "P2P-PROV-DISC-PBC-REQ "
#define P2P_EVENT_PROV_DISC_PBC_RESP   "P2P-PROV-DISC-PBC-RESP "
#define P2P_EVENT_PROV_DISC_FAILURE   "P2P-PROV-DISC-FAILURE"
#define P2P_EVENT_SERV_DISC_REQ   "P2P-SERV-DISC-REQ "
#define P2P_EVENT_SERV_DISC_RESP   "P2P-SERV-DISC-RESP "
#define P2P_EVENT_INVITATION_RECEIVED   "P2P-INVITATION-RECEIVED "
#define P2P_EVENT_INVITATION_RESULT   "P2P-INVITATION-RESULT "
#define P2P_EVENT_FIND_STOPPED   "P2P-FIND-STOPPED "
#define INTERWORKING_AP   "INTERWORKING-AP "
#define INTERWORKING_NO_MATCH   "INTERWORKING-NO-MATCH "
#define WPS_EVENT_PIN_NEEDED   "WPS-PIN-NEEDED "
#define WPS_EVENT_NEW_AP_SETTINGS   "WPS-NEW-AP-SETTINGS "
#define WPS_EVENT_REG_SUCCESS   "WPS-REG-SUCCESS "
#define WPS_EVENT_AP_SETUP_LOCKED   "WPS-AP-SETUP-LOCKED "
#define WPS_EVENT_AP_SETUP_UNLOCKED   "WPS-AP-SETUP-UNLOCKED "
#define WPS_EVENT_AP_PIN_ENABLED   "WPS-AP-PIN-ENABLED "
#define WPS_EVENT_AP_PIN_DISABLED   "WPS-AP-PIN-DISABLED "
#define AP_STA_CONNECTED   "AP-STA-CONNECTED "
#define AP_STA_DISCONNECTED   "AP-STA-DISCONNECTED "
#define WPA_BSS_MASK_ALL   0xFFFFFFFF
#define WPA_BSS_MASK_ID   BIT(0)
#define WPA_BSS_MASK_BSSID   BIT(1)
#define WPA_BSS_MASK_FREQ   BIT(2)
#define WPA_BSS_MASK_BEACON_INT   BIT(3)
#define WPA_BSS_MASK_CAPABILITIES   BIT(4)
#define WPA_BSS_MASK_QUAL   BIT(5)
#define WPA_BSS_MASK_NOISE   BIT(6)
#define WPA_BSS_MASK_LEVEL   BIT(7)
#define WPA_BSS_MASK_TSF   BIT(8)
#define WPA_BSS_MASK_AGE   BIT(9)
#define WPA_BSS_MASK_IE   BIT(10)
#define WPA_BSS_MASK_FLAGS   BIT(11)
#define WPA_BSS_MASK_SSID   BIT(12)
#define WPA_BSS_MASK_WPS_SCAN   BIT(13)
#define WPA_BSS_MASK_P2P_SCAN   BIT(14)
#define WPA_BSS_MASK_INTERNETW   BIT(15)

Functions

struct wpa_ctrlwpa_ctrl_open (const char *ctrl_path)
 Open a control interface to wpa_supplicant/hostapd.
void wpa_ctrl_close (struct wpa_ctrl *ctrl)
 Close a control interface to wpa_supplicant/hostapd.
int wpa_ctrl_request (struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len, char *reply, size_t *reply_len, void(*msg_cb)(char *msg, size_t len))
 Send a command to wpa_supplicant/hostapd.
int wpa_ctrl_attach (struct wpa_ctrl *ctrl)
 Register as an event monitor for the control interface.
int wpa_ctrl_detach (struct wpa_ctrl *ctrl)
 Unregister event monitor from the control interface.
int wpa_ctrl_recv (struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
 Receive a pending control interface message.
int wpa_ctrl_pending (struct wpa_ctrl *ctrl)
 Check whether there are pending event messages.
int wpa_ctrl_get_fd (struct wpa_ctrl *ctrl)
 Get file descriptor used by the control interface.

Detailed Description

wpa_supplicant/hostapd control interface library

Copyright
Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>

This software may be distributed under the terms of the BSD license. See README for more details.


Define Documentation

#define P2P_EVENT_DEVICE_FOUND   "P2P-DEVICE-FOUND "

P2P device found

#define P2P_EVENT_DEVICE_LOST   "P2P-DEVICE-LOST "

P2P device lost

#define P2P_EVENT_GO_NEG_REQUEST   "P2P-GO-NEG-REQUEST "

A P2P device requested GO negotiation, but we were not ready to start the negotiation

#define WPA_CTRL_REQ   "CTRL-REQ-"

Interactive request for identity/password/pin

#define WPA_CTRL_RSP   "CTRL-RSP-"

Response to identity/password/pin request

#define WPA_EVENT_ASSOC_REJECT   "CTRL-EVENT-ASSOC-REJECT "

Association rejected during connection attempt

#define WPA_EVENT_BSS_ADDED   "CTRL-EVENT-BSS-ADDED "

A new BSS entry was added (followed by BSS entry id and BSSID)

#define WPA_EVENT_BSS_REMOVED   "CTRL-EVENT-BSS-REMOVED "

A BSS entry was removed (followed by BSS entry id and BSSID)

#define WPA_EVENT_CONNECTED   "CTRL-EVENT-CONNECTED "

Authentication completed successfully and data connection enabled

#define WPA_EVENT_DISCONNECTED   "CTRL-EVENT-DISCONNECTED "

Disconnected, data connection is not available

#define WPA_EVENT_EAP_FAILURE   "CTRL-EVENT-EAP-FAILURE "

EAP authentication failed (EAP-Failure received)

#define WPA_EVENT_EAP_METHOD   "CTRL-EVENT-EAP-METHOD "

EAP method selected

#define WPA_EVENT_EAP_NOTIFICATION   "CTRL-EVENT-EAP-NOTIFICATION "

EAP-Request/Notification received

#define WPA_EVENT_EAP_PEER_CERT   "CTRL-EVENT-EAP-PEER-CERT "

EAP peer certificate from TLS

#define WPA_EVENT_EAP_PROPOSED_METHOD   "CTRL-EVENT-EAP-PROPOSED-METHOD "

EAP method proposed by the server

#define WPA_EVENT_EAP_STARTED   "CTRL-EVENT-EAP-STARTED "

EAP authentication started (EAP-Request/Identity received)

#define WPA_EVENT_EAP_SUCCESS   "CTRL-EVENT-EAP-SUCCESS "

EAP authentication completed successfully

#define WPA_EVENT_EAP_TLS_CERT_ERROR   "CTRL-EVENT-EAP-TLS-CERT-ERROR "

EAP TLS certificate chain validation error

#define WPA_EVENT_PASSWORD_CHANGED   "CTRL-EVENT-PASSWORD-CHANGED "

Password change was completed successfully

#define WPA_EVENT_SCAN_RESULTS   "CTRL-EVENT-SCAN-RESULTS "

New scan results available

#define WPA_EVENT_STATE_CHANGE   "CTRL-EVENT-STATE-CHANGE "

wpa_supplicant state change

#define WPA_EVENT_TERMINATING   "CTRL-EVENT-TERMINATING "

wpa_supplicant is exiting

#define WPS_EVENT_AP_AVAILABLE   "WPS-AP-AVAILABLE "

Available WPS AP found in scan results

#define WPS_EVENT_AP_AVAILABLE_AUTH   "WPS-AP-AVAILABLE-AUTH "

Available WPS AP with our address as authorized in scan results

#define WPS_EVENT_AP_AVAILABLE_PBC   "WPS-AP-AVAILABLE-PBC "

Available WPS AP with active PBC found in scan results

#define WPS_EVENT_AP_AVAILABLE_PIN   "WPS-AP-AVAILABLE-PIN "

Available WPS AP with recently selected PIN registrar found in scan results

#define WPS_EVENT_CRED_RECEIVED   "WPS-CRED-RECEIVED "

A new credential received

#define WPS_EVENT_FAIL   "WPS-FAIL "

WPS registration failed after M2/M2D

#define WPS_EVENT_M2D   "WPS-M2D "

M2D received

#define WPS_EVENT_OVERLAP   "WPS-OVERLAP-DETECTED "

WPS overlap detected in PBC mode

#define WPS_EVENT_SUCCESS   "WPS-SUCCESS "

WPS registration completed successfully

#define WPS_EVENT_TIMEOUT   "WPS-TIMEOUT "

WPS enrollment attempt timed out and was terminated


Function Documentation

int wpa_ctrl_attach ( struct wpa_ctrl ctrl)

Register as an event monitor for the control interface.

Parameters:
ctrlControl interface data from wpa_ctrl_open()
Returns:
0 on success, -1 on failure, -2 on timeout

This function registers the control interface connection as a monitor for wpa_supplicant/hostapd events. After a success wpa_ctrl_attach() call, the control interface connection starts receiving event messages that can be read with wpa_ctrl_recv().

void wpa_ctrl_close ( struct wpa_ctrl ctrl)

Close a control interface to wpa_supplicant/hostapd.

Parameters:
ctrlControl interface data from wpa_ctrl_open()

This function is used to close a control interface.

int wpa_ctrl_detach ( struct wpa_ctrl ctrl)

Unregister event monitor from the control interface.

Parameters:
ctrlControl interface data from wpa_ctrl_open()
Returns:
0 on success, -1 on failure, -2 on timeout

This function unregisters the control interface connection as a monitor for wpa_supplicant/hostapd events, i.e., cancels the registration done with wpa_ctrl_attach().

int wpa_ctrl_get_fd ( struct wpa_ctrl ctrl)

Get file descriptor used by the control interface.

Parameters:
ctrlControl interface data from wpa_ctrl_open()
Returns:
File descriptor used for the connection

This function can be used to get the file descriptor that is used for the control interface connection. The returned value can be used, e.g., with select() while waiting for multiple events.

The returned file descriptor must not be used directly for sending or receiving packets; instead, the library functions wpa_ctrl_request() and wpa_ctrl_recv() must be used for this.

struct wpa_ctrl* wpa_ctrl_open ( const char *  ctrl_path) [read]

Open a control interface to wpa_supplicant/hostapd.

Parameters:
ctrl_pathPath for UNIX domain sockets; ignored if UDP sockets are used.
Returns:
Pointer to abstract control interface data or NULL on failure

This function is used to open a control interface to wpa_supplicant/hostapd. ctrl_path is usually /var/run/wpa_supplicant or /var/run/hostapd. This path is configured in wpa_supplicant/hostapd and other programs using the control interface need to use matching path configuration.

int wpa_ctrl_pending ( struct wpa_ctrl ctrl)

Check whether there are pending event messages.

Parameters:
ctrlControl interface data from wpa_ctrl_open()
Returns:
1 if there are pending messages, 0 if no, or -1 on error

This function will check whether there are any pending control interface message available to be received with wpa_ctrl_recv(). wpa_ctrl_pending() is only used for event messages, i.e., wpa_ctrl_attach() must have been used to register the control interface as an event monitor.

int wpa_ctrl_recv ( struct wpa_ctrl ctrl,
char *  reply,
size_t *  reply_len 
)

Receive a pending control interface message.

Parameters:
ctrlControl interface data from wpa_ctrl_open()
replyBuffer for the message data
reply_lenLength of the reply buffer
Returns:
0 on success, -1 on failure

This function will receive a pending control interface message. This function will block if no messages are available. The received response will be written to reply and reply_len is set to the actual length of the reply. wpa_ctrl_recv() is only used for event messages, i.e., wpa_ctrl_attach() must have been used to register the control interface as an event monitor.

int wpa_ctrl_request ( struct wpa_ctrl ctrl,
const char *  cmd,
size_t  cmd_len,
char *  reply,
size_t *  reply_len,
void(*)(char *msg, size_t len)  msg_cb 
)

Send a command to wpa_supplicant/hostapd.

Parameters:
ctrlControl interface data from wpa_ctrl_open()
cmdCommand; usually, ASCII text, e.g., "PING"
cmd_lenLength of the cmd in bytes
replyBuffer for the response
reply_lenReply buffer length
msg_cbCallback function for unsolicited messages or NULL if not used
Returns:
0 on success, -1 on error (send or receive failed), -2 on timeout

This function is used to send commands to wpa_supplicant/hostapd. Received response will be written to reply and reply_len is set to the actual length of the reply. This function will block for up to two seconds while waiting for the reply. If unsolicited messages are received, the blocking time may be longer.

msg_cb can be used to register a callback function that will be called for unsolicited messages received while waiting for the command response. These messages may be received if wpa_ctrl_request() is called at the same time as wpa_supplicant/hostapd is sending such a message. This can happen only if the program has used wpa_ctrl_attach() to register itself as a monitor for event messages. Alternatively to msg_cb, programs can register two control interface connections and use one of them for commands and the other one for receiving event messages, in other words, call wpa_ctrl_attach() only for the control interface connection that will be used for event messages.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines