ctrl_iface.h 5.3 KB

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