anchao commented on a change in pull request #4716: URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r736136893
########## File path: arch/sim/src/sim/up_usrsock.c ########## @@ -0,0 +1,443 @@ +/**************************************************************************** + * arch/sim/src/sim/up_usrsock.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <fcntl.h> +#include <errno.h> +#include <poll.h> +#include <syslog.h> +#include <string.h> + +#include <nuttx/fs/fs.h> +#include <nuttx/net/usrsock.h> + +#include "up_usrsock_host.h" + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +struct usrsock_s +{ + struct file usock; + uint8_t data[4096]; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +typedef int (*usrsock_handler_t)(FAR struct usrsock_s *usrsock, + FAR const void *data, size_t len); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct usrsock_s g_usrsock; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int usrsock_send(FAR struct usrsock_s *usrsock, + FAR const void *buf, size_t len) +{ + FAR uint8_t *data = (FAR uint8_t *)buf; + ssize_t ret; + + while (len > 0) + { + ret = file_write(&usrsock->usock, data, len); + if (ret < 0) + { + return ret; + } + + data += ret; + len -= ret; + } + + return 0; +} + +static int usrsock_send_ack(FAR struct usrsock_s *usrsock, + uint8_t xid, int32_t result) +{ + struct usrsock_message_req_ack_s ack; + + ack.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK; + ack.head.flags = (result == -EINPROGRESS); + + ack.xid = xid; + ack.result = result; + + return usrsock_send(usrsock, &ack, sizeof(ack)); +} + +static int usrsock_send_dack(FAR struct usrsock_s *usrsock, + struct usrsock_message_datareq_ack_s *ack, Review comment: Done ########## File path: arch/sim/Kconfig ########## @@ -127,15 +127,32 @@ config SIM_WALLTIME_SIGNAL endchoice +choice + prompt "Simulated Network Interface" + default SIM_NETNULL if !NET_ETHERNET + default SIM_NETDEV if NET_ETHERNET + +config SIM_NETNULL + bool "Simulated Network NULL Device" + ---help--- + Simulated Network NULL Device. + config SIM_NETDEV bool "Simulated Network Device" - default y select ARCH_HAVE_NETDEV_STATISTICS select SCHED_LPWORK depends on NET_ETHERNET ---help--- Build in support for a simulated network device. +config SIM_NETUSRSOCK + bool "Simulated Network Device with Native Stack via usrsock" + depends on NET_USRSOCK + ---help--- + Build-in support for a simulated network device using native stack via usrsock Review comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
