]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
FT: Add set/get identity/radius_cui callback functions
authorMichael Braun <michael-dev@fami-braun.de>
Thu, 18 May 2017 13:21:54 +0000 (15:21 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 6 Apr 2018 16:01:16 +0000 (19:01 +0300)
These are needed to allow wpa_auth_ft.c to control identity/radius_cui
values for STAs.

Signed-off-by: Michael Braun <michael-dev@fami-braun.de>
src/ap/wpa_auth.h
src/ap/wpa_auth_glue.c

index c31e4a548f83ce064b6cf66f4bfa368b98ac12ad..bc99e5afaea9237facb318a50c2cca58e6d48054 100644 (file)
@@ -266,6 +266,13 @@ struct wpa_auth_callbacks {
                        struct vlan_description *vlan);
        int (*get_vlan)(void *ctx, const u8 *sta_addr,
                        struct vlan_description *vlan);
+       int (*set_identity)(void *ctx, const u8 *sta_addr,
+                           const u8 *identity, size_t identity_len);
+       size_t (*get_identity)(void *ctx, const u8 *sta_addr, const u8 **buf);
+       int (*set_radius_cui)(void *ctx, const u8 *sta_addr,
+                             const u8 *radius_cui, size_t radius_cui_len);
+       size_t (*get_radius_cui)(void *ctx, const u8 *sta_addr, const u8 **buf);
+
        int (*send_ft_action)(void *ctx, const u8 *dst,
                              const u8 *data, size_t data_len);
        int (*add_tspec)(void *ctx, const u8 *sta_addr, u8 *tspec_ie,
index 16ab9921f89f70a70c8512f65033d9e5902d4680..229daef607e6c19a82145b99dc09fae4d84f6aae 100644 (file)
@@ -888,6 +888,148 @@ static int hostapd_wpa_auth_get_vlan(void *ctx, const u8 *sta_addr,
 }
 
 
+static int
+hostapd_wpa_auth_set_identity(void *ctx, const u8 *sta_addr,
+                             const u8 *identity, size_t identity_len)
+{
+       struct hostapd_data *hapd = ctx;
+       struct sta_info *sta;
+
+       sta = ap_get_sta(hapd, sta_addr);
+       if (!sta)
+               return -1;
+
+       os_free(sta->identity);
+       sta->identity = NULL;
+
+       if (sta->eapol_sm) {
+               os_free(sta->eapol_sm->identity);
+               sta->eapol_sm->identity = NULL;
+               sta->eapol_sm->identity_len = 0;
+       }
+
+       if (!identity_len)
+               return 0;
+
+       /* sta->identity is NULL terminated */
+       sta->identity = os_zalloc(identity_len + 1);
+       if (!sta->identity)
+               return -1;
+       os_memcpy(sta->identity, identity, identity_len);
+
+       if (sta->eapol_sm) {
+               sta->eapol_sm->identity = os_zalloc(identity_len);
+               if (!sta->eapol_sm->identity)
+                       return -1;
+               os_memcpy(sta->eapol_sm->identity, identity, identity_len);
+               sta->eapol_sm->identity_len = identity_len;
+       }
+
+       return 0;
+}
+
+
+static size_t
+hostapd_wpa_auth_get_identity(void *ctx, const u8 *sta_addr, const u8 **buf)
+{
+       struct hostapd_data *hapd = ctx;
+       struct sta_info *sta;
+       size_t len;
+       char *identity;
+
+       sta = ap_get_sta(hapd, sta_addr);
+       if (!sta)
+               return 0;
+
+       *buf = ieee802_1x_get_identity(sta->eapol_sm, &len);
+       if (*buf && len)
+               return len;
+
+       if (!sta->identity) {
+               *buf = NULL;
+               return 0;
+       }
+
+       identity = sta->identity;
+       len = os_strlen(identity);
+       *buf = (u8 *) identity;
+
+       return len;
+}
+
+
+static int
+hostapd_wpa_auth_set_radius_cui(void *ctx, const u8 *sta_addr,
+                               const u8 *radius_cui, size_t radius_cui_len)
+{
+       struct hostapd_data *hapd = ctx;
+       struct sta_info *sta;
+
+       sta = ap_get_sta(hapd, sta_addr);
+       if (!sta)
+               return -1;
+
+       os_free(sta->radius_cui);
+       sta->radius_cui = NULL;
+
+       if (sta->eapol_sm) {
+               wpabuf_free(sta->eapol_sm->radius_cui);
+               sta->eapol_sm->radius_cui = NULL;
+       }
+
+       if (!radius_cui)
+               return 0;
+
+       /* sta->radius_cui is NULL terminated */
+       sta->radius_cui = os_zalloc(radius_cui_len + 1);
+       if (!sta->radius_cui)
+               return -1;
+       os_memcpy(sta->radius_cui, radius_cui, radius_cui_len);
+
+       if (sta->eapol_sm) {
+               sta->eapol_sm->radius_cui = wpabuf_alloc_copy(radius_cui,
+                                                             radius_cui_len);
+               if (!sta->eapol_sm->radius_cui)
+                       return -1;
+       }
+
+       return 0;
+}
+
+
+static size_t
+hostapd_wpa_auth_get_radius_cui(void *ctx, const u8 *sta_addr, const u8 **buf)
+{
+       struct hostapd_data *hapd = ctx;
+       struct sta_info *sta;
+       struct wpabuf *b;
+       size_t len;
+       char *radius_cui;
+
+       sta = ap_get_sta(hapd, sta_addr);
+       if (!sta)
+               return 0;
+
+       b = ieee802_1x_get_radius_cui(sta->eapol_sm);
+       if (b) {
+               len = wpabuf_len(b);
+               *buf = wpabuf_head(b);
+               return len;
+       }
+
+       if (!sta->radius_cui) {
+               *buf = NULL;
+               return 0;
+       }
+
+       radius_cui = sta->radius_cui;
+       len = os_strlen(radius_cui);
+       *buf = (u8 *) radius_cui;
+
+       return len;
+}
+
+
 static void hostapd_rrb_receive(void *ctx, const u8 *src_addr, const u8 *buf,
                                size_t len)
 {
@@ -1009,6 +1151,10 @@ int hostapd_setup_wpa(struct hostapd_data *hapd)
                .add_tspec = hostapd_wpa_auth_add_tspec,
                .set_vlan = hostapd_wpa_auth_set_vlan,
                .get_vlan = hostapd_wpa_auth_get_vlan,
+               .set_identity = hostapd_wpa_auth_set_identity,
+               .get_identity = hostapd_wpa_auth_get_identity,
+               .set_radius_cui = hostapd_wpa_auth_set_radius_cui,
+               .get_radius_cui = hostapd_wpa_auth_get_radius_cui,
 #endif /* CONFIG_IEEE80211R_AP */
        };
        const u8 *wpa_ie;