wpa_ctrl.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * wpa_supplicant/hostapd control interface library
  3. * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #ifndef WPA_CTRL_H
  15. #define WPA_CTRL_H
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /* wpa_supplicant control interface - fixed message prefixes */
  20. /** Interactive request for identity/password/pin */
  21. #define WPA_CTRL_REQ "CTRL-REQ-"
  22. /** Response to identity/password/pin request */
  23. #define WPA_CTRL_RSP "CTRL-RSP-"
  24. /* Event messages with fixed prefix */
  25. /** Authentication completed successfully and data connection enabled */
  26. #define WPA_EVENT_CONNECTED "CTRL-EVENT-CONNECTED "
  27. /** Disconnected, data connection is not available */
  28. #define WPA_EVENT_DISCONNECTED "CTRL-EVENT-DISCONNECTED "
  29. /** wpa_supplicant is exiting */
  30. #define WPA_EVENT_TERMINATING "CTRL-EVENT-TERMINATING "
  31. /** Password change was completed successfully */
  32. #define WPA_EVENT_PASSWORD_CHANGED "CTRL-EVENT-PASSWORD-CHANGED "
  33. /** EAP-Request/Notification received */
  34. #define WPA_EVENT_EAP_NOTIFICATION "CTRL-EVENT-EAP-NOTIFICATION "
  35. /** EAP authentication started (EAP-Request/Identity received) */
  36. #define WPA_EVENT_EAP_STARTED "CTRL-EVENT-EAP-STARTED "
  37. /** EAP method proposed by the server */
  38. #define WPA_EVENT_EAP_PROPOSED_METHOD "CTRL-EVENT-EAP-PROPOSED-METHOD "
  39. /** EAP method selected */
  40. #define WPA_EVENT_EAP_METHOD "CTRL-EVENT-EAP-METHOD "
  41. /** EAP peer certificate from TLS */
  42. #define WPA_EVENT_EAP_PEER_CERT "CTRL-EVENT-EAP-PEER-CERT "
  43. /** EAP TLS certificate chain validation error */
  44. #define WPA_EVENT_EAP_TLS_CERT_ERROR "CTRL-EVENT-EAP-TLS-CERT-ERROR "
  45. /** EAP authentication completed successfully */
  46. #define WPA_EVENT_EAP_SUCCESS "CTRL-EVENT-EAP-SUCCESS "
  47. /** EAP authentication failed (EAP-Failure received) */
  48. #define WPA_EVENT_EAP_FAILURE "CTRL-EVENT-EAP-FAILURE "
  49. /** New scan results available */
  50. #define WPA_EVENT_SCAN_RESULTS "CTRL-EVENT-SCAN-RESULTS "
  51. /** A new BSS entry was added (followed by BSS entry id and BSSID) */
  52. #define WPA_EVENT_BSS_ADDED "CTRL-EVENT-BSS-ADDED "
  53. /** A BSS entry was removed (followed by BSS entry id and BSSID) */
  54. #define WPA_EVENT_BSS_REMOVED "CTRL-EVENT-BSS-REMOVED "
  55. /** WPS overlap detected in PBC mode */
  56. #define WPS_EVENT_OVERLAP "WPS-OVERLAP-DETECTED "
  57. /** Available WPS AP with active PBC found in scan results */
  58. #define WPS_EVENT_AP_AVAILABLE_PBC "WPS-AP-AVAILABLE-PBC "
  59. /** Available WPS AP with recently selected PIN registrar found in scan results
  60. */
  61. #define WPS_EVENT_AP_AVAILABLE_PIN "WPS-AP-AVAILABLE-PIN "
  62. /** Available WPS AP found in scan results */
  63. #define WPS_EVENT_AP_AVAILABLE "WPS-AP-AVAILABLE "
  64. /** A new credential received */
  65. #define WPS_EVENT_CRED_RECEIVED "WPS-CRED-RECEIVED "
  66. /** M2D received */
  67. #define WPS_EVENT_M2D "WPS-M2D "
  68. /** WPS registration failed after M2/M2D */
  69. #define WPS_EVENT_FAIL "WPS-FAIL "
  70. /** WPS registration completed successfully */
  71. #define WPS_EVENT_SUCCESS "WPS-SUCCESS "
  72. /** WPS enrollment attempt timed out and was terminated */
  73. #define WPS_EVENT_TIMEOUT "WPS-TIMEOUT "
  74. #define WPS_EVENT_ENROLLEE_SEEN "WPS-ENROLLEE-SEEN "
  75. /* WPS ER events */
  76. #define WPS_EVENT_ER_AP_ADD "WPS-ER-AP-ADD "
  77. #define WPS_EVENT_ER_AP_REMOVE "WPS-ER-AP-REMOVE "
  78. #define WPS_EVENT_ER_ENROLLEE_ADD "WPS-ER-ENROLLEE-ADD "
  79. #define WPS_EVENT_ER_ENROLLEE_REMOVE "WPS-ER-ENROLLEE-REMOVE "
  80. #define WPS_EVENT_ER_AP_SETTINGS "WPS-ER-AP-SETTINGS "
  81. /* hostapd control interface - fixed message prefixes */
  82. #define WPS_EVENT_PIN_NEEDED "WPS-PIN-NEEDED "
  83. #define WPS_EVENT_NEW_AP_SETTINGS "WPS-NEW-AP-SETTINGS "
  84. #define WPS_EVENT_REG_SUCCESS "WPS-REG-SUCCESS "
  85. #define WPS_EVENT_AP_SETUP_LOCKED "WPS-AP-SETUP-LOCKED "
  86. #define AP_STA_CONNECTED "AP-STA-CONNECTED "
  87. #define AP_STA_DISCONNECTED "AP-STA-DISCONNECTED "
  88. /* wpa_supplicant/hostapd control interface access */
  89. /**
  90. * wpa_ctrl_open - Open a control interface to wpa_supplicant/hostapd
  91. * @ctrl_path: Path for UNIX domain sockets; ignored if UDP sockets are used.
  92. * Returns: Pointer to abstract control interface data or %NULL on failure
  93. *
  94. * This function is used to open a control interface to wpa_supplicant/hostapd.
  95. * ctrl_path is usually /var/run/wpa_supplicant or /var/run/hostapd. This path
  96. * is configured in wpa_supplicant/hostapd and other programs using the control
  97. * interface need to use matching path configuration.
  98. */
  99. struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path);
  100. /**
  101. * wpa_ctrl_close - Close a control interface to wpa_supplicant/hostapd
  102. * @ctrl: Control interface data from wpa_ctrl_open()
  103. *
  104. * This function is used to close a control interface.
  105. */
  106. void wpa_ctrl_close(struct wpa_ctrl *ctrl);
  107. /**
  108. * wpa_ctrl_request - Send a command to wpa_supplicant/hostapd
  109. * @ctrl: Control interface data from wpa_ctrl_open()
  110. * @cmd: Command; usually, ASCII text, e.g., "PING"
  111. * @cmd_len: Length of the cmd in bytes
  112. * @reply: Buffer for the response
  113. * @reply_len: Reply buffer length
  114. * @msg_cb: Callback function for unsolicited messages or %NULL if not used
  115. * Returns: 0 on success, -1 on error (send or receive failed), -2 on timeout
  116. *
  117. * This function is used to send commands to wpa_supplicant/hostapd. Received
  118. * response will be written to reply and reply_len is set to the actual length
  119. * of the reply. This function will block for up to two seconds while waiting
  120. * for the reply. If unsolicited messages are received, the blocking time may
  121. * be longer.
  122. *
  123. * msg_cb can be used to register a callback function that will be called for
  124. * unsolicited messages received while waiting for the command response. These
  125. * messages may be received if wpa_ctrl_request() is called at the same time as
  126. * wpa_supplicant/hostapd is sending such a message. This can happen only if
  127. * the program has used wpa_ctrl_attach() to register itself as a monitor for
  128. * event messages. Alternatively to msg_cb, programs can register two control
  129. * interface connections and use one of them for commands and the other one for
  130. * receiving event messages, in other words, call wpa_ctrl_attach() only for
  131. * the control interface connection that will be used for event messages.
  132. */
  133. int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
  134. char *reply, size_t *reply_len,
  135. void (*msg_cb)(char *msg, size_t len));
  136. /**
  137. * wpa_ctrl_attach - Register as an event monitor for the control interface
  138. * @ctrl: Control interface data from wpa_ctrl_open()
  139. * Returns: 0 on success, -1 on failure, -2 on timeout
  140. *
  141. * This function registers the control interface connection as a monitor for
  142. * wpa_supplicant/hostapd events. After a success wpa_ctrl_attach() call, the
  143. * control interface connection starts receiving event messages that can be
  144. * read with wpa_ctrl_recv().
  145. */
  146. int wpa_ctrl_attach(struct wpa_ctrl *ctrl);
  147. /**
  148. * wpa_ctrl_detach - Unregister event monitor from the control interface
  149. * @ctrl: Control interface data from wpa_ctrl_open()
  150. * Returns: 0 on success, -1 on failure, -2 on timeout
  151. *
  152. * This function unregisters the control interface connection as a monitor for
  153. * wpa_supplicant/hostapd events, i.e., cancels the registration done with
  154. * wpa_ctrl_attach().
  155. */
  156. int wpa_ctrl_detach(struct wpa_ctrl *ctrl);
  157. /**
  158. * wpa_ctrl_recv - Receive a pending control interface message
  159. * @ctrl: Control interface data from wpa_ctrl_open()
  160. * @reply: Buffer for the message data
  161. * @reply_len: Length of the reply buffer
  162. * Returns: 0 on success, -1 on failure
  163. *
  164. * This function will receive a pending control interface message. This
  165. * function will block if no messages are available. The received response will
  166. * be written to reply and reply_len is set to the actual length of the reply.
  167. * wpa_ctrl_recv() is only used for event messages, i.e., wpa_ctrl_attach()
  168. * must have been used to register the control interface as an event monitor.
  169. */
  170. int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len);
  171. /**
  172. * wpa_ctrl_pending - Check whether there are pending event messages
  173. * @ctrl: Control interface data from wpa_ctrl_open()
  174. * Returns: 1 if there are pending messages, 0 if no, or -1 on error
  175. *
  176. * This function will check whether there are any pending control interface
  177. * message available to be received with wpa_ctrl_recv(). wpa_ctrl_pending() is
  178. * only used for event messages, i.e., wpa_ctrl_attach() must have been used to
  179. * register the control interface as an event monitor.
  180. */
  181. int wpa_ctrl_pending(struct wpa_ctrl *ctrl);
  182. /**
  183. * wpa_ctrl_get_fd - Get file descriptor used by the control interface
  184. * @ctrl: Control interface data from wpa_ctrl_open()
  185. * Returns: File descriptor used for the connection
  186. *
  187. * This function can be used to get the file descriptor that is used for the
  188. * control interface connection. The returned value can be used, e.g., with
  189. * select() while waiting for multiple events.
  190. *
  191. * The returned file descriptor must not be used directly for sending or
  192. * receiving packets; instead, the library functions wpa_ctrl_request() and
  193. * wpa_ctrl_recv() must be used for this.
  194. */
  195. int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl);
  196. #ifdef CONFIG_CTRL_IFACE_UDP
  197. #define WPA_CTRL_IFACE_PORT 9877
  198. #define WPA_GLOBAL_CTRL_IFACE_PORT 9878
  199. #endif /* CONFIG_CTRL_IFACE_UDP */
  200. #ifdef __cplusplus
  201. }
  202. #endif
  203. #endif /* WPA_CTRL_H */