]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
macsec_qca: Support macsec secy id getting from driver
authorleiwei <leiwei@codeaurora.org>
Tue, 10 Aug 2021 07:18:14 +0000 (15:18 +0800)
committerJouni Malinen <j@w1.fi>
Mon, 18 Oct 2021 20:32:34 +0000 (23:32 +0300)
Use the new nss_macsec_secy_id_get() function, if available, instead of
the hardcoded ifname to secy_id mapping.

Signed-off-by: leiwei <leiwei@codeaurora.org>
src/drivers/driver_macsec_qca.c

index 928f02499510f47238171128986a2b4f853500b6..54964f37e3ed58aa5b87ee09d71b1d13d265a943 100644 (file)
@@ -257,6 +257,33 @@ static int macsec_qca_init_sockets(struct macsec_qca_data *drv, u8 *own_addr)
 }
 
 
+static int macsec_qca_secy_id_get(const char *ifname, u32 *secy_id)
+{
+#ifdef NSS_MACSEC_SECY_ID_GET_FUNC
+       /* Get secy id from nss macsec driver */
+       return nss_macsec_secy_id_get((u8 *) ifname, secy_id);
+#else /* NSS_MACSEC_SECY_ID_GET_FUNC */
+       /* Board specific settings */
+       if (os_strcmp(ifname, "eth2") == 0) {
+               *secy_id = 1;
+       } else if (os_strcmp(ifname, "eth3") == 0) {
+               *secy_id = 2;
+       } else if (os_strcmp(ifname, "eth4") == 0 ||
+                  os_strcmp(ifname, "eth0") == 0) {
+               *secy_id = 0;
+       } else if (os_strcmp(ifname, "eth5") == 0 ||
+                  os_strcmp(ifname, "eth1") == 0) {
+               *secy_id = 1;
+       } else {
+               *secy_id = -1;
+               return -1;
+       }
+
+       return 0;
+#endif /* NSS_MACSEC_SECY_ID_GET_FUNC */
+}
+
+
 static void * macsec_qca_init(void *ctx, const char *ifname)
 {
        struct macsec_qca_data *drv;
@@ -265,13 +292,12 @@ static void * macsec_qca_init(void *ctx, const char *ifname)
        if (drv == NULL)
                return NULL;
 
-       /* Board specific settings */
-       if (os_memcmp("eth2", ifname, 4) == 0)
-               drv->secy_id = 1;
-       else if (os_memcmp("eth3", ifname, 4) == 0)
-               drv->secy_id = 2;
-       else
-               drv->secy_id = -1;
+       if (macsec_qca_secy_id_get(ifname, &drv->secy_id)) {
+               wpa_printf(MSG_ERROR,
+                          "macsec_qca: Failed to get secy_id for %s", ifname);
+               os_free(drv);
+               return NULL;
+       }
 
        if (driver_wired_init_common(&drv->common, ifname, ctx) < 0) {
                os_free(drv);
@@ -303,17 +329,13 @@ static void * macsec_qca_hapd_init(struct hostapd_data *hapd,
                return NULL;
        }
 
-       /* Board specific settings */
-       if (os_memcmp("eth2", params->ifname, 4) == 0)
-               drv->secy_id = 1;
-       else if (os_memcmp("eth3", params->ifname, 4) == 0)
-               drv->secy_id = 2;
-       else if (os_memcmp("eth4", params->ifname, 4) == 0)
-               drv->secy_id = 0;
-       else if (os_memcmp("eth5", params->ifname, 4) == 0)
-               drv->secy_id = 1;
-       else
-               drv->secy_id = -1;
+       if (macsec_qca_secy_id_get(params->ifname, &drv->secy_id)) {
+               wpa_printf(MSG_ERROR,
+                          "macsec_qca: Failed to get secy_id for %s",
+                          params->ifname);
+               os_free(drv);
+               return NULL;
+       }
 
        drv->common.ctx = hapd;
        os_strlcpy(drv->common.ifname, params->ifname,