Xenomai API  2.6.5
rtdm.h
Go to the documentation of this file.
1 
47 #ifndef _RTDM_H
48 #define _RTDM_H
49 
50 #ifdef __KERNEL__
51 
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>
58 
59 typedef u32 socklen_t;
60 typedef struct task_struct rtdm_user_info_t;
61 
62 #else /* !__KERNEL__ */
63 
64 #include <fcntl.h>
65 #include <stddef.h>
66 #include <stdint.h>
67 #include <sys/ioctl.h>
68 #include <sys/socket.h>
69 
70 #endif /* !__KERNEL__ */
71 
81 #define RTDM_API_VER 8
82 
84 #define RTDM_API_MIN_COMPAT_VER 6
85 
89 typedef uint64_t nanosecs_abs_t;
90 
95 typedef int64_t nanosecs_rel_t;
96 
102 #define RTDM_TIMEOUT_INFINITE 0
103 
105 #define RTDM_TIMEOUT_NONE (-1)
106 
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
125 /*
126 #define RTDM_CLASS_USB ?
127 #define RTDM_CLASS_FIREWIRE ?
128 #define RTDM_CLASS_INTERBUS ?
129 #define RTDM_CLASS_PROFIBUS ?
130 #define ...
131 */
132 #define RTDM_CLASS_EXPERIMENTAL 224
133 #define RTDM_CLASS_MAX 255
134 
136 #define RTDM_SUBCLASS_GENERIC (-1)
137 
138 #define RTIOC_TYPE_COMMON 0
139 
145 #define RTDM_MAX_DEVNAME_LEN 31
146 
151 typedef struct rtdm_device_info {
154 
157 
162 
166 
171 #define RTDM_PURGE_RX_BUFFER 0x0001
172 #define RTDM_PURGE_TX_BUFFER 0x0002
173 
185 #define RTIOC_DEVICE_INFO \
186  _IOR(RTIOC_TYPE_COMMON, 0x00, struct rtdm_device_info)
187 
192 #define RTIOC_PURGE _IOW(RTIOC_TYPE_COMMON, 0x10, int)
193 
196 /* Internally used for mapping socket functions on IOCTLs */
197 struct _rtdm_getsockopt_args {
198  int level;
199  int optname;
200  void *optval;
201  socklen_t *optlen;
202 };
203 
204 struct _rtdm_setsockopt_args {
205  int level;
206  int optname;
207  const void *optval;
208  socklen_t optlen;
209 };
210 
211 struct _rtdm_getsockaddr_args {
212  struct sockaddr *addr;
213  socklen_t *addrlen;
214 };
215 
216 struct _rtdm_setsockaddr_args {
217  const struct sockaddr *addr;
218  socklen_t addrlen;
219 };
220 
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, \
230  int)
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, \
238  int)
239 
240 #ifdef __KERNEL__
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,
247  size_t nbyte);
248 ssize_t __rt_dev_write(rtdm_user_info_t *user_info, int fd, const void *buf,
249  size_t nbyte);
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);
254 #endif /* __KERNEL__ */
255 
256 /* Define RTDM_NO_DEFAULT_USER_API to switch off the default rt_dev_xxx
257  * interface when providing a customised user API */
258 #ifndef RTDM_NO_DEFAULT_USER_API
259 
260 #ifdef __KERNEL__
261 
262 #define rt_dev_open(path, oflag, ...) \
263  __rt_dev_open(NULL, path, oflag)
264 
265 #define rt_dev_socket(protocol_family, socket_type, protocol) \
266  __rt_dev_socket(NULL, protocol_family, socket_type, protocol)
267 
268 #define rt_dev_close(fd) \
269  __rt_dev_close(NULL, fd)
270 
271 #define rt_dev_ioctl(fd, request, ...) \
272  __rt_dev_ioctl(NULL, fd, request, __VA_ARGS__)
273 
274 #define rt_dev_read(fd, buf, nbyte) \
275  __rt_dev_read(NULL, fd, buf, nbyte)
276 
277 #define rt_dev_write(fd, buf, nbyte) \
278  __rt_dev_write(NULL, fd, buf, nbyte)
279 
280 #define rt_dev_recvmsg(fd, msg, flags) \
281  __rt_dev_recvmsg(NULL, fd, msg, flags)
282 
283 #define rt_dev_sendmsg(fd, msg, flags) \
284  __rt_dev_sendmsg(NULL, fd, msg, flags)
285 
286 static inline ssize_t rt_dev_recvfrom(int fd, void *buf, size_t len, int flags,
287  struct sockaddr *from,
288  socklen_t *fromlen)
289 {
290  struct iovec iov;
291  struct user_msghdr msg;
292  int ret;
293 
294  iov.iov_base = buf;
295  iov.iov_len = len;
296 
297  msg.msg_name = from;
298  msg.msg_namelen = from ? *fromlen : 0;
299  msg.msg_iov = &iov;
300  msg.msg_iovlen = 1;
301  msg.msg_control = NULL;
302  msg.msg_controllen = 0;
303 
304  ret = rt_dev_recvmsg(fd, &msg, flags);
305  if (ret >= 0 && from)
306  *fromlen = msg.msg_namelen;
307  return ret;
308 }
309 
310 #else /* !__KERNEL__ */
311 
312 #define user_msghdr msghdr
313 
314 #ifdef __cplusplus
315 extern "C" {
316 #endif
317 
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);
326 
327 ssize_t rt_dev_recvfrom(int fd, void *buf, size_t len, int flags,
328  struct sockaddr *from, socklen_t *fromlen);
329 
330 #ifdef __cplusplus
331 }
332 #endif
333 
334 #endif /* !__KERNEL__ */
335 
336 #ifdef __cplusplus
337 extern "C" {
338 #endif
339 
340 static inline ssize_t rt_dev_recv(int fd, void *buf, size_t len, int flags)
341 {
342  return rt_dev_recvfrom(fd, buf, len, flags, NULL, NULL);
343 }
344 
345 static inline ssize_t rt_dev_sendto(int fd, const void *buf, size_t len,
346  int flags, const struct sockaddr *to,
347  socklen_t tolen)
348 {
349  struct iovec iov;
350  struct user_msghdr msg;
351 
352  iov.iov_base = (void *)buf;
353  iov.iov_len = len;
354 
355  msg.msg_name = (struct sockaddr *)to;
356  msg.msg_namelen = tolen;
357  msg.msg_iov = &iov;
358  msg.msg_iovlen = 1;
359  msg.msg_control = NULL;
360  msg.msg_controllen = 0;
361 
362  return rt_dev_sendmsg(fd, &msg, flags);
363 }
364 
365 static inline ssize_t rt_dev_send(int fd, const void *buf, size_t len,
366  int flags)
367 {
368  return rt_dev_sendto(fd, buf, len, flags, NULL, 0);
369 }
370 
371 static inline int rt_dev_getsockopt(int fd, int level, int optname,
372  void *optval, socklen_t *optlen)
373 {
374  struct _rtdm_getsockopt_args args =
375  { level, optname, optval, optlen };
376 
377  return rt_dev_ioctl(fd, _RTIOC_GETSOCKOPT, &args);
378 }
379 
380 static inline int rt_dev_setsockopt(int fd, int level, int optname,
381  const void *optval, socklen_t optlen)
382 {
383  struct _rtdm_setsockopt_args args =
384  { level, optname, (void *)optval, optlen };
385 
386  return rt_dev_ioctl(fd, _RTIOC_SETSOCKOPT, &args);
387 }
388 
389 static inline int rt_dev_bind(int fd, const struct sockaddr *my_addr,
390  socklen_t addrlen)
391 {
392  struct _rtdm_setsockaddr_args args = { my_addr, addrlen };
393 
394  return rt_dev_ioctl(fd, _RTIOC_BIND, &args);
395 }
396 
397 static inline int rt_dev_connect(int fd, const struct sockaddr *serv_addr,
398  socklen_t addrlen)
399 {
400  struct _rtdm_setsockaddr_args args = { serv_addr, addrlen };
401 
402  return rt_dev_ioctl(fd, _RTIOC_CONNECT, &args);
403 }
404 
405 static inline int rt_dev_listen(int fd, int backlog)
406 {
407  return rt_dev_ioctl(fd, _RTIOC_LISTEN, backlog);
408 }
409 
410 static inline int rt_dev_accept(int fd, struct sockaddr *addr,
411  socklen_t *addrlen)
412 {
413  struct _rtdm_getsockaddr_args args = { addr, addrlen };
414 
415  return rt_dev_ioctl(fd, _RTIOC_ACCEPT, &args);
416 }
417 
418 static inline int rt_dev_getsockname(int fd, struct sockaddr *name,
419  socklen_t *namelen)
420 {
421  struct _rtdm_getsockaddr_args args = { name, namelen };
422 
423  return rt_dev_ioctl(fd, _RTIOC_GETSOCKNAME, &args);
424 }
425 
426 static inline int rt_dev_getpeername(int fd, struct sockaddr *name,
427  socklen_t *namelen)
428 {
429  struct _rtdm_getsockaddr_args args = { name, namelen };
430 
431  return rt_dev_ioctl(fd, _RTIOC_GETPEERNAME, &args);
432 }
433 
434 static inline int rt_dev_shutdown(int fd, int how)
435 {
436  return rt_dev_ioctl(fd, _RTIOC_SHUTDOWN, how);
437 }
438 
439 #ifdef __cplusplus
440 }
441 #endif
442 
443 #endif /* RTDM_NO_DEFAULT_USER_API */
444 
445 #endif /* _RTDM_H */
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.