1 /*
2 * Copyright (c) 2006-2021, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2018-06-06 ChenYong First version
9 */
10
11 #include <rtthread.h>
12
13 #include <netdb.h>
14 #include <sal_low_lvl.h>
15
16 #include <at_socket.h>
17 #include <af_inet.h>
18
19 #include <netdev.h>
20
21 #ifdef SAL_USING_POSIX
22 #include <poll.h>
23 #endif
24
25 #ifdef SAL_USING_AT
26
27 #ifdef SAL_USING_POSIX
at_poll(struct dfs_file * file,struct rt_pollreq * req)28 static int at_poll(struct dfs_file *file, struct rt_pollreq *req)
29 {
30 int mask = 0;
31 struct at_socket *sock;
32 struct sal_socket *sal_sock;
33
34 sal_sock = sal_get_socket((int)file->vnode->data);
35 if(!sal_sock)
36 {
37 return -1;
38 }
39
40 sock = at_get_socket((int)sal_sock->user_data);
41 if (sock != NULL)
42 {
43 rt_base_t level;
44
45 rt_poll_add(&sock->wait_head, req);
46
47 level = rt_hw_interrupt_disable();
48 if (sock->rcvevent)
49 {
50 mask |= POLLIN;
51 }
52 if (sock->sendevent)
53 {
54 mask |= POLLOUT;
55 }
56 if (sock->errevent)
57 {
58 mask |= POLLERR;
59 }
60 rt_hw_interrupt_enable(level);
61 }
62
63 return mask;
64 }
65 #endif
66
67 static const struct sal_socket_ops at_socket_ops =
68 {
69 at_socket,
70 at_closesocket,
71 at_bind,
72 #ifdef AT_USING_SOCKET_SERVER
73 at_listen,
74 #else
75 NULL,
76 #endif
77 at_connect,
78 #ifdef AT_USING_SOCKET_SERVER
79 at_accept,
80 #else
81 NULL,
82 #endif
83 at_sendto,
84 NULL,
85 NULL,
86 at_recvfrom,
87 at_getsockopt,
88 at_setsockopt,
89 at_shutdown,
90 NULL,
91 NULL,
92 NULL,
93 NULL,
94 #ifdef SAL_USING_POSIX
95 at_poll,
96 #endif /* SAL_USING_POSIX */
97 };
98
99 static const struct sal_netdb_ops at_netdb_ops =
100 {
101 at_gethostbyname,
102 at_gethostbyname_r,
103 at_getaddrinfo,
104 at_freeaddrinfo,
105 };
106
107 static const struct sal_proto_family at_inet_family =
108 {
109 AF_AT,
110 AF_INET,
111 &at_socket_ops,
112 &at_netdb_ops,
113 };
114
115
116 /* Set AT network interface device protocol family information */
sal_at_netdev_set_pf_info(struct netdev * netdev)117 int sal_at_netdev_set_pf_info(struct netdev *netdev)
118 {
119 RT_ASSERT(netdev);
120
121 netdev->sal_user_data = (void *) &at_inet_family;
122 return 0;
123 }
124
125 #endif /* SAL_USING_AT */
126