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