Skip to content

gateway: initial pouch over coap#225

Open
mniestroj wants to merge 9 commits into
mainfrom
coap-gateway-over-pouch
Open

gateway: initial pouch over coap#225
mniestroj wants to merge 9 commits into
mainfrom
coap-gateway-over-pouch

Conversation

@mniestroj

Copy link
Copy Markdown
Collaborator

No description provided.

@mniestroj mniestroj marked this pull request as draft June 4, 2026 14:05
@mniestroj mniestroj force-pushed the coap-gateway-over-pouch branch 5 times, most recently from bf6d27d to 17cdd85 Compare June 11, 2026 10:58
The header was never intended as part of the public API. Only the gateway
and broker endpoint use it.

Move it next to its implementation so that the public include tree only
contains the supported API.

Signed-off-by: Marcin Niestroj <marcin.niestroj@canonical.com>
The 'info' name was generic enough to clash with similarly-named log
modules elsewhere. Pick a more specific name.

Signed-off-by: Marcin Niestroj <marcin.niestroj@canonical.com>
Cached serial length is zero and zcbor_compare_strings() reports a match
against a zero-length expected serial before any server certificate has
been received. In that case 'server_cert_provisioned' is reported as true.

Skip the comparison until a serial has actually been read.

Signed-off-by: Marcin Niestroj <marcin.niestroj@canonical.com>
The single-threaded usage assumption is about to be broken by a new
gateway transport (added in a later commit) that calls into the CoAP
client from a separate thread.  Introduce a mutex covering all
socket and buffer state, and lock it around the public entry points.

Signed-off-by: Marcin Niestroj <marcin.niestroj@canonical.com>
A subsequent commit will add a gateway transport (gateway.c) that
needs to set up the DTLS socket, fetch the server certificate, upload
the device certificate and inspect the cached server cert.

Make those helpers non-static, drop the sec_tag parameter from
pouch_coap_setup_socket() (it already had the value cached from
pouch_coap_client_init()), move the sec_tag validation into the helper.

Add pouch_coap_server_cert_get() so the gateway can pass the cert on to the
broker bearer.

No behaviour change for existing callers.

Signed-off-by: Marcin Niestroj <marcin.niestroj@canonical.com>
The Zephyr CoAP port already exposes the gateway address as
CONFIG_POUCH_COAP_GW_URI in port/zephyr/transport/coap/Kconfig, but the
sysbuild config and the test workflow were still pushing the value via
the old CONFIG_GOLIOTH_COAP_HOST_URI name (now removed from the
port).  Align the sysbuild Kconfig and the CI export with the active
port symbol, and switch from a full coap[s]:// URL to a hostname so
the names match the actual usage on the port side.

Signed-off-by: Marcin Niestroj <marcin.niestroj@canonical.com>
@mniestroj mniestroj force-pushed the coap-gateway-over-pouch branch 3 times, most recently from 54abe97 to b1e9559 Compare June 11, 2026 14:14
Introduce a pluggable cloud transport interface so the gateway core
can forward pouches and certificates without hard-coding any concrete
transport.  A transport implements three operations
(ensure_ready/forward_pouch/upload_device_cert) and registers itself
through pouch_gateway_cloud_transport_register().  The matching
dispatcher helpers in src/gateway/cloud.c look up the active
transport and return -ENODEV when none is registered, keeping the
gateway core trivially testable.

A concrete CoAP transport is added in a later commit. This commit
only adds the abstraction.

Signed-off-by: Marcin Niestroj <marcin.niestroj@canonical.com>
Wire the gateway core and the gateway/gateway_custom_connect samples
to the new pouch CoAP stack.

Implement the pouch_gateway_cloud_transport vtable on top of the CoAP
client helpers, gated by CONFIG_POUCH_GATEWAY_CLOUD_TRANSPORT_COAP
(default y when both POUCH_GATEWAY and POUCH_TRANSPORT_COAP_CLIENT are
enabled).  The transport is registered by calling
pouch_coap_gateway_init() after pouch_coap_client_init().

Rewrite cert, uplink and downlink on top of the cloud vtable.  The
uplink now concatenates the full pouch into a pouch_buf and forwards
it through pouch_gateway_cloud_forward_pouch() in one call instead of
streaming block-by-block, dropping the bespoke block.[ch] pool in
favour of pouch_buf/blockbuf.

cert.c routes the device cert upload through the vtable and loads the
built-in server cert from a module_init() entry point instead of lazily on
connect. Move pouch/gateway/downlink.h into src/gateway/ since it is no
longer part of the public API.

Extract the Zephyr GATT broker sources into a dedicated subdirectory
CMakeLists, move the broker endpoint sources into the generic
transport library behind CONFIG_POUCH_GATEWAY, and link the gateway
library against the pouch core instead of re-adding it as a
subdirectory.  Make POUCH_GATEWAY depend on POUCH.

The samples load mTLS DTLS credentials from a LittleFS partition and
import the device private key into PSA, dropping the PSK flow.
Sysbuild gains GATEWAY_MOUNT_CREDS to mount a per-build creds volume
into native_sim, and the pytest harness for 'gateway' provisions an
EC keypair with a CA-signed device cert automatically.

Signed-off-by: Marcin Niestroj <marcin.niestroj@canonical.com>
Add native_sim ztest suites that exercise the gateway core directly
against a stub cloud transport and a malloc-backed blockbuf, without
pulling in Bluetooth or the broker GATT library.

The cloud suite covers transport registration and dispatcher fallbacks.
The uplink suite covers open/write/close including the resp_cb plumbing
and the cloud-disabled (-ENODEV) path.  The downlink suite covers
single- and multi-block paths, abort and end-on-error.

Signed-off-by: Marcin Niestroj <marcin.niestroj@canonical.com>
@mniestroj mniestroj force-pushed the coap-gateway-over-pouch branch from b1e9559 to adc4d4e Compare June 11, 2026 14:14
@mniestroj mniestroj marked this pull request as ready for review June 11, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant