]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
hostapd: Add hostapd_ctrl_iface_receive_process()
authorAnton Nayshtut <qca_antonn@qca.qualcomm.com>
Thu, 16 Jul 2015 10:19:49 +0000 (13:19 +0300)
committerJouni Malinen <j@w1.fi>
Thu, 16 Jul 2015 17:21:00 +0000 (20:21 +0300)
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>
hostapd/ctrl_iface.c

index d2055c3b20ef1ad008909e19c4f124189e821138..73df223a4ce7b231cdbfbb3fd3bd7ee06283dbd5 100644 (file)
@@ -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",