blob: 1dac5dd3b78234ad4329c15d233fa0620c9e260a [file] [log] [blame]
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001/* pcu_l1_if.cpp
2 *
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04003 * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04004 *
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
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040020#include <stdio.h>
21#include <unistd.h>
22#include <stdlib.h>
Andreas Eversberg0aed6542012-06-23 10:33:16 +020023#include <string.h>
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040024#include <errno.h>
25#include <assert.h>
Andreas Eversberg0aed6542012-06-23 10:33:16 +020026#include <sys/socket.h>
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040027#include <sys/un.h>
Andreas Eversberg81a12be2013-03-16 16:16:41 +010028#include <arpa/inet.h>
Andreas Eversberg0aed6542012-06-23 10:33:16 +020029extern "C" {
30#include <osmocom/core/talloc.h>
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040031#include <osmocom/core/select.h>
32#include <osmocom/core/msgb.h>
Andreas Eversberg0aed6542012-06-23 10:33:16 +020033}
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040034
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040035#include <gprs_rlcmac.h>
36#include <pcu_l1_if.h>
37#include <gprs_debug.h>
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040038#include <gprs_bssgp_pcu.h>
39#include <pcuif_proto.h>
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020040#include <bts.h>
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +020041#include <tbf.h>
Andreas Eversberg0aed6542012-06-23 10:33:16 +020042
Andreas Eversberga23c7ee2012-12-18 10:47:28 +010043// FIXME: move this, when changed from c++ to c.
44extern "C" {
45void *l1if_open_pdch(void *priv, uint32_t hlayer1);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +010046int l1if_connect_pdch(void *obj, uint8_t ts);
47int l1if_pdch_req(void *obj, uint8_t ts, int is_ptcch, uint32_t fn,
48 uint16_t arfcn, uint8_t block_nr, uint8_t *data, uint8_t len);
49}
50
Andreas Eversberge266bd42012-07-13 14:00:21 +020051extern void *tall_pcu_ctx;
52
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040053/*
54 * PCU messages
55 */
Ivan Kluchnikove3a05962012-03-18 15:48:51 +040056
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040057struct msgb *pcu_msgb_alloc(uint8_t msg_type, uint8_t bts_nr)
58{
59 struct msgb *msg;
60 struct gsm_pcu_if *pcu_prim;
61
62 msg = msgb_alloc(sizeof(struct gsm_pcu_if), "pcu_sock_tx");
63 if (!msg)
64 return NULL;
65 msgb_put(msg, sizeof(struct gsm_pcu_if));
66 pcu_prim = (struct gsm_pcu_if *) msg->data;
67 pcu_prim->msg_type = msg_type;
68 pcu_prim->bts_nr = bts_nr;
Ivan Kluchnikove3a05962012-03-18 15:48:51 +040069
70 return msg;
71}
72
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040073static int pcu_tx_act_req(uint8_t trx, uint8_t ts, uint8_t activate)
Ivan Kluchnikov4277f0c2012-04-12 14:24:35 +040074{
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040075 struct msgb *msg;
76 struct gsm_pcu_if *pcu_prim;
77 struct gsm_pcu_if_act_req *act_req;
78
79 LOGP(DL1IF, LOGL_INFO, "Sending %s request: trx=%d ts=%d\n",
80 (activate) ? "activate" : "deactivate", trx, ts);
81
82 msg = pcu_msgb_alloc(PCU_IF_MSG_ACT_REQ, 0);
83 if (!msg)
84 return -ENOMEM;
85 pcu_prim = (struct gsm_pcu_if *) msg->data;
86 act_req = &pcu_prim->u.act_req;
87 act_req->activate = activate;
88 act_req->trx_nr = trx;
89 act_req->ts_nr = ts;
90
91 return pcu_sock_send(msg);
92}
93
94static int pcu_tx_data_req(uint8_t trx, uint8_t ts, uint8_t sapi,
95 uint16_t arfcn, uint32_t fn, uint8_t block_nr, uint8_t *data,
96 uint8_t len)
97{
98 struct msgb *msg;
99 struct gsm_pcu_if *pcu_prim;
100 struct gsm_pcu_if_data *data_req;
101
102 LOGP(DL1IF, LOGL_DEBUG, "Sending data request: trx=%d ts=%d sapi=%d "
103 "arfcn=%d fn=%d block=%d data=%s\n", trx, ts, sapi, arfcn, fn,
104 block_nr, osmo_hexdump(data, len));
105
106 msg = pcu_msgb_alloc(PCU_IF_MSG_DATA_REQ, 0);
107 if (!msg)
108 return -ENOMEM;
109 pcu_prim = (struct gsm_pcu_if *) msg->data;
110 data_req = &pcu_prim->u.data_req;
111
112 data_req->sapi = sapi;
113 data_req->fn = fn;
114 data_req->arfcn = arfcn;
115 data_req->trx_nr = trx;
116 data_req->ts_nr = ts;
117 data_req->block_nr = block_nr;
118 memcpy(data_req->data, data, len);
119 data_req->len = len;
120
121 return pcu_sock_send(msg);
122}
123
124void pcu_l1if_tx_pdtch(msgb *msg, uint8_t trx, uint8_t ts, uint16_t arfcn,
125 uint32_t fn, uint8_t block_nr)
126{
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100127#ifdef ENABLE_SYSMODSP
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200128 struct gprs_rlcmac_bts *bts = bts_main_data();
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100129
130 if (bts->trx[trx].fl1h)
131 l1if_pdch_req(bts->trx[trx].fl1h, ts, 0, fn, arfcn, block_nr,
132 msg->data, msg->len);
133 else
134#endif
135 pcu_tx_data_req(trx, ts, PCU_IF_SAPI_PDTCH, arfcn, fn, block_nr,
136 msg->data, msg->len);
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200137 msgb_free(msg);
Ivan Kluchnikov4277f0c2012-04-12 14:24:35 +0400138}
139
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400140void pcu_l1if_tx_ptcch(msgb *msg, uint8_t trx, uint8_t ts, uint16_t arfcn,
141 uint32_t fn, uint8_t block_nr)
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400142{
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100143#ifdef ENABLE_SYSMODSP
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200144 struct gprs_rlcmac_bts *bts = bts_main_data();
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100145
146 if (bts->trx[trx].fl1h)
147 l1if_pdch_req(bts->trx[trx].fl1h, ts, 1, fn, arfcn, block_nr,
148 msg->data, msg->len);
149 else
150#endif
151 pcu_tx_data_req(trx, ts, PCU_IF_SAPI_PTCCH, arfcn, fn, block_nr,
152 msg->data, msg->len);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400153 msgb_free(msg);
154}
155
Andreas Eversberg7b045012012-07-05 07:38:49 +0200156void pcu_l1if_tx_agch(bitvec * block, int plen)
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400157{
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400158 uint8_t data[23]; /* prefix PLEN */
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400159
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400160 /* FIXME: why does OpenBTS has no PLEN and no fill in message? */
161 bitvec_pack(block, data + 1);
162 data[0] = (plen << 2) | 0x01;
163 pcu_tx_data_req(0, 0, PCU_IF_SAPI_AGCH, 0, 0, 0, data, 23);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400164}
165
Holger Hans Peter Freyther52c911b2013-08-24 18:30:54 +0200166void pcu_l1if_tx_pch(bitvec * block, int plen, const char *imsi)
Ivan Kluchnikovc7e7f682012-06-29 22:53:15 +0400167{
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400168 uint8_t data[23+3]; /* prefix PLEN */
169
170 /* paging group */
171 if (!imsi || strlen(imsi) < 3)
172 return;
173 imsi += strlen(imsi) - 3;
174 data[0] = imsi[0];
175 data[1] = imsi[1];
176 data[2] = imsi[2];
177
178 bitvec_pack(block, data + 3+1);
179 data[3] = (plen << 2) | 0x01;
180 pcu_tx_data_req(0, 0, PCU_IF_SAPI_PCH, 0, 0, 0, data, 23+3);
Ivan Kluchnikovc7e7f682012-06-29 22:53:15 +0400181}
182
Holger Hans Peter Freyther9ae367f2013-10-26 16:42:38 +0200183extern "C" int pcu_rx_data_ind_pdtch(uint8_t trx_no, uint8_t ts_no, uint8_t *data,
Andreas Eversberg570b44b2013-03-16 16:15:01 +0100184 uint8_t len, uint32_t fn, int8_t rssi)
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100185{
Holger Hans Peter Freyther9ae367f2013-10-26 16:42:38 +0200186 struct gprs_rlcmac_pdch *pdch;
187
188 pdch = &bts_main_data()->trx[trx_no].pdch[ts_no];
189 return pdch->rcv_block(data, len, fn, rssi);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100190}
191
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400192static int pcu_rx_data_ind(struct gsm_pcu_if_data *data_ind)
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400193{
194 int rc = 0;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400195
196 LOGP(DL1IF, LOGL_DEBUG, "Data indication received: sapi=%d arfcn=%d "
197 "block=%d data=%s\n", data_ind->sapi,
198 data_ind->arfcn, data_ind->block_nr,
199 osmo_hexdump(data_ind->data, data_ind->len));
200
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400201 switch (data_ind->sapi) {
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400202 case PCU_IF_SAPI_PDTCH:
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100203 rc = pcu_rx_data_ind_pdtch(data_ind->trx_nr, data_ind->ts_nr,
Andreas Eversberg570b44b2013-03-16 16:15:01 +0100204 data_ind->data, data_ind->len, data_ind->fn,
205 data_ind->rssi);
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400206 break;
207 default:
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400208 LOGP(DL1IF, LOGL_ERROR, "Received PCU data indication with "
209 "unsupported sapi %d\n", data_ind->sapi);
210 rc = -EINVAL;
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400211 }
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400212
213 return rc;
214}
215
Andreas Eversberga9be1542012-09-27 09:23:24 +0200216static int pcu_rx_data_cnf(struct gsm_pcu_if_data *data_cnf)
217{
218 int rc = 0;
219
220 LOGP(DL1IF, LOGL_DEBUG, "Data confirm received: sapi=%d fn=%d\n",
221 data_cnf->sapi, data_cnf->fn);
222
223 switch (data_cnf->sapi) {
224 case PCU_IF_SAPI_PCH:
Andreas Eversberg8c3680d2012-10-08 12:30:56 +0200225 if (data_cnf->data[2] == 0x3f)
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200226 rc = gprs_rlcmac_imm_ass_cnf(BTS::main_bts(),
227 data_cnf->data, data_cnf->fn);
Andreas Eversberga9be1542012-09-27 09:23:24 +0200228 break;
229 default:
230 LOGP(DL1IF, LOGL_ERROR, "Received PCU data confirm with "
231 "unsupported sapi %d\n", data_cnf->sapi);
232 rc = -EINVAL;
233 }
234
235 return rc;
236}
237
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100238// FIXME: remove this, when changed from c++ to c.
239extern "C" int pcu_rx_rts_req_pdtch(uint8_t trx, uint8_t ts, uint16_t arfcn,
240 uint32_t fn, uint8_t block_nr)
241{
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200242 return gprs_rlcmac_rcv_rts_block(bts_main_data(),
243 trx, ts, arfcn, fn, block_nr);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100244}
245
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400246static int pcu_rx_rts_req(struct gsm_pcu_if_rts_req *rts_req)
Ivan Kluchnikov5310d452012-04-17 22:00:31 +0400247{
248 int rc = 0;
Ivan Kluchnikov5310d452012-04-17 22:00:31 +0400249
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400250 LOGP(DL1IF, LOGL_DEBUG, "RTS request received: trx=%d ts=%d sapi=%d "
251 "arfcn=%d fn=%d block=%d\n", rts_req->trx_nr, rts_req->ts_nr,
252 rts_req->sapi, rts_req->arfcn, rts_req->fn, rts_req->block_nr);
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400253
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400254 switch (rts_req->sapi) {
255 case PCU_IF_SAPI_PDTCH:
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100256 pcu_rx_rts_req_pdtch(rts_req->trx_nr, rts_req->ts_nr,
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400257 rts_req->arfcn, rts_req->fn, rts_req->block_nr);
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400258 break;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400259 case PCU_IF_SAPI_PTCCH:
260 /* FIXME */
261 {
262 struct msgb *msg = msgb_alloc(23, "l1_prim");
263 memset(msgb_put(msg, 23), 0x2b, 23);
264 pcu_l1if_tx_ptcch(msg, rts_req->trx_nr, rts_req->ts_nr,
265 rts_req->arfcn, rts_req->fn, rts_req->block_nr);
266 }
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400267 break;
268 default:
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400269 LOGP(DL1IF, LOGL_ERROR, "Received PCU RTS request with "
270 "unsupported sapi %d\n", rts_req->sapi);
271 rc = -EINVAL;
272 }
273
274 return rc;
275}
276
277static int pcu_rx_rach_ind(struct gsm_pcu_if_rach_ind *rach_ind)
278{
279 int rc = 0;
280
281 LOGP(DL1IF, LOGL_INFO, "RACH request received: sapi=%d "
282 "qta=%d, ra=%d, fn=%d\n", rach_ind->sapi, rach_ind->qta,
283 rach_ind->ra, rach_ind->fn);
284
285 switch (rach_ind->sapi) {
286 case PCU_IF_SAPI_RACH:
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200287 rc = gprs_rlcmac_rcv_rach(bts_main_data(),
Holger Hans Peter Freytherb0250eb2013-10-17 13:46:19 +0200288 rach_ind->ra, rach_ind->fn,
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400289 rach_ind->qta);
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400290 break;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400291 default:
292 LOGP(DL1IF, LOGL_ERROR, "Received PCU rach request with "
293 "unsupported sapi %d\n", rach_ind->sapi);
294 rc = -EINVAL;
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400295 }
296
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400297 return rc;
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400298}
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200299
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400300static int pcu_rx_info_ind(struct gsm_pcu_if_info_ind *info_ind)
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200301{
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200302 struct gprs_rlcmac_bts *bts = bts_main_data();
Holger Hans Peter Freythere8d9a5f2013-07-28 19:11:20 +0200303 struct gprs_bssgp_pcu *pcu;
Andreas Eversberg2b914642012-07-19 13:06:26 +0200304 struct gprs_rlcmac_pdch *pdch;
Andreas Eversberg81a12be2013-03-16 16:16:41 +0100305 struct in_addr ia;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400306 int rc = 0;
Andreas Eversberg2b914642012-07-19 13:06:26 +0200307 int trx, ts;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400308 int i;
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200309
Andreas Eversberg8389fd02012-07-18 10:06:48 +0200310 if (info_ind->version != PCU_IF_VERSION) {
311 fprintf(stderr, "PCU interface version number of BTS (%d) is "
312 "different (%d).\nPlease re-compile!\n",
313 info_ind->version, PCU_IF_VERSION);
314 exit(-1);
315 }
316
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400317 LOGP(DL1IF, LOGL_DEBUG, "Info indication received:\n");
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200318
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400319 if (!(info_ind->flags & PCU_IF_FLAG_ACTIVE)) {
320 LOGP(DL1IF, LOGL_NOTICE, "BTS not available\n");
321bssgp_failed:
322 /* free all TBF */
323 for (trx = 0; trx < 8; trx++) {
324 bts->trx[trx].arfcn = info_ind->trx[trx].arfcn;
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200325 for (ts = 0; ts < 8; ts++)
Holger Hans Peter Freyther09ef27a2013-10-20 16:37:05 +0200326 bts->trx[trx].pdch[ts].free_resources();
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400327 }
Holger Hans Peter Freythera30f4762013-07-11 16:13:38 +0200328 gprs_bssgp_destroy_or_exit();
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400329 return 0;
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200330 }
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400331 LOGP(DL1IF, LOGL_INFO, "BTS available\n");
Andreas Eversberg514491d2012-09-23 06:42:07 +0200332 LOGP(DL1IF, LOGL_DEBUG, " mcc=%x\n", info_ind->mcc);
333 LOGP(DL1IF, LOGL_DEBUG, " mnc=%x\n", info_ind->mnc);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400334 LOGP(DL1IF, LOGL_DEBUG, " lac=%d\n", info_ind->lac);
335 LOGP(DL1IF, LOGL_DEBUG, " rac=%d\n", info_ind->rac);
Andreas Eversberg514491d2012-09-23 06:42:07 +0200336 LOGP(DL1IF, LOGL_DEBUG, " cell_id=%d\n", ntohs(info_ind->cell_id));
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100337 LOGP(DL1IF, LOGL_DEBUG, " bsic=%d\n", info_ind->bsic);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400338 LOGP(DL1IF, LOGL_DEBUG, " nsei=%d\n", info_ind->nsei);
339 LOGP(DL1IF, LOGL_DEBUG, " nse_timer=%d %d %d %d %d %d %d\n",
340 info_ind->nse_timer[0], info_ind->nse_timer[1],
341 info_ind->nse_timer[2], info_ind->nse_timer[3],
342 info_ind->nse_timer[4], info_ind->nse_timer[5],
343 info_ind->nse_timer[6]);
344 LOGP(DL1IF, LOGL_DEBUG, " cell_timer=%d %d %d %d %d %d %d %d %d %d "
345 "%d\n",
346 info_ind->cell_timer[0], info_ind->cell_timer[1],
347 info_ind->cell_timer[2], info_ind->cell_timer[3],
348 info_ind->cell_timer[4], info_ind->cell_timer[5],
349 info_ind->cell_timer[6], info_ind->cell_timer[7],
350 info_ind->cell_timer[8], info_ind->cell_timer[9],
351 info_ind->cell_timer[10]);
352 LOGP(DL1IF, LOGL_DEBUG, " repeat_time=%d\n", info_ind->repeat_time);
353 LOGP(DL1IF, LOGL_DEBUG, " repeat_count=%d\n", info_ind->repeat_count);
354 LOGP(DL1IF, LOGL_DEBUG, " bvci=%d\n", info_ind->bvci);
355 LOGP(DL1IF, LOGL_DEBUG, " t3142=%d\n", info_ind->t3142);
356 LOGP(DL1IF, LOGL_DEBUG, " t3169=%d\n", info_ind->t3169);
357 LOGP(DL1IF, LOGL_DEBUG, " t3191=%d\n", info_ind->t3191);
358 LOGP(DL1IF, LOGL_DEBUG, " t3193=%d (ms)\n", info_ind->t3193_10ms * 10);
359 LOGP(DL1IF, LOGL_DEBUG, " t3195=%d\n", info_ind->t3195);
360 LOGP(DL1IF, LOGL_DEBUG, " n3101=%d\n", info_ind->n3101);
361 LOGP(DL1IF, LOGL_DEBUG, " n3103=%d\n", info_ind->n3103);
362 LOGP(DL1IF, LOGL_DEBUG, " n3105=%d\n", info_ind->n3105);
363 LOGP(DL1IF, LOGL_DEBUG, " cv_countdown=%d\n", info_ind->cv_countdown);
364 LOGP(DL1IF, LOGL_DEBUG, " dl_tbf_ext=%d\n", info_ind->dl_tbf_ext);
365 LOGP(DL1IF, LOGL_DEBUG, " ul_tbf_ext=%d\n", info_ind->ul_tbf_ext);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100366 bts->bsic = info_ind->bsic;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400367 for (i = 0; i < 4; i++) {
368 if ((info_ind->flags & (PCU_IF_FLAG_CS1 << i)))
369 LOGP(DL1IF, LOGL_DEBUG, " Use CS%d\n", i+1);
370 }
371 for (i = 0; i < 9; i++) {
372 if ((info_ind->flags & (PCU_IF_FLAG_MCS1 << i)))
373 LOGP(DL1IF, LOGL_DEBUG, " Use MCS%d\n", i+1);
374 }
375 LOGP(DL1IF, LOGL_DEBUG, " initial_cs=%d\n", info_ind->initial_cs);
376 LOGP(DL1IF, LOGL_DEBUG, " initial_mcs=%d\n", info_ind->initial_mcs);
377 LOGP(DL1IF, LOGL_DEBUG, " nsvci=%d\n", info_ind->nsvci[0]);
378 LOGP(DL1IF, LOGL_DEBUG, " local_port=%d\n", info_ind->local_port[0]);
379 LOGP(DL1IF, LOGL_DEBUG, " remote_port=%d\n", info_ind->remote_port[0]);
Andreas Eversberg81a12be2013-03-16 16:16:41 +0100380 ia.s_addr = htonl(info_ind->remote_ip[0]);
381 LOGP(DL1IF, LOGL_DEBUG, " remote_ip=%s\n", inet_ntoa(ia));
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200382
Holger Hans Peter Freythere8d9a5f2013-07-28 19:11:20 +0200383 pcu = gprs_bssgp_create_and_connect(bts, info_ind->local_port[0],
Harald Welte30a73d82013-03-10 08:54:30 +0000384 info_ind->remote_ip[0], info_ind->remote_port[0],
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400385 info_ind->nsei, info_ind->nsvci[0], info_ind->bvci,
386 info_ind->mcc, info_ind->mnc, info_ind->lac, info_ind->rac,
387 info_ind->cell_id);
Holger Hans Peter Freythere8d9a5f2013-07-28 19:11:20 +0200388 if (!pcu) {
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400389 LOGP(DL1IF, LOGL_NOTICE, "SGSN not available\n");
390 goto bssgp_failed;
391 }
392
393 bts->cs1 = !!(info_ind->flags & PCU_IF_FLAG_CS1);
394 bts->cs2 = !!(info_ind->flags & PCU_IF_FLAG_CS2);
395 bts->cs3 = !!(info_ind->flags & PCU_IF_FLAG_CS3);
396 bts->cs4 = !!(info_ind->flags & PCU_IF_FLAG_CS4);
397 if (!bts->cs1 && !bts->cs2 && !bts->cs3 && !bts->cs4)
398 bts->cs1 = 1;
399 if (info_ind->t3142) { /* if timer values are set */
400 bts->t3142 = info_ind->t3142;
401 bts->t3169 = info_ind->t3169;
402 bts->t3191 = info_ind->t3191;
403 bts->t3193_msec = info_ind->t3193_10ms * 10;
404 bts->t3195 = info_ind->t3195;
405 bts->n3101 = info_ind->n3101;
406 bts->n3103 = info_ind->n3103;
407 bts->n3105 = info_ind->n3105;
408 }
Andreas Eversberg8b761a32012-07-20 21:50:31 +0200409 if (!bts->force_cs) {
410 if (info_ind->initial_cs < 1 || info_ind->initial_cs > 4)
Andreas Eversberg499ff412012-10-03 14:21:36 +0200411 bts->initial_cs_dl = 1;
Andreas Eversberg8b761a32012-07-20 21:50:31 +0200412 else
Andreas Eversberg499ff412012-10-03 14:21:36 +0200413 bts->initial_cs_dl = info_ind->initial_cs;
414 bts->initial_cs_ul = bts->initial_cs_dl;
Andreas Eversberg8b761a32012-07-20 21:50:31 +0200415 }
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400416
417 for (trx = 0; trx < 8; trx++) {
418 bts->trx[trx].arfcn = info_ind->trx[trx].arfcn;
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100419 if ((info_ind->flags & PCU_IF_FLAG_SYSMO)
420 && info_ind->trx[trx].hlayer1) {
421#ifdef ENABLE_SYSMODSP
422 LOGP(DL1IF, LOGL_DEBUG, " TRX %d hlayer1=%x\n", trx,
423 info_ind->trx[trx].hlayer1);
424 if (!bts->trx[trx].fl1h)
425 bts->trx[trx].fl1h = l1if_open_pdch(
426 (void *)trx,
427 info_ind->trx[trx].hlayer1);
428 if (!bts->trx[trx].fl1h) {
429 LOGP(DL1IF, LOGL_FATAL, "Failed to open direct "
430 "DSP access for PDCH.\n");
431 exit(0);
432 }
433#else
434 LOGP(DL1IF, LOGL_FATAL, "Compiled without direct DSP "
435 "access for PDCH, but enabled at "
436 "BTS. Please deactivate it!\n");
437 exit(0);
438#endif
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100439 }
440
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400441 for (ts = 0; ts < 8; ts++) {
Andreas Eversberg2b914642012-07-19 13:06:26 +0200442 pdch = &bts->trx[trx].pdch[ts];
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400443 if ((info_ind->trx[trx].pdch_mask & (1 << ts))) {
444 /* FIXME: activate dynamically at RLCMAC */
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200445 if (!pdch->is_enabled()) {
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100446#ifdef ENABLE_SYSMODSP
447 if ((info_ind->flags &
448 PCU_IF_FLAG_SYSMO))
449 l1if_connect_pdch(
450 bts->trx[trx].fl1h, ts);
451#endif
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400452 pcu_tx_act_req(trx, ts, 1);
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200453 pdch->enable();
Andreas Eversberg3b7461c2012-07-20 11:19:59 +0200454 }
Andreas Eversberg2b914642012-07-19 13:06:26 +0200455 pdch->tsc = info_ind->trx[trx].tsc[ts];
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400456 LOGP(DL1IF, LOGL_INFO, "PDCH: trx=%d ts=%d\n",
457 trx, ts);
458 } else {
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200459 if (pdch->is_enabled()) {
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400460 pcu_tx_act_req(trx, ts, 0);
Holger Hans Peter Freyther09ef27a2013-10-20 16:37:05 +0200461 pdch->free_resources();
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200462 pdch->disable();
Andreas Eversberg3b7461c2012-07-20 11:19:59 +0200463 }
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400464 }
465 }
466 }
467
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200468 return rc;
469}
470
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400471static int pcu_rx_time_ind(struct gsm_pcu_if_time_ind *time_ind)
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200472{
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400473 uint8_t fn13 = time_ind->fn % 13;
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200474
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400475 /* omit frame numbers not starting at a MAC block */
476 if (fn13 != 0 && fn13 != 4 && fn13 != 8)
477 return 0;
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100478#warning uncomment
479// LOGP(DL1IF, LOGL_DEBUG, "Time indication received: %d\n",
480// time_ind->fn % 52);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400481
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200482 BTS::main_bts()->set_current_frame_number(time_ind->fn);
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200483 return 0;
484}
485
Andreas Eversberg2b914642012-07-19 13:06:26 +0200486static int pcu_rx_pag_req(struct gsm_pcu_if_pag_req *pag_req)
487{
488 LOGP(DL1IF, LOGL_DEBUG, "Paging request received: chan_needed=%d "
489 "length=%d\n", pag_req->chan_needed, pag_req->identity_lv[0]);
490
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200491 return BTS::main_bts()->add_paging(pag_req->chan_needed,
Andreas Eversberg2b914642012-07-19 13:06:26 +0200492 pag_req->identity_lv);
493}
494
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400495int pcu_rx(uint8_t msg_type, struct gsm_pcu_if *pcu_prim)
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200496{
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400497 int rc = 0;
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200498
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400499 switch (msg_type) {
500 case PCU_IF_MSG_DATA_IND:
501 rc = pcu_rx_data_ind(&pcu_prim->u.data_ind);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400502 break;
Andreas Eversberga9be1542012-09-27 09:23:24 +0200503 case PCU_IF_MSG_DATA_CNF:
504 rc = pcu_rx_data_cnf(&pcu_prim->u.data_cnf);
505 break;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400506 case PCU_IF_MSG_RTS_REQ:
507 rc = pcu_rx_rts_req(&pcu_prim->u.rts_req);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400508 break;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400509 case PCU_IF_MSG_RACH_IND:
510 rc = pcu_rx_rach_ind(&pcu_prim->u.rach_ind);
511 break;
512 case PCU_IF_MSG_INFO_IND:
513 rc = pcu_rx_info_ind(&pcu_prim->u.info_ind);
514 break;
515 case PCU_IF_MSG_TIME_IND:
516 rc = pcu_rx_time_ind(&pcu_prim->u.time_ind);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400517 break;
Andreas Eversberg2b914642012-07-19 13:06:26 +0200518 case PCU_IF_MSG_PAG_REQ:
519 rc = pcu_rx_pag_req(&pcu_prim->u.pag_req);
520 break;
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400521 default:
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400522 LOGP(DL1IF, LOGL_ERROR, "Received unknwon PCU msg type %d\n",
523 msg_type);
524 rc = -EINVAL;
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200525 }
526
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400527 return rc;
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200528}