HS 2.0R2: Add common OSEN definitions
[mech_eap.git] / src / common / wpa_common.c
index c3afbfd..c9d0ccb 100644 (file)
@@ -56,6 +56,11 @@ int wpa_eapol_key_mic(const u8 *key, int ver, const u8 *buf, size_t len,
        case WPA_KEY_INFO_TYPE_AES_128_CMAC:
                return omac1_aes_128(key, buf, len, mic);
 #endif /* CONFIG_IEEE80211R || CONFIG_IEEE80211W */
+#ifdef CONFIG_HS20
+       case WPA_KEY_INFO_TYPE_AKM_DEFINED:
+               /* FIX: This should be based on negotiated AKM */
+               return omac1_aes_128(key, buf, len, mic);
+#endif /* CONFIG_HS20 */
        default:
                return -1;
        }
@@ -353,6 +358,16 @@ static int rsn_selector_to_bitfield(const u8 *s)
 #endif /* CONFIG_IEEE80211W */
        if (RSN_SELECTOR_GET(s) == RSN_CIPHER_SUITE_GCMP)
                return WPA_CIPHER_GCMP;
+       if (RSN_SELECTOR_GET(s) == RSN_CIPHER_SUITE_CCMP_256)
+               return WPA_CIPHER_CCMP_256;
+       if (RSN_SELECTOR_GET(s) == RSN_CIPHER_SUITE_GCMP_256)
+               return WPA_CIPHER_GCMP_256;
+       if (RSN_SELECTOR_GET(s) == RSN_CIPHER_SUITE_BIP_GMAC_128)
+               return WPA_CIPHER_BIP_GMAC_128;
+       if (RSN_SELECTOR_GET(s) == RSN_CIPHER_SUITE_BIP_GMAC_256)
+               return WPA_CIPHER_BIP_GMAC_256;
+       if (RSN_SELECTOR_GET(s) == RSN_CIPHER_SUITE_BIP_CMAC_256)
+               return WPA_CIPHER_BIP_CMAC_256;
        return 0;
 }
 
@@ -912,6 +927,12 @@ const char * wpa_cipher_txt(int cipher)
                return "CCMP+TKIP";
        case WPA_CIPHER_GCMP:
                return "GCMP";
+       case WPA_CIPHER_GCMP_256:
+               return "GCMP-256";
+       case WPA_CIPHER_CCMP_256:
+               return "CCMP-256";
+       case WPA_CIPHER_GTK_NOT_USED:
+               return "GTK_NOT_USED";
        default:
                return "UNKNOWN";
        }
