163 Commits

Author SHA1 Message Date
Piyush Patle 0dccc8ba21 include/debug.h: Move to include/nuttx/debug.h
debug.h is a NuttX-specific, non-POSIX header. Placing it in the
top-level include/ directory creates naming conflicts with external
projects that define their own debug.h.
This commit moves the canonical header to include/nuttx/debug.h,
following the NuttX convention for non-POSIX/non-standard headers,
and updates all in-tree references.

A backward-compatibility shim is left at include/debug.h that
emits a deprecation #warning and re-includes <nuttx/debug.h>,
allowing out-of-tree code to continue building while migrating.

Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
2026-04-07 07:50:06 -03:00
zhangyuan29 c99fa1994f net/utils: add union name for tasking compiler compatibility
Some compilers like Tasking do not support anonymous unions/structs.
Add explicit names to the anonymous union and struct members in
snoop_packet_header_s and update all references accordingly.

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
2026-02-12 10:49:44 -03:00
zhanghongyu aee7ea0d7d net/utils: conn_dev_sem_timedwait supports the input parameter sconn being NULL
thus supporting scenarios that only require break netdev_lock.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 07:48:06 -03:00
zhanghongyu 11c4bb7f31 utils.h: add conn_dev_sem_timedwait interface to simplify code logic
the following code can be modified

  conn_dev_unlock(&conn->sconn, conn->dev);
  ret = net_sem_timedwait_uninterruptible(&conn->snd_sem,
    tcp_send_gettimeout(start, timeout));
  conn_dev_lock(&conn->sconn, conn->dev);
to

  ret = conn_dev_sem_timedwait(&conn->snd_sem, false,
    tcp_send_gettimeout(start, timeout), &conn->sconn, conn->dev);

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 07:48:06 -03:00
zhanghongyu b8850e4eb3 conn_lock: inline conn_lock/conn_dev_lock
modify functions that are simple but frequently called into inline
functions, thereby reducing CPU loading without significantly changing
the code size.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 07:48:06 -03:00
zhanghongyu f27a9bbc27 net/usrsock: replace net_lock with usrsock_lock
Build Documentation / build-html (push) Has been cancelled
remove the use of net_lock in the usrsock module and decouple it from
other network modules.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-01 07:35:12 -03:00
zhanghongyu 24ee7cba86 net_lock: add net_sem_timedwait2, passing in rmutex that needs to be break
two rmutexes can be passed in, and later the wait scenarios that require
break the conn and netdev locks will be replaced.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-01 07:35:12 -03:00
zhanghongyu 0900b21217 net: change conn lock from mutex to rmutex
Build Documentation / build-html (push) Has been cancelled
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 eb60667561 net/utils/net_lock.c: add api to lock conn and netdev
add new api to protect access and operation to conn and dev

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhangshuai39 c44834fb92 nuttx/net: Expose the net_ipv6addr_maskcmp interface to user-mode calls
This interface needs to be called in the libc library, but the interface is implemented in the kernel, so this interface needs to be exposed

Signed-off-by: zhangshuai39 <zhangshuai39@xiaomi.com>
2025-12-25 22:13:43 +08:00
zhanghongyu 908596dde3 net/bufpool: fix typo
A previous spelling mistake has been detected. fix it

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-25 08:33:13 -03:00
zhanghongyu e87082b195 net/utils/net_bufpool: add lock to struct net_bufpool_s and bufpool_navail
Add a lock to net_bufpool to simplify the protocol stack code.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-07 11:11:21 +08:00
wangchen 678164bf4e net_bufpool.c:when timeout value is zero,It don't break netlock
Resolve some timing issues caused by calling net_breaklock to release netlock in the function NET_BUFPOOL_TRYALLOC

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2025-11-10 22:30:37 -05:00
dongjiuzhu1 a5485d6c53 net/utils: avoid unalign access g_tcp_connections_buffer
the address is 0x3c270203, cause unaligned access usage Fault
(gdb) p g_tcp_connections
$1 = {pool = 0x3c270203 <g_tcp_connections_buffer> <error: Cannot access memory at address 0x3c270203>,
prealloc = 8, dynalloc = 1, nodesize = -376, sem = {semcount = 32767, flags = 0 '\000',
waitlist = {head = 0x0, tail = 0x0}}, freebuffers = {head = 0x0, tail = 0x0}}

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-09 08:04:21 -03:00
raiden00pl 9aab92e3cf net: unify Private Types banners
unify Private Types banners according to NuttX coding standard

