blob: dbd35834880442a501104d8d4f1a9a207f9b56d9 [file] [log] [blame]
Stefan Sørensenb88a6f82014-01-31 12:01:01 +01001#include "defs.h"
2#include <sys/ioctl.h>
3#include <linux/ptp_clock.h>
4
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00005#include "xlat/ptp_flags_options.h"
Stefan Sørensenb88a6f82014-01-31 12:01:01 +01006
Dmitry V. Levinc7afb482015-01-19 18:44:21 +00007int
8ptp_ioctl(struct tcb *tcp, const unsigned int code, long arg)
Stefan Sørensenb88a6f82014-01-31 12:01:01 +01009{
10 if (!verbose(tcp))
11 return 0;
12
13 switch (code) {
14 case PTP_CLOCK_GETCAPS: /* decode on exit */
15 {
16 struct ptp_clock_caps caps;
17
18 if (entering(tcp) || syserror(tcp) ||
19 umove(tcp, arg, &caps) < 0)
20 return 0;
21
22 tprintf(", {max_adj=%d, n_alarm=%d, n_ext_ts=%d, n_per_out=%d, pps=%d}",
23 caps.max_adj, caps.n_alarm, caps.n_ext_ts,
24 caps.n_per_out, caps.pps);
25 return 1;
26 }
27
28 case PTP_EXTTS_REQUEST: /* decode on enter */
29 {
30 struct ptp_extts_request extts;
31
32 if (exiting(tcp))
33 return 1;
34 if (umove(tcp, arg, &extts) < 0) {
35 tprintf(", %#lx", arg);
36 return 0;
37 }
38 tprintf(", {index=%d, flags=", extts.index);
39 printflags(ptp_flags_options, extts.flags, "PTP_???");
40 tprints("}");
41 return 1;
42 }
43
44 case PTP_PEROUT_REQUEST: /* decode on enter */
45 {
46 struct ptp_perout_request perout;
47
48 if (exiting(tcp))
49 return 1;
50 if (umove(tcp, arg, &perout) < 0) {
51 tprintf(", %#lx", arg);
52 return 0;
53 }
54
55 tprintf(", {start={%" PRId64 ", %" PRIu32 "}"
56 ", period={%" PRId64 ", %" PRIu32 "}"
57 ", index=%d, flags=",
58 (int64_t)perout.start.sec, perout.start.nsec,
59 (int64_t)perout.period.sec, perout.period.nsec,
60 perout.index);
61 printflags(ptp_flags_options, perout.flags, "PTP_???");
62 tprints("}");
63 return 1;
64 }
65
66 case PTP_ENABLE_PPS: /* decode on enter */
67 if (entering(tcp))
68 tprintf(", %ld", arg);
69 return 1;
70
71 case PTP_SYS_OFFSET: /* decode on exit */
72 {
73 struct ptp_sys_offset sysoff;
74 unsigned int i;
75
76 if (entering(tcp) || umove(tcp, arg, &sysoff) < 0)
77 return 0;
78
79 tprintf(", {n_samples=%u, ts={", sysoff.n_samples);
80 if (syserror(tcp)) {
81 tprints("...}}");
82 return 1;
83 }
84 if (sysoff.n_samples > PTP_MAX_SAMPLES)
85 sysoff.n_samples = PTP_MAX_SAMPLES;
86 tprintf("{%" PRId64 ", %" PRIu32 "}",
87 (int64_t)sysoff.ts[0].sec, sysoff.ts[0].nsec);
88 for (i = 1; i < 2*sysoff.n_samples+1; ++i)
89 tprintf(", {%" PRId64 ", %" PRIu32 "}",
90 (int64_t)sysoff.ts[i].sec, sysoff.ts[i].nsec);
91 tprints("}}");
92 return 1;
93 }
94
95 default: /* decode on exit */
96 return 0;
97 }
98}