# fins — Port 9600 Omron FINS PLC Memory Area Read & Write Frames (`fins`)

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

- **Full Protocol Name:** Omron Factory Interface Network Service (NJ/NX/CJ/CS PLC Protocol)
- **Keyword:** `fins`
- **OSI Layer & Transport:** Layer 7 · UDP 9600 (or TCP 9600 via transport tcp)
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** Omron W342 / W227 FINS Reference Manual
- **Wireshark Display Filter:** `omron`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> UDP 9600 (or TCP 9600 via transport tcp) (transport tcp|udp) -> Omron FINS`

## Overview

Factory-automation lines running Omron CJ/CS/NJ PLCs speak FINS on port `9600` (`area "dm"`, `dna`/`da1`/`sna`/`sa1`): add `transport tcp` and FrameAssembly wraps the 10-byte FINS header in the `"FINS"` TCP magic envelope automatically.

Factory Interface Network Service (`fins`) is Omron’s native industrial PLC protocol across **Sysmac NJ/NX, CJ2, CS1, and CP1 controllers** in automotive assembly, packaging, and battery manufacturing lines on **UDP or TCP port `9600`**. Every FINS PDU carries a **10-byte FINS Header** (`ICF` Information Control Field `0x80` command / `0xc0` response, `RSV`, `GCT` Gateway Count `0x02`, `DNA`/`DA1`/`DA2` destination network/node/unit, `SNA`/`SA1`/`SA2` source network/node/unit, and `SID` Service ID) followed by a 2-byte `Command Code` (`0x0101` Memory Area Read, `0x0102` Memory Area Write, `0x0501` Controller Data Read). When `transport tcp` is selected, FrameAssembly also prepends the **16-byte ASCII `"FINS"` (`46 49 4e 53`) TCP framing header** automatically!

FrameAssembly maps Omron memory mnemonics (`area "DM"` `0x82`, `"CIO"` `0xb0`, `"WR"` `0xb1`, `"HR"` `0xb2`) and response end-codes (`errcode 0x0000`) directly to wire bytes.

## Minimal Quickstart (`fins_quickstart.frasm`)

```frameassembly
host scada_hmi { ip 192.168.250.10 }
host omron_cj2 { ip 192.168.250.1 }

compile {
    scada_hmi -> omron_cj2 fins read da1 1 sa1 10 sid 1 area "DM" addr 100 count 2 wait 2ms
    scada_hmi <- omron_cj2 fins read response da1 10 sa1 1 sid 1 errcode 0x0000 value 1250
}
```

### Automatic Wire Calculations

- Defaults to UDP destination port `9600`; when `transport tcp` is specified, switches to stateful TCP `9600` and prepends the mandatory 16-byte `"FINS"` (`0x46494e53`, `Command = 2`, `Error = 0`) FINS/TCP wrapper.
- Sets `ICF = 0x80` on commands and `ICF = 0xc0` (plus 2-byte `End Code` `errcode`) automatically when `response` / `isresponse` is present.
- Translates memory area names (`"DM"` -> `0x82`, `"CIO"` -> `0xb0`, `"WR"` -> `0xb1`, `"HR"` -> `0xb2`, `"AR"` -> `0xb3`) and writes 16-bit word `addr` + bit `0x00` + 16-bit `count`.

## Practical Lab Example: Packaging Line Omron CJ2M Poll: DM Word Read, Setpoint Write & Controller Read (`fins_omron_dm_read_write.frasm`)

Reads 4 Data Memory (`DM100..DM103`) words over UDP `9600`, writes a conveyor speed setpoint (`DM200 = 1500`), and queries Controller Data (`cmd 0x0501`).

```frameassembly
host sysmac_ws { ip 10.250.1.25 }
host cj2m_cpu  { ip 10.250.1.1 }

