# `XMAVLink.Frame`
[🔗](https://github.com/fancydrones/xmavlink/blob/main/lib/mavlink/frame.ex#L20)

Represent and work with MAVLink v1/2 message frames

# `message`

```elixir
@type message() :: XMAVLink.Message.t()
```

# `t`

```elixir
@type t() :: %XMAVLink.Frame{
  checksum: 0..65535,
  compatible_flags: non_neg_integer(),
  crc_extra: XMAVLink.Types.crc_extra(),
  incompatible_flags: non_neg_integer(),
  mavlink_1_raw: binary() | nil,
  mavlink_2_raw: binary() | nil,
  message: message() | nil,
  message_id: XMAVLink.Types.message_id(),
  payload: binary(),
  payload_length: 0..255,
  sequence_number: 0..255,
  signature: XMAVLink.Frame.Signature.t() | nil,
  source_component: 1..255,
  source_system: 1..255,
  target: :broadcast | :system | :system_component | :component,
  target_component: 0..255,
  target_system: 0..255,
  version: version()
}
```

# `version`

```elixir
@type version() :: 1 | 2
```

# `binary_to_frame_and_tail`

```elixir
@spec binary_to_frame_and_tail(binary()) ::
  {t(), binary()} | {nil, binary()} | :not_a_frame
```

# `pack_frame`

# `sign_frame`

```elixir
@spec sign_frame(t(), &lt;&lt;_::256&gt;&gt;, 0..255, 0..281_474_976_710_655) ::
  {:ok, t()}
  | {:error,
     :already_signed
     | :checksum_invalid
     | :invalid_crc_extra
     | :invalid_link_id
     | :invalid_mavlink_2_frame
     | :invalid_secret_key
     | :invalid_timestamp
     | :mavlink_1_not_signable
     | :missing_crc_extra
     | :missing_mavlink_2_raw
     | :unsupported_incompatible_flags}
```

Sign an already packed MAVLink 2 frame.

This is a low-level frame utility. It sets `MAVLINK_IFLAG_SIGNED`,
recalculates the checksum for the signed header, and appends the 13-byte
MAVLink 2 signature trailer. It does not manage link timestamp state or
router/connection signing policy. The existing packed frame checksum must
already match the frame's `crc_extra`.

# `signed?`

```elixir
@spec signed?(t() | non_neg_integer()) :: boolean()
```

# `validate_and_unpack`

```elixir
@spec validate_and_unpack(t(), module()) ::
  {:ok, t()}
  | :failed_to_unpack
  | :checksum_invalid
  | :unknown_message
  | :signed_frame_unsupported
```

# `validate_and_unpack`

```elixir
@spec validate_and_unpack(t(), module(), XMAVLink.Signing.t() | nil) ::
  {:ok, t(), XMAVLink.Signing.t() | nil}
  | {:unknown_message, XMAVLink.Signing.t() | nil}
  | {:error,
     :failed_to_unpack
     | :checksum_invalid
     | :unknown_message
     | XMAVLink.Signing.validate_error(), XMAVLink.Signing.t() | nil}
```

# `validate_signature`

```elixir
@spec validate_signature(t(), &lt;&lt;_::256&gt;&gt;) ::
  :ok
  | {:error,
     :invalid_secret_key
     | :invalid_mavlink_2_frame
     | :signature_invalid
     | :unsigned_frame}
```

Validate the MAVLink 2 signature trailer for an already parsed signed frame.

This only verifies the cryptographic signature over the signed packet bytes.
It does not enforce timestamp replay rules or unpack the frame payload.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
