aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcu_main.cpp
diff options
context:
space:
mode:
authorIvan Kluchnikov <kluchnikovi@gmail.com>2012-07-12 14:49:15 +0400
committerIvan Kluchnikov <kluchnikovi@gmail.com>2012-07-12 14:49:15 +0400
commitef7f28cc7fe67e353821c5f88bc80d5120fec3ca (patch)
treeca1b24fafa82862b1d5cd38ce1434973033588f0 /src/pcu_main.cpp
parentc7e7f6868b6f24346424dee904f4e76d3f216ff4 (diff)
parente13fa2d56936d6bed8febcc41508a30e4a1038f0 (diff)
Merge branch 'jolly_new'
Merge is based on jolly_new branch with two modifications. 1. Modified PCU L1 interface. pcu_l1_if.cpp - common functions for tx and rx messages on L1 interface. sysmo_sock.cpp - SYSMO-PCU socket functions. openbts_sock.cpp - OpenBTS-PCU socket functions. pcuif_proto.h - L1 interface's primitives. 2. Modified encoding of RLC/MAC Control messages, now we use structures and encode_gsm_rlcmac_downlink() function for encode control blocks (without hand-coding).
Diffstat (limited to 'src/pcu_main.cpp')
-rw-r--r--src/pcu_main.cpp131
1 files changed, 80 insertions, 51 deletions
diff --git a/src/pcu_main.cpp b/src/pcu_main.cpp
index fa1ffb19..6c30c1e4 100644
--- a/src/pcu_main.cpp
+++ b/src/pcu_main.cpp
@@ -20,66 +20,96 @@
#include <gprs_bssgp_pcu.h>
#include <arpa/inet.h>
#include <pcu_l1_if.h>
+#include <gprs_rlcmac.h>
#include <gsm_timer.h>
#include <gprs_debug.h>
+#include <unistd.h>
+#include <getopt.h>
-// TODO: We should move this parameters to config file.
-#define SGSN_IP "127.0.0.1"
-#define SGSN_PORT 23000
-#define NSVCI 4
+struct gprs_rlcmac_bts *gprs_rlcmac_bts;
+extern struct gprs_nsvc *nsvc;
+uint16_t spoof_mcc = 0, spoof_mnc = 0;
-int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, struct msgb *msg, uint16_t bvci)
+static void print_help()
{
- int rc = 0;
- switch (event) {
- case GPRS_NS_EVT_UNIT_DATA:
- /* hand the message into the BSSGP implementation */
- rc = gprs_bssgp_pcu_rcvmsg(msg);
- break;
- default:
- LOGP(DPCU, LOGL_ERROR, "RLCMAC: Unknown event %u from NS\n", event);
- if (msg)
- talloc_free(msg);
- rc = -EIO;
- break;
+ 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", 1, 0, 'm' },
+ { "mnc", 1, 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;
+ }
}
- return rc;
}
int main(int argc, char *argv[])
{
- uint16_t nsvci = NSVCI;
- struct gprs_ns_inst *sgsn_nsi;
- struct gprs_nsvc *nsvc;
- osmo_init_logging(&gprs_log_info);
- pcu_l1if_open();
+ struct gprs_rlcmac_bts *bts;
+ int rc;
- sgsn_nsi = gprs_ns_instantiate(&sgsn_ns_cb, NULL);
- bssgp_nsi = sgsn_nsi;
+ bts = gprs_rlcmac_bts = talloc_zero(NULL, struct gprs_rlcmac_bts);
+ if (!gprs_rlcmac_bts)
+ return -ENOMEM;
+ gprs_rlcmac_bts->initial_cs = 1;
+ bts->initial_cs = 1;
+ bts->cs1 = 1;
+ bts->t3142 = 20;
+ bts->t3169 = 5;
+ bts->t3191 = 5;
+ bts->t3193_msec = 100;
+ bts->t3195 = 5;
+ bts->n3101 = 10;
+ bts->n3103 = 4;
+ bts->n3105 = 8;
- if (!bssgp_nsi)
- {
- LOGP(DPCU, LOGL_ERROR, "Unable to instantiate NS\n");
- exit(1);
+ 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);
}
- 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.lac = PCU_LAC;
- bctx->ra_id.rac = PCU_RAC;
- bctx->bvci = BVCI;
- uint8_t cause = 39;
- gprs_ns_nsip_listen(sgsn_nsi);
+ rc = pcu_l1if_open();
- struct sockaddr_in dest;
- dest.sin_family = AF_INET;
- dest.sin_port = htons(SGSN_PORT);
- inet_aton(SGSN_IP, &dest.sin_addr);
+ if (rc < 0)
+ return rc;
- nsvc = gprs_ns_nsip_connect(sgsn_nsi, &dest, NSEI, nsvci);
- unsigned i = 0;
while (1)
{
osmo_gsm_timers_check();
@@ -87,11 +117,10 @@ int main(int argc, char *argv[])
osmo_gsm_timers_update();
osmo_select_main(0);
- if (i == 7)
- {
- bssgp_tx_bvc_reset(bctx, BVCI, cause);
- }
- i++;
}
-}
+ pcu_l1if_close();
+ talloc_free(gprs_rlcmac_bts);
+
+ return 0;
+}