blob: b2bc425e9ad71b74e6d869c71a3f5fdc949d2f69 [file] [log] [blame]
Philipp Maierb4999b62016-10-26 15:19:41 +02001/* pcu_sock.c: Connect from PCU via unix domain socket */
2
3/* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
4 * (C) 2009-2012 by Andreas Eversberg <jolly@eversberg.eu>
5 * (C) 2012 by Holger Hans Peter Freyther
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#include <stdio.h>
25#include <unistd.h>
26#include <stdlib.h>
27#include <string.h>
28#include <errno.h>
29#include <assert.h>
30#include <sys/socket.h>
31#include <sys/un.h>
32
33#include <osmocom/core/talloc.h>
34#include <osmocom/core/select.h>
35#include <osmocom/core/socket.h>
36#include <osmocom/core/logging.h>
37#include <osmocom/gsm/l1sap.h>
38#include <osmocom/gsm/gsm0502.h>
39
40#include <openbsc/gsm_data.h>
41#include <openbsc/pcu_if.h>
42#include <openbsc/pcuif_proto.h>
43#include <openbsc/signal.h>
44#include <openbsc/debug.h>
45#include <openbsc/abis_rsl.h>
46
47static int pcu_sock_send(struct gsm_bts *bts, struct msgb *msg);
48uint32_t trx_get_hlayer1(struct gsm_bts_trx *trx);
49int pcu_direct = 0;
50
51static const char *sapi_string[] = {
52 [PCU_IF_SAPI_RACH] = "RACH",
53 [PCU_IF_SAPI_AGCH] = "AGCH",
54 [PCU_IF_SAPI_PCH] = "PCH",
55 [PCU_IF_SAPI_BCCH] = "BCCH",
56 [PCU_IF_SAPI_PDTCH] = "PDTCH",
57 [PCU_IF_SAPI_PRACH] = "PRACH",
58 [PCU_IF_SAPI_PTCCH] = "PTCCH",
59};
60
61static struct gsm_bts_trx *trx_by_nr(struct gsm_bts *bts, uint8_t trx_nr)
62{
63 struct gsm_bts_trx *trx;
64
65 llist_for_each_entry(trx, &bts->trx_list, list) {
66 if (trx->nr == trx_nr)
67 return trx;
68 }
69
70 return NULL;
71}
72
73/* Check if BTS has a PCU connection */
74static bool pcu_connected(struct gsm_bts *bts)
75{
76 struct pcu_sock_state *state = bts->pcu_state;
77
78 if (!state)
79 return false;
80 if (state->conn_bfd.fd <= 0)
81 return false;
82 return true;
83}
84
85/*
86 * PCU messages
87 */
88
89/* Set up an message buffer to package an pcu interface message */
90struct msgb *pcu_msgb_alloc(uint8_t msg_type, uint8_t bts_nr)
91{
92 struct msgb *msg;
93 struct gsm_pcu_if *pcu_prim;
94
95 msg = msgb_alloc(sizeof(struct gsm_pcu_if), "pcu_sock_tx");
96 if (!msg)
97 return NULL;
98
99 msgb_put(msg, sizeof(struct gsm_pcu_if));
100 pcu_prim = (struct gsm_pcu_if *) msg->data;
101 pcu_prim->msg_type = msg_type;
102 pcu_prim->bts_nr = bts_nr;
103
104 return msg;
105}
106
107/* Helper function exclusivly used by pcu_if_signal_cb() */
108static bool ts_should_be_pdch(struct gsm_bts_trx_ts *ts) {
109 if (ts->pchan == GSM_PCHAN_PDCH)
110 return true;
111 if (ts->pchan == GSM_PCHAN_TCH_F_PDCH) {
112 /* When we're busy deactivating the PDCH, we first set
113 * DEACT_PENDING, tell the PCU about it and wait for a
114 * response. So DEACT_PENDING means "no PDCH" to the PCU.
115 * Similarly, when we're activating PDCH, we set the
116 * ACT_PENDING and wait for an activation response from the
117 * PCU, so ACT_PENDING means "is PDCH". */
118 if (ts->flags & TS_F_PDCH_ACTIVE)
119 return !(ts->flags & TS_F_PDCH_DEACT_PENDING);
120 else
121 return (ts->flags & TS_F_PDCH_ACT_PENDING);
122 }
123 if (ts->pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH) {
124 /*
125 * When we're busy de-/activating the PDCH, we first set
126 * ts->dyn.pchan_want, tell the PCU about it and wait for a
127 * response. So only care about dyn.pchan_want here.
128 */
129 return ts->dyn.pchan_want == GSM_PCHAN_PDCH;
130 }
131 return false;
132}
133
134/* Send BTS properties to the PCU */
135static int pcu_tx_info_ind(struct gsm_bts *bts)
136{
137 struct msgb *msg;
138 struct gsm_pcu_if *pcu_prim;
139 struct gsm_pcu_if_info_ind *info_ind;
140 struct gprs_rlc_cfg *rlcc;
141 struct gsm_bts_gprs_nsvc *nsvc;
142 struct gsm_bts_trx *trx;
143 struct gsm_bts_trx_ts *ts;
144 int i, j;
145
146 OSMO_ASSERT(bts);
147 OSMO_ASSERT(bts->network);
148
149 LOGP(DPCU, LOGL_INFO, "Sending info for BTS %d\n",bts->nr);
150
151 rlcc = &bts->gprs.cell.rlc_cfg;
152
153 msg = pcu_msgb_alloc(PCU_IF_MSG_INFO_IND, bts->nr);
154 if (!msg)
155 return -ENOMEM;
156
157 pcu_prim = (struct gsm_pcu_if *) msg->data;
158 info_ind = &pcu_prim->u.info_ind;
159 info_ind->version = PCU_IF_VERSION;
160 info_ind->flags |= PCU_IF_FLAG_ACTIVE;
161
162 if (pcu_direct)
163 info_ind->flags |= PCU_IF_FLAG_SYSMO;
164
165 /* RAI */
166 info_ind->mcc = bts->network->country_code;
167 info_ind->mnc = bts->network->network_code;
168 info_ind->lac = bts->location_area_code;
169 info_ind->rac = bts->gprs.rac;
170
171 /* NSE */
172 info_ind->nsei = bts->gprs.nse.nsei;
173 memcpy(info_ind->nse_timer, bts->gprs.nse.timer, 7);
174 memcpy(info_ind->cell_timer, bts->gprs.cell.timer, 11);
175
176 /* cell attributes */
177 info_ind->cell_id = bts->cell_identity;
178 info_ind->repeat_time = rlcc->paging.repeat_time;
179 info_ind->repeat_count = rlcc->paging.repeat_count;
180 info_ind->bvci = bts->gprs.cell.bvci;
181 info_ind->t3142 = rlcc->parameter[RLC_T3142];
182 info_ind->t3169 = rlcc->parameter[RLC_T3169];
183 info_ind->t3191 = rlcc->parameter[RLC_T3191];
184 info_ind->t3193_10ms = rlcc->parameter[RLC_T3193];
185 info_ind->t3195 = rlcc->parameter[RLC_T3195];
186 info_ind->n3101 = rlcc->parameter[RLC_N3101];
187 info_ind->n3103 = rlcc->parameter[RLC_N3103];
188 info_ind->n3105 = rlcc->parameter[RLC_N3105];
189 info_ind->cv_countdown = rlcc->parameter[CV_COUNTDOWN];
190 if (rlcc->cs_mask & (1 << GPRS_CS1))
191 info_ind->flags |= PCU_IF_FLAG_CS1;
192 if (rlcc->cs_mask & (1 << GPRS_CS2))
193 info_ind->flags |= PCU_IF_FLAG_CS2;
194 if (rlcc->cs_mask & (1 << GPRS_CS3))
195 info_ind->flags |= PCU_IF_FLAG_CS3;
196 if (rlcc->cs_mask & (1 << GPRS_CS4))
197 info_ind->flags |= PCU_IF_FLAG_CS4;
198 if (bts->gprs.mode == BTS_GPRS_EGPRS) {
199 if (rlcc->cs_mask & (1 << GPRS_MCS1))
200 info_ind->flags |= PCU_IF_FLAG_MCS1;
201 if (rlcc->cs_mask & (1 << GPRS_MCS2))
202 info_ind->flags |= PCU_IF_FLAG_MCS2;
203 if (rlcc->cs_mask & (1 << GPRS_MCS3))
204 info_ind->flags |= PCU_IF_FLAG_MCS3;
205 if (rlcc->cs_mask & (1 << GPRS_MCS4))
206 info_ind->flags |= PCU_IF_FLAG_MCS4;
207 if (rlcc->cs_mask & (1 << GPRS_MCS5))
208 info_ind->flags |= PCU_IF_FLAG_MCS5;
209 if (rlcc->cs_mask & (1 << GPRS_MCS6))
210 info_ind->flags |= PCU_IF_FLAG_MCS6;
211 if (rlcc->cs_mask & (1 << GPRS_MCS7))
212 info_ind->flags |= PCU_IF_FLAG_MCS7;
213 if (rlcc->cs_mask & (1 << GPRS_MCS8))
214 info_ind->flags |= PCU_IF_FLAG_MCS8;
215 if (rlcc->cs_mask & (1 << GPRS_MCS9))
216 info_ind->flags |= PCU_IF_FLAG_MCS9;
217 }
218#warning "isn't dl_tbf_ext wrong?: * 10 and no ntohs"
219 info_ind->dl_tbf_ext = rlcc->parameter[T_DL_TBF_EXT];
220#warning "isn't ul_tbf_ext wrong?: * 10 and no ntohs"
221 info_ind->ul_tbf_ext = rlcc->parameter[T_UL_TBF_EXT];
222 info_ind->initial_cs = rlcc->initial_cs;
223 info_ind->initial_mcs = rlcc->initial_mcs;
224
225 /* NSVC */
226 for (i = 0; i < 2; i++) {
227 nsvc = &bts->gprs.nsvc[i];
228 info_ind->nsvci[i] = nsvc->nsvci;
229 info_ind->local_port[i] = nsvc->local_port;
230 info_ind->remote_port[i] = nsvc->remote_port;
231 info_ind->remote_ip[i] = nsvc->remote_ip;
232 }
233
234 for (i = 0; i < 8; i++) {
235 trx = trx_by_nr(bts, i);
236 if (!trx)
237 break;
238 info_ind->trx[i].pdch_mask = 0;
239 info_ind->trx[i].arfcn = trx->arfcn;
240 for (j = 0; j < 8; j++) {
241 ts = &trx->ts[j];
242 if (ts->mo.nm_state.operational == NM_OPSTATE_ENABLED
243 && ts_should_be_pdch(ts)) {
244 info_ind->trx[i].pdch_mask |= (1 << j);
245 info_ind->trx[i].tsc[j] =
246 (ts->tsc >= 0) ? ts->tsc : bts->bsic & 7;
247 LOGP(DPCU, LOGL_INFO, "trx=%d ts=%d: "
248 "available (tsc=%d arfcn=%d)\n",
249 trx->nr, ts->nr,
250 info_ind->trx[i].tsc[j],
251 info_ind->trx[i].arfcn);
252 }
253 }
254 }
255
256 return pcu_sock_send(bts, msg);
257}
258
259void pcu_info_update(struct gsm_bts *bts)
260{
261 if (pcu_connected(bts))
262 pcu_tx_info_ind(bts);
263}
264
265/* Forward rach indication to PCU */
266int pcu_tx_rach_ind(struct gsm_bts *bts, int16_t qta, uint16_t ra, uint32_t fn,
267 uint8_t is_11bit, enum ph_burst_type burst_type)
268{
269 struct msgb *msg;
270 struct gsm_pcu_if *pcu_prim;
271 struct gsm_pcu_if_rach_ind *rach_ind;
272
273 /* Bail if no PCU is connected */
274 if (!pcu_connected(bts)) {
275 LOGP(DRSL, LOGL_ERROR, "BTS %d CHAN RQD(GPRS) but PCU not "
276 "connected!\n", bts->nr);
277 return -ENODEV;
278 }
279
280 LOGP(DPCU, LOGL_INFO, "Sending RACH indication: qta=%d, ra=%d, "
281 "fn=%d\n", qta, ra, fn);
282
283 msg = pcu_msgb_alloc(PCU_IF_MSG_RACH_IND, bts->nr);
284 if (!msg)
285 return -ENOMEM;
286 pcu_prim = (struct gsm_pcu_if *) msg->data;
287 rach_ind = &pcu_prim->u.rach_ind;
288
289 rach_ind->sapi = PCU_IF_SAPI_RACH;
290 rach_ind->ra = ra;
291 rach_ind->qta = qta;
292 rach_ind->fn = fn;
293 rach_ind->is_11bit = is_11bit;
294 rach_ind->burst_type = burst_type;
295
296 return pcu_sock_send(bts, msg);
297}
298
299static int pcu_rx_data_req(struct gsm_bts *bts, uint8_t msg_type,
300 struct gsm_pcu_if_data *data_req)
301{
302 uint8_t is_ptcch;
303 struct gsm_bts_trx *trx;
304 struct gsm_bts_trx_ts *ts;
305 struct msgb *msg;
306 int rc = 0;
307
308 LOGP(DPCU, LOGL_DEBUG, "Data request received: sapi=%s arfcn=%d "
309 "block=%d data=%s\n", sapi_string[data_req->sapi],
310 data_req->arfcn, data_req->block_nr,
311 osmo_hexdump(data_req->data, data_req->len));
312
313 switch (data_req->sapi) {
314 case PCU_IF_SAPI_PCH:
315 if (msg_type == PCU_IF_MSG_PAG_REQ) {
316 /* FIXME: Add function to schedule paging request.
317 * This might not be required, if PCU_IF_MSG_DATA_REQ
318 * is used instead. */
319 } else {
320 struct gsm_bts_role_bts *btsb = bts->role;
321
322 printf("paging_add_imm_ass(btsb->paging_state, data_req->data,data_req->len);\n");
323 }
324 break;
325 case PCU_IF_SAPI_AGCH:
326 msg = msgb_alloc(data_req->len, "pcu_agch");
327 if (!msg) {
328 rc = -ENOMEM;
329 break;
330 }
331 msg->l3h = msgb_put(msg, data_req->len);
332 memcpy(msg->l3h, data_req->data, data_req->len);
333
334 if (rsl_imm_assign_cmd(bts, msg->len, msg->data)) {
335 msgb_free(msg);
336 rc = -EIO;
337 }
338 break;
339 default:
340 LOGP(DPCU, LOGL_ERROR, "Received PCU data request with "
341 "unsupported sapi %d\n", data_req->sapi);
342 rc = -EINVAL;
343 }
344
345 return rc;
346}
347
348static int pcu_rx(struct gsm_network *net, uint8_t msg_type,
349 struct gsm_pcu_if *pcu_prim)
350{
351 int rc = 0;
352 struct gsm_bts *bts;
353
354 /* FIXME: allow multiple BTS */
355 bts = llist_entry(net->bts_list.next, struct gsm_bts, list);
356
357 switch (msg_type) {
358 case PCU_IF_MSG_DATA_REQ:
359 case PCU_IF_MSG_PAG_REQ:
360 rc = pcu_rx_data_req(bts, msg_type, &pcu_prim->u.data_req);
361 break;
362 default:
363 LOGP(DPCU, LOGL_ERROR, "Received unknwon PCU msg type %d\n",
364 msg_type);
365 rc = -EINVAL;
366 }
367
368 return rc;
369}
370
371/*
372 * PCU socket interface
373 */
374
375static int pcu_sock_send(struct gsm_bts *bts, struct msgb *msg)
376{
377 struct pcu_sock_state *state = bts->pcu_state;
378 struct osmo_fd *conn_bfd;
379 struct gsm_pcu_if *pcu_prim = (struct gsm_pcu_if *) msg->data;
380
381 if (!state) {
382 if (pcu_prim->msg_type != PCU_IF_MSG_TIME_IND)
383 LOGP(DPCU, LOGL_INFO, "PCU socket not created, "
384 "dropping message\n");
385 msgb_free(msg);
386 return -EINVAL;
387 }
388 conn_bfd = &state->conn_bfd;
389 if (conn_bfd->fd <= 0) {
390 if (pcu_prim->msg_type != PCU_IF_MSG_TIME_IND)
391 LOGP(DPCU, LOGL_NOTICE, "PCU socket not connected, "
392 "dropping message\n");
393 msgb_free(msg);
394 return -EIO;
395 }
396 msgb_enqueue(&state->upqueue, msg);
397 conn_bfd->when |= BSC_FD_WRITE;
398
399 return 0;
400}
401
402static void pcu_sock_close(struct pcu_sock_state *state)
403{
404 struct osmo_fd *bfd = &state->conn_bfd;
405 struct gsm_bts *bts;
406 struct gsm_bts_trx *trx;
407 struct gsm_bts_trx_ts *ts;
408 int i, j;
409
410 /* FIXME: allow multiple BTS */
411 bts = llist_entry(state->net->bts_list.next, struct gsm_bts, list);
412
413 LOGP(DPCU, LOGL_NOTICE, "PCU socket has LOST connection\n");
414
415 close(bfd->fd);
416 bfd->fd = -1;
417 osmo_fd_unregister(bfd);
418
419 /* re-enable the generation of ACCEPT for new connections */
420 state->listen_bfd.when |= BSC_FD_READ;
421
422#if 0
423 /* remove si13, ... */
424 bts->si_valid &= ~(1 << SYSINFO_TYPE_13);
425 osmo_signal_dispatch(SS_GLOBAL, S_NEW_SYSINFO, bts);
426#endif
427
428 /* release PDCH */
429 for (i = 0; i < 8; i++) {
430 trx = trx_by_nr(bts, i);
431 if (!trx)
432 break;
433 for (j = 0; j < 8; j++) {
434 ts = &trx->ts[j];
435 if (ts->mo.nm_state.operational == NM_OPSTATE_ENABLED
436 && ts->pchan == GSM_PCHAN_PDCH) {
437 printf("l1sap_chan_rel(trx,gsm_lchan2chan_nr(ts->lchan));\n");
438 }
439 }
440 }
441
442 /* flush the queue */
443 while (!llist_empty(&state->upqueue)) {
444 struct msgb *msg = msgb_dequeue(&state->upqueue);
445 msgb_free(msg);
446 }
447}
448
449static int pcu_sock_read(struct osmo_fd *bfd)
450{
451 struct pcu_sock_state *state = (struct pcu_sock_state *)bfd->data;
452 struct gsm_pcu_if *pcu_prim;
453 struct msgb *msg;
454 int rc;
455
456 msg = msgb_alloc(sizeof(*pcu_prim), "pcu_sock_rx");
457 if (!msg)
458 return -ENOMEM;
459
460 pcu_prim = (struct gsm_pcu_if *) msg->tail;
461
462 rc = recv(bfd->fd, msg->tail, msgb_tailroom(msg), 0);
463 if (rc == 0)
464 goto close;
465
466 if (rc < 0) {
467 if (errno == EAGAIN)
468 return 0;
469 goto close;
470 }
471
472 rc = pcu_rx(state->net, pcu_prim->msg_type, pcu_prim);
473
474 /* as we always synchronously process the message in pcu_rx() and
475 * its callbacks, we can free the message here. */
476 msgb_free(msg);
477
478 return rc;
479
480close:
481 msgb_free(msg);
482 pcu_sock_close(state);
483 return -1;
484}
485
486static int pcu_sock_write(struct osmo_fd *bfd)
487{
488 struct pcu_sock_state *state = bfd->data;
489 int rc;
490
491 while (!llist_empty(&state->upqueue)) {
492 struct msgb *msg, *msg2;
493 struct gsm_pcu_if *pcu_prim;
494
495 /* peek at the beginning of the queue */
496 msg = llist_entry(state->upqueue.next, struct msgb, list);
497 pcu_prim = (struct gsm_pcu_if *)msg->data;
498
499 bfd->when &= ~BSC_FD_WRITE;
500
501 /* bug hunter 8-): maybe someone forgot msgb_put(...) ? */
502 if (!msgb_length(msg)) {
503 LOGP(DPCU, LOGL_ERROR, "message type (%d) with ZERO "
504 "bytes!\n", pcu_prim->msg_type);
505 goto dontsend;
506 }
507
508 /* try to send it over the socket */
509 rc = write(bfd->fd, msgb_data(msg), msgb_length(msg));
510 if (rc == 0)
511 goto close;
512 if (rc < 0) {
513 if (errno == EAGAIN) {
514 bfd->when |= BSC_FD_WRITE;
515 break;
516 }
517 goto close;
518 }
519
520dontsend:
521 /* _after_ we send it, we can deueue */
522 msg2 = msgb_dequeue(&state->upqueue);
523 assert(msg == msg2);
524 msgb_free(msg);
525 }
526 return 0;
527
528close:
529 pcu_sock_close(state);
530
531 return -1;
532}
533
534static int pcu_sock_cb(struct osmo_fd *bfd, unsigned int flags)
535{
536 int rc = 0;
537
538 if (flags & BSC_FD_READ)
539 rc = pcu_sock_read(bfd);
540 if (rc < 0)
541 return rc;
542
543 if (flags & BSC_FD_WRITE)
544 rc = pcu_sock_write(bfd);
545
546 return rc;
547}
548
549/* accept connection comming from PCU */
550static int pcu_sock_accept(struct osmo_fd *bfd, unsigned int flags)
551{
552 struct pcu_sock_state *state = (struct pcu_sock_state *)bfd->data;
553 struct osmo_fd *conn_bfd = &state->conn_bfd;
554 struct sockaddr_un un_addr;
555 socklen_t len;
556 int rc;
557
558 len = sizeof(un_addr);
559 rc = accept(bfd->fd, (struct sockaddr *) &un_addr, &len);
560 if (rc < 0) {
561 LOGP(DPCU, LOGL_ERROR, "Failed to accept a new connection\n");
562 return -1;
563 }
564
565 if (conn_bfd->fd >= 0) {
566 LOGP(DPCU, LOGL_NOTICE, "PCU connects but we already have "
567 "another active connection ?!?\n");
568 /* We already have one PCU connected, this is all we support */
569 state->listen_bfd.when &= ~BSC_FD_READ;
570 close(rc);
571 return 0;
572 }
573
574 conn_bfd->fd = rc;
575 conn_bfd->when = BSC_FD_READ;
576 conn_bfd->cb = pcu_sock_cb;
577 conn_bfd->data = state;
578
579 if (osmo_fd_register(conn_bfd) != 0) {
580 LOGP(DPCU, LOGL_ERROR, "Failed to register new connection "
581 "fd\n");
582 close(conn_bfd->fd);
583 conn_bfd->fd = -1;
584 return -1;
585 }
586
587 LOGP(DPCU, LOGL_NOTICE, "PCU socket connected to external PCU\n");
588
589 return 0;
590}
591
592/* Open connection to PCU */
593int pcu_sock_init(const char *path, struct gsm_bts *bts)
594{
595 struct pcu_sock_state *state;
596 struct osmo_fd *bfd;
597 int rc;
598
599 state = talloc_zero(NULL, struct pcu_sock_state);
600 if (!state)
601 return -ENOMEM;
602
603 INIT_LLIST_HEAD(&state->upqueue);
604 state->net = bts->network;
605 state->conn_bfd.fd = -1;
606
607 bfd = &state->listen_bfd;
608
609 bfd->fd = osmo_sock_unix_init(SOCK_SEQPACKET, 0, path,
610 OSMO_SOCK_F_BIND);
611 if (bfd->fd < 0) {
612 LOGP(DPCU, LOGL_ERROR, "Could not create unix socket: %s\n",
613 strerror(errno));
614 talloc_free(state);
615 return -1;
616 }
617
618 bfd->when = BSC_FD_READ;
619 bfd->cb = pcu_sock_accept;
620 bfd->data = state;
621
622 rc = osmo_fd_register(bfd);
623 if (rc < 0) {
624 LOGP(DPCU, LOGL_ERROR, "Could not register listen fd: %d\n",
625 rc);
626 close(bfd->fd);
627 talloc_free(state);
628 return rc;
629 }
630
631 bts->pcu_state = state;
632 return 0;
633}
634
635/* Close connection to PCU */
636void pcu_sock_exit(struct gsm_bts *bts)
637{
638 struct pcu_sock_state *state = bts->pcu_state;
639 struct osmo_fd *bfd, *conn_bfd;
640
641 if (!state)
642 return;
643
644 conn_bfd = &state->conn_bfd;
645 if (conn_bfd->fd > 0)
646 pcu_sock_close(state);
647 bfd = &state->listen_bfd;
648 close(bfd->fd);
649 osmo_fd_unregister(bfd);
650 talloc_free(state);
651 bts->pcu_state = NULL;
652}
653