From patchwork Mon Mar 14 15:06:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neels Hofmeyr X-Patchwork-Id: 597089 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (lists.osmocom.org [IPv6:2a01:4f8:191:444b::2:7]) by ozlabs.org (Postfix) with ESMTP id 3qP1Mm6ygBz9sCy for ; Tue, 15 Mar 2016 02:08:04 +1100 (AEDT) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 834B61AC1E; Mon, 14 Mar 2016 15:08:03 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from einhorn.in-berlin.de (einhorn.in-berlin.de [IPv6:2001:bf0:c000::1:8]) by lists.osmocom.org (Postfix) with ESMTP id AE9641ABD2 for ; Mon, 14 Mar 2016 15:07:55 +0000 (UTC) X-Envelope-From: nhofmeyr@sysmocom.de X-Envelope-To: Received: from localhost (gw-01.freifunk.isp.faust2k.net [87.128.109.145]) (authenticated bits=0) by einhorn.in-berlin.de (8.14.4/8.14.4/Debian-4) with ESMTP id u2EF7seQ023613 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 14 Mar 2016 16:07:55 +0100 From: Neels Hofmeyr To: openbsc@lists.osmocom.org Subject: [PATCH 1/3] 04.08: add inline funcs for pdisc + msg type bitmasks Date: Mon, 14 Mar 2016 16:06:46 +0100 Message-Id: <1457968008-15769-2-git-send-email-nhofmeyr@sysmocom.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1457968008-15769-1-git-send-email-nhofmeyr@sysmocom.de> References: <1457968008-15769-1-git-send-email-nhofmeyr@sysmocom.de> X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Development of OpenBSC, OsmoBSC, OsmoNITB, OsmoCSCN" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" Add inline functions for both release <= 98 and release >= 99 as well as a default define. Use the release 98 by default since the current code base uses the r98 bitmasks. These inline functions relieve callers of the decision on masking bits of the protocol discriminator and message type octets. Also add a define for the protocol discriminator extension to one octet length (GSM48_PDISC_EXTEND). Apply new pdisc function in gsm0480.c. --- include/osmocom/gsm/protocol/gsm_04_08.h | 56 ++++++++++++++++++++++++++++++++ src/gsm/gsm0480.c | 4 +-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/include/osmocom/gsm/protocol/gsm_04_08.h b/include/osmocom/gsm/protocol/gsm_04_08.h index eefaf2b..9930032 100644 --- a/include/osmocom/gsm/protocol/gsm_04_08.h +++ b/include/osmocom/gsm/protocol/gsm_04_08.h @@ -747,9 +747,65 @@ struct gsm48_rr_status { #define GSM48_PDISC_SM_GPRS 0x0a #define GSM48_PDISC_NC_SS 0x0b #define GSM48_PDISC_LOC 0x0c +#define GSM48_PDISC_EXTEND 0x0e #define GSM48_PDISC_MASK 0x0f #define GSM48_PDISC_USSD 0x11 +static inline uint8_t gsm48_hdr_pdisc(struct gsm48_hdr *hdr) +{ + /* + * 3GPP TS 24.007 version 12.0.0 Release 12, + * 11.2.3.1.1 Protocol discriminator + */ + uint8_t pdisc = hdr->proto_discr & GSM48_PDISC_MASK; + if (pdisc == GSM48_PDISC_EXTEND) + return hdr->proto_discr; + return pdisc; +} + +static inline uint8_t gsm48_hdr_msg_type_r98(struct gsm48_hdr *hdr) +{ + /* + * 3GPP TS 24.007 version 12.0.0 Release 12, + * 11.2.3.2.1 Message type octet (when accessing Release 98 and older + * networks only) + */ + switch (gsm48_hdr_pdisc(hdr)) { + case GSM48_PDISC_MM: + case GSM48_PDISC_CC: + case GSM48_PDISC_NC_SS: + case GSM48_PDISC_GROUP_CC: + case GSM48_PDISC_BCAST_CC: + case GSM48_PDISC_LOC: + return hdr->msg_type & 0xbf; + default: + return hdr->msg_type; + } +} + +static inline uint8_t gsm48_hdr_msg_type_r99(struct gsm48_hdr *hdr) +{ + /* + * 3GPP TS 24.007 version 12.0.0 Release 12, + * 11.2.3.2.2 Message type octet (when accessing Release 99 and newer + * networks) + */ + switch (gsm48_hdr_pdisc(hdr)) { + case GSM48_PDISC_MM: + case GSM48_PDISC_CC: + return hdr->msg_type & 0x3f; + case GSM48_PDISC_NC_SS: + case GSM48_PDISC_GROUP_CC: + case GSM48_PDISC_BCAST_CC: + case GSM48_PDISC_LOC: + return hdr->msg_type & 0xbf; + default: + return hdr->msg_type; + } +} + +#define gsm48_hdr_msg_type gsm48_hdr_msg_type_r98 + /* Section 10.4 */ #define GSM48_MT_RR_INIT_REQ 0x3c #define GSM48_MT_RR_ADD_ASS 0x3b diff --git a/src/gsm/gsm0480.c b/src/gsm/gsm0480.c index 952604b..8963b78 100644 --- a/src/gsm/gsm0480.c +++ b/src/gsm/gsm0480.c @@ -220,7 +220,7 @@ int gsm0480_decode_ussd_request(const struct gsm48_hdr *hdr, uint16_t len, return 0; } - if ((hdr->proto_discr & 0x0f) == GSM48_PDISC_NC_SS) { + if (gsm48_hdr_pdisc(hdr) == GSM48_PDISC_NC_SS) { req->transaction_id = hdr->proto_discr & 0x70; ss.transaction_id = req->transaction_id; @@ -254,7 +254,7 @@ int gsm0480_decode_ss_request(const struct gsm48_hdr *hdr, uint16_t len, return 0; } - if ((hdr->proto_discr & 0x0f) == GSM48_PDISC_NC_SS) { + if (gsm48_hdr_pdisc(hdr) == GSM48_PDISC_NC_SS) { req->transaction_id = hdr->proto_discr & 0x70; rc = parse_ss(hdr, len, req); }