Change in libosmocore[master]: Add function to combine nibbles into byte

2019-01-17 Thread Max
Max has abandoned this change. ( https://gerrit.osmocom.org/12573 )

Change subject: Add function to combine nibbles into byte
..


Abandoned
--
To view, visit https://gerrit.osmocom.org/12573
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: abandon
Gerrit-Change-Id: I380687c31a787c0a109819f7c3b2946eae52675e
Gerrit-Change-Number: 12573
Gerrit-PatchSet: 2
Gerrit-Owner: Max 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Reviewer: Max 
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-Reviewer: Vadim Yanitskiy 


Change in libosmocore[master]: Add function to combine nibbles into byte

2019-01-16 Thread Vadim Yanitskiy
Vadim Yanitskiy has posted comments on this change. ( 
https://gerrit.osmocom.org/12573 )

Change subject: Add function to combine nibbles into byte
..


Patch Set 2: Code-Review-1

> I think this is API bloat.
 > If you start like this, where will it lead?

Hehe, this reminds me the time when I was involved in web-development.
jQuery has become so popular, so multiple funny questions from noobs
began to appear on StackOverflow (not only), e.g.:

  how to sum two numbers using jQuery? :D

So, in general I am agree with Neels.


--
To view, visit https://gerrit.osmocom.org/12573
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I380687c31a787c0a109819f7c3b2946eae52675e
Gerrit-Change-Number: 12573
Gerrit-PatchSet: 2
Gerrit-Owner: Max 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Reviewer: Max 
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-Comment-Date: Wed, 16 Jan 2019 12:54:26 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in libosmocore[master]: Add function to combine nibbles into byte

2019-01-16 Thread Neels Hofmeyr
Neels Hofmeyr has posted comments on this change. ( 
https://gerrit.osmocom.org/12573 )

Change subject: Add function to combine nibbles into byte
..


Patch Set 2: Code-Review-1

I think this is API bloat.
We do a lot of custom bit shifting and it's not something that needs API.
Everyone knows how to compose a byte from two nibbles.
We're not likely to replace all the nibbles-to-byte conversions with calls to 
this function.
If you start like this, where will it lead? osmo_bytes_to_int16_t()? 
osmo_3bit_plus_5bit_to_byte()?


--
To view, visit https://gerrit.osmocom.org/12573
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I380687c31a787c0a109819f7c3b2946eae52675e
Gerrit-Change-Number: 12573
Gerrit-PatchSet: 2
Gerrit-Owner: Max 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Reviewer: Max 
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-CC: Vadim Yanitskiy 
Gerrit-Comment-Date: Wed, 16 Jan 2019 12:45:59 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in libosmocore[master]: Add function to combine nibbles into byte

2019-01-16 Thread Max
Max has posted comments on this change. ( https://gerrit.osmocom.org/12573 )

Change subject: Add function to combine nibbles into byte
..


Patch Set 2:

(1 comment)

https://gerrit.osmocom.org/#/c/12573/1/include/osmocom/core/bits.h
File include/osmocom/core/bits.h:

https://gerrit.osmocom.org/#/c/12573/1/include/osmocom/core/bits.h@52
PS1, Line 52: hi Value to be placed in MSB nibble
> Copy pasted ;) Did you mean MSB?
Sure thing :)



-- 
To view, visit https://gerrit.osmocom.org/12573
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I380687c31a787c0a109819f7c3b2946eae52675e
Gerrit-Change-Number: 12573
Gerrit-PatchSet: 2
Gerrit-Owner: Max 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Reviewer: Max 
Gerrit-CC: Vadim Yanitskiy 
Gerrit-Comment-Date: Wed, 16 Jan 2019 10:00:22 +
Gerrit-HasComments: Yes
Gerrit-HasLabels: No


Change in libosmocore[master]: Add function to combine nibbles into byte

2019-01-16 Thread Max
Hello Jenkins Builder,

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

https://gerrit.osmocom.org/12573

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

Change subject: Add function to combine nibbles into byte
..

Add function to combine nibbles into byte

It's a very common patter throughout GSM 04.08 and other protocols where
single byte store 2 different values occupying 1 nibble each.

Change-Id: I380687c31a787c0a109819f7c3b2946eae52675e
---
M include/osmocom/core/bits.h
M include/osmocom/gsm/gsm0808_utils.h
M include/osmocom/gsm/gsm48.h
M include/osmocom/gsm/protocol/gsm_03_41.h
M src/gsm/gsm0808.c
M src/gsm/gsm23003.c
M src/gsm/gsm48.c
M tests/utils/utils_test.c
8 files changed, 21 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/73/12573/2
--
To view, visit https://gerrit.osmocom.org/12573
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I380687c31a787c0a109819f7c3b2946eae52675e
Gerrit-Change-Number: 12573
Gerrit-PatchSet: 2
Gerrit-Owner: Max 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-CC: Vadim Yanitskiy 


Change in libosmocore[master]: Add function to combine nibbles into byte

2019-01-15 Thread Vadim Yanitskiy
Vadim Yanitskiy has posted comments on this change. ( 
https://gerrit.osmocom.org/12573 )

Change subject: Add function to combine nibbles into byte
..


Patch Set 1:

(1 comment)

https://gerrit.osmocom.org/#/c/12573/1/include/osmocom/core/bits.h
File include/osmocom/core/bits.h:

https://gerrit.osmocom.org/#/c/12573/1/include/osmocom/core/bits.h@52
PS1, Line 52: hi Value to be placed in LSB nibble
Copy pasted ;) Did you mean MSB?



--
To view, visit https://gerrit.osmocom.org/12573
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I380687c31a787c0a109819f7c3b2946eae52675e
Gerrit-Change-Number: 12573
Gerrit-PatchSet: 1
Gerrit-Owner: Max 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-CC: Vadim Yanitskiy 
Gerrit-Comment-Date: Wed, 16 Jan 2019 03:48:34 +
Gerrit-HasComments: Yes
Gerrit-HasLabels: No


Change in libosmocore[master]: Add function to combine nibbles into byte

2019-01-15 Thread Max
Max has uploaded this change for review. ( https://gerrit.osmocom.org/12573


Change subject: Add function to combine nibbles into byte
..

Add function to combine nibbles into byte

It's a very common patter throughout GSM 04.08 and other protocols where
single byte store 2 different values occupying 1 nibble each.

Change-Id: I380687c31a787c0a109819f7c3b2946eae52675e
---
M include/osmocom/core/bits.h
M include/osmocom/gsm/gsm0808_utils.h
M include/osmocom/gsm/gsm48.h
M include/osmocom/gsm/protocol/gsm_03_41.h
M src/gsm/gsm0808.c
M src/gsm/gsm23003.c
M src/gsm/gsm48.c
M tests/utils/utils_test.c
8 files changed, 21 insertions(+), 9 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/73/12573/1

diff --git a/include/osmocom/core/bits.h b/include/osmocom/core/bits.h
index b1b8040..8027bdd 100644
--- a/include/osmocom/core/bits.h
+++ b/include/osmocom/core/bits.h
@@ -47,6 +47,16 @@

 int osmo_pbit2ubit(ubit_t *out, const pbit_t *in, unsigned int num_bits);

+/*! Nibble combination.
+ *  \param[in] lo Value to be placed in LSB nibble
+ *  \param[in] hi Value to be placed in LSB nibble
+ *  \returns combined nibble value
+ */
+static inline uint8_t osmo_nibble(uint8_t lo, uint8_t hi)
+{
+   return lo | (hi << 4);
+}
+
 void osmo_nibble_shift_right(uint8_t *out, const uint8_t *in,
 unsigned int num_nibbles);
 void osmo_nibble_shift_left_unal(uint8_t *out, const uint8_t *in,
diff --git a/include/osmocom/gsm/gsm0808_utils.h 
b/include/osmocom/gsm/gsm0808_utils.h
index 4a2233e..4cc917b 100644
--- a/include/osmocom/gsm/gsm0808_utils.h
+++ b/include/osmocom/gsm/gsm0808_utils.h
@@ -237,7 +237,7 @@
return 0;
}

-   return channel_mode << 4 | channel;
+   return osmo_nibble(channel, channel_mode);
 }

 const char *gsm0808_channel_type_name(const struct gsm0808_channel_type *ct);
diff --git a/include/osmocom/gsm/gsm48.h b/include/osmocom/gsm/gsm48.h
index 0f5727a..69b2eeb 100644
--- a/include/osmocom/gsm/gsm48.h
+++ b/include/osmocom/gsm/gsm48.h
@@ -71,4 +71,4 @@
   uint8_t pdisc, uint8_t msg_type);

 #define gsm48_push_l3hdr_tid(msg, pdisc, tid, msg_type) \
-   gsm48_push_l3hdr(msg, (pdisc & 0x0f) | (tid << 4), msg_type)
+   gsm48_push_l3hdr(msg, osmo_nibble(pdisc & 0x0f, tid), msg_type)
diff --git a/include/osmocom/gsm/protocol/gsm_03_41.h 
b/include/osmocom/gsm/protocol/gsm_03_41.h
index 1b399ae..cd84fd4 100644
--- a/include/osmocom/gsm/protocol/gsm_03_41.h
+++ b/include/osmocom/gsm/protocol/gsm_03_41.h
@@ -5,6 +5,7 @@

 #include 

+#include 
 #include 
 #include 

@@ -73,7 +74,7 @@
uint8_t data[0];
 } __attribute__((packed));

