Skip to content

Commit

Permalink
Merge pull request #4 from monich/sae
Browse files Browse the repository at this point in the history
Add missing caps
  • Loading branch information
monich committed Jan 17, 2023
2 parents 4e59a0e + 82e57f5 commit 9f11630
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 123 deletions.
11 changes: 9 additions & 2 deletions include/gsupplicant_interface.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015-2020 Jolla Ltd.
* Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand Down Expand Up @@ -104,7 +104,14 @@ typedef struct gsupplicant_interface_caps {
#define GSUPPLICANT_INTERFACE_CAPS_MODES_P2P (0x00000008)

gint max_scan_ssid;
guint caps_reserved[2];
guint group_mgmt; /* Used since 1.0.27 */

#define GSUPPLICANT_INTERFACE_CAPS_GROUP_MGMT_BIP (0x00000001)
#define GSUPPLICANT_INTERFACE_CAPS_GROUP_MGMT_BIP_GMAC_128 (0x00000002)
#define GSUPPLICANT_INTERFACE_CAPS_GROUP_MGMT_BIP_GMAC_256 (0x00000004)
#define GSUPPLICANT_INTERFACE_CAPS_GROUP_MGMT_BIP_CMAC_256 (0x00000008)

guint caps_reserved;
} GSupplicantInterfaceCaps;

