diff options
Diffstat (limited to 'openbsc/src/gprs/gprs_subscriber.c')
-rw-r--r-- | openbsc/src/gprs/gprs_subscriber.c | 131 |
1 files changed, 78 insertions, 53 deletions
diff --git a/openbsc/src/gprs/gprs_subscriber.c b/openbsc/src/gprs/gprs_subscriber.c index 3467293be..71f5ff188 100644 --- a/openbsc/src/gprs/gprs_subscriber.c +++ b/openbsc/src/gprs/gprs_subscriber.c @@ -20,13 +20,14 @@ * */ +#include <osmocom/gsm/protocol/gsm_04_08_gprs.h> +#include <osmocom/gsm/gsup.h> #include <openbsc/gsm_subscriber.h> #include <openbsc/gprs_gsup_client.h> #include <openbsc/sgsn.h> #include <openbsc/gprs_sgsn.h> #include <openbsc/gprs_gmm.h> -#include <openbsc/gprs_gsup_messages.h> #include <openbsc/gprs_utils.h> #include <openbsc/debug.h> @@ -158,14 +159,14 @@ void gprs_subscr_cancel(struct gsm_subscriber *subscr) } static int gprs_subscr_tx_gsup_message(struct gsm_subscriber *subscr, - struct gprs_gsup_message *gsup_msg) + struct osmo_gsup_message *gsup_msg) { struct msgb *msg = gprs_gsup_msgb_alloc(); if (strlen(gsup_msg->imsi) == 0 && subscr) strncpy(gsup_msg->imsi, subscr->imsi, sizeof(gsup_msg->imsi) - 1); - gprs_gsup_encode(msg, gsup_msg); + osmo_gsup_encode(msg, gsup_msg); LOGGSUBSCRP(LOGL_INFO, subscr, "Sending GSUP, will send: %s\n", msgb_hexdump(msg)); @@ -179,38 +180,38 @@ static int gprs_subscr_tx_gsup_message(struct gsm_subscriber *subscr, } static int gprs_subscr_tx_gsup_error_reply(struct gsm_subscriber *subscr, - struct gprs_gsup_message *gsup_orig, + struct osmo_gsup_message *gsup_orig, enum gsm48_gmm_cause cause) { - struct gprs_gsup_message gsup_reply = {0}; + struct osmo_gsup_message gsup_reply = {0}; strncpy(gsup_reply.imsi, gsup_orig->imsi, sizeof(gsup_reply.imsi) - 1); gsup_reply.cause = cause; gsup_reply.message_type = - GPRS_GSUP_TO_MSGT_ERROR(gsup_orig->message_type); + OSMO_GSUP_TO_MSGT_ERROR(gsup_orig->message_type); return gprs_subscr_tx_gsup_message(subscr, &gsup_reply); } static int gprs_subscr_handle_gsup_auth_res(struct gsm_subscriber *subscr, - struct gprs_gsup_message *gsup_msg) + struct osmo_gsup_message *gsup_msg) { unsigned idx; struct sgsn_subscriber_data *sdata = subscr->sgsn_data; LOGGSUBSCRP(LOGL_INFO, subscr, - "Got SendAuthenticationInfoResult, num_auth_tuples = %zu\n", - gsup_msg->num_auth_tuples); + "Got SendAuthenticationInfoResult, num_auth_vectors = %zu\n", + gsup_msg->num_auth_vectors); - if (gsup_msg->num_auth_tuples > 0) { + if (gsup_msg->num_auth_vectors > 0) { memset(sdata->auth_triplets, 0, sizeof(sdata->auth_triplets)); for (idx = 0; idx < ARRAY_SIZE(sdata->auth_triplets); idx++) sdata->auth_triplets[idx].key_seq = GSM_KEY_SEQ_INVAL; } - for (idx = 0; idx < gsup_msg->num_auth_tuples; idx++) { - size_t key_seq = gsup_msg->auth_tuples[idx].key_seq; + for (idx = 0; idx < gsup_msg->num_auth_vectors; idx++) { + size_t key_seq = idx; LOGGSUBSCRP(LOGL_DEBUG, subscr, "Adding auth tuple, cksn = %zu\n", key_seq); if (key_seq >= ARRAY_SIZE(sdata->auth_triplets)) { @@ -219,7 +220,8 @@ static int gprs_subscr_handle_gsup_auth_res(struct gsm_subscriber *subscr, key_seq); continue; } - sdata->auth_triplets[key_seq] = gsup_msg->auth_tuples[idx]; + sdata->auth_triplets[key_seq].vec = gsup_msg->auth_vectors[idx]; + sdata->auth_triplets[key_seq].key_seq = key_seq; } sdata->auth_triplets_updated = 1; @@ -259,7 +261,7 @@ static struct sgsn_subscriber_pdp_data *gprs_subscr_pdp_data_get_by_id( static void gprs_subscr_gsup_insert_data(struct gsm_subscriber *subscr, - struct gprs_gsup_message *gsup_msg) + struct osmo_gsup_message *gsup_msg) { struct sgsn_subscriber_data *sdata = subscr->sgsn_data; unsigned idx; @@ -296,7 +298,7 @@ static void gprs_subscr_gsup_insert_data(struct gsm_subscriber *subscr, } for (idx = 0; idx < gsup_msg->num_pdp_infos; idx++) { - struct gprs_gsup_pdp_info *pdp_info = &gsup_msg->pdp_infos[idx]; + struct osmo_gsup_pdp_info *pdp_info = &gsup_msg->pdp_infos[idx]; size_t ctx_id = pdp_info->context_id; struct sgsn_subscriber_pdp_data *pdp_data; @@ -336,8 +338,11 @@ static void gprs_subscr_gsup_insert_data(struct gsm_subscriber *subscr, } static int gprs_subscr_handle_gsup_upd_loc_res(struct gsm_subscriber *subscr, - struct gprs_gsup_message *gsup_msg) + struct osmo_gsup_message *gsup_msg) { + /* contrary to MAP, we allow piggy-backing subscriber data onto + * the UPDATE LOCATION RESULT, and don't mandate the use of a + * separate nested INSERT SUBSCRIBER DATA transaction */ gprs_subscr_gsup_insert_data(subscr, gsup_msg); subscr->authorized = 1; @@ -349,6 +354,22 @@ static int gprs_subscr_handle_gsup_upd_loc_res(struct gsm_subscriber *subscr, return 0; } +static int gprs_subscr_handle_gsup_isd_req(struct gsm_subscriber *subscr, + struct osmo_gsup_message *gsup_msg) +{ + struct osmo_gsup_message gsup_reply = {0}; + + gprs_subscr_gsup_insert_data(subscr, gsup_msg); + + subscr->authorized = 1; + subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE; + subscr->flags |= GPRS_SUBSCRIBER_ENABLE_PURGE; + gprs_subscr_update(subscr); + + gsup_reply.message_type = OSMO_GSUP_MSGT_INSERT_DATA_RESULT; + return gprs_subscr_tx_gsup_message(subscr, &gsup_reply); +} + static int check_cause(int cause) { switch (cause) { @@ -366,7 +387,7 @@ static int check_cause(int cause) } static int gprs_subscr_handle_gsup_auth_err(struct gsm_subscriber *subscr, - struct gprs_gsup_message *gsup_msg) + struct osmo_gsup_message *gsup_msg) { unsigned idx; struct sgsn_subscriber_data *sdata = subscr->sgsn_data; @@ -419,7 +440,7 @@ static int gprs_subscr_handle_gsup_auth_err(struct gsm_subscriber *subscr, } static int gprs_subscr_handle_gsup_upd_loc_err(struct gsm_subscriber *subscr, - struct gprs_gsup_message *gsup_msg) + struct osmo_gsup_message *gsup_msg) { int cause_err; @@ -465,9 +486,9 @@ static int gprs_subscr_handle_gsup_upd_loc_err(struct gsm_subscriber *subscr, } static int gprs_subscr_handle_gsup_purge_no_subscr( - struct gprs_gsup_message *gsup_msg) + struct osmo_gsup_message *gsup_msg) { - if (GPRS_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) { + if (OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) { LOGGSUPP(LOGL_NOTICE, gsup_msg, "Purge MS has failed with cause '%s' (%d)\n", get_value_string(gsm48_gmm_cause_names, gsup_msg->cause), @@ -480,7 +501,7 @@ static int gprs_subscr_handle_gsup_purge_no_subscr( } static int gprs_subscr_handle_gsup_purge_res(struct gsm_subscriber *subscr, - struct gprs_gsup_message *gsup_msg) + struct osmo_gsup_message *gsup_msg) { LOGGSUBSCRP(LOGL_INFO, subscr, "Completing purge MS\n"); @@ -492,7 +513,7 @@ static int gprs_subscr_handle_gsup_purge_res(struct gsm_subscriber *subscr, } static int gprs_subscr_handle_gsup_purge_err(struct gsm_subscriber *subscr, - struct gprs_gsup_message *gsup_msg) + struct osmo_gsup_message *gsup_msg) { LOGGSUBSCRP(LOGL_NOTICE, subscr, "Purge MS has failed with cause '%s' (%d)\n", @@ -525,17 +546,17 @@ static int gprs_subscr_handle_gsup_purge_err(struct gsm_subscriber *subscr, } static int gprs_subscr_handle_loc_cancel_req(struct gsm_subscriber *subscr, - struct gprs_gsup_message *gsup_msg) + struct osmo_gsup_message *gsup_msg) { - struct gprs_gsup_message gsup_reply = {0}; + struct osmo_gsup_message gsup_reply = {0}; int is_update_procedure = !gsup_msg->cancel_type || - gsup_msg->cancel_type == GPRS_GSUP_CANCEL_TYPE_UPDATE; + gsup_msg->cancel_type == OSMO_GSUP_CANCEL_TYPE_UPDATE; LOGGSUBSCRP(LOGL_INFO, subscr, "Cancelling MS subscriber (%s)\n", is_update_procedure ? "update procedure" : "subscription withdraw"); - gsup_reply.message_type = GPRS_GSUP_MSGT_LOCATION_CANCEL_RESULT; + gsup_reply.message_type = OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT; gprs_subscr_tx_gsup_message(subscr, &gsup_reply); if (is_update_procedure) @@ -552,16 +573,16 @@ static int gprs_subscr_handle_loc_cancel_req(struct gsm_subscriber *subscr, return 0; } -static int gprs_subscr_handle_unknown_imsi(struct gprs_gsup_message *gsup_msg) +static int gprs_subscr_handle_unknown_imsi(struct osmo_gsup_message *gsup_msg) { - if (GPRS_GSUP_IS_MSGT_REQUEST(gsup_msg->message_type)) { + if (OSMO_GSUP_IS_MSGT_REQUEST(gsup_msg->message_type)) { gprs_subscr_tx_gsup_error_reply(NULL, gsup_msg, GMM_CAUSE_IMSI_UNKNOWN); LOGP(DGPRS, LOGL_NOTICE, "Unknown IMSI %s, discarding GSUP request " "of type 0x%02x\n", gsup_msg->imsi, gsup_msg->message_type); - } else if (GPRS_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) { + } else if (OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) { LOGP(DGPRS, LOGL_NOTICE, "Unknown IMSI %s, discarding GSUP error " "of type 0x%02x, cause '%s' (%d)\n", @@ -584,10 +605,10 @@ int gprs_subscr_rx_gsup_message(struct msgb *msg) size_t data_len = msgb_l2len(msg); int rc = 0; - struct gprs_gsup_message gsup_msg = {0}; + struct osmo_gsup_message gsup_msg = {0}; struct gsm_subscriber *subscr; - rc = gprs_gsup_decode(data, data_len, &gsup_msg); + rc = osmo_gsup_decode(data, data_len, &gsup_msg); if (rc < 0) { LOGP(DGPRS, LOGL_ERROR, "decoding GSUP message fails with error '%s' (%d)\n", @@ -598,21 +619,21 @@ int gprs_subscr_rx_gsup_message(struct msgb *msg) if (!gsup_msg.imsi[0]) { LOGP(DGPRS, LOGL_ERROR, "Missing IMSI in GSUP message\n"); - if (GPRS_GSUP_IS_MSGT_REQUEST(gsup_msg.message_type)) + if (OSMO_GSUP_IS_MSGT_REQUEST(gsup_msg.message_type)) gprs_subscr_tx_gsup_error_reply(NULL, &gsup_msg, GMM_CAUSE_INV_MAND_INFO); return -GMM_CAUSE_INV_MAND_INFO; } - if (!gsup_msg.cause && GPRS_GSUP_IS_MSGT_ERROR(gsup_msg.message_type)) + if (!gsup_msg.cause && OSMO_GSUP_IS_MSGT_ERROR(gsup_msg.message_type)) gsup_msg.cause = GMM_CAUSE_NET_FAIL; subscr = gprs_subscr_get_by_imsi(gsup_msg.imsi); if (!subscr) { switch (gsup_msg.message_type) { - case GPRS_GSUP_MSGT_PURGE_MS_RESULT: - case GPRS_GSUP_MSGT_PURGE_MS_ERROR: + case OSMO_GSUP_MSGT_PURGE_MS_RESULT: + case OSMO_GSUP_MSGT_PURGE_MS_ERROR: return gprs_subscr_handle_gsup_purge_no_subscr(&gsup_msg); default: return gprs_subscr_handle_unknown_imsi(&gsup_msg); @@ -623,36 +644,39 @@ int gprs_subscr_rx_gsup_message(struct msgb *msg) "Received GSUP message of type 0x%02x\n", gsup_msg.message_type); switch (gsup_msg.message_type) { - case GPRS_GSUP_MSGT_LOCATION_CANCEL_REQUEST: + case OSMO_GSUP_MSGT_LOCATION_CANCEL_REQUEST: rc = gprs_subscr_handle_loc_cancel_req(subscr, &gsup_msg); break; - case GPRS_GSUP_MSGT_SEND_AUTH_INFO_RESULT: + case OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT: rc = gprs_subscr_handle_gsup_auth_res(subscr, &gsup_msg); break; - case GPRS_GSUP_MSGT_SEND_AUTH_INFO_ERROR: + case OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR: rc = gprs_subscr_handle_gsup_auth_err(subscr, &gsup_msg); break; - case GPRS_GSUP_MSGT_UPDATE_LOCATION_RESULT: + case OSMO_GSUP_MSGT_UPDATE_LOCATION_RESULT: rc = gprs_subscr_handle_gsup_upd_loc_res(subscr, &gsup_msg); break; - case GPRS_GSUP_MSGT_UPDATE_LOCATION_ERROR: + case OSMO_GSUP_MSGT_UPDATE_LOCATION_ERROR: rc = gprs_subscr_handle_gsup_upd_loc_err(subscr, &gsup_msg); break; - case GPRS_GSUP_MSGT_PURGE_MS_ERROR: + case OSMO_GSUP_MSGT_PURGE_MS_ERROR: rc = gprs_subscr_handle_gsup_purge_err(subscr, &gsup_msg); break; - case GPRS_GSUP_MSGT_PURGE_MS_RESULT: + case OSMO_GSUP_MSGT_PURGE_MS_RESULT: rc = gprs_subscr_handle_gsup_purge_res(subscr, &gsup_msg); break; - case GPRS_GSUP_MSGT_INSERT_DATA_REQUEST: - case GPRS_GSUP_MSGT_DELETE_DATA_REQUEST: + case OSMO_GSUP_MSGT_INSERT_DATA_REQUEST: + rc = gprs_subscr_handle_gsup_isd_req(subscr, &gsup_msg); + break; + + case OSMO_GSUP_MSGT_DELETE_DATA_REQUEST: LOGGSUBSCRP(LOGL_ERROR, subscr, "Rx GSUP message type %d not yet implemented\n", gsup_msg.message_type); @@ -665,7 +689,7 @@ int gprs_subscr_rx_gsup_message(struct msgb *msg) LOGGSUBSCRP(LOGL_ERROR, subscr, "Rx GSUP message type %d not valid at SGSN\n", gsup_msg.message_type); - if (GPRS_GSUP_IS_MSGT_REQUEST(gsup_msg.message_type)) + if (OSMO_GSUP_IS_MSGT_REQUEST(gsup_msg.message_type)) gprs_subscr_tx_gsup_error_reply( subscr, &gsup_msg, GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL); rc = -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL; @@ -680,11 +704,11 @@ int gprs_subscr_rx_gsup_message(struct msgb *msg) int gprs_subscr_purge(struct gsm_subscriber *subscr) { struct sgsn_subscriber_data *sdata = subscr->sgsn_data; - struct gprs_gsup_message gsup_msg = {0}; + struct osmo_gsup_message gsup_msg = {0}; LOGGSUBSCRP(LOGL_INFO, subscr, "purging MS subscriber\n"); - gsup_msg.message_type = GPRS_GSUP_MSGT_PURGE_MS_REQUEST; + gsup_msg.message_type = OSMO_GSUP_MSGT_PURGE_MS_REQUEST; /* Provide the HLR number in case it is known */ gsup_msg.hlr_enc_len = sdata->hlr_len; @@ -695,23 +719,23 @@ int gprs_subscr_purge(struct gsm_subscriber *subscr) int gprs_subscr_query_auth_info(struct gsm_subscriber *subscr) { - struct gprs_gsup_message gsup_msg = {0}; + struct osmo_gsup_message gsup_msg = {0}; LOGGSUBSCRP(LOGL_INFO, subscr, "subscriber auth info is not available\n"); - gsup_msg.message_type = GPRS_GSUP_MSGT_SEND_AUTH_INFO_REQUEST; + gsup_msg.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST; return gprs_subscr_tx_gsup_message(subscr, &gsup_msg); } int gprs_subscr_location_update(struct gsm_subscriber *subscr) { - struct gprs_gsup_message gsup_msg = {0}; + struct osmo_gsup_message gsup_msg = {0}; LOGGSUBSCRP(LOGL_INFO, subscr, "subscriber data is not available\n"); - gsup_msg.message_type = GPRS_GSUP_MSGT_UPDATE_LOCATION_REQUEST; + gsup_msg.message_type = OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST; return gprs_subscr_tx_gsup_message(subscr, &gsup_msg); } @@ -755,8 +779,9 @@ struct gsm_subscriber *gprs_subscr_get_or_create_by_mmctx(struct sgsn_mm_ctx *mm } if (strcpy(subscr->equipment.imei, mmctx->imei) != 0) { - strncpy(subscr->equipment.imei, mmctx->imei, GSM_IMEI_LENGTH-1); - subscr->equipment.imei[GSM_IMEI_LENGTH-1] = 0; + strncpy(subscr->equipment.imei, mmctx->imei, + sizeof(subscr->equipment.imei)-1); + subscr->equipment.imei[sizeof(subscr->equipment.imei)-1] = 0; } if (subscr->lac != mmctx->ra.lac) |