SMPPEX.Pdu.UDH (smppex v3.0.2) View Source

Module for parsing encoded IEs from UDHs.

Link to this section Summary

Functions

Encodes IEs and prepends message with the encoded value.

Extracts list of IEs from UDH.

Checks if message in PDU has UDH (by inspecting esm_class field).

Link to this section Types

Link to this section Functions

Specs

add([ie()], binary()) :: {:ok, binary()} | {:error, any()}

Encodes IEs and prepends message with the encoded value.

The result is one of the following:

  • {:ok, message} where message is the original message prefixed with UDH;
  • {:error, reason} in case of errors.

Example

iex> ies = [{0x05, <<0x06, 0x2d, 0x00, 0x00>>}, {0x00, <<0x01, 0x02, 0x01>>}]
iex> SMPPEX.Pdu.UDH.add(ies, "message")
{:ok, <<0x0B, 0x05, 0x04, 0x06, 0x2d, 0x00, 0x00, 0x00, 0x03, 0x01, 0x02, 0x01, "message">>}

iex> ies = [{0, 123}]
iex> SMPPEX.Pdu.UDH.add(ies, "message")
{:error, "Invalid UDH IE data"}

iex> ies = [{345, "ie"}]
iex> SMPPEX.Pdu.UDH.add(ies, "message")
{:error, "Invalid UDH IE id"}

iex> ies = [{-1, "ie"}]
iex> SMPPEX.Pdu.UDH.add(ies, "message")
{:error, "Invalid UDH IE id"}

iex> ies = [{0, <<1 :: integer-size(2040)>>}]
iex> SMPPEX.Pdu.UDH.add(ies, "message")
{:error, "UDH is too long"}

Specs

extract(message :: binary()) :: {:error, term()} | {:ok, [ie()], binary()}

Extracts list of IEs from UDH.

Returns one of the following

  • {:ok, ies, message} where ies is a list of IE tuples {id, value} and message is the original message without UDH;
  • {:error, reason} in case of errors.

Example

iex> data = <<5, 0, 3, 197, 3, 3, "message">>
iex> SMPPEX.Pdu.UDH.extract(data)
{:ok, [{0, <<197, 3, 3>>}], "message"}

iex> data = <<0x0B, 0x05, 0x04, 0x06, 0x2d, 0x00, 0x00, 0x00, 0x03, 0x01, 0x02, 0x01, "message">>
iex> SMPPEX.Pdu.UDH.extract(data)
{:ok, [{0x05, <<0x06, 0x2d, 0x00, 0x00>>}, {0x00, <<0x01, 0x02, 0x01>>}], "message"}

iex> data = <<0x10, "short">>
iex> SMPPEX.Pdu.UDH.extract(data)
{:error, "Invalid UDH length"}

iex> data = <<0x06, 0x00, 0x03, 0x01, 0x02, 0x01, "message">>
iex> SMPPEX.Pdu.UDH.extract(data)
{:error, "Invalid UDH data"}

iex> data = <<5, 0, 4, 197, 3, 3, "message">>
iex> SMPPEX.Pdu.UDH.extract(data)
{:error, "Invalid UDH IE length"}

Specs

has_udh?(pdu :: SMPPEX.Pdu.t()) :: boolean()

Checks if message in PDU has UDH (by inspecting esm_class field).

Example

iex> pdu = SMPPEX.Pdu.new({1,0,1}, %{esm_class: 0}, %{})
iex> SMPPEX.Pdu.UDH.has_udh?(pdu)
false

iex> pdu = SMPPEX.Pdu.new({1,0,1}, %{esm_class: 0b01000000}, %{})
iex> SMPPEX.Pdu.UDH.has_udh?(pdu)
true