cunicodegsmpdusmspdu

Issue generating unicode PDU message 16bit binary


I am using a PDU generator I found from github and everything works fine when generating simple 7bit character messages.

The issue is that I want to send Unicode characters in 16bit mode and I have to input a char message of hex values in UTF-16BE format split into two characters for each Unicode character like so.

Say an Unicode character of 'Ė' will translate to U+0116 in Unicode and to '\x01\x16' in my program.

I am using this format based on an example from the github repo.

char* message = "\x01\x01\x01\x16"; // Output message will translate to 'āĖ' and is working fine

However inputting a character which would contain a hex value of '\x00' will ignore the rest of the message like so.

char* message = "\x01\x01\x01\x16\x00\x41\x00\x42\x00\x43"; // Output message will translate to 'āĖ'
// when decoded but should instead contain  'āĖABC'

I tried to look around for a solution with no success, here are some parts of the encoding function which seems to generate the PDU message.

void make_pdu(char* number, char* message, int messagelen, int alphabet, int flash_sms, int report, int with_udh,
              char* udh_data, char* mode, char* pdu, int validity, int replace_msg, int system_msg, int number_type)
{
  int coding;
  int flags;
  char tmp[50];
  char tmp2[500];
  int numberformat;
  int numberlength;
  char *p;
  int l;

  ...

  if (alphabet == 1)
    coding = 4; // 8bit binary
  else if (alphabet == 2)
    coding = 8; // 16bit <THE OPTION I USE>
  else
    coding = 0; // 7bit
  if (flash_sms > 0)
    coding += 0x10; // Bits 1 and 0 have a message class meaning (class 0, alert)

  /* Create the PDU string of the message */
  if (alphabet==1 || alphabet==2 || system_msg) // THE OPTION I USE
  {
    ...
    binary2pdu(message,messagelen,tmp2);
  }
  else
    messagelen=text2pdu(message,messagelen,tmp2,udh_data);

  /* concatenate the first part of the PDU string */
  if (strcmp(mode,"old")==0)
    sprintf(pdu,"%02X00%02X%02X%s00%02X%02X",flags,numberlength,numberformat,tmp,coding,messagelen);
  else // THE OPTION I USE
  {
    ...
    sprintf(pdu, "00%02X00%02X%02X%s%02X%02X%02X%02X", flags, numberlength, numberformat, tmp, proto, coding, validity, messagelen);
  }

  /* concatenate the text to the PDU string */
  strcat(pdu,tmp2);
}
/* Converts binary to PDU string, this is basically a hex dump. */
void binary2pdu(char* binary, int length, char* pdu)
{
  int character;
  char octett[10];

  if (length>maxsms_binary)
    length=maxsms_binary;
  pdu[0]=0;
  for (character=0;character<length; character++)
  {
    //printf("Beep\n");
    sprintf(octett,"%02X",(unsigned char) binary[character]);
    strcat(pdu,octett);
  }
}

Solution

  • As pointed by MikeCAT, the value of \x00 means the end of string. I have been using strlen() to specity the length of the string which was the problem. Tracking the correct length of the message solved the problem.