wpa_ctrl.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 selected */
  38. #define WPA_EVENT_EAP_METHOD "CTRL-EVENT-EAP-METHOD "
  39. /** EAP authentication completed successfully */
  40. #define WPA_EVENT_EAP_SUCCESS "CTRL-EVENT-EAP-SUCCESS "
  41. /** EAP authentication failed (EAP-Failure received) */
  42. #define WPA_EVENT_EAP_FAILURE "CTRL-EVENT-EAP-FAILURE "
  43. /** New scan results available */
  44. #define WPA_EVENT_SCAN_RESULTS "CTRL-EVENT-SCAN-RESULTS "
  45. /** WPS overlap detected in PBC mode */
  46. #define WPS_EVENT_OVERLAP "WPS-OVERLAP-DETECTED "
  47. /** Available WPS AP with active PBC found in scan results */
  48. #define WPS_EVENT_AP_AVAILABLE_PBC "WPS-AP-AVAILABLE-PBC "
  49. /** Available WPS AP with recently selected PIN registrar found in scan results
  50. */
  51. #define WPS_EVENT_AP_AVAILABLE_PIN "WPS-AP-AVAILABLE-PIN "
  52. /** Available WPS AP found in scan results */
  53. #define WPS_EVENT_AP_AVAILABLE "WPS-AP-AVAILABLE "
  54. /** A new credential received */
  55. #define WPS_EVENT_CRED_RECEIVED "WPS-CRED-RECEIVED "
  56. /** M2D received */
  57. #define WPS_EVENT_M2D "WPS-M2D "
  58. /** WPS registration failed after M2/M2D */
  59. #define WPS_EVENT_FAIL "WPS-FAIL "
  60. /** WPS registration completed successfully */
  61. #define WPS_EVENT_SUCCESS "WPS-SUCCESS "
  62. /** WPS enrollment attempt timed out and was terminated */
  63. #define WPS_EVENT_TIMEOUT "WPS-TIMEOUT "
  64. /* hostapd control interface - fixed message prefixes */
  65. #define WPS_EVENT_PIN_NEEDED "WPS-PIN-NEEDED "
  66. #define WPS_EVENT_NEW_AP_SETTINGS "WPS-NEW-AP-SETTINGS "
  67. #define WPS_EVENT_REG_SUCCESS "WPS-REG-SUCCESS "
  68. #define WPS_EVENT_AP_SETUP_LOCKED "WPS-AP-SETUP-LOCKED "
  69. #define AP_STA_CONNECTED "AP-STA-CONNECTED "
  70. #define AP_STA_DISCONNECTED "AP-STA-DISCONNECTED "
  71. /* wpa_supplicant/hostapd control interface access */
  72. /**
  73. * wpa_ctrl_open - Open a control interface to wpa_supplicant/hostapd
  74. * @ctrl_path: Path for UNIX domain sockets; ignored if UDP sockets are used.
  75. * Returns: Pointer to abstract control interface data or %NULL on failure
  76. *
  77. * This function is used to open a control interface to wpa_supplicant/hostapd.
  78. * ctrl_path is usually /var/run/wpa_supplicant or /var/run/hostapd. This path
  79. * is configured in wpa_supplicant/hostapd and other programs using the control
  80. * interface need to use matching path configuration.
  81. */
  82. struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path);
  83. /**
  84. * wpa_ctrl_close - Close a control interface to wpa_supplicant/hostapd
  85. * @ctrl: Control interface data from wpa_ctrl_open()
  86. *
  87. * This function is used to close a control interface.
  88. */
  89. void wpa_ctrl_close(struct wpa_ctrl *ctrl);
  90. /**
  91. * wpa_ctrl_request - Send a command to wpa_supplicant/hostapd
  92. * @ctrl: Control interface data from wpa_ctrl_open()
  93. * @cmd: Command; usually, ASCII text, e.g., "PING"
  94. * @cmd_len: Length of the cmd in bytes
  95. * @reply: Buffer for the response
  96. * @reply_len: Reply buffer length
  97. * @msg_cb: Callback function for unsolicited messages or %NULL if not used
  98. * Returns: 0 on success, -1 on error (send or receive failed), -2 on timeout
  99. *
  100. * This function is used to send commands to wpa_supplicant/hostapd. Received
  101. * response will be written to reply and reply_len is set to the actual length
  102. * of the reply. This function will block for up to two seconds while waiting
  103. * for the reply. If unsolicited messages are received, the blocking time may
  104. * be longer.
  105. *
  106. * msg_cb can be used to register a callback function that will be called for
  107. * unsolicited messages received while waiting for the command response. These
  108. * messages may be received if wpa_ctrl_request() is called at the same time as
  109. * wpa_supplicant/hostapd is sending such a message. This can happen only if
  110. * the program has used wpa_ctrl_attach() to register itself as a monitor for
  111. * event messages. Alternatively to msg_cb, programs can register two control
  112. * interface connections and use one of them for commands and the other one for
  113. * receiving event messages, in other words, call wpa_ctrl_attach() only for
  114. * the control interface connection that will be used for event messages.
  115. */
  116. int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
  117. char *reply, size_t *reply_len,
  118. void (*msg_cb)(char *msg, size_t len));
  119. /**
  120. * wpa_ctrl_attach - Register as an event monitor for the control interface
  121. * @ctrl: Control interface data from wpa_ctrl_open()
  122. * Returns: 0 on success, -1 on failure, -2 on timeout
  123. *
  124. * This function registers the control interface connection as a monitor for
  125. * wpa_supplicant/hostapd events. After a success wpa_ctrl_attach() call, the
  126. * control interface connection starts receiving event messages that can be
  127. * read with wpa_ctrl_recv().
  128. */
  129. int wpa_ctrl_attach(struct wpa_ctrl *ctrl);
  130. /**
  131. * wpa_ctrl_detach - Unregister event monitor from the control interface
  132. * @ctrl: Control interface data from wpa_ctrl_open()
  133. * Returns: 0 on success, -1 on failure, -2 on timeout
  134. *
  135. * This function unregisters the control interface connection as a monitor for
  136. * wpa_supplicant/hostapd events, i.e., cancels the registration done with
  137. * wpa_ctrl_attach().
  138. */
  139. int wpa_ctrl_detach(struct wpa_ctrl *ctrl);
  140. /**
  141. * wpa_ctrl_recv - Receive a pending control interface message
  142. * @ctrl: Control interface data from wpa_ctrl_open()
  143. * @reply: Buffer for the message data
  144. * @reply_len: Length of the reply buffer
  145. * Returns: 0 on success, -1 on failure
  146. *
  147. * This function will receive a pending control interface message. This
  148. * function will block if no messages are available. The received response will
  149. * be written to reply and reply_len is set to the actual length of the reply.
  150. * wpa_ctrl_recv() is only used for event messages, i.e., wpa_ctrl_attach()
  151. * must have been used to register the control interface as an event monitor.
  152. */
  153. int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len);
  154. /**
  155. * wpa_ctrl_pending - Check whether there are pending event messages
  156. * @ctrl: Control interface data from wpa_ctrl_open()
  157. * Returns: 1 if there are pending messages, 0 if no, or -1 on error
  158. *
  159. * This function will check whether there are any pending control interface
  160. * message available to be received with wpa_ctrl_recv(). wpa_ctrl_pending() is
  161. * only used for event messages, i.e., wpa_ctrl_attach() must have been used to
  162. * register the control interface as an event monitor.
  163. */
  164. int wpa_ctrl_pending(struct wpa_ctrl *ctrl);
  165. /**
  166. * wpa_ctrl_get_fd - Get file descriptor used by the control interface
  167. * @ctrl: Control interface data from wpa_ctrl_open()
  168. * Returns: File descriptor used for the connection
  169. *
  170. * This function can be used to get the file descriptor that is used for the
  171. * control interface connection. The returned value can be used, e.g., with
  172. * select() while waiting for multiple events.
  173. *
  174. * The returned file descriptor must not be used directly for sending or
  175. * receiving packets; instead, the library functions wpa_ctrl_request() and
  176. * wpa_ctrl_recv() must be used for this.
  177. */
  178. int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl);
  179. #ifdef CONFIG_CTRL_IFACE_UDP
  180. #define WPA_CTRL_IFACE_PORT 9877
  181. #define WPA_GLOBAL_CTRL_IFACE_PORT 9878
  182. #endif /* CONFIG_CTRL_IFACE_UDP */
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186. #endif /* WPA_CTRL_H */