1189251Ssam/*
2189251Ssam * WPA Supplicant / UNIX domain socket -based control interface
3189251Ssam * Copyright (c) 2004-2005, Jouni Malinen <j@w1.fi>
4189251Ssam *
5252726Srpaulo * This software may be distributed under the terms of the BSD license.
6252726Srpaulo * See README for more details.
7189251Ssam */
8189251Ssam
9189251Ssam#ifndef CTRL_IFACE_H
10189251Ssam#define CTRL_IFACE_H
11189251Ssam
12189251Ssam#ifdef CONFIG_CTRL_IFACE
13189251Ssam
14189251Ssam/* Shared functions from ctrl_iface.c; to be called by ctrl_iface backends */
15189251Ssam
16189251Ssam/**
17189251Ssam * wpa_supplicant_ctrl_iface_process - Process ctrl_iface command
18189251Ssam * @wpa_s: Pointer to wpa_supplicant data
19189251Ssam * @buf: Received command buffer (nul terminated string)
20189251Ssam * @resp_len: Variable to be set to the response length
21189251Ssam * Returns: Response (*resp_len bytes) or %NULL on failure
22189251Ssam *
23189251Ssam * Control interface backends call this function when receiving a message that
24189251Ssam * they do not process internally, i.e., anything else than ATTACH, DETACH,
25189251Ssam * and LEVEL. The return response value is then sent to the external program
26189251Ssam * that sent the command. Caller is responsible for freeing the buffer after
27189251Ssam * this. If %NULL is returned, *resp_len can be set to two special values:
28189251Ssam * 1 = send "FAIL\n" response, 2 = send "OK\n" response. If *resp_len has any
29189251Ssam * other value, no response is sent.
30189251Ssam */
31189251Ssamchar * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
32189251Ssam					 char *buf, size_t *resp_len);
33189251Ssam
34189251Ssam/**
35189251Ssam * wpa_supplicant_ctrl_iface_process - Process global ctrl_iface command
36189251Ssam * @global: Pointer to global data from wpa_supplicant_init()
37189251Ssam * @buf: Received command buffer (nul terminated string)
38189251Ssam * @resp_len: Variable to be set to the response length
39189251Ssam * Returns: Response (*resp_len bytes) or %NULL on failure
40189251Ssam *
41189251Ssam * Control interface backends call this function when receiving a message from
42189251Ssam * the global ctrl_iface connection. The return response value is then sent to
43189251Ssam * the external program that sent the command. Caller is responsible for
44189251Ssam * freeing the buffer after this. If %NULL is returned, *resp_len can be set to
45189251Ssam * two special values: 1 = send "FAIL\n" response, 2 = send "OK\n" response. If
46189251Ssam * *resp_len has any other value, no response is sent.
47189251Ssam */
48189251Ssamchar * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
49189251Ssam						char *buf, size_t *resp_len);
50189251Ssam
51189251Ssam
52189251Ssam/* Functions that each ctrl_iface backend must implement */
53189251Ssam
54189251Ssam/**
55189251Ssam * wpa_supplicant_ctrl_iface_init - Initialize control interface
56189251Ssam * @wpa_s: Pointer to wpa_supplicant data
57189251Ssam * Returns: Pointer to private data on success, %NULL on failure
58189251Ssam *
59189251Ssam * Initialize the control interface and start receiving commands from external
60189251Ssam * programs.
61189251Ssam *
62189251Ssam * Required to be implemented in each control interface backend.
63189251Ssam */
64189251Ssamstruct ctrl_iface_priv *
65189251Ssamwpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s);
66189251Ssam
67189251Ssam/**
68189251Ssam * wpa_supplicant_ctrl_iface_deinit - Deinitialize control interface
69189251Ssam * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init()
70189251Ssam *
71189251Ssam * Deinitialize the control interface that was initialized with
72189251Ssam * wpa_supplicant_ctrl_iface_init().
73189251Ssam *
74189251Ssam * Required to be implemented in each control interface backend.
75189251Ssam */
76189251Ssamvoid wpa_supplicant_ctrl_iface_deinit(struct ctrl_iface_priv *priv);
77189251Ssam
78189251Ssam/**
79189251Ssam * wpa_supplicant_ctrl_iface_wait - Wait for ctrl_iface monitor
80189251Ssam * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init()
81189251Ssam *
82189251Ssam * Wait until the first message from an external program using the control
83189251Ssam * interface is received. This function can be used to delay normal startup
84189251Ssam * processing to allow control interface programs to attach with
85189251Ssam * %wpa_supplicant before normal operations are started.
86189251Ssam *
87189251Ssam * Required to be implemented in each control interface backend.
88189251Ssam */
89189251Ssamvoid wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv);
90189251Ssam
91189251Ssam/**
92189251Ssam * wpa_supplicant_global_ctrl_iface_init - Initialize global control interface
93189251Ssam * @global: Pointer to global data from wpa_supplicant_init()
94189251Ssam * Returns: Pointer to private data on success, %NULL on failure
95189251Ssam *
96189251Ssam * Initialize the global control interface and start receiving commands from
97189251Ssam * external programs.
98189251Ssam *
99189251Ssam * Required to be implemented in each control interface backend.
100189251Ssam */
101189251Ssamstruct ctrl_iface_global_priv *
102189251Ssamwpa_supplicant_global_ctrl_iface_init(struct wpa_global *global);
103189251Ssam
104189251Ssam/**
105189251Ssam * wpa_supplicant_global_ctrl_iface_deinit - Deinitialize global ctrl interface
106189251Ssam * @priv: Pointer to private data from wpa_supplicant_global_ctrl_iface_init()
107189251Ssam *
108189251Ssam * Deinitialize the global control interface that was initialized with
109189251Ssam * wpa_supplicant_global_ctrl_iface_init().
110189251Ssam *
111189251Ssam * Required to be implemented in each control interface backend.
112189251Ssam */
113189251Ssamvoid wpa_supplicant_global_ctrl_iface_deinit(
114189251Ssam	struct ctrl_iface_global_priv *priv);
115189251Ssam
116189251Ssam#else /* CONFIG_CTRL_IFACE */
117189251Ssam
118189251Ssamstatic inline struct ctrl_iface_priv *
119189251Ssamwpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
120189251Ssam{
121189251Ssam	return (void *) -1;
122189251Ssam}
123189251Ssam
124189251Ssamstatic inline void
125189251Ssamwpa_supplicant_ctrl_iface_deinit(struct ctrl_iface_priv *priv)
126189251Ssam{
127189251Ssam}
128189251Ssam
129189251Ssamstatic inline void
130189251Ssamwpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv, int level,
131189251Ssam			       char *buf, size_t len)
132189251Ssam{
133189251Ssam}
134189251Ssam
135189251Ssamstatic inline void
136189251Ssamwpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv)
137189251Ssam{
138189251Ssam}
139189251Ssam
140189251Ssamstatic inline struct ctrl_iface_global_priv *
141189251Ssamwpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
142189251Ssam{
143189251Ssam	return (void *) 1;
144189251Ssam}
145189251Ssam
146189251Ssamstatic inline void
147189251Ssamwpa_supplicant_global_ctrl_iface_deinit(struct ctrl_iface_global_priv *priv)
148189251Ssam{
149189251Ssam}
150189251Ssam
151189251Ssam#endif /* CONFIG_CTRL_IFACE */
152189251Ssam
153189251Ssam#endif /* CTRL_IFACE_H */
154