Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1 | /* pcu_main.cpp |
| 2 | * |
| 3 | * Copyright (C) 2012 Ivan Klyuchnikov |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | |
| 20 | #include <gprs_bssgp_pcu.h> |
Ivan Kluchnikov | a9f1ff2 | 2012-05-24 22:25:06 +0400 | [diff] [blame] | 21 | #include <arpa/inet.h> |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 22 | #include <pcu_l1_if.h> |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 23 | #include <gprs_rlcmac.h> |
Ivan Kluchnikov | 61a33f7 | 2012-04-12 15:22:06 +0400 | [diff] [blame] | 24 | #include <gsm_timer.h> |
Ivan Kluchnikov | a9f1ff2 | 2012-05-24 22:25:06 +0400 | [diff] [blame] | 25 | #include <gprs_debug.h> |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 26 | #include <unistd.h> |
| 27 | #include <getopt.h> |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 28 | |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 29 | struct gprs_rlcmac_bts *gprs_rlcmac_bts; |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 30 | extern struct gprs_nsvc *nsvc; |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 31 | uint16_t spoof_mcc = 0, spoof_mnc = 0; |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 32 | |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 33 | static void print_help() |
| 34 | { |
| 35 | printf( "Some useful options:\n" |
| 36 | " -h --help this text\n" |
| 37 | " -m --mcc MCC use given MCC instead of value " |
| 38 | "provided by BTS\n" |
| 39 | " -n --mnc MNC use given MNC instead of value " |
| 40 | "provided by BTS\n" |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | /* FIXME: finally get some option parsing code into libosmocore */ |
| 45 | static void handle_options(int argc, char **argv) |
| 46 | { |
| 47 | while (1) { |
| 48 | int option_idx = 0, c; |
| 49 | static const struct option long_options[] = { |
| 50 | { "help", 0, 0, 'h' }, |
Andreas Eversberg | 1944bd5 | 2012-07-06 09:32:39 +0200 | [diff] [blame] | 51 | { "mcc", 1, 0, 'm' }, |
| 52 | { "mnc", 1, 0, 'n' }, |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 53 | { 0, 0, 0, 0 } |
| 54 | }; |
| 55 | |
| 56 | c = getopt_long(argc, argv, "hm:n:", |
| 57 | long_options, &option_idx); |
| 58 | if (c == -1) |
| 59 | break; |
| 60 | |
| 61 | switch (c) { |
| 62 | case 'h': |
| 63 | print_help(); |
| 64 | exit(0); |
| 65 | break; |
| 66 | case 'm': |
| 67 | spoof_mcc = atoi(optarg); |
| 68 | break; |
| 69 | case 'n': |
| 70 | spoof_mnc = atoi(optarg); |
| 71 | break; |
| 72 | default: |
| 73 | fprintf(stderr, "Unknown option '%c'\n", c); |
| 74 | exit(0); |
| 75 | break; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 80 | int main(int argc, char *argv[]) |
| 81 | { |
Andreas Eversberg | dfa563c | 2012-07-06 08:13:59 +0200 | [diff] [blame] | 82 | struct gprs_rlcmac_bts *bts; |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 83 | int rc; |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 84 | |
Andreas Eversberg | dfa563c | 2012-07-06 08:13:59 +0200 | [diff] [blame] | 85 | bts = gprs_rlcmac_bts = talloc_zero(NULL, struct gprs_rlcmac_bts); |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 86 | if (!gprs_rlcmac_bts) |
| 87 | return -ENOMEM; |
Andreas Eversberg | b3c6f6c | 2012-07-06 07:40:08 +0200 | [diff] [blame] | 88 | gprs_rlcmac_bts->initial_cs = 1; |
Andreas Eversberg | dfa563c | 2012-07-06 08:13:59 +0200 | [diff] [blame] | 89 | bts->initial_cs = 1; |
| 90 | bts->cs1 = 1; |
| 91 | bts->t3142 = 20; |
| 92 | bts->t3169 = 5; |
| 93 | bts->t3191 = 5; |
| 94 | bts->t3193_msec = 100; |
| 95 | bts->t3195 = 5; |
| 96 | bts->n3101 = 10; |
| 97 | bts->n3103 = 4; |
| 98 | bts->n3105 = 8; |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 99 | |
Ivan Kluchnikov | a9f1ff2 | 2012-05-24 22:25:06 +0400 | [diff] [blame] | 100 | osmo_init_logging(&gprs_log_info); |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 101 | |
| 102 | handle_options(argc, argv); |
| 103 | if ((!!spoof_mcc) + (!!spoof_mnc) == 1) { |
| 104 | fprintf(stderr, "--mcc and --mnc must be specified " |
| 105 | "together.\n"); |
| 106 | exit(0); |
| 107 | } |
| 108 | |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 109 | rc = pcu_l1if_open(); |
| 110 | if (rc < 0) |
| 111 | return rc; |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 112 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 113 | while (1) |
| 114 | { |
Ivan Kluchnikov | 61a33f7 | 2012-04-12 15:22:06 +0400 | [diff] [blame] | 115 | osmo_gsm_timers_check(); |
| 116 | osmo_gsm_timers_prepare(); |
| 117 | osmo_gsm_timers_update(); |
| 118 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 119 | osmo_select_main(0); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 120 | } |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 121 | |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 122 | pcu_l1if_close(); |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 123 | talloc_free(gprs_rlcmac_bts); |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 124 | |
| 125 | return 0; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 126 | } |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 127 | |