Skip to content

Add TCP Listen and Accept#196

Merged
MarkusLassila merged 2 commits into
nrfconnect:mainfrom
MarkusLassila:tcp-listen-accept
Mar 12, 2026
Merged

Add TCP Listen and Accept#196
MarkusLassila merged 2 commits into
nrfconnect:mainfrom
MarkusLassila:tcp-listen-accept

Conversation

@MarkusLassila
Copy link
Copy Markdown
Contributor

@MarkusLassila MarkusLassila commented Feb 27, 2026

Add AT#XLISTEN and AT#XACCEPT for TCP server functionality.

Jira: SM-240

@MarkusLassila MarkusLassila changed the title Tcp listen accept Add TCP Listen and Accept Feb 27, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds TCP server support to the Serial Modem AT socket layer by documenting and implementing AT#XLISTEN / AT#XACCEPT, plus extending AT#XSOCKET? output to include remote peer info for accepted sockets.

Changes:

  • Extend AT#XSOCKET? read response to optionally include accepted peer address/port.
  • Add AT#XLISTEN (listen) and AT#XACCEPT (accept) AT commands in implementation and docs.
  • Update unit tests and test harness wiring (AT wrapper routing + kernel alloc stubs) to cover listen/accept behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
doc/app/at_socket.rst Documents #XLISTEN / #XACCEPT and extends #XSOCKET? response format with peer info.
app/src/sm_at_socket.c Implements listen/accept, tracks bound port + listen state, and stores peer address for accepted sockets.
app/tests/at_socket/src/nrf_modem_at_wrapper.c Routes AT#XLISTEN / AT#XACCEPT to custom-command wrappers in tests.
app/tests/at_socket/src/test_at_socket.c Adds tests for listen/accept and updates socket-count assumptions.
app/tests/at_socket/CMakeLists.txt Links new kernel stubs into the at_socket test target.
app/tests/stubs/kernel_stubs.c Provides k_malloc/k_free stubs for the unit-test environment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/src/sm_at_socket.c
Comment thread app/src/sm_at_socket.c
Comment thread app/src/sm_at_socket.c Outdated
Comment thread app/src/sm_at_socket.c Outdated
Comment thread app/tests/at_socket/src/test_at_socket.c Outdated
Comment thread app/tests/at_socket/src/test_at_socket.c Outdated
Comment thread app/tests/at_socket/src/test_at_socket.c Outdated
Comment thread app/src/sm_at_socket.c Outdated
Copy link
Copy Markdown
Collaborator

@trantanen trantanen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going through doc and parts of code.

Comment thread app/tests/at_socket/src/test_at_socket.c Outdated
Comment thread app/src/sm_at_socket.c
Comment thread doc/app/at_socket.rst Outdated
Comment thread doc/app/at_socket.rst Outdated
Comment thread doc/app/at_socket.rst Outdated
Comment thread doc/app/at_socket.rst Outdated
Comment thread doc/app/at_socket.rst Outdated
Comment thread doc/app/at_socket.rst Outdated
Comment thread doc/app/at_socket.rst Outdated
Comment thread app/src/sm_at_socket.c Outdated
Comment thread app/src/sm_at_socket.c Outdated
Comment thread app/src/sm_at_socket.c Outdated
@MarkusLassila MarkusLassila force-pushed the tcp-listen-accept branch 3 times, most recently from ac3bea8 to 67ca2cf Compare March 10, 2026 14:22
@MarkusLassila MarkusLassila force-pushed the tcp-listen-accept branch 3 times, most recently from b323581 to 917689c Compare March 11, 2026 08:03
@MarkusLassila
Copy link
Copy Markdown
Contributor Author

@divipillai: Adding missing migration guide still

@MarkusLassila
Copy link
Copy Markdown
Contributor Author

@divipillai, migration guide added, feel free to review.

Comment thread doc/app/at_socket.rst Outdated
Comment thread app/tests/at_socket/src/test_at_socket.c Outdated
Comment thread app/tests/at_socket/src/test_at_socket.c
Comment thread app/tests/at_socket/src/test_at_socket.c Outdated
Comment thread doc/app/at_socket.rst Outdated
Comment thread doc/migration_notes.rst Outdated
Comment thread doc/app/at_socket.rst Outdated
Comment thread doc/app/at_socket.rst Outdated
Comment thread doc/app/at_socket.rst Outdated
Comment thread doc/app/at_socket.rst Outdated
Comment thread doc/migration_notes.rst
Comment thread doc/migration_notes.rst Outdated
@MarkusLassila MarkusLassila force-pushed the tcp-listen-accept branch 4 times, most recently from 10159f9 to caa864a Compare March 12, 2026 12:06
Add AT#XLISTEN and AT#XACCEPT for TCP server functionality.

Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
Basic unit tests for AT#XLISTEN and AT#XACCEPT.

Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
Copy link
Copy Markdown
Collaborator

@trantanen trantanen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to have this back 😄

Comment on lines +974 to +975
__cmock_nrf_accept_Stub(mock_nrf_accept_with_peer_callback);
__cmock_zsock_inet_ntop_Stub(mock_zsock_inet_ntop_192_168_0_100_callback);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if there is a reason why CMockReturnMemThruPtr wouldn't work here?
You can also skip this here now. I think we have places where we could probably use it more.

@MarkusLassila MarkusLassila merged commit f8d857d into nrfconnect:main Mar 12, 2026
3 checks passed
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.

5 participants