@@ -1078,6 +1099,9 @@ int wpa_insert_pmkid(u8 *ies, size_t ies_len, const u8 *pmkid)
 int wpa_cipher_key_len(int cipher)
 {
        switch (cipher) {
+       case WPA_CIPHER_CCMP_256:
+       case WPA_CIPHER_GCMP_256:
+               return 32;
        case WPA_CIPHER_CCMP:
        case WPA_CIPHER_GCMP:
                return 16;
@@ -1096,6 +1120,8 @@ int wpa_cipher_key_len(int cipher)
 int wpa_cipher_rsc_len(int cipher)
 {
        switch (cipher) {
+       case WPA_CIPHER_CCMP_256:
+       case WPA_CIPHER_GCMP_256:
        case WPA_CIPHER_CCMP:
        case WPA_CIPHER_GCMP:
        case WPA_CIPHER_TKIP:
@@ -1112,6 +1138,10 @@ int wpa_cipher_rsc_len(int cipher)
 int wpa_cipher_to_alg(int cipher)
 {
        switch (cipher) {
+       case WPA_CIPHER_CCMP_256:
+               return WPA_ALG_CCMP_256;
+       case WPA_CIPHER_GCMP_256:
+               return WPA_ALG_GCMP_256;
        case WPA_CIPHER_CCMP:
                return WPA_ALG_CCMP;
        case WPA_CIPHER_GCMP:
@@ -1126,29 +1156,11 @@ int wpa_cipher_to_alg(int cipher)
 }
 
 
-enum wpa_cipher wpa_cipher_to_suite_driver(int cipher)
-{
-       switch (cipher) {
-       case WPA_CIPHER_NONE:
-               return CIPHER_NONE;
-       case WPA_CIPHER_WEP40:
-               return CIPHER_WEP40;
-       case WPA_CIPHER_WEP104:
-               return CIPHER_WEP104;
-       case WPA_CIPHER_CCMP:
-               return CIPHER_CCMP;
-       case WPA_CIPHER_GCMP:
-               return CIPHER_GCMP;
-       case WPA_CIPHER_TKIP:
-       default:
-               return CIPHER_TKIP;
-       }
-}
-
-
 int wpa_cipher_valid_pairwise(int cipher)
 {
-       return cipher == WPA_CIPHER_CCMP ||
+       return cipher == WPA_CIPHER_CCMP_256 ||
+               cipher == WPA_CIPHER_GCMP_256 ||
+               cipher == WPA_CIPHER_CCMP ||
                cipher == WPA_CIPHER_GCMP ||
                cipher == WPA_CIPHER_TKIP;
 }
@@ -1156,6 +1168,10 @@ int wpa_cipher_valid_pairwise(int cipher)
 
 u32 wpa_cipher_to_suite(int proto, int cipher)
 {
+       if (cipher & WPA_CIPHER_CCMP_256)
+               return RSN_CIPHER_SUITE_CCMP_256;
+       if (cipher & WPA_CIPHER_GCMP_256)
+               return RSN_CIPHER_SUITE_GCMP_256;
        if (cipher & WPA_CIPHER_CCMP)
                return (proto == WPA_PROTO_RSN ?
                        RSN_CIPHER_SUITE_CCMP : WPA_CIPHER_SUITE_CCMP);
@@ -1173,6 +1189,8 @@ u32 wpa_cipher_to_suite(int proto, int cipher)
        if (cipher & WPA_CIPHER_NONE)
                return (proto == WPA_PROTO_RSN ?
                        RSN_CIPHER_SUITE_NONE : WPA_CIPHER_SUITE_NONE);
+       if (cipher & WPA_CIPHER_GTK_NOT_USED)
+               return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED;
        return 0;
 }
 
@@ -1181,6 +1199,16 @@ int rsn_cipher_put_suites(u8 *pos, int ciphers)
 {
        int num_suites = 0;
 
+       if (ciphers & WPA_CIPHER_CCMP_256) {
+               RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP_256);
+               pos += RSN_SELECTOR_LEN;
+               num_suites++;
+       }
+       if (ciphers & WPA_CIPHER_GCMP_256) {
+               RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_GCMP_256);
+               pos += RSN_SELECTOR_LEN;
+               num_suites++;
+       }
        if (ciphers & WPA_CIPHER_CCMP) {
                RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
                pos += RSN_SELECTOR_LEN;
@@ -1232,6 +1260,10 @@ int wpa_cipher_put_suites(u8 *pos, int ciphers)
 
 int wpa_pick_pairwise_cipher(int ciphers, int none_allowed)
 {
+       if (ciphers & WPA_CIPHER_CCMP_256)
+               return WPA_CIPHER_CCMP_256;
+       if (ciphers & WPA_CIPHER_GCMP_256)
+               return WPA_CIPHER_GCMP_256;
        if (ciphers & WPA_CIPHER_CCMP)
                return WPA_CIPHER_CCMP;
        if (ciphers & WPA_CIPHER_GCMP)
@@ -1246,10 +1278,16 @@ int wpa_pick_pairwise_cipher(int ciphers, int none_allowed)
 
 int wpa_pick_group_cipher(int ciphers)
 {
+       if (ciphers & WPA_CIPHER_CCMP_256)
+               return WPA_CIPHER_CCMP_256;
+       if (ciphers & WPA_CIPHER_GCMP_256)
+               return WPA_CIPHER_GCMP_256;
        if (ciphers & WPA_CIPHER_CCMP)
                return WPA_CIPHER_CCMP;
        if (ciphers & WPA_CIPHER_GCMP)
                return WPA_CIPHER_GCMP;
+       if (ciphers & WPA_CIPHER_GTK_NOT_USED)
+               return WPA_CIPHER_GTK_NOT_USED;
        if (ciphers & WPA_CIPHER_TKIP)
                return WPA_CIPHER_TKIP;
        if (ciphers & WPA_CIPHER_WEP104)
@@ -1280,7 +1318,11 @@ int wpa_parse_cipher(const char *value)
                        end++;
                last = *end == '\0';
                *end = '\0';
-               if (os_strcmp(start, "CCMP") == 0)
+               if (os_strcmp(start, "CCMP-256") == 0)
+                       val |= WPA_CIPHER_CCMP_256;
+               else if (os_strcmp(start, "GCMP-256") == 0)
+                       val |= WPA_CIPHER_GCMP_256;
+               else if (os_strcmp(start, "CCMP") == 0)
                        val |= WPA_CIPHER_CCMP;
                else if (os_strcmp(start, "GCMP") == 0)
                        val |= WPA_CIPHER_GCMP;
@@ -1292,6 +1334,8 @@ int wpa_parse_cipher(const char *value)
                        val |= WPA_CIPHER_WEP40;
                else if (os_strcmp(start, "NONE") == 0)
                        val |= WPA_CIPHER_NONE;
+               else if (os_strcmp(start, "GTK_NOT_USED") == 0)
+                       val |= WPA_CIPHER_GTK_NOT_USED;
                else {
                        os_free(buf);
                        return -1;
@@ -1312,6 +1356,20 @@ int wpa_write_ciphers(char *start, char *end, int ciphers, const char *delim)
        char *pos = start;
        int ret;
 
+       if (ciphers & WPA_CIPHER_CCMP_256) {
+               ret = os_snprintf(pos, end - pos, "%sCCMP-256",
+                                 pos == start ? "" : delim);
+               if (ret < 0 || ret >= end - pos)
+                       return -1;
+               pos += ret;
+       }
+       if (ciphers & WPA_CIPHER_GCMP_256) {
+               ret = os_snprintf(pos, end - pos, "%sGCMP-256",
+                                 pos == start ? "" : delim);
+               if (ret < 0 || ret >= end - pos)
+                       return -1;
+               pos += ret;
+       }
        if (ciphers & WPA_CIPHER_CCMP) {
                ret = os_snprintf(pos, end - pos, "%sCCMP",
                                  pos == start ? "" : delim);
@@ -1373,5 +1431,11 @@ int wpa_select_ap_group_cipher(int wpa, int wpa_pairwise, int rsn_pairwise)
                return WPA_CIPHER_TKIP;
        if ((pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) == WPA_CIPHER_GCMP)
                return WPA_CIPHER_GCMP;
+       if ((pairwise & (WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP |
+                        WPA_CIPHER_GCMP)) == WPA_CIPHER_GCMP_256)
+               return WPA_CIPHER_GCMP_256;
+       if ((pairwise & (WPA_CIPHER_CCMP_256 | WPA_CIPHER_CCMP |
+                        WPA_CIPHER_GCMP)) == WPA_CIPHER_CCMP_256)
+               return WPA_CIPHER_CCMP_256;
        return WPA_CIPHER_CCMP;
 }