Commit graph

60363 commits

Author SHA1 Message Date
dongjiuzhu1
314cccf166 drivers/timers/ptp: support ptp clock dummy driver
This patch adds a dummy PTP clock driver implementation that provides
a software-based PTP clock for testing and development purposes.

Key changes include:

1. Dummy PTP clock driver implementation:
   - Added drivers/timers/ptp_clock_dummy.c
   - Provides software-based PTP clock using system monotonic clock
   - Implements all required lower-half driver operations

2. Lower-half driver operations:
   - adjfine: Frequency adjustment (stores adjustment value)
   - adjtime: Time offset adjustment (applies delta to base time)
   - gettime: Returns current PTP clock time
   - settime: Sets PTP clock time
   - getcaps: Reports clock capabilities (1 billion PPB max adjustment)
   - getcrosststamp: Provides system/device cross-timestamp

3. Driver initialization:
   - Added ptp_clock_dummy_init() in drivers/drivers_initialize.c
   - Auto-registration under CONFIG_PTP_CLOCK_DUMMY configuration
   - Creates /dev/ptp0 character device node

4. Build system integration:
   - Added CONFIG_PTP_CLOCK_DUMMY Kconfig option (depends on PTP_CLOCK)
   - Updated CMakeLists.txt and Make.defs
   - Added include/nuttx/timers/ptp_clock_dummy.h header

5. Implementation details:
   - Uses clock_gettime(CLOCK_MONOTONIC) as time base
   - Tracks time offset and frequency adjustment internally
   - Suitable for testing PTP clock applications without hardware

This dummy driver enables development and testing of PTP clock applications
on platforms without dedicated PTP hardware support.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-12-30 10:22:09 -03:00
dongjiuzhu1
31eb339356 drivers/timers/ptp: support ptp clock driver model
This patch introduces the foundational PTP (Precision Time Protocol) clock
driver framework for NuttX, enabling precise time synchronization support
based on IEEE 1588 standard.

Key changes include:

1. New PTP clock driver infrastructure:
   - Added drivers/timers/ptp_clock.c implementing upper-half driver
   - Created include/nuttx/timers/ptp_clock.h with PTP clock interfaces
   - Implemented upper/lower half driver architecture for hardware abstraction

2. Core functionality:
   - Clock time get/set operations (gettime, settime)
   - Frequency adjustment support (adjtime, adjfine)
   - Phase adjustment capabilities
   - System-device cross-timestamping for precise synchronization

3. IOCTL commands:
   - PTP_CLOCK_SETTIME/GETTIME for time manipulation
   - PTP_CLOCK_GETRES for resolution queries
   - PTP_CLOCK_ADJTIME for time adjustment
   - PTP_CLOCK_GETCAPS for capability queries
   - PTP_SYS_OFFSET* for system offset measurements

4. Supporting structures:
   - struct ptp_lowerhalf_s: lower-half driver interface
   - struct ptp_clock_caps: clock capabilities descriptor
   - struct ptp_sys_offset: system time offset measurement
   - Added timex structures in include/sys/timex.h for ADJ_* operations

5. Build system integration:
   - Added CONFIG_PTP_CLOCK Kconfig option
   - Updated CMakeLists.txt and Make.defs
   - Added PTPCLK debug macros in include/debug.h

This framework provides the base for PTP clock implementations, allowing
hardware-specific drivers to register and provide precise time services
through a standardized interface.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-12-30 10:22:09 -03:00
Justin Erenkrantz
7298977894 risc-v/litex: Add 64-bit S-mode vexiiriscv support for litex.
Most of the peripheral support matches litex vexriscv-smp.

* arch/risc-v/Kconfig: Defer RV32 selection to core as litex board can do RV64.
* arch/risc-v/src/litex/Make.defs
  arch/risc-v/src/litex/hardware/litex_clint.h
  arch/risc-v/src/litex/hardware/litex_memorymap.h
  arch/risc-v/src/litex/hardware/litex_plic.h
  arch/risc-v/src/litex/litex_irq.c
  arch/risc-v/src/litex/litex_irq_dispatch.c: Add CONFIG_LITEX_CORE_VEXIIRISCV
  conditional where vexriscv_smp conditionals are.
* boards/risc-v/litex/arty_a7/configs/nsh-vexii/defconfig: New config.
* boards/risc-v/litex/arty_a7/include/vexii_irq.h: vexiiriscv irq defintion.
* boards/risc-v/litex/arty_a7/include/vexii_memorymap.h: vexiiriscv memory map.
* boards/risc-v/litex/arty_a7/scripts/ld.script: Define __global_pointer for
  toolchain happiness matching other RISC-V linker scripts.

(This commit was written with assistance from Claude Code.)

