07edc9a070
Add driver for 'native_sim' target that implements offloaded socket networking by the use of host networking stack and wrapped BSD sockets API. This driver has following advantages over existing networking drivers for emulated platforms that are already in tree: * no TUN/TAP use means that no additional setup is required on the host side: * possible to use it within unpriviledged Docker containers, either for development or in CI * possibility to use and test offloaded sockets (CONFIG_NET_SOCKETS_OFFLOAD=y) with emulated target, which allows to increase tests coverage of this feature, without requirement of using hardware Native Simulator host libc has different error codes than embedded libc used by Zephyr. Convert between those. Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
126 lines
1.9 KiB
C
126 lines
1.9 KiB
C
/**
|
|
* Copyright (c) 2023-2024 Marcin Niestroj
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include "nsos_errno.h"
|
|
|
|
#ifndef ARRAY_SIZE
|
|
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
|
|
#endif
|
|
|
|
struct nsos_mid_errno_map {
|
|
/** Zephyr/host error code */
|
|
int err;
|
|
/** NSOS middleground error code */
|
|
int mid_err;
|
|
};
|
|
|
|
#define ERR(_name) \
|
|
{ _name, NSOS_MID_ ## _name }
|
|
|
|
static const struct nsos_mid_errno_map map[] = {
|
|
ERR(EPERM),
|
|
ERR(ENOENT),
|
|
ERR(ESRCH),
|
|
ERR(EINTR),
|
|
ERR(EIO),
|
|
ERR(ENXIO),
|
|
ERR(E2BIG),
|
|
ERR(ENOEXEC),
|
|
ERR(EBADF),
|
|
ERR(ECHILD),
|
|
ERR(EAGAIN),
|
|
ERR(ENOMEM),
|
|
ERR(EACCES),
|
|
ERR(EFAULT),
|
|
ERR(ENOTBLK),
|
|
ERR(EBUSY),
|
|
ERR(EEXIST),
|
|
ERR(EXDEV),
|
|
ERR(ENODEV),
|
|
ERR(ENOTDIR),
|
|
ERR(EISDIR),
|
|
ERR(EINVAL),
|
|
ERR(ENFILE),
|
|
ERR(EMFILE),
|
|
ERR(ENOTTY),
|
|
ERR(ETXTBSY),
|
|
ERR(EFBIG),
|
|
ERR(ENOSPC),
|
|
ERR(ESPIPE),
|
|
ERR(EROFS),
|
|
ERR(EMLINK),
|
|
ERR(EPIPE),
|
|
ERR(EDOM),
|
|
ERR(ERANGE),
|
|
ERR(ENOMSG),
|
|
ERR(EDEADLK),
|
|
ERR(ENOLCK),
|
|
ERR(ENOSTR),
|
|
ERR(ENODATA),
|
|
ERR(ETIME),
|
|
ERR(ENOSR),
|
|
ERR(EPROTO),
|
|
ERR(EBADMSG),
|
|
ERR(ENOSYS),
|
|
ERR(ENOTEMPTY),
|
|
ERR(ENAMETOOLONG),
|
|
ERR(ELOOP),
|
|
ERR(EOPNOTSUPP),
|
|
ERR(EPFNOSUPPORT),
|
|
ERR(ECONNRESET),
|
|
ERR(ENOBUFS),
|
|
ERR(EAFNOSUPPORT),
|
|
ERR(EPROTOTYPE),
|
|
ERR(ENOTSOCK),
|
|
ERR(ENOPROTOOPT),
|
|
ERR(ESHUTDOWN),
|
|
ERR(ECONNREFUSED),
|
|
ERR(EADDRINUSE),
|
|
ERR(ECONNABORTED),
|
|
ERR(ENETUNREACH),
|
|
ERR(ENETDOWN),
|
|
ERR(ETIMEDOUT),
|
|
ERR(EHOSTDOWN),
|
|
ERR(EHOSTUNREACH),
|
|
ERR(EINPROGRESS),
|
|
ERR(EALREADY),
|
|
ERR(EDESTADDRREQ),
|
|
ERR(EMSGSIZE),
|
|
ERR(EPROTONOSUPPORT),
|
|
ERR(ESOCKTNOSUPPORT),
|
|
ERR(EADDRNOTAVAIL),
|
|
ERR(ENETRESET),
|
|
ERR(EISCONN),
|
|
ERR(ENOTCONN),
|
|
ERR(ETOOMANYREFS),
|
|
ERR(ENOTSUP),
|
|
ERR(EILSEQ),
|
|
ERR(EOVERFLOW),
|
|
ERR(ECANCELED),
|
|
};
|
|
|
|
int errno_to_nsos_mid(int err)
|
|
{
|
|
for (int i = 0; i < ARRAY_SIZE(map); i++) {
|
|
if (map[i].err == err) {
|
|
return map[i].mid_err;
|
|
}
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
int errno_from_nsos_mid(int err)
|
|
{
|
|
for (int i = 0; i < ARRAY_SIZE(map); i++) {
|
|
if (map[i].mid_err == err) {
|
|
return map[i].err;
|
|
}
|
|
}
|
|
|
|
return err;
|
|
}
|