Xenomai  3.0.8
rtdm.h
1 /*
2  * Copyright (C) 2005, 2006 Jan Kiszka <jan.kiszka@web.de>
3  * Copyright (C) 2005 Joerg Langenberg <joerg.langenberg@gmx.net>
4  *
5  * Xenomai is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Xenomai is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Xenomai; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19 #ifndef _COBALT_RTDM_RTDM_H
20 #define _COBALT_RTDM_RTDM_H
21 
22 #include <linux/types.h>
23 #include <linux/fcntl.h>
24 #include <linux/ioctl.h>
25 #include <linux/sched.h>
26 #include <linux/socket.h>
27 #include <cobalt/kernel/ppd.h>
28 #include <rtdm/fd.h>
29 
30 typedef __u32 socklen_t;
31 
32 #include <rtdm/uapi/rtdm.h>
33 
34 int __rtdm_dev_open(const char *path, int oflag);
35 
36 int __rtdm_dev_socket(int protocol_family,
37  int socket_type, int protocol);
38 
39 static inline int rtdm_open(const char *path, int oflag, ...)
40 {
41  return __rtdm_dev_open(path, oflag);
42 }
43 
44 static inline int rtdm_socket(int protocol_family,
45  int socket_type, int protocol)
46 {
47  return __rtdm_dev_socket(protocol_family, socket_type, protocol);
48 }
49 
50 static inline int rtdm_close(int fd)
51 {
52  return rtdm_fd_close(fd, RTDM_FD_MAGIC);
53 }
54 
55 #define rtdm_fcntl(__fd, __cmd, __args...) \
56  rtdm_fd_fcntl(__fd, __cmd, ##__args)
57 
58 #define rtdm_ioctl(__fd, __request, __args...) \
59  rtdm_fd_ioctl(__fd, __request, ##__args)
60 
61 static inline ssize_t rtdm_read(int fd, void *buf, size_t count)
62 {
63  return rtdm_fd_read(fd, buf, count);
64 }
65 
66 static inline ssize_t rtdm_write(int fd, const void *buf, size_t count)
67 {
68  return rtdm_fd_write(fd, buf, count);
69 }
70 
71 static inline ssize_t rtdm_recvmsg(int s, struct user_msghdr *msg, int flags)
72 {
73  return rtdm_fd_recvmsg(s, msg, flags);
74 }
75 
76 static inline ssize_t rtdm_sendmsg(int s, const struct user_msghdr *msg, int flags)
77 {
78  return rtdm_fd_sendmsg(s, msg, flags);
79 }
80 
81 static inline
82 ssize_t rtdm_recvfrom(int s, void *buf, size_t len, int flags,
83  struct sockaddr *from,
84  socklen_t *fromlen)
85 {
86  struct user_msghdr msg;
87  struct iovec iov;
88  ssize_t ret;
89 
90  iov.iov_base = buf;
91  iov.iov_len = len;
92  msg.msg_name = from;
93  msg.msg_namelen = from ? *fromlen : 0;
94  msg.msg_iov = &iov;
95  msg.msg_iovlen = 1;
96  msg.msg_control = NULL;
97  msg.msg_controllen = 0;
98 
99  ret = rtdm_recvmsg(s, &msg, flags);
100  if (ret < 0)
101  return ret;
102 
103  if (from)
104  *fromlen = msg.msg_namelen;
105 
106  return ret;
107 }
108 
109 static inline ssize_t rtdm_recv(int s, void *buf, size_t len, int flags)
110 {
111  return rtdm_recvfrom(s, buf, len, flags, NULL, NULL);
112 }
113 
114 static inline ssize_t rtdm_sendto(int s, const void *buf, size_t len,
115  int flags, const struct sockaddr *to,
116  socklen_t tolen)
117 {
118  struct user_msghdr msg;
119  struct iovec iov;
120 
121  iov.iov_base = (void *)buf;
122  iov.iov_len = len;
123  msg.msg_name = (struct sockaddr *)to;
124  msg.msg_namelen = tolen;
125  msg.msg_iov = &iov;
126  msg.msg_iovlen = 1;
127  msg.msg_control = NULL;
128  msg.msg_controllen = 0;
129 
130  return rtdm_sendmsg(s, &msg, flags);
131 }
132 
133 static inline ssize_t rtdm_send(int s, const void *buf, size_t len, int flags)
134 {
135  return rtdm_sendto(s, buf, len, flags, NULL, 0);
136 }
137 
138 static inline int rtdm_getsockopt(int s, int level, int optname,
139  void *optval, socklen_t *optlen)
140 {
141  struct _rtdm_getsockopt_args args = {
142  level, optname, optval, optlen
143  };
144 
145  return rtdm_ioctl(s, _RTIOC_GETSOCKOPT, &args);
146 }
147 
148 static inline int rtdm_setsockopt(int s, int level, int optname,
149  const void *optval, socklen_t optlen)
150 {
151  struct _rtdm_setsockopt_args args = {
152  level, optname, (void *)optval, optlen
153  };
154 
155  return rtdm_ioctl(s, _RTIOC_SETSOCKOPT, &args);
156 }
157 
158 static inline int rtdm_bind(int s, const struct sockaddr *my_addr,
159  socklen_t addrlen)
160 {
161  struct _rtdm_setsockaddr_args args = {
162  my_addr, addrlen
163  };
164 
165  return rtdm_ioctl(s, _RTIOC_BIND, &args);
166 }
167 
168 static inline int rtdm_connect(int s, const struct sockaddr *serv_addr,
169  socklen_t addrlen)
170 {
171  struct _rtdm_setsockaddr_args args = {
172  serv_addr, addrlen
173  };
174 
175  return rtdm_ioctl(s, _RTIOC_CONNECT, &args);
176 }
177 
178 static inline int rtdm_listen(int s, int backlog)
179 {
180  return rtdm_ioctl(s, _RTIOC_LISTEN, backlog);
181 }
182 
183 static inline int rtdm_accept(int s, struct sockaddr *addr,
184  socklen_t *addrlen)
185 {
186  struct _rtdm_getsockaddr_args args = {
187  addr, addrlen
188  };
189 
190  return rtdm_ioctl(s, _RTIOC_ACCEPT, &args);
191 }
192 
193 static inline int rtdm_getsockname(int s, struct sockaddr *name,
194  socklen_t *namelen)
195 {
196  struct _rtdm_getsockaddr_args args = {
197  name, namelen
198  };
199 
200  return rtdm_ioctl(s, _RTIOC_GETSOCKNAME, &args);
201 }
202 
203 static inline int rtdm_getpeername(int s, struct sockaddr *name,
204  socklen_t *namelen)
205 {
206  struct _rtdm_getsockaddr_args args = {
207  name, namelen
208  };
209 
210  return rtdm_ioctl(s, _RTIOC_GETPEERNAME, &args);
211 }
212 
213 static inline int rtdm_shutdown(int s, int how)
214 {
215  return rtdm_ioctl(s, _RTIOC_SHUTDOWN, how);
216 }
217 
218 #endif /* _COBALT_RTDM_RTDM_H */
int rtdm_connect(int fd, const struct sockaddr *serv_addr, socklen_t addrlen)
Connect to remote address.
int rtdm_shutdown(int fd, int how)
Shut down parts of a connection.
int rtdm_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
Set socket option.
int rtdm_bind(int fd, const struct sockaddr *my_addr, socklen_t addrlen)
Bind to local address.
int rtdm_open(const char *path, int oflag,...)
Open a device.
ssize_t rtdm_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen)
Transmit message to socket.
int rtdm_ioctl(int fd, int request,...)
Issue an IOCTL.
int rtdm_getpeername(int fd, struct sockaddr *name, socklen_t *namelen)
Get socket destination address.
int rtdm_socket(int protocol_family, int socket_type, int protocol)
Create a socket.
int rtdm_listen(int fd, int backlog)
Listen to incoming connection requests.
Real-Time Driver Model for Xenomai, user API header.
int rtdm_close(int fd)
Close a device or socket.
ssize_t rtdm_sendmsg(int fd, const struct user_msghdr *msg, int flags)
Transmit message to socket.
ssize_t rtdm_read(int fd, void *buf, size_t nbyte)
Read from device.
ssize_t rtdm_send(int fd, const void *buf, size_t len, int flags)
Transmit message to socket.
ssize_t rtdm_recvmsg(int fd, struct user_msghdr *msg, int flags)
Receive message from socket.
ssize_t rtdm_write(int fd, const void *buf, size_t nbyte)
Write to device.
int rtdm_accept(int fd, struct sockaddr *addr, socklen_t *addrlen)
Accept a connection request.
ssize_t rtdm_recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen)
Receive message from socket.
int rtdm_getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen)
Get socket option.
int rtdm_getsockname(int fd, struct sockaddr *name, socklen_t *namelen)
Get local socket address.
ssize_t rtdm_recv(int fd, void *buf, size_t len, int flags)
Receive message from socket.