From d3fa84dbba3b67cdbe2d8c789b2833b5ddf42068 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 20 Apr 2016 17:50:17 +0200 Subject: use new libosmocore gsm_23_003.h for IMEI/IMSI length ... rather than our private definitions everwhere. As an added benefit, gprs_gsup_messages.h is now free of any header dependencies within openbsc. --- openbsc/include/openbsc/gprs_gsup_messages.h | 7 ++++--- openbsc/include/openbsc/gprs_sgsn.h | 7 +++---- openbsc/include/openbsc/gsm_subscriber.h | 7 +++---- openbsc/include/openbsc/ipaccess.h | 3 ++- openbsc/src/gprs/gprs_gsup_messages.c | 1 + openbsc/src/gprs/gprs_subscriber.c | 5 +++-- openbsc/src/gprs/gtphub_ares.c | 2 +- openbsc/src/libcommon/gsm_subscriber_base.c | 2 +- openbsc/src/libmsc/ctrl_commands.c | 2 +- openbsc/src/libmsc/db.c | 7 ++++--- openbsc/src/osmo-bsc_nat/bsc_ussd.c | 2 +- openbsc/tests/gtphub/gtphub_test.c | 2 +- 12 files changed, 25 insertions(+), 22 deletions(-) diff --git a/openbsc/include/openbsc/gprs_gsup_messages.h b/openbsc/include/openbsc/gprs_gsup_messages.h index c4e97570c..fe8bef555 100644 --- a/openbsc/include/openbsc/gprs_gsup_messages.h +++ b/openbsc/include/openbsc/gprs_gsup_messages.h @@ -22,9 +22,10 @@ #pragma once #include +#include +#include #include -/* Needed for GSM_IMSI_LENGTH: */ -#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 @@ -98,7 +99,7 @@ struct gprs_gsup_pdp_info { struct gprs_gsup_message { enum gprs_gsup_message_type message_type; - char imsi[GSM_IMSI_LENGTH]; + char imsi[GSM23003_IMSI_MAX_DIGITS+2]; enum gsm48_gmm_cause cause; enum gprs_gsup_cancel_type cancel_type; int pdp_info_compl; diff --git a/openbsc/include/openbsc/gprs_sgsn.h b/openbsc/include/openbsc/gprs_sgsn.h index 49d5407f5..898b7a514 100644 --- a/openbsc/include/openbsc/gprs_sgsn.h +++ b/openbsc/include/openbsc/gprs_sgsn.h @@ -9,11 +9,10 @@ #include #include +#include #include -#define GSM_IMSI_LENGTH 17 -#define GSM_IMEI_LENGTH 17 #define GSM_EXTENSION_LENGTH 15 #define GSM_APN_LENGTH 102 @@ -98,12 +97,12 @@ struct sgsn_ggsn_lookup { struct sgsn_mm_ctx { struct llist_head list; - char imsi[GSM_IMSI_LENGTH]; + char imsi[GSM23003_IMSI_MAX_DIGITS+1]; enum gprs_mm_state mm_state; uint32_t p_tmsi; uint32_t p_tmsi_old; /* old P-TMSI before new is confirmed */ uint32_t p_tmsi_sig; - char imei[GSM_IMEI_LENGTH]; + char imei[GSM23003_IMEISV_NUM_DIGITS+1]; /* Opt: Software Version Numbber / TS 23.195 */ char msisdn[GSM_EXTENSION_LENGTH]; struct gprs_ra_id ra; diff --git a/openbsc/include/openbsc/gsm_subscriber.h b/openbsc/include/openbsc/gsm_subscriber.h index 7d6c776bc..9df989a79 100644 --- a/openbsc/include/openbsc/gsm_subscriber.h +++ b/openbsc/include/openbsc/gsm_subscriber.h @@ -3,9 +3,8 @@ #include "gsm_data.h" #include +#include -#define GSM_IMEI_LENGTH 17 -#define GSM_IMSI_LENGTH 17 #define GSM_NAME_LENGTH 160 #define GSM_EXTENSION_LENGTH 15 /* MSISDN can only be 15 digits length */ @@ -32,7 +31,7 @@ struct gsm_subscriber_group { struct gsm_equipment { long long unsigned int id; - char imei[GSM_IMEI_LENGTH]; + char imei[GSM23003_IMEISV_NUM_DIGITS+1]; char name[GSM_NAME_LENGTH]; struct gsm48_classmark1 classmark1; @@ -45,7 +44,7 @@ struct gsm_equipment { struct gsm_subscriber { struct gsm_subscriber_group *group; long long unsigned int id; - char imsi[GSM_IMSI_LENGTH]; + char imsi[GSM23003_IMSI_MAX_DIGITS+1]; uint32_t tmsi; uint16_t lac; char name[GSM_NAME_LENGTH]; diff --git a/openbsc/include/openbsc/ipaccess.h b/openbsc/include/openbsc/ipaccess.h index 38151c477..82e89c27d 100644 --- a/openbsc/include/openbsc/ipaccess.h +++ b/openbsc/include/openbsc/ipaccess.h @@ -5,13 +5,14 @@ #include "gsm_subscriber.h" #include #include +#include struct ipac_msgt_sccp_state { uint8_t src_ref[3]; uint8_t dst_ref[3]; uint8_t trans_id; uint8_t invoke_id; - char imsi[GSM_IMSI_LENGTH]; + char imsi[GSM23003_IMSI_MAX_DIGITS+1]; uint8_t data[0]; } __attribute__((packed)); diff --git a/openbsc/src/gprs/gprs_gsup_messages.c b/openbsc/src/gprs/gprs_gsup_messages.c index 0b1dc9b00..b3c8dab5f 100644 --- a/openbsc/src/gprs/gprs_gsup_messages.c +++ b/openbsc/src/gprs/gprs_gsup_messages.c @@ -31,6 +31,7 @@ #include #include +#include #include diff --git a/openbsc/src/gprs/gprs_subscriber.c b/openbsc/src/gprs/gprs_subscriber.c index 5b0bf398c..648f91204 100644 --- a/openbsc/src/gprs/gprs_subscriber.c +++ b/openbsc/src/gprs/gprs_subscriber.c @@ -757,8 +757,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) diff --git a/openbsc/src/gprs/gtphub_ares.c b/openbsc/src/gprs/gtphub_ares.c index 947f2ddd5..667013b8b 100644 --- a/openbsc/src/gprs/gtphub_ares.c +++ b/openbsc/src/gprs/gtphub_ares.c @@ -55,7 +55,7 @@ struct ggsn_lookup { struct gtphub *hub; - char imsi_str[GSM_IMSI_LENGTH]; + char imsi_str[GSM23003_IMSI_MAX_DIGITS+1]; char apn_ni_str[GSM_APN_LENGTH]; char apn_oi_str[GSM_APN_LENGTH]; int have_3dig_mnc; diff --git a/openbsc/src/libcommon/gsm_subscriber_base.c b/openbsc/src/libcommon/gsm_subscriber_base.c index a455824a3..50f411888 100644 --- a/openbsc/src/libcommon/gsm_subscriber_base.c +++ b/openbsc/src/libcommon/gsm_subscriber_base.c @@ -112,7 +112,7 @@ struct gsm_subscriber *subscr_get_or_create(struct gsm_subscriber_group *sgrp, if (!subscr) return NULL; - strncpy(subscr->imsi, imsi, GSM_IMSI_LENGTH-1); + strncpy(subscr->imsi, imsi, sizeof(subscr->imsi)-1); subscr->group = sgrp; return subscr; } diff --git a/openbsc/src/libmsc/ctrl_commands.c b/openbsc/src/libmsc/ctrl_commands.c index 9ac39de95..0d6a37c96 100644 --- a/openbsc/src/libmsc/ctrl_commands.c +++ b/openbsc/src/libmsc/ctrl_commands.c @@ -56,7 +56,7 @@ static int verify_subscriber_modify(struct ctrl_cmd *cmd, const char *value, voi if (!imsi || !msisdn) rc = 1; - else if (strlen(imsi) >= GSM_IMSI_LENGTH) + else if (strlen(imsi) > GSM23003_IMSI_MAX_DIGITS) rc = 1; else if (strlen(msisdn) >= GSM_EXTENSION_LENGTH) rc = 1; diff --git a/openbsc/src/libmsc/db.c b/openbsc/src/libmsc/db.c index a23ec89ae..e5017ae7b 100644 --- a/openbsc/src/libmsc/db.c +++ b/openbsc/src/libmsc/db.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -529,7 +530,7 @@ struct gsm_subscriber *db_create_subscriber(const char *imsi) return NULL; } subscr->id = dbi_conn_sequence_last(conn, NULL); - strncpy(subscr->imsi, imsi, GSM_IMSI_LENGTH-1); + strncpy(subscr->imsi, imsi, sizeof(subscr->imsi)-1); dbi_result_free(result); LOGP(DDB, LOGL_INFO, "New Subscriber: ID %llu, IMSI %s\n", subscr->id, subscr->imsi); db_subscriber_alloc_exten(subscr); @@ -803,7 +804,7 @@ static void db_set_from_query(struct gsm_subscriber *subscr, dbi_conn result) const char *string; string = dbi_result_get_string(result, "imsi"); if (string) - strncpy(subscr->imsi, string, GSM_IMSI_LENGTH-1); + strncpy(subscr->imsi, string, sizeof(subscr->imsi)-1); string = dbi_result_get_string(result, "tmsi"); if (string) @@ -1317,7 +1318,7 @@ int db_subscriber_alloc_token(struct gsm_subscriber *subscriber, uint32_t *token return 0; } -int db_subscriber_assoc_imei(struct gsm_subscriber *subscriber, char imei[GSM_IMEI_LENGTH]) +int db_subscriber_assoc_imei(struct gsm_subscriber *subscriber, char imei[GSM23003_IMEISV_NUM_DIGITS]) { unsigned long long equipment_id, watch_id; dbi_result result; diff --git a/openbsc/src/osmo-bsc_nat/bsc_ussd.c b/openbsc/src/osmo-bsc_nat/bsc_ussd.c index e0809059a..2f68381ac 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_ussd.c +++ b/openbsc/src/osmo-bsc_nat/bsc_ussd.c @@ -400,7 +400,7 @@ int bsc_ussd_check(struct nat_sccp_connection *con, struct bsc_nat_parsed *parse if (parsed->bssap != BSSAP_MSG_DTAP) return 0; - if (strlen(con->filter_state.imsi) >= GSM_IMSI_LENGTH) + if (strlen(con->filter_state.imsi) > GSM23003_IMSI_MAX_DIGITS) return 0; hdr48 = bsc_unpack_dtap(parsed, msg, &len); diff --git a/openbsc/tests/gtphub/gtphub_test.c b/openbsc/tests/gtphub/gtphub_test.c index 8ce83c82e..e24967b85 100644 --- a/openbsc/tests/gtphub/gtphub_test.c +++ b/openbsc/tests/gtphub/gtphub_test.c @@ -388,7 +388,7 @@ static void test_expiry(void) #undef MAP3 } -char resolve_ggsn_got_imsi[GSM_IMSI_LENGTH]; +char resolve_ggsn_got_imsi[GSM23003_IMSI_MAX_DIGITS+1]; char resolve_ggsn_got_ni[GSM_APN_LENGTH]; struct osmo_sockaddr resolved_ggsn_addr; -- cgit v1.2.3