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> |
Ivan Kluchnikov | 61a33f7 | 2012-04-12 15:22:06 +0400 | [diff] [blame] | 23 | #include <gsm_timer.h> |
Ivan Kluchnikov | a9f1ff2 | 2012-05-24 22:25:06 +0400 | [diff] [blame] | 24 | #include <gprs_debug.h> |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 25 | |
| 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 Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 30 | |
| 31 | int 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 Kluchnikov | a9f1ff2 | 2012-05-24 22:25:06 +0400 | [diff] [blame] | 40 | LOGP(DPCU, LOGL_ERROR, "RLCMAC: Unknown event %u from NS\n", event); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 41 | if (msg) |
| 42 | talloc_free(msg); |
| 43 | rc = -EIO; |
| 44 | break; |
| 45 | } |
| 46 | return rc; |
| 47 | } |
| 48 | |
| 49 | int main(int argc, char *argv[]) |
| 50 | { |
| 51 | uint16_t nsvci = NSVCI; |
| 52 | struct gprs_ns_inst *sgsn_nsi; |
| 53 | struct gprs_nsvc *nsvc; |
Ivan Kluchnikov | a9f1ff2 | 2012-05-24 22:25:06 +0400 | [diff] [blame] | 54 | osmo_init_logging(&gprs_log_info); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 55 | pcu_l1if_open(); |
| 56 | |
Harald Welte | 477e79e | 2012-06-18 12:21:03 +0800 | [diff] [blame] | 57 | sgsn_nsi = gprs_ns_instantiate(&sgsn_ns_cb, NULL); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 58 | bssgp_nsi = sgsn_nsi; |
| 59 | |
| 60 | if (!bssgp_nsi) |
| 61 | { |
Ivan Kluchnikov | a9f1ff2 | 2012-05-24 22:25:06 +0400 | [diff] [blame] | 62 | LOGP(DPCU, LOGL_ERROR, "Unable to instantiate NS\n"); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 63 | 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 | |
Harald Welte | 477e79e | 2012-06-18 12:21:03 +0800 | [diff] [blame] | 81 | nsvc = gprs_ns_nsip_connect(sgsn_nsi, &dest, NSEI, nsvci); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 82 | unsigned i = 0; |
| 83 | while (1) |
| 84 | { |
Ivan Kluchnikov | 61a33f7 | 2012-04-12 15:22:06 +0400 | [diff] [blame] | 85 | osmo_gsm_timers_check(); |
| 86 | osmo_gsm_timers_prepare(); |
| 87 | osmo_gsm_timers_update(); |
| 88 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 89 | osmo_select_main(0); |
| 90 | if (i == 7) |
| 91 | { |
| 92 | bssgp_tx_bvc_reset(bctx, BVCI, cause); |
| 93 | } |
| 94 | i++; |
| 95 | } |
| 96 | } |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 97 | |