Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/4292

to look at the new patch set (#4).

Expand bitvec_write_field()

Previously only boolean values were allowed while in practice it's
sometimes necessary to use L/H. Allow user to specify this explicitly
and make old function into wrapper around extended version. Use extended
function in tests and update output accordingly.

Change-Id: Iee648d764de9f3e7ef850f40864ad701c83f61db
Related: OS#1526
---
M include/osmocom/core/bitvec.h
M src/bitvec.c
M tests/bits/bitfield_test.c
M tests/bits/bitfield_test.ok
4 files changed, 22 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/92/4292/4

diff --git a/include/osmocom/core/bitvec.h b/include/osmocom/core/bitvec.h
index 3e68ddb..b7eba1f 100644
--- a/include/osmocom/core/bitvec.h
+++ b/include/osmocom/core/bitvec.h
@@ -72,6 +72,7 @@
 unsigned int bitvec_unpack(struct bitvec *bv, const uint8_t *buffer);
 uint64_t bitvec_read_field(struct bitvec *bv, unsigned int *read_index, 
unsigned int len);
 int bitvec_write_field(struct bitvec *bv, unsigned int *write_index, uint64_t 
val, unsigned int len);
+int bitvec_write_field_ext(struct bitvec *bv, uint32_t *write_index, uint64_t 
val, uint8_t len, bool use_lh);
 int bitvec_fill(struct bitvec *bv, unsigned int num_bits, enum bit_value fill);
 char bit_value_to_char(enum bit_value v);
 void bitvec_to_string_r(const struct bitvec *bv, char *str);
diff --git a/src/bitvec.c b/src/bitvec.c
index 0683694..646594b 100644
--- a/src/bitvec.c
+++ b/src/bitvec.c
@@ -500,16 +500,18 @@
 /*! write into the vector
  *  \param[in] bv The boolean vector to work on
  *  \param[in,out] write_index Where writing supposed to start in the vector
+ *  \param[in] val value to be written to the vector
  *  \param[in] len How many bits to write
+ *  \param[in] use_lh whether to interpret the bits as L/H values or as 0/1
  *  \returns next write index or negative value on error
  */
-int bitvec_write_field(struct bitvec *bv, unsigned int *write_index, uint64_t 
val, unsigned int len)
+int bitvec_write_field_ext(struct bitvec *bv, uint32_t *write_index, uint64_t 
val, uint8_t len, bool use_lh)
 {
        int rc;
 
        bv->cur_bit = *write_index;
 
-       rc = bitvec_set_u64(bv, val, len, false);
+       rc = bitvec_set_u64(bv, val, len, use_lh);
        if (rc != 0)
                return rc;
 
@@ -518,6 +520,18 @@
        return 0;
 }
 
+/*! write into the vector
+ *  \param[in] bv The boolean vector to work on
+ *  \param[in,out] write_index Where writing supposed to start in the vector
+ *  \param[in] val value to be written to the vector
+ *  \param[in] len How many bits to write
+ *  \returns next write index or negative value on error
+ */
+int bitvec_write_field(struct bitvec *bv, unsigned int *write_index, uint64_t 
val, unsigned int len)
+{
+       return bitvec_write_field_ext(bv, (uint32_t *)write_index, val, len, 
false);
+}
+
 /*! convert enum to corresponding character
  *  \param v input value (bit)
  *  \return single character, either 0, 1, L or H */
diff --git a/tests/bits/bitfield_test.c b/tests/bits/bitfield_test.c
index 0a86e1f..e7023f7 100644
--- a/tests/bits/bitfield_test.c
+++ b/tests/bits/bitfield_test.c
@@ -19,10 +19,7 @@
        INTRO(use_lh);
 
        /* GSM 04.08 10.5.2.16 IA Rest Octets */
-       if (use_lh) /* FIXME: add function to encode LH properly */
-               bitvec_write_field(dest, &wp, 3, 2);            /* "HH" */
-       else
-               bitvec_write_field(dest, &wp, 3, 2);            /* "HH" */
+       bitvec_write_field_ext(dest, &wp, 3, 2, use_lh);        /* "HH" */
        bitvec_write_field(dest, &wp, 1, 2);                    /* "01" Packet 
Downlink Assignment */
        bitvec_write_field(dest, &wp, ttli, 32);                /* TLLI */
        bitvec_write_field(dest, &wp, 1, 1);                    /* switch TFI: 
on */
@@ -35,10 +32,7 @@
        bitvec_write_field(dest, &wp, 0, 1);                    /* No 
TIMING_ADVANCE_INDEX: */
        bitvec_write_field(dest, &wp, 0, 1);                    /* TBF Starting 
TIME present */
        bitvec_write_field(dest, &wp, 0, 1);                    /* P0 not 
present */
-       if (use_lh) { /* FIXME: add function to encode LH properly */
-               bitvec_write_field(dest, &wp, 1, 1);            /* "H" - 
additional for R99 */
-       } else
-               bitvec_write_field(dest, &wp, 1, 1);            /* "H" - 
additional for R99 */
+       bitvec_write_field_ext(dest, &wp, 1, 1, use_lh);        /* "H" - 
additional for R99 */
        bitvec_write_field(dest, &wp, ws_enc, 5);               /* EGPRS Window 
Size */
        bitvec_write_field(dest, &wp, 0, 2);                    /* 
LINK_QUALITY_MEASUREMENT_MODE */
        bitvec_write_field(dest, &wp, 0, 1);                    /* BEP_PERIOD2 
not present */
@@ -56,10 +50,7 @@
        INTRO(use_lh);
 
        /* GMS 04.08 10.5.2.37b 10.5.2.16 */
-       if (use_lh) /* FIXME: add function to encode LH properly */
-               bitvec_write_field(dest, &wp, 3, 2);                            
/* "HH" */
-       else
-               bitvec_write_field(dest, &wp, 3, 2);                            
/* "HH" */
+       bitvec_write_field_ext(dest, &wp, 3, 2, use_lh);                        
/* "HH" */
        bitvec_write_field(dest, &wp, 0, 2);                                    
/* "0" Packet Uplink Assignment */
        if (!tbf) {
                bitvec_write_field(dest, &wp, 0, 1);                            
/* Block Allocation: SBA */
diff --git a/tests/bits/bitfield_test.ok b/tests/bits/bitfield_test.ok
index f920a11..cd863cf 100644
--- a/tests/bits/bitfield_test.ok
+++ b/tests/bits/bitfield_test.ok
@@ -4,12 +4,12 @@
 
 
 === start test_bitvec_ia_octet_encode_pkt_dl_ass(1) ===
-Encoded PKT DL ASS IA Rest Octets: dd ea db ee f8 00 22 31 2b 2b 2b 2b 2b 2b 
2b 2b 2b 2b 2b 2b 2b 2b 
+Encoded PKT DL ASS IA Rest Octets: dd ea db ee f8 00 20 31 2b 2b 2b 2b 2b 2b 
2b 2b 2b 2b 2b 2b 2b 2b 
 === end test_bitvec_ia_octet_encode_pkt_dl_ass(1) ===
 
 
 === start test_bitdiff(22) ===
-=== total 0 bits differ ===
+=== total 1 bits differ ===
 === end test_bitdiff(22) ===
 
 

-- 
To view, visit https://gerrit.osmocom.org/4292
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Iee648d764de9f3e7ef850f40864ad701c83f61db
Gerrit-PatchSet: 4
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Max <msur...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Minh-Quang Nguyen <minh-quang.ngu...@nutaq.com>

Reply via email to