• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <string.h>
16 #include <stdbool.h>
17 #include <stdarg.h>
18 #include <sys/errno.h>
19 #include <sys/lock.h>
20 #include <sys/fcntl.h>
21 #include <sys/ioctl.h>
22 #include "sdkconfig.h"
23 #include "lwip/sockets.h"
24 #include "lwip/sys.h"
25 #include "los_task.h"
26 
27 #ifdef CONFIG_VFS_SUPPORT_IO
28 #error This file should only be built when CONFIG_VFS_SUPPORT_IO=n
29 #endif
30 
31 /* Default implementations of read/write provided in newlib component,
32  * used as a fallback for console I/O.
33  */
34 extern ssize_t _write_r_console(struct _reent *r, int fd, const void * data, size_t size);
35 extern ssize_t _read_r_console(struct _reent *r, int fd, const void * data, size_t size);
36 #if 0
37 ssize_t _write_r(struct _reent *r, int fd, const void * data, size_t size)
38 {
39     if (fd < LWIP_SOCKET_OFFSET) {
40         return 0;// _write_r_console(r, fd, data, size);
41     }
42     return lwip_write(fd, data, size);
43 }
44 
45 ssize_t _read_r(struct _reent *r, int fd, void * dst, size_t size)
46 {
47     if (fd < LWIP_SOCKET_OFFSET) {
48         return 0;// _read_r_console(r, fd, dst, size);
49     }
50     return lwip_read(fd, dst, size);
51 }
52 
53 int _close_r(struct _reent *r, int fd)
54 {
55     if (fd < LWIP_SOCKET_OFFSET) {
56         errno = ENOSYS;
57         return -1;
58     }
59     return lwip_close(fd);
60 }
61 #endif
_fcntl_r(struct _reent * r,int fd,int cmd,int arg)62 int _fcntl_r(struct _reent *r, int fd, int cmd, int arg)
63 {
64     return lwip_fcntl(fd, cmd, arg);
65 }
66 
__wrap_ioctl(int fd,int cmd,...)67 int __wrap_ioctl(int fd, int cmd, ...)
68 {
69     va_list args;
70     va_start(args, cmd);
71     int res = lwip_ioctl(fd, cmd, va_arg(args, void*));
72     va_end(args);
73     return res;
74 }
75 
select(int nfds,fd_set * readfds,fd_set * writefds,fd_set * errorfds,struct timeval * timeout)76 int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout)
77 {
78     return lwip_select(nfds, readfds, writefds, errorfds, timeout);
79 }
80 
esp_vfs_lwip_sockets_register(void)81 void esp_vfs_lwip_sockets_register(void)
82 {
83     /* Doesn't register anything, just a hook to force linking this file */
84 }
85