52 #include <linux/types.h>
53 #include <linux/fcntl.h>
54 #include <linux/ioctl.h>
55 #include <linux/sched.h>
56 #include <linux/socket.h>
57 #include <asm/xenomai/wrappers.h>
59 typedef u32 socklen_t;
60 typedef struct task_struct rtdm_user_info_t;
67 #include <sys/ioctl.h>
68 #include <sys/socket.h>
81 #define RTDM_API_VER 8
84 #define RTDM_API_MIN_COMPAT_VER 6
102 #define RTDM_TIMEOUT_INFINITE 0
105 #define RTDM_TIMEOUT_NONE (-1)
118 #define RTDM_CLASS_PARPORT 1
119 #define RTDM_CLASS_SERIAL 2
120 #define RTDM_CLASS_CAN 3
121 #define RTDM_CLASS_NETWORK 4
122 #define RTDM_CLASS_RTMAC 5
123 #define RTDM_CLASS_TESTING 6
124 #define RTDM_CLASS_RTIPC 7
132 #define RTDM_CLASS_EXPERIMENTAL 224
133 #define RTDM_CLASS_MAX 255
136 #define RTDM_SUBCLASS_GENERIC (-1)
138 #define RTIOC_TYPE_COMMON 0
145 #define RTDM_MAX_DEVNAME_LEN 31
171 #define RTDM_PURGE_RX_BUFFER 0x0001
172 #define RTDM_PURGE_TX_BUFFER 0x0002
185 #define RTIOC_DEVICE_INFO \
186 _IOR(RTIOC_TYPE_COMMON, 0x00, struct rtdm_device_info)
192 #define RTIOC_PURGE _IOW(RTIOC_TYPE_COMMON, 0x10, int)
197 struct _rtdm_getsockopt_args {
204 struct _rtdm_setsockopt_args {
211 struct _rtdm_getsockaddr_args {
212 struct sockaddr *addr;
216 struct _rtdm_setsockaddr_args {
217 const struct sockaddr *addr;
221 #define _RTIOC_GETSOCKOPT _IOW(RTIOC_TYPE_COMMON, 0x20, \
222 struct _rtdm_getsockopt_args)
223 #define _RTIOC_SETSOCKOPT _IOW(RTIOC_TYPE_COMMON, 0x21, \
224 struct _rtdm_setsockopt_args)
225 #define _RTIOC_BIND _IOW(RTIOC_TYPE_COMMON, 0x22, \
226 struct _rtdm_setsockaddr_args)
227 #define _RTIOC_CONNECT _IOW(RTIOC_TYPE_COMMON, 0x23, \
228 struct _rtdm_setsockaddr_args)
229 #define _RTIOC_LISTEN _IOW(RTIOC_TYPE_COMMON, 0x24, \
231 #define _RTIOC_ACCEPT _IOW(RTIOC_TYPE_COMMON, 0x25, \
232 struct _rtdm_getsockaddr_args)
233 #define _RTIOC_GETSOCKNAME _IOW(RTIOC_TYPE_COMMON, 0x26, \
234 struct _rtdm_getsockaddr_args)
235 #define _RTIOC_GETPEERNAME _IOW(RTIOC_TYPE_COMMON, 0x27, \
236 struct _rtdm_getsockaddr_args)
237 #define _RTIOC_SHUTDOWN _IOW(RTIOC_TYPE_COMMON, 0x28, \
241 int __rt_dev_open(rtdm_user_info_t *user_info,
const char *path,
int oflag);
242 int __rt_dev_socket(rtdm_user_info_t *user_info,
int protocol_family,
243 int socket_type,
int protocol);
244 int __rt_dev_close(rtdm_user_info_t *user_info,
int fd);
245 int __rt_dev_ioctl(rtdm_user_info_t *user_info,
int fd,
int request, ...);
246 ssize_t __rt_dev_read(rtdm_user_info_t *user_info,
int fd,
void *buf,
248 ssize_t __rt_dev_write(rtdm_user_info_t *user_info,
int fd,
const void *buf,
250 ssize_t __rt_dev_recvmsg(rtdm_user_info_t *user_info,
int fd,
251 struct user_msghdr *msg,
int flags);
252 ssize_t __rt_dev_sendmsg(rtdm_user_info_t *user_info,
int fd,
253 const struct user_msghdr *msg,
int flags);
258 #ifndef RTDM_NO_DEFAULT_USER_API
262 #define rt_dev_open(path, oflag, ...) \
263 __rt_dev_open(NULL, path, oflag)
265 #define rt_dev_socket(protocol_family, socket_type, protocol) \
266 __rt_dev_socket(NULL, protocol_family, socket_type, protocol)
268 #define rt_dev_close(fd) \
269 __rt_dev_close(NULL, fd)
271 #define rt_dev_ioctl(fd, request, ...) \
272 __rt_dev_ioctl(NULL, fd, request, __VA_ARGS__)
274 #define rt_dev_read(fd, buf, nbyte) \
275 __rt_dev_read(NULL, fd, buf, nbyte)
277 #define rt_dev_write(fd, buf, nbyte) \
278 __rt_dev_write(NULL, fd, buf, nbyte)
280 #define rt_dev_recvmsg(fd, msg, flags) \
281 __rt_dev_recvmsg(NULL, fd, msg, flags)
283 #define rt_dev_sendmsg(fd, msg, flags) \
284 __rt_dev_sendmsg(NULL, fd, msg, flags)
286 static inline ssize_t rt_dev_recvfrom(
int fd,
void *buf,
size_t len,
int flags,
287 struct sockaddr *from,
291 struct user_msghdr msg;
298 msg.msg_namelen = from ? *fromlen : 0;
301 msg.msg_control = NULL;
302 msg.msg_controllen = 0;
305 if (ret >= 0 && from)
306 *fromlen = msg.msg_namelen;
312 #define user_msghdr msghdr
318 int rt_dev_open(
const char *path,
int oflag, ...);
319 int rt_dev_socket(
int protocol_family,
int socket_type,
int protocol);
320 int rt_dev_close(
int fd);
321 int rt_dev_ioctl(
int fd,
int request, ...);
322 ssize_t rt_dev_read(
int fd,
void *buf,
size_t nbyte);
323 ssize_t rt_dev_write(
int fd,
const void *buf,
size_t nbyte);
324 ssize_t
rt_dev_recvmsg(
int fd,
struct user_msghdr *msg,
int flags);
325 ssize_t
rt_dev_sendmsg(
int fd,
const struct user_msghdr *msg,
int flags);
327 ssize_t rt_dev_recvfrom(
int fd,
void *buf,
size_t len,
int flags,
328 struct sockaddr *from, socklen_t *fromlen);
340 static inline ssize_t
rt_dev_recv(
int fd,
void *buf,
size_t len,
int flags)
342 return rt_dev_recvfrom(fd, buf, len, flags, NULL, NULL);
345 static inline ssize_t
rt_dev_sendto(
int fd,
const void *buf,
size_t len,
346 int flags,
const struct sockaddr *to,
350 struct user_msghdr msg;
352 iov.iov_base = (
void *)buf;
355 msg.msg_name = (
struct sockaddr *)to;
356 msg.msg_namelen = tolen;
359 msg.msg_control = NULL;
360 msg.msg_controllen = 0;
365 static inline ssize_t
rt_dev_send(
int fd,
const void *buf,
size_t len,
372 void *optval, socklen_t *optlen)
374 struct _rtdm_getsockopt_args args =
375 { level, optname, optval, optlen };
377 return rt_dev_ioctl(fd, _RTIOC_GETSOCKOPT, &args);
381 const void *optval, socklen_t optlen)
383 struct _rtdm_setsockopt_args args =
384 { level, optname, (
void *)optval, optlen };
386 return rt_dev_ioctl(fd, _RTIOC_SETSOCKOPT, &args);
389 static inline int rt_dev_bind(
int fd,
const struct sockaddr *my_addr,
392 struct _rtdm_setsockaddr_args args = { my_addr, addrlen };
394 return rt_dev_ioctl(fd, _RTIOC_BIND, &args);
397 static inline int rt_dev_connect(
int fd,
const struct sockaddr *serv_addr,
400 struct _rtdm_setsockaddr_args args = { serv_addr, addrlen };
402 return rt_dev_ioctl(fd, _RTIOC_CONNECT, &args);
407 return rt_dev_ioctl(fd, _RTIOC_LISTEN, backlog);
410 static inline int rt_dev_accept(
int fd,
struct sockaddr *addr,
413 struct _rtdm_getsockaddr_args args = { addr, addrlen };
415 return rt_dev_ioctl(fd, _RTIOC_ACCEPT, &args);
421 struct _rtdm_getsockaddr_args args = { name, namelen };
423 return rt_dev_ioctl(fd, _RTIOC_GETSOCKNAME, &args);
429 struct _rtdm_getsockaddr_args args = { name, namelen };
431 return rt_dev_ioctl(fd, _RTIOC_GETPEERNAME, &args);
436 return rt_dev_ioctl(fd, _RTIOC_SHUTDOWN, how);
int rt_dev_bind(int fd, const struct sockaddr *my_addr, socklen_t addrlen)
Bind to local address.
int rt_dev_shutdown(int fd, int how)
Shut down parts of a connection.
int rt_dev_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
Set socket option.
int64_t nanosecs_rel_t
RTDM type for representing relative intervals.
Definition: rtdm.h:95
ssize_t rt_dev_recv(int fd, void *buf, size_t len, int flags)
Receive message from socket.
int rt_dev_accept(int fd, struct sockaddr *addr, socklen_t *addrlen)
Accept a connection requests.
ssize_t rt_dev_send(int fd, const void *buf, size_t len, int flags)
Transmit message to socket.
ssize_t rt_dev_recvmsg(int fd, struct user_msghdr *msg, int flags)
Receive message from socket.
int device_sub_class
Device sub-class, either RTDM_SUBCLASS_GENERIC or a RTDM_SUBCLASS_xxx definition of the related Devic...
Definition: rtdm.h:161
uint64_t nanosecs_abs_t
RTDM type for representing absolute dates.
Definition: rtdm.h:89
int rt_dev_getsockname(int fd, struct sockaddr *name, socklen_t *namelen)
Get local socket address.
int rt_dev_connect(int fd, const struct sockaddr *serv_addr, socklen_t addrlen)
Connect to remote address.
int profile_version
Supported device profile version.
Definition: rtdm.h:164
int device_flags
Device flags, see Device Flags for details.
Definition: rtdm.h:153
Device information.
Definition: rtdm.h:151
ssize_t rt_dev_sendmsg(int fd, const struct user_msghdr *msg, int flags)
Transmit message to socket.
int device_class
Device class ID, see RTDM_CLASS_xxx.
Definition: rtdm.h:156
int rt_dev_getpeername(int fd, struct sockaddr *name, socklen_t *namelen)
Get socket destination address.
struct rtdm_device_info rtdm_device_info_t
Device information.
ssize_t rt_dev_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen)
Transmit message to socket.
int rt_dev_getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen)
Get socket option.
int rt_dev_listen(int fd, int backlog)
Listen for incomming connection requests.