Signed-off-by: Justin Erenkrantz <justin@erenkrantz.com>
2025-12-30 10:18:57 -03:00
wenquan1
1f5cd930a4 net/arp: support ARP entry learned on gratuitous ARP response
learn arp when received gratuitiout arp

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:10:50 +08:00
wenquan1
7e4c3f4a60 net/arp: support ARP entry learned on gratuitous ARP response
learn arp when receive gratuitous arp response

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:10:50 +08:00
wenquan1
dfaed9b855 net/icmp: Support icmp timestamp request
When received a icmp timestamp request, send a icmp timestamp reply.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:05:46 +08:00
wenquan1
d2887ef15f net/tcp: fix send RST bug when receive syn retransmit in syn-rcvd state
Fix send RST bug when receive syn retransmit in syn-rcvd state

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
476e193812 net/tcp: ignore fin packet in syn-sent state
Ignore fin packet in syn-sent state

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
e3c2ab8267 net/tcp: drop the packet with neither SYN or RST flag set in syn-sent state
Drop the packet with neither SYN or RST flag set in syn-sent state

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
b09b5dfc9c net/tcp: ignore a RST control message in syn-send state
Ignore a RST control message in syn-send state

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
12de7e6dd5 net/tcp: ignore a segment carrying an unacceptable ACK and RST in syn-send state
Ignore a segment carrying an unacceptable ACK and RST in syn-send state

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
62f8c400b6 net/tcp: send a reset if the SYN is in the window buf error
According rfc793 p71, after step1 check OTW seq, and step2 check RST flag, then check syn flag.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
c4494c714c net/tcp: support OTW SEQ number check except SYN-SEND state
According rfc793 p69, from state SYN-RECEIVED to state TIME-WAIT, if the incoming segment is not acceptable, an acknowledgment should be sent in reply (unless the RST bit is set):
<SEQ=SND.NXT><ACK=RCV.NXT><CTL=ACK>

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
758b6dd847 net/tcp: support OTW SEQ number check in SYN-RCVD state
According rfc793 p69, In SYN-RCVD state, if the incoming segment is not acceptable, an acknowledgment should be sent in reply (unless the RST bit is set):
<SEQ=SND.NXT><ACK=RCV.NXT><CTL=ACK>

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
ee5009295c tcp_reset: Modify RST packet responses to comply with RFC 793.
According to RFC793, the flags of TCP reply packet should be as follows:
1. `RST` if flags of request packet has `ACK`
2. `RST|ACK` if flags of request packet has no `ACK`, at the same time, the sequence should be set to zero.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 11:44:38 +08:00
wenquan1
424a924f65 net/ipv6: Drop IP packet shorter than length in IP header
If the length of received ip packet is shorter than length in ip header, drop it.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 11:28:38 +08:00
zhanghongyu
6d916a4b0a arp_send: call arp_update before txnotify
if update is called after tx, in an environment with very low
latency (such as a simulator), the received arp_response will
be overwritten by update (NULL), resulting in arp learning success,
but the packets are always not sent correctly and are converted
into arp packets.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-30 11:28:22 +08:00
wenquan1
4ae08155f9 net/arp: limit arp request when arp is in progress to prevent ARP flooding
Wait a fixed number of milliseconds before sending a retry ARP request for the same destination if the IP address mapping is not exist to prevent ARP flooding

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 11:28:22 +08:00
wenquan1
6b30226c0e Revert "net/arp: modify some flow of arp return failure"
This reverts commit 2863f1d8d6da477dfef7013f93dd9b34efb4f378.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 11:28:22 +08:00
wenquan1
033299710f net/arp: fix the problem of arp notify and flood arp sending
when a arp response reached, it should notify all tasks waiting the address. if the address is unreachable, do not send arp request to prevent arp flooding.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 11:28:22 +08:00
gaohedong
ea31ceac23 net/ethernet: fix compilation issues
fix compilation issues

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-29 23:31:51 +08:00
wenquan1
c0fa2cae3d net/tcp: fix conn->work use after free in worker queue list
in multi-core cpu, tcp_free and tcp_timer_expiry->tcp_timer will work in parallel, after tcp_free call work_cancle, tcp->timer will call tcp_update_timer to re-add work to worker queue, then tcp_free free conn, in this condition, it will result use after free.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-29 22:42:49 +08:00
wenquan1
cc0cc552fc net/tcp: discard fin packet in LISTEN state
Discard fin packet in LISTEN state

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-29 22:42:23 +08:00
wangchen
302731ad1a docs: add ICMP ping guide (usage, options, examples)
Add index.rst: ping usage, flags (-c -i -W -s -I), output, examples, errors.

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2025-12-29 22:41:40 +08:00
wenquan1
fb7dcc3d89 net/tcp: fix error check of OTW ACK sequence of zero-window probe ack
Due to illegal sndseq_max increase when send zero-window probe or keealive probe

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-29 22:39:56 +08:00
wenquan1
74ab7816a1 net/tcp: send a reset if ack is not acceptable in syn-received state
In SYN-RCVD state, if the ACK is not acceptable, send a reset.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-29 22:39:56 +08:00
wenquan1
8ead446ee4 net/tcp: support OTW check and response with an empty acknowledgment segment
According RFC793,p72~p73 In states from ESTABLISHED to LASTACK:"If the ACK acks something not yet sent (SEG.ACK > SND.NXT) then send an ACK, drop the segment, and return"

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-29 22:39:56 +08:00
liqinhui
facb9d4e65 net/tcp: Initialize the sndseq_max.
Initialize conn->sndseq_max when tcp conn alloc

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2025-12-29 22:39:56 +08:00
zhanghongyu
a91c50243e net/tcp: send reset when retransmitted number greater than TCP_MAXRTX
in the current process, if tcpstate is at TCP_FIN_WAIT_1, TCP_CLOSING,
and TCP_LAST_ACK, and the peer does not reply TCP_ACK, it will be
retransmitted permanently. to avoid continuous occupation of resources,
now when the retransmission equals TCP_MAXRTX, a reset message will be
sent and the conn resources will be reclaimed in tcp_close_work.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 22:38:25 +08:00
wenquan1
11ea1de01d net/tcp: fix tcp conn lock leak when port in use in tcp_selectport
Fix tcp conn lock leak when port in use in tcp_selectport.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-29 10:33:18 -03:00
zhanghongyu
6addf24fa2 net/tcp: replace TCP_CLOSE with TCP_ABORT
since we added TCP_TXCLOSE and TCP_RXCLOSE, only RST-like exception
flows now trigger TCP_CLOSE events, so replace the remaining
TCP_CLOSE with TCP_ABORT.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 19:22:23 +08:00
zhanghongyu
fa47ab7bd2 net/tcp: add TCP_RXCLOSE to handle rx is shutdown
notify the local waiting recv process; otherwise, after the peer TX
is closed, the wait of the recv process will continue to wait.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 19:22:23 +08:00
zhanghongyu
2ad01e2aab net/tcp: support recv packet in the TCP_FIN_WAIT_1/2 state
shutdown should send TCP_FIN packet.

