Xenomai API  2.5.6.1
include/rtdm/rtdm.h
Go to the documentation of this file.
00001 
00047 #ifndef _RTDM_H
00048 #define _RTDM_H
00049 
00050 #ifdef __KERNEL__
00051 
00052 #include <linux/types.h>
00053 #include <linux/fcntl.h>
00054 #include <linux/ioctl.h>
00055 #include <linux/sched.h>
00056 #include <linux/socket.h>
00057 
00058 typedef u32 socklen_t;
00059 typedef struct task_struct rtdm_user_info_t;
00060 
00061 #else /* !__KERNEL__ */
00062 
00063 #include <fcntl.h>
00064 #include <stddef.h>
00065 #include <stdint.h>
00066 #include <sys/ioctl.h>
00067 #include <sys/socket.h>
00068 
00069 #endif /* !__KERNEL__ */
00070 
00080 #define RTDM_API_VER                    8
00081 
00083 #define RTDM_API_MIN_COMPAT_VER         6
00084 
00088 typedef uint64_t nanosecs_abs_t;
00089 
00094 typedef int64_t nanosecs_rel_t;
00095 
00101 #define RTDM_TIMEOUT_INFINITE           0
00102 
00104 #define RTDM_TIMEOUT_NONE               (-1)
00105 
00117 #define RTDM_CLASS_PARPORT              1
00118 #define RTDM_CLASS_SERIAL               2
00119 #define RTDM_CLASS_CAN                  3
00120 #define RTDM_CLASS_NETWORK              4
00121 #define RTDM_CLASS_RTMAC                5
00122 #define RTDM_CLASS_TESTING              6
00123 #define RTDM_CLASS_RTIPC                7
00124 /*
00125 #define RTDM_CLASS_USB                  ?
00126 #define RTDM_CLASS_FIREWIRE             ?
00127 #define RTDM_CLASS_INTERBUS             ?
00128 #define RTDM_CLASS_PROFIBUS             ?
00129 #define ...
00130 */
00131 #define RTDM_CLASS_EXPERIMENTAL         224
00132 #define RTDM_CLASS_MAX                  255
00133 
00135 #define RTDM_SUBCLASS_GENERIC           (-1)
00136 
00137 #define RTIOC_TYPE_COMMON               0
00138 
00144 #define RTDM_MAX_DEVNAME_LEN            31
00145 
00150 typedef struct rtdm_device_info {
00152         int device_flags;
00153 
00155         int device_class;
00156 
00160         int device_sub_class;
00161 
00163         int profile_version;
00164 } rtdm_device_info_t;
00165 
00170 #define RTDM_PURGE_RX_BUFFER            0x0001
00171 #define RTDM_PURGE_TX_BUFFER            0x0002
00172 
00184 #define RTIOC_DEVICE_INFO \
00185         _IOR(RTIOC_TYPE_COMMON, 0x00, struct rtdm_device_info)
00186 
00191 #define RTIOC_PURGE             _IOW(RTIOC_TYPE_COMMON, 0x10, int)
00192 
00195 /* Internally used for mapping socket functions on IOCTLs */
00196 struct _rtdm_getsockopt_args {
00197         int level;
00198         int optname;
00199         void *optval;
00200         socklen_t *optlen;
00201 };
00202 
00203 struct _rtdm_setsockopt_args {
00204         int level;
00205         int optname;
00206         const void *optval;
00207         socklen_t optlen;
00208 };
00209 
00210 struct _rtdm_getsockaddr_args {
00211         struct sockaddr *addr;
00212         socklen_t *addrlen;
00213 };
00214 
00215 struct _rtdm_setsockaddr_args {
00216         const struct sockaddr *addr;
00217         socklen_t addrlen;
00218 };
00219 
00220 #define _RTIOC_GETSOCKOPT       _IOW(RTIOC_TYPE_COMMON, 0x20,           \
00221                                      struct _rtdm_getsockopt_args)
00222 #define _RTIOC_SETSOCKOPT       _IOW(RTIOC_TYPE_COMMON, 0x21,           \
00223                                      struct _rtdm_setsockopt_args)
00224 #define _RTIOC_BIND             _IOW(RTIOC_TYPE_COMMON, 0x22,           \
00225                                      struct _rtdm_setsockaddr_args)
00226 #define _RTIOC_CONNECT          _IOW(RTIOC_TYPE_COMMON, 0x23,           \
00227                                      struct _rtdm_setsockaddr_args)
00228 #define _RTIOC_LISTEN           _IOW(RTIOC_TYPE_COMMON, 0x24,           \
00229                                      int)
00230 #define _RTIOC_ACCEPT           _IOW(RTIOC_TYPE_COMMON, 0x25,           \
00231                                      struct _rtdm_getsockaddr_args)
00232 #define _RTIOC_GETSOCKNAME      _IOW(RTIOC_TYPE_COMMON, 0x26,           \
00233                                      struct _rtdm_getsockaddr_args)
00234 #define _RTIOC_GETPEERNAME      _IOW(RTIOC_TYPE_COMMON, 0x27,           \
00235                                      struct _rtdm_getsockaddr_args)
00236 #define _RTIOC_SHUTDOWN         _IOW(RTIOC_TYPE_COMMON, 0x28,           \
00237                                      int)
00238 
00239 #ifdef __KERNEL__
00240 int __rt_dev_open(rtdm_user_info_t *user_info, const char *path, int oflag);
00241 int __rt_dev_socket(rtdm_user_info_t *user_info, int protocol_family,
00242                     int socket_type, int protocol);
00243 int __rt_dev_close(rtdm_user_info_t *user_info, int fd);
00244 int __rt_dev_ioctl(rtdm_user_info_t *user_info, int fd, int request, ...);
00245 ssize_t __rt_dev_read(rtdm_user_info_t *user_info, int fd, void *buf,
00246                       size_t nbyte);
00247 ssize_t __rt_dev_write(rtdm_user_info_t *user_info, int fd, const void *buf,
00248                        size_t nbyte);
00249 ssize_t __rt_dev_recvmsg(rtdm_user_info_t *user_info, int fd,
00250                          struct msghdr *msg, int flags);
00251 ssize_t __rt_dev_sendmsg(rtdm_user_info_t *user_info, int fd,
00252                          const struct msghdr *msg, int flags);
00253 #endif /* __KERNEL__ */
00254 
00255 /* Define RTDM_NO_DEFAULT_USER_API to switch off the default rt_dev_xxx
00256  * interface when providing a customised user API */
00257 #ifndef RTDM_NO_DEFAULT_USER_API
00258 
00259 #ifdef __KERNEL__
00260 
00261 #define rt_dev_open(path, oflag, ...)                           \
00262         __rt_dev_open(NULL, path, oflag)
00263 
00264 #define rt_dev_socket(protocol_family, socket_type, protocol)   \
00265         __rt_dev_socket(NULL, protocol_family, socket_type, protocol)
00266 
00267 #define rt_dev_close(fd)                                        \
00268         __rt_dev_close(NULL, fd)
00269 
00270 #define rt_dev_ioctl(fd, request, ...)                          \
00271         __rt_dev_ioctl(NULL, fd, request, __VA_ARGS__)
00272 
00273 #define rt_dev_read(fd, buf, nbyte)                             \
00274         __rt_dev_read(NULL, fd, buf, nbyte)
00275 
00276 #define rt_dev_write(fd, buf, nbyte)                            \
00277         __rt_dev_write(NULL, fd, buf, nbyte)
00278 
00279 #define rt_dev_recvmsg(fd, msg, flags)                          \
00280         __rt_dev_recvmsg(NULL, fd, msg, flags)
00281 
00282 #define rt_dev_sendmsg(fd, msg, flags)                          \
00283         __rt_dev_sendmsg(NULL, fd, msg, flags)
00284 
00285 static inline ssize_t rt_dev_recvfrom(int fd, void *buf, size_t len, int flags,
00286                                       struct sockaddr *from,
00287                                       socklen_t *fromlen)
00288 {
00289         struct iovec iov;
00290         struct msghdr msg;
00291         int ret;
00292 
00293         iov.iov_base = buf;
00294         iov.iov_len = len;
00295 
00296         msg.msg_name = from;
00297         msg.msg_namelen = from ? *fromlen : 0;
00298         msg.msg_iov = &iov;
00299         msg.msg_iovlen = 1;
00300         msg.msg_control = NULL;
00301         msg.msg_controllen = 0;
00302 
00303         ret = rt_dev_recvmsg(fd, &msg, flags);
00304         if (ret >= 0 && from)
00305                 *fromlen = msg.msg_namelen;
00306         return ret;
00307 }
00308 
00309 #else /* !__KERNEL__ */
00310 
00311 #ifdef __cplusplus
00312 extern "C" {
00313 #endif
00314 
00315 int rt_dev_open(const char *path, int oflag, ...);
00316 int rt_dev_socket(int protocol_family, int socket_type, int protocol);
00317 int rt_dev_close(int fd);
00318 int rt_dev_ioctl(int fd, int request, ...);
00319 ssize_t rt_dev_read(int fd, void *buf, size_t nbyte);
00320 ssize_t rt_dev_write(int fd, const void *buf, size_t nbyte);
00321 ssize_t rt_dev_recvmsg(int fd, struct msghdr *msg, int flags);
00322 ssize_t rt_dev_sendmsg(int fd, const struct msghdr *msg, int flags);
00323 
00324 ssize_t rt_dev_recvfrom(int fd, void *buf, size_t len, int flags,
00325                         struct sockaddr *from, socklen_t *fromlen);
00326 
00327 #ifdef __cplusplus
00328 }
00329 #endif
00330 
00331 #endif /* !__KERNEL__ */
00332 
00333 #ifdef __cplusplus
00334 extern "C" {
00335 #endif
00336 
00337 static inline ssize_t rt_dev_recv(int fd, void *buf, size_t len, int flags)
00338 {
00339         return rt_dev_recvfrom(fd, buf, len, flags, NULL, NULL);
00340 }
00341 
00342 static inline ssize_t rt_dev_sendto(int fd, const void *buf, size_t len,
00343                                     int flags, const struct sockaddr *to,
00344                                     socklen_t tolen)
00345 {
00346         struct iovec iov;
00347         struct msghdr msg;
00348 
00349         iov.iov_base = (void *)buf;
00350         iov.iov_len = len;
00351 
00352         msg.msg_name = (struct sockaddr *)to;
00353         msg.msg_namelen = tolen;
00354         msg.msg_iov = &iov;
00355         msg.msg_iovlen = 1;
00356         msg.msg_control = NULL;
00357         msg.msg_controllen = 0;
00358 
00359         return rt_dev_sendmsg(fd, &msg, flags);
00360 }
00361 
00362 static inline ssize_t rt_dev_send(int fd, const void *buf, size_t len,
00363                                   int flags)
00364 {
00365         return rt_dev_sendto(fd, buf, len, flags, NULL, 0);
00366 }
00367 
00368 static inline int rt_dev_getsockopt(int fd, int level, int optname,
00369                                     void *optval, socklen_t *optlen)
00370 {
00371         struct _rtdm_getsockopt_args args =
00372                 { level, optname, optval, optlen };
00373 
00374         return rt_dev_ioctl(fd, _RTIOC_GETSOCKOPT, &args);
00375 }
00376 
00377 static inline int rt_dev_setsockopt(int fd, int level, int optname,
00378                                     const void *optval, socklen_t optlen)
00379 {
00380         struct _rtdm_setsockopt_args args =
00381                 { level, optname, (void *)optval, optlen };
00382 
00383         return rt_dev_ioctl(fd, _RTIOC_SETSOCKOPT, &args);
00384 }
00385 
00386 static inline int rt_dev_bind(int fd, const struct sockaddr *my_addr,
00387                               socklen_t addrlen)
00388 {
00389         struct _rtdm_setsockaddr_args args = { my_addr, addrlen };
00390 
00391         return rt_dev_ioctl(fd, _RTIOC_BIND, &args);
00392 }
00393 
00394 static inline int rt_dev_connect(int fd, const struct sockaddr *serv_addr,
00395                                  socklen_t addrlen)
00396 {
00397         struct _rtdm_setsockaddr_args args = { serv_addr, addrlen };
00398 
00399         return rt_dev_ioctl(fd, _RTIOC_CONNECT, &args);
00400 }
00401 
00402 static inline int rt_dev_listen(int fd, int backlog)
00403 {
00404         return rt_dev_ioctl(fd, _RTIOC_LISTEN, backlog);
00405 }
00406 
00407 static inline int rt_dev_accept(int fd, struct sockaddr *addr,
00408                                 socklen_t *addrlen)
00409 {
00410         struct _rtdm_getsockaddr_args args = { addr, addrlen };
00411 
00412         return rt_dev_ioctl(fd, _RTIOC_ACCEPT, &args);
00413 }
00414 
00415 static inline int rt_dev_getsockname(int fd, struct sockaddr *name,
00416                                      socklen_t *namelen)
00417 {
00418         struct _rtdm_getsockaddr_args args = { name, namelen };
00419 
00420         return rt_dev_ioctl(fd, _RTIOC_GETSOCKNAME, &args);
00421 }
00422 
00423 static inline int rt_dev_getpeername(int fd, struct sockaddr *name,
00424                                      socklen_t *namelen)
00425 {
00426         struct _rtdm_getsockaddr_args args = { name, namelen };
00427 
00428         return rt_dev_ioctl(fd, _RTIOC_GETPEERNAME, &args);
00429 }
00430 
00431 static inline int rt_dev_shutdown(int fd, int how)
00432 {
00433         return rt_dev_ioctl(fd, _RTIOC_SHUTDOWN, how);
00434 }
00435 
00436 #ifdef __cplusplus
00437 }
00438 #endif
00439 
00440 #endif /* RTDM_NO_DEFAULT_USER_API */
00441 
00442 #endif /* _RTDM_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines