Repository navigation
feat(tuya-lan): add optional LAN 3.5 local control - #48
Draft
heshaoqiong-tuya wants to merge 3 commits into
Draft
heshaoqiong-tuya wants to merge 3 commits into
heshaoqiong-tuya wants to merge 3 commits into
Conversation
heshaoqiong-tuya
marked this pull request as draft
October 21, 2026 15:09
heshaoqiong-tuya
added a commit
that referenced
this pull request
Oct 21, 2026
Devices need local discovery and authenticated DP control using the same schema, values and callbacks as cloud controls, with application ownership of scheduling, lifecycle and every cloud report. Add an application-driven LAN 3.5 service with UDP discovery, bounded TCP Sessions, nonce authentication, per-Session keys, AES-GCM framing, replay checks, heartbeat replies, DP control/query, explicit status reports and an authenticated extension callback for P2P signaling. Applications own P2P negotiation and media transport. Share transactional local DP ingress through iot_client_apply_local_dps(): validate and stage the complete batch, commit atomically, mark dirty and invoke save/DP callbacks outside the lock. LAN never publishes MQTT or clears cloud dirty bits. Keep all platform capabilities in pal_t. Add optional IPv4 server/datagram callbacks directly in pal_posix.c and pal_freertos.c; accepted and connected TCP reuse send/receive/poll/close with one handle contract and matching allocator cleanup. Preserve nonblocking timeout-zero I/O and bounded positive timeouts. LAN takes the shared config.pal and checks its optional network group; base PAL validation keeps its existing callback requirements. Make LAN opt-in with AGENTIC_KIT_ENABLE_LAN and the ESP-IDF Kconfig option, both disabled by default. Keep pal_t layout independent of the switch; exclude optional networking code and leave those callbacks NULL when off. Align host/ESP-IDF source lists, POSIX demo, CI LAN-off builds, serial test registration, GitLab leak checks and pinned FreeRTOS header compilation. Document architecture, shared DP flows, callback ownership, queue semantics, resource budgets, lifecycle, build options and the P2P boundary in bilingual reference/architecture/porting guides. Register domain language, CONTEXT-MAP, ADR 0001, navigation, AGENTS.md and release notes linked to PR #48. BREAKING CHANGE: pal_t gains optional server/datagram members, extending its layout. Rebuild the SDK and all PAL consumers. Custom ports using LAN must implement the complete optional network group; other ports may leave it NULL. Verified: serial CTest LAN enabled 34/34 and disabled 29/29; full ASan/UBSan 34/34 suites; IoT DP 23/23, LAN protocol 12/12, service 6/6, independent encrypted peer 9/9 and POSIX/FreeRTOS network cases 7/7 each; pinned FreeRTOS C99 checks 5/5; ESP32-S3 translation-unit checks 3/3; standalone POSIX lan_demo builds; docs-site 2/2 locales, i18n parity 35/35 pages, document-link checks 2/2 and Mermaid syntax 6/6; git diff --check clean. Co-Authored-By: OpenAI Codex <noreply@openai.com>
heshaoqiong-tuya
force-pushed
the
feature/tuya-lan
branch
from
October 21, 2026 15:16
ce8660b to
c6bb9d4
Compare
heshaoqiong-tuya
added a commit
that referenced
this pull request
Oct 22, 2026
Devices need local discovery and authenticated DP control using the same schema, values and callbacks as cloud controls, with application ownership of scheduling, lifecycle and every cloud report. Add an application-driven LAN 3.5 service with UDP discovery, bounded TCP Sessions, nonce authentication, per-Session keys, AES-GCM framing, replay checks, heartbeat replies, DP control/query, explicit status reports and an authenticated extension callback for P2P signaling. Applications own P2P negotiation and media transport. Share transactional local DP ingress through iot_client_apply_local_dps(): validate and stage the complete batch, commit atomically, mark dirty and invoke save/DP callbacks outside the lock. LAN never publishes MQTT or clears cloud dirty bits. Keep all platform capabilities in pal_t. Add optional IPv4 server/datagram callbacks directly in pal_posix.c and pal_freertos.c; accepted and connected TCP reuse send/receive/poll/close with one handle contract and matching allocator cleanup. Preserve nonblocking timeout-zero I/O and bounded positive timeouts. LAN takes the shared config.pal and checks its optional network group; base PAL validation keeps its existing callback requirements. Share length-bounded JSON lexical checks before cJSON normalization so LAN and local DP ingress enforce one set of UTF-8, escape, surrogate and number rules. Keep structure and domain validation with their owning modules. Share bounded C-string checks while preserving each API's existing limits. Use socket handle names that cover TCP, listeners and UDP; log handle allocation failures explicitly while retaining the existing PAL error codes. Route business-service logs through BIZ_LOG* and the lower-only AGENTIC_KIT_BIZ_LOG_LEVEL ceiling. Share private typed-list decoding and failure cleanup across role, language and timbre queries, retaining their result contracts. Cover allocation failures, partial lists, string boundaries, Unicode inputs and log configurations with registered regression checks. Make LAN opt-in with AGENTIC_KIT_ENABLE_LAN and the ESP-IDF Kconfig option, both disabled by default. Keep pal_t layout independent of the switch; exclude optional networking code and leave those callbacks NULL when off. Align host/ESP-IDF source lists, POSIX demo, CI LAN-off builds, serial test registration, GitLab leak checks and pinned FreeRTOS header compilation. Document architecture, shared DP flows, callback ownership, queue semantics, resource budgets, lifecycle, build options and the P2P boundary in bilingual reference/architecture/porting guides. Register domain language, CONTEXT-MAP, ADR 0001, navigation, AGENTS.md and release notes linked to PR #48. BREAKING CHANGE: pal_t gains optional server/datagram members, extending its layout. Rebuild the SDK and all PAL consumers. Custom ports using LAN must implement the complete optional network group; other ports may leave it NULL. Verified: serial CTest LAN enabled 37/37 and disabled 32/32; full ASan/UBSan 37/37 suites; IoT DP 24/24, business roles 16/16, business log compile matrix 38/38, shared JSON lexical cases 82/82 (4 groups), bounded string groups 3/3, LAN protocol 12/12, service 7/7, independent encrypted peer 10/10 and POSIX/FreeRTOS network cases 7/7 each; pinned FreeRTOS C99 checks 5/5; ESP32-S3 translation-unit checks 3/3; standalone POSIX lan_demo and role_management_demo build; docs-site 2/2 locales, i18n parity 35/35 pages and document-link checks 2/2; git diff --check clean. Co-Authored-By: OpenAI Codex <noreply@openai.com>
heshaoqiong-tuya
force-pushed
the
feature/tuya-lan
branch
from
October 22, 2026 02:10
c6bb9d4 to
24c6c9d
Compare
heshaoqiong-tuya
added a commit
that referenced
this pull request
Oct 22, 2026
Devices need local discovery and authenticated DP control using the same schema, values and callbacks as cloud controls, with application ownership of scheduling, lifecycle and every cloud report. Add an application-driven LAN 3.5 service with UDP discovery, bounded TCP Sessions, nonce authentication, per-Session keys, AES-GCM framing, replay checks, heartbeat replies, DP control/query, explicit status reports and an authenticated extension callback for P2P signaling. Applications own P2P negotiation and media transport. Share transactional local DP ingress through iot_client_apply_local_dps(): validate and stage the complete batch, commit atomically, mark dirty and invoke save/DP callbacks outside the lock. LAN never publishes MQTT or clears cloud dirty bits. Keep all platform capabilities in pal_t. Add optional IPv4 server/datagram callbacks directly in pal_posix.c and pal_freertos.c; accepted and connected TCP reuse send/receive/poll/close with one handle contract and matching allocator cleanup. Preserve nonblocking timeout-zero I/O and bounded positive timeouts. LAN takes the shared config.pal and checks its optional network group; base PAL validation keeps its existing callback requirements. Share length-bounded JSON lexical checks before cJSON normalization so LAN and local DP ingress enforce one set of UTF-8, escape, surrogate and number rules. Keep structure and domain validation with their owning modules. Share bounded C-string checks while preserving each API's existing limits. Use socket handle names that cover TCP, listeners and UDP; log handle allocation failures explicitly while retaining the existing PAL error codes. Route business-service logs through BIZ_LOG* and the lower-only AGENTIC_KIT_BIZ_LOG_LEVEL ceiling. Share private typed-list decoding and failure cleanup across role, language and timbre queries, retaining their result contracts. Cover allocation failures, partial lists, string boundaries, Unicode inputs and log configurations with registered regression checks. Make LAN opt-in with AGENTIC_KIT_ENABLE_LAN and the ESP-IDF Kconfig option, both disabled by default. Keep pal_t layout independent of the switch; exclude optional networking code and leave those callbacks NULL when off. Align host/ESP-IDF source lists, POSIX demo, CI LAN-off builds, serial test registration, GitLab leak checks and pinned FreeRTOS header compilation. Document architecture, shared DP flows, callback ownership, queue semantics, resource budgets, lifecycle, build options and the P2P boundary in bilingual reference/architecture/porting guides. Register domain language, CONTEXT-MAP, ADR 0001, navigation, AGENTS.md and release notes linked to PR #48. BREAKING CHANGE: pal_t gains optional server/datagram members, extending its layout. Rebuild the SDK and all PAL consumers. Custom ports using LAN must implement the complete optional network group; other ports may leave it NULL. Verified: serial CTest LAN enabled 37/37 and disabled 32/32; full ASan/UBSan 37/37 suites; IoT DP 24/24, business roles 16/16, business log compile matrix 38/38, shared JSON lexical cases 82/82 (4 groups), bounded string groups 3/3, LAN protocol 12/12, service 7/7, independent encrypted peer 10/10 and POSIX/FreeRTOS network cases 7/7 each; pinned FreeRTOS C99 checks 5/5; ESP32-S3 translation-unit checks 3/3; standalone POSIX lan_demo and role_management_demo build; docs-site 2/2 locales, i18n parity 35/35 pages and document-link checks 2/2; git diff --check clean. Co-Authored-By: OpenAI Codex <noreply@openai.com>
heshaoqiong-tuya
force-pushed
the
feature/tuya-lan
branch
from
October 22, 2026 02:11
24c6c9d to
b718474
Compare
heshaoqiong-tuya
added a commit
that referenced
this pull request
Oct 28, 2026
Devices need local discovery and authenticated DP control using the same schema, values and callbacks as cloud controls, with application ownership of scheduling, lifecycle and every cloud report. Add an application-driven LAN 3.5 service with UDP discovery, bounded TCP Sessions, nonce authentication, per-Session keys, AES-GCM framing, replay checks, heartbeat replies, DP control/query, explicit status reports and an authenticated extension callback for P2P signaling. Applications own P2P negotiation and media transport. Share transactional local DP ingress through iot_client_apply_local_dps(): validate and stage the complete batch, commit atomically, mark dirty and invoke save/DP callbacks outside the lock. LAN never publishes MQTT or clears cloud dirty bits. Keep all platform capabilities in pal_t. Add optional IPv4 server/datagram callbacks directly in pal_posix.c and pal_freertos.c; accepted and connected TCP reuse send/receive/poll/close with one handle contract and matching allocator cleanup. Preserve nonblocking timeout-zero I/O and bounded positive timeouts. LAN takes the shared config.pal and checks its optional network group; base PAL validation keeps its existing callback requirements. Share length-bounded JSON lexical checks before cJSON normalization so LAN and local DP ingress enforce one set of UTF-8, escape, surrogate and number rules. Keep structure and domain validation with their owning modules. Share bounded C-string checks while preserving each API's existing limits. Use socket handle names that cover TCP, listeners and UDP; log handle allocation failures explicitly while retaining the existing PAL error codes. Route business-service logs through BIZ_LOG* and the lower-only AGENTIC_KIT_BIZ_LOG_LEVEL ceiling. Share private typed-list decoding and failure cleanup across role, language and timbre queries, retaining their result contracts. Cover allocation failures, partial lists, string boundaries, Unicode inputs and log configurations with registered regression checks. Make LAN opt-in with AGENTIC_KIT_ENABLE_LAN and the ESP-IDF Kconfig option, both disabled by default. Keep pal_t layout independent of the switch; exclude optional networking code and leave those callbacks NULL when off. Align host/ESP-IDF source lists, POSIX demo, CI LAN-off builds, serial test registration, GitLab leak checks and pinned FreeRTOS header compilation. Document architecture, shared DP flows, callback ownership, queue semantics, resource budgets, lifecycle, build options and the P2P boundary in bilingual reference/architecture/porting guides. Register domain language, CONTEXT-MAP, ADR 0001, navigation, AGENTS.md and release notes linked to PR #48. BREAKING CHANGE: pal_t gains optional server/datagram members, extending its layout. Rebuild the SDK and all PAL consumers. Custom ports using LAN must implement the complete optional network group; other ports may leave it NULL. Verified: serial CTest LAN enabled 37/37 and disabled 32/32; full ASan/UBSan 37/37 suites; IoT DP 24/24, business roles 16/16, business log compile matrix 38/38, shared JSON lexical cases 82/82 (4 groups), bounded string groups 3/3, LAN protocol 12/12, service 7/7, independent encrypted peer 10/10 and POSIX/FreeRTOS network cases 7/7 each; pinned FreeRTOS C99 checks 5/5; ESP32-S3 translation-unit checks 3/3; standalone POSIX lan_demo and role_management_demo build; docs-site 2/2 locales, i18n parity 35/35 pages and document-link checks 2/2; git diff --check clean. Co-Authored-By: OpenAI Codex <noreply@openai.com>
heshaoqiong-tuya
force-pushed
the
feature/tuya-lan
branch
from
October 28, 2026 03:32
b718474 to
92202ad
Compare
heshaoqiong-tuya
added a commit
that referenced
this pull request
Oct 28, 2026
Devices need local discovery and authenticated DP control using the same schema, values and callbacks as cloud controls, with application ownership of scheduling, lifecycle and every cloud report. Add an application-driven LAN 3.5 service with UDP discovery, bounded TCP Sessions, nonce authentication, per-Session keys, AES-GCM framing, replay checks, heartbeat replies, DP control/query, explicit status reports and an authenticated extension callback for P2P signaling. Applications own P2P negotiation and media transport. Share transactional local DP ingress through iot_client_apply_local_dps(): validate and stage the complete batch, commit atomically, mark dirty and invoke save/DP callbacks outside the lock. LAN never publishes MQTT or clears cloud dirty bits. Keep all platform capabilities in pal_t. Add optional IPv4 server/datagram callbacks directly in pal_posix.c and pal_freertos.c; accepted and connected TCP reuse send/receive/poll/close with one handle contract and matching allocator cleanup. Preserve nonblocking timeout-zero I/O and bounded positive timeouts. LAN takes the shared config.pal and checks its optional network group; base PAL validation keeps its existing callback requirements. Share length-bounded JSON lexical checks before cJSON normalization so LAN and local DP ingress enforce one set of UTF-8, escape, surrogate and number rules. Keep structure and domain validation with their owning modules. Share bounded C-string checks while preserving each API's existing limits. Use socket handle names that cover TCP, listeners and UDP; log handle allocation failures explicitly while retaining the existing PAL error codes. Route business-service logs through BIZ_LOG* and the lower-only AGENTIC_KIT_BIZ_LOG_LEVEL ceiling. Share private typed-list decoding and failure cleanup across role, language and timbre queries, retaining their result contracts. Cover allocation failures, partial lists, string boundaries, Unicode inputs and log configurations with registered regression checks. Make LAN opt-in with AGENTIC_KIT_ENABLE_LAN and the ESP-IDF Kconfig option, both disabled by default. Keep pal_t layout independent of the switch; exclude optional networking code and leave those callbacks NULL when off. Align host/ESP-IDF source lists, POSIX demo, CI LAN-off builds, serial test registration, GitLab leak checks and pinned FreeRTOS header compilation. Document architecture, shared DP flows, callback ownership, queue semantics, resource budgets, lifecycle, build options and the P2P boundary in bilingual reference/architecture/porting guides. Register domain language, CONTEXT-MAP, ADR 0001, navigation, AGENTS.md and release notes linked to PR #48. BREAKING CHANGE: pal_t gains optional server/datagram members, extending its layout. Rebuild the SDK and all PAL consumers. Custom ports using LAN must implement the complete optional network group; other ports may leave it NULL. Verified: serial CTest LAN enabled 37/37 and disabled 32/32; full ASan/UBSan 37/37 suites; IoT DP 24/24, business roles 16/16, business log compile matrix 38/38, shared JSON lexical cases 82/82 (4 groups), bounded string groups 3/3, LAN protocol 12/12, service 7/7, independent encrypted peer 10/10 and POSIX/FreeRTOS network cases 7/7 each; pinned FreeRTOS C99 checks 5/5; ESP32-S3 translation-unit checks 3/3; standalone POSIX lan_demo and role_management_demo build; docs-site 2/2 locales, i18n parity 35/35 pages and document-link checks 2/2; git diff --check clean. Co-Authored-By: OpenAI Codex <noreply@openai.com>
heshaoqiong-tuya
force-pushed
the
feature/tuya-lan
branch
from
October 28, 2026 05:44
92202ad to
3cc3ead
Compare
Activated devices need App discovery and authenticated local DP control with application-owned scheduling, lifecycle and cloud reporting. Add an opt-in LAN 3.5 service with UDP queries and five-second announcements, bounded TCP Sessions, nonce/HMAC authentication, per-Session AES-GCM keys, replay checks, heartbeats, DP control/query, explicit reports and extensions. Reply to discovery at the App's fixed port and add the configured devId to query replies. Document the explicit TuyaOpen compatibility differences. Fail immediately on protocol, JSON, callback, resource and targeted send or report errors without queuing an error ACK. Reject unexpected messages before authentication, including inbound TYPE4. Close sockets immediately inside callbacks, defer object reclamation until their stacks unwind and stop dispatching subsequent coalesced Frames after a failure. Preserve retryable PAL_ERR_AGAIN and positive partial I/O. Share transactional local DP ingress through iot_client_apply_local_dps(): validate the whole batch, commit atomically, mark dirty and invoke existing callbacks outside the lock. Share bounded lexical/string checks with LAN. The application owns MQTT publication and channel reporting. Extend the shared PAL with optional server/datagram callbacks and matching POSIX/FreeRTOS handle allocation, nonblocking I/O and failure diagnostics. Integrate local DP and business-service diagnostics through the module log facades; consolidate business list decoding and regression cleanup. Wire both build paths, LAN-off checks, serial tests, leak checks and the POSIX demo, and document domain contracts, ADRs and bilingual integration guides. BREAKING CHANGE: pal_t gains optional server/datagram members. Rebuild the SDK and PAL consumers. Custom LAN ports must implement the complete group. Verified on the final combined tree: serial CTest 40/40; LAN API cases 8/8, protocol groups 22/22 and service cases 7/7; targeted ASan/UBSan CTest 5/5; documentation builds 2/2 locales, i18n parity 36/36 and link tests 2/2. Co-Authored-By: OpenAI Codex <noreply@openai.com>
Route SDK buffers through the ESP-IDF capability allocator, preferring PSRAM and falling back to internal RAM when unavailable or exhausted. Require MALLOC_CAP_8BIT in both preferences so strings, cJSON and crypto buffers cannot select 32-bit-only IRAM. Pair either allocation with heap_caps_free while retaining the FreeRTOS heap on other platforms. Exercise the production ESP_PLATFORM branch with capability-aware heap regressions, register the binary for CTest and leak checks, and document the allocation policy in both porting guides and the changelog. Verified: allocator regressions 4/4; normal and ASan/UBSan allocator CTest 1/1 each; documentation builds 2/2 locales. Co-Authored-By: Claude Code <noreply@anthropic.com> Co-Authored-By: OpenAI Codex <noreply@openai.com>
Increase the default cloud HTTP completion budget from five to ten seconds so requests have longer to finish before the SDK reports a timeout. Keep this independent cloud policy change separate from LAN protocol behavior, and record the changed default in the unreleased changelog. Verified: full serial CTest 40/40; targeted ASan/UBSan CTest 5/5. Co-Authored-By: OpenAI Codex <noreply@openai.com>
heshaoqiong-tuya
force-pushed
the
feature/tuya-lan
branch
from
November 3, 2026 12:51
3cc3ead to
b107ce8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add optional Tuya LAN 3.5 local control for activated devices, including discovery, Session authentication, DP control/query, heartbeat replies and explicit status reports.
pal_t, with POSIX and FreeRTOS implementations. Accepted TCP connections reuse existing send, receive, poll and close callbacks.Migration
Rebuild the SDK and all PAL consumers after the
pal_tlayout extension. Custom ports enabling LAN must implement the complete optional networking callback group.