2014-03-25 20:39:02 +01:00
|
|
|
/*
|
|
|
|
* Wired Ethernet driver interface for QCA MACsec driver
|
|
|
|
* Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
|
|
|
|
* Copyright (c) 2004, Gunter Burchardt <tira@isx.de>
|
|
|
|
* Copyright (c) 2013-2014, Qualcomm Atheros, Inc.
|
|
|
|
*
|
|
|
|
* 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 <net/if.h>
|
2016-08-12 15:07:35 +02:00
|
|
|
#include <inttypes.h>
|
2014-03-25 20:39:02 +01:00
|
|
|
#ifdef __linux__
|
|
|
|
#include <netpacket/packet.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#endif /* __linux__ */
|
|
|
|
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) */
|
|
|
|
#ifdef __sun__
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#endif /* __sun__ */
|
|
|
|
|
|
|
|
#include "utils/common.h"
|
|
|
|
#include "utils/eloop.h"
|
|
|
|
#include "common/defs.h"
|
|
|
|
#include "common/ieee802_1x_defs.h"
|
2016-09-20 09:43:05 +02:00
|
|
|
#include "pae/ieee802_1x_kay.h"
|
2014-03-25 20:39:02 +01:00
|
|
|
#include "driver.h"
|
2016-11-27 20:08:44 +01:00
|
|
|
#include "driver_wired_common.h"
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
#include "nss_macsec_secy.h"
|
|
|
|
#include "nss_macsec_secy_rx.h"
|
|
|
|
#include "nss_macsec_secy_tx.h"
|
|
|
|
|
|
|
|
#define MAXSC 16
|
|
|
|
|
2018-08-01 10:27:22 +02:00
|
|
|
#define SAK_128_LEN 16
|
|
|
|
#define SAK_256_LEN 32
|
|
|
|
|
2014-03-25 20:39:02 +01:00
|
|
|
/* TCI field definition */
|
|
|
|
#define TCI_ES 0x40
|
|
|
|
#define TCI_SC 0x20
|
|
|
|
#define TCI_SCB 0x10
|
|
|
|
#define TCI_E 0x08
|
|
|
|
#define TCI_C 0x04
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
#endif /* _MSC_VER */
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma pack(pop)
|
|
|
|
#endif /* _MSC_VER */
|
|
|
|
|
2016-10-21 14:45:26 +02:00
|
|
|
struct channel_map {
|
|
|
|
struct ieee802_1x_mka_sci sci;
|
|
|
|
};
|
|
|
|
|
2014-03-25 20:39:02 +01:00
|
|
|
struct macsec_qca_data {
|
2016-11-27 20:08:44 +01:00
|
|
|
struct driver_wired_common_data common;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-11-27 20:08:44 +01:00
|
|
|
u32 secy_id;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
/* shadow */
|
|
|
|
Boolean always_include_sci;
|
|
|
|
Boolean use_es;
|
|
|
|
Boolean use_scb;
|
|
|
|
Boolean protect_frames;
|
|
|
|
Boolean replay_protect;
|
|
|
|
u32 replay_window;
|
2016-10-21 14:45:26 +02:00
|
|
|
|
|
|
|
struct channel_map receive_channel_map[MAXSC];
|
|
|
|
struct channel_map transmit_channel_map[MAXSC];
|
2014-03-25 20:39:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void __macsec_drv_init(struct macsec_qca_data *drv)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
fal_rx_ctl_filt_t rx_ctl_filt;
|
|
|
|
fal_tx_ctl_filt_t tx_ctl_filt;
|
|
|
|
|
|
|
|
wpa_printf(MSG_INFO, "%s: secy_id=%d", __func__, drv->secy_id);
|
|
|
|
|
|
|
|
/* Enable Secy and Let EAPoL bypass */
|
|
|
|
ret = nss_macsec_secy_en_set(drv->secy_id, TRUE);
|
|
|
|
if (ret)
|
|
|
|
wpa_printf(MSG_ERROR, "nss_macsec_secy_en_set: FAIL");
|
|
|
|
|
|
|
|
ret = nss_macsec_secy_sc_sa_mapping_mode_set(drv->secy_id,
|
|
|
|
FAL_SC_SA_MAP_1_4);
|
|
|
|
if (ret)
|
|
|
|
wpa_printf(MSG_ERROR,
|
|
|
|
"nss_macsec_secy_sc_sa_mapping_mode_set: FAIL");
|
|
|
|
|
|
|
|
os_memset(&rx_ctl_filt, 0, sizeof(rx_ctl_filt));
|
|
|
|
rx_ctl_filt.bypass = 1;
|
|
|
|
rx_ctl_filt.match_type = IG_CTL_COMPARE_ETHER_TYPE;
|
|
|
|
rx_ctl_filt.match_mask = 0xffff;
|
|
|
|
rx_ctl_filt.ether_type_da_range = 0x888e;
|
|
|
|
ret = nss_macsec_secy_rx_ctl_filt_set(drv->secy_id, 0, &rx_ctl_filt);
|
|
|
|
if (ret)
|
|
|
|
wpa_printf(MSG_ERROR, "nss_macsec_secy_rx_ctl_filt_set: FAIL");
|
|
|
|
|
|
|
|
os_memset(&tx_ctl_filt, 0, sizeof(tx_ctl_filt));
|
|
|
|
tx_ctl_filt.bypass = 1;
|
|
|
|
tx_ctl_filt.match_type = EG_CTL_COMPARE_ETHER_TYPE;
|
|
|
|
tx_ctl_filt.match_mask = 0xffff;
|
|
|
|
tx_ctl_filt.ether_type_da_range = 0x888e;
|
|
|
|
ret = nss_macsec_secy_tx_ctl_filt_set(drv->secy_id, 0, &tx_ctl_filt);
|
|
|
|
if (ret)
|
|
|
|
wpa_printf(MSG_ERROR, "nss_macsec_secy_tx_ctl_filt_set: FAIL");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void __macsec_drv_deinit(struct macsec_qca_data *drv)
|
|
|
|
{
|
|
|
|
nss_macsec_secy_en_set(drv->secy_id, FALSE);
|
|
|
|
nss_macsec_secy_rx_sc_del_all(drv->secy_id);
|
|
|
|
nss_macsec_secy_tx_sc_del_all(drv->secy_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void * macsec_qca_init(void *ctx, const char *ifname)
|
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv;
|
|
|
|
|
|
|
|
drv = os_zalloc(sizeof(*drv));
|
|
|
|
if (drv == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Board specific settings */
|
2016-11-27 20:08:50 +01:00
|
|
|
if (os_memcmp("eth2", ifname, 4) == 0)
|
2014-03-25 20:39:02 +01:00
|
|
|
drv->secy_id = 1;
|
2016-11-27 20:08:50 +01:00
|
|
|
else if (os_memcmp("eth3", ifname, 4) == 0)
|
2014-03-25 20:39:02 +01:00
|
|
|
drv->secy_id = 2;
|
|
|
|
else
|
|
|
|
drv->secy_id = -1;
|
|
|
|
|
2016-11-27 20:08:50 +01:00
|
|
|
if (driver_wired_init_common(&drv->common, ifname, ctx) < 0) {
|
2014-03-25 20:39:02 +01:00
|
|
|
os_free(drv);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return drv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void macsec_qca_deinit(void *priv)
|
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
|
|
|
|
2016-11-27 20:08:51 +01:00
|
|
|
driver_wired_deinit_common(&drv->common);
|
2014-03-25 20:39:02 +01:00
|
|
|
os_free(drv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int macsec_qca_macsec_init(void *priv, struct macsec_init_params *params)
|
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
|
|
|
|
|
|
|
drv->always_include_sci = params->always_include_sci;
|
|
|
|
drv->use_es = params->use_es;
|
|
|
|
drv->use_scb = params->use_scb;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "%s: es=%d, scb=%d, sci=%d",
|
|
|
|
__func__, drv->use_es, drv->use_scb,
|
|
|
|
drv->always_include_sci);
|
|
|
|
|
|
|
|
__macsec_drv_init(drv);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int macsec_qca_macsec_deinit(void *priv)
|
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "%s", __func__);
|
|
|
|
|
|
|
|
__macsec_drv_deinit(drv);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-07 12:08:12 +02:00
|
|
|
static int macsec_qca_get_capability(void *priv, enum macsec_cap *cap)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "%s", __func__);
|
|
|
|
|
|
|
|
*cap = MACSEC_CAP_INTEG_AND_CONF_0_30_50;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-25 20:39:02 +01:00
|
|
|
static int macsec_qca_enable_protect_frames(void *priv, Boolean enabled)
|
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
|
|
|
|
|
|
|
|
drv->protect_frames = enabled;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int macsec_qca_set_replay_protect(void *priv, Boolean enabled,
|
|
|
|
unsigned int window)
|
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "%s: enabled=%d, win=%u",
|
|
|
|
__func__, enabled, window);
|
|
|
|
|
|
|
|
drv->replay_protect = enabled;
|
|
|
|
drv->replay_window = window;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-01 10:27:22 +02:00
|
|
|
static fal_cipher_suite_e macsec_qca_cs_type_get(u64 cs)
|
|
|
|
{
|
|
|
|
if (cs == CS_ID_GCM_AES_128)
|
|
|
|
return FAL_CIPHER_SUITE_AES_GCM_128;
|
|
|
|
if (cs == CS_ID_GCM_AES_256)
|
|
|
|
return FAL_CIPHER_SUITE_AES_GCM_256;
|
|
|
|
return FAL_CIPHER_SUITE_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 15:07:35 +02:00
|
|
|
static int macsec_qca_set_current_cipher_suite(void *priv, u64 cs)
|
2014-03-25 20:39:02 +01:00
|
|
|
{
|
2018-08-01 10:27:22 +02:00
|
|
|
struct macsec_qca_data *drv = priv;
|
|
|
|
fal_cipher_suite_e cs_type;
|
|
|
|
|
|
|
|
if (cs != CS_ID_GCM_AES_128 && cs != CS_ID_GCM_AES_256) {
|
2016-08-12 15:07:35 +02:00
|
|
|
wpa_printf(MSG_ERROR,
|
|
|
|
"%s: NOT supported CipherSuite: %016" PRIx64,
|
|
|
|
__func__, cs);
|
2014-03-25 20:39:02 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-08-01 10:27:22 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: CipherSuite: %016" PRIx64, __func__, cs);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2018-08-01 10:27:22 +02:00
|
|
|
cs_type = macsec_qca_cs_type_get(cs);
|
|
|
|
return nss_macsec_secy_cipher_suite_set(drv->secy_id, cs_type);
|
2014-03-25 20:39:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int macsec_qca_enable_controlled_port(void *priv, Boolean enabled)
|
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "%s: enable=%d", __func__, enabled);
|
|
|
|
|
|
|
|
ret += nss_macsec_secy_controlled_port_en_set(drv->secy_id, enabled);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-21 14:45:26 +02:00
|
|
|
static int macsec_qca_lookup_channel(struct channel_map *map,
|
|
|
|
struct ieee802_1x_mka_sci *sci,
|
|
|
|
u32 *channel)
|
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAXSC; i++) {
|
|
|
|
if (os_memcmp(&map[i].sci, sci,
|
|
|
|
sizeof(struct ieee802_1x_mka_sci)) == 0) {
|
|
|
|
*channel = i;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void macsec_qca_register_channel(struct channel_map *map,
|
|
|
|
struct ieee802_1x_mka_sci *sci,
|
|
|
|
u32 channel)
|
|
|
|
{
|
|
|
|
os_memcpy(&map[channel].sci, sci, sizeof(struct ieee802_1x_mka_sci));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int macsec_qca_lookup_receive_channel(struct macsec_qca_data *drv,
|
|
|
|
struct receive_sc *sc,
|
|
|
|
u32 *channel)
|
|
|
|
{
|
|
|
|
return macsec_qca_lookup_channel(drv->receive_channel_map, &sc->sci,
|
|
|
|
channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void macsec_qca_register_receive_channel(struct macsec_qca_data *drv,
|
|
|
|
struct receive_sc *sc,
|
|
|
|
u32 channel)
|
|
|
|
{
|
|
|
|
macsec_qca_register_channel(drv->receive_channel_map, &sc->sci,
|
|
|
|
channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int macsec_qca_lookup_transmit_channel(struct macsec_qca_data *drv,
|
|
|
|
struct transmit_sc *sc,
|
|
|
|
u32 *channel)
|
|
|
|
{
|
|
|
|
return macsec_qca_lookup_channel(drv->transmit_channel_map, &sc->sci,
|
|
|
|
channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void macsec_qca_register_transmit_channel(struct macsec_qca_data *drv,
|
|
|
|
struct transmit_sc *sc,
|
|
|
|
u32 channel)
|
|
|
|
{
|
|
|
|
macsec_qca_register_channel(drv->transmit_channel_map, &sc->sci,
|
|
|
|
channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-20 09:43:05 +02:00
|
|
|
static int macsec_qca_get_receive_lowest_pn(void *priv, struct receive_sa *sa)
|
2014-03-25 20:39:02 +01:00
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
|
|
|
int ret = 0;
|
|
|
|
u32 next_pn = 0;
|
|
|
|
bool enabled = FALSE;
|
|
|
|
u32 win;
|
2016-10-21 14:45:26 +02:00
|
|
|
u32 channel;
|
|
|
|
|
|
|
|
ret = macsec_qca_lookup_receive_channel(priv, sa->sc, &channel);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-09-20 09:43:05 +02:00
|
|
|
ret += nss_macsec_secy_rx_sa_next_pn_get(drv->secy_id, channel, sa->an,
|
2014-03-25 20:39:02 +01:00
|
|
|
&next_pn);
|
|
|
|
ret += nss_macsec_secy_rx_sc_replay_protect_get(drv->secy_id, channel,
|
|
|
|
&enabled);
|
|
|
|
ret += nss_macsec_secy_rx_sc_anti_replay_window_get(drv->secy_id,
|
|
|
|
channel, &win);
|
|
|
|
|
|
|
|
if (enabled)
|
2016-09-20 09:43:05 +02:00
|
|
|
sa->lowest_pn = (next_pn > win) ? (next_pn - win) : 1;
|
2014-03-25 20:39:02 +01:00
|
|
|
else
|
2016-09-20 09:43:05 +02:00
|
|
|
sa->lowest_pn = next_pn;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-09-20 09:43:05 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: lpn=0x%x", __func__, sa->lowest_pn);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-20 09:43:05 +02:00
|
|
|
static int macsec_qca_get_transmit_next_pn(void *priv, struct transmit_sa *sa)
|
2014-03-25 20:39:02 +01:00
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
|
|
|
int ret = 0;
|
2016-10-21 14:45:26 +02:00
|
|
|
u32 channel;
|
|
|
|
|
|
|
|
ret = macsec_qca_lookup_transmit_channel(priv, sa->sc, &channel);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-09-20 09:43:05 +02:00
|
|
|
ret += nss_macsec_secy_tx_sa_next_pn_get(drv->secy_id, channel, sa->an,
|
|
|
|
&sa->next_pn);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-09-20 09:43:05 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: npn=0x%x", __func__, sa->next_pn);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-20 09:43:05 +02:00
|
|
|
int macsec_qca_set_transmit_next_pn(void *priv, struct transmit_sa *sa)
|
2014-03-25 20:39:02 +01:00
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
|
|
|
int ret = 0;
|
2016-10-21 14:45:26 +02:00
|
|
|
u32 channel;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-10-21 14:45:26 +02:00
|
|
|
ret = macsec_qca_lookup_transmit_channel(priv, sa->sc, &channel);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-09-20 09:43:05 +02:00
|
|
|
ret += nss_macsec_secy_tx_sa_next_pn_set(drv->secy_id, channel, sa->an,
|
|
|
|
sa->next_pn);
|
|
|
|
|
|
|
|
wpa_printf(MSG_INFO, "%s: npn=0x%x", __func__, sa->next_pn);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int macsec_qca_get_available_receive_sc(void *priv, u32 *channel)
|
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
|
|
|
int ret = 0;
|
|
|
|
u32 sc_ch = 0;
|
|
|
|
bool in_use = FALSE;
|
|
|
|
|
|
|
|
for (sc_ch = 0; sc_ch < MAXSC; sc_ch++) {
|
|
|
|
ret = nss_macsec_secy_rx_sc_in_used_get(drv->secy_id, sc_ch,
|
|
|
|
&in_use);
|
|
|
|
if (ret)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!in_use) {
|
|
|
|
*channel = sc_ch;
|
|
|
|
wpa_printf(MSG_DEBUG, "%s: channel=%d",
|
|
|
|
__func__, *channel);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "%s: no available channel", __func__);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-07 12:08:10 +02:00
|
|
|
static int macsec_qca_create_receive_sc(void *priv, struct receive_sc *sc,
|
2014-03-25 20:39:02 +01:00
|
|
|
unsigned int conf_offset,
|
|
|
|
int validation)
|
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
|
|
|
int ret = 0;
|
|
|
|
fal_rx_prc_lut_t entry;
|
|
|
|
fal_rx_sc_validate_frame_e vf;
|
|
|
|
enum validate_frames validate_frames = validation;
|
2016-10-21 14:45:26 +02:00
|
|
|
u32 channel;
|
2016-10-07 12:08:10 +02:00
|
|
|
const u8 *sci_addr = sc->sci.addr;
|
|
|
|
u16 sci_port = be_to_host16(sc->sci.port);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-10-21 14:45:26 +02:00
|
|
|
ret = macsec_qca_get_available_receive_sc(priv, &channel);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
2014-03-25 20:39:02 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: channel=%d", __func__, channel);
|
|
|
|
|
|
|
|
/* rx prc lut */
|
|
|
|
os_memset(&entry, 0, sizeof(entry));
|
|
|
|
|
|
|
|
os_memcpy(entry.sci, sci_addr, ETH_ALEN);
|
2018-08-22 10:29:20 +02:00
|
|
|
entry.sci[6] = (sci_port >> 8) & 0xff;
|
|
|
|
entry.sci[7] = sci_port & 0xff;
|
2014-03-25 20:39:02 +01:00
|
|
|
entry.sci_mask = 0xf;
|
|
|
|
|
|
|
|
entry.valid = 1;
|
|
|
|
entry.channel = channel;
|
|
|
|
entry.action = FAL_RX_PRC_ACTION_PROCESS;
|
|
|
|
entry.offset = conf_offset;
|
|
|
|
|
|
|
|
/* rx validate frame */
|
|
|
|
if (validate_frames == Strict)
|
|
|
|
vf = FAL_RX_SC_VALIDATE_FRAME_STRICT;
|
|
|
|
else if (validate_frames == Checked)
|
|
|
|
vf = FAL_RX_SC_VALIDATE_FRAME_CHECK;
|
|
|
|
else
|
|
|
|
vf = FAL_RX_SC_VALIDATE_FRAME_DISABLED;
|
|
|
|
|
|
|
|
ret += nss_macsec_secy_rx_prc_lut_set(drv->secy_id, channel, &entry);
|
|
|
|
ret += nss_macsec_secy_rx_sc_create(drv->secy_id, channel);
|
|
|
|
ret += nss_macsec_secy_rx_sc_validate_frame_set(drv->secy_id, channel,
|
|
|
|
vf);
|
|
|
|
ret += nss_macsec_secy_rx_sc_replay_protect_set(drv->secy_id, channel,
|
|
|
|
drv->replay_protect);
|
|
|
|
ret += nss_macsec_secy_rx_sc_anti_replay_window_set(drv->secy_id,
|
|
|
|
channel,
|
|
|
|
drv->replay_window);
|
|
|
|
|
2016-10-21 14:45:26 +02:00
|
|
|
macsec_qca_register_receive_channel(drv, sc, channel);
|
|
|
|
|
2014-03-25 20:39:02 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-07 12:08:10 +02:00
|
|
|
static int macsec_qca_delete_receive_sc(void *priv, struct receive_sc *sc)
|
2014-03-25 20:39:02 +01:00
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
2016-10-21 14:45:26 +02:00
|
|
|
int ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
fal_rx_prc_lut_t entry;
|
2016-10-21 14:45:26 +02:00
|
|
|
u32 channel;
|
|
|
|
|
|
|
|
ret = macsec_qca_lookup_receive_channel(priv, sc, &channel);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "%s: channel=%d", __func__, channel);
|
|
|
|
|
|
|
|
/* rx prc lut */
|
|
|
|
os_memset(&entry, 0, sizeof(entry));
|
|
|
|
|
|
|
|
ret += nss_macsec_secy_rx_sc_del(drv->secy_id, channel);
|
|
|
|
ret += nss_macsec_secy_rx_prc_lut_set(drv->secy_id, channel, &entry);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-20 09:43:09 +02:00
|
|
|
static int macsec_qca_create_receive_sa(void *priv, struct receive_sa *sa)
|
2014-03-25 20:39:02 +01:00
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
2016-10-21 14:45:26 +02:00
|
|
|
int ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
fal_rx_sak_t rx_sak;
|
|
|
|
int i = 0;
|
2016-10-21 14:45:26 +02:00
|
|
|
u32 channel;
|
|
|
|
|
|
|
|
ret = macsec_qca_lookup_receive_channel(priv, sa->sc, &channel);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "%s, channel=%d, an=%d, lpn=0x%x",
|
2016-09-20 09:43:09 +02:00
|
|
|
__func__, channel, sa->an, sa->lowest_pn);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
os_memset(&rx_sak, 0, sizeof(rx_sak));
|
2018-08-01 10:27:22 +02:00
|
|
|
rx_sak.sak_len = sa->pkey->key_len;
|
|
|
|
if (sa->pkey->key_len == SAK_128_LEN) {
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
rx_sak.sak[i] = sa->pkey->key[15 - i];
|
|
|
|
} else if (sa->pkey->key_len == SAK_256_LEN) {
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
rx_sak.sak1[i] = sa->pkey->key[15 - i];
|
|
|
|
rx_sak.sak[i] = sa->pkey->key[31 - i];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-09-20 09:43:09 +02:00
|
|
|
ret += nss_macsec_secy_rx_sa_create(drv->secy_id, channel, sa->an);
|
|
|
|
ret += nss_macsec_secy_rx_sak_set(drv->secy_id, channel, sa->an,
|
|
|
|
&rx_sak);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-20 09:43:09 +02:00
|
|
|
static int macsec_qca_enable_receive_sa(void *priv, struct receive_sa *sa)
|
2014-03-25 20:39:02 +01:00
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
2016-10-21 14:45:26 +02:00
|
|
|
int ret;
|
|
|
|
u32 channel;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-10-21 14:45:26 +02:00
|
|
|
ret = macsec_qca_lookup_receive_channel(priv, sa->sc, &channel);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-09-20 09:43:09 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: channel=%d, an=%d", __func__, channel,
|
|
|
|
sa->an);
|
|
|
|
|
|
|
|
ret += nss_macsec_secy_rx_sa_en_set(drv->secy_id, channel, sa->an,
|
|
|
|
TRUE);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-20 09:43:09 +02:00
|
|
|
static int macsec_qca_disable_receive_sa(void *priv, struct receive_sa *sa)
|
2014-03-25 20:39:02 +01:00
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
2016-10-21 14:45:26 +02:00
|
|
|
int ret;
|
|
|
|
u32 channel;
|
|
|
|
|
|
|
|
ret = macsec_qca_lookup_receive_channel(priv, sa->sc, &channel);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-09-20 09:43:09 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: channel=%d, an=%d", __func__, channel,
|
|
|
|
sa->an);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-09-20 09:43:09 +02:00
|
|
|
ret += nss_macsec_secy_rx_sa_en_set(drv->secy_id, channel, sa->an,
|
|
|
|
FALSE);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int macsec_qca_get_available_transmit_sc(void *priv, u32 *channel)
|
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
|
|
|
u32 sc_ch = 0;
|
|
|
|
bool in_use = FALSE;
|
|
|
|
|
|
|
|
for (sc_ch = 0; sc_ch < MAXSC; sc_ch++) {
|
2016-10-21 14:45:26 +02:00
|
|
|
if (nss_macsec_secy_tx_sc_in_used_get(drv->secy_id, sc_ch,
|
|
|
|
&in_use))
|
2014-03-25 20:39:02 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!in_use) {
|
|
|
|
*channel = sc_ch;
|
|
|
|
wpa_printf(MSG_DEBUG, "%s: channel=%d",
|
|
|
|
__func__, *channel);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "%s: no avaiable channel", __func__);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-07 12:08:09 +02:00
|
|
|
static int macsec_qca_create_transmit_sc(void *priv, struct transmit_sc *sc,
|
2014-03-25 20:39:02 +01:00
|
|
|
unsigned int conf_offset)
|
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
2016-10-21 14:45:26 +02:00
|
|
|
int ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
fal_tx_class_lut_t entry;
|
|
|
|
u8 psci[ETH_ALEN + 2];
|
2016-10-21 14:45:26 +02:00
|
|
|
u32 channel;
|
2018-05-25 04:41:01 +02:00
|
|
|
u16 sci_port = be_to_host16(sc->sci.port);
|
2016-10-21 14:45:26 +02:00
|
|
|
|
|
|
|
ret = macsec_qca_get_available_transmit_sc(priv, &channel);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "%s: channel=%d", __func__, channel);
|
|
|
|
|
|
|
|
/* class lut */
|
|
|
|
os_memset(&entry, 0, sizeof(entry));
|
|
|
|
|
|
|
|
entry.valid = 1;
|
|
|
|
entry.action = FAL_TX_CLASS_ACTION_FORWARD;
|
|
|
|
entry.channel = channel;
|
|
|
|
|
2016-10-07 12:08:09 +02:00
|
|
|
os_memcpy(psci, sc->sci.addr, ETH_ALEN);
|
2018-08-22 10:29:20 +02:00
|
|
|
psci[6] = (sci_port >> 8) & 0xff;
|
|
|
|
psci[7] = sci_port & 0xff;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
ret += nss_macsec_secy_tx_class_lut_set(drv->secy_id, channel, &entry);
|
|
|
|
ret += nss_macsec_secy_tx_sc_create(drv->secy_id, channel, psci, 8);
|
|
|
|
ret += nss_macsec_secy_tx_sc_protect_set(drv->secy_id, channel,
|
|
|
|
drv->protect_frames);
|
|
|
|
ret += nss_macsec_secy_tx_sc_confidentiality_offset_set(drv->secy_id,
|
|
|
|
channel,
|
|
|
|
conf_offset);
|
|
|
|
|
2016-10-21 14:45:26 +02:00
|
|
|
macsec_qca_register_transmit_channel(drv, sc, channel);
|
|
|
|
|
2014-03-25 20:39:02 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-07 12:08:09 +02:00
|
|
|
static int macsec_qca_delete_transmit_sc(void *priv, struct transmit_sc *sc)
|
2014-03-25 20:39:02 +01:00
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
2016-10-21 14:45:26 +02:00
|
|
|
int ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
fal_tx_class_lut_t entry;
|
2016-10-21 14:45:26 +02:00
|
|
|
u32 channel;
|
|
|
|
|
|
|
|
ret = macsec_qca_lookup_transmit_channel(priv, sc, &channel);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "%s: channel=%d", __func__, channel);
|
|
|
|
|
|
|
|
/* class lut */
|
|
|
|
os_memset(&entry, 0, sizeof(entry));
|
|
|
|
|
|
|
|
ret += nss_macsec_secy_tx_class_lut_set(drv->secy_id, channel, &entry);
|
|
|
|
ret += nss_macsec_secy_tx_sc_del(drv->secy_id, channel);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-20 09:43:07 +02:00
|
|
|
static int macsec_qca_create_transmit_sa(void *priv, struct transmit_sa *sa)
|
2014-03-25 20:39:02 +01:00
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
2016-10-21 14:45:26 +02:00
|
|
|
int ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
u8 tci = 0;
|
|
|
|
fal_tx_sak_t tx_sak;
|
|
|
|
int i;
|
2016-10-21 14:45:26 +02:00
|
|
|
u32 channel;
|
|
|
|
|
|
|
|
ret = macsec_qca_lookup_transmit_channel(priv, sa->sc, &channel);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"%s: channel=%d, an=%d, next_pn=0x%x, confidentiality=%d",
|
2016-09-20 09:43:07 +02:00
|
|
|
__func__, channel, sa->an, sa->next_pn, sa->confidentiality);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
if (drv->always_include_sci)
|
|
|
|
tci |= TCI_SC;
|
|
|
|
else if (drv->use_es)
|
|
|
|
tci |= TCI_ES;
|
|
|
|
else if (drv->use_scb)
|
|
|
|
tci |= TCI_SCB;
|
|
|
|
|
2016-09-20 09:43:07 +02:00
|
|
|
if (sa->confidentiality)
|
2014-03-25 20:39:02 +01:00
|
|
|
tci |= TCI_E | TCI_C;
|
|
|
|
|
|
|
|
os_memset(&tx_sak, 0, sizeof(tx_sak));
|
2018-08-01 10:27:22 +02:00
|
|
|
tx_sak.sak_len = sa->pkey->key_len;
|
|
|
|
if (sa->pkey->key_len == SAK_128_LEN) {
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
tx_sak.sak[i] = sa->pkey->key[15 - i];
|
|
|
|
} else if (sa->pkey->key_len == SAK_256_LEN) {
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
tx_sak.sak1[i] = sa->pkey->key[15 - i];
|
|
|
|
tx_sak.sak[i] = sa->pkey->key[31 - i];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-09-20 09:43:07 +02:00
|
|
|
ret += nss_macsec_secy_tx_sa_next_pn_set(drv->secy_id, channel, sa->an,
|
|
|
|
sa->next_pn);
|
|
|
|
ret += nss_macsec_secy_tx_sak_set(drv->secy_id, channel, sa->an,
|
|
|
|
&tx_sak);
|
2014-03-25 20:39:02 +01:00
|
|
|
ret += nss_macsec_secy_tx_sc_tci_7_2_set(drv->secy_id, channel,
|
|
|
|
(tci >> 2));
|
2016-09-20 09:43:07 +02:00
|
|
|
ret += nss_macsec_secy_tx_sc_an_set(drv->secy_id, channel, sa->an);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-20 09:43:07 +02:00
|
|
|
static int macsec_qca_enable_transmit_sa(void *priv, struct transmit_sa *sa)
|
2014-03-25 20:39:02 +01:00
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
2016-10-21 14:45:26 +02:00
|
|
|
int ret;
|
|
|
|
u32 channel;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-10-21 14:45:26 +02:00
|
|
|
ret = macsec_qca_lookup_transmit_channel(priv, sa->sc, &channel);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-09-20 09:43:07 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: channel=%d, an=%d", __func__, channel,
|
|
|
|
sa->an);
|
|
|
|
|
|
|
|
ret += nss_macsec_secy_tx_sa_en_set(drv->secy_id, channel, sa->an,
|
|
|
|
TRUE);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-20 09:43:07 +02:00
|
|
|
static int macsec_qca_disable_transmit_sa(void *priv, struct transmit_sa *sa)
|
2014-03-25 20:39:02 +01:00
|
|
|
{
|
|
|
|
struct macsec_qca_data *drv = priv;
|
2016-10-21 14:45:26 +02:00
|
|
|
int ret;
|
|
|
|
u32 channel;
|
|
|
|
|
|
|
|
ret = macsec_qca_lookup_transmit_channel(priv, sa->sc, &channel);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-09-20 09:43:07 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: channel=%d, an=%d", __func__, channel,
|
|
|
|
sa->an);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
2016-09-20 09:43:07 +02:00
|
|
|
ret += nss_macsec_secy_tx_sa_en_set(drv->secy_id, channel, sa->an,
|
|
|
|
FALSE);
|
2014-03-25 20:39:02 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const struct wpa_driver_ops wpa_driver_macsec_qca_ops = {
|
|
|
|
.name = "macsec_qca",
|
|
|
|
.desc = "QCA MACsec Ethernet driver",
|
2016-11-27 20:08:54 +01:00
|
|
|
.get_ssid = driver_wired_get_ssid,
|
2016-11-27 20:08:53 +01:00
|
|
|
.get_bssid = driver_wired_get_bssid,
|
2016-11-27 20:08:52 +01:00
|
|
|
.get_capa = driver_wired_get_capa,
|
2014-03-25 20:39:02 +01:00
|
|
|
.init = macsec_qca_init,
|
|
|
|
.deinit = macsec_qca_deinit,
|
|
|
|
|
|
|
|
.macsec_init = macsec_qca_macsec_init,
|
|
|
|
.macsec_deinit = macsec_qca_macsec_deinit,
|
2016-10-07 12:08:12 +02:00
|
|
|
.macsec_get_capability = macsec_qca_get_capability,
|
2014-03-25 20:39:02 +01:00
|
|
|
.enable_protect_frames = macsec_qca_enable_protect_frames,
|
|
|
|
.set_replay_protect = macsec_qca_set_replay_protect,
|
|
|
|
.set_current_cipher_suite = macsec_qca_set_current_cipher_suite,
|
|
|
|
.enable_controlled_port = macsec_qca_enable_controlled_port,
|
|
|
|
.get_receive_lowest_pn = macsec_qca_get_receive_lowest_pn,
|
|
|
|
.get_transmit_next_pn = macsec_qca_get_transmit_next_pn,
|
|
|
|
.set_transmit_next_pn = macsec_qca_set_transmit_next_pn,
|
|
|
|
.create_receive_sc = macsec_qca_create_receive_sc,
|
|
|
|
.delete_receive_sc = macsec_qca_delete_receive_sc,
|
|
|
|
.create_receive_sa = macsec_qca_create_receive_sa,
|
|
|
|
.enable_receive_sa = macsec_qca_enable_receive_sa,
|
|
|
|
.disable_receive_sa = macsec_qca_disable_receive_sa,
|
|
|
|
.create_transmit_sc = macsec_qca_create_transmit_sc,
|
|
|
|
.delete_transmit_sc = macsec_qca_delete_transmit_sc,
|
|
|
|
.create_transmit_sa = macsec_qca_create_transmit_sa,
|
|
|
|
.enable_transmit_sa = macsec_qca_enable_transmit_sa,
|
|
|
|
.disable_transmit_sa = macsec_qca_disable_transmit_sa,
|
|
|
|
};
|