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> |
| 28 | |
| 29 | #include "bscconfig.h" |
| 30 | |
Pau Espin Pedrol | 02514bc | 2019-08-30 16:14:22 +0200 | [diff] [blame] | 31 | #include <osmocom/sgsn/gprs_mm_state_gb_fsm.h> |
Pau Espin Pedrol | 8333ef1 | 2019-08-29 19:26:12 +0200 | [diff] [blame] | 32 | #include <osmocom/sgsn/gprs_sgsn.h> |
| 33 | #include <osmocom/sgsn/gprs_gmm.h> |
| 34 | #include <osmocom/sgsn/debug.h> |
| 35 | |
Pau Espin Pedrol | 8333ef1 | 2019-08-29 19:26:12 +0200 | [diff] [blame] | 36 | /* Main entry point for incoming 04.08 GPRS messages from Gb */ |
| 37 | int gsm0408_gprs_rcvmsg_gb(struct msgb *msg, struct gprs_llc_llme *llme, |
| 38 | bool drop_cipherable) |
| 39 | { |
| 40 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
| 41 | uint8_t pdisc = gsm48_hdr_pdisc(gh); |
| 42 | struct sgsn_mm_ctx *mmctx; |
| 43 | struct gprs_ra_id ra_id; |
| 44 | int rc = -EINVAL; |
| 45 | |
| 46 | bssgp_parse_cell_id(&ra_id, msgb_bcid(msg)); |
| 47 | mmctx = sgsn_mm_ctx_by_tlli(msgb_tlli(msg), &ra_id); |
| 48 | if (mmctx) { |
| 49 | msgid2mmctx(mmctx, msg); |
| 50 | rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_PKTS_SIG_IN]); |
| 51 | mmctx->gb.llme = llme; |
Pau Espin Pedrol | 02514bc | 2019-08-30 16:14:22 +0200 | [diff] [blame] | 52 | osmo_fsm_inst_dispatch(mmctx->gb.mm_state_fsm, E_MM_PDU_RECEPTION, NULL); |
Pau Espin Pedrol | 8333ef1 | 2019-08-29 19:26:12 +0200 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /* MMCTX can be NULL */ |
| 56 | |
Pau Espin Pedrol | 8333ef1 | 2019-08-29 19:26:12 +0200 | [diff] [blame] | 57 | switch (pdisc) { |
| 58 | case GSM48_PDISC_MM_GPRS: |
| 59 | rc = gsm0408_rcv_gmm(mmctx, msg, llme, drop_cipherable); |
| 60 | break; |
| 61 | case GSM48_PDISC_SM_GPRS: |
| 62 | rc = gsm0408_rcv_gsm(mmctx, msg, llme); |
| 63 | break; |
| 64 | default: |
| 65 | LOGMMCTXP(LOGL_NOTICE, mmctx, |
| 66 | "Unknown GSM 04.08 discriminator 0x%02x: %s\n", |
| 67 | pdisc, osmo_hexdump((uint8_t *)gh, msgb_l3len(msg))); |
| 68 | /* FIXME: return status message */ |
| 69 | break; |
| 70 | } |
| 71 | |
| 72 | /* MMCTX can be invalid */ |
| 73 | |
| 74 | return rc; |
| 75 | } |