blob: ae176bc09992d67b35d82e6d81ccbddb1ca51660 [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>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040026
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020027struct gprs_rlcmac_bts *gprs_rlcmac_bts;
28
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040029// TODO: We should move this parameters to config file.
30#define SGSN_IP "127.0.0.1"
31#define SGSN_PORT 23000
32#define NSVCI 4
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040033
34int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, struct msgb *msg, uint16_t bvci)
35{
36 int rc = 0;
37 switch (event) {
38 case GPRS_NS_EVT_UNIT_DATA:
39 /* hand the message into the BSSGP implementation */
40 rc = gprs_bssgp_pcu_rcvmsg(msg);
41 break;
42 default:
Ivan Kluchnikova9f1ff22012-05-24 22:25:06 +040043 LOGP(DPCU, LOGL_ERROR, "RLCMAC: Unknown event %u from NS\n", event);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040044 if (msg)
45 talloc_free(msg);
46 rc = -EIO;
47 break;
48 }
49 return rc;
50}
51
52int main(int argc, char *argv[])
53{
54 uint16_t nsvci = NSVCI;
55 struct gprs_ns_inst *sgsn_nsi;
56 struct gprs_nsvc *nsvc;
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020057
58 gprs_rlcmac_bts = talloc_zero(NULL, struct gprs_rlcmac_bts);
59 if (!gprs_rlcmac_bts)
60 return -ENOMEM;
Andreas Eversbergb3c6f6c2012-07-06 07:40:08 +020061 gprs_rlcmac_bts->initial_cs = 1;
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020062
Ivan Kluchnikova9f1ff22012-05-24 22:25:06 +040063 osmo_init_logging(&gprs_log_info);
Ivan Kluchnikove3a05962012-03-18 15:48:51 +040064 pcu_l1if_open();
65
Harald Welted6790092012-06-18 12:21:03 +080066 sgsn_nsi = gprs_ns_instantiate(&sgsn_ns_cb, NULL);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040067 bssgp_nsi = sgsn_nsi;
68
69 if (!bssgp_nsi)
70 {
Ivan Kluchnikova9f1ff22012-05-24 22:25:06 +040071 LOGP(DPCU, LOGL_ERROR, "Unable to instantiate NS\n");
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040072 exit(1);
73 }
74 bctx = btsctx_alloc(BVCI, NSEI);
75 bctx->cell_id = CELL_ID;
76 bctx->nsei = NSEI;
77 bctx->ra_id.mnc = MNC;
78 bctx->ra_id.mcc = MCC;
79 bctx->ra_id.lac = PCU_LAC;
80 bctx->ra_id.rac = PCU_RAC;
81 bctx->bvci = BVCI;
82 uint8_t cause = 39;
83 gprs_ns_nsip_listen(sgsn_nsi);
84
85 struct sockaddr_in dest;
86 dest.sin_family = AF_INET;
87 dest.sin_port = htons(SGSN_PORT);
88 inet_aton(SGSN_IP, &dest.sin_addr);
89
Harald Welted6790092012-06-18 12:21:03 +080090 nsvc = gprs_ns_nsip_connect(sgsn_nsi, &dest, NSEI, nsvci);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040091 unsigned i = 0;
92 while (1)
93 {
Ivan Kluchnikov61a33f72012-04-12 15:22:06 +040094 osmo_gsm_timers_check();
95 osmo_gsm_timers_prepare();
96 osmo_gsm_timers_update();
97
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040098 osmo_select_main(0);
99 if (i == 7)
100 {
101 bssgp_tx_bvc_reset(bctx, BVCI, cause);
102 }
103 i++;
104 }
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200105
106 talloc_free(gprs_rlcmac_bts);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400107}
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400108