osmo-epdg: implement Tunnel Request/Response

Requires gsup message types in libosmocore
This commit is contained in:
Alexander Couzens 2023-03-23 17:44:19 +01:00
parent 46a01090bb
commit 40974e78dd
5 changed files with 100 additions and 4 deletions

View File

@ -194,6 +194,47 @@ static bool enqueue(private_osmo_epdg_gsup_client_t *this, gsup_request_t *req,
return ret; return ret;
} }
METHOD(osmo_epdg_gsup_client_t, tunnel_request, osmo_epdg_gsup_response_t*,
private_osmo_epdg_gsup_client_t *this, char *imsi, char *apn)
{
struct osmo_gsup_message gsup_msg = {0};
struct msgb *msg;
bool timedout;
DBG1(DBG_NET, "Tunnel Request Request for %s", imsi);
gsup_msg.message_type = OSMO_GSUP_MSGT_EPDG_TUNNEL_REQUEST;
gsup_msg.current_rat_type = OSMO_RAT_EUTRAN_SGS;
if (!imsi || strlen(imsi) == 0)
{
/* TODO: inval imsi! */
return NULL;
}
strncpy(gsup_msg.imsi, imsi, sizeof(gsup_msg.imsi));
msg = encode_to_msgb(&gsup_msg);
if (!msg)
{
DBG1(DBG_NET, "Couldn't alloc/encode gsup message.");
return NULL;
}
/* TODO: add APN! */
gsup_request_t *req = gsup_request_create(OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST, msg);
osmo_epdg_gsup_response_t *resp = NULL;
timedout = enqueue(this, req, 5000);
if (timedout)
{
gsup_request_destroy(this, req);
return NULL;
}
resp = req->resp;
req->resp = NULL;
gsup_request_destroy(this, req);
return ret;
}
METHOD(osmo_epdg_gsup_client_t, send_auth_request, osmo_epdg_gsup_response_t*, METHOD(osmo_epdg_gsup_client_t, send_auth_request, osmo_epdg_gsup_response_t*,
private_osmo_epdg_gsup_client_t *this, char *imsi, uint8_t cn_domain, chunk_t *auts, chunk_t *auts_rand) private_osmo_epdg_gsup_client_t *this, char *imsi, uint8_t cn_domain, chunk_t *auts, chunk_t *auts_rand)
{ {
@ -489,6 +530,7 @@ osmo_epdg_gsup_client_t *osmo_epdg_gsup_client_create(char *uri)
.public = { .public = {
.send_auth_request = _send_auth_request, .send_auth_request = _send_auth_request,
.update_location = _update_location, .update_location = _update_location,
.tunnel_request = _tunnel_request,
.destroy = _destroy, .destroy = _destroy,
}, },
.uri = strdup(uri), .uri = strdup(uri),

View File

@ -61,6 +61,14 @@ struct osmo_epdg_gsup_client_t {
char *imsi, char *imsi,
uint8_t cn_domain); uint8_t cn_domain);
/**
* Tunnel Request
*
* @return NULL or the osmo_gsup_message
*/
osmo_epdg_gsup_response_t *(*tunnel_request)(osmo_epdg_gsup_client_t *this,
char *imsi, char *apn);
/** /**
* Destroy a osmo_epdg_gsup_client_t. * Destroy a osmo_epdg_gsup_client_t.
*/ */

View File

@ -89,12 +89,34 @@ METHOD(listener_t, authorize, bool,
ike_sa->get_name(ike_sa), ike_sa->get_name(ike_sa),
final, final,
ike_sa->has_condition(ike_sa, COND_EAP_AUTHENTICATED)); ike_sa->has_condition(ike_sa, COND_EAP_AUTHENTICATED));
sleep(1); if (!final)
if (final)
{ {
/* TODO: create new Tunnel and save Tunnel information locally */ return TRUE;
} }
osmo_epdg_gsup_response_t *resp = this->gsup->tunnel_request(this->gsup, imsi, apn);
if (!resp)
{
DBG1(DBG_NET, "epdg: GSUP: couldn't send Tunnel Requeset.");
goto err;
}
if (resp->gsup.message_type == OSMO_GSUP_MSGT_EPDG_TUNNEL_ERROR)
{
DBG1(DBG_NET, "epdg_listener: Tunnel Error! Cause: %02x", resp->gsup.cause);
goto err;
}
else if (resp->gsup.message_type != OSMO_GSUP_MSGT_EPDG_TUNNEL_RESULT)
{
DBG1(DBG_NET, "epdg_listener: Tunnel unexpected message type: %02x", resp->gsup.message_type);
goto err;
}
return TRUE;
err:
*success = FALSE;
/* keep still subscribed */
return TRUE; return TRUE;
} }

View File

@ -19,6 +19,7 @@
#include <errno.h> #include <errno.h>
#include <osmocom/core/msgb.h> #include <osmocom/core/msgb.h>
#include <sa/ike_sa.h>
#include <utils/utils.h> #include <utils/utils.h>
#include <utils/debug.h> #include <utils/debug.h>
@ -63,3 +64,24 @@ int get_imsi(identification_t *id, char *imsi, size_t imsi_len)
strncpy(imsi, nai.ptr + 1, min(15, imsi_len)); strncpy(imsi, nai.ptr + 1, min(15, imsi_len));
return 0; return 0;
} }
int get_apn(ike_sa_t *sa, char *apn, size_t apn_len)
{
identification_t* apn_id;
chunk_t apn_chunk;
apn_id = sa->get_my_id(sa);
if (!apn_id)
{
return -EINVAL;
}
apn_chunk = apn_id->get_encoding(apn_id);
if (apn_chunk.len >= apn_len)
{
return -ENOMEM;
}
strncpy(apn, apn_chunk.ptr, apn_len);
return -1;
}

View File

@ -17,6 +17,7 @@
*/ */
#include <osmocom/core/msgb.h> #include <osmocom/core/msgb.h>
#include <sa/ike_sa.h>
#include <utils/chunk.h> #include <utils/chunk.h>
#include <utils/identification.h> #include <utils/identification.h>
@ -25,3 +26,4 @@
struct msgb *chunk_to_msgb(chunk_t *chunk); struct msgb *chunk_to_msgb(chunk_t *chunk);
int get_imsi(identification_t *id, char *imsi, size_t imsi_len); 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);