ctrl_iface.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * WPA Supplicant / UNIX domain socket -based control interface
  3. * Copyright (c) 2004-2005, 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 CTRL_IFACE_H
  15. #define CTRL_IFACE_H
  16. #ifdef CONFIG_CTRL_IFACE
  17. /* Shared functions from ctrl_iface.c; to be called by ctrl_iface backends */
  18. /**
  19. * wpa_supplicant_ctrl_iface_process - Process ctrl_iface command
  20. * @wpa_s: Pointer to wpa_supplicant data
  21. * @buf: Received command buffer (nul terminated string)
  22. * @resp_len: Variable to be set to the response length
  23. * Returns: Response (*resp_len bytes) or %NULL on failure
  24. *
  25. * Control interface backends call this function when receiving a message that
  26. * they do not process internally, i.e., anything else than ATTACH, DETACH,
  27. * and LEVEL. The return response value is then sent to the external program
  28. * that sent the command. Caller is responsible for freeing the buffer after
  29. * this. If %NULL is returned, *resp_len can be set to two special values:
  30. * 1 = send "FAIL\n" response, 2 = send "OK\n" response. If *resp_len has any
  31. * other value, no response is sent.
  32. */
  33. char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
  34. char *buf, size_t *resp_len);
  35. /**
  36. * wpa_supplicant_ctrl_iface_process - Process global ctrl_iface command
  37. * @global: Pointer to global data from wpa_supplicant_init()
  38. * @buf: Received command buffer (nul terminated string)
  39. * @resp_len: Variable to be set to the response length
  40. * Returns: Response (*resp_len bytes) or %NULL on failure
  41. *
  42. * Control interface backends call this function when receiving a message from
  43. * the global ctrl_iface connection. The return response value is then sent to
  44. * the external program that sent the command. Caller is responsible for
  45. * freeing the buffer after this. If %NULL is returned, *resp_len can be set to
  46. * two special values: 1 = send "FAIL\n" response, 2 = send "OK\n" response. If
  47. * *resp_len has any other value, no response is sent.
  48. */
  49. char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
  50. char *buf, size_t *resp_len);
  51. /* Functions that each ctrl_iface backend must implement */
  52. /**
  53. * wpa_supplicant_ctrl_iface_init - Initialize control interface
  54. * @wpa_s: Pointer to wpa_supplicant data
  55. * Returns: Pointer to private data on success, %NULL on failure
  56. *
  57. * Initialize the control interface and start receiving commands from external
  58. * programs.
  59. *
  60. * Required to be implemented in each control interface backend.
  61. */
  62. struct ctrl_iface_priv *
  63. wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s);
  64. /**
  65. * wpa_supplicant_ctrl_iface_deinit - Deinitialize control interface
  66. * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init()
  67. *
  68. * Deinitialize the control interface that was initialized with
  69. * wpa_supplicant_ctrl_iface_init().
  70. *
  71. * Required to be implemented in each control interface backend.
  72. */
  73. void wpa_supplicant_ctrl_iface_deinit(struct ctrl_iface_priv *priv);
  74. /**
  75. * wpa_supplicant_ctrl_iface_wait - Wait for ctrl_iface monitor
  76. * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init()
  77. *
  78. * Wait until the first message from an external program using the control
  79. * interface is received. This function can be used to delay normal startup
  80. * processing to allow control interface programs to attach with
  81. * %wpa_supplicant before normal operations are started.
  82. *
  83. * Required to be implemented in each control interface backend.
  84. */
  85. void wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv);
  86. /**
  87. * wpa_supplicant_ctrl_iface_ctrl_rsp_handle - Handle a control response
  88. * @wpa_s: Pointer to wpa_supplicant data
  89. * @ssid: Pointer to the network block the reply is for
  90. * @field: field the response is a reply for
  91. * @value: value (ie, password, etc) for @field
  92. * Returns: 0 on success, non-zero on error
  93. *
  94. * Helper function to handle replies to control interface requests.
  95. */
  96. int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant *wpa_s,
  97. struct wpa_ssid *ssid,
  98. const char *field,
  99. const char *value);
  100. /**
  101. * wpa_supplicant_global_ctrl_iface_init - Initialize global control interface
  102. * @global: Pointer to global data from wpa_supplicant_init()
  103. * Returns: Pointer to private data on success, %NULL on failure
  104. *
  105. * Initialize the global control interface and start receiving commands from
  106. * external programs.
  107. *
  108. * Required to be implemented in each control interface backend.
  109. */
  110. struct ctrl_iface_global_priv *
  111. wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global);
  112. /**
  113. * wpa_supplicant_global_ctrl_iface_deinit - Deinitialize global ctrl interface
  114. * @priv: Pointer to private data from wpa_supplicant_global_ctrl_iface_init()
  115. *
  116. * Deinitialize the global control interface that was initialized with
  117. * wpa_supplicant_global_ctrl_iface_init().
  118. *
  119. * Required to be implemented in each control interface backend.
  120. */
  121. void wpa_supplicant_global_ctrl_iface_deinit(
  122. struct ctrl_iface_global_priv *priv);
  123. #else /* CONFIG_CTRL_IFACE */
  124. static inline struct ctrl_iface_priv *
  125. wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
  126. {
  127. return (void *) -1;
  128. }
  129. static inline void
  130. wpa_supplicant_ctrl_iface_deinit(struct ctrl_iface_priv *priv)
  131. {
  132. }
  133. static inline void
  134. wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv, int level,
  135. char *buf, size_t len)
  136. {
  137. }
  138. static inline void
  139. wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv)
  140. {
  141. }
  142. static inline struct ctrl_iface_global_priv *
  143. wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
  144. {
  145. return (void *) 1;
  146. }
  147. static inline void
  148. wpa_supplicant_global_ctrl_iface_deinit(struct ctrl_iface_global_priv *priv)
  149. {
  150. }
  151. #endif /* CONFIG_CTRL_IFACE */
  152. #endif /* CTRL_IFACE_H */