Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 为什么我需要两个不同的wpa_请求连接(wpa_cli-ctrl_conn和mon_conn)_Linux_Embedded Linux_Wireless_Wpa - Fatal编程技术网

Linux 为什么我需要两个不同的wpa_请求连接(wpa_cli-ctrl_conn和mon_conn)

Linux 为什么我需要两个不同的wpa_请求连接(wpa_cli-ctrl_conn和mon_conn),linux,embedded-linux,wireless,wpa,Linux,Embedded Linux,Wireless,Wpa,我正在编写自己的C库来管理linux中的wlan。我基于wpa_cli接口,但我不明白,为什么他们使用两种wpa_ctrl结构: static struct wpa_ctrl *ctrl_conn; static struct wpa_ctrl *mon_conn; 当我仅使用ctrl_conn打开并连接时,它也可以工作。wpa_cli有两种工作方式:交互式和非交互式 当出现提示时,您正在以交互方式使用wpa\u cli,反之亦然 以下是互动模式: $ wpa_cli -i wlan0 wpa

我正在编写自己的C库来管理linux中的wlan。我基于wpa_cli接口,但我不明白,为什么他们使用两种wpa_ctrl结构:

static struct wpa_ctrl *ctrl_conn;
static struct wpa_ctrl *mon_conn;

当我仅使用ctrl_conn打开并连接时,它也可以工作。

wpa_cli
有两种工作方式:交互式非交互式

当出现提示时,您正在以交互方式使用
wpa\u cli
,反之亦然

以下是互动模式:

$ wpa_cli -i wlan0
wpa_cli v2.1
Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi> and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.

Interactive mode

> status
wpa_state=INACTIVE
address=98:fc:11:d1:89:68
uuid=0cb62eb3-776e-55d2-a4f9-983cdd3e48d2
$ wpa_cli -i wlan0 status
wpa_state=INACTIVE
address=98:fc:11:d1:89:68
uuid=0cb62eb3-776e-55d2-a4f9-983cdd3e48d2
似乎在使用交互式模式时,
wpa\u cli
同时使用
ctrl\u conn
mon\u conn
ctrl\u-conn
仅用于发送命令,
mon\u-conn
用于获取事件(即它是通过
wpa\u-ctrl\u-attach()
附加的事件)

当您使用非交互式模式时,
wpa_cli
只使用
ctrl_conn
,因为没有返回任何事件

如果您计划使用
wpa\u-suplicant
事件(我希望您会这样做),我认为最好使用两个不同的连接,如
wpa\u-ctrl\u-request()
中所述:


如何回答这个问题?请看
/**
 * wpa_ctrl_request - Send a command to wpa_supplicant/hostapd
 * @ctrl: Control interface data from wpa_ctrl_open()
 * @cmd: Command; usually, ASCII text, e.g., "PING"
 * @cmd_len: Length of the cmd in bytes
 * @reply: Buffer for the response
 * @reply_len: Reply buffer length
 * @msg_cb: Callback function for unsolicited messages or %NULL if not used
 * Returns: 0 on success, -1 on error (send or receive failed), -2 on timeout
 *
 * This function is used to send commands to wpa_supplicant/hostapd. Received
 * response will be written to reply and reply_len is set to the actual length
 * of the reply. This function will block for up to two seconds while waiting
 * for the reply. If unsolicited messages are received, the blocking time may
 * be longer.
 *
 * msg_cb can be used to register a callback function that will be called for
 * unsolicited messages received while waiting for the command response. These
 * messages may be received if wpa_ctrl_request() is called at the same time as
 * wpa_supplicant/hostapd is sending such a message. This can happen only if
 * the program has used wpa_ctrl_attach() to register itself as a monitor for
 * event messages. Alternatively to msg_cb, programs can register two control
 * interface connections and use one of them for commands and the other one for
 * receiving event messages, in other words, call wpa_ctrl_attach() only for
 * the control interface connection that will be used for event messages.
 */
int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
             char *reply, size_t *reply_len,
             void (*msg_cb)(char *msg, size_t len));