diff --git a/openbsc/include/openbsc/Makefile.am b/openbsc/include/openbsc/Makefile.am index 631a74e5e..8a31fe5a9 100644 --- a/openbsc/include/openbsc/Makefile.am +++ b/openbsc/include/openbsc/Makefile.am @@ -15,7 +15,7 @@ noinst_HEADERS = abis_nm.h abis_rsl.h db.h gsm_04_08.h gsm_data.h \ bss.h gsm_data_shared.h ipaccess.h mncc_int.h \ arfcn_range_encode.h nat_rewrite_trie.h bsc_nat_callstats.h \ osmux.h mgcp_transcode.h gprs_utils.h utils.h \ - gprs_gb_parse.h smpp.h meas_feed.h gprs_gsup_messages.h \ + gprs_gb_parse.h smpp.h meas_feed.h osmo_gsup_messages.h \ gprs_gsup_client.h bsc_msg_filter.h \ oap.h oap_messages.h \ gtphub.h diff --git a/openbsc/include/openbsc/gprs_gsup_messages.h b/openbsc/include/openbsc/gprs_gsup_messages.h deleted file mode 100644 index fe8bef555..000000000 --- a/openbsc/include/openbsc/gprs_gsup_messages.h +++ /dev/null @@ -1,119 +0,0 @@ -/* GPRS Subscriber Update Protocol message encoder/decoder */ - -/* (C) 2014 by Sysmocom s.f.m.c. GmbH - * All Rights Reserved - * - * Author: Jacob Erlbeck - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation; either version 3 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ -#pragma once - -#include -#include -#include -#include -#include - -#define GPRS_GSUP_MAX_NUM_PDP_INFO 10 /* GSM 09.02 limits this to 50 */ -#define GPRS_GSUP_MAX_NUM_AUTH_INFO 5 -#define GPRS_GSUP_MAX_MSISDN_LEN 9 - -#define GPRS_GSUP_PDP_TYPE_SIZE 2 - -enum gprs_gsup_iei { - GPRS_GSUP_IMSI_IE = 0x01, - GPRS_GSUP_CAUSE_IE = 0x02, - GPRS_GSUP_AUTH_TUPLE_IE = 0x03, - GPRS_GSUP_PDP_INFO_COMPL_IE = 0x04, - GPRS_GSUP_PDP_INFO_IE = 0x05, - GPRS_GSUP_CANCEL_TYPE_IE = 0x06, - GPRS_GSUP_FREEZE_PTMSI_IE = 0x07, - GPRS_GSUP_MSISDN_IE = 0x08, - GPRS_GSUP_HLR_NUMBER_IE = 0x09, - GPRS_GSUP_PDP_CONTEXT_ID_IE = 0x10, - GPRS_GSUP_PDP_TYPE_IE = 0x11, - GPRS_GSUP_ACCESS_POINT_NAME_IE = 0x12, - GPRS_GSUP_PDP_QOS_IE = 0x13, - GPRS_GSUP_RAND_IE = 0x20, - GPRS_GSUP_SRES_IE = 0x21, - GPRS_GSUP_KC_IE = 0x22 -}; - -enum gprs_gsup_message_type { - GPRS_GSUP_MSGT_UPDATE_LOCATION_REQUEST = 0b00000100, - GPRS_GSUP_MSGT_UPDATE_LOCATION_ERROR = 0b00000101, - GPRS_GSUP_MSGT_UPDATE_LOCATION_RESULT = 0b00000110, - - GPRS_GSUP_MSGT_SEND_AUTH_INFO_REQUEST = 0b00001000, - GPRS_GSUP_MSGT_SEND_AUTH_INFO_ERROR = 0b00001001, - GPRS_GSUP_MSGT_SEND_AUTH_INFO_RESULT = 0b00001010, - - GPRS_GSUP_MSGT_PURGE_MS_REQUEST = 0b00001100, - GPRS_GSUP_MSGT_PURGE_MS_ERROR = 0b00001101, - GPRS_GSUP_MSGT_PURGE_MS_RESULT = 0b00001110, - - GPRS_GSUP_MSGT_INSERT_DATA_REQUEST = 0b00010000, - GPRS_GSUP_MSGT_INSERT_DATA_ERROR = 0b00010001, - GPRS_GSUP_MSGT_INSERT_DATA_RESULT = 0b00010010, - - GPRS_GSUP_MSGT_DELETE_DATA_REQUEST = 0b00010100, - GPRS_GSUP_MSGT_DELETE_DATA_ERROR = 0b00010101, - GPRS_GSUP_MSGT_DELETE_DATA_RESULT = 0b00010110, - - GPRS_GSUP_MSGT_LOCATION_CANCEL_REQUEST = 0b00011100, - GPRS_GSUP_MSGT_LOCATION_CANCEL_ERROR = 0b00011101, - GPRS_GSUP_MSGT_LOCATION_CANCEL_RESULT = 0b00011110, -}; - -#define GPRS_GSUP_IS_MSGT_REQUEST(msgt) (((msgt) & 0b00000011) == 0b00) -#define GPRS_GSUP_IS_MSGT_ERROR(msgt) (((msgt) & 0b00000011) == 0b01) -#define GPRS_GSUP_TO_MSGT_ERROR(msgt) (((msgt) & 0b11111100) | 0b01) - -enum gprs_gsup_cancel_type { - GPRS_GSUP_CANCEL_TYPE_UPDATE = 1, /* on wire: 0 */ - GPRS_GSUP_CANCEL_TYPE_WITHDRAW = 2, /* on wire: 1 */ -}; - -struct gprs_gsup_pdp_info { - unsigned int context_id; - int have_info; - uint16_t pdp_type; - const uint8_t *apn_enc; - size_t apn_enc_len; - const uint8_t *qos_enc; - size_t qos_enc_len; -}; - -struct gprs_gsup_message { - enum gprs_gsup_message_type message_type; - char imsi[GSM23003_IMSI_MAX_DIGITS+2]; - enum gsm48_gmm_cause cause; - enum gprs_gsup_cancel_type cancel_type; - int pdp_info_compl; - int freeze_ptmsi; - struct osmo_auth_vector auth_vectors[GPRS_GSUP_MAX_NUM_AUTH_INFO]; - size_t num_auth_vectors; - struct gprs_gsup_pdp_info pdp_infos[GPRS_GSUP_MAX_NUM_PDP_INFO]; - size_t num_pdp_infos; - const uint8_t *msisdn_enc; - size_t msisdn_enc_len; - const uint8_t *hlr_enc; - size_t hlr_enc_len; -}; - -int gprs_gsup_decode(const uint8_t *data, size_t data_len, - struct gprs_gsup_message *gsup_msg); -void gprs_gsup_encode(struct msgb *msg, const struct gprs_gsup_message *gsup_msg); diff --git a/openbsc/include/openbsc/osmo_gsup_messages.h b/openbsc/include/openbsc/osmo_gsup_messages.h new file mode 100644 index 000000000..bdc46aaee --- /dev/null +++ b/openbsc/include/openbsc/osmo_gsup_messages.h @@ -0,0 +1,120 @@ +/* Osmocom Subscriber Update Protocol message encoder/decoder */ + +/* (C) 2014 by Sysmocom s.f.m.c. GmbH + * (C) 2016 by Harald Welte + * All Rights Reserved + * + * Author: Jacob Erlbeck + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include +#include +#include +#include +#include + +#define OSMO_GSUP_MAX_NUM_PDP_INFO 10 /* GSM 09.02 limits this to 50 */ +#define OSMO_GSUP_MAX_NUM_AUTH_INFO 5 +#define OSMO_GSUP_MAX_MSISDN_LEN 9 + +#define OSMO_GSUP_PDP_TYPE_SIZE 2 + +enum osmo_gsup_iei { + OSMO_GSUP_IMSI_IE = 0x01, + OSMO_GSUP_CAUSE_IE = 0x02, + OSMO_GSUP_AUTH_TUPLE_IE = 0x03, + OSMO_GSUP_PDP_INFO_COMPL_IE = 0x04, + OSMO_GSUP_PDP_INFO_IE = 0x05, + OSMO_GSUP_CANCEL_TYPE_IE = 0x06, + OSMO_GSUP_FREEZE_PTMSI_IE = 0x07, + OSMO_GSUP_MSISDN_IE = 0x08, + OSMO_GSUP_HLR_NUMBER_IE = 0x09, + OSMO_GSUP_PDP_CONTEXT_ID_IE = 0x10, + OSMO_GSUP_PDP_TYPE_IE = 0x11, + OSMO_GSUP_ACCESS_POINT_NAME_IE = 0x12, + OSMO_GSUP_PDP_QOS_IE = 0x13, + OSMO_GSUP_RAND_IE = 0x20, + OSMO_GSUP_SRES_IE = 0x21, + OSMO_GSUP_KC_IE = 0x22, +}; + +enum osmo_gsup_message_type { + OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST = 0b00000100, + OSMO_GSUP_MSGT_UPDATE_LOCATION_ERROR = 0b00000101, + OSMO_GSUP_MSGT_UPDATE_LOCATION_RESULT = 0b00000110, + + OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST = 0b00001000, + OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR = 0b00001001, + OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT = 0b00001010, + + OSMO_GSUP_MSGT_PURGE_MS_REQUEST = 0b00001100, + OSMO_GSUP_MSGT_PURGE_MS_ERROR = 0b00001101, + OSMO_GSUP_MSGT_PURGE_MS_RESULT = 0b00001110, + + OSMO_GSUP_MSGT_INSERT_DATA_REQUEST = 0b00010000, + OSMO_GSUP_MSGT_INSERT_DATA_ERROR = 0b00010001, + OSMO_GSUP_MSGT_INSERT_DATA_RESULT = 0b00010010, + + OSMO_GSUP_MSGT_DELETE_DATA_REQUEST = 0b00010100, + OSMO_GSUP_MSGT_DELETE_DATA_ERROR = 0b00010101, + OSMO_GSUP_MSGT_DELETE_DATA_RESULT = 0b00010110, + + OSMO_GSUP_MSGT_LOCATION_CANCEL_REQUEST = 0b00011100, + OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR = 0b00011101, + OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT = 0b00011110, +}; + +#define OSMO_GSUP_IS_MSGT_REQUEST(msgt) (((msgt) & 0b00000011) == 0b00) +#define OSMO_GSUP_IS_MSGT_ERROR(msgt) (((msgt) & 0b00000011) == 0b01) +#define OSMO_GSUP_TO_MSGT_ERROR(msgt) (((msgt) & 0b11111100) | 0b01) + +enum osmo_gsup_cancel_type { + OSMO_GSUP_CANCEL_TYPE_UPDATE = 1, /* on wire: 0 */ + OSMO_GSUP_CANCEL_TYPE_WITHDRAW = 2, /* on wire: 1 */ +}; + +struct osmo_gsup_pdp_info { + unsigned int context_id; + int have_info; + uint16_t pdp_type; + const uint8_t *apn_enc; + size_t apn_enc_len; + const uint8_t *qos_enc; + size_t qos_enc_len; +}; + +struct osmo_gsup_message { + enum osmo_gsup_message_type message_type; + char imsi[GSM23003_IMSI_MAX_DIGITS+2]; + enum gsm48_gmm_cause cause; + enum osmo_gsup_cancel_type cancel_type; + int pdp_info_compl; + int freeze_ptmsi; + struct osmo_auth_vector auth_vectors[OSMO_GSUP_MAX_NUM_AUTH_INFO]; + size_t num_auth_vectors; + struct osmo_gsup_pdp_info pdp_infos[OSMO_GSUP_MAX_NUM_PDP_INFO]; + size_t num_pdp_infos; + const uint8_t *msisdn_enc; + size_t msisdn_enc_len; + const uint8_t *hlr_enc; + size_t hlr_enc_len; +}; + +int osmo_gsup_decode(const uint8_t *data, size_t data_len, + struct osmo_gsup_message *gsup_msg); +void osmo_gsup_encode(struct msgb *msg, const struct osmo_gsup_message *gsup_msg); diff --git a/openbsc/src/gprs/Makefile.am b/openbsc/src/gprs/Makefile.am index 104bd296b..7889d5fd9 100644 --- a/openbsc/src/gprs/Makefile.am +++ b/openbsc/src/gprs/Makefile.am @@ -26,7 +26,7 @@ osmo_sgsn_SOURCES = gprs_gmm.c gprs_sgsn.c gprs_sndcp.c gprs_sndcp_vty.c \ sgsn_main.c sgsn_vty.c sgsn_libgtp.c \ gprs_llc.c gprs_llc_parse.c gprs_llc_vty.c crc24.c \ sgsn_ctrl.c sgsn_auth.c gprs_subscriber.c \ - gprs_gsup_messages.c gprs_utils.c gprs_gsup_client.c \ + osmo_gsup_messages.c gprs_utils.c gprs_gsup_client.c \ sgsn_cdr.c sgsn_ares.c \ oap.c oap_messages.c osmo_sgsn_LDADD = \ diff --git a/openbsc/src/gprs/gprs_subscriber.c b/openbsc/src/gprs/gprs_subscriber.c index 648f91204..d9bc10a18 100644 --- a/openbsc/src/gprs/gprs_subscriber.c +++ b/openbsc/src/gprs/gprs_subscriber.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -159,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)); @@ -180,21 +180,21 @@ 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; @@ -261,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; @@ -298,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; @@ -338,7 +338,7 @@ 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) { gprs_subscr_gsup_insert_data(subscr, gsup_msg); @@ -368,7 +368,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; @@ -421,7 +421,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; @@ -467,9 +467,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), @@ -482,7 +482,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"); @@ -494,7 +494,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", @@ -527,17 +527,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) @@ -554,16 +554,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", @@ -586,10 +586,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", @@ -600,21 +600,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); @@ -625,36 +625,36 @@ 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: + case OSMO_GSUP_MSGT_DELETE_DATA_REQUEST: LOGGSUBSCRP(LOGL_ERROR, subscr, "Rx GSUP message type %d not yet implemented\n", gsup_msg.message_type); @@ -667,7 +667,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; @@ -682,11 +682,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; @@ -697,23 +697,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); } diff --git a/openbsc/src/gprs/gprs_gsup_messages.c b/openbsc/src/gprs/osmo_gsup_messages.c similarity index 74% rename from openbsc/src/gprs/gprs_gsup_messages.c rename to openbsc/src/gprs/osmo_gsup_messages.c index b3c8dab5f..00ada5b24 100644 --- a/openbsc/src/gprs/gprs_gsup_messages.c +++ b/openbsc/src/gprs/osmo_gsup_messages.c @@ -1,4 +1,4 @@ -/* GPRS Subscriber Update Protocol message encoder/decoder */ +/* Osmocom Subscriber Update Protocol message encoder/decoder */ /* * (C) 2014 by Sysmocom s.f.m.c. GmbH @@ -23,10 +23,10 @@ * */ -#include +#include #include -#include +//#include #include #include @@ -36,7 +36,7 @@ #include static int decode_pdp_info(uint8_t *data, size_t data_len, - struct gprs_gsup_pdp_info *pdp_info) + struct osmo_gsup_pdp_info *pdp_info) { int rc; uint8_t tag; @@ -45,7 +45,7 @@ static int decode_pdp_info(uint8_t *data, size_t data_len, /* specific parts */ while (data_len > 0) { - enum gprs_gsup_iei iei; + enum osmo_gsup_iei iei; rc = gprs_shift_tlv(&data, &data_len, &tag, &value, &value_len); if (rc < 0) @@ -54,21 +54,21 @@ static int decode_pdp_info(uint8_t *data, size_t data_len, iei = tag; switch (iei) { - case GPRS_GSUP_PDP_CONTEXT_ID_IE: + case OSMO_GSUP_PDP_CONTEXT_ID_IE: pdp_info->context_id = decode_big_endian(value, value_len); break; - case GPRS_GSUP_PDP_TYPE_IE: + case OSMO_GSUP_PDP_TYPE_IE: pdp_info->pdp_type = decode_big_endian(value, value_len) & 0x0fff; break; - case GPRS_GSUP_ACCESS_POINT_NAME_IE: + case OSMO_GSUP_ACCESS_POINT_NAME_IE: pdp_info->apn_enc = value; pdp_info->apn_enc_len = value_len; break; - case GPRS_GSUP_PDP_QOS_IE: + case OSMO_GSUP_PDP_QOS_IE: pdp_info->qos_enc = value; pdp_info->qos_enc_len = value_len; break; @@ -90,7 +90,7 @@ static int decode_auth_info(uint8_t *data, size_t data_len, uint8_t tag; uint8_t *value; size_t value_len; - enum gprs_gsup_iei iei; + enum osmo_gsup_iei iei; /* specific parts */ while (data_len > 0) { @@ -101,21 +101,21 @@ static int decode_auth_info(uint8_t *data, size_t data_len, iei = tag; switch (iei) { - case GPRS_GSUP_RAND_IE: + case OSMO_GSUP_RAND_IE: if (value_len != sizeof(auth_vector->rand)) goto parse_error; memcpy(auth_vector->rand, value, value_len); break; - case GPRS_GSUP_SRES_IE: + case OSMO_GSUP_SRES_IE: if (value_len != sizeof(auth_vector->sres)) goto parse_error; memcpy(auth_vector->sres, value, value_len); break; - case GPRS_GSUP_KC_IE: + case OSMO_GSUP_KC_IE: if (value_len != sizeof(auth_vector->kc)) goto parse_error; @@ -138,8 +138,8 @@ parse_error: return -1; } -int gprs_gsup_decode(const uint8_t *const_data, size_t data_len, - struct gprs_gsup_message *gsup_msg) +int osmo_gsup_decode(const uint8_t *const_data, size_t data_len, + struct osmo_gsup_message *gsup_msg) { int rc; uint8_t tag; @@ -150,9 +150,9 @@ int gprs_gsup_decode(const uint8_t *const_data, size_t data_len, uint8_t *data = (uint8_t *)const_data; uint8_t *value; size_t value_len; - static const struct gprs_gsup_pdp_info empty_pdp_info = {0}; + static const struct osmo_gsup_pdp_info empty_pdp_info = {0}; static const struct osmo_auth_vector empty_auth_info = {0}; - static const struct gprs_gsup_message empty_gsup_message = {0}; + static const struct osmo_gsup_message empty_gsup_message = {0}; *gsup_msg = empty_gsup_message; @@ -163,7 +163,7 @@ int gprs_gsup_decode(const uint8_t *const_data, size_t data_len, gsup_msg->message_type = decode_big_endian(value, 1); - rc = gprs_match_tlv(&data, &data_len, GPRS_GSUP_IMSI_IE, + rc = gprs_match_tlv(&data, &data_len, OSMO_GSUP_IMSI_IE, &value, &value_len); if (rc <= 0) @@ -183,8 +183,8 @@ int gprs_gsup_decode(const uint8_t *const_data, size_t data_len, /* specific parts */ while (data_len > 0) { - enum gprs_gsup_iei iei; - struct gprs_gsup_pdp_info pdp_info; + enum osmo_gsup_iei iei; + struct osmo_gsup_pdp_info pdp_info; struct osmo_auth_vector auth_info; rc = gprs_shift_tlv(&data, &data_len, &tag, &value, &value_len); @@ -194,34 +194,34 @@ int gprs_gsup_decode(const uint8_t *const_data, size_t data_len, iei = tag; switch (iei) { - case GPRS_GSUP_IMSI_IE: - case GPRS_GSUP_PDP_TYPE_IE: - case GPRS_GSUP_ACCESS_POINT_NAME_IE: - case GPRS_GSUP_RAND_IE: - case GPRS_GSUP_SRES_IE: - case GPRS_GSUP_KC_IE: + case OSMO_GSUP_IMSI_IE: + case OSMO_GSUP_PDP_TYPE_IE: + case OSMO_GSUP_ACCESS_POINT_NAME_IE: + case OSMO_GSUP_RAND_IE: + case OSMO_GSUP_SRES_IE: + case OSMO_GSUP_KC_IE: LOGP(DGPRS, LOGL_NOTICE, "GSUP IE type %d not expected (ignored)\n", iei); continue; - case GPRS_GSUP_CAUSE_IE: + case OSMO_GSUP_CAUSE_IE: gsup_msg->cause = decode_big_endian(value, value_len); break; - case GPRS_GSUP_CANCEL_TYPE_IE: + case OSMO_GSUP_CANCEL_TYPE_IE: gsup_msg->cancel_type = decode_big_endian(value, value_len) + 1; break; - case GPRS_GSUP_PDP_INFO_COMPL_IE: + case OSMO_GSUP_PDP_INFO_COMPL_IE: gsup_msg->pdp_info_compl = 1; break; - case GPRS_GSUP_FREEZE_PTMSI_IE: + case OSMO_GSUP_FREEZE_PTMSI_IE: gsup_msg->freeze_ptmsi = 1; break; - case GPRS_GSUP_PDP_CONTEXT_ID_IE: + case OSMO_GSUP_PDP_CONTEXT_ID_IE: /* When these IE appear in the top-level part of the * message, they are used by Delete Subscr Info to delete * single entries. We don't have an extra list for @@ -229,8 +229,8 @@ int gprs_gsup_decode(const uint8_t *const_data, size_t data_len, /* fall through */ - case GPRS_GSUP_PDP_INFO_IE: - if (gsup_msg->num_pdp_infos >= GPRS_GSUP_MAX_NUM_PDP_INFO) { + case OSMO_GSUP_PDP_INFO_IE: + if (gsup_msg->num_pdp_infos >= OSMO_GSUP_MAX_NUM_PDP_INFO) { LOGP(DGPRS, LOGL_ERROR, "GSUP IE type %d (PDP_INFO) max exceeded\n", iei); @@ -239,7 +239,7 @@ int gprs_gsup_decode(const uint8_t *const_data, size_t data_len, pdp_info = empty_pdp_info; - if (iei == GPRS_GSUP_PDP_INFO_IE) { + if (iei == OSMO_GSUP_PDP_INFO_IE) { rc = decode_pdp_info(value, value_len, &pdp_info); if (rc < 0) return rc; @@ -253,8 +253,8 @@ int gprs_gsup_decode(const uint8_t *const_data, size_t data_len, pdp_info; break; - case GPRS_GSUP_AUTH_TUPLE_IE: - if (gsup_msg->num_auth_vectors >= GPRS_GSUP_MAX_NUM_AUTH_INFO) { + case OSMO_GSUP_AUTH_TUPLE_IE: + if (gsup_msg->num_auth_vectors >= OSMO_GSUP_MAX_NUM_AUTH_INFO) { LOGP(DGPRS, LOGL_ERROR, "GSUP IE type %d (AUTH_INFO) max exceeded\n", iei); @@ -271,12 +271,12 @@ int gprs_gsup_decode(const uint8_t *const_data, size_t data_len, auth_info; break; - case GPRS_GSUP_MSISDN_IE: + case OSMO_GSUP_MSISDN_IE: gsup_msg->msisdn_enc = value; gsup_msg->msisdn_enc_len = value_len; break; - case GPRS_GSUP_HLR_NUMBER_IE: + case OSMO_GSUP_HLR_NUMBER_IE: gsup_msg->hlr_enc = value; gsup_msg->hlr_enc_len = value_len; break; @@ -291,8 +291,8 @@ int gprs_gsup_decode(const uint8_t *const_data, size_t data_len, return 0; } -static void encode_pdp_info(struct msgb *msg, enum gprs_gsup_iei iei, - const struct gprs_gsup_pdp_info *pdp_info) +static void encode_pdp_info(struct msgb *msg, enum osmo_gsup_iei iei, + const struct osmo_gsup_pdp_info *pdp_info) { uint8_t *len_field; size_t old_len; @@ -302,22 +302,22 @@ static void encode_pdp_info(struct msgb *msg, enum gprs_gsup_iei iei, old_len = msgb_length(msg); u8 = pdp_info->context_id; - msgb_tlv_put(msg, GPRS_GSUP_PDP_CONTEXT_ID_IE, sizeof(u8), &u8); + msgb_tlv_put(msg, OSMO_GSUP_PDP_CONTEXT_ID_IE, sizeof(u8), &u8); if (pdp_info->pdp_type) { - msgb_tlv_put(msg, GPRS_GSUP_PDP_TYPE_IE, - GPRS_GSUP_PDP_TYPE_SIZE, + msgb_tlv_put(msg, OSMO_GSUP_PDP_TYPE_IE, + OSMO_GSUP_PDP_TYPE_SIZE, encode_big_endian(pdp_info->pdp_type | 0xf000, - GPRS_GSUP_PDP_TYPE_SIZE)); + OSMO_GSUP_PDP_TYPE_SIZE)); } if (pdp_info->apn_enc) { - msgb_tlv_put(msg, GPRS_GSUP_ACCESS_POINT_NAME_IE, + msgb_tlv_put(msg, OSMO_GSUP_ACCESS_POINT_NAME_IE, pdp_info->apn_enc_len, pdp_info->apn_enc); } if (pdp_info->qos_enc) { - msgb_tlv_put(msg, GPRS_GSUP_PDP_QOS_IE, + msgb_tlv_put(msg, OSMO_GSUP_PDP_QOS_IE, pdp_info->qos_enc_len, pdp_info->qos_enc); } @@ -325,7 +325,7 @@ static void encode_pdp_info(struct msgb *msg, enum gprs_gsup_iei iei, *len_field = msgb_length(msg) - old_len; } -static void encode_auth_info(struct msgb *msg, enum gprs_gsup_iei iei, +static void encode_auth_info(struct msgb *msg, enum osmo_gsup_iei iei, const struct osmo_auth_vector *auth_vector) { uint8_t *len_field; @@ -334,20 +334,20 @@ static void encode_auth_info(struct msgb *msg, enum gprs_gsup_iei iei, len_field = msgb_tlv_put(msg, iei, 0, NULL) - 1; old_len = msgb_length(msg); - msgb_tlv_put(msg, GPRS_GSUP_RAND_IE, + msgb_tlv_put(msg, OSMO_GSUP_RAND_IE, sizeof(auth_vector->rand), auth_vector->rand); - msgb_tlv_put(msg, GPRS_GSUP_SRES_IE, + msgb_tlv_put(msg, OSMO_GSUP_SRES_IE, sizeof(auth_vector->sres), auth_vector->sres); - msgb_tlv_put(msg, GPRS_GSUP_KC_IE, + msgb_tlv_put(msg, OSMO_GSUP_KC_IE, sizeof(auth_vector->kc), auth_vector->kc); /* Update length field */ *len_field = msgb_length(msg) - old_len; } -void gprs_gsup_encode(struct msgb *msg, const struct gprs_gsup_message *gsup_msg) +void osmo_gsup_encode(struct msgb *msg, const struct osmo_gsup_message *gsup_msg) { uint8_t u8; int idx; @@ -366,32 +366,32 @@ void gprs_gsup_encode(struct msgb *msg, const struct gprs_gsup_message *gsup_msg /* Note that gsm48_encode_bcd_number puts the length into the first * octet. Since msgb_tlv_put will add this length byte, we'll have to * skip it */ - msgb_tlv_put(msg, GPRS_GSUP_IMSI_IE, bcd_len - 1, &bcd_buf[1]); + msgb_tlv_put(msg, OSMO_GSUP_IMSI_IE, bcd_len - 1, &bcd_buf[1]); /* specific parts */ if (gsup_msg->msisdn_enc) - msgb_tlv_put(msg, GPRS_GSUP_MSISDN_IE, + msgb_tlv_put(msg, OSMO_GSUP_MSISDN_IE, gsup_msg->msisdn_enc_len, gsup_msg->msisdn_enc); if (gsup_msg->hlr_enc) - msgb_tlv_put(msg, GPRS_GSUP_HLR_NUMBER_IE, + msgb_tlv_put(msg, OSMO_GSUP_HLR_NUMBER_IE, gsup_msg->hlr_enc_len, gsup_msg->hlr_enc); if ((u8 = gsup_msg->cause)) - msgb_tlv_put(msg, GPRS_GSUP_CAUSE_IE, sizeof(u8), &u8); + msgb_tlv_put(msg, OSMO_GSUP_CAUSE_IE, sizeof(u8), &u8); if ((u8 = gsup_msg->cancel_type)) { u8 -= 1; - msgb_tlv_put(msg, GPRS_GSUP_CANCEL_TYPE_IE, sizeof(u8), &u8); + msgb_tlv_put(msg, OSMO_GSUP_CANCEL_TYPE_IE, sizeof(u8), &u8); } if (gsup_msg->pdp_info_compl) - msgb_tlv_put(msg, GPRS_GSUP_PDP_INFO_COMPL_IE, 0, &u8); + msgb_tlv_put(msg, OSMO_GSUP_PDP_INFO_COMPL_IE, 0, &u8); if (gsup_msg->freeze_ptmsi) - msgb_tlv_put(msg, GPRS_GSUP_FREEZE_PTMSI_IE, 0, &u8); + msgb_tlv_put(msg, OSMO_GSUP_FREEZE_PTMSI_IE, 0, &u8); for (idx = 0; idx < gsup_msg->num_pdp_infos; idx++) { - const struct gprs_gsup_pdp_info *pdp_info; + const struct osmo_gsup_pdp_info *pdp_info; pdp_info = &gsup_msg->pdp_infos[idx]; @@ -399,10 +399,10 @@ void gprs_gsup_encode(struct msgb *msg, const struct gprs_gsup_message *gsup_msg continue; if (pdp_info->have_info) { - encode_pdp_info(msg, GPRS_GSUP_PDP_INFO_IE, pdp_info); + encode_pdp_info(msg, OSMO_GSUP_PDP_INFO_IE, pdp_info); } else { u8 = pdp_info->context_id; - msgb_tlv_put(msg, GPRS_GSUP_PDP_CONTEXT_ID_IE, + msgb_tlv_put(msg, OSMO_GSUP_PDP_CONTEXT_ID_IE, sizeof(u8), &u8); } } @@ -412,6 +412,6 @@ void gprs_gsup_encode(struct msgb *msg, const struct gprs_gsup_message *gsup_msg auth_vector = &gsup_msg->auth_vectors[idx]; - encode_auth_info(msg, GPRS_GSUP_AUTH_TUPLE_IE, auth_vector); + encode_auth_info(msg, OSMO_GSUP_AUTH_TUPLE_IE, auth_vector); } }