summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2017-07-29 04:26:21 +0600
committerHarald Welte <laforge@gnumonks.org>2018-01-17 10:45:39 +0000
commit5b0790df523b82f327ddc8e7d538380101ac2cae (patch)
treeadb1b13c591f14acd0a92b73953560e3e07dc1c3 /src
parentfa6c2b9b53d577df916089a26a815e37277eb888 (diff)
gsm0480: clean up the parse_process_uss_req() code
This change reduces the degree of code nesting... Change-Id: I467f75794c5ac9df75c001245b18bbdfcfaadd88
Diffstat (limited to 'src')
-rw-r--r--src/gsm/gsm0480.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/gsm/gsm0480.c b/src/gsm/gsm0480.c
index dcf487af..11c66e94 100644
--- a/src/gsm/gsm0480.c
+++ b/src/gsm/gsm0480.c
@@ -439,33 +439,34 @@ static int parse_ss_invoke(const uint8_t *invoke_data, uint16_t length,
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 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;
+
+ /* 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;
- 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 > GSM0480_USSD_7BIT_STRING_LEN)
- num_chars = GSM0480_USSD_7BIT_STRING_LEN;
- gsm_7bit_decode_n_ussd((char *)req->ussd_text,
- sizeof(req->ussd_text),
- &(uss_req_data[7]), num_chars);
- rc = 1;
- }
- }
+ 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 > GSM0480_USSD_7BIT_STRING_LEN)
+ num_chars = GSM0480_USSD_7BIT_STRING_LEN;
+
+ gsm_7bit_decode_n_ussd((char *)req->ussd_text,
+ sizeof(req->ussd_text), &(uss_req_data[7]), num_chars);
+
+ return 1;
}
- return rc;
+
+ return 0;
}
/* Parse the parameters of a Interrogate/Activate/DeactivateSS Request */