2017-11-20 18:15:31 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Wireless daemon for Linux
|
|
|
|
*
|
2019-10-25 00:43:08 +02:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation. All rights reserved.
|
2017-11-20 18:15:31 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-04-04 14:02:38 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2017-11-20 18:15:31 +01:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ell/ell.h>
|
|
|
|
|
2018-10-26 21:34:58 +02:00
|
|
|
#include "src/iwd.h"
|
2019-11-07 23:33:51 +01:00
|
|
|
#include "src/module.h"
|
2018-10-26 21:34:58 +02:00
|
|
|
#include "src/watchlist.h"
|
|
|
|
#include "src/simauth.h"
|
2017-11-20 18:15:31 +01:00
|
|
|
|
|
|
|
static struct l_queue *auth_providers;
|
|
|
|
|
|
|
|
struct iwd_sim_auth {
|
|
|
|
const struct iwd_sim_auth_driver *driver;
|
|
|
|
void *driver_data;
|
|
|
|
bool aka_supported : 1;
|
|
|
|
bool sim_supported : 1;
|
|
|
|
char *nai;
|
|
|
|
int pending;
|
2017-12-12 00:55:46 +01:00
|
|
|
struct watchlist auth_watchers;
|
2017-11-20 18:15:31 +01:00
|
|
|
};
|
|
|
|
|
2017-12-12 00:55:46 +01:00
|
|
|
struct iwd_sim_auth *iwd_sim_auth_create(
|
|
|
|
const struct iwd_sim_auth_driver *driver)
|
2017-11-20 18:15:31 +01:00
|
|
|
{
|
|
|
|
struct iwd_sim_auth *auth = l_new(struct iwd_sim_auth, 1);
|
|
|
|
|
2017-12-12 00:55:46 +01:00
|
|
|
auth->driver = driver;
|
|
|
|
watchlist_init(&auth->auth_watchers, NULL);
|
2017-11-20 18:15:31 +01:00
|
|
|
|
2017-12-12 00:55:46 +01:00
|
|
|
return auth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iwd_sim_auth_set_nai(struct iwd_sim_auth *auth, const char *nai)
|
|
|
|
{
|
2017-11-20 18:15:31 +01:00
|
|
|
auth->nai = l_strdup(nai);
|
2017-12-12 00:55:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void iwd_sim_auth_set_capabilities(struct iwd_sim_auth *auth,
|
|
|
|
bool sim_supported, bool aka_supported)
|
|
|
|
{
|
|
|
|
auth->sim_supported = sim_supported;
|
|
|
|
auth->aka_supported = aka_supported;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iwd_sim_auth_set_data(struct iwd_sim_auth *auth, void *driver_data)
|
|
|
|
{
|
2017-11-20 18:15:31 +01:00
|
|
|
auth->driver_data = driver_data;
|
2017-12-12 00:55:46 +01:00
|
|
|
}
|
2017-11-20 18:15:31 +01:00
|
|
|
|
2017-12-12 00:55:46 +01:00
|
|
|
bool iwd_sim_auth_register(struct iwd_sim_auth *auth)
|
|
|
|
{
|
|
|
|
return l_queue_push_head(auth_providers, auth);
|
|
|
|
}
|
2017-11-20 18:15:31 +01:00
|
|
|
|
|
|
|
void *iwd_sim_auth_get_data(struct iwd_sim_auth *auth)
|
|
|
|
{
|
|
|
|
return auth->driver_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy_provider(void *data)
|
|
|
|
{
|
|
|
|
struct iwd_sim_auth *auth = data;
|
|
|
|
|
|
|
|
if (auth->driver->remove)
|
|
|
|
auth->driver->remove(auth);
|
|
|
|
|
2017-12-12 00:55:46 +01:00
|
|
|
watchlist_destroy(&auth->auth_watchers);
|
2017-11-30 19:15:18 +01:00
|
|
|
|
2017-11-20 18:15:31 +01:00
|
|
|
l_free(auth->nai);
|
|
|
|
l_free(auth);
|
|
|
|
}
|
|
|
|
|
2017-12-12 00:55:46 +01:00
|
|
|
void iwd_sim_auth_remove(struct iwd_sim_auth *auth)
|
2017-11-20 18:15:31 +01:00
|
|
|
{
|
2020-11-16 23:22:18 +01:00
|
|
|
if (auth->driver && auth->driver->cancel_request)
|
2017-12-14 23:26:17 +01:00
|
|
|
auth->driver->cancel_request(auth, auth->pending);
|
|
|
|
|
|
|
|
WATCHLIST_NOTIFY_NO_ARGS(&auth->auth_watchers,
|
|
|
|
sim_auth_unregistered_cb_t);
|
|
|
|
|
|
|
|
l_queue_remove(auth_providers, auth);
|
2017-11-20 18:15:31 +01:00
|
|
|
|
|
|
|
destroy_provider(auth);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *iwd_sim_auth_get_nai(struct iwd_sim_auth *auth)
|
|
|
|
{
|
|
|
|
return auth->nai;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct iwd_sim_auth *iwd_sim_auth_find(bool sim, bool aka)
|
|
|
|
{
|
|
|
|
struct iwd_sim_auth *auth;
|
|
|
|
const struct l_queue_entry *entry;
|
|
|
|
|
|
|
|
for (entry = l_queue_get_entries(auth_providers); entry;
|
|
|
|
entry = entry->next) {
|
|
|
|
auth = entry->data;
|
|
|
|
|
|
|
|
if (sim && !auth->sim_supported)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (aka && !auth->aka_supported)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return auth;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-12-12 00:55:46 +01:00
|
|
|
unsigned int sim_auth_unregistered_watch_add(struct iwd_sim_auth *auth,
|
|
|
|
sim_auth_unregistered_cb_t cb, void *data)
|
2017-11-20 18:15:31 +01:00
|
|
|
{
|
2017-12-12 00:55:46 +01:00
|
|
|
return watchlist_add(&auth->auth_watchers, cb, data, NULL);
|
2017-11-20 18:15:31 +01:00
|
|
|
}
|
|
|
|
|
2017-12-12 00:55:46 +01:00
|
|
|
void sim_auth_unregistered_watch_remove(struct iwd_sim_auth *auth,
|
2017-11-20 18:15:31 +01:00
|
|
|
unsigned int id)
|
|
|
|
{
|
2017-12-12 00:55:46 +01:00
|
|
|
watchlist_remove(&auth->auth_watchers, id);
|
2017-11-20 18:15:31 +01:00
|
|
|
}
|
|
|
|
|
2017-12-13 22:19:36 +01:00
|
|
|
int sim_auth_check_milenage(struct iwd_sim_auth *auth,
|
2017-11-20 18:15:31 +01:00
|
|
|
const uint8_t *rand, const uint8_t *autn,
|
|
|
|
sim_auth_check_milenage_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
if (!auth->aka_supported)
|
2017-12-13 22:19:36 +01:00
|
|
|
return -1;
|
2017-11-20 18:15:31 +01:00
|
|
|
|
|
|
|
/* save ID in case simauth is destroyed */
|
|
|
|
auth->pending = auth->driver->check_milenage(auth, rand, autn,
|
|
|
|
cb, data);
|
|
|
|
|
|
|
|
return auth->pending;
|
|
|
|
}
|
|
|
|
|
2017-12-13 22:19:36 +01:00
|
|
|
int sim_auth_run_gsm(struct iwd_sim_auth *auth, const uint8_t *rands,
|
2017-11-20 18:15:31 +01:00
|
|
|
int num_rands, sim_auth_run_gsm_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
if (!auth->sim_supported)
|
2017-12-13 22:19:36 +01:00
|
|
|
return -1;
|
2017-11-20 18:15:31 +01:00
|
|
|
|
|
|
|
/* save ID in case simauth is destroyed */
|
|
|
|
auth->pending = auth->driver->run_gsm(auth, rands, num_rands, cb, data);
|
|
|
|
|
|
|
|
return auth->pending;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sim_auth_cancel_request(struct iwd_sim_auth *auth, int id)
|
|
|
|
{
|
|
|
|
if (auth->driver->cancel_request)
|
|
|
|
auth->driver->cancel_request(auth, id);
|
|
|
|
}
|
|
|
|
|
2019-05-19 20:10:06 +02:00
|
|
|
static int sim_auth_init(void)
|
2017-11-20 18:15:31 +01:00
|
|
|
{
|
|
|
|
auth_providers = l_queue_new();
|
2019-05-19 20:10:06 +02:00
|
|
|
return 0;
|
2017-11-20 18:15:31 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 20:10:06 +02:00
|
|
|
static void sim_auth_exit(void)
|
2017-11-20 18:15:31 +01:00
|
|
|
{
|
|
|
|
if (l_queue_length(auth_providers) > 0)
|
|
|
|
l_warn("Auth provider queue was not empty on exit!");
|
|
|
|
|
|
|
|
l_queue_destroy(auth_providers, destroy_provider);
|
|
|
|
}
|
2019-05-19 20:10:06 +02:00
|
|
|
|
|
|
|
IWD_MODULE(simauth, sim_auth_init, sim_auth_exit)
|