These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / staging / rtl8188eu / os_dep / ioctl_linux.c
index 96c1c2d..a076ede 100644 (file)
@@ -19,6 +19,8 @@
  ******************************************************************************/
 #define _IOCTL_LINUX_C_
 
+#include <linux/ieee80211.h>
+
 #include <osdep_service.h>
 #include <drv_types.h>
 #include <wlan_bssdef.h>
@@ -177,8 +179,8 @@ static char *translate_scan(struct adapter *padapter,
 
        cap = le16_to_cpu(le_tmp);
 
-       if (cap & (WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_BSS)) {
-               if (cap & WLAN_CAPABILITY_BSS)
+       if (!WLAN_CAPABILITY_IS_STA_BSS(cap)) {
+               if (cap & WLAN_CAPABILITY_ESS)
                        iwe.u.mode = IW_MODE_MASTER;
                else
                        iwe.u.mode = IW_MODE_ADHOC;
@@ -455,7 +457,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
                                        psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
 
                                if (param->u.crypt.set_tx == 1) { /* pairwise key */
-                                       memcpy(psta->dot118021x_UncstKey.skey,  param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                       memcpy(psta->dot118021x_UncstKey.skey,  param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
 
                                        if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */
                                                memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
@@ -467,7 +469,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
 
                                        rtw_setstakey_cmd(padapter, (unsigned char *)psta, true);
                                } else { /* group key */
-                                       memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey,  param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                       memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey,  param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16 ));
                                        memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
                                        memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
                                        padapter->securitypriv.binstallGrpkey = true;
@@ -602,7 +604,7 @@ static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ie
                                if ((eid == _VENDOR_SPECIFIC_IE_) && (!memcmp(&buf[cnt+2], wps_oui, 4))) {
                                        DBG_88E("SET WPS_IE\n");
 
-                                       padapter->securitypriv.wps_ie_len = ((buf[cnt+1]+2) < (MAX_WPA_IE_LEN<<2)) ? (buf[cnt+1]+2) : (MAX_WPA_IE_LEN<<2);
+                                       padapter->securitypriv.wps_ie_len = min(buf[cnt + 1] + 2, MAX_WPA_IE_LEN << 2);
 
                                        memcpy(padapter->securitypriv.wps_ie, &buf[cnt], padapter->securitypriv.wps_ie_len);
 
@@ -1319,7 +1321,7 @@ static int rtw_wx_set_essid(struct net_device *dev,
        authmode = padapter->securitypriv.ndisauthtype;
        DBG_88E("=>%s\n", __func__);
        if (wrqu->essid.flags && wrqu->essid.length) {
-               len = (wrqu->essid.length < IW_ESSID_MAX_SIZE) ? wrqu->essid.length : IW_ESSID_MAX_SIZE;
+               len = min_t(uint, wrqu->essid.length, IW_ESSID_MAX_SIZE);
 
                if (wrqu->essid.length != 33)
                        DBG_88E("ssid =%s, len =%d\n", extra, wrqu->essid.length);
@@ -1625,7 +1627,7 @@ static int rtw_wx_set_enc(struct net_device *dev,
                padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
                padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
                padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
-               padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
+               padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
                authmode = Ndis802_11AuthModeOpen;
                padapter->securitypriv.ndisauthtype = authmode;
 
@@ -1664,7 +1666,7 @@ static int rtw_wx_set_enc(struct net_device *dev,
                DBG_88E("rtw_wx_set_enc():erq->flags = 0x%x\n", erq->flags);
 
                padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;/* Ndis802_11EncryptionDisabled; */
-               padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
+               padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
                padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
                padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
                authmode = Ndis802_11AuthModeOpen;
@@ -1855,7 +1857,7 @@ static int rtw_wx_set_auth(struct net_device *dev,
                        padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
                        padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
                        padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
-                       padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
+                       padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
                        padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
                }
 
@@ -1869,7 +1871,7 @@ static int rtw_wx_set_auth(struct net_device *dev,
                        rtw_disassoc_cmd(padapter, 500, false);
                        DBG_88E("%s...call rtw_indicate_disconnect\n ", __func__);
                        rtw_indicate_disconnect(padapter);
-                       rtw_free_assoc_resources(padapter, 1);
+                       rtw_free_assoc_resources(padapter);
                }
                ret = wpa_set_auth_algs(dev, (u32)param->value);
                break;
@@ -2333,7 +2335,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
                                DBG_88E("%s, set group_key, WEP\n", __func__);
 
                                memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,
-                                           param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                           param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
 
                                psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
                                if (param->u.crypt.key_len == 13)
@@ -2342,7 +2344,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
                                DBG_88E("%s, set group_key, TKIP\n", __func__);
                                psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
                                memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,
-                                           param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                           param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
                                /* set mic key */
                                memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
                                memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
@@ -2352,7 +2354,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
                                DBG_88E("%s, set group_key, CCMP\n", __func__);
                                psecuritypriv->dot118021XGrpPrivacy = _AES_;
                                memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,
-                                           param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                           param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
                        } else {
                                DBG_88E("%s, set group_key, none\n", __func__);
                                psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
@@ -2373,7 +2375,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
        if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) { /*  psk/802_1x */
                if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
                        if (param->u.crypt.set_tx == 1) {
-                               memcpy(psta->dot118021x_UncstKey.skey,  param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                               memcpy(psta->dot118021x_UncstKey.skey,  param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
 
                                if (strcmp(param->u.crypt.alg, "WEP") == 0) {
                                        DBG_88E("%s, set pairwise key, WEP\n", __func__);
@@ -2407,7 +2409,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
                        } else { /* group key??? */
                                if (strcmp(param->u.crypt.alg, "WEP") == 0) {
                                        memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,
-                                                   param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                                   param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
                                        psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
                                        if (param->u.crypt.key_len == 13)
                                                psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
@@ -2415,7 +2417,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
                                        psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
 
                                        memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,
-                                                   param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                                   param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
 
                                        /* set mic key */
                                        memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
@@ -2426,7 +2428,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
                                        psecuritypriv->dot118021XGrpPrivacy = _AES_;
 
                                        memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,
-                                                   param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                                   param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
                                } else {
                                        psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
                                }
@@ -2483,16 +2485,13 @@ static int rtw_set_beacon(struct net_device *dev, struct ieee_param *param, int
 
 static int rtw_hostapd_sta_flush(struct net_device *dev)
 {
-       int ret = 0;
        struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
 
        DBG_88E("%s\n", __func__);
 
        flush_all_cam_entry(padapter);  /* clear CAM */
 
-       ret = rtw_sta_flush(padapter);
-
-       return ret;
+       return rtw_sta_flush(padapter);
 }
 
 static int rtw_add_sta(struct net_device *dev, struct ieee_param *param)
@@ -2664,12 +2663,13 @@ static int rtw_get_sta_wpaie(struct net_device *dev, struct ieee_param *param)
 
        psta = rtw_get_stainfo(pstapriv, param->sta_addr);
        if (psta) {
-               if ((psta->wpa_ie[0] == WLAN_EID_RSN) || (psta->wpa_ie[0] == WLAN_EID_GENERIC)) {
+               if (psta->wpa_ie[0] == WLAN_EID_RSN ||
+                   psta->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
                        int wpa_ie_len;
                        int copy_len;
 
                        wpa_ie_len = psta->wpa_ie[1];
-                       copy_len = ((wpa_ie_len+2) > sizeof(psta->wpa_ie)) ? (sizeof(psta->wpa_ie)) : (wpa_ie_len+2);
+                       copy_len = min_t(int, wpa_ie_len + 2, sizeof(psta->wpa_ie));
                        param->u.wpa_ie.len = copy_len;
                        memcpy(param->u.wpa_ie.reserved, psta->wpa_ie, copy_len);
                } else {
@@ -2807,7 +2807,6 @@ static int rtw_set_hidden_ssid(struct net_device *dev, struct ieee_param *param,
 
 static int rtw_ioctl_acl_remove_sta(struct net_device *dev, struct ieee_param *param, int len)
 {
-       int ret = 0;
        struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
 
@@ -2818,13 +2817,11 @@ static int rtw_ioctl_acl_remove_sta(struct net_device *dev, struct ieee_param *p
            param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
            param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
                return -EINVAL;
-       ret = rtw_acl_remove_sta(padapter, param->sta_addr);
-       return ret;
+       return rtw_acl_remove_sta(padapter, param->sta_addr);
 }
 
 static int rtw_ioctl_acl_add_sta(struct net_device *dev, struct ieee_param *param, int len)
 {
-       int ret = 0;
        struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
 
@@ -2835,8 +2832,7 @@ static int rtw_ioctl_acl_add_sta(struct net_device *dev, struct ieee_param *para
            param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
            param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
                return -EINVAL;
-       ret = rtw_acl_add_sta(padapter, param->sta_addr);
-       return ret;
+       return rtw_acl_add_sta(padapter, param->sta_addr);
 }
 
 static int rtw_ioctl_set_macaddr_acl(struct net_device *dev, struct ieee_param *param, int len)
@@ -2978,7 +2974,7 @@ static int rtw_wx_set_priv(struct net_device *dev,
 
                if ((_VENDOR_SPECIFIC_IE_ == probereq_wpsie[0]) &&
                    (!memcmp(&probereq_wpsie[2], wps_oui, 4))) {
-                       cp_sz = probereq_wpsie_len > MAX_WPS_IE_LEN ? MAX_WPS_IE_LEN : probereq_wpsie_len;
+                       cp_sz = min(probereq_wpsie_len, MAX_WPS_IE_LEN);
 
                        pmlmepriv->wps_probe_req_ie_len = 0;
                        kfree(pmlmepriv->wps_probe_req_ie);
@@ -3095,7 +3091,7 @@ static struct iw_statistics *rtw_get_wireless_stats(struct net_device *dev)
 
 struct iw_handler_def rtw_handlers_def = {
        .standard = rtw_handlers,
-       .num_standard = sizeof(rtw_handlers) / sizeof(iw_handler),
+       .num_standard = ARRAY_SIZE(rtw_handlers),
        .get_wireless_stats = rtw_get_wireless_stats,
 };