xref: /freebsd/contrib/wpa/wpa_supplicant/ctrl_iface.h (revision 39beb93c3f8bdbf72a61fda42300b5ebed7390c8)
139beb93cSSam Leffler /*
239beb93cSSam Leffler  * WPA Supplicant / UNIX domain socket -based control interface
339beb93cSSam Leffler  * Copyright (c) 2004-2005, Jouni Malinen <j@w1.fi>
439beb93cSSam Leffler  *
539beb93cSSam Leffler  * This program is free software; you can redistribute it and/or modify
639beb93cSSam Leffler  * it under the terms of the GNU General Public License version 2 as
739beb93cSSam Leffler  * published by the Free Software Foundation.
839beb93cSSam Leffler  *
939beb93cSSam Leffler  * Alternatively, this software may be distributed under the terms of BSD
1039beb93cSSam Leffler  * license.
1139beb93cSSam Leffler  *
1239beb93cSSam Leffler  * See README and COPYING for more details.
1339beb93cSSam Leffler  */
1439beb93cSSam Leffler 
1539beb93cSSam Leffler #ifndef CTRL_IFACE_H
1639beb93cSSam Leffler #define CTRL_IFACE_H
1739beb93cSSam Leffler 
1839beb93cSSam Leffler #ifdef CONFIG_CTRL_IFACE
1939beb93cSSam Leffler 
2039beb93cSSam Leffler /* Shared functions from ctrl_iface.c; to be called by ctrl_iface backends */
2139beb93cSSam Leffler 
2239beb93cSSam Leffler /**
2339beb93cSSam Leffler  * wpa_supplicant_ctrl_iface_process - Process ctrl_iface command
2439beb93cSSam Leffler  * @wpa_s: Pointer to wpa_supplicant data
2539beb93cSSam Leffler  * @buf: Received command buffer (nul terminated string)
2639beb93cSSam Leffler  * @resp_len: Variable to be set to the response length
2739beb93cSSam Leffler  * Returns: Response (*resp_len bytes) or %NULL on failure
2839beb93cSSam Leffler  *
2939beb93cSSam Leffler  * Control interface backends call this function when receiving a message that
3039beb93cSSam Leffler  * they do not process internally, i.e., anything else than ATTACH, DETACH,
3139beb93cSSam Leffler  * and LEVEL. The return response value is then sent to the external program
3239beb93cSSam Leffler  * that sent the command. Caller is responsible for freeing the buffer after
3339beb93cSSam Leffler  * this. If %NULL is returned, *resp_len can be set to two special values:
3439beb93cSSam Leffler  * 1 = send "FAIL\n" response, 2 = send "OK\n" response. If *resp_len has any
3539beb93cSSam Leffler  * other value, no response is sent.
3639beb93cSSam Leffler  */
3739beb93cSSam Leffler char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
3839beb93cSSam Leffler 					 char *buf, size_t *resp_len);
3939beb93cSSam Leffler 
4039beb93cSSam Leffler /**
4139beb93cSSam Leffler  * wpa_supplicant_ctrl_iface_process - Process global ctrl_iface command
4239beb93cSSam Leffler  * @global: Pointer to global data from wpa_supplicant_init()
4339beb93cSSam Leffler  * @buf: Received command buffer (nul terminated string)
4439beb93cSSam Leffler  * @resp_len: Variable to be set to the response length
4539beb93cSSam Leffler  * Returns: Response (*resp_len bytes) or %NULL on failure
4639beb93cSSam Leffler  *
4739beb93cSSam Leffler  * Control interface backends call this function when receiving a message from
4839beb93cSSam Leffler  * the global ctrl_iface connection. The return response value is then sent to
4939beb93cSSam Leffler  * the external program that sent the command. Caller is responsible for
5039beb93cSSam Leffler  * freeing the buffer after this. If %NULL is returned, *resp_len can be set to
5139beb93cSSam Leffler  * two special values: 1 = send "FAIL\n" response, 2 = send "OK\n" response. If
5239beb93cSSam Leffler  * *resp_len has any other value, no response is sent.
5339beb93cSSam Leffler  */
5439beb93cSSam Leffler char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
5539beb93cSSam Leffler 						char *buf, size_t *resp_len);
5639beb93cSSam Leffler 
5739beb93cSSam Leffler 
5839beb93cSSam Leffler /* Functions that each ctrl_iface backend must implement */
5939beb93cSSam Leffler 
6039beb93cSSam Leffler /**
6139beb93cSSam Leffler  * wpa_supplicant_ctrl_iface_init - Initialize control interface
6239beb93cSSam Leffler  * @wpa_s: Pointer to wpa_supplicant data
6339beb93cSSam Leffler  * Returns: Pointer to private data on success, %NULL on failure
6439beb93cSSam Leffler  *
6539beb93cSSam Leffler  * Initialize the control interface and start receiving commands from external
6639beb93cSSam Leffler  * programs.
6739beb93cSSam Leffler  *
6839beb93cSSam Leffler  * Required to be implemented in each control interface backend.
6939beb93cSSam Leffler  */
7039beb93cSSam Leffler struct ctrl_iface_priv *
7139beb93cSSam Leffler wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s);
7239beb93cSSam Leffler 
7339beb93cSSam Leffler /**
7439beb93cSSam Leffler  * wpa_supplicant_ctrl_iface_deinit - Deinitialize control interface
7539beb93cSSam Leffler  * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init()
7639beb93cSSam Leffler  *
7739beb93cSSam Leffler  * Deinitialize the control interface that was initialized with
7839beb93cSSam Leffler  * wpa_supplicant_ctrl_iface_init().
7939beb93cSSam Leffler  *
8039beb93cSSam Leffler  * Required to be implemented in each control interface backend.
8139beb93cSSam Leffler  */
8239beb93cSSam Leffler void wpa_supplicant_ctrl_iface_deinit(struct ctrl_iface_priv *priv);
8339beb93cSSam Leffler 
8439beb93cSSam Leffler /**
8539beb93cSSam Leffler  * wpa_supplicant_ctrl_iface_wait - Wait for ctrl_iface monitor
8639beb93cSSam Leffler  * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init()
8739beb93cSSam Leffler  *
8839beb93cSSam Leffler  * Wait until the first message from an external program using the control
8939beb93cSSam Leffler  * interface is received. This function can be used to delay normal startup
9039beb93cSSam Leffler  * processing to allow control interface programs to attach with
9139beb93cSSam Leffler  * %wpa_supplicant before normal operations are started.
9239beb93cSSam Leffler  *
9339beb93cSSam Leffler  * Required to be implemented in each control interface backend.
9439beb93cSSam Leffler  */
9539beb93cSSam Leffler void wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv);
9639beb93cSSam Leffler 
9739beb93cSSam Leffler /**
9839beb93cSSam Leffler  * wpa_supplicant_global_ctrl_iface_init - Initialize global control interface
9939beb93cSSam Leffler  * @global: Pointer to global data from wpa_supplicant_init()
10039beb93cSSam Leffler  * Returns: Pointer to private data on success, %NULL on failure
10139beb93cSSam Leffler  *
10239beb93cSSam Leffler  * Initialize the global control interface and start receiving commands from
10339beb93cSSam Leffler  * external programs.
10439beb93cSSam Leffler  *
10539beb93cSSam Leffler  * Required to be implemented in each control interface backend.
10639beb93cSSam Leffler  */
10739beb93cSSam Leffler struct ctrl_iface_global_priv *
10839beb93cSSam Leffler wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global);
10939beb93cSSam Leffler 
11039beb93cSSam Leffler /**
11139beb93cSSam Leffler  * wpa_supplicant_global_ctrl_iface_deinit - Deinitialize global ctrl interface
11239beb93cSSam Leffler  * @priv: Pointer to private data from wpa_supplicant_global_ctrl_iface_init()
11339beb93cSSam Leffler  *
11439beb93cSSam Leffler  * Deinitialize the global control interface that was initialized with
11539beb93cSSam Leffler  * wpa_supplicant_global_ctrl_iface_init().
11639beb93cSSam Leffler  *
11739beb93cSSam Leffler  * Required to be implemented in each control interface backend.
11839beb93cSSam Leffler  */
11939beb93cSSam Leffler void wpa_supplicant_global_ctrl_iface_deinit(
12039beb93cSSam Leffler 	struct ctrl_iface_global_priv *priv);
12139beb93cSSam Leffler 
12239beb93cSSam Leffler #else /* CONFIG_CTRL_IFACE */
12339beb93cSSam Leffler 
12439beb93cSSam Leffler static inline struct ctrl_iface_priv *
12539beb93cSSam Leffler wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
12639beb93cSSam Leffler {
12739beb93cSSam Leffler 	return (void *) -1;
12839beb93cSSam Leffler }
12939beb93cSSam Leffler 
13039beb93cSSam Leffler static inline void
13139beb93cSSam Leffler wpa_supplicant_ctrl_iface_deinit(struct ctrl_iface_priv *priv)
13239beb93cSSam Leffler {
13339beb93cSSam Leffler }
13439beb93cSSam Leffler 
13539beb93cSSam Leffler static inline void
13639beb93cSSam Leffler wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv, int level,
13739beb93cSSam Leffler 			       char *buf, size_t len)
13839beb93cSSam Leffler {
13939beb93cSSam Leffler }
14039beb93cSSam Leffler 
14139beb93cSSam Leffler static inline void
14239beb93cSSam Leffler wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv)
14339beb93cSSam Leffler {
14439beb93cSSam Leffler }
14539beb93cSSam Leffler 
14639beb93cSSam Leffler static inline struct ctrl_iface_global_priv *
14739beb93cSSam Leffler wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
14839beb93cSSam Leffler {
14939beb93cSSam Leffler 	return (void *) 1;
15039beb93cSSam Leffler }
15139beb93cSSam Leffler 
15239beb93cSSam Leffler static inline void
15339beb93cSSam Leffler wpa_supplicant_global_ctrl_iface_deinit(struct ctrl_iface_global_priv *priv)
15439beb93cSSam Leffler {
15539beb93cSSam Leffler }
15639beb93cSSam Leffler 
15739beb93cSSam Leffler #endif /* CONFIG_CTRL_IFACE */
15839beb93cSSam Leffler 
15939beb93cSSam Leffler #endif /* CTRL_IFACE_H */
160