1 /*
2 * WPA Supplicant / UNIX domain socket -based control interface
3 * Copyright (c) 2004-2020, 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
9 #ifndef CTRL_IFACE_H
10 #define CTRL_IFACE_H
11
12 #ifdef CONFIG_CTRL_IFACE
13 #ifdef LOS_CONFIG_P2P
14 #define MAX_WPA_P2P_PEER_NUM 64
15 #endif
16 #ifdef LOS_WPA_PATCH
17
18 struct ctrl_iface_priv {
19 struct wpa_supplicant *wpa_s;
20 int sock;
21 #ifndef LOS_WPA_EVENT_CALLBAK
22 struct dl_list ctrl_dst;
23 #endif /* LOS_WPA_EVENT_CALLBAK */
24 void *event_queue;
25 };
26
27 struct ctrl_iface_global_priv {
28 struct wpa_global *global;
29 int sock;
30 #ifndef LOS_WPA_EVENT_CALLBAK
31 struct dl_list ctrl_dst;
32 #endif /* LOS_WPA_EVENT_CALLBAK */
33 };
34
35 struct ctrl_iface_event_buf {
36 struct wpa_supplicant *wpa_s;
37 char* buf;
38 };
39
40 extern struct ctrl_iface_priv *g_ctrl_iface_data;
41 #endif /* LOS_WPA_PATCH */
42
43 #ifndef CTRL_IFACE_MAX_LEN
44 #define CTRL_IFACE_MAX_LEN 8192
45 #endif /* CTRL_IFACE_MAX_LEN */
46
47 /* Shared functions from ctrl_iface.c; to be called by ctrl_iface backends */
48
49 /**
50 * wpa_supplicant_ctrl_iface_process - Process ctrl_iface command
51 * @wpa_s: Pointer to wpa_supplicant data
52 * @buf: Received command buffer (nul terminated string)
53 * @resp_len: Variable to be set to the response length
54 * Returns: Response (*resp_len bytes) or %NULL on failure
55 *
56 * Control interface backends call this function when receiving a message that
57 * they do not process internally, i.e., anything else than ATTACH, DETACH,
58 * and LEVEL. The return response value is then sent to the external program
59 * that sent the command. Caller is responsible for freeing the buffer after
60 * this. If %NULL is returned, *resp_len can be set to two special values:
61 * 1 = send "FAIL\n" response, 2 = send "OK\n" response. If *resp_len has any
62 * other value, no response is sent.
63 */
64 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
65 char *buf, size_t *resp_len);
66
67 /**
68 * wpa_supplicant_global_ctrl_iface_process - Process global ctrl_iface command
69 * @global: Pointer to global data from wpa_supplicant_init()
70 * @buf: Received command buffer (nul terminated string)
71 * @resp_len: Variable to be set to the response length
72 * Returns: Response (*resp_len bytes) or %NULL on failure
73 *
74 * Control interface backends call this function when receiving a message from
75 * the global ctrl_iface connection. The return response value is then sent to
76 * the external program that sent the command. Caller is responsible for
77 * freeing the buffer after this. If %NULL is returned, *resp_len can be set to
78 * two special values: 1 = send "FAIL\n" response, 2 = send "OK\n" response. If
79 * *resp_len has any other value, no response is sent.
80 */
81 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
82 char *buf, size_t *resp_len);
83
84
85 /* Functions that each ctrl_iface backend must implement */
86
87 #ifdef LOS_WPA_PATCH
88 struct ctrl_iface_priv *los_ctrl_iface_init(void *data);
89 #endif /* LOS_WPA_PATCH */
90
91 /**
92 * wpa_supplicant_ctrl_iface_init - Initialize control interface
93 * @wpa_s: Pointer to wpa_supplicant data
94 * Returns: Pointer to private data on success, %NULL on failure
95 *
96 * Initialize the control interface and start receiving commands from external
97 * programs.
98 *
99 * Required to be implemented in each control interface backend.
100 */
101 struct ctrl_iface_priv *
102 wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s);
103
104 /**
105 * wpa_supplicant_ctrl_iface_deinit - Deinitialize control interface
106 * @wpa_s: Pointer to wpa_supplicant data
107 * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init()
108 *
109 * Deinitialize the control interface that was initialized with
110 * wpa_supplicant_ctrl_iface_init() and any data related to the wpa_s instance.
111 * @priv may be %NULL if the control interface has not yet been initialized.
112 *
113 * Required to be implemented in each control interface backend.
114 */
115 void wpa_supplicant_ctrl_iface_deinit(struct wpa_supplicant *wpa_s,
116 struct ctrl_iface_priv *priv);
117
118 /**
119 * wpa_supplicant_ctrl_iface_wait - Wait for ctrl_iface monitor
120 * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init()
121 *
122 * Wait until the first message from an external program using the control
123 * interface is received. This function can be used to delay normal startup
124 * processing to allow control interface programs to attach with
125 * %wpa_supplicant before normal operations are started.
126 *
127 * Required to be implemented in each control interface backend.
128 */
129 void wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv);
130
131 /**
132 * wpa_supplicant_global_ctrl_iface_init - Initialize global control interface
133 * @global: Pointer to global data from wpa_supplicant_init()
134 * Returns: Pointer to private data on success, %NULL on failure
135 *
136 * Initialize the global control interface and start receiving commands from
137 * external programs.
138 *
139 * Required to be implemented in each control interface backend.
140 */
141 struct ctrl_iface_global_priv *
142 wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global);
143
144 /**
145 * wpa_supplicant_global_ctrl_iface_deinit - Deinitialize global ctrl interface
146 * @priv: Pointer to private data from wpa_supplicant_global_ctrl_iface_init()
147 *
148 * Deinitialize the global control interface that was initialized with
149 * wpa_supplicant_global_ctrl_iface_init().
150 *
151 * Required to be implemented in each control interface backend.
152 */
153 void wpa_supplicant_global_ctrl_iface_deinit(
154 struct ctrl_iface_global_priv *priv);
155 #ifndef EXT_CODE_CROP
156 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s);
157 #endif /* EXT_CODE_CROP */
158 #else /* CONFIG_CTRL_IFACE */
159
160 static inline struct ctrl_iface_priv *
wpa_supplicant_ctrl_iface_init(struct wpa_supplicant * wpa_s)161 wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
162 {
163 return (void *) -1;
164 }
165
166 static inline void
wpa_supplicant_ctrl_iface_deinit(struct wpa_supplicant * wpa_s,struct ctrl_iface_priv * priv)167 wpa_supplicant_ctrl_iface_deinit(struct wpa_supplicant *wpa_s,
168 struct ctrl_iface_priv *priv)
169 {
170 }
171
172 static inline void
wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv * priv,int level,char * buf,size_t len)173 wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv, int level,
174 char *buf, size_t len)
175 {
176 }
177
178 static inline void
wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv * priv)179 wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv)
180 {
181 }
182
183 static inline struct ctrl_iface_global_priv *
wpa_supplicant_global_ctrl_iface_init(struct wpa_global * global)184 wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
185 {
186 return (void *) 1;
187 }
188
189 static inline void
wpa_supplicant_global_ctrl_iface_deinit(struct ctrl_iface_global_priv * priv)190 wpa_supplicant_global_ctrl_iface_deinit(struct ctrl_iface_global_priv *priv)
191 {
192 }
193 #ifndef EXT_CODE_CROP
wpas_ctrl_radio_work_flush(struct wpa_supplicant * wpa_s)194 static inline void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
195 {
196 }
197 #endif /* EXT_CODE_CROP */
198 #endif /* CONFIG_CTRL_IFACE */
199 #ifdef LOS_WPA_PATCH
200 #ifndef LOS_WPA_EVENT_CALLBAK
201 void wpa_supplicant_ctrl_iface_msg_cb(void *ctx, int level, int global,
202 const char *txt, size_t len);
203
204 extern void hostapd_ctrl_iface_msg_cb(void *ctx, int level, int global,
205 const char *txt, size_t len);
206 #endif /* LOS_WPA_EVENT_CALLBAK */
207 #ifdef LOS_CONFIG_MESH
208 void wpa_mesh_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
209 char *reply, int reply_size, int *reply_len);
210 #endif /* LOS_CONFIG_MESH */
211 #endif /* LOS_WPA_PATCH */
212 #endif /* CTRL_IFACE_H */
213