Signed-off-by: raiden00pl <raiden00@railab.me>
2025-05-28 10:17:15 +08:00
Lars Kruse 3ce85ca54e style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
Zhe Weng 50b3ab7671 net/bufpool: Call init automatically on alloc
Note: Initialize function of protocols (tcp, udp, pkt, etc.) are kept empty.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-01-07 22:00:21 +08:00
Zhe Weng f702f1705f net/bufpool: Use SEM_INITIALIZER to init sem
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-01-07 22:00:21 +08:00
Zhe Weng 84d261e3be net: Optimize ipfwd and wrbuffer by buffer pool
To allow dynamic allocation of these structs, performance keeps the same
as the previous implementation.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-12-23 16:57:19 -03:00
Zhe Weng 1fe07d0838 net: Add buffer pool to replace connection allocation
Our net socket connection allocations are powerful but redundant
because they're implemented once in each protocol.  This is not good for
further optimizing and extending to other allocations, so maybe we can
add a common implementation for the usage.

Impact:
1. We add a `struct net_bufpool_s` as pool descriptor, which may use a
   little bit more memory than previous implementation (~28Bytes).
2. We share same functions between pools, so code size may shrink under
   some scenarios.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-12-23 16:57:19 -03:00
ouyangxiangzhen 17c51c0667 userspace: Exclude nuttx/arch.h
This patch fixed userspace headers conflict. Architecture-related definition and API should not be exposed to users.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-11-01 16:59:37 +08:00
Xiang Xiao 32784b0898 libc: Refine the arc4random_buf implementation
fill the buffer with getrandom instead random pool
and move the implementation to from crypto to libc

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-26 18:04:21 -03:00
hujun5 a567148888 sched: add up_this_task and up_change_task macro stub
reason:
We can utilize percpu storage to hold information about the
current running task. If we intend to implement this feature, we would
need to define two macros that help us manage this percpu information
effectively.

up_this_task: This macro is designed to read the contents of the percpu
              register to retrieve information about the current
              running task.This allows us to quickly access
              task-specific data without having to disable interrupts,
              access global variables and obtain the current cpu index.

up_update_task: This macro is responsible for updating the contents of
                the percpu register.It is typically called during
                initialization or when a context switch occurs to ensure
                that the percpu register reflects the information of the
                newly running task.

Configuring NuttX and compile:
$ ./tools/configure.sh -l qemu-armv8a:nsh_smp
$ make
Running with qemu
$ qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic \
   -machine virt,virtualization=on,gic-version=3 \
   -net none -chardev stdio,id=con,mux=on -serial chardev:con \
   -mon chardev=con,mode=readline -kernel ./nuttx

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-15 15:25:55 +08:00
Alin Jerpelea 67d02a45eb net: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-09-12 01:08:11 +08:00
Petro Karashchenko 1528b8dcca nuttx: resolve various 'FAR' and 'CODE' issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2024-08-26 10:21:03 +08:00
Petro Karashchenko d499ac9d58 nuttx: fix multiple 'FAR', 'CODE' and style issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2024-08-25 19:22:15 +08:00
daichuan fe01d7c462 modify for offload checksum and add macro with tcp/icmp/icmpv6/igmp checksum
Signed-off-by: daichuan <daichuan@xiaomi.com>
2024-08-24 20:41:40 +08:00
wangchen ff7eda46e7 net_chksum.c:mod process of generating sum to solve checksum error
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-08-21 01:38:23 +08:00
Zhe Weng e543a8086e net: Optimize TCP/UDP port selection
Optimize TCP/UDP port selection, and fix possibly dead loop.

Finish discussion in https://github.com/apache/nuttx/pull/12116#discussion_r1560851977

Note:
Linux also uses EADDRINUSE for failing in finding a portno, according to https://man7.org/linux/man-pages/man2/bind.2.html

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-12 15:46:29 +08:00
Zhe Weng 676826cb7c net/utils: Add net_ipv6_payload to get IPv6 L4 payload
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-11 22:23:29 +08:00
Zhe Weng 4c99ad1ba9 net/utils: Switch argument order of net_ipv6_pref2mask
When implementing IPv6-related logic, we found the `net_ipv6_pref2mask`
and `net_ipv6addr_copy` are using different argument order:
```
net_ipv6addr_copy(ifaddr->addr, addr);
net_ipv6_pref2mask(preflen, ifaddr->mask);
```
Change the order to:
```
net_ipv6addr_copy(ifaddr->addr, addr);
net_ipv6_pref2mask(ifaddr->mask, preflen);
```

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-07 19:30:36 +08:00
Zhe Weng 96233e0c42 net/netdev: Support multiple IPv6 addresses per device
Compatible with previous usage, because may network drivers are using old member name to print logs, and there's no significant need to change them now.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-07 19:30:36 +08:00
Zhe Weng c7845f5b25 netlink: Explicitly set ip address for netlink notify
Prepare for multiple IPv6 addresses per net device, then we can notify
add/remove of a single address later.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-07 19:30:36 +08:00
Zhe Weng 5096a2c9fd net/tcp: Take out get random process as common function
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-06 09:04:09 +08:00
Zhe Weng ef1ad691c3 net/icmpv6: Fix net mask logic in icmpv6_setaddresses
1. Both IPv6 addresses and net masks should be stored in network byte
   order
2. Fix last 2 bytes of mask applying (although it seldom triggers)

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-10-24 10:31:14 -03:00
wanggang26 d827ee5ffc refine: set file mode when oflags contains O_CREAT
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-09-23 15:20:51 +08:00
wanggang26 e930476b4b enable O_CLOEXEC explicit
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-09-22 13:51:00 +08:00
hujun5 34dcd1c50a net: remove [enter|leave]_critical_section and sched_[un]lock
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-08-10 12:24:30 +03:00
Zhe Weng 4b7604cf81 net: Rename tcp_dataconcat to net_iob_concat
Allow other protocols like UDP to use concat logic.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-07-18 10:51:45 +08:00
chao an 6ee9ec7656 build: add initial cmake build system
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:50:48 +08:00
Xiang Xiao 8d56a9bbcb Remove #warning if the code already return the error code or value
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-18 15:44:28 +03:00
Ville Juven 1e9560e1e5 net/net_cmsg.c: Fix warning about using void* arithmetics
utils/net_cmsg.c: In function 'cmsg_append':
utils/net_cmsg.c:82:23: error: pointer of type 'void *' used in arithmetic [-Werror=pointer-arith]
   82 |   msg->msg_control    += cmsgspace;
      |                       ^~
cc1: all warnings being treated as errors

Using void pointers in arithmetic operations is a GCC extension, it is
not supported by the standard. Because what is the size of a void ?
2023-05-10 17:58:25 +08:00
zhanghongyu c288752bef recvmsg: control msg support multi-attribute return
adapts to third-party code compilation. in the process of porting ConnMan,
multiple control message options are enabled, such as IPV6_RECVPKTINFO and
IPV6_RECVHOPLIMIT, so I changed the Filling implementation of the control
message.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-04 12:04:11 +02:00
zhangyuan21 c239d19df0 nuttx: add more dependent header file
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-04-11 09:13:32 +03:00
zhanghongyu a2097cfb71 net: modify find device logic
The priorities for finding a network adapter are as follows:
1. if laddr is not ANY, use laddr to find device;
2. if laddr is ANY, and bound index is not 0, use bound index
   to find device;
3. if laddr is ANY and no device is bound, use raddr to find
   device.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-02-12 01:25:34 +08:00
chao an 3a0fdb019d nuttx: replace all ARRAY_SIZE()/ARRAYSIZE() to nitems()
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-09 20:05:44 +08:00
lilei19 1d8af7e105 add holder for mutex
Signed-off-by: lilei19 <lilei19@xiaomi.com>
2023-01-31 12:08:05 +09:00
Masayuki Ishikawa dc454765fb Revert "add holder for mutex"
This reverts commit fc176addeb.
2023-01-19 06:04:48 +09:00
lilei19 fc176addeb add holder for mutex
Signed-off-by: lilei19 <lilei19@xiaomi.com>
2023-01-18 17:40:58 +08:00
Xiang Xiao a851ad84c3 net: consistent the net sem wait naming conversion
to prepare the new mutex wait function

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-15 12:31:30 -03:00