CoAP · Study deck

CoAP Block and Discovery Contracts

A constrained node cannot always carry a firmware image in one CoAP message, and a new client cannot use a resource it cannot discover.

Broker Bex is your guide for this deck.

blockdiscovery
Broker Bex, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Choose Block1 or Block2 and record block size, retry, resume, and hash-verification evidence for a large CoAP transfer.
  • Decode Block option NUM, M, and SZX fields and check them against byte offsets in a trace.
  • Describe /.well-known/core discovery, CoRE Link Format attributes, filtered discovery queries, and Content-Format 40.
  • Review Max-Age, ETag revalidation, and proxy caching decisions for constrained CoAP resources.
iotclass.org

Major section

Reassemble the Image the Server Actually Sent

Blocks 0–3: 1,024 bytes each; block 4: 904 bytes, M=0; assembled length 5,000 bytes, then hash and signature.

  • Blocks zero through three each carry 1,024 bytes.Together those four full blocks carry 4,096 bytes.
  • Block four carries the remaining 904 bytes.Its M field is zero, which marks the final block.
  • Verify the assembled 5,000-byte image before installation.Check its hash and signature after confirming the final length.
CoAP Block2 transfer contract showing block option semantics, representation continuity, exactly-once reassembly under retry or reorder, and final length and hash evidence.
CoAP Block2 transfer contract showing block option semantics, representation continuity, exactly-once reassembly under retry or reorder, and final length and hash evidence.
iotclass.org

Major section

Reassemble the Image the Server Actually Sent (continued)

A lost response does not mean the server should advance state blindly.

  • The client can request the same block number again, and the server should return the matching portion of the same representation.
  • Mixing old and new blocks could produce 5,000 bytes that are still unsafe.
  • A link-format record can name a resource path, content type, interface, resource type, and observability.
  • Authorization remains separate from knowing that a URI exists.
iotclass.org

Major section

Start With the Broken Firmware Download

One block is missing, and a nearby cache may describe an old file.

  • The device needs proof before it resumes or installs anything.
  • A protocol means the shared rules for a message exchange.
  • CoAP means Constrained Application Protocol, a compact message system for small devices.
  • Firmware means the software stored on a device.
iotclass.org

Major section

Start With the Broken Firmware Download (continued)

A block is one numbered piece of a larger transfer.

  • This runway does not prove every proxy or update route.
  • The device asks for a firmware image, receives several blocks, loses one packet, then wakes later behind a proxy that may still have cached metadata.
  • A working demo is not enough; the transfer needs block size, numbering, retry, resume, hash, discovery, and freshness evidence.
iotclass.org

Major section

Overview: Block-wise Transfer Moves Big Payloads Through Small Datagrams

The key benefit is failure isolation.

  • Each block is carried in its own request/response exchange with its own Message ID, so a lost block is retransmitted alone rather than forcing the entire payload to restart.
  • In a real maintenance window, that isolation changes the rollout plan.

Key terms

Each block
Each block is its own exchange, so loss costs one block, not the whole transfer.
Encryption
Encryption is a separate concern (DTLS/OSCORE).

Why it matters

A loss repeats only its numbered block; continuity fields prevent pieces from different representations being combined; final length and hash evidence close acceptance.

CoAP Block2 transfer contract showing block option semantics, representation continuity, exactly-once reassembly under retry or reorder, and final length and hash evidence.
CoAP Block2 transfer contract showing block option semantics, representation continuity, exactly-once reassembly under retry or reorder, and final length and hash evidence.
iotclass.org

Major section

Overview: Block-wise Transfer Moves Big Payloads Through Small Datagrams (continued)

The transfer has 384 numbered blocks.

  • The review evidence should record the chosen block size, retry cap, resume point, hash check, and the condition that triggers rollback to the previous profile.
  • That ordered contract turns the pump-controller example into a testable transfer rather than assuming that smaller datagrams alone make delivery safe.
  • Failure isolationEach block is its own exchange, so loss costs one block, not the whole transfer.
iotclass.org

Major section

Practitioner: The Block Option Encodes NUM, More, and a Size Exponent

With SZX 4 the client sends 256-byte Block1 chunks, so it needs ceil(18,432 / 256) = 72 blocks.

  • NUM is the block number within the transfer.
  • M (the More flag) is 1 while further blocks follow and 0 on the last block.
  • Fewest exchanges; needs the largest buffer/MTU.
iotclass.org

Major section

Under the Hood: Discovery via CoRE Link Format, and Caching Through Proxies

