Skip to content

Commit

Permalink
move gsm48_gmm_att_tlvdef into gprs_gmm_util
Browse files Browse the repository at this point in the history
The gprs_gmm.c is huge. Move message parsing into gprs_gmm_util.c.

Change-Id: I67dcdb986fd01dc093501d324b5c376246a5d30d
  • Loading branch information
lynxis committed Oct 22, 2024
1 parent 72283a1 commit 8a2ed97
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 23 deletions.
1 change: 1 addition & 0 deletions include/osmocom/sgsn/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ noinst_HEADERS = \
gprs_gmm.h \
gprs_gmm_fsm.h \
gprs_gmm_attach.h \
gprs_gmm_util.h \
gprs_mm_state_gb_fsm.h \
gprs_mm_state_iu_fsm.h \
gprs_ns.h \
Expand Down
5 changes: 5 additions & 0 deletions include/osmocom/sgsn/gprs_gmm_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <osmocom/gsm/tlv.h>

extern const struct tlv_definition gsm48_gmm_ie_tlvdef;
1 change: 1 addition & 0 deletions src/sgsn/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ osmo_sgsn_SOURCES = \
gprs_gmm_attach.c \
gprs_gmm.c \
gprs_gmm_fsm.c \
gprs_gmm_util.c \
gprs_mm_state_gb_fsm.c \
gprs_ns.c \
gprs_routing_area.c \
Expand Down
28 changes: 5 additions & 23 deletions src/sgsn/gprs_gmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,12 @@
#include <osmocom/sgsn/gprs_sm.h>
#include <osmocom/sgsn/gtp.h>
#include <osmocom/sgsn/pdpctx.h>
#include <osmocom/sgsn/gprs_gmm_util.h>

#include <pdp.h>

#define PTMSI_ALLOC

static const struct tlv_definition gsm48_gmm_att_tlvdef = {
.def = {
[GSM48_IE_GMM_CIPH_CKSN] = { TLV_TYPE_SINGLE_TV, 1 },
[GSM48_IE_GMM_TIMER_READY] = { TLV_TYPE_TV, 1 },
[GSM48_IE_GMM_ALLOC_PTMSI] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_PTMSI_SIG] = { TLV_TYPE_FIXED, 3 },
[GSM48_IE_GMM_AUTH_RAND] = { TLV_TYPE_FIXED, 16 },
[GSM48_IE_GMM_AUTH_SRES] = { TLV_TYPE_FIXED, 4 },
[GSM48_IE_GMM_AUTH_RES_EXT] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_AUTH_FAIL_PAR] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_IMEISV] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_RX_NPDU_NUM_LIST] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_DRX_PARAM] = { TLV_TYPE_FIXED, 2 },
[GSM48_IE_GMM_MS_NET_CAPA] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_PDP_CTX_STATUS] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_PS_LCS_CAPA] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_GMM_MBMS_CTX_ST] = { TLV_TYPE_TLV, 0 },
},
};

/* Our implementation, should be kept in SGSN */

