blob: 9842ea1e71e67a771da785162358a4d5de586040 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant / UNIX domain socket -based control interface
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003 * Copyright (c) 2004-2020, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#ifndef CTRL_IFACE_H
10#define CTRL_IFACE_H
11
12#ifdef CONFIG_CTRL_IFACE
13
Hai Shalom4fbc08f2020-05-18 12:37:00 -070014#ifndef CTRL_IFACE_MAX_LEN
15#define CTRL_IFACE_MAX_LEN 8192
16#endif /* CTRL_IFACE_MAX_LEN */
17
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018/* Shared functions from ctrl_iface.c; to be called by ctrl_iface backends */
19
20/**
21 * wpa_supplicant_ctrl_iface_process - Process ctrl_iface command
22 * @wpa_s: Pointer to wpa_supplicant data
23 * @buf: Received command buffer (nul terminated string)
24 * @resp_len: Variable to be set to the response length
25 * Returns: Response (*resp_len bytes) or %NULL on failure
26 *
27 * Control interface backends call this function when receiving a message that
28 * they do not process internally, i.e., anything else than ATTACH, DETACH,
29 * and LEVEL. The return response value is then sent to the external program
30 * that sent the command. Caller is responsible for freeing the buffer after
31 * this. If %NULL is returned, *resp_len can be set to two special values:
32 * 1 = send "FAIL\n" response, 2 = send "OK\n" response. If *resp_len has any
33 * other value, no response is sent.
34 */
35char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
36 char *buf, size_t *resp_len);
37
38/**
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080039 * wpa_supplicant_global_ctrl_iface_process - Process global ctrl_iface command
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040 * @global: Pointer to global data from wpa_supplicant_init()
41 * @buf: Received command buffer (nul terminated string)
42 * @resp_len: Variable to be set to the response length
43 * Returns: Response (*resp_len bytes) or %NULL on failure
44 *
45 * Control interface backends call this function when receiving a message from
46 * the global ctrl_iface connection. The return response value is then sent to
47 * the external program that sent the command. Caller is responsible for
48 * freeing the buffer after this. If %NULL is returned, *resp_len can be set to
49 * two special values: 1 = send "FAIL\n" response, 2 = send "OK\n" response. If
50 * *resp_len has any other value, no response is sent.
51 */
52char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
53 char *buf, size_t *resp_len);
54
55
56/* Functions that each ctrl_iface backend must implement */
57
58/**
59 * wpa_supplicant_ctrl_iface_init - Initialize control interface
60 * @wpa_s: Pointer to wpa_supplicant data
61 * Returns: Pointer to private data on success, %NULL on failure
62 *
63 * Initialize the control interface and start receiving commands from external
64 * programs.
65 *
66 * Required to be implemented in each control interface backend.
67 */
68struct ctrl_iface_priv *
69wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s);
70
71/**
72 * wpa_supplicant_ctrl_iface_deinit - Deinitialize control interface
Jouni Malinenf3f8d3c2021-02-05 00:28:17 +020073 * @wpa_s: Pointer to wpa_supplicant data
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070074 * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init()
75 *
76 * Deinitialize the control interface that was initialized with
Jouni Malinenf3f8d3c2021-02-05 00:28:17 +020077 * wpa_supplicant_ctrl_iface_init() and any data related to the wpa_s instance.
78 * @priv may be %NULL if the control interface has not yet been initialized.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070079 *
80 * Required to be implemented in each control interface backend.
81 */
Jouni Malinenf3f8d3c2021-02-05 00:28:17 +020082void wpa_supplicant_ctrl_iface_deinit(struct wpa_supplicant *wpa_s,
83 struct ctrl_iface_priv *priv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070084
85/**
86 * wpa_supplicant_ctrl_iface_wait - Wait for ctrl_iface monitor
87 * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init()
88 *
89 * Wait until the first message from an external program using the control
90 * interface is received. This function can be used to delay normal startup
91 * processing to allow control interface programs to attach with
92 * %wpa_supplicant before normal operations are started.
93 *
94 * Required to be implemented in each control interface backend.
95 */
96void wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv);
97
98/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070099 * wpa_supplicant_global_ctrl_iface_init - Initialize global control interface
100 * @global: Pointer to global data from wpa_supplicant_init()
101 * Returns: Pointer to private data on success, %NULL on failure
102 *
103 * Initialize the global control interface and start receiving commands from
104 * external programs.
105 *
106 * Required to be implemented in each control interface backend.
107 */
108struct ctrl_iface_global_priv *
109wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global);
110
111/**
112 * wpa_supplicant_global_ctrl_iface_deinit - Deinitialize global ctrl interface
113 * @priv: Pointer to private data from wpa_supplicant_global_ctrl_iface_init()
114 *
115 * Deinitialize the global control interface that was initialized with
116 * wpa_supplicant_global_ctrl_iface_init().
117 *
118 * Required to be implemented in each control interface backend.
119 */
120void wpa_supplicant_global_ctrl_iface_deinit(
121 struct ctrl_iface_global_priv *priv);
122
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800123void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s);
124
Sunil Ravia04bd252022-05-02 22:54:18 -0700125int wpas_ctrl_cmd_debug_level(const char *cmd);
126
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700127#else /* CONFIG_CTRL_IFACE */
128
129static inline struct ctrl_iface_priv *
130wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
131{
132 return (void *) -1;
133}
134
135static inline void
Hai Shaloma20dcd72022-02-04 13:43:00 -0800136wpa_supplicant_ctrl_iface_deinit(struct wpa_supplicant *wpa_s,
137 struct ctrl_iface_priv *priv)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700138{
139}
140
141static inline void
142wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv, int level,
143 char *buf, size_t len)
144{
145}
146
147static inline void
148wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv)
149{
150}
151
152static inline struct ctrl_iface_global_priv *
153wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
154{
155 return (void *) 1;
156}
157
158static inline void
159wpa_supplicant_global_ctrl_iface_deinit(struct ctrl_iface_global_priv *priv)
160{
161}
162
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800163static inline void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
164{
165}
166
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700167#endif /* CONFIG_CTRL_IFACE */
168
169#endif /* CTRL_IFACE_H */