Here rt is the resource type, if is the interface description, ct is the content-format the resource speaks (50 = JSON), and obs marks it observable.

  • A client can narrow the query — GET /.well-known/core?rt=temperature returns only temperature links — which keeps discovery cheap on a large node.
  • Every response carries an implicit or explicit Max-Age (option 14, default 60 seconds) stating how long it stays fresh.
  • The evidence record should show the discovery query, Link Format body, Max-Age value, ETag revalidation result, and which resources are excluded from shared caching.
iotclass.org

Major section

Under the Hood: Discovery via CoRE Link Format, and Caching Through Proxies (continued)

Max-Age expired → revalidate with stored ETag → unchanged origin returns 2.03 Valid without a body.

  • Max-Age sets how long a cached response stays fresh.After expiry, the proxy must revalidate rather than assume the representation is current.
  • The proxy sends its stored ETag to the origin.That validator asks whether the cached representation has changed.
  • A 2.03 Valid response confirms the representation is unchanged.The origin can avoid sending the unchanged body while the proxy refreshes validity.
iotclass.org

Deck summary

Key takeaways

It selects the firmware resource and requests a block.

  • A lost response does not mean the server should advance state blindly.
  • One block is missing, and a nearby cache may describe an old file.
  • A block is one numbered piece of a larger transfer.
  • The key benefit is failure isolation.
iotclass.org

Retrieval practice

Recall check 1 of 4

Broker Bex says: answer from memory, then check your reasoning.

Q1Why does CoAP use block-wise transfer instead of relying on IP fragmentation for a large firmware image?

ABecause blocks are encrypted automatically while IP fragments cannot be.
BBecause each CoAP block is a separately retransmittable exchange.
CBecause IP fragmentation is prohibited on every IoT radio network.
DBecause block-wise transfer reduces the image's total byte size.
Show answer

Answer: B Block-wise transfer isolates failures to a single block, which is far more robust than IP fragmentation on lossy constrained links.

iotclass.org

Retrieval practice

Recall check 2 of 4

Broker Bex says: answer from memory, then check your reasoning.

Q2In a CoAP block-wise option, a block has SZX = 6 and the More (M) flag set to 0. What does that mean?

ASZX is the literal byte count, so this is a 6-byte final block.
BIt uses 1024-byte blocks and this block is final.
CIt uses 1024-byte blocks and another block must follow.
DSZX chooses the CBOR content format for this block.
Show answer

Answer: B Block size is 2^(SZX+4) = 2^10 = 1024 bytes, and M = 0 marks the last block, so the transfer ends here.

iotclass.org

Retrieval practice

Recall check 3 of 4

Broker Bex says: answer from memory, then check your reasoning.

Q3A CoAP caching proxy holds a sensor response with an ETag whose Max-Age has just expired. It revalidates with that ETag and the value is unchanged. What origin response makes this efficient?

A2.03 Valid without payload after ETag revalidation finds no change.
B2.05 Content with full payload every time cached Max-Age expires.
C4.04 Not Found solely because the cached copy became stale.
DNo response until the proxy deletes the entry and each client polls.
Show answer

Answer: A ETag-based revalidation lets the origin answer 2.03 Valid without resending the body, refreshing the cache cheaply.

iotclass.org

Retrieval practice

Recall check 4 of 4

Broker Bex says: answer from memory, then check your reasoning.

Q4A client wants only temperature resources from a large CoAP node. Which discovery contract gives it a compact, typed result?

AFilter /.well-known/core by resource type and read typed CoRE links.
BGuess temperature URIs instead of using the node's discovery links.
CRead every resource and discard its typed link attributes afterward.
DSend control commands to actuators in place of resource discovery.
Show answer

Answer: A The filter returns relevant links, while link attributes describe each resource.

iotclass.org

Print reference

Answers

Answer key.

  1. B · Block-wise transfer isolates failures to a single block, which is far more robust than IP fragmentation on lossy constrained links.
  2. B · Block size is 2^(SZX+4) = 2^10 = 1024 bytes, and M = 0 marks the last block, so the transfer ends here.
  3. A · ETag-based revalidation lets the origin answer 2.03 Valid without resending the body, refreshing the cache cheaply.
  4. A · The filter returns relevant links, while link attributes describe each resource.
iotclass.org
With the answer frame visible, check four decisions. Separate numbered exchanges let us retry a lost block. S-Z-X fixes block size, and M marks whether more follow. E-Tag revalidation can avoid resending an unchanged body. Filtered discovery narrows the resource list. None of these checks authorizes a firmware install.