aboutsummaryrefslogtreecommitdiffstats
path: root/hostapd/ctrl_iface.c
diff options
context:
space:
mode:
authorAnton Nayshtut <qca_antonn@qca.qualcomm.com>2015-07-16 10:19:49 (GMT)
committerJouni Malinen <j@w1.fi>2015-07-16 17:21:00 (GMT)
commit585478e2b9097df4bf4faebc16f5922a8b2e32b0 (patch)
tree8662c5eeb31a658a2d7fe6223721591faff1a8f2 /hostapd/ctrl_iface.c
parent2531dc9f6bd21b2677e8281e1f11db568e3f667d (diff)
downloadhostap-585478e2b9097df4bf4faebc16f5922a8b2e32b0.zip
hostap-585478e2b9097df4bf4faebc16f5922a8b2e32b0.tar.gz
hostap-585478e2b9097df4bf4faebc16f5922a8b2e32b0.tar.bz2
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>
Diffstat (limited to 'hostapd/ctrl_iface.c')
-rw-r--r--hostapd/ctrl_iface.c89
1 files changed, 53 insertions, 36 deletions
diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index d2055c3..73df223 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -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,
- void *sock_ctx)
+static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
+ char *buf, char *reply,
+ int reply_size,
+ struct sockaddr_un *from,
+ socklen_t fromlen)
{
- 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;
- }
+ int reply_len, res;
os_memcpy(reply, "OK\n", 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_size);
} 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;
} 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;
} 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))
reply_len = -1;
} 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);
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,
fromlen) < 0) {
wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",