Pau Espin Pedrol | 8333ef1 | 2019-08-29 19:26:12 +0200 | [diff] [blame] | 1 | /* 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 Couzens | f23e2db | 2020-07-27 22:39:58 +0200 | [diff] [blame] | 28 | #include <osmocom/gprs/gprs_ns2.h> |
| 29 | #include <osmocom/gprs/gprs_bssgp_bss.h> |
| 30 | #include <osmocom/sgsn/gprs_llc.h> |
Pau Espin Pedrol | 8333ef1 | 2019-08-29 19:26:12 +0200 | [diff] [blame] | 31 | |
| 32 | #include "bscconfig.h" |
| 33 | |
| 34 | #include <osmocom/sgsn/gprs_sgsn.h> |
Pau Espin Pedrol | 8333ef1 | 2019-08-29 19:26:12 +0200 | [diff] [blame] | 35 | #include <osmocom/sgsn/debug.h> |
| 36 | |
Alexander Couzens | f23e2db | 2020-07-27 22:39:58 +0200 | [diff] [blame] | 37 | void gprs_ns_prim_status_cb(struct osmo_gprs_ns2_prim *nsp) |
| 38 | { |
| 39 | switch (nsp->u.status.cause) { |
Alexander Couzens | 21afdf9 | 2021-01-27 20:56:55 +0100 | [diff] [blame] | 40 | case GPRS_NS2_AFF_CAUSE_SNS_CONFIGURED: |
Alexander Couzens | f23e2db | 2020-07-27 22:39:58 +0200 | [diff] [blame] | 41 | LOGP(DGPRS, LOGL_NOTICE, "NS-E %d SNS configured.\n", nsp->nsei); |
| 42 | break; |
Alexander Couzens | 21afdf9 | 2021-01-27 20:56:55 +0100 | [diff] [blame] | 43 | case GPRS_NS2_AFF_CAUSE_RECOVERY: |
Alexander Couzens | f23e2db | 2020-07-27 22:39:58 +0200 | [diff] [blame] | 44 | 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 Couzens | 21afdf9 | 2021-01-27 20:56:55 +0100 | [diff] [blame] | 54 | case GPRS_NS2_AFF_CAUSE_FAILURE: |
Alexander Couzens | f23e2db | 2020-07-27 22:39:58 +0200 | [diff] [blame] | 55 | 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 */ |
| 65 | int 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 Couzens | 21afdf9 | 2021-01-27 20:56:55 +0100 | [diff] [blame] | 83 | case GPRS_NS2_PRIM_UNIT_DATA: |
Alexander Couzens | f23e2db | 2020-07-27 22:39:58 +0200 | [diff] [blame] | 84 | /* 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 Couzens | 21afdf9 | 2021-01-27 20:56:55 +0100 | [diff] [blame] | 91 | case GPRS_NS2_PRIM_STATUS: |
Alexander Couzens | f23e2db | 2020-07-27 22:39:58 +0200 | [diff] [blame] | 92 | 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 | } |