hostapd: Add hostapd_ctrl_iface_receive_process()
The newly introduced function will be used in followup commits to handle requests redirected from the global control interface. Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
parent
2531dc9f6b
commit
585478e2b9
1 changed files with 53 additions and 36 deletions
|
@ -1930,40 +1930,13 @@ static int hostapd_ctrl_iface_eapol_set(struct hostapd_data *hapd, char *cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
|
static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
|
||||||
void *sock_ctx)
|
char *buf, char *reply,
|
||||||
|
int reply_size,
|
||||||
|
struct sockaddr_un *from,
|
||||||
|
socklen_t fromlen)
|
||||||
{
|
{
|
||||||
struct hostapd_data *hapd = eloop_ctx;
|
int reply_len, res;
|
||||||
char buf[4096];
|
|
||||||
int res;
|
|
||||||
struct sockaddr_un from;
|
|
||||||
socklen_t fromlen = sizeof(from);
|
|
||||||
char *reply;
|
|
||||||
const int reply_size = 4096;
|
|
||||||
int reply_len;
|
|
||||||
int level = MSG_DEBUG;
|
|
||||||
|
|
||||||
res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
|
|
||||||
(struct sockaddr *) &from, &fromlen);
|
|
||||||
if (res < 0) {
|
|
||||||
wpa_printf(MSG_ERROR, "recvfrom(ctrl_iface): %s",
|
|
||||||
strerror(errno));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
buf[res] = '\0';
|
|
||||||
if (os_strcmp(buf, "PING") == 0)
|
|
||||||
level = MSG_EXCESSIVE;
|
|
||||||
wpa_hexdump_ascii(level, "RX ctrl_iface", (u8 *) buf, res);
|
|
||||||
|
|
||||||
reply = os_malloc(reply_size);
|
|
||||||
if (reply == NULL) {
|
|
||||||
if (sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
|
|
||||||
fromlen) < 0) {
|
|
||||||
wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
|
|
||||||
strerror(errno));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
os_memcpy(reply, "OK\n", 3);
|
os_memcpy(reply, "OK\n", 3);
|
||||||
reply_len = 3;
|
reply_len = 3;
|
||||||
|
@ -2021,13 +1994,13 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
|
||||||
reply_len = hostapd_ctrl_iface_sta_next(hapd, buf + 9, reply,
|
reply_len = hostapd_ctrl_iface_sta_next(hapd, buf + 9, reply,
|
||||||
reply_size);
|
reply_size);
|
||||||
} else if (os_strcmp(buf, "ATTACH") == 0) {
|
} else if (os_strcmp(buf, "ATTACH") == 0) {
|
||||||
if (hostapd_ctrl_iface_attach(hapd, &from, fromlen))
|
if (hostapd_ctrl_iface_attach(hapd, from, fromlen))
|
||||||
reply_len = -1;
|
reply_len = -1;
|
||||||
} else if (os_strcmp(buf, "DETACH") == 0) {
|
} else if (os_strcmp(buf, "DETACH") == 0) {
|
||||||
if (hostapd_ctrl_iface_detach(hapd, &from, fromlen))
|
if (hostapd_ctrl_iface_detach(hapd, from, fromlen))
|
||||||
reply_len = -1;
|
reply_len = -1;
|
||||||
} else if (os_strncmp(buf, "LEVEL ", 6) == 0) {
|
} else if (os_strncmp(buf, "LEVEL ", 6) == 0) {
|
||||||
if (hostapd_ctrl_iface_level(hapd, &from, fromlen,
|
if (hostapd_ctrl_iface_level(hapd, from, fromlen,
|
||||||
buf + 6))
|
buf + 6))
|
||||||
reply_len = -1;
|
reply_len = -1;
|
||||||
} else if (os_strncmp(buf, "NEW_STA ", 8) == 0) {
|
} else if (os_strncmp(buf, "NEW_STA ", 8) == 0) {
|
||||||
|
@ -2194,6 +2167,50 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
|
||||||
os_memcpy(reply, "FAIL\n", 5);
|
os_memcpy(reply, "FAIL\n", 5);
|
||||||
reply_len = 5;
|
reply_len = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return reply_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
|
||||||
|
void *sock_ctx)
|
||||||
|
{
|
||||||
|
struct hostapd_data *hapd = eloop_ctx;
|
||||||
|
char buf[4096];
|
||||||
|
int res;
|
||||||
|
struct sockaddr_un from;
|
||||||
|
socklen_t fromlen = sizeof(from);
|
||||||
|
char *reply;
|
||||||
|
const int reply_size = 4096;
|
||||||
|
int reply_len;
|
||||||
|
int level = MSG_DEBUG;
|
||||||
|
|
||||||
|
res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
|
||||||
|
(struct sockaddr *) &from, &fromlen);
|
||||||
|
if (res < 0) {
|
||||||
|
wpa_printf(MSG_ERROR, "recvfrom(ctrl_iface): %s",
|
||||||
|
strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
buf[res] = '\0';
|
||||||
|
if (os_strcmp(buf, "PING") == 0)
|
||||||
|
level = MSG_EXCESSIVE;
|
||||||
|
wpa_hexdump_ascii(level, "RX ctrl_iface", (u8 *) buf, res);
|
||||||
|
|
||||||
|
reply = os_malloc(reply_size);
|
||||||
|
if (reply == NULL) {
|
||||||
|
if (sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
|
||||||
|
fromlen) < 0) {
|
||||||
|
wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
|
||||||
|
strerror(errno));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
reply_len = hostapd_ctrl_iface_receive_process(hapd, buf,
|
||||||
|
reply, reply_size,
|
||||||
|
&from, fromlen);
|
||||||
|
|
||||||
if (sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from,
|
if (sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from,
|
||||||
fromlen) < 0) {
|
fromlen) < 0) {
|
||||||
wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
|
wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
|
||||||
|
|
Loading…
Reference in a new issue