start implementing osmo_epdg

This commit is contained in:
Alexander Couzens 2023-03-28 21:02:23 +02:00
parent d776ea007c
commit 8074d68e57
3 changed files with 196 additions and 0 deletions

View File

@ -0,0 +1,98 @@
/*
* Copyright (C) 2023 sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
* Author: Alexander Couzens <acouzens@sysmocom.de>
*
* SPDX-License-Identifier: GPL-2.0+
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
*/
#include <daemon.h>
#include <plugins/plugin.h>
#include <unistd.h>
#include "osmo_epdg_plugin.h"
#include "osmo_epdg_db.h"
#include "osmo_epdg_utils.h"
typedef struct private_osmo_epdg_db_t private_osmo_epdg_db_t;
/**
* Private data of an osmo_epdg_db_t object.
*/
struct private_osmo_epdg_db_t {
/**
* Public osmo_epdg_db_t interface.
*/
osmo_epdg_db_t public;
osmo_epdg_gsup_client_t *gsup;
};
METHOD(osmo_epdg_db_t, create_subscriber_imsi, osmo_epdg_ue_t *,
private_osmo_epdg_db_t *this, ike_sa_t *ike_sa,
char *imsi)
{
return NULL;
}
METHOD(osmo_epdg_db_t, get_subscriber_imsi, osmo_epdg_ue_t *,
private_osmo_epdg_db_t *this, char *imsi, int offset)
{
return NULL;
}
METHOD(osmo_epdg_db_t, get_subscriber_id, osmo_epdg_ue_t *,
private_osmo_epdg_db_t *this, uint32_t id)
{
return NULL;
}
METHOD(osmo_epdg_db_t, destroy_subscriber_id, void,
private_osmo_epdg_db_t *this, uint32_t id)
{
return NULL;
}
METHOD(osmo_epdg_db_t, destroy_subscriber, void,
private_osmo_epdg_db_t *this)
{
return NULL;
}
METHOD(osmo_epdg_db_t, destroy, void,
private_osmo_epdg_db_t *this)
{
free(this);
}
/**
* See header
*/
osmo_epdg_db_t *osmo_epdg_db_create(osmo_epdg_gsup_client_t *gsup)
{
private_osmo_epdg_db_t *this;
INIT(this,
.public = {
.create_subscriber_imsi = _create_subscriber_imsi,
.create_subscriber = _create_subscriber,
.get_subscriber_id = _get_subscriber_id,
.get_subscriber_imsi = _get_subscriber_imsi,
.destroy_subscriber_id = _destroy_subscriber_id,
.destroy_subscriber = _destroy_subscriber,
.destroy = _destroy,
},
);
return &this->public;
}

View File

@ -0,0 +1,74 @@
/*
* Copyright (C) 2023 sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
* Author: Alexander Couzens <acouzens@sysmocom.de>
*
* SPDX-License-Identifier: GPL-2.0+
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
*/
// TODO: check license
/**
* @defgroup osmo_epdg_db osmo_epdg_db
* @{ @ingroup osmo_epdg
*/
#ifndef OSMO_EPDG_LISTENER_H_
#define OSMO_EPDG_LISTENER_H_
#include <bus/listeners/listener.h>
#include "gsup_client.h"
typedef struct osmo_epdg_db_t osmo_epdg_db_t;
/**
* SIM listener implementation using a set of AKA functions.
*/
struct osmo_epdg_db_t {
/**
* Create new subscriber by imsi, before sending authentication
*/
osmo_epdg_ue_t *(*create_subscriber_imsi)(osmo_epdg_db_t *this, ike_sa_t *ike_sa, char *imsi);
/**
* Get subscriber by imsi, there might be multiple UE by this IMSI
*/
osmo_epdg_ue_t *(*get_subscriber_imsi)(osmo_epdg_db_t *this, char *imsi, int offset);
/**
* Get subscriber by id
*/
osmo_epdg_ue_t *(*get_subscriber_id)(osmo_epdg_db_t *this, uint32_t id);
/**
* Destroy subscriber by imsi
*/
void (*destroy_subscriber_id)(osmo_epdg_db_t *this, uint32_t id);
/**
* Destroy subscriber by object
*/
void (*destroy_subscriber)(osmo_epdg_db_t *this, osmo_epdg_ue_t *ue);
/**
* Destroy a osmo_epdg_db_t.
*/
void (*destroy)(osmo_epdg_db_t *this);
};
/**
* Create a osmo_epdg_db instance.
*/
osmo_epdg_db_t *osmo_epdg_db_create(osmo_epdg_gsup_client_t *gsup);
#endif /** OSMO_EPDG_LISTENER_H_ @}*/

View File

@ -24,6 +24,30 @@
#define IPA_ALLOC_SIZE 1200
enum ue_state state {
/* Initial */
UE_UNAUTHENTICATED,
/* Authenticated */
UE_AUTHENTICATED,
/* Wait for GSUP Update Location Request */
UE_WAIT_LOCATION_UPDATE,
/* Wait for GSUP Tunnel Request */
UE_WAIT_TUNNEL,
/* Everything ready, data can flow */
UE_CONNECTED,
};
/* TODO: how to clean up/garbage collect */
struct osmo_epdg_ue {
/* increasing uniq id */
uint32_t id;
/* imsi should be uniq, need protected against fake UE */
char *imsi;
enum ue_state state;
/* TODO: missing strongswan session pointer */
};
typedef struct osmo_epdg_ue osmo_epdg_ue_t;
struct msgb *chunk_to_msgb(chunk_t *chunk);
int get_imsi(identification_t *id, char *imsi, size_t imsi_len);
int get_apn(ike_sa_t *sa, char *apn, size_t apn_len);