close should send TCP_RST packet when the data in readahead has not been
                                 read and NEW_DATA has arrived.
             send TCP_FIN packet when in other cases.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 19:22:23 +08:00
zhanghongyu
0588d08d75 net/tcp: remove SYN_RCVD state conn by listener created when free listener
after the listener fd is closed, the half-open connections associated
with the listener are not reclaimed. According to the protocol standard,
they should be reclaimed in a timely manner.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 19:20:01 +08:00
zhanghongyu
93cba3da64 net/tcp: add tcp_conn_cmp to compare tcp connection
encapsulate similar code into a function to simplify code logic.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 19:20:01 +08:00
gaohedong
8638e9ce43 net/devif: fix poll issue when ifdown
When the interface is in a down state, it triggers a poll busy loop issue.

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-29 19:18:55 +08:00
gaohedong
e1e6d8821e net/icmp: check src ip for icmp request message
Check src ip for icmp request message. Drop the request message if src ip is broadcast/multicast.

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-29 19:18:11 +08:00
Matteo Golin
0885b324a1 docs/cmocka: Fill out documentation for cmocka
Write documentation for cmocka.

Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
2025-12-29 19:16:21 +08:00
wenquan1
0891fa5cfb net/ipv4: Send ICMP Destination Unreachable for unknown protocol
According RFC1122 3.2.2.1, A host SHOULD generate Destination Unreachable messages with code: 2(Protocol Unreachable), when the designated transport protocol is not supported.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-29 19:15:57 +08:00
xuxingliang
cdd8032cb9 arch/armv8-m: Fix IRQ number corruption in exception_direct with O2 optimization
When compiling with O2 optimization, the compiler optimizes the code
in a way that causes irq variable to be corrupted. The getipsr()
function reads IPSR into r0, but the subsequent inline assembly that
sets FPSCR also uses r0 without declaring it as clobbered. This causes
the compiler to reuse r0 for the immediate value (0x40000), overwriting
the IRQ number read from IPSR.

The issue manifests as:
- getipsr() correctly reads IPSR (e.g., 0xf for IRQ 15)
- Compiler optimizes and reuses r0 for ARM_FPSCR_LTPSIZE_NONE (0x40000)
- irq variable gets the wrong value 0x40000 instead of actual IRQ number
- This leads to assertion failures in irq_dispatch due to invalid IRQ

Root cause analysis from disassembly:
  mrs r0, IPSR          ; Read IPSR to r0
  mov.w r0, #262144     ; Compiler overwrites r0 with 0x40000!
  vmsr fpscr, r0        ; Set FPSCR
  str r0, [sp, #4]      ; Store corrupted 0x40000 as irq
  ...
  ldr r0, [sp, #4]      ; Load corrupted value
  bl irq_dispatch       ; Call with wrong IRQ number 0x40000

Fix by adding r0 to the clobber list in the inline assembly, which
forces the compiler to save irq value before using r0 for FPSCR setup.

This issue only occurs at O2 optimization level and affects ARMv8-M
architecture with FPU enabled.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-12-29 19:15:21 +08:00
zhangshuai39
4eb222f0a7 netlib: Supplementing the netlib_check_ipconnectivity documentation
A brief introduction to the interface functions, parameters, and return values.

Signed-off-by: zhangshuai39 <zhangshuai39@xiaomi.com>
2025-12-29 19:14:59 +08:00
gaohedong
a5a29bdbbb net/ethernet: update all iob information in the iob_update_pktlen
Update io_len to 0 when pktlen is 0. otherwise, io_pktlen and io_len will be inconsistent, cause free check failure.

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-29 14:40:26 +08:00
gaohedong
ca7c6e2a6f net/arp: dont learn arp information if interface is noarp
Dont learn arp information from ip packet if interface is noarp

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-29 14:38:36 +08:00
gaohedong
7e6138f258 net/ioctl: add a socket interface for ioctl
Add a socket family for ioctl.

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-29 14:38:15 +08:00
zhanghongyu
b0ab56aca2 netdev_upperhalf: add direct rx mode
avoid packet processing delays caused by task switching,
to support those applications that are extremely time-sensitive.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 14:29:24 +08:00
Julian Oes
2a5de4ebc6 littlefs: fix statfs underflow during active writes
lfs_fs_size() can return more blocks than block_count during active
writes due to copy-on-write blocks. This caused f_bavail to underflow
to a large positive number. Add clamping to prevent this.

Signed-off-by: Julian Oes <julian@oes.ch>
2025-12-29 14:23:04 +08:00
zhanghongyu
0900b21217 net: change conn lock from mutex to rmutex
UDP and PKT will hold the dev lock and conn lock when calling back the
protocol stack from the network dirver. At this time, if the poll_notify
notifies usrsock_server and executes poll_teardown, a conn double lock
will appear. so we changed the lock to a recursive lock

sched_dumpstack
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/Libs/libc/sched/sched_dumpstack.c:71
__assert
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/libs/libc/assert/lib_assert.c:49
nxsem_wait_slow
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/sched/semaphore/sem_wait.c:102 (discriminator 1)
nxmutex_lock
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/include/nuttx/mutex.h:514
udp_pollteardown
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/udp/udp_netpoll.c:278
usrsock_rpmsg_poll_setup
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/usrsock/usrsock_rpmsg_server.c:1232
usrsock_rpmsg_poll_cb
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/usrsock/usrsock_rpmsg_server.c:1299
poll_notify
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/fs/vfs/fs_poll.c:296
udp_poll_eventhandler
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/udp/udp_netpoll.c:105
devif_conn_event
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/devif/devif_callback.c:481
udp_callback
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/udp/udp_callback.c:324
udp_input_conn
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/udp/udp_input.c:150
ipv4_in
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/devif/ipv4_input.c:425
ipv4_input
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/devif/ipv4_input.c:533
tun_net_receive_tun
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/net/tun.c:574
tun_net_receive_tun
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/net/tun.c:574
file_writev_compat
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/fs/vfs/fs_write.c:89
rpmsgdev_write_handler
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/misc/rpmsgdev_server.c:354
rpmsg_virtio_process_rx_buffer
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/rpmsg/rpmsg_virtio.c:256
rpmsg_virtio_rx_worker
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/rpmsg/rpmsg_virtio.c:291
work_dispatch
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/sched/wqueue/kwork_thread.c:233
work_thread
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/sched/wqueue/kwork_thread.c:293
nxtask_start
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/sched/task/task_start.c:99

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhanghongyu
3e18d72661 netdev_upperhalf.c: add vlan lock in rxpoll flow
Protect the RX process of the VLAN network card.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhanghongyu
c8713a1b48 net: protect the older network cards driver's tx and rx process
Add netdev_lock in xxx_input and txavail to adapt to drivers that do not
use upperhalf.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhanghongyu
6b625dfdf2 net/inet: replace net_lock with conn_lock
Protect icmp resources through conn_lock

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00