From 7006cc0c4663b7c884a5fdbb04631696ddc2b475 Mon Sep 17 00:00:00 2001 From: Alexander Couzens Date: Fri, 9 Feb 2024 18:27:12 +0100 Subject: [PATCH] osmo_epdg: add PDP Info on SAI GSUP messages The SAI GSUP message now requires to have PDP Info filled with APN and PDP type which should be already knows at this state. Hardcoding PDP type for now. --- src/libcharon/plugins/osmo_epdg/gsup_client.c | 29 +++++++++++++++++-- src/libcharon/plugins/osmo_epdg/gsup_client.h | 3 +- .../plugins/osmo_epdg/osmo_epdg_provider.c | 23 +++++++++++++-- .../plugins/osmo_epdg/osmo_epdg_utils.c | 2 +- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/libcharon/plugins/osmo_epdg/gsup_client.c b/src/libcharon/plugins/osmo_epdg/gsup_client.c index 8b5f09834..78fb9f3cf 100644 --- a/src/libcharon/plugins/osmo_epdg/gsup_client.c +++ b/src/libcharon/plugins/osmo_epdg/gsup_client.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -198,7 +199,6 @@ METHOD(osmo_epdg_gsup_client_t, tunnel_request, osmo_epdg_gsup_response_t*, private_osmo_epdg_gsup_client_t *this, char *imsi) { struct osmo_gsup_message gsup_msg = {0}; - struct osmo_gsup_pdp_info *pdp; struct msgb *msg; bool timedout; @@ -236,11 +236,15 @@ METHOD(osmo_epdg_gsup_client_t, tunnel_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, char *apn, uint8_t pdp_type) { struct osmo_gsup_message gsup_msg = {0}; struct msgb *msg; bool timedout; + char apn_enc[APN_MAXLEN]; + size_t apn_enc_len = 0; + int ret; DBG1(DBG_NET, "Send Auth Request for %s", imsi); gsup_msg.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST; @@ -255,6 +259,12 @@ METHOD(osmo_epdg_gsup_client_t, send_auth_request, osmo_epdg_gsup_response_t*, } strncpy(gsup_msg.imsi, imsi, sizeof(gsup_msg.imsi)); + if (!apn || strlen(apn) == 0) + { + /* TODO: inval apn! */ + return NULL; + } + switch (cn_domain) { case 0: @@ -292,6 +302,21 @@ METHOD(osmo_epdg_gsup_client_t, send_auth_request, osmo_epdg_gsup_response_t*, gsup_msg.rand = auts_rand->ptr; } + gsup_msg.pdp_infos[0].context_id = 0; + gsup_msg.pdp_infos[0].pdp_type_nr = pdp_type; + gsup_msg.pdp_infos[0].pdp_type_org = PDP_TYPE_ORG_IETF; + + ret = osmo_apn_from_str(apn_enc, APN_MAXLEN, apn); + if (ret < 0) + { + DBG1(DBG_NET, "Couldn't encode APN %s!", apn); + return NULL; + } + apn_enc_len = ret; + gsup_msg.pdp_infos[0].apn_enc = apn_enc; + gsup_msg.pdp_infos[0].apn_enc_len = apn_enc_len; + gsup_msg.num_pdp_infos = 1; + msg = encode_to_msgb(&gsup_msg); if (!msg) { diff --git a/src/libcharon/plugins/osmo_epdg/gsup_client.h b/src/libcharon/plugins/osmo_epdg/gsup_client.h index d0e8dfe4e..a238009ed 100644 --- a/src/libcharon/plugins/osmo_epdg/gsup_client.h +++ b/src/libcharon/plugins/osmo_epdg/gsup_client.h @@ -50,7 +50,8 @@ struct osmo_epdg_gsup_client_t { * @return NULL or the osmo_epdg_gsup_response_t */ osmo_epdg_gsup_response_t *(*send_auth_request)(osmo_epdg_gsup_client_t *this, - char *imsi, uint8_t cn_domain, chunk_t *auts, chunk_t *auts_rand); + char *imsi, uint8_t cn_domain, chunk_t *auts, chunk_t *auts_rand, + char *apn, uint8_t pdp_type); /** * Update Location Request diff --git a/src/libcharon/plugins/osmo_epdg/osmo_epdg_provider.c b/src/libcharon/plugins/osmo_epdg/osmo_epdg_provider.c index 872838275..85ca7ba8a 100644 --- a/src/libcharon/plugins/osmo_epdg/osmo_epdg_provider.c +++ b/src/libcharon/plugins/osmo_epdg/osmo_epdg_provider.c @@ -22,6 +22,8 @@ #include #include +#include +#include #define AKA_SQN_LEN 6 #define AKA_K_LEN 16 @@ -71,16 +73,31 @@ METHOD(simaka_provider_t, get_quintuplet, bool, char rand[AKA_RAND_LEN], char xres[AKA_RES_MAX], int *xres_len, char ck[AKA_CK_LEN], char ik[AKA_IK_LEN], char autn[AKA_AUTN_LEN]) { + char apn[APN_MAXLEN]; char imsi[17] = {0}; + ike_sa_t *ike_sa; + if (get_imsi(id, imsi, sizeof(imsi) - 1)) { DBG1(DBG_NET, "epdg: get_quintuplet: Can't find IMSI in EAP identity."); return FALSE; } - - /* TODO: check before if this is a null terminated string */ + + ike_sa = charon->bus->get_sa(charon->bus); + if (!ike_sa) + { + DBG1(DBG_NET, "epdg: get_quintuplet: Can't get ike_sa."); + return FALSE; + } + + if (get_apn(ike_sa, apn, APN_MAXLEN)) + { + DBG1(DBG_NET, "epdg: get_quintuplet: Can't get APN."); + return FALSE; + } + osmo_epdg_gsup_response_t *resp = this->gsup->send_auth_request( - this->gsup, imsi, OSMO_GSUP_CN_DOMAIN_PS, NULL, NULL); + this->gsup, imsi, OSMO_GSUP_CN_DOMAIN_PS, NULL, NULL, apn, PDP_TYPE_N_IETF_IPv4); if (!resp) { return FALSE; diff --git a/src/libcharon/plugins/osmo_epdg/osmo_epdg_utils.c b/src/libcharon/plugins/osmo_epdg/osmo_epdg_utils.c index c831e1e95..1ca34ed96 100644 --- a/src/libcharon/plugins/osmo_epdg/osmo_epdg_utils.c +++ b/src/libcharon/plugins/osmo_epdg/osmo_epdg_utils.c @@ -84,5 +84,5 @@ int get_apn(ike_sa_t *sa, char *apn, size_t apn_len) memcpy(apn, apn_chunk.ptr, apn_chunk.len); apn[apn_chunk.len] = 0; - return -1; + return 0; }