# ENUM integration manual  

In this article, you can learn more about how to use the Infobip ENUM interface for HLR lookups.
  
## Connectivity
  
To enable connectivity between the Infobip ENUM interface and the client system, the client needs to provide a list of IP addresses which will be safelisted in the Infobip ENUM system.
  
## ENUM query packet
  
There are requirements that each ENUM query must fulfill. **QTYPE** in the ENUM query must be **NAPTR** and there are additional restrictions to ENUM query parameters that must be compiled so that the query is not rejected by the ENUM server.
  
### ENUM query packet format [#enum-query-packet-format-enum-query-packet]

#### HEADER section of ENUM query packet [#header-section-of-enum-query-packet-enum-query-packet]

1. **QR** bit must be set to **0** representing DNS query.
2. Opcode must be **0** representing a standard DNS query.
3. It is only possible to make one ENUM query per DNS packet. Therefore, **QDCOUNT** value must be **1**.
4. **ANCOUNT**, **NSCOUNT**, and **ARCOUNT** must be **0**.

#### QUESTION section of ENUM query packet [#question-section-of-enum-query-packet-enum-query-packet]

1. **QNAME** must be as specified in **RFC 3761**. It is a **E.164** number on which first a well-known rule is applied with a mandatory appended Infobip ENUM root (e.g., **+442079460148** after applying first a well-known rule and appending the Infobip ENUM root **8.4.1.0.6.4.9.7.0.2.4.4.infobip.net**).
2. **QTYPE** must be **NAPTR** specified in **RFC 2168**.
3. **QCLASS** can be any defined in **RFC 1035**, a standard for this service should be the internet class (IN).

Example of Valid ENUM query using dig is:

<samp>dig naptr 5.4.3.7.1.0.5.1.9.5.8.3.infobip.net @x.x.x.x</samp>
  
(where X.X.X.X represents IP address of the ENUM server)
  
## ENUM server responses
  
ENUM server response format is compliant to **RFC 1035** and **RFC 3761** which means that RR that are returned only contain **NAPTR** **RDATA**, also the ENUM error responses are returned in case of error while processing the ENUM query.
  
### ENUM response packet format [#enum-response-packet-format-enum-server-responses]

#### HEADER section of ENUM response [#header-section-of-enum-response-enum-server-responses]

1. **QR** bit is set to **1**, representing DNS response.
2. **RCODE** value can be any value as per specification.

#### QUESTION section of ENUM response packet [#question-section-of-enum-response-packet-enum-server-responses]
  
It is the same as Question in the ENUM query that response is for. The Answer section is present in case there were no errors while processing the ENUM query request.
  
#### ENUM responses in case of error processing ENUM query [#enum-responses-in-case-of-error-processing-enum-query-enum-server-responses]
  
In case the ENUM query is successfully processed and the HLR query was successful (there was no timeout reached), an ENUM server sends a response which contains the Answer section. The Answer section contains the HLR query result in the RR for which **RDATA** type is **NAPTR**.
  
#### ENUM error response packet format [#enum-error-response-packet-format-enum-server-responses]

#### HEADER section of ENUM error response [#header-section-of-enum-error-response-enum-server-responses]

1. **QR** bit is set to **1**, representing DNS response.
2. **RCODE** value representing an error, zero value in ENUM error response will never be returned.

**RCODE** values in case of specific error are shown in the table below:
  
| RCODE value | ERROR CAUSE |
| --- | --- |
| Packet discarded | HEADER section parsing error. |
| FORMERR | Any other ENUM query section parsing error. |
| SERVFAIL | Invalid Query |
| SERVFAIL | Failed sending HLR query |
| SERVFAIL | Timeout while for waiting HLR query response. |
| NXDOMAIN | Invalid E.164 number in the ENUM query Validity of E.164. number is checked based on the prefix (Country Code and Identification Code of number). List of all valid number prefixes which are updated on daily basis is maintained. In case that number prefix which is submitted via ENUM is not in that list HLR query is not sent to SS7 network and ENUM server responds with NXDOMAIN error. |
| NOTIMPL | System failure. |
| REFUSED | Unknown Error |

#### ENUM responses in case of successfully processed ENUM query [#enum-responses-in-case-of-successfully-processed-enum-query-enum-server-responses]
  
In case the ENUM query is successfully processed and the HLR query was successful (there was no timeout reached), the ENUM server sends a response which contains the Answer section. The Answer section contains the HLR query result in the RR for which RDATA type is NAPTR.
  
#### ENUM successful response packet format [#enum-successful-response-packet-format-enum-server-responses]

#### PR format [#pr-format-enum-server-responses]

1. **NAME** represents the **RR** name, it the same as the ENUM query **QNAME**.
2. **TYPE** is the same as the ENUM query **QTYPE** which is **NAPTR**.
3. **CLASS** default returning class is internet class (IN).
4. **TTL** default value is 86400 seconds (24h).
5. **RDLENGTH** represents the length in bytes of **NAPTR**.

## RDATA
  
**NAPTR** **RDATA** values returned by ENUM server are:
  
|  |
|  |
| Preference | 100 |
| Flags | “u“ |
| Services | “E2U+pstn:tel” |
| Regular Expression | "!^.*!tel:\\1\;hlr=xxxxxx\;imsi=xxxxxx\;msc=xxxxxx\;msisdn=xxxxxx\;status=xxxx" |
| Replacement | . |

|  |
|  |
| imsi=xxxxxx | IMSI which is returned in the HLR response. |
| msc=xxxxx | Serving MSC GT which is returned in the HLR response (last 4 digits of MSC are not returned because of the possibility of SMS Fraud/Spoof using obtained routing information). |
| status=xxxxxx | Status of HLR query (HLR error code). |
| Regular Expression | "!^.*!tel:\\1\;hlr=xxxxxx\;imsi=xxxxxx\;msc=xxxxxx\;msisdn=xxxxxx\;status=xxxx" |

**Example of ENUM query response using dig in case of successful HLR query:**
  
`;; Got answer:`
`;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 195`
`;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0`
`;; QUESTION SECTION: ;5.4.3.7.1.0.5.1.9.5.8.3.infobip.net. IN NAPTR`
`;; ANSWER SECTION:`
`5.4.3.7.1.0.5.1.9.5.8.3.infobip.net. 86400 IN NAPTR 10 100 "u" "E2U+pstn:tel" "!^ .*!tel:\\1\;hlr=385915017345\;imsi=219101100165275\;msc=3859\;msisdn=38591501734 5\;status=00 00" .`
`;; Query time: 546 msec`
  
**Example of ENUM query response using dig in case of HLR query error:**
  
`;; Got answer:`
`;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1696`
`;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0`
`;; QUESTION SECTION: ;7.0.0.0.0.6.8.9.5.8.3.infobip.net. IN NAPTR`
`;; ANSWER SECTION:`
`7.0.0.0.0.6.8.9.5.8.3.infobip.net. 86400 IN NAPTR 10 100 "u" "E2U+pstn:tel" "!^.* !tel:\\1\;msisdn=38598600007\;status=0006`
`;; Query time: 383 msec`