@@ -895,13 +895,14 @@ nsapi_size_or_error_t AT_CellularSMS::get_sms(char* buf, uint16_t len, char* pho
895
895
index+=14 ;
896
896
}
897
897
898
+ int udl = hex_str_to_int (pdu+index, 2 );
898
899
index +=2 ;
900
+
899
901
int paddingBits = 0 ;
900
- int parts = 1 ;
901
902
int partnro = 1 ;
902
903
if (userDataHeader) {
903
904
// we need to read User Defined Header to know what part number this message is.
904
- index += read_udh_from_pdu (pdu+index, info, partnro, parts, paddingBits);
905
+ index += read_udh_from_pdu (pdu+index, info, partnro, paddingBits);
905
906
}
906
907
907
908
if (part_number) {
@@ -910,7 +911,7 @@ nsapi_size_or_error_t AT_CellularSMS::get_sms(char* buf, uint16_t len, char* pho
910
911
911
912
if (msg) {
912
913
// we are reading the message
913
- err = read_pdu_payload (pdu+index, dataScheme, msg, paddingBits, partnro == parts );
914
+ err = read_pdu_payload (pdu+index, udl, dataScheme, msg, paddingBits);
914
915
}
915
916
else {
916
917
if (dataScheme == 0x00 ) {
@@ -933,16 +934,16 @@ nsapi_size_or_error_t AT_CellularSMS::get_sms(char* buf, uint16_t len, char* pho
933
934
}
934
935
}
935
936
936
- // read params from User DEfined Header
937
- int AT_CellularSMS::read_udh_from_pdu (const char * pdu, sms_info_t *info, int &part_number, int &parts,
938
- int &padding_bits) {
937
+ // read params from User Defined Header
938
+ int AT_CellularSMS::read_udh_from_pdu (const char * pdu, sms_info_t *info, int &part_number, int &padding_bits) {
939
939
940
940
int index = 0 ;
941
941
int udhLength = hex_str_to_int (pdu, 2 );
942
942
index +=2 ;
943
943
944
944
// if there is padding bits then udhlen is octet bigger as we need to keep septet boundary
945
945
padding_bits = ((udhLength+1 ) * 8 ) % 7 ; // +1 is for udhLength itself
946
+
946
947
if (padding_bits) {
947
948
padding_bits = 7 - padding_bits;
948
949
} else {
@@ -966,9 +967,8 @@ int AT_CellularSMS::read_udh_from_pdu(const char* pdu, sms_info_t *info, int &pa
966
967
index +=4 ;
967
968
}
968
969
969
- parts = hex_str_to_int (pdu+index, 2 );
970
970
if (info) {
971
- info->parts = parts ;
971
+ info->parts = hex_str_to_int (pdu+index, 2 ) ;
972
972
}
973
973
index +=2 ;
974
974
@@ -978,13 +978,11 @@ int AT_CellularSMS::read_udh_from_pdu(const char* pdu, sms_info_t *info, int &pa
978
978
return (udhLength*2 + 2 ); // udh in hex and udhl
979
979
}
980
980
981
- nsapi_size_or_error_t AT_CellularSMS::read_pdu_payload (const char * pdu, int scheme, char *msg, int padding_bits,
982
- bool last_part)
981
+ nsapi_size_or_error_t AT_CellularSMS::read_pdu_payload (const char * pdu, int msg_len, int scheme, char *msg, int padding_bits)
983
982
{
984
983
if (scheme == 0x00 ) {
985
984
// 7 bit gsm encoding, must do the conversions from hex to 7-bit encoding and to ascii
986
- return unpack_7_bit_gsm_to_str (pdu, strlen (pdu)/2 , msg, padding_bits, last_part);
987
-
985
+ return unpack_7_bit_gsm_to_str (pdu, strlen (pdu)/2 , msg, padding_bits, msg_len);
988
986
} else if (scheme == 0x04 ) {
989
987
// 8bit scheme so just convert hexstring to charstring
990
988
return hex_str_to_char_str (pdu, strlen (pdu), msg);
@@ -1261,7 +1259,7 @@ uint16_t AT_CellularSMS::pack_7_bit_gsm_and_hex(const char* str, uint16_t len, c
1261
1259
}
1262
1260
1263
1261
uint16_t AT_CellularSMS::unpack_7_bit_gsm_to_str (const char * str, int len, char *buf, int padding_bits,
1264
- bool last_part )
1262
+ int msg_len )
1265
1263
{
1266
1264
int strCount = 0 ;
1267
1265
uint16_t decodedCount = 0 ;
@@ -1284,9 +1282,7 @@ uint16_t AT_CellularSMS::pack_7_bit_gsm_and_hex(const char* str, uint16_t len, c
1284
1282
} else if (shift == 6 ) {
1285
1283
hex_str_to_char_str (str + (strCount-1 )*2 , 2 , &tmp1);
1286
1284
buf[decodedCount] = gsm_to_ascii[(((tmp1>>2 )) | (tmp << 6 )) & 0x7F ];
1287
- // we are unpacking the last byte and so tmp is not complete as it's not completed by the next byte.
1288
- // unless this is a multipart message and not the last part.
1289
- if (!((strCount+1 == len) && last_part)) {
1285
+ if (decodedCount+1 < msg_len) {
1290
1286
hex_str_to_char_str (str + strCount*2 , 2 , &tmp);
1291
1287
decodedCount++;
1292
1288
buf[decodedCount] = gsm_to_ascii[(tmp>>1 ) & 0x7F ];
0 commit comments