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> |
Pau Espin Pedrol | 35f0e66 | 2019-09-02 18:27:27 +0200 | [diff] [blame] | 34 | #include <osmocom/sgsn/gprs_sm.h> |
Pau Espin Pedrol | 8333ef1 | 2019-08-29 19:26:12 +0200 | [diff] [blame] | 35 | #include <osmocom/sgsn/debug.h> |
| 36 | |
Alexander Couzens | a8f7825 | 2019-09-16 02:44:58 +0200 | [diff] [blame] | 37 | /* Has to be called whenever any PDU (signaling, data, ...) has been received */ |
| 38 | void gprs_gb_recv_pdu(struct sgsn_mm_ctx *mmctx) { |
| 39 | if (mmctx->gb.llme) |
| 40 | osmo_fsm_inst_dispatch(mmctx->gb.mm_state_fsm, E_MM_PDU_RECEPTION, NULL); |
| 41 | } |
| 42 | |
Pau Espin Pedrol | 8333ef1 | 2019-08-29 19:26:12 +0200 | [diff] [blame] | 43 | /* Main entry point for incoming 04.08 GPRS messages from Gb */ |
| 44 | int gsm0408_gprs_rcvmsg_gb(struct msgb *msg, struct gprs_llc_llme *llme, |
| 45 | bool drop_cipherable) |
| 46 | { |
| 47 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg); |
| 48 | uint8_t pdisc = gsm48_hdr_pdisc(gh); |
| 49 | struct sgsn_mm_ctx *mmctx; |
| 50 | struct gprs_ra_id ra_id; |
| 51 | int rc = -EINVAL; |
| 52 | |
| 53 | bssgp_parse_cell_id(&ra_id, msgb_bcid(msg)); |
| 54 | mmctx = sgsn_mm_ctx_by_tlli(msgb_tlli(msg), &ra_id); |
| 55 | if (mmctx) { |
| 56 | msgid2mmctx(mmctx, msg); |
| 57 | rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_PKTS_SIG_IN]); |
| 58 | mmctx->gb.llme = llme; |
Alexander Couzens | a8f7825 | 2019-09-16 02:44:58 +0200 | [diff] [blame] | 59 | gprs_gb_recv_pdu(mmctx); |
Pau Espin Pedrol | 8333ef1 | 2019-08-29 19:26:12 +0200 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /* MMCTX can be NULL */ |
| 63 | |
Pau Espin Pedrol | 8333ef1 | 2019-08-29 19:26:12 +0200 | [diff] [blame] | 64 | switch (pdisc) { |
| 65 | case GSM48_PDISC_MM_GPRS: |
| 66 | rc = gsm0408_rcv_gmm(mmctx, msg, llme, drop_cipherable); |
| 67 | break; |
| 68 | case GSM48_PDISC_SM_GPRS: |
| 69 | rc = gsm0408_rcv_gsm(mmctx, msg, llme); |
| 70 | break; |
| 71 | default: |
| 72 | LOGMMCTXP(LOGL_NOTICE, mmctx, |
| 73 | "Unknown GSM 04.08 discriminator 0x%02x: %s\n", |
| 74 | pdisc, osmo_hexdump((uint8_t *)gh, msgb_l3len(msg))); |
| 75 | /* FIXME: return status message */ |
| 76 | break; |
| 77 | } |
| 78 | |
| 79 | /* MMCTX can be invalid */ |
| 80 | |
| 81 | return rc; |
| 82 | } |
Alexander Couzens | 030824e | 2019-09-17 01:43:50 +0200 | [diff] [blame^] | 83 | |
| 84 | |
| 85 | int gprs_gb_page_ps_ra(struct sgsn_mm_ctx *mmctx) |
| 86 | { |
| 87 | struct bssgp_paging_info pinfo; |
| 88 | int rc; |
| 89 | |
| 90 | /* FIXME: page whole routing area, not only the last known cell */ |
| 91 | |
| 92 | /* initiate PS PAGING procedure */ |
| 93 | memset(&pinfo, 0, sizeof(pinfo)); |
| 94 | pinfo.mode = BSSGP_PAGING_PS; |
| 95 | pinfo.scope = BSSGP_PAGING_BVCI; |
| 96 | pinfo.bvci = mmctx->gb.bvci; |
| 97 | pinfo.imsi = mmctx->imsi; |
| 98 | pinfo.ptmsi = &mmctx->p_tmsi; |
| 99 | pinfo.drx_params = mmctx->drx_parms; |
| 100 | pinfo.qos[0] = 0; // FIXME |
| 101 | rc = bssgp_tx_paging(mmctx->gb.nsei, 0, &pinfo); |
| 102 | rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_PAGING_PS]); |
| 103 | |
| 104 | return rc; |
| 105 | } |