1 /* 2 * WPA Supplicant / UNIX domain socket -based control interface 3 * Copyright (c) 2004-2005, 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 14 /* Shared functions from ctrl_iface.c; to be called by ctrl_iface backends */ 15 16 /** 17 * wpa_supplicant_ctrl_iface_process - Process ctrl_iface command 18 * @wpa_s: Pointer to wpa_supplicant data 19 * @buf: Received command buffer (nul terminated string) 20 * @resp_len: Variable to be set to the response length 21 * Returns: Response (*resp_len bytes) or %NULL on failure 22 * 23 * Control interface backends call this function when receiving a message that 24 * they do not process internally, i.e., anything else than ATTACH, DETACH, 25 * and LEVEL. The return response value is then sent to the external program 26 * that sent the command. Caller is responsible for freeing the buffer after 27 * this. If %NULL is returned, *resp_len can be set to two special values: 28 * 1 = send "FAIL\n" response, 2 = send "OK\n" response. If *resp_len has any 29 * other value, no response is sent. 30 */ 31 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, 32 char *buf, size_t *resp_len); 33 34 /** 35 * wpa_supplicant_global_ctrl_iface_process - Process global ctrl_iface command 36 * @global: Pointer to global data from wpa_supplicant_init() 37 * @buf: Received command buffer (nul terminated string) 38 * @resp_len: Variable to be set to the response length 39 * Returns: Response (*resp_len bytes) or %NULL on failure 40 * 41 * Control interface backends call this function when receiving a message from 42 * the global ctrl_iface connection. The return response value is then sent to 43 * the external program that sent the command. Caller is responsible for 44 * freeing the buffer after this. If %NULL is returned, *resp_len can be set to 45 * two special values: 1 = send "FAIL\n" response, 2 = send "OK\n" response. If 46 * *resp_len has any other value, no response is sent. 47 */ 48 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global, 49 char *buf, size_t *resp_len); 50 51 52 /* Functions that each ctrl_iface backend must implement */ 53 54 /** 55 * wpa_supplicant_ctrl_iface_init - Initialize control interface 56 * @wpa_s: Pointer to wpa_supplicant data 57 * Returns: Pointer to private data on success, %NULL on failure 58 * 59 * Initialize the control interface and start receiving commands from external 60 * programs. 61 * 62 * Required to be implemented in each control interface backend. 63 */ 64 struct ctrl_iface_priv * 65 wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s); 66 67 /** 68 * wpa_supplicant_ctrl_iface_deinit - Deinitialize control interface 69 * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init() 70 * 71 * Deinitialize the control interface that was initialized with 72 * wpa_supplicant_ctrl_iface_init(). 73 * 74 * Required to be implemented in each control interface backend. 75 */ 76 void wpa_supplicant_ctrl_iface_deinit(struct ctrl_iface_priv *priv); 77 78 /** 79 * wpa_supplicant_ctrl_iface_wait - Wait for ctrl_iface monitor 80 * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init() 81 * 82 * Wait until the first message from an external program using the control 83 * interface is received. This function can be used to delay normal startup 84 * processing to allow control interface programs to attach with 85 * %wpa_supplicant before normal operations are started. 86 * 87 * Required to be implemented in each control interface backend. 88 */ 89 void wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv); 90 91 /** 92 * wpa_supplicant_global_ctrl_iface_init - Initialize global control interface 93 * @global: Pointer to global data from wpa_supplicant_init() 94 * Returns: Pointer to private data on success, %NULL on failure 95 * 96 * Initialize the global control interface and start receiving commands from 97 * external programs. 98 * 99 * Required to be implemented in each control interface backend. 100 */ 101 struct ctrl_iface_global_priv * 102 wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global); 103 104 /** 105 * wpa_supplicant_global_ctrl_iface_deinit - Deinitialize global ctrl interface 106 * @priv: Pointer to private data from wpa_supplicant_global_ctrl_iface_init() 107 * 108 * Deinitialize the global control interface that was initialized with 109 * wpa_supplicant_global_ctrl_iface_init(). 110 * 111 * Required to be implemented in each control interface backend. 112 */ 113 void wpa_supplicant_global_ctrl_iface_deinit( 114 struct ctrl_iface_global_priv *priv); 115 116 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s); 117 118 #else /* CONFIG_CTRL_IFACE */ 119 120 static inline struct ctrl_iface_priv * 121 wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s) 122 { 123 return (void *) -1; 124 } 125 126 static inline void 127 wpa_supplicant_ctrl_iface_deinit(struct ctrl_iface_priv *priv) 128 { 129 } 130 131 static inline void 132 wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv, int level, 133 char *buf, size_t len) 134 { 135 } 136 137 static inline void 138 wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv) 139 { 140 } 141 142 static inline struct ctrl_iface_global_priv * 143 wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global) 144 { 145 return (void *) 1; 146 } 147 148 static inline void 149 wpa_supplicant_global_ctrl_iface_deinit(struct ctrl_iface_global_priv *priv) 150 { 151 } 152 153 static inline void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s) 154 { 155 } 156 157 #endif /* CONFIG_CTRL_IFACE */ 158 159 #endif /* CTRL_IFACE_H */ 160