blob: 2a5f2c7ddfa8ce09507aa7fc181b608d82cd4fc1 [file] [log] [blame]
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001/* 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 Kluchnikova9f1ff22012-05-24 22:25:06 +040021#include <arpa/inet.h>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040022#include <pcu_l1_if.h>
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020023#include <gprs_rlcmac.h>
Ivan Kluchnikov61a33f72012-04-12 15:22:06 +040024#include <gsm_timer.h>
Ivan Kluchnikova9f1ff22012-05-24 22:25:06 +040025#include <gprs_debug.h>
Andreas Eversberg81e895b2012-07-06 08:24:53 +020026#include <unistd.h>
27#include <getopt.h>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040028
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020029struct gprs_rlcmac_bts *gprs_rlcmac_bts;
Andreas Eversberg3e372d52012-07-06 09:28:15 +020030extern struct gprs_nsvc *nsvc;
Andreas Eversberg81e895b2012-07-06 08:24:53 +020031uint16_t spoof_mcc = 0, spoof_mnc = 0;
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020032
Andreas Eversberg81e895b2012-07-06 08:24:53 +020033static 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 */
45static 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' },
51 { "mcc", 0, 0, 'm' },
52 { "mnc", 0, 0, 'n' },
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 Kluchnikov8ee60512012-03-05 19:24:57 +040080int main(int argc, char *argv[])
81{
Andreas Eversbergdfa563c2012-07-06 08:13:59 +020082 struct gprs_rlcmac_bts *bts;
Andreas Eversberg3e372d52012-07-06 09:28:15 +020083 int rc;
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020084
Andreas Eversbergdfa563c2012-07-06 08:13:59 +020085 bts = gprs_rlcmac_bts = talloc_zero(NULL, struct gprs_rlcmac_bts);
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020086 if (!gprs_rlcmac_bts)
87 return -ENOMEM;
Andreas Eversbergb3c6f6c2012-07-06 07:40:08 +020088 gprs_rlcmac_bts->initial_cs = 1;
Andreas Eversbergdfa563c2012-07-06 08:13:59 +020089 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 Eversberg5dac2f02012-06-27 15:52:04 +020099
Ivan Kluchnikova9f1ff22012-05-24 22:25:06 +0400100 osmo_init_logging(&gprs_log_info);
Andreas Eversberg81e895b2012-07-06 08:24:53 +0200101
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 Eversberg3e372d52012-07-06 09:28:15 +0200109 rc = pcu_l1if_open();
110 if (rc < 0)
111 return rc;
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400112
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400113 while (1)
114 {
Ivan Kluchnikov61a33f72012-04-12 15:22:06 +0400115 osmo_gsm_timers_check();
116 osmo_gsm_timers_prepare();
117 osmo_gsm_timers_update();
118
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400119 osmo_select_main(0);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400120 }
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200121
Andreas Eversberg3e372d52012-07-06 09:28:15 +0200122 pcu_l1if_close();
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200123 talloc_free(gprs_rlcmac_bts);
Andreas Eversberg3e372d52012-07-06 09:28:15 +0200124
125 return 0;
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400126}
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400127