blob: 329f669f2a511755fa23e6ca9e24fd98f40b2505 [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>
Ivan Kluchnikov61a33f72012-04-12 15:22:06 +040023#include <gsm_timer.h>
Ivan Kluchnikova9f1ff22012-05-24 22:25:06 +040024#include <gprs_debug.h>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040025
26// TODO: We should move this parameters to config file.
27#define SGSN_IP "127.0.0.1"
28#define SGSN_PORT 23000
29#define NSVCI 4
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040030
31int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, struct msgb *msg, uint16_t bvci)
32{
33 int rc = 0;
34 switch (event) {
35 case GPRS_NS_EVT_UNIT_DATA:
36 /* hand the message into the BSSGP implementation */
37 rc = gprs_bssgp_pcu_rcvmsg(msg);
38 break;
39 default:
Ivan Kluchnikova9f1ff22012-05-24 22:25:06 +040040 LOGP(DPCU, LOGL_ERROR, "RLCMAC: Unknown event %u from NS\n", event);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040041 if (msg)
42 talloc_free(msg);
43 rc = -EIO;
44 break;
45 }
46 return rc;
47}
48
49int main(int argc, char *argv[])
50{
51 uint16_t nsvci = NSVCI;
52 struct gprs_ns_inst *sgsn_nsi;
53 struct gprs_nsvc *nsvc;
Ivan Kluchnikova9f1ff22012-05-24 22:25:06 +040054 osmo_init_logging(&gprs_log_info);
Ivan Kluchnikove3a05962012-03-18 15:48:51 +040055 pcu_l1if_open();
56
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040057 sgsn_nsi = gprs_ns_instantiate(&sgsn_ns_cb);
58 bssgp_nsi = sgsn_nsi;
59
60 if (!bssgp_nsi)
61 {
Ivan Kluchnikova9f1ff22012-05-24 22:25:06 +040062 LOGP(DPCU, LOGL_ERROR, "Unable to instantiate NS\n");
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040063 exit(1);
64 }
65 bctx = btsctx_alloc(BVCI, NSEI);
66 bctx->cell_id = CELL_ID;
67 bctx->nsei = NSEI;
68 bctx->ra_id.mnc = MNC;
69 bctx->ra_id.mcc = MCC;
70 bctx->ra_id.lac = PCU_LAC;
71 bctx->ra_id.rac = PCU_RAC;
72 bctx->bvci = BVCI;
73 uint8_t cause = 39;
74 gprs_ns_nsip_listen(sgsn_nsi);
75
76 struct sockaddr_in dest;
77 dest.sin_family = AF_INET;
78 dest.sin_port = htons(SGSN_PORT);
79 inet_aton(SGSN_IP, &dest.sin_addr);
80
81 nsvc = nsip_connect(sgsn_nsi, &dest, NSEI, nsvci);
82 unsigned i = 0;
83 while (1)
84 {
Ivan Kluchnikov61a33f72012-04-12 15:22:06 +040085 osmo_gsm_timers_check();
86 osmo_gsm_timers_prepare();
87 osmo_gsm_timers_update();
88
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040089 osmo_select_main(0);
90 if (i == 7)
91 {
92 bssgp_tx_bvc_reset(bctx, BVCI, cause);
93 }
94 i++;
95 }
96}
Ivan Kluchnikove3a05962012-03-18 15:48:51 +040097