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> |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 26 | |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 27 | struct gprs_rlcmac_bts *gprs_rlcmac_bts; |
| 28 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 29 | // 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 Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 33 | |
| 34 | int 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 Kluchnikov | a9f1ff2 | 2012-05-24 22:25:06 +0400 | [diff] [blame] | 43 | LOGP(DPCU, LOGL_ERROR, "RLCMAC: Unknown event %u from NS\n", event); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 44 | if (msg) |
| 45 | talloc_free(msg); |
| 46 | rc = -EIO; |
| 47 | break; |
| 48 | } |
| 49 | return rc; |
| 50 | } |
| 51 | |
| 52 | int main(int argc, char *argv[]) |
| 53 | { |
| 54 | uint16_t nsvci = NSVCI; |
| 55 | struct gprs_ns_inst *sgsn_nsi; |
| 56 | struct gprs_nsvc *nsvc; |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 57 | |
| 58 | gprs_rlcmac_bts = talloc_zero(NULL, struct gprs_rlcmac_bts); |
| 59 | if (!gprs_rlcmac_bts) |
| 60 | return -ENOMEM; |
Andreas Eversberg | b3c6f6c | 2012-07-06 07:40:08 +0200 | [diff] [blame^] | 61 | gprs_rlcmac_bts->initial_cs = 1; |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 62 | |
Ivan Kluchnikov | a9f1ff2 | 2012-05-24 22:25:06 +0400 | [diff] [blame] | 63 | osmo_init_logging(&gprs_log_info); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 64 | pcu_l1if_open(); |
| 65 | |
Harald Welte | d679009 | 2012-06-18 12:21:03 +0800 | [diff] [blame] | 66 | sgsn_nsi = gprs_ns_instantiate(&sgsn_ns_cb, NULL); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 67 | bssgp_nsi = sgsn_nsi; |
| 68 | |
| 69 | if (!bssgp_nsi) |
| 70 | { |
Ivan Kluchnikov | a9f1ff2 | 2012-05-24 22:25:06 +0400 | [diff] [blame] | 71 | LOGP(DPCU, LOGL_ERROR, "Unable to instantiate NS\n"); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 72 | 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 Welte | d679009 | 2012-06-18 12:21:03 +0800 | [diff] [blame] | 90 | nsvc = gprs_ns_nsip_connect(sgsn_nsi, &dest, NSEI, nsvci); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 91 | unsigned i = 0; |
| 92 | while (1) |
| 93 | { |
Ivan Kluchnikov | 61a33f7 | 2012-04-12 15:22:06 +0400 | [diff] [blame] | 94 | osmo_gsm_timers_check(); |
| 95 | osmo_gsm_timers_prepare(); |
| 96 | osmo_gsm_timers_update(); |
| 97 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 98 | osmo_select_main(0); |
| 99 | if (i == 7) |
| 100 | { |
| 101 | bssgp_tx_bvc_reset(bctx, BVCI, cause); |
| 102 | } |
| 103 | i++; |
| 104 | } |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 105 | |
| 106 | talloc_free(gprs_rlcmac_bts); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 107 | } |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 108 | |