typedef struct gsupplicant_signal_poll {
Expand Down
13 changes: 10 additions & 3 deletions include/gsupplicant_types.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015-2020 Jolla Ltd.
* Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand Down Expand Up @@ -52,7 +52,10 @@ typedef enum gsupplicant_cipher {
GSUPPLICANT_CIPHER_TKIP = (0x00000004),
GSUPPLICANT_CIPHER_WEP104 = (0x00000008),
GSUPPLICANT_CIPHER_WEP40 = (0x00000010),
GSUPPLICANT_CIPHER_AES128_CMAC = (0x00000020)
GSUPPLICANT_CIPHER_AES128_CMAC = (0x00000020),
GSUPPLICANT_CIPHER_CCMP_256 = (0x00000040), /* Since 1.0.27 */
GSUPPLICANT_CIPHER_GCMP = (0x00000080), /* Since 1.0.27 */
GSUPPLICANT_CIPHER_GCMP_256 = (0x00000100) /* Since 1.0.27 */
} GSUPPLICANT_CIPHER;

typedef enum gsupplicant_keymgmt {
Expand All @@ -66,7 +69,11 @@ typedef enum gsupplicant_keymgmt {
GSUPPLICANT_KEYMGMT_WPA_EAP_SHA256 = (0x00000040),
GSUPPLICANT_KEYMGMT_IEEE8021X = (0x00000080),
GSUPPLICANT_KEYMGMT_WPA_NONE = (0x00000100),
GSUPPLICANT_KEYMGMT_WPS = (0x00000200)
GSUPPLICANT_KEYMGMT_WPS = (0x00000200),
GSUPPLICANT_KEYMGMT_SAE = (0x00000400), /* Since 1.0.27 */
GSUPPLICANT_KEYMGMT_SAE_EXT_KEY = (0x00000800), /* Since 1.0.27 */
GSUPPLICANT_KEYMGMT_FT_SAE = (0x00001000), /* Since 1.0.27 */
GSUPPLICANT_KEYMGMT_FT_SAE_EXT_KEY = (0x00002000) /* Since 1.0.27 */
} GSUPPLICANT_KEYMGMT;

typedef enum gsupplicant_protocol {
Expand Down
44 changes: 41 additions & 3 deletions src/gsupplicant.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015-2021 Jolla Ltd.
* Copyright (C) 2015-2021 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand Down Expand Up @@ -177,7 +177,10 @@ static const GSupNameIntPair gsupplicant_cipher_suites [] = {
{ "tkip", GSUPPLICANT_CIPHER_TKIP },
{ "wep104", GSUPPLICANT_CIPHER_WEP104 },
{ "wep40", GSUPPLICANT_CIPHER_WEP40 },
{ "aes128cmac", GSUPPLICANT_CIPHER_AES128_CMAC }
{ "aes128cmac", GSUPPLICANT_CIPHER_AES128_CMAC },
{ "ccmp-256", GSUPPLICANT_CIPHER_CCMP_256 },
{ "gcmp", GSUPPLICANT_CIPHER_GCMP },
{ "gcmp-256", GSUPPLICANT_CIPHER_GCMP_256 }
};

static const GSupNameIntPair gsupplicant_keymgmt_suites [] = {
Expand All @@ -190,7 +193,11 @@ static const GSupNameIntPair gsupplicant_keymgmt_suites [] = {
{ "wpa-eap-sha256", GSUPPLICANT_KEYMGMT_WPA_EAP_SHA256 },
{ "ieee8021x", GSUPPLICANT_KEYMGMT_IEEE8021X },
{ "wpa-none", GSUPPLICANT_KEYMGMT_WPA_NONE },
{ "wps", GSUPPLICANT_KEYMGMT_WPS }
{ "wps", GSUPPLICANT_KEYMGMT_WPS },
{ "sae", GSUPPLICANT_KEYMGMT_SAE },
{ "sae-ext-key", GSUPPLICANT_KEYMGMT_SAE_EXT_KEY },
{ "ft-sae", GSUPPLICANT_KEYMGMT_FT_SAE },
{ "ft-sae-ext-key", GSUPPLICANT_KEYMGMT_FT_SAE_EXT_KEY }
};

/*==========================================================================*
Expand Down Expand Up @@ -890,6 +897,37 @@ gsupplicant_keymgmt_suite_name(
gsupplicant_keymgmt_suites, G_N_ELEMENTS(gsupplicant_keymgmt_suites));
}

/*==========================================================================*
* Internal API
*==========================================================================*/

GSUPPLICANT_CIPHER
gsupplicant_parse_cipher_value(
const char* name,
GVariant* value)
{
return gsupplicant_parse_bit_value(name, value,
gsupplicant_cipher_suites, G_N_ELEMENTS(gsupplicant_cipher_suites));
}

GSUPPLICANT_CIPHER
gsupplicant_parse_cipher_list(
const char* name,
GVariant* value)
{
return gsupplicant_parse_bits_array(0, name, value,
gsupplicant_cipher_suites, G_N_ELEMENTS(gsupplicant_cipher_suites));
}

GSUPPLICANT_KEYMGMT
gsupplicant_parse_keymgmt_list(
const char* name,
GVariant* value)
{
return gsupplicant_parse_bits_array(0, name, value,
gsupplicant_keymgmt_suites, G_N_ELEMENTS(gsupplicant_keymgmt_suites));
}

/*==========================================================================*
* Internals
*==========================================================================*/
Expand Down
84 changes: 9 additions & 75 deletions src/gsupplicant_bss.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015-2021 Jolla Ltd.
* Copyright (C) 2015-2021 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand Down Expand Up @@ -34,6 +34,7 @@

#include "gsupplicant_bss.h"
#include "gsupplicant_interface.h"
#include "gsupplicant_p.h"
#include "gsupplicant_util_p.h"
#include "gsupplicant_dbus.h"
#include "gsupplicant_log.h"
Expand Down Expand Up @@ -481,37 +482,11 @@ gsupplicant_bss_parse_wpa(
{
GSupplicantBSSWPA* wpa = data;
if (!g_strcmp0(name, "KeyMgmt")) {
static const GSupNameIntPair keymgmt_map [] = {
{ "wpa-psk", GSUPPLICANT_KEYMGMT_WPA_PSK },
{ "wpa-eap", GSUPPLICANT_KEYMGMT_WPA_EAP },
{ "wpa-none", GSUPPLICANT_KEYMGMT_WPA_NONE }
};
wpa->keymgmt = gsupplicant_parse_bits_array(0, name, value,
keymgmt_map, G_N_ELEMENTS(keymgmt_map));
wpa->keymgmt = gsupplicant_parse_keymgmt_list(name, value);
} else if (!g_strcmp0(name, "Pairwise")) {
static const GSupNameIntPair pairwise_map [] = {
{ "ccmp", GSUPPLICANT_CIPHER_CCMP },
{ "tkip", GSUPPLICANT_CIPHER_TKIP }
};
wpa->pairwise = gsupplicant_parse_bits_array(0, name, value,
pairwise_map, G_N_ELEMENTS(pairwise_map));
wpa->pairwise = gsupplicant_parse_cipher_list(name, value);
} else if (!g_strcmp0(name, "Group")) {
static const GSupNameIntPair group_map [] = {
{ "ccmp", GSUPPLICANT_CIPHER_CCMP },
{ "tkip", GSUPPLICANT_CIPHER_TKIP },
{ "wep104", GSUPPLICANT_CIPHER_WEP104 },
{ "wep40", GSUPPLICANT_CIPHER_WEP40 }
};
GASSERT(g_variant_is_of_type(value, G_VARIANT_TYPE_STRING));
if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
const char* str = g_variant_get_string(value, NULL);
const GSupNameIntPair* pair = gsupplicant_name_int_find_name(str,
group_map, G_N_ELEMENTS(group_map));
if (pair) {
GVERBOSE(" %s: %s", name, str);
wpa->group = pair->value;
}
}
wpa->group = gsupplicant_parse_cipher_value(name, value);
} else {
GWARN("Unexpected WPA dictionary key %s", name);
}
Expand Down Expand Up @@ -553,54 +528,13 @@ gsupplicant_bss_parse_rsn(
{
GSupplicantBSSRSN* rsn = data;
if (!g_strcmp0(name, "KeyMgmt")) {
static const GSupNameIntPair keymgmt_map [] = {
{ "wpa-psk", GSUPPLICANT_KEYMGMT_WPA_PSK },
{ "wpa-eap", GSUPPLICANT_KEYMGMT_WPA_EAP },
{ "wpa-ft-psk", GSUPPLICANT_KEYMGMT_WPA_FT_PSK },
{ "wpa-ft-eap", GSUPPLICANT_KEYMGMT_WPA_FT_EAP },
{ "wpa-psk-sha256", GSUPPLICANT_KEYMGMT_WPA_PSK_SHA256 },
{ "wpa-eap-sha256", GSUPPLICANT_KEYMGMT_WPA_EAP_SHA256 },
};
rsn->keymgmt = gsupplicant_parse_bits_array(0, name, value,
keymgmt_map, G_N_ELEMENTS(keymgmt_map));
rsn->keymgmt = gsupplicant_parse_keymgmt_list(name, value);
} else if (!g_strcmp0(name, "Pairwise")) {
static const GSupNameIntPair pairwise_map [] = {
{ "ccmp", GSUPPLICANT_CIPHER_CCMP },
{ "tkip", GSUPPLICANT_CIPHER_TKIP }
};
rsn->pairwise = gsupplicant_parse_bits_array(0, name, value,
pairwise_map, G_N_ELEMENTS(pairwise_map));
rsn->pairwise = gsupplicant_parse_cipher_list(name, value);
} else if (!g_strcmp0(name, "Group")) {
static const GSupNameIntPair group_map [] = {
{ "ccmp", GSUPPLICANT_CIPHER_CCMP },
{ "tkip", GSUPPLICANT_CIPHER_TKIP },
{ "wep104", GSUPPLICANT_CIPHER_WEP104 },
{ "wep40", GSUPPLICANT_CIPHER_WEP40 }
};
GASSERT(g_variant_is_of_type(value, G_VARIANT_TYPE_STRING));
if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
const char* str = g_variant_get_string(value, NULL);
const GSupNameIntPair* pair = gsupplicant_name_int_find_name(str,
group_map, G_N_ELEMENTS(group_map));
if (pair) {
GVERBOSE(" %s: %s", name, str);
rsn->group = pair->value;
}
}
rsn->group = gsupplicant_parse_cipher_value(name, value);
} else if (!g_strcmp0(name, "MgmtGroup")) {
static const GSupNameIntPair mgmt_group_map [] = {
{ "aes128cmac", GSUPPLICANT_CIPHER_AES128_CMAC }
};
GASSERT(g_variant_is_of_type(value, G_VARIANT_TYPE_STRING));
if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
const char* str = g_variant_get_string(value, NULL);
const GSupNameIntPair* pair = gsupplicant_name_int_find_name(str,
mgmt_group_map, G_N_ELEMENTS(mgmt_group_map));
if (pair) {
GVERBOSE(" %s: %s", name, str);
rsn->mgmt_group = pair->value;
}
}
rsn->mgmt_group = gsupplicant_parse_cipher_value(name, value);
} else {
GWARN("Unexpected RSN dictionary key %s", name);
}
Expand Down
46 changes: 15 additions & 31 deletions src/gsupplicant_interface.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015-2021 Jolla Ltd.
* Copyright (C) 2015-2021 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand Down Expand Up @@ -36,6 +36,7 @@
#include "gsupplicant_network.h"
#include "gsupplicant_bss.h"
#include "gsupplicant.h"
#include "gsupplicant_p.h"
#include "gsupplicant_util_p.h"
#include "gsupplicant_dbus.h"
#include "gsupplicant_log.h"
Expand Down Expand Up @@ -1460,37 +1461,11 @@ gsupplicant_interface_parse_cap(
{
GSupplicantInterfaceCaps* caps = data;
if (!g_strcmp0(name, "Pairwise")) {
static const GSupNameIntPair pairwise_map [] = {
{ "ccmp", GSUPPLICANT_CIPHER_CCMP },
{ "tkip", GSUPPLICANT_CIPHER_TKIP },
{ "none", GSUPPLICANT_CIPHER_NONE }
};
caps->pairwise = gsupplicant_parse_bits_array(0, name, value,
pairwise_map, G_N_ELEMENTS(pairwise_map));
caps->pairwise = gsupplicant_parse_cipher_list(name, value);
} else if (!g_strcmp0(name, "Group")) {
static const GSupNameIntPair group_map [] = {
{ "ccmp", GSUPPLICANT_CIPHER_CCMP },
{ "tkip", GSUPPLICANT_CIPHER_TKIP },
{ "wep104", GSUPPLICANT_CIPHER_WEP104 },
{ "wep40", GSUPPLICANT_CIPHER_WEP40 }
};
caps->group = gsupplicant_parse_bits_array(0, name, value,
group_map, G_N_ELEMENTS(group_map));
caps->group = gsupplicant_parse_cipher_list(name, value);
} else if (!g_strcmp0(name, "KeyMgmt")) {
static const GSupNameIntPair keymgmt_map [] = {
{ "wpa-psk", GSUPPLICANT_KEYMGMT_WPA_PSK },
{ "wpa-ft-psk", GSUPPLICANT_KEYMGMT_WPA_FT_PSK },
{ "wpa-psk-sha256", GSUPPLICANT_KEYMGMT_WPA_PSK_SHA256 },
{ "wpa-eap", GSUPPLICANT_KEYMGMT_WPA_EAP },
{ "wpa-ft-eap", GSUPPLICANT_KEYMGMT_WPA_FT_EAP },
{ "wpa-eap-sha256", GSUPPLICANT_KEYMGMT_WPA_EAP_SHA256 },
{ "ieee8021x", GSUPPLICANT_KEYMGMT_IEEE8021X },
{ "wpa-none", GSUPPLICANT_KEYMGMT_WPA_NONE },
{ "wps", GSUPPLICANT_KEYMGMT_WPS },
{ "none", GSUPPLICANT_KEYMGMT_NONE }
};
caps->keymgmt = gsupplicant_parse_bits_array(0, name, value,
keymgmt_map, G_N_ELEMENTS(keymgmt_map));
caps->keymgmt = gsupplicant_parse_keymgmt_list(name, value);
} else if (!g_strcmp0(name, "Protocol")) {
static const GSupNameIntPair protocol_map [] = {
{ "rsn", GSUPPLICANT_PROTOCOL_RSN },
Expand All @@ -1516,7 +1491,7 @@ gsupplicant_interface_parse_cap(
scan_map, G_N_ELEMENTS(scan_map));
} else if (!g_strcmp0(name, "Modes")) {
static const GSupNameIntPair modes_map [] = {
{ "infrastructure", GSUPPLICANT_INTERFACE_CAPS_MODES_INFRA},
{ "infrastructure", GSUPPLICANT_INTERFACE_CAPS_MODES_INFRA },
{ "ad-hoc", GSUPPLICANT_INTERFACE_CAPS_MODES_AD_HOC },
{ "ap", GSUPPLICANT_INTERFACE_CAPS_MODES_AP },
{ "p2p", GSUPPLICANT_INTERFACE_CAPS_MODES_P2P }
Expand All @@ -1526,6 +1501,15 @@ gsupplicant_interface_parse_cap(
} else if (!g_strcmp0(name, "MaxScanSSID")) {
caps->max_scan_ssid = g_variant_get_int32(value);
GVERBOSE(" %s: %d", name, caps->max_scan_ssid);
} else if (!g_strcmp0(name, "GroupMgmt")) {
static const GSupNameIntPair group_mgmt_map [] = {
{"aes-128-cmac",GSUPPLICANT_INTERFACE_CAPS_GROUP_MGMT_BIP },
{"bip-gmac-128",GSUPPLICANT_INTERFACE_CAPS_GROUP_MGMT_BIP_GMAC_128},
{"bip-gmac-256",GSUPPLICANT_INTERFACE_CAPS_GROUP_MGMT_BIP_GMAC_256},
{"bip-cmac-256",GSUPPLICANT_INTERFACE_CAPS_GROUP_MGMT_BIP_CMAC_256}
};
caps->group_mgmt = gsupplicant_parse_bits_array(0, name, value,
group_mgmt_map, G_N_ELEMENTS(group_mgmt_map));
} else {
GWARN("Unexpected interface capability key %s", name);
}
Expand Down
63 changes: 63 additions & 0 deletions src/gsupplicant_p.h
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef GSUPPLICANT_PRIVATE_H
#define GSUPPLICANT_PRIVATE_H

#include "gsupplicant_types_p.h"

GSUPPLICANT_CIPHER
gsupplicant_parse_cipher_value(
const char* name,
GVariant* value) /* G_VARIANT_TYPE_STRING */
GSUPPLICANT_INTERNAL;

GSUPPLICANT_CIPHER
gsupplicant_parse_cipher_list(
const char* name,
GVariant* value) /* G_VARIANT_TYPE_STRING_ARRAY */
GSUPPLICANT_INTERNAL;

GSUPPLICANT_KEYMGMT
gsupplicant_parse_keymgmt_list(
const char* name,
GVariant* value) /* G_VARIANT_TYPE_STRING_ARRAY */
GSUPPLICANT_INTERNAL;

#endif /* GSUPPLICANT_PRIVATE_H */

/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/

0 comments on commit 9f11630

Please sign in to comment.