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 | |
| 31 | #include <osmocom/sgsn/gprs_sgsn.h> |
| 32 | #include <osmocom/sgsn/gprs_gmm.h> |
| 33 | #include <osmocom/sgsn/debug.h> |
| 34 | |
| 35 | /* Update the MM context state */ |
| 36 | static void gsm0408_gprs_notify_pdu_gb(struct sgsn_mm_ctx *mmctx) |
| 37 | { |
| 38 | switch (mmctx->pmm_state) { |
| 39 | case MM_STANDBY: |
| 40 | mmctx_set_mm_state(mmctx, MM_READY); |
| 41 | break; |
| 42 | case MM_READY: /* RE-arm the timer upon receival of Gb PDUs */ |
| 43 | mmctx_state_timer_start(mmctx, 3314); |
| 44 | break; |
| 45 | default: |
| 46 | break; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | /* Main entry point for incoming 04.08 GPRS messages from Gb */ |
| 51 | int gsm0408_gprs_rcvmsg_gb(struct msgb *msg, struct gprs_llc_llme *llme, |
| 52 | bool drop_cipherable) |
| 53 | { |
| 54 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
| 55 | uint8_t pdisc = gsm48_hdr_pdisc(gh); |
| 56 | struct sgsn_mm_ctx *mmctx; |
| 57 | struct gprs_ra_id ra_id; |
| 58 | int rc = -EINVAL; |
| 59 | |
| 60 | bssgp_parse_cell_id(&ra_id, msgb_bcid(msg)); |
| 61 | mmctx = sgsn_mm_ctx_by_tlli(msgb_tlli(msg), &ra_id); |
| 62 | if (mmctx) { |
| 63 | msgid2mmctx(mmctx, msg); |
| 64 | rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_PKTS_SIG_IN]); |
| 65 | mmctx->gb.llme = llme; |
| 66 | } |
| 67 | |
| 68 | /* MMCTX can be NULL */ |
| 69 | |
| 70 | if (mmctx) |
| 71 | gsm0408_gprs_notify_pdu_gb(mmctx); |
| 72 | |
| 73 | switch (pdisc) { |
| 74 | case GSM48_PDISC_MM_GPRS: |
| 75 | rc = gsm0408_rcv_gmm(mmctx, msg, llme, drop_cipherable); |
| 76 | break; |
| 77 | case GSM48_PDISC_SM_GPRS: |
| 78 | rc = gsm0408_rcv_gsm(mmctx, msg, llme); |
| 79 | break; |
| 80 | default: |
| 81 | LOGMMCTXP(LOGL_NOTICE, mmctx, |
| 82 | "Unknown GSM 04.08 discriminator 0x%02x: %s\n", |
| 83 | pdisc, osmo_hexdump((uint8_t *)gh, msgb_l3len(msg))); |
| 84 | /* FIXME: return status message */ |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | /* MMCTX can be invalid */ |
| 89 | |
| 90 | return rc; |
| 91 | } |