Browse code

smsops: fix len calc for a concatenated sms

- fixed the calculation for concatenated SMSs
based on TS 23.040, Sec. 9.2.3.16

Aleksandar Yosifov authored on 19/11/2020 13:39:13
Showing 1 changed files
... ...
@@ -195,7 +195,7 @@ static int ascii_to_gsm(str sms, char * output_buffer, int buffer_size) {
195 195
 		}
196 196
 	}
197 197
 
198
-	if (i <= sms.len)
198
+	if (i < sms.len)
199 199
 		output_buffer[output_buffer_length++] =	(sms.s[i] & BITMASK_7BITS) >> (carry_on_bits - 1);
200 200
 
201 201
 	return output_buffer_length;
... ...
@@ -606,6 +606,15 @@ int decode_3gpp_sms(struct sip_msg *msg) {
606 606
 							udh_read += (1 /* IE ID */ + 1 /* IE Len */ + ie->data.len /* IE data */);
607 607
 						}
608 608
 
609
+						// TS 23.040, Sec. 9.2.3.16
610
+						// Coding: 7 Bit
611
+						if (rp_data->pdu.coding == 0x00) {
612
+							int udh_bit_len = (1 + udh_len) * 8; // add 1 octet for the udh length
613
+							udh_bit_len += (7 - (udh_bit_len % 7));
614
+							len -= (udh_bit_len / 7);
615
+						}else{
616
+							len -= (1 + udh_len); // add 1 octet for the udh length
617
+						}
609 618
 					}
610 619
 
611 620
 					blen = 2 + len*4;
... ...
@@ -618,6 +627,7 @@ int decode_3gpp_sms(struct sip_msg *msg) {
618 627
 					// Coding: 7 Bit
619 628
 					if (rp_data->pdu.coding == 0x00) {
620 629
 						// We don't care about the extra used bytes here.
630
+						rp_data->pdu.payload.sm.len = len;
621 631
 						rp_data->pdu.payload.sm.len = gsm_to_ascii(&body.s[p], len, rp_data->pdu.payload.sm, fill_bits);
622 632
 					} else {
623 633
 						// Length is worst-case 2 * len (UCS2 is 2 Bytes, UTF8 is worst-case 4 Bytes)