osmo-epdg: implement Tunnel Request/Response
Requires gsup message types in libosmocore
This commit is contained in:
parent
2bf7e10d94
commit
c469464d8a
|
@ -194,6 +194,56 @@ static bool enqueue(private_osmo_epdg_gsup_client_t *this, gsup_request_t *req,
|
|||
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 osmo_gsup_pdp_info *pdp;
|
||||
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));
|
||||
|
||||
if (apn && strlen(apn) > 0)
|
||||
{
|
||||
gsup_msg.num_pdp_infos = 1;
|
||||
pdp = &gsup_msg.pdp_infos[0];
|
||||
pdp->context_id = 1;
|
||||
pdp->have_info = 1;
|
||||
pdp->apn_enc = apn;
|
||||
pdp->apn_enc_len = strlen(apn);
|
||||
}
|
||||
|
||||
msg = encode_to_msgb(&gsup_msg);
|
||||
if (!msg)
|
||||
{
|
||||
DBG1(DBG_NET, "Couldn't alloc/encode gsup message.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gsup_request_t *req = gsup_request_create(OSMO_GSUP_MSGT_EPDG_TUNNEL_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 resp;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -403,6 +453,8 @@ static bool on_recv_pdu(void *data, osmo_epdg_ipa_client_t *client, struct msgb
|
|||
case OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT:
|
||||
case OSMO_GSUP_MSGT_UPDATE_LOCATION_ERROR:
|
||||
case OSMO_GSUP_MSGT_UPDATE_LOCATION_RESULT:
|
||||
case OSMO_GSUP_MSGT_EPDG_TUNNEL_ERROR:
|
||||
case OSMO_GSUP_MSGT_EPDG_TUNNEL_RESULT:
|
||||
this->mutex->lock(this->mutex);
|
||||
if ((this->current_request->msg_type & 0xfffffffc) != (resp->gsup.message_type & 0xfffffffc))
|
||||
{
|
||||
|
@ -489,6 +541,7 @@ osmo_epdg_gsup_client_t *osmo_epdg_gsup_client_create(char *uri)
|
|||
.public = {
|
||||
.send_auth_request = _send_auth_request,
|
||||
.update_location = _update_location,
|
||||
.tunnel_request = _tunnel_request,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
.uri = strdup(uri),
|
||||
|
|
|
@ -61,6 +61,14 @@ struct osmo_epdg_gsup_client_t {
|
|||
char *imsi,
|
||||
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.
|
||||
*/
|
||||
|
|
|
@ -84,17 +84,49 @@ METHOD(listener_t, authorize, bool,
|
|||
private_osmo_epdg_listener_t *this, ike_sa_t *ike_sa,
|
||||
bool final, bool *success)
|
||||
{
|
||||
int ret;
|
||||
char apn[APN_MAXLEN];
|
||||
DBG1(DBG_NET, "Authorized: uniq 0x%08x, name %s final: %d, eap: %d!",
|
||||
ike_sa->get_unique_id(ike_sa),
|
||||
ike_sa->get_name(ike_sa),
|
||||
final,
|
||||
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;
|
||||
}
|
||||
|
||||
apn[0] = 0;
|
||||
ret = get_apn(sa, apn, APN_MAXLEN);
|
||||
if (!ret && ret != -EINVAL)
|
||||
{
|
||||
DBG1(DBG_NET, "epdg_listener: Tunnel Request: Couldn't get APN!");
|
||||
goto err;
|
||||
}
|
||||
|
||||
osmo_epdg_gsup_response_t *resp = this->gsup->tunnel_request(this->gsup, imsi, apn);
|
||||
if (!resp)
|
||||
{
|
||||
DBG1(DBG_NET, "epdg_listener: Tunnel Request: GSUP: couldn't send.");
|
||||
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 Response: unexpected message type: %02x", resp->gsup.message_type);
|
||||
goto err;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
err:
|
||||
*success = FALSE;
|
||||
/* keep still subscribed */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <sa/ike_sa.h>
|
||||
#include <utils/utils.h>
|
||||
#include <utils/debug.h>
|
||||
|
||||
|
@ -63,3 +64,25 @@ int get_imsi(identification_t *id, char *imsi, size_t imsi_len)
|
|||
strncpy(imsi, nai.ptr + 1, min(15, imsi_len));
|
||||
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;
|
||||
}
|
||||
|
||||
memcpy(apn, apn_chunk.ptr, apn_chunk.len);
|
||||
apn[apn_chunk.len] = 0;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define OSMO_EPDG_UTILS_H_
|
||||
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <sa/ike_sa.h>
|
||||
#include <utils/chunk.h>
|
||||
#include <utils/identification.h>
|
||||
|
||||
|
@ -28,5 +29,6 @@
|
|||
|
||||
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);
|
||||
|
||||
#endif /* OSMO_EPDG_UTILS_H_ */
|
||||
|
|
Loading…
Reference in New Issue