# SMPP

Ella PSAP connects to each [SMSC](<https://docs.ellanetworks.com/psap/reference/api/smscs/index.md>) as an ESME, over SMPP 3.4.

## Binds

Ella PSAP opens one session per account and SMSC address, with `bind_transceiver`.

### `bind_transceiver` Fields

The fields of each bind.

| Field | Value |
| --- | --- |
| `system_id` | The account's system ID. |
| `password` | The account's password. |
| `system_type` | Empty. |
| `interface_version` | `0x34` |
| `addr_ton`, `addr_npi`, `address_range` | `0`, `0`, empty. |

### Accounts

What each account of an SMSC receives.

| Account | Receives |
| --- | --- |
| Texts | The emergency texts of the SMSC's text service, and the delivery receipts of replies. |
| AML | The AML messages of the SMSC's AML service. |

Ella PSAP binds the AML account only when the SMSC has one. An AML message is stored as an [AML report](<https://docs.ellanetworks.com/psap/reference/api/aml/index.md>), not as a text.

### Reconnection

After a session fails or a bind is refused, Ella PSAP binds again after 1 second, then doubles the wait up to 1 minute.

## Received `deliver_sm`

Ella PSAP answers each `deliver_sm` from the SMSC.

| `deliver_sm` | Response |
| --- | --- |
| A text, or a part of a text, from a phone | `ESME_ROK` |
| A text with an empty `source_addr` | `ESME_RINVSRCADR` |
| A delivery receipt (`esm_class` `0x04`) | `ESME_ROK` |

### Text Decoding

How the user data, `short_message` or `message_payload`, is read from `data_coding`.

| `data_coding` | Read as |
| --- | --- |
| `0x00`; `0x10` to `0x1F` and `0x40` to `0x5F` with bits 3 and 2 at `00`; `0xC0` to `0xDF`; `0xF0` to `0xF3`, `0xF8` to `0xFB` | GSM 7-bit default alphabet: one septet per octet, unless an octet is over `0x7F`, then packed. |
| `0x01` | ASCII |
| `0x03` | Latin-1 |
| `0x08`; `0x10` to `0x1F` and `0x40` to `0x5F` with bits 3 and 2 at `10`; `0xE0` to `0xEF` | UCS-2 |
| Other | Binary, not decoded. |

### Concatenated Texts

How the parts of one long text are recognised.

| Marker | Fields |
| --- | --- |
| User data header, `esm_class` bit `0x40` | Information element `0x00` (8-bit reference) or `0x08` (16-bit reference). |
| Optional parameters | `sar_msg_ref_num`, `sar_total_segments` and `sar_segment_seqnum`. |

How the parts become one text.

| Case | Stored text |
| --- | --- |
| Every part arrives within 2 minutes of the first | The parts joined in order, status `received`. |
| A part is missing 2 minutes after the first | The parts received, with `�` for each missing part, status `incomplete`. |

### Delivery Receipts

How a receipt finds the part of a reply it is about.

| Receipt field | Use |
| --- | --- |
| `receipted_message_id`, else `id:` in the text | The `message_id` of the part. |
| `message_state`, else `stat:` in the text | The new status of the part. |

| State | Part status |
| --- | --- |
| `DELIVERED`, `DELIVRD` | `delivered` |
| `ENROUTE`, `ACCEPTED`, `ACCEPTD` | Unchanged. |
| Any other | `failed`, with the state as the error. |

## Sent `submit_sm`

Ella PSAP sends each part of a text as one `submit_sm`, on a bound session of the SMSC's texts account.

### `submit_sm` Fields

The fields of each `submit_sm`.

| Field | Value |
| --- | --- |
| `source_addr_ton`, `source_addr_npi`, `source_addr` | `0`, `1`, the number the text is sent from. |
| `dest_addr_ton`, `dest_addr_npi`, `destination_addr` | `1`, `1`, the phone. |
| `esm_class` | `0x00`, or `0x40` when the part has a user data header. |
| `data_coding` | `0x00`, GSM 7-bit with one septet per octet, when every character allows it. Else `0x08`, UCS-2. |
| `registered_delivery` | `1`, a delivery receipt on the final status. |
| `short_message` | The part. |

### Splitting

How many characters fit in one `submit_sm`.

| Encoding | Text in one part | Each part of a split text |
| --- | --- | --- |
| GSM 7-bit | 160 septets | 153 septets, after a 6-octet concatenation header |
| UCS-2 | 70 characters | 67 characters, after a 6-octet concatenation header |
