drivers: Add freq parameter to send_mlme() function
[mech_eap.git] / src / drivers / driver_hostap.c
index 456b0b4..14c52d2 100644 (file)
@@ -2,20 +2,14 @@
  * Driver interaction with Linux Host AP driver
  * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
  */
 
 #include "includes.h"
 #include <sys/ioctl.h>
 
-#include "wireless_copy.h"
+#include "linux_wext.h"
 #include "common.h"
 #include "driver.h"
 #include "driver_wext.h"
@@ -220,7 +214,7 @@ static void handle_read(int sock, void *eloop_ctx, void *sock_ctx)
 
        len = recv(sock, buf, sizeof(buf), 0);
        if (len < 0) {
-               perror("recv");
+               wpa_printf(MSG_ERROR, "recv: %s", strerror(errno));
                return;
        }
 
@@ -235,19 +229,21 @@ static int hostap_init_sockets(struct hostap_driver_data *drv, u8 *own_addr)
 
        drv->sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
        if (drv->sock < 0) {
-               perror("socket[PF_PACKET,SOCK_RAW]");
+               wpa_printf(MSG_ERROR, "socket[PF_PACKET,SOCK_RAW]: %s",
+                          strerror(errno));
                return -1;
        }
 
        if (eloop_register_read_sock(drv->sock, handle_read, drv, NULL)) {
-               printf("Could not register read socket\n");
+               wpa_printf(MSG_ERROR, "Could not register read socket");
                return -1;
        }
 
         memset(&ifr, 0, sizeof(ifr));
         snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%sap", drv->iface);
         if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
-               perror("ioctl(SIOCGIFINDEX)");
+               wpa_printf(MSG_ERROR, "ioctl(SIOCGIFINDEX): %s",
+                          strerror(errno));
                return -1;
         }
 
@@ -262,7 +258,7 @@ static int hostap_init_sockets(struct hostap_driver_data *drv, u8 *own_addr)
                   addr.sll_ifindex);
 
        if (bind(drv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-               perror("bind");
+               wpa_printf(MSG_ERROR, "bind: %s", strerror(errno));
                return -1;
        }
 
@@ -270,7 +266,8 @@ static int hostap_init_sockets(struct hostap_driver_data *drv, u8 *own_addr)
 }
 
 
-static int hostap_send_mlme(void *priv, const u8 *msg, size_t len)
+static int hostap_send_mlme(void *priv, const u8 *msg, size_t len, int noack,
+                           unsigned int freq)
 {
        struct hostap_driver_data *drv = priv;
        struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) msg;