Expand Down Expand Up @@ -635,7 +617,7 @@ static int gsm48_rx_gmm_auth_ciph_resp(struct sgsn_mm_ctx *ctx,
/* Stop T3360 */
mmctx_timer_stop(ctx, 3360);

tlv_parse(&tp, &gsm48_gmm_att_tlvdef, acr->data,
tlv_parse(&tp, &gsm48_gmm_ie_tlvdef, acr->data,
(msg->data + msg->len) - acr->data, 0, 0);

if (!TLVP_PRESENT(&tp, GSM48_IE_GMM_AUTH_SRES) ||
Expand Down Expand Up @@ -694,7 +676,7 @@ static int gsm48_rx_gmm_auth_ciph_fail(struct sgsn_mm_ctx *ctx,
LOGMMCTXP(LOGL_INFO, ctx, "-> GMM AUTH AND CIPH FAILURE (cause = %s)\n",
get_value_string(gsm48_gmm_cause_names, gmm_cause));

tlv_parse(&tp, &gsm48_gmm_att_tlvdef, gh->data+1, msg->len - 1, 0, 0);
tlv_parse(&tp, &gsm48_gmm_ie_tlvdef, gh->data+1, msg->len - 1, 0, 0);

/* Only if GMM cause is present and the AUTS is provided, we can
* start re-sync procedure */
Expand Down Expand Up @@ -1651,7 +1633,7 @@ static int gsm48_rx_gmm_ra_upd_req(struct sgsn_mm_ctx *mmctx, struct msgb *msg,

/* Optional: Old P-TMSI Signature, Requested READY timer, TMSI Status,
* DRX parameter, MS network capability */
tlv_parse(&tp, &gsm48_gmm_att_tlvdef, cur,
tlv_parse(&tp, &gsm48_gmm_ie_tlvdef, cur,
(msg->data + msg->len) - cur, 0, 0);

switch (upd_type) {
Expand Down Expand Up @@ -1937,7 +1919,7 @@ static int gsm48_rx_gmm_service_req(struct sgsn_mm_ctx *ctx, struct msgb *msg)
LOGPC(DMM, LOGL_INFO, "\n");

/* Optional: PDP context status, MBMS context status, Uplink data status, Device properties */
tlv_parse(&tp, &gsm48_gmm_att_tlvdef, cur, (msg->data + msg->len) - cur, 0, 0);
tlv_parse(&tp, &gsm48_gmm_ie_tlvdef, cur, (msg->data + msg->len) - cur, 0, 0);

switch (mi.type) {
case GSM_MI_TYPE_IMSI:
Expand Down
49 changes: 49 additions & 0 deletions src/sgsn/gprs_gmm_util.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*! \file gprs_bssgp_util.c
* GPRS GMM protocol implementation as per 3GPP TS 24.008 */
/*
* (C) 2009-2015 by Harald Welte <[email protected]>
* (C) 2024 by sysmocom - s.f.m.c. GmbH <[email protected]>
* All Rights Reserved
*
* SPDX-License-Identifier: AGPL-3.0+
*
* Author: Alexander Couzens <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <osmocom/gsm/gsm48.h>
#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
#include <osmocom/gsm/tlv.h>

const struct tlv_definition gsm48_gmm_ie_tlvdef = {
.def = {
[GSM48_IE_GMM_CIPH_CKSN] = { TLV_TYPE_SINGLE_TV, 1 },
[GSM48_IE_GMM_TIMER_READY] = { TLV_TYPE_TV, 1 },
[GSM48_IE_GMM_ALLOC_PTMSI] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_PTMSI_SIG] = { TLV_TYPE_FIXED, 3 },
[GSM48_IE_GMM_AUTH_RAND] = { TLV_TYPE_FIXED, 16 },
[GSM48_IE_GMM_AUTH_SRES] = { TLV_TYPE_FIXED, 4 },
[GSM48_IE_GMM_AUTH_RES_EXT] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_AUTH_FAIL_PAR] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_IMEISV] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_RX_NPDU_NUM_LIST] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_DRX_PARAM] = { TLV_TYPE_FIXED, 2 },
[GSM48_IE_GMM_MS_NET_CAPA] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_PDP_CTX_STATUS] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_PS_LCS_CAPA] = { TLV_TYPE_TLV, 0 },
[GSM48_IE_GMM_GMM_MBMS_CTX_ST] = { TLV_TYPE_TLV, 0 },
},
};

1 change: 1 addition & 0 deletions tests/gprs_routing_area/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ gprs_routing_area_test_LDADD = \
$(top_builddir)/src/sgsn/gprs_gmm_attach.o \
$(top_builddir)/src/sgsn/gprs_gmm.o \
$(top_builddir)/src/sgsn/gprs_gmm_fsm.o \
$(top_builddir)/src/sgsn/gprs_gmm_util.o \
$(top_builddir)/src/sgsn/gprs_mm_state_gb_fsm.o \
$(top_builddir)/src/sgsn/gprs_routing_area.o \
$(top_builddir)/src/sgsn/gtp_ggsn.o \
Expand Down
1 change: 1 addition & 0 deletions tests/sgsn/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ sgsn_test_LDADD = \
$(top_builddir)/src/sgsn/gprs_gmm_attach.o \
$(top_builddir)/src/sgsn/gprs_gmm.o \
$(top_builddir)/src/sgsn/gprs_gmm_fsm.o \
$(top_builddir)/src/sgsn/gprs_gmm_util.o \
$(top_builddir)/src/sgsn/gprs_mm_state_gb_fsm.o \
$(top_builddir)/src/sgsn/gprs_routing_area.o \
$(top_builddir)/src/sgsn/gtp_ggsn.o \
Expand Down

0 comments on commit 8a2ed97

Please sign in to comment.