-#define GSM341_MSG_CODE(ms) ((ms)->serial.code_lo | ((ms)->serial.code_hi << 
4))
+#define GSM341_MSG_CODE(ms) osmo_nibble((ms)->serial.code_lo, 
(ms)->serial.code_hi)

 /* Section 9.3.2.1 - Geographical Scope */
 #define GSM341_GS_CELL_WIDE_IMMED  0
diff --git a/src/gsm/gsm0808.c b/src/gsm/gsm0808.c
index 59b1657..2254630 100644
--- a/src/gsm/gsm0808.c
+++ b/src/gsm/gsm0808.c
@@ -293,7 +293,7 @@
return NULL;

/* Set cause code class in the upper byte */
-   cause = 0x80 | (class << 4);
+   cause = osmo_nibble(0x80, class);
cause = cause << 8;

/* Set cause code extension in the lower byte */
diff --git a/src/gsm/gsm23003.c b/src/gsm/gsm23003.c
index 1d9cefe..eaf0fb4 100644
--- a/src/gsm/gsm23003.c
+++ b/src/gsm/gsm23003.c
@@ -32,6 +32,7 @@
 #include 
 #include 
 #include 
+#include 

 static bool is_n_digits(const char *str, int min_digits, int max_digits)
 {
@@ -218,10 +219,10 @@
to_bcd(bcd, plmn->mnc);
if (plmn->mnc > 99 || plmn->mnc_3_digits) {
bcd_dst[1] |= bcd[2] << 4;
-   bcd_dst[2] = bcd[0] | (bcd[1] << 4);
+   bcd_dst[2] = osmo_nibble(bcd[0], bcd[1]);
} else {
bcd_dst[1] |= 0xf << 4;
-   bcd_dst[2] = bcd[1] | (bcd[2] << 4);
+   bcd_dst[2] = osmo_nibble(bcd[1], bcd[2]);
}
 }

diff --git a/src/gsm/gsm48.c b/src/gsm/gsm48.c
index 795e98b..e5d1592 100644
--- a/src/gsm/gsm48.c
+++ b/src/gsm/gsm48.c
@@ -659,7 +659,7 @@
else
upper = osmo_char2bcd(id[++off]) & 0x0f;

-   buf[2 + i] = (upper << 4) | lower;
+   buf[2 + i] = osmo_nibble(lower, upper);
}

return 2 + buf[1];
diff --git a/tests/utils/utils_test.c b/tests/utils/utils_test.c
index a773b3f..b677a5f 100644
--- a/tests/utils/utils_test.c
+++ b/tests/utils/utils_test.c
@@ -510,7 +510,7 @@
in_buf[16] = '\0';
for (j = 0; j < 16; j++) {
for (i = 0; i < 16; i++)
-   in_buf[i] = (j << 4) | i;
+   in_buf[i] = osmo_nibble(i, j);
printf("\"%s\"\n", osmo_escape_str((const char*)in_buf, 16));
}

@@ -558,7