From 81e895b6193530ea4b180c2118b9f40bb33de5b7 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Fri, 6 Jul 2012 08:24:53 +0200 Subject: Adding MCC/MNC spoof options to pcu_main.cpp The option added is required to change PLMN that is announced to SGSN. This allows BTS to have a different PLMN. (Usefull for roaming in conjunction with simlock.) --- src/pcu_main.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/src/pcu_main.cpp b/src/pcu_main.cpp index 8f64e315..8ef5acc4 100644 --- a/src/pcu_main.cpp +++ b/src/pcu_main.cpp @@ -23,14 +23,64 @@ #include #include #include +#include +#include struct gprs_rlcmac_bts *gprs_rlcmac_bts; +uint16_t spoof_mcc = 0, spoof_mnc = 0; // TODO: We should move this parameters to config file. #define SGSN_IP "127.0.0.1" #define SGSN_PORT 23000 #define NSVCI 4 +static void print_help() +{ + printf( "Some useful options:\n" + " -h --help this text\n" + " -m --mcc MCC use given MCC instead of value " + "provided by BTS\n" + " -n --mnc MNC use given MNC instead of value " + "provided by BTS\n" + ); +} + +/* FIXME: finally get some option parsing code into libosmocore */ +static void handle_options(int argc, char **argv) +{ + while (1) { + int option_idx = 0, c; + static const struct option long_options[] = { + { "help", 0, 0, 'h' }, + { "mcc", 0, 0, 'm' }, + { "mnc", 0, 0, 'n' }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "hm:n:", + long_options, &option_idx); + if (c == -1) + break; + + switch (c) { + case 'h': + print_help(); + exit(0); + break; + case 'm': + spoof_mcc = atoi(optarg); + break; + case 'n': + spoof_mnc = atoi(optarg); + break; + default: + fprintf(stderr, "Unknown option '%c'\n", c); + exit(0); + break; + } + } +} + int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, struct msgb *msg, uint16_t bvci) { int rc = 0; @@ -72,6 +122,14 @@ int main(int argc, char *argv[]) bts->n3105 = 8; osmo_init_logging(&gprs_log_info); + + handle_options(argc, argv); + if ((!!spoof_mcc) + (!!spoof_mnc) == 1) { + fprintf(stderr, "--mcc and --mnc must be specified " + "together.\n"); + exit(0); + } + pcu_l1if_open(); sgsn_nsi = gprs_ns_instantiate(&sgsn_ns_cb, NULL); @@ -85,8 +143,8 @@ int main(int argc, char *argv[]) bctx = btsctx_alloc(BVCI, NSEI); bctx->cell_id = CELL_ID; bctx->nsei = NSEI; - bctx->ra_id.mnc = MNC; - bctx->ra_id.mcc = MCC; + bctx->ra_id.mnc = spoof_mcc ? : MNC; + bctx->ra_id.mcc = spoof_mnc ? : MCC; bctx->ra_id.lac = PCU_LAC; bctx->ra_id.rac = PCU_RAC; bctx->bvci = BVCI; -- cgit v1.2.3