1526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt/* 2526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * WPA Supplicant / UNIX domain socket -based control interface 3526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Copyright (c) 2004-2005, Jouni Malinen <j@w1.fi> 4526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 5526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * This program is free software; you can redistribute it and/or modify 6526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * it under the terms of the GNU General Public License version 2 as 7526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * published by the Free Software Foundation. 8526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 9526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Alternatively, this software may be distributed under the terms of BSD 10526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * license. 11526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 12526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * See README and COPYING for more details. 13526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt */ 14526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 15526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#ifndef CTRL_IFACE_H 16526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#define CTRL_IFACE_H 17526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 18526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#ifdef CONFIG_CTRL_IFACE 19526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 20526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt/* Shared functions from ctrl_iface.c; to be called by ctrl_iface backends */ 21526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 22526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt/** 23526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * wpa_supplicant_ctrl_iface_process - Process ctrl_iface command 24526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * @wpa_s: Pointer to wpa_supplicant data 25526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * @buf: Received command buffer (nul terminated string) 26526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * @resp_len: Variable to be set to the response length 27526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Returns: Response (*resp_len bytes) or %NULL on failure 28526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 29526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Control interface backends call this function when receiving a message that 30526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * they do not process internally, i.e., anything else than ATTACH, DETACH, 31526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * and LEVEL. The return response value is then sent to the external program 32526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * that sent the command. Caller is responsible for freeing the buffer after 33526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * this. If %NULL is returned, *resp_len can be set to two special values: 34526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 1 = send "FAIL\n" response, 2 = send "OK\n" response. If *resp_len has any 35526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * other value, no response is sent. 36526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt */ 37526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtchar * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, 38526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt char *buf, size_t *resp_len); 39526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 40526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt/** 41526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * wpa_supplicant_ctrl_iface_process - Process global ctrl_iface command 42526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * @global: Pointer to global data from wpa_supplicant_init() 43526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * @buf: Received command buffer (nul terminated string) 44526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * @resp_len: Variable to be set to the response length 45526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Returns: Response (*resp_len bytes) or %NULL on failure 46526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 47526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Control interface backends call this function when receiving a message from 48526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * the global ctrl_iface connection. The return response value is then sent to 49526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * the external program that sent the command. Caller is responsible for 50526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * freeing the buffer after this. If %NULL is returned, *resp_len can be set to 51526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * two special values: 1 = send "FAIL\n" response, 2 = send "OK\n" response. If 52526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * *resp_len has any other value, no response is sent. 53526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt */ 54526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtchar * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global, 55526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt char *buf, size_t *resp_len); 56526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 57526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 58526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt/* Functions that each ctrl_iface backend must implement */ 59526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 60526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt/** 61526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * wpa_supplicant_ctrl_iface_init - Initialize control interface 62526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * @wpa_s: Pointer to wpa_supplicant data 63526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Returns: Pointer to private data on success, %NULL on failure 64526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 65526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Initialize the control interface and start receiving commands from external 66526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * programs. 67526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 68526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Required to be implemented in each control interface backend. 69526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt */ 70526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtstruct ctrl_iface_priv * 71526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtwpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s); 72526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 73526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt/** 74526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * wpa_supplicant_ctrl_iface_deinit - Deinitialize control interface 75526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init() 76526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 77526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Deinitialize the control interface that was initialized with 78526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * wpa_supplicant_ctrl_iface_init(). 79526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 80526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Required to be implemented in each control interface backend. 81526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt */ 82526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtvoid wpa_supplicant_ctrl_iface_deinit(struct ctrl_iface_priv *priv); 83526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 84526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt/** 85526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * wpa_supplicant_ctrl_iface_wait - Wait for ctrl_iface monitor 86526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init() 87526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 88526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Wait until the first message from an external program using the control 89526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * interface is received. This function can be used to delay normal startup 90526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * processing to allow control interface programs to attach with 91526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * %wpa_supplicant before normal operations are started. 92526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 93526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Required to be implemented in each control interface backend. 94526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt */ 95526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtvoid wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv); 96526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 97526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt/** 98526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * wpa_supplicant_global_ctrl_iface_init - Initialize global control interface 99526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * @global: Pointer to global data from wpa_supplicant_init() 100526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Returns: Pointer to private data on success, %NULL on failure 101526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 102526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Initialize the global control interface and start receiving commands from 103526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * external programs. 104526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 105526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Required to be implemented in each control interface backend. 106526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt */ 107526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtstruct ctrl_iface_global_priv * 108526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtwpa_supplicant_global_ctrl_iface_init(struct wpa_global *global); 109526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 110526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt/** 111526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * wpa_supplicant_global_ctrl_iface_deinit - Deinitialize global ctrl interface 112526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * @priv: Pointer to private data from wpa_supplicant_global_ctrl_iface_init() 113526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 114526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Deinitialize the global control interface that was initialized with 115526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * wpa_supplicant_global_ctrl_iface_init(). 116526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * 117526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Required to be implemented in each control interface backend. 118526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt */ 119526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtvoid wpa_supplicant_global_ctrl_iface_deinit( 120526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt struct ctrl_iface_global_priv *priv); 121526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 122526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#else /* CONFIG_CTRL_IFACE */ 123526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 124526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtstatic inline struct ctrl_iface_priv * 125526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtwpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s) 126526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt{ 127526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt return (void *) -1; 128526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt} 129526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 130526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtstatic inline void 131526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtwpa_supplicant_ctrl_iface_deinit(struct ctrl_iface_priv *priv) 132526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt{ 133526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt} 134526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 135526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtstatic inline void 136526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtwpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv, int level, 137526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt char *buf, size_t len) 138526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt{ 139526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt} 140526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 141526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtstatic inline void 142526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtwpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv) 143526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt{ 144526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt} 145526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 146526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtstatic inline struct ctrl_iface_global_priv * 147526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtwpa_supplicant_global_ctrl_iface_init(struct wpa_global *global) 148526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt{ 149526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt return (void *) 1; 150526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt} 151526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 152526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtstatic inline void 153526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtwpa_supplicant_global_ctrl_iface_deinit(struct ctrl_iface_global_priv *priv) 154526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt{ 155526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt} 156526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 157526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#endif /* CONFIG_CTRL_IFACE */ 158526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt 159526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#endif /* CTRL_IFACE_H */ 160