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