From patchwork Tue Apr 19 14:06:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max X-Patchwork-Id: 612168 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 3qq6Jc1RsZz9t90 for ; Wed, 20 Apr 2016 00:06:56 +1000 (AEST) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id CFF9013E60; Tue, 19 Apr 2016 14:06:49 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from mail.sysmocom.de (mail.sysmocom.de [IPv6:2a01:4f8:191:444c::2:4]) by lists.osmocom.org (Postfix) with ESMTP id 0D71E13E58 for ; Tue, 19 Apr 2016 14:06:47 +0000 (UTC) Received: from mail.sysmocom.de (mail.sysmocom.de [144.76.43.93]) by mail.sysmocom.de (Postfix) with ESMTP id 7991D1AF626; Tue, 19 Apr 2016 14:06:17 +0000 (UTC) Received: from pbell.local (ip5b418565.dynamic.kabel-deutschland.de [91.65.133.101]) by mail.sysmocom.de (Postfix) with ESMTPSA id 2CB2C1AF622; Tue, 19 Apr 2016 14:06:16 +0000 (UTC) From: msuraev@sysmocom.de To: openbsc@lists.osmocom.org Subject: [PATCH] Add function for appending range1024 to bitvec Date: Tue, 19 Apr 2016 16:06:15 +0200 Message-Id: <1461074775-23946-1-git-send-email-msuraev@sysmocom.de> X-Mailer: git-send-email 2.8.1 X-Virus-Scanned: ClamAV using ClamSMTP 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: , Cc: Max Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" From: Max Add convenience function to append range1024 encoded data (see 3GPP TS 44.018 Annex J) to a given bitvec. --- include/osmocom/core/bitvec.h | 3 +++ src/bitvec.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/osmocom/core/bitvec.h b/include/osmocom/core/bitvec.h index c3c1153..704573c 100644 --- a/include/osmocom/core/bitvec.h +++ b/include/osmocom/core/bitvec.h @@ -44,6 +44,8 @@ #include #include +#include + /*! \brief A single GSM bit * * In GSM mac blocks, every bit can be 0 or 1, or L or H. L/H are @@ -75,6 +77,7 @@ int bitvec_set_uint(struct bitvec *bv, uint32_t in, unsigned int count); int bitvec_get_uint(struct bitvec *bv, unsigned int num_bits); int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, enum bit_value val); int bitvec_spare_padding(struct bitvec *bv, unsigned int up_to_bit); +void bitvec_add_range1024(struct bitvec *bv, const struct gsm48_range_1024 *r); int bitvec_get_bytes(struct bitvec *bv, uint8_t *bytes, unsigned int count); int bitvec_set_bytes(struct bitvec *bv, const uint8_t *bytes, unsigned int count); struct bitvec *bitvec_alloc(unsigned int size, TALLOC_CTX *bvctx); diff --git a/src/bitvec.c b/src/bitvec.c index a92fd71..7334341 100644 --- a/src/bitvec.c +++ b/src/bitvec.c @@ -38,6 +38,7 @@ #include #include +#include #define BITNUM_FROM_COMP(byte, bit) ((byte*8)+bit) @@ -523,6 +524,41 @@ static inline unsigned leading_bits(uint8_t x, bool b) } return 7; } + +/*! \brief append range1024 encoded data to bit vector */ +void bitvec_add_range1024(struct bitvec *bv, const struct gsm48_range_1024 *r) +{ + bitvec_set_uint(bv, r->w1_hi, 2); + bitvec_set_uint(bv, r->w1_lo, 8); + bitvec_set_uint(bv, r->w2_hi, 8); + bitvec_set_uint(bv, r->w2_lo, 1); + bitvec_set_uint(bv, r->w3_hi, 7); + bitvec_set_uint(bv, r->w3_lo, 2); + bitvec_set_uint(bv, r->w4_hi, 6); + bitvec_set_uint(bv, r->w4_lo, 2); + bitvec_set_uint(bv, r->w5_hi, 6); + bitvec_set_uint(bv, r->w5_lo, 2); + bitvec_set_uint(bv, r->w6_hi, 6); + bitvec_set_uint(bv, r->w6_lo, 2); + bitvec_set_uint(bv, r->w7_hi, 6); + bitvec_set_uint(bv, r->w7_lo, 2); + bitvec_set_uint(bv, r->w8_hi, 6); + bitvec_set_uint(bv, r->w8_lo, 1); + bitvec_set_uint(bv, r->w9, 7); + bitvec_set_uint(bv, r->w10, 7); + bitvec_set_uint(bv, r->w11_hi, 1); + bitvec_set_uint(bv, r->w11_lo, 6); + bitvec_set_uint(bv, r->w12_hi, 2); + bitvec_set_uint(bv, r->w12_lo, 5); + bitvec_set_uint(bv, r->w13_hi, 3); + bitvec_set_uint(bv, r->w13_lo, 4); + bitvec_set_uint(bv, r->w14_hi, 4); + bitvec_set_uint(bv, r->w14_lo, 3); + bitvec_set_uint(bv, r->w15_hi, 5); + bitvec_set_uint(bv, r->w15_lo, 2); + bitvec_set_uint(bv, r->w16, 6); +} + /*! \brief force bit vector to all 0 and current bit to the beginnig of the vector */ void bitvec_zero(struct bitvec *bv) {