我正在编写自己的C库来管理Linux中的wlan。我基于wpa_cli接口,但我无法理解,为什么它们使用两个wpa_ctrl结构:
static struct wpa_ctrl *ctrl_conn;
static struct wpa_ctrl *mon_conn;
当我仅打开并附加ctrl_conn吗?
wpa_cli
以两种方式起作用:交互式和非交互式
出现提示时,您将以wpa_cli
交互方式使用,反之亦然。
这是交互模式:
$ wpa_cli -i wlan0
wpa_cli v2.1
Copyright (c) 2004-2014, Jouni Malinen <[email protected]> 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_cli
使用ctrl_conn
和mon_conn
。ctrl_conn
仅用于发送命令,并mon_conn
用于获取事件(即,它是通过附加的事件wpa_ctrl_attach()
)。
当您使用非交互模式下,wpa_cli
仅使用ctrl_conn
,因为没有返回的事件。
如果您打算使用wpa_supplicant
事件(希望您会这样做),我认为最好使用两个不同的连接,如wpa_ctrl_request()
有关msg_cb参数的注释中所述:
/**
* 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));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句