# hartip — Port 5094 FieldComm HART-IP Process Transmitter Gateways (`hartip`)

> **FrameAssembly v3.3.0** · Protocol 115 of 81 · Canonical URL: https://frameassembly-lang.dev/docs/protocols/hartip

- **Full Protocol Name:** Highway Addressable Remote Transducer Over IP (Process Field Instruments)
- **Keyword:** `hartip`
- **OSI Layer & Transport:** Layer 7 · UDP 5094 (or TCP 5094 via transport tcp)
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** FieldComm Group HCF_SPEC-085, IEC 62591 (WirelessHART)
- **Wireshark Display Filter:** `hart_ip`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> UDP 5094 (or TCP 5094 via transport tcp) (transport tcp|udp) -> HART-IP (IEC 62591)`

## Overview

Smart 4–20 mA pressure and valve transmitters reach IP historians via WirelessHART/HART-IP gateways on port `5094` — `hartip` wraps the 8-byte HART-IP header + inner HART token-ring PDU with valid XOR checksums.

HART-IP (`hartip`, FieldComm Group `HCF_SPEC-085` / IEC 62591) bridges 4–20 mA smart process transmitters, **WirelessHART gateways**, and asset management systems (Emerson AMS, Yokogawa PRM, Honeywell FDM) onto refinery and chemical-plant IP networks over **UDP or TCP port `5094`**. Every HART-IP packet starts with an **8-byte Header** (`Version = 1`, `Message Type`: `0` Request / `1` Response / `2` Publish, `Message ID`: `0` Session Initiate / `1` Session Close / `2` Keep-Alive / `3` Token-Passing PDU Pass-Through, `Status`, `16-bit Sequence Number txid`, and `16-bit Byte Count`).

FrameAssembly encodes Session Initiate (`mode` Master Type + `holdtime` Inactivity Close Timer), Keep-Alive, Session Close, and **Message ID `3` HART Token-Passing PDU** frames complete with XOR longitudinal parity check byte!

## Minimal Quickstart (`hartip_quickstart.frasm`)

```frameassembly
host ams_server { ip 10.94.1.10 }
host whart_gw   { ip 10.94.2.50 }

compile {
    ams_server -> whart_gw hartip init txid 1 mode 1 holdtime 60000 wait 3ms
    ams_server <- whart_gw hartip init isresponse txid 1 status 0 mode 1 holdtime 60000 wait 5ms
    ams_server -> whart_gw hartip msgid 3 txid 2 addr 0 cmd 1 wait 4ms
    ams_server <- whart_gw hartip msgid 3 isresponse txid 2 status 0 addr 0 cmd 1
}
```

### Automatic Wire Calculations

- Defaults to UDP destination port `5094` (`transport tcp` switches to stateful TCP `5094`) and computes the big-endian 16-bit `Byte Count` (including the 8-byte header) automatically.
- Sets `Message Type = 1` (`Response`) whenever `isresponse` or `response` is present (`0` `Request` by default).
- On `msgid 3` (HART Pass-Through), wraps `addr` (short frame polling address) and `cmd` (`0` Read Unique ID, `1` Read Primary Variable, `3` Read Dynamic Variables) with a valid trailing XOR checksum byte.

## Practical Lab Example: WirelessHART Gateway Session: Initiate, Read Primary Variable (Cmd 1), Keep-Alive & Close (`hartip_process_transmitter_poll.frasm`)

Initiates a Primary Master (`mode 1`) HART-IP session over UDP `5094`, polls pressure transmitter `addr 1` with Universal Command `3` (Dynamic Variables), exchanges a `keepalive`, and closes the session cleanly.

```frameassembly
host dcs_ams  { ip 172.20.94.10 }
host whart_ap { ip 172.20.94.100 }

compile {
    // 1. Session Initiate (Message ID 0): Primary Master (mode 1), 60,000 ms inactivity timer
    dcs_ams -> whart_ap hartip init txid 100 mode 1 holdtime 60000 wait 2ms
    dcs_ams <- whart_ap hartip init isresponse txid 100 status 0 mode 1 holdtime 60000 wait 5ms
    // 2. Pass-Through Token-Passing PDU (Message ID 3): HART Command 3 (Read Dynamic Variables)
    dcs_ams -> whart_ap hartip msgid 3 txid 101 addr 1 cmd 3 wait 4ms
    dcs_ams <- whart_ap hartip msgid 3 isresponse txid 101 status 0 addr 1 cmd 3 wait 15ms
    // 3. Keep-Alive (Message ID 2) & Graceful Session Close (Message ID 1)
    dcs_ams -> whart_ap hartip keepalive txid 102 wait 2ms
    dcs_ams <- whart_ap hartip keepalive isresponse txid 102 status 0 wait 5ms
    dcs_ams -> whart_ap hartip close txid 103 wait 2ms
    dcs_ams <- whart_ap hartip close isresponse txid 103 status 0
}
```

```bash
# 1. Eyeball relative timestamps, ports & wire lengths in your terminal
frameassembly show hartip_process_transmitter_poll.frasm

# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'
frameassembly hartip_process_transmitter_poll.frasm hartip_process_transmitter_poll.pcap
frameassembly hartip_process_transmitter_poll.frasm hartip_process_transmitter_poll.pcapng

# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture
frameassembly reverse hartip_process_transmitter_poll.pcap hartip_process_transmitter_poll_edited.frasm

# 4. Verify dissected protocol fields in tshark
tshark -r hartip_process_transmitter_poll.pcap
```

## All `hartip` Keywords & Header Options

Packet line pattern: `src_host -> dst_host hartip [init | close | keepalive | msgid "<text_or_num>"] [version <0..255>] [msgtype "<text_or_num>"] [isresponse | response] [status <0..255>] [txid <0..65535>] [mode <0..255>] [holdtime <number>] [addr <0..255>] [cmd <0..255>] [transport <udp|tcp>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `init \| close \| keepalive \| msgid "<text_or_num>"` | 8-bit HART-IP Message ID (`0` Initiate, `1` Close, `2` Keep-Alive, `3` Token-Passing PDU) | `init (0) or 3 when cmd/addr is set` | Sets byte 2 (`Message ID`) of the 8-byte HART-IP header and formats the matching body. |
| `msgtype "<text_or_num>" \| isresponse \| response` | HART-IP Message Type (`0` Request, `1` Response, `2` Publish/Notification, `15` NAK) | `0 (Request); 1 (Response) with isresponse` | Sets byte 1 (`Message Type`) of the HART-IP header. |
| `version <0..255> \| status <0..255> \| txid <0..65535>` | Header Version (`1` plain, `2` TLS/DTLS), Status (`0` Success), and 16-bit Sequence Number | `version 1, status 0, txid 1` | Populates bytes 0, 3, and 4..5 of the 8-byte HART-IP header. |
| `mode <0..255> \| holdtime <number>` | Master Type (`1` Primary, `0` Secondary) & 32-bit Inactivity Close Timer (ms) | `mode 1, holdtime 30000` | Writes the 5-byte payload of `Session Initiate` (`Message ID = 0`). |
| `addr <0..255> \| cmd <0..255>` | HART polling address & Universal/Practice Command (`0`, `1`, `2`, `3`, `6`, `48`) | `addr 0, cmd 0` | Builds an embedded HART Token-Passing short frame inside `Message ID = 3` with valid XOR parity. |
| `transport <udp\|tcp>` | `udp` or `tcp` | `udp` | Switches Layer 4 between UDP `5094` and stateful TCP `5094`. |

## Cross-Layer Options Valid with `hartip`

| Option | Range / Format | Default | Effect |
| --- | --- | --- | --- |
| `wait <number><ns\|us\|ms\|s\|m>` | Time gap (ns, us, ms, s, m) | `10ms` | Advances the packet timestamp clock after sending this packet and before the next packet (`wait 0ns` sends back-to-back). |
| `comment "<text>"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"`, `"de:ad:be:ef"`, or `"\x01\x02"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType 0..65535 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or standalone Layer 2 16-bit EtherType. |
| `fcs \| badfcs` | Ethernet CRC-32 trailer flags (choose one) | `Omitted` | `fcs` appends a valid IEEE 802.3 4-byte CRC-32 Frame Check Sequence trailer; `badfcs` XOR-corrupts the CRC-32 for NIC/tap negative tests. |
| `vlan <0..4095> [pcp <0..7>] [dei <0\|1>]` | VLAN ID 0..4095, PCP 0..7, DEI 0..1 | `Untagged` | Wraps the packet in an IEEE 802.1Q VLAN tag (`0x8100`) with optional 802.1p QoS priority. |
| `qinq <0..4095> [innervlan <0..4095>]` | Outer S-VLAN 0..4095, Inner C-VLAN 0..4095 | `Untagged (innervlan 1 when qinq is set)` | Double-tags the packet with outer IEEE 802.1ad S-Tag (`0x88a8`) plus inner IEEE 802.1Q C-Tag (`0x8100`). |
| `mpls <0..1048575> [label <0..1048575>] [exp\|tc <0..7>] [bos <0\|1>] [mplsttl <0..255>]` | Repeatable label stack (0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255) | `Unlabeled (auto bos=0 on outer labels, bos=1 on bottom)` | Prepends one or more 32-bit MPLS label shims (`0x8847`, e.g. `mpls 16000 mpls 24010`) ahead of Layer 2 EoMPLS or Layer 3 payloads. |
| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 64, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |
| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |
| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 5094 (or TCP 5094 via transport tcp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `transport <tcp\|udp\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |
| `badchecksum \| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |
| `seq <number> \| acknum <number> \| win\|window <0..65535> \| urgent <0..65535> \| syn \| ack \| psh \| fin \| rst \| urg \| ece \| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |

## Common Mistakes & Quick Fixes

### Send Session Initiate (init) Before Pass-Through Commands for Stateful Gateways

- **Valid v3.3.0 Syntax:** `ams -> gw hartip init txid 1 mode 1 holdtime 60000
ams -> gw hartip msgid 3 txid 2 cmd 1`

FieldComm HART-IP servers require an active session (`Message ID 0` Initiate) before accepting `Message ID 3` HART Pass-Through requests.

### Preserve Matching txid on HART-IP Responses

- **Valid v3.3.0 Syntax:** `ams -> gw hartip keepalive txid 55
ams <- gw hartip keepalive isresponse txid 55`

Bytes 4..5 (`Sequence Number`) pair asynchronous HART-IP responses with in-flight master requests.
