drivers: modem: sim7080: handle F_GETFL/F_SETFL in offload_ioctl - #117364
drivers: modem: sim7080: handle F_GETFL/F_SETFL in offload_ioctl#117364dafiest-hub wants to merge 1 commit into
Conversation
The native TLS socket layer calls zsock_fcntl(F_GETFL) on the underlying offloaded socket to clear and restore O_NONBLOCK around the TLS handshake (ztls_connect_ctx), before issuing the underlying connect. offload_ioctl() only handled the poll ioctls, so the fcntl failed with EINVAL and any connection over TLS-native sockets on top of this driver aborted before AT+CAOPEN was ever sent, with only a confusing "AT+CACLOSE=0 ret: -5" from the cleanup path in the log. Handle ZVFS_F_GETFL and ZVFS_F_SETFL by returning 0: the offloaded socket is always blocking and non-blocking reads are requested per call via MSG_DONTWAIT. This is the same approach used by the ublox-sara-r4 and hl78xx drivers. Tested on SIM7080G (Cat-M1) hardware against an MQTT broker on port 8883 with CONFIG_NET_SOCKETS_SOCKOPT_TLS=y and CONFIG_MQTT_LIB_TLS=y: without this change mqtt_connect() always fails with -EINVAL; with it the TLS handshake and MQTT session complete normally. Note: this issue was diagnosed and the fix developed with the assistance of an AI tool; the change was reviewed and verified on real hardware by the author. Assisted-by: AI tool (Claude Code) Signed-off-by: Angel Covarrubias <angelcovarrubias319@gmail.com>
|
Hello @dafiest-hub, and thank you very much for your first Pull Request (PR) to the Zephyr Project! All PRs must pass our Continuous Integration (CI) pipeline before merging. When the pipeline run for your PR completes, you are expected to investigate the results, fix any errors, and update your PR for a fresh round of review. Since this is your first contribution, a project community member must manually approve your CI run (this helps us avoid abuse of our CI system). A bot should assign some reviewers who can start the run for you soon. As a heads-up, you will probably have to update your PR to fix CI issues and address review feedback in order to get it ready for merge. Some key rules for updating your PR are:
Also, see:
If you are stuck or need help, you can join us on Discord and ask questions; many community members try to help new contributors there 😊. Try to pick a Discord channel that is associated with the technical details of your request. If you're not sure, use the #general channel. |
Problem
With
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y(native TLS over the offloaded socket, e.g.CONFIG_MQTT_LIB_TLS=y), every connection attempt over the SIM7080 driver fails beforeAT+CAOPENis ever sent. The only visible symptom is a confusing cleanup-path error:Root cause
ztls_connect_ctx()(subsys/net/lib/sockets/sockets_tls.c) callszsock_fcntl(F_GETFL)on the underlying offloaded socket to clear/restoreO_NONBLOCKaround the TLS handshake, before issuing the underlyingconnect(). The driver'soffload_ioctl()only handles the three poll ioctls, soF_GETFLhits thedefault:branch (errno = EINVAL, return -1). The TLS layer then aborts the connect, the socket is closed (producing theAT+CACLOSE=0on a socket that was never opened), andmqtt_connect()surfaces-EINVAL.Fix
Handle
ZVFS_F_GETFLandZVFS_F_SETFLby returning 0: the offloaded socket is always blocking, and non-blocking reads are requested per call viaMSG_DONTWAIT. This is the same approach used by theublox-sara-r4andhl78xxdrivers.Testing
Tested on SIM7080G (Cat-M1, Telcel MX) hardware on
esp32_devkitc/esp32/procpu, connecting to an EMQX broker on port 8883 withCONFIG_NET_SOCKETS_SOCKOPT_TLS=y+CONFIG_MQTT_LIB_TLS=y(mbedTLS in software over the plain-TCP offload): without this changemqtt_connect()always fails with-EINVAL; with it the TLS handshake completes and the MQTT session (CONNACK, QoS1 subscribe/publish) runs normally.Disclosure
This issue was diagnosed and the fix developed with the assistance of an AI tool (Claude Code); the change was reviewed and verified on real hardware by the author.
🤖 Generated with Claude Code
https://claude.ai/code/session_01P1pQeLhNjvsTrXARmZ3LwK