compile {
    // 1. Memory Area Read (0x0101): Read 4 words starting at DM100 (SID = 10)
    sysmac_ws -> cj2m_cpu fins read dna 0 da1 1 da2 0 sna 0 sa1 25 sa2 0 sid 10 area "DM" addr 100 count 4 wait 2ms
    sysmac_ws <- cj2m_cpu fins read response dna 0 da1 25 da2 0 sna 0 sa1 1 sa2 0 sid 10 errcode 0x0000 value 420 wait 8ms
    // 2. Memory Area Write (0x0102): Write setpoint 1500 into DM200 (SID = 11)
    sysmac_ws -> cj2m_cpu fins write da1 1 sa1 25 sid 11 area "DM" addr 200 count 1 value 1500 wait 2ms
    sysmac_ws <- cj2m_cpu fins write response da1 25 sa1 1 sid 11 errcode 0x0000 wait 10ms
    // 3. Controller Data Read (0x0501) over FINS/TCP (port 9600)
    sysmac_ws -> cj2m_cpu tcp syn srcport 54600 dstport 9600 wait 1ms
    sysmac_ws <- cj2m_cpu tcp syn ack wait 1ms
    sysmac_ws -> cj2m_cpu tcp ack wait 1ms
    sysmac_ws -> cj2m_cpu fins cmd 0x0501 da1 1 sa1 25 sid 12 transport tcp wait 2ms
    sysmac_ws <- cj2m_cpu fins cmd 0x0501 response da1 25 sa1 1 sid 12 errcode 0x0000 transport tcp
}
```

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

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

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

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

## All `fins` Keywords & Header Options

Packet line pattern: `src_host -> dst_host fins [read | write | cmd "<text_or_num>"] [response | isresponse] [icf <0..255>] [dna <0..255>] [da1 <0..255>] [da2 <0..255>] [sna <0..255>] [sa1 <0..255>] [sa2 <0..255>] [sid <0..255>] [area "<text_or_num>"] [addr <0..65535>] [count <0..65535>] [value <0..65535>] [errcode <0..65535>] [transport <udp|tcp>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `read \| write \| cmd "<text_or_num>" \| [response \| isresponse]` | 16-bit FINS Command Code (`0x0101` Read, `0x0102` Write, `0x0401` Run, `0x0402` Stop, `0x0501` Controller Info) | `read (0x0101), command (ICF 0x80)` | Sets the 2-byte `(MRC, SRC)` Command Code and toggles `ICF` (`0x80` vs `0xc0` with `response`). |
| `icf <0..255> \| sid <0..255>` | 8-bit Information Control Field & 8-bit Service ID | `icf 0x80 (or 0xc0), sid 1` | Writes byte 0 (`ICF`) and byte 9 (`SID` transaction correlation byte) of the 10-byte FINS header. |
| `dna <0..255> \| da1 <0..255> \| da2 <0..255> \| sna <0..255> \| sa1 <0..255> \| sa2 <0..255>` | Destination & Source `(Network, Node, Unit)` FINS routing triples | `dna 0, da1 1, da2 0, sna 0, sa1 10, sa2 0` | Writes bytes 3..8 of the 10-byte FINS header (`da1`/`sa1` typically match the last IPv4 octet). |
| `area "<text_or_num>" \| addr <0..65535> \| count <0..65535> \| value <0..65535>` | Memory Area ("DM","CIO","WR","HR","AR" or hex code), 16-bit Word Address, Item Count, and 16-bit Word Value | `area "DM" (0x82), addr 0, count 1, value 0` | Populates Memory Area Read/Write request parameters and response/write word payloads. |
| `errcode <0..65535> \| transport <udp\|tcp>` | 16-bit FINS Response End Code (`0x0000` Normal) & L4 transport | `errcode 0x0000, transport udp` | Writes `(MRES, SRES)` in response frames or switches between FINS/UDP and `"FINS"`-framed FINS/TCP. |

## Cross-Layer Options Valid with `fins`

| 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 9600 (or TCP 9600 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

### Swap da1 and sa1 Node Numbers on <- PLC Responses

- **Valid v3.3.0 Syntax:** `hmi -> plc fins read da1 1 sa1 25 sid 1 area "DM" addr 100
hmi <- plc fins read response da1 25 sa1 1 sid 1 errcode 0`

Omron PLCs swap the FINS Source `(SNA, SA1, SA2)` and Destination `(DNA, DA1, DA2)` node triples while echoing the caller’s `SID`.

### Quote Area Mnemonics Like "DM" or "CIO"

- **Valid v3.3.0 Syntax:** `hmi -> plc fins read area "DM" addr 100 count 2`

Quoting `"DM"`, `"CIO"`, `"WR"`, or `"HR"` makes memory-bank strings unmistakable next to strict-lowercase `.frasm` keywords.
