libosmocore[master]: gsm0480: refactor the parse_process_uss_req()

2017-08-09 Thread Harald Welte

Patch Set 3: Code-Review+2

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I467f75794c5ac9df75c001245b18bbdfcfaadd88
Gerrit-PatchSet: 3
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy 
Gerrit-Reviewer: Alexander Chemeris 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Ivan Kluchnikov 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


libosmocore[master]: gsm0480: refactor the parse_process_uss_req()

2017-08-01 Thread Harald Welte

Patch Set 3:

rather than improving the manually-generated code for USSD/SS parsing, 
shouldn't we simply move to using asn1c for generaging C code for the SS 
related ASN.1?

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I467f75794c5ac9df75c001245b18bbdfcfaadd88
Gerrit-PatchSet: 3
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy 
Gerrit-Reviewer: Alexander Chemeris 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Ivan Kluchnikov 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


libosmocore[master]: gsm0480: refactor the parse_process_uss_req()

2017-07-30 Thread Alexander Chemeris

Patch Set 3: Code-Review+1

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I467f75794c5ac9df75c001245b18bbdfcfaadd88
Gerrit-PatchSet: 3
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy 
Gerrit-Reviewer: Alexander Chemeris 
Gerrit-Reviewer: Ivan Kluchnikov 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[PATCH] libosmocore[master]: gsm0480: refactor the parse_process_uss_req()

2017-07-29 Thread Vadim Yanitskiy
Hello Jenkins Builder,

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

https://gerrit.osmocom.org/3375

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

gsm0480: refactor the parse_process_uss_req()

This change reduces the degree of code nesting using
the 'follow by contradiction' pattern.

Change-Id: I467f75794c5ac9df75c001245b18bbdfcfaadd88
---
M src/gsm/gsm0480.c
1 file changed, 20 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/75/3375/2

diff --git a/src/gsm/gsm0480.c b/src/gsm/gsm0480.c
index 1c01e64..de99223 100644
--- a/src/gsm/gsm0480.c
+++ b/src/gsm/gsm0480.c
@@ -427,36 +427,37 @@
 static int parse_process_uss_req(const uint8_t *uss_req_data, uint16_t length,
 struct ss_request *req)
 {
-   int rc = 0;
int num_chars;
uint8_t dcs;
-
 
/* we need at least that much */
if (length < 8)
return 0;
 
+   if (uss_req_data[0] != GSM_0480_SEQUENCE_TAG)
+   return 0;
 
-   if (uss_req_data[0] == GSM_0480_SEQUENCE_TAG) {
-   if (uss_req_data[2] == ASN1_OCTET_STRING_TAG) {
-   dcs = uss_req_data[4];
-   if ((dcs == 0x0F) &&
-   (uss_req_data[5] == ASN1_OCTET_STRING_TAG)) {
-   num_chars = (uss_req_data[6] * 8) / 7;
-   /* Prevent a mobile-originated buffer-overrun! 
*/
-   if (num_chars > MAX_LEN_USSD_STRING)
-   num_chars = MAX_LEN_USSD_STRING;
+   /* Both 2th and 5th should be equal to ASN1_OCTET_STRING_TAG */
+   if ((uss_req_data[2] & uss_req_data[5]) != ASN1_OCTET_STRING_TAG)
+   return 0;
 
-   num_chars = gsm_7bit_decode_n_ussd((char 
*)req->ussd_text,
-   sizeof(req->ussd_text), 
&(uss_req_data[7]), num_chars);
+   dcs = uss_req_data[4];
+   if (dcs == 0x0F) {
+   num_chars = (uss_req_data[6] * 8) / 7;
+   /* Prevent a mobile-originated buffer-overrun! */
+   if (num_chars > MAX_LEN_USSD_STRING)
+   num_chars = MAX_LEN_USSD_STRING;
 
-   req->ussd_text_language = 0x80;
-   req->ussd_text_len = num_chars;
-   rc = 1;
-   }
-   }
+   num_chars = gsm_7bit_decode_n_ussd((char *)req->ussd_text,
+   sizeof(req->ussd_text), &(uss_req_data[7]), num_chars);
+
+   req->ussd_text_language = 0x80;
+   req->ussd_text_len = num_chars;
+
+   return 1;
}
-   return rc;
+
+   return 0;
 }
 
 /* Parse the parameters of a Interrogate/Activate/DeactivateSS Request */

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I467f75794c5ac9df75c001245b18bbdfcfaadd88
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy 
Gerrit-Reviewer: Jenkins Builder


[PATCH] libosmocore[master]: gsm0480: refactor the parse_process_uss_req()

2017-07-29 Thread Vadim Yanitskiy

Review at  https://gerrit.osmocom.org/3375

gsm0480: refactor the parse_process_uss_req()

This change reduces the degree of code nesting using
the 'follow by contradiction' pattern.

Change-Id: I467f75794c5ac9df75c001245b18bbdfcfaadd88
---
M src/gsm/gsm0480.c
1 file changed, 20 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/75/3375/1

diff --git a/src/gsm/gsm0480.c b/src/gsm/gsm0480.c
index 1c01e64..de99223 100644
--- a/src/gsm/gsm0480.c
+++ b/src/gsm/gsm0480.c
@@ -427,36 +427,37 @@
 static int parse_process_uss_req(const uint8_t *uss_req_data, uint16_t length,
 struct ss_request *req)
 {
-   int rc = 0;
int num_chars;
uint8_t dcs;
-
 
/* we need at least that much */
if (length < 8)
return 0;
 
+   if (uss_req_data[0] != GSM_0480_SEQUENCE_TAG)
+   return 0;
 
-   if (uss_req_data[0] == GSM_0480_SEQUENCE_TAG) {
-   if (uss_req_data[2] == ASN1_OCTET_STRING_TAG) {
-   dcs = uss_req_data[4];
-   if ((dcs == 0x0F) &&
-   (uss_req_data[5] == ASN1_OCTET_STRING_TAG)) {
-   num_chars = (uss_req_data[6] * 8) / 7;
-   /* Prevent a mobile-originated buffer-overrun! 
*/
-   if (num_chars > MAX_LEN_USSD_STRING)
-   num_chars = MAX_LEN_USSD_STRING;
+   /* Both 2th and 5th should be equal to ASN1_OCTET_STRING_TAG */
+   if ((uss_req_data[2] & uss_req_data[5]) != ASN1_OCTET_STRING_TAG)
+   return 0;
 
-   num_chars = gsm_7bit_decode_n_ussd((char 
*)req->ussd_text,
-   sizeof(req->ussd_text), 
&(uss_req_data[7]), num_chars);
+   dcs = uss_req_data[4];
+   if (dcs == 0x0F) {
+   num_chars = (uss_req_data[6] * 8) / 7;
+   /* Prevent a mobile-originated buffer-overrun! */
+   if (num_chars > MAX_LEN_USSD_STRING)
+   num_chars = MAX_LEN_USSD_STRING;
 
-   req->ussd_text_language = 0x80;
-   req->ussd_text_len = num_chars;
-   rc = 1;
-   }
-   }
+   num_chars = gsm_7bit_decode_n_ussd((char *)req->ussd_text,
+   sizeof(req->ussd_text), &(uss_req_data[7]), num_chars);
+
+   req->ussd_text_language = 0x80;
+   req->ussd_text_len = num_chars;
+
+   return 1;
}
-   return rc;
+
+   return 0;
 }
 
 /* Parse the parameters of a Interrogate/Activate/DeactivateSS Request */

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I467f75794c5ac9df75c001245b18bbdfcfaadd88
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy