Commit Graph

63 Commits

Author SHA1 Message Date
ligd c9bc6b1ad5 rpmsg socket: add return value check.
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-09-19 09:33:30 +08:00
yintao 89329dff3b net/rpmsg: set conn->backlog=-1 only when socket listening
Signed-off-by: yintao <yintao@xiaomi.com>
2023-09-18 20:58:30 +08:00
Bowen Wang 49dbe7e177 rpmsg_sockif: add recvlock for conn->sendsize in connect
conn->sendsize is used in rpmsg_socket_ept_cb() and
rpmsg_socket_connect_internal(), the connected event may be missed
as stated below:

1. in rpmsg_socket_connect_internal(), judge conn->sendsize == 0
   and prepare to wait sendsem;
2. interrupt by rptun thread, rpmsg_socket_ept_cb() is called to
   update conn->sendsize and post the sendsem, but the no one wait
   rx sem yet, so not post (see rpmsg_socket_post());
3. return to rpmsg_socket_connect_internal() to wait the sendsem, but
   has miss the connected event.

So add recvlock in rpmsg_socket_connect_internal() also.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-09-09 00:17:36 +08:00
Ville Juven e163c74b90 rpmsg/rpmsg_sockif.c: Fix printf format for u64 type
Use PRIx64 which defines the width correctly regardless or architecture.

Fixes build error:
rpmsg/rpmsg_sockif.c:610:57: error: format '%llx' expects argument of type 'long long unsigned int', but argument 4 has type 'uint64_t' {aka 'long unsigned int'} [-Werror=format=]
  610 |       snprintf(conn->nameid, sizeof(conn->nameid), ":%llx", g_rpmsg_id++);
      |                                                      ~~~^   ~~~~~~~~~~~~
      |                                                         |             |
      |                                                         |             uint64_t {aka long unsigned int}
      |                                                         long long unsigned int
      |                                                      %lx
2023-08-23 23:36:15 +08:00
Bowen Wang 5bc32727b4 rpmsg_sockif: block poll shoud not set POLLERR
Support poll rpmsg socket fd with block mode

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-08-19 01:30:18 +08:00
Zhe Weng d3bca3c2cf net: Add FIOC_FILEPATH ioctl support for ICMP(v6)/RPMsg/Usrsock sockets
Example of /proc/PID/group/fd in this case:

FD  OFLAGS  TYPE POS       PATH
3   3       9    0         icmp:[dev eth0, id 1, flg 1]
4   3       9    0         icmp6:[dev eth0, id 2, flg 1]
5   3       9    0         rpmsg:[ap:[test:0]<->remote] # server side
5   3       9    0         rpmsg:[remote<->ap:[test:0]] # client side

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-15 15:00:59 +08:00
ligd 0383377d78 rpmsg_socket: rpmsg_socket_ns_bound() with lock
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-08-03 08:01:31 -07:00
ligd 17010ff811 rpmsg_socket: move nameid outof user define space
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-08-03 08:01:31 -07:00
dongjiuzhu1 44b08d3a67 net/rpmsg: read receiving data after unbind
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-07-29 07:04:43 -07:00
dongjiuzhu1 9a22741e32 net/rpmsg: get credentials between client and server
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-07-28 07:40:00 -07: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
chao an 36591af615 net/rpmsg: initialize semaphore count before wait
recvmsg() will incorrectly return 0 if the count of sema before waiting is greater than 0,
This commit will reinitialize the sema count before waiting:

1181 static ssize_t rpmsg_socket_recvmsg(FAR struct socket *psock,
1182                                     FAR struct msghdr *msg, int flags)
1183 {
...
1255   ret = net_sem_timedwait(&conn->recvsem,
1256                       _SO_TIMEOUT(conn->sconn.s_rcvtimeo)); // recvsem.sem_count == 1; return 0
...
1264   if (!conn->recvdata)              // recvdata not consumed; goto else
1265     {
1266       ret = conn->recvlen;
1267     }
1268   else
1269     {
1270       conn->recvdata = NULL;
1271     }
...
1282   return ret;                        // BUGON! incorrectly return 0 to user
1283 }

Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-16 17:15:42 +08:00
Zhe Weng 9f8d587b64 net/rpmsg: Set family for rpaddr in ns_bind
The rpmsg addr get from socket accept has rp_family=0, which is not
intended, to avoid wrong logic in other place, set the rp_family
in ns_bind function.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-04-21 13:18:48 +03:00
Xiang Xiao 75ecbd4382 net/local: Return the unblock handle correctly in local_accept
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-09 09:17:19 +01:00
Xiang Xiao 0ef073573a net: Remove protocol argument from si_setup callback
since the implementor could get the same value from socket::s_proto

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-13 22:41:19 +08:00
Gustavo Henrique Nihei e6b204f438 nuttx: Use MIN/MAX definitions from "sys/param.h"
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2023-02-01 23:47:44 +08:00
ligd 1b333bfad5 rpmsg_socket: destroy_ept only at close
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-18 02:11:16 +08:00
ligd a7dea8ddf6 rpmsg_socket: shouldn't call create_device again after create_ept
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-18 02:11:16 +08:00
ligd d6cad21a17 rpmsg_socket: rpmsg_send_nocpy() should lock with rpmsg_destroy_ept
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-18 02:11:16 +08:00
ligd c0735f06f6 rpmsg_socket: release tx buffer when send_oncopy failed
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-18 02:11:16 +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
chao an 3caa551ff4 net: remove psock reference from connect
Signed-off-by: chao an <anchao@xiaomi.com>
2022-11-24 22:57:42 +08:00
ligd 03ff9d1a94 rpmsg socket: add lock to poll & poll_notify
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-11-11 20:08:17 +08:00
Xiang Xiao a446b5816f mm/circbuf: Remove MM_CIRCBUF option from Kconfig
since the linker can remove the unused object file from the final image

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-08 10:18:27 -03:00
anjiahao 5724c6b2e4 sem:remove sem default protocl
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-10-22 14:50:48 +08:00
anjiahao d1d46335df Replace nxsem API when used as a lock with nxmutex API
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-17 15:59:46 +09:00
wangbowen6 344c8be049 poll: add poll_notify() api and call it in all drivers
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2022-09-26 12:06:32 +08:00
Xiang Xiao e0bb281e7a net: Align the prototype of sock_intf_s::si_ioctl with file_operations::ioctl
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-06 22:46:37 +08:00
ligd 8a3683fb9f rptun: add ns_match callback to resolve rptun deadlock
thread A: accept -> net_lock -> socket_rpmsg_accept
          -> rpmsg_register_callabck -> rptun_lock
thread B: ns_bind -> rpmsg_socket_ns_bind -> get_tx_payload_buffer
          -> rptun_wait_tx -> usrsock_rpmsg_ept_cb -> usrsockdev_write
          -> net_lock -> deadlock

fix:
add ns_match callback

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-07-27 20:36:51 +08:00
ligd 79952163c1 rpmsg_socket: use sendto_nocopy() instead of send_nocopy().
only wait ept ready after ept_create, not after ept_destroy

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-07-23 08:16:48 +03:00
ligd 9c106c1bdc rpmsg_socket: defalut set POLLERR POLLHUP to events
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-07-23 08:16:48 +03:00
ligd ba990619ed socket_rpmsg: set poll err instead return err
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-07-23 08:16:48 +03:00
ligd 630ca45a50 rpmsg_socket: connect addrlen can bigger then expect
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-07-23 08:16:48 +03:00
Jiuzhu Dong fab2f6d3d8 net/rpmsg: fix minor issue on strncpy
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-07-23 08:16:48 +03:00
Xiang Xiao 9785d6606c openamp: Change the dependence from OPENAMP to RPTUN
since all rpmsg driver need the extension api exposed by rptun driver

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-04-05 10:05:41 +03:00
hejianliang3 e9648d8a73 net:fix coverity warning
Signed-off-by: hejianliang3 <hejianliang3@xiaomi.com>
2022-04-03 14:37:53 +03:00
ligd 1796663e08 rpmsg_socket: fix kasan report error
==1598322==ERROR: AddressSanitizer: heap-use-after-free on address 0xf514f8a8 at pc 0x58ac3898 bp 0xd0b4d488 sp 0xd0b4d478
READ of size 4 at 0xf514f8a8 thread T0
    #0 0x58ac3897 in rpmsg_socket_pollnotify rpmsg/rpmsg_sockif.c:211
    #1 0x58ac512f in rpmsg_socket_ept_cb rpmsg/rpmsg_sockif.c:312
    #2 0x5787881c in rpmsg_virtio_rx_callback open-amp/lib/rpmsg/rpmsg_virtio.c:331
    #3 0x57886a67 in virtqueue_notification open-amp/lib/virtio/virtqueue.c:623
    #4 0x5786fb89 in rproc_virtio_notified open-amp/lib/remoteproc/remoteproc_virtio.c:340
    #5 0x5786bde3 in remoteproc_get_notification open-amp/lib/remoteproc/remoteproc.c:985
    #6 0x57755a50 in rptun_worker rptun/rptun.c:303
    #7 0x57755e51 in rptun_thread rptun/rptun.c:352
    #8 0x57730d4a in nxtask_start task/task_start.c:128
    #9 0xdeadbeee  (/memfd:pulseaudio (deleted)+0x15dbeee)

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-03-29 10:09:49 +08:00
Eero Nurkkala b59dd92528 net/rpmsg: fix compile-time warning
Fix this compile-time warning:

rpmsg/rpmsg_sockif.c:381:24: warning: format '%d' expects argument of type 'int', but argument 3 has type 'ssize_t' {aka 'long int'} [-Wformat=]
  381 |                   nerr("circbuf_write overflow, %d, %d\n", written, len);
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~
      |                                                            |
      |                                                            ssize_t {aka long int}

Signed-off-by: Eero Nurkkala <eero.nurkkala@offcode.fi>
2022-03-25 22:18:28 +08:00
chao.an 369f7cc451 net/rpmsg: fix the NULL pointer reference on nonblock accept
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-02-11 21:22:45 +08:00
chao.an 3fce144aeb net/inet: move recv/send timeout into socket_conn_s
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-02-10 15:04:33 -03:00
chao.an 99cde13a11 net/inet: move socket flags into socket_conn_s
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-02-10 15:04:33 -03:00
ligd 5c5bd7161c socket_rpmsg: fix ept_cb crash on server side
after correct:
client:                 server
connect                 ns_bind --> create new conn --> create_ept
                        accept  --> set conn->psock to newpsock

Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-12-13 21:15:59 -06:00
ligd 4a5d577483 socket_rpmsg: add socket_rpmsg_ioctl support
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-12-13 21:15:59 -06:00
ligd aab5d3d390 rpmsg_socket: handle block/nonblock while send/recv
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-12-13 21:15:59 -06:00
ligd be70ab2ebb rpmsg_scoket: handle race condition on ept_cb RPMSG_SOCKET_CMD_SYNC
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-12-13 21:15:59 -06:00
ligd d0486be2a3 socket_rpmsg: fix conn->psock NULL in ept_cb
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-12-13 21:15:59 -06:00
ligd 022c06766a socket_rpmsg: use ns_bound to send SYNC packet
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-11-04 13:29:51 -05:00
ligd 883d66b906 socket_rpmsg: fix save rp_name error when accept
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-11-04 13:29:51 -05:00
ligd 00ef4fca51 rpmgs_socket: set RPMSG_SOCKET_NAME_SIZE to 16 for handing prefix
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-11-04 13:29:51 -05:00
ligd 59ae421314 socket_rpmsg: support SOCK_SEQPACKET
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-11-04 13:29:51 -05:00