Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

evdev_mpers.c 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) 2015 Etienne Gemsa <etienne.gemsa@lse.epita.fr>
  3. * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
  4. * Copyright (c) 2015-2018 The strace developers.
  5. * All rights reserved.
  6. *
  7. * SPDX-License-Identifier: LGPL-2.1-or-later
  8. */
  9. #include "defs.h"
  10. #ifdef HAVE_LINUX_INPUT_H
  11. # include DEF_MPERS_TYPE(struct_ff_effect)
  12. # include <linux/ioctl.h>
  13. # include <linux/input.h>
  14. typedef struct ff_effect struct_ff_effect;
  15. #endif /* HAVE_LINUX_INPUT_H */
  16. #include MPERS_DEFS
  17. #ifdef HAVE_LINUX_INPUT_H
  18. static void
  19. decode_envelope(void *const data)
  20. {
  21. const struct ff_envelope *const envelope = data;
  22. tprintf(", envelope={attack_length=%" PRIu16
  23. ", attack_level=%" PRIu16
  24. ", fade_length=%" PRIu16
  25. ", fade_level=%#x}",
  26. envelope->attack_length,
  27. envelope->attack_level,
  28. envelope->fade_length,
  29. envelope->fade_level);
  30. }
  31. static int
  32. ff_effect_ioctl(struct tcb *const tcp, const kernel_ulong_t arg)
  33. {
  34. tprints(", ");
  35. struct_ff_effect ffe;
  36. if (umove_or_printaddr(tcp, arg, &ffe))
  37. return RVAL_IOCTL_DECODED;
  38. tprints("{type=");
  39. print_evdev_ff_type(ffe.type);
  40. tprintf(", id=%" PRIu16
  41. ", direction=%" PRIu16 ", ",
  42. ffe.id,
  43. ffe.direction);
  44. if (abbrev(tcp)) {
  45. tprints("...}");
  46. return RVAL_IOCTL_DECODED;
  47. }
  48. tprintf("trigger={button=%" PRIu16
  49. ", interval=%" PRIu16 "}"
  50. ", replay={length=%" PRIu16
  51. ", delay=%" PRIu16 "}",
  52. ffe.trigger.button,
  53. ffe.trigger.interval,
  54. ffe.replay.length,
  55. ffe.replay.delay);
  56. switch (ffe.type) {
  57. case FF_CONSTANT:
  58. tprintf(", constant={level=%" PRId16,
  59. ffe.u.constant.level);
  60. decode_envelope(&ffe.u.constant.envelope);
  61. tprints("}");
  62. break;
  63. case FF_RAMP:
  64. tprintf(", ramp={start_level=%" PRId16
  65. ", end_level=%" PRId16,
  66. ffe.u.ramp.start_level,
  67. ffe.u.ramp.end_level);
  68. decode_envelope(&ffe.u.ramp.envelope);
  69. tprints("}");
  70. break;
  71. case FF_PERIODIC:
  72. tprintf(", periodic={waveform=%" PRIu16
  73. ", period=%" PRIu16
  74. ", magnitude=%" PRId16
  75. ", offset=%" PRId16
  76. ", phase=%" PRIu16,
  77. ffe.u.periodic.waveform,
  78. ffe.u.periodic.period,
  79. ffe.u.periodic.magnitude,
  80. ffe.u.periodic.offset,
  81. ffe.u.periodic.phase);
  82. decode_envelope(&ffe.u.periodic.envelope);
  83. tprintf(", custom_len=%u, custom_data=",
  84. ffe.u.periodic.custom_len);
  85. printaddr(ptr_to_kulong(ffe.u.periodic.custom_data));
  86. tprints("}");
  87. break;
  88. case FF_RUMBLE:
  89. tprintf(", rumble={strong_magnitude=%" PRIu16
  90. ", weak_magnitude=%" PRIu16 "}",
  91. ffe.u.rumble.strong_magnitude,
  92. ffe.u.rumble.weak_magnitude);
  93. break;
  94. default:
  95. break;
  96. }
  97. tprints("}");
  98. return RVAL_IOCTL_DECODED;
  99. }
  100. MPERS_PRINTER_DECL(int, evdev_write_ioctl_mpers, struct tcb *const tcp,
  101. const unsigned int code, const kernel_ulong_t arg)
  102. {
  103. switch (code) {
  104. case EVIOCSFF:
  105. return ff_effect_ioctl(tcp, arg);
  106. default:
  107. return RVAL_DECODED;
  108. }
  109. }
  110. #endif /* HAVE_LINUX_INPUT_H */