blob: b6769179124e7ee3799c3f01ae088044866ba0fa [file] [log] [blame]
Pau Espin Pedrol8333ef12019-08-29 19:26:12 +02001/* Messages on the Gb interface (A/Gb mode) */
2
3/* (C) 2009-2015 by Harald Welte <laforge@gnumonks.org>
4 * (C) 2010 by On-Waves
5 * (C) 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
6 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24#include <osmocom/core/rate_ctr.h>
25
26#include <osmocom/gprs/gprs_msgb.h>
27#include <osmocom/gprs/gprs_bssgp.h>
Alexander Couzensf23e2db2020-07-27 22:39:58 +020028#include <osmocom/gprs/gprs_ns2.h>
29#include <osmocom/gprs/gprs_bssgp_bss.h>
30#include <osmocom/sgsn/gprs_llc.h>
Pau Espin Pedrol8333ef12019-08-29 19:26:12 +020031
32#include "bscconfig.h"
33
34#include <osmocom/sgsn/gprs_sgsn.h>
Pau Espin Pedrol8333ef12019-08-29 19:26:12 +020035#include <osmocom/sgsn/debug.h>
36
Alexander Couzensf23e2db2020-07-27 22:39:58 +020037void gprs_ns_prim_status_cb(struct osmo_gprs_ns2_prim *nsp)
38{
39 switch (nsp->u.status.cause) {
Alexander Couzens21afdf92021-01-27 20:56:55 +010040 case GPRS_NS2_AFF_CAUSE_SNS_CONFIGURED:
Alexander Couzensf23e2db2020-07-27 22:39:58 +020041 LOGP(DGPRS, LOGL_NOTICE, "NS-E %d SNS configured.\n", nsp->nsei);
42 break;
Alexander Couzens21afdf92021-01-27 20:56:55 +010043 case GPRS_NS2_AFF_CAUSE_RECOVERY:
Alexander Couzensf23e2db2020-07-27 22:39:58 +020044 LOGP(DGPRS, LOGL_NOTICE, "NS-E %d became available\n", nsp->nsei);
45 /* workaround for broken BSS which doesn't respond correct to BSSGP status message.
46 * Sent a BSSGP Reset when a persistent NSVC comes up for the first time. */
47 if (nsp->u.status.first && nsp->u.status.persistent) {
48 struct bssgp_bvc_ctx bctx = {
49 .nsei = nsp->nsei,
50 };
51 bssgp_tx_bvc_reset2(&bctx, BVCI_SIGNALLING, BSSGP_CAUSE_EQUIP_FAIL, false);
52 }
53 break;
Alexander Couzens21afdf92021-01-27 20:56:55 +010054 case GPRS_NS2_AFF_CAUSE_FAILURE:
Alexander Couzensf23e2db2020-07-27 22:39:58 +020055 LOGP(DGPRS, LOGL_NOTICE, "NS-E %d became unavailable\n", nsp->nsei);
56 break;
57 default:
58 LOGP(DGPRS, LOGL_NOTICE, "NS: %s Unknown prim %d from NS\n",
59 get_value_string(osmo_prim_op_names, nsp->oph.operation), nsp->oph.primitive);
60 break;
61 }
62}
63
64/* call-back function for the NS protocol */
65int gprs_ns_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
66{
67 struct osmo_gprs_ns2_prim *nsp;
68 int rc = 0;
69
70 if (oph->sap != SAP_NS)
71 return 0;
72
73 nsp = container_of(oph, struct osmo_gprs_ns2_prim, oph);
74
75 if (oph->operation != PRIM_OP_INDICATION) {
76 LOGP(DGPRS, LOGL_NOTICE, "NS: %s Unknown prim %d from NS\n",
77 get_value_string(osmo_prim_op_names, oph->operation),
78 oph->operation);
79 return 0;
80 }
81
82 switch (oph->primitive) {
Alexander Couzens21afdf92021-01-27 20:56:55 +010083 case GPRS_NS2_PRIM_UNIT_DATA:
Alexander Couzensf23e2db2020-07-27 22:39:58 +020084 /* hand the message into the BSSGP implementation */
85 /* add required msg fields for Gb layer */
86 msgb_bssgph(oph->msg) = oph->msg->l3h;
87 msgb_bvci(oph->msg) = nsp->bvci;
88 msgb_nsei(oph->msg) = nsp->nsei;
89 rc = bssgp_rcvmsg(oph->msg);
90 break;
Alexander Couzens21afdf92021-01-27 20:56:55 +010091 case GPRS_NS2_PRIM_STATUS:
Alexander Couzensf23e2db2020-07-27 22:39:58 +020092 gprs_ns_prim_status_cb(nsp);
93 break;
94 default:
95 LOGP(DGPRS, LOGL_NOTICE, "NS: %s Unknown prim %d from NS\n",
96 get_value_string(osmo_prim_op_names, oph->operation), oph->primitive);
97 break;
98 }
99
100 if (oph->msg)
101 msgb_free(oph->msg);
102
103 return rc;
104}