@@ -319,7 +316,7 @@ static int hostap_send_eapol(void *priv, const u8 *addr, const u8 *data,
        pos += 2;
        memcpy(pos, data, data_len);
 
-       res = hostap_send_mlme(drv, (u8 *) hdr, len);
+       res = hostap_send_mlme(drv, (u8 *) hdr, len, 0);
        if (res < 0) {
                wpa_printf(MSG_ERROR, "hostap_send_eapol - packet len: %lu - "
                           "failed: %d (%s)",
@@ -367,9 +364,9 @@ static int hostap_set_iface_flags(void *priv, int dev_up)
                os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
                ifr.ifr_mtu = HOSTAPD_MTU;
                if (ioctl(drv->ioctl_sock, SIOCSIFMTU, &ifr) != 0) {
-                       perror("ioctl[SIOCSIFMTU]");
-                       printf("Setting MTU failed - trying to survive with "
-                              "current value\n");
+                       wpa_printf(MSG_INFO,
+                                  "Setting MTU failed - trying to survive with current value: ioctl[SIOCSIFMTU]: %s",
+                                  strerror(errno));
                }
        }
 
@@ -389,7 +386,8 @@ static int hostapd_ioctl(void *priv, struct prism2_hostapd_param *param,
        iwr.u.data.length = len;
 
        if (ioctl(drv->ioctl_sock, PRISM2_IOCTL_HOSTAPD, &iwr) < 0) {
-               perror("ioctl[PRISM2_IOCTL_HOSTAPD]");
+               wpa_printf(MSG_ERROR, "ioctl[PRISM2_IOCTL_HOSTAPD]: %s",
+                          strerror(errno));
                return -1;
        }
 
@@ -503,7 +501,8 @@ static int hostap_ioctl_prism2param(void *priv, int param, int value)
        *i++ = value;
 
        if (ioctl(drv->ioctl_sock, PRISM2_IOCTL_PRISM2_PARAM, &iwr) < 0) {
-               perror("ioctl[PRISM2_IOCTL_PRISM2_PARAM]");
+               wpa_printf(MSG_ERROR, "ioctl[PRISM2_IOCTL_PRISM2_PARAM]: %s",
+                          strerror(errno));
                return -1;
        }
 
@@ -560,8 +559,8 @@ static int hostap_set_ssid(void *priv, const u8 *buf, int len)
        iwr.u.essid.length = len + 1;
 
        if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
-               perror("ioctl[SIOCSIWESSID]");
-               printf("len=%d\n", len);
+               wpa_printf(MSG_ERROR, "ioctl[SIOCSIWESSID,len=%d]: %s",
+                          len, strerror(errno));
                return -1;
        }
 
@@ -925,8 +924,9 @@ static int hostap_get_we_version(struct hostap_driver_data *drv)
                sizeof(range->enc_capa);
 
        if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
-               perror("ioctl[SIOCGIWRANGE]");
-               free(range);
+               wpa_printf(MSG_ERROR, "ioctl[SIOCGIWRANGE]: %s",
+                          strerror(errno));
+               os_free(range);
                return -1;
        } else if (iwr.u.data.length >= minlen &&
                   range->we_version_compiled >= 18) {
@@ -981,23 +981,25 @@ static void * hostap_init(struct hostapd_data *hapd,
 
        drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
        if (drv->ioctl_sock < 0) {
-               perror("socket[PF_INET,SOCK_DGRAM]");
-               free(drv);
+               wpa_printf(MSG_ERROR, "socket[PF_INET,SOCK_DGRAM]: %s",
+                          strerror(errno));
+               os_free(drv);
                return NULL;
        }
 
        if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD, 1)) {
-               printf("Could not enable hostapd mode for interface %s\n",
-                      drv->iface);
+               wpa_printf(MSG_ERROR,
+                          "Could not enable hostapd mode for interface %s",
+                          drv->iface);
                close(drv->ioctl_sock);
-               free(drv);
+               os_free(drv);
                return NULL;
        }
 
        if (hostap_init_sockets(drv, params->own_addr) ||
            hostap_wireless_event_init(drv)) {
                close(drv->ioctl_sock);
-               free(drv);
+               os_free(drv);
                return NULL;
        }
 
@@ -1051,7 +1053,7 @@ static int hostap_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
        memcpy(mgmt.bssid, own_addr, ETH_ALEN);
        mgmt.u.deauth.reason_code = host_to_le16(reason);
        return hostap_send_mlme(drv, (u8 *) &mgmt, IEEE80211_HDRLEN +
-                               sizeof(mgmt.u.deauth));
+                               sizeof(mgmt.u.deauth), 0);
 }
 
 
@@ -1066,7 +1068,8 @@ static int hostap_set_freq(void *priv, struct hostapd_freq_params *freq)
        iwr.u.freq.e = 0;
 
        if (ioctl(drv->ioctl_sock, SIOCSIWFREQ, &iwr) < 0) {
-               perror("ioctl[SIOCSIWFREQ]");
+               wpa_printf(MSG_ERROR, "ioctl[SIOCSIWFREQ]: %s",
+                          strerror(errno));
                return -1;
        }
 
@@ -1088,7 +1091,7 @@ static int hostap_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
        memcpy(mgmt.bssid, own_addr, ETH_ALEN);
        mgmt.u.disassoc.reason_code = host_to_le16(reason);
        return  hostap_send_mlme(drv, (u8 *) &mgmt, IEEE80211_HDRLEN +
-                                sizeof(mgmt.u.disassoc));
+                                sizeof(mgmt.u.disassoc), 0);
 }
 
 
@@ -1166,7 +1169,7 @@ static void wpa_driver_hostap_poll_client(void *priv, const u8 *own_addr,
        os_memcpy(hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
        os_memcpy(hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
 
-       hostap_send_mlme(priv, (u8 *)&hdr, sizeof(hdr));
+       hostap_send_mlme(priv, (u8 *)&hdr, sizeof(hdr), 0);
 }