eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

common.c (2684B)


      1 /*
      2  *
      3  *  Wireless daemon for Linux
      4  *
      5  *  Copyright (C) 2014-2019  Intel Corporation. All rights reserved.
      6  *
      7  *  This library is free software; you can redistribute it and/or
      8  *  modify it under the terms of the GNU Lesser General Public
      9  *  License as published by the Free Software Foundation; either
     10  *  version 2.1 of the License, or (at your option) any later version.
     11  *
     12  *  This library is distributed in the hope that it will be useful,
     13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  *  Lesser General Public License for more details.
     16  *
     17  *  You should have received a copy of the GNU Lesser General Public
     18  *  License along with this library; if not, write to the Free Software
     19  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20  *
     21  */
     22 
     23 #ifdef HAVE_CONFIG_H
     24 #include <config.h>
     25 #endif
     26 
     27 #include <stddef.h>
     28 #include <stdbool.h>
     29 #include <string.h>
     30 
     31 #include "src/iwd.h"
     32 #include "src/common.h"
     33 #include "src/ie.h"
     34 
     35 const char *security_to_str(enum security security)
     36 {
     37 	switch (security) {
     38 	case SECURITY_NONE:
     39 		return "open";
     40 	case SECURITY_WEP:
     41 		return "wep";
     42 	case SECURITY_PSK:
     43 		return "psk";
     44 	case SECURITY_8021X:
     45 		return "8021x";
     46 	}
     47 
     48 	return NULL;
     49 }
     50 
     51 bool security_from_str(const char *str, enum security *security)
     52 {
     53 	if (!strcmp(str, "open"))
     54 		*security = SECURITY_NONE;
     55 	else if (!strcmp(str, "wep"))
     56 		*security = SECURITY_WEP;
     57 	else if (!strcmp(str, "psk"))
     58 		*security = SECURITY_PSK;
     59 	else if (!strcmp(str, "8021x"))
     60 		*security = SECURITY_8021X;
     61 	else
     62 		return false;
     63 
     64 	return true;
     65 }
     66 
     67 #define AKM_IS_PSK(akm)							\
     68 (									\
     69 	akm & (IE_RSN_AKM_SUITE_PSK |					\
     70 		IE_RSN_AKM_SUITE_PSK_SHA256 |				\
     71 		IE_RSN_AKM_SUITE_FT_USING_PSK |				\
     72 		IE_RSN_AKM_SUITE_SAE_SHA256 |				\
     73 		IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256)			\
     74 )
     75 
     76 #define AKM_IS_8021X(akm) \
     77 (									\
     78 	akm & (IE_RSN_AKM_SUITE_8021X |					\
     79 		IE_RSN_AKM_SUITE_8021X_SHA256 |				\
     80 		IE_RSN_AKM_SUITE_FT_OVER_8021X |			\
     81 		IE_RSN_AKM_SUITE_FT_OVER_8021X_SHA384 |			\
     82 		IE_RSN_AKM_SUITE_FILS_SHA256 |				\
     83 		IE_RSN_AKM_SUITE_FILS_SHA384 |				\
     84 		IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256 |			\
     85 		IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384 |			\
     86 		IE_RSN_AKM_SUITE_OSEN)					\
     87 )
     88 
     89 enum security security_determine(uint16_t bss_capability,
     90 					const struct ie_rsn_info *info)
     91 {
     92 	if (info && AKM_IS_PSK(info->akm_suites))
     93 		return SECURITY_PSK;
     94 
     95 	if (info && AKM_IS_8021X(info->akm_suites))
     96 		return SECURITY_8021X;
     97 
     98 	if (info && (info->akm_suites & IE_RSN_AKM_SUITE_OWE))
     99 		return SECURITY_NONE;
    100 
    101 	if (bss_capability & IE_BSS_CAP_PRIVACY)
    102 		return SECURITY_WEP;
    103 
    104 	return SECURITY_NONE;
    105 }