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.

v4l2.c 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. /*
  2. * Copyright (c) 2014 Philippe De Muyter <phdm@macqel.be>
  3. * Copyright (c) 2014 William Manley <will@williammanley.net>
  4. * Copyright (c) 2011 Peter Zotov <whitequark@whitequark.org>
  5. * Copyright (c) 2014-2019 The strace developers.
  6. * All rights reserved.
  7. *
  8. * SPDX-License-Identifier: LGPL-2.1-or-later
  9. */
  10. #include "defs.h"
  11. #include <stdint.h>
  12. #include <linux/ioctl.h>
  13. #include <linux/types.h>
  14. #include <linux/videodev2.h>
  15. #include DEF_MPERS_TYPE(struct_v4l2_buffer)
  16. #include DEF_MPERS_TYPE(struct_v4l2_clip)
  17. #ifdef VIDIOC_CREATE_BUFS
  18. # include DEF_MPERS_TYPE(struct_v4l2_create_buffers)
  19. #endif
  20. #include DEF_MPERS_TYPE(struct_v4l2_ext_control)
  21. #include DEF_MPERS_TYPE(struct_v4l2_ext_controls)
  22. #include DEF_MPERS_TYPE(struct_v4l2_format)
  23. #include DEF_MPERS_TYPE(struct_v4l2_framebuffer)
  24. #include DEF_MPERS_TYPE(struct_v4l2_input)
  25. #include DEF_MPERS_TYPE(struct_v4l2_standard)
  26. typedef struct v4l2_buffer struct_v4l2_buffer;
  27. typedef struct v4l2_clip struct_v4l2_clip;
  28. #ifdef VIDIOC_CREATE_BUFS
  29. typedef struct v4l2_create_buffers struct_v4l2_create_buffers;
  30. #endif
  31. typedef struct v4l2_ext_control struct_v4l2_ext_control;
  32. typedef struct v4l2_ext_controls struct_v4l2_ext_controls;
  33. typedef struct v4l2_format struct_v4l2_format;
  34. typedef struct v4l2_framebuffer struct_v4l2_framebuffer;
  35. typedef struct v4l2_input struct_v4l2_input;
  36. typedef struct v4l2_standard struct_v4l2_standard;
  37. #include MPERS_DEFS
  38. #include "print_fields.h"
  39. #include "print_utils.h"
  40. #include "xstring.h"
  41. /* v4l2_fourcc_be was added by Linux commit v3.18-rc1~101^2^2~127 */
  42. #ifndef v4l2_fourcc_be
  43. # define v4l2_fourcc_be(a, b, c, d) (v4l2_fourcc(a, b, c, d) | (1U << 31))
  44. #endif
  45. #define FMT_FRACT "%u/%u"
  46. #define ARGS_FRACT(x) ((x).numerator), ((x).denominator)
  47. #define FMT_RECT "{left=%d, top=%d, width=%u, height=%u}"
  48. #define ARGS_RECT(x) (x).left, (x).top, (x).width, (x).height
  49. #include "xlat/v4l2_pix_fmts.h"
  50. #include "xlat/v4l2_sdr_fmts.h"
  51. static void
  52. print_pixelformat(uint32_t fourcc, const struct xlat *xlat)
  53. {
  54. unsigned char a[] = {
  55. (unsigned char) fourcc,
  56. (unsigned char) (fourcc >> 8),
  57. (unsigned char) (fourcc >> 16),
  58. (unsigned char) (fourcc >> 24),
  59. };
  60. unsigned int i;
  61. tprints("v4l2_fourcc(");
  62. /* Generic char array printing routine. */
  63. for (i = 0; i < ARRAY_SIZE(a); ++i) {
  64. unsigned char c = a[i];
  65. if (i)
  66. tprints(", ");
  67. if (c == '\'' || c == '\\') {
  68. char sym[] = {
  69. '\'',
  70. '\\',
  71. c,
  72. '\'',
  73. '\0'
  74. };
  75. tprints(sym);
  76. } else if (is_print(c)) {
  77. char sym[] = {
  78. '\'',
  79. c,
  80. '\'',
  81. '\0'
  82. };
  83. tprints(sym);
  84. } else {
  85. char hex[] = {
  86. BYTE_HEX_CHARS_PRINTF_QUOTED(c),
  87. '\0'
  88. };
  89. tprints(hex);
  90. }
  91. }
  92. tprints(")");
  93. if (xlat) {
  94. const char *pixfmt_name = xlookup(xlat, fourcc);
  95. if (pixfmt_name)
  96. tprints_comment(pixfmt_name);
  97. }
  98. }
  99. #include "xlat/v4l2_device_capabilities_flags.h"
  100. static int
  101. print_v4l2_capability(struct tcb *const tcp, const kernel_ulong_t arg)
  102. {
  103. struct v4l2_capability caps;
  104. if (entering(tcp))
  105. return 0;
  106. tprints(", ");
  107. if (umove_or_printaddr(tcp, arg, &caps))
  108. return RVAL_IOCTL_DECODED;
  109. PRINT_FIELD_CSTRING("{", caps, driver);
  110. PRINT_FIELD_CSTRING(", ", caps, card);
  111. PRINT_FIELD_CSTRING(", ", caps, bus_info);
  112. tprintf(", version=%u.%u.%u, capabilities=",
  113. (caps.version >> 16) & 0xFF,
  114. (caps.version >> 8) & 0xFF,
  115. caps.version & 0xFF);
  116. printflags(v4l2_device_capabilities_flags, caps.capabilities,
  117. "V4L2_CAP_???");
  118. #ifdef HAVE_STRUCT_V4L2_CAPABILITY_DEVICE_CAPS
  119. tprints(", device_caps=");
  120. printflags(v4l2_device_capabilities_flags, caps.device_caps,
  121. "V4L2_CAP_???");
  122. #endif
  123. tprints("}");
  124. return RVAL_IOCTL_DECODED;
  125. }
  126. #include "xlat/v4l2_buf_types.h"
  127. #include "xlat/v4l2_format_description_flags.h"
  128. static int
  129. print_v4l2_fmtdesc(struct tcb *const tcp, const kernel_ulong_t arg)
  130. {
  131. struct v4l2_fmtdesc f;
  132. if (entering(tcp)) {
  133. tprints(", ");
  134. if (umove_or_printaddr(tcp, arg, &f))
  135. return RVAL_IOCTL_DECODED;
  136. tprintf("{index=%u, type=", f.index);
  137. printxval(v4l2_buf_types, f.type, "V4L2_BUF_TYPE_???");
  138. return 0;
  139. }
  140. if (!syserror(tcp) && !umove(tcp, arg, &f)) {
  141. tprints(", flags=");
  142. printflags(v4l2_format_description_flags, f.flags,
  143. "V4L2_FMT_FLAG_???");
  144. PRINT_FIELD_CSTRING(", ", f, description);
  145. tprints(", pixelformat=");
  146. print_pixelformat(f.pixelformat, v4l2_pix_fmts);
  147. }
  148. tprints("}");
  149. return RVAL_IOCTL_DECODED;
  150. }
  151. #include "xlat/v4l2_fields.h"
  152. #include "xlat/v4l2_colorspaces.h"
  153. #include "xlat/v4l2_vbi_flags.h"
  154. #include "xlat/v4l2_sliced_flags.h"
  155. static bool
  156. print_v4l2_clip(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
  157. {
  158. const struct_v4l2_clip *p = elem_buf;
  159. tprintf(FMT_RECT, ARGS_RECT(p->c));
  160. return true;
  161. }
  162. static bool
  163. print_v4l2_format_fmt(struct tcb *const tcp, const char *prefix,
  164. const struct_v4l2_format *f)
  165. {
  166. bool ret = true;
  167. switch (f->type) {
  168. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  169. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  170. tprints(prefix);
  171. tprintf("fmt.pix={width=%u, height=%u, pixelformat=",
  172. f->fmt.pix.width, f->fmt.pix.height);
  173. print_pixelformat(f->fmt.pix.pixelformat, v4l2_pix_fmts);
  174. tprints(", field=");
  175. printxval(v4l2_fields, f->fmt.pix.field, "V4L2_FIELD_???");
  176. tprintf(", bytesperline=%u, sizeimage=%u, colorspace=",
  177. f->fmt.pix.bytesperline, f->fmt.pix.sizeimage);
  178. printxval(v4l2_colorspaces, f->fmt.pix.colorspace,
  179. "V4L2_COLORSPACE_???");
  180. tprints("}");
  181. break;
  182. #if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
  183. case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
  184. case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: {
  185. unsigned int i, max;
  186. tprints(prefix);
  187. tprintf("fmt.pix_mp={width=%u, height=%u, pixelformat=",
  188. f->fmt.pix_mp.width, f->fmt.pix_mp.height);
  189. print_pixelformat(f->fmt.pix_mp.pixelformat, v4l2_pix_fmts);
  190. tprints(", field=");
  191. printxval(v4l2_fields, f->fmt.pix_mp.field, "V4L2_FIELD_???");
  192. tprints(", colorspace=");
  193. printxval(v4l2_colorspaces, f->fmt.pix_mp.colorspace,
  194. "V4L2_COLORSPACE_???");
  195. tprints(", plane_fmt=[");
  196. max = f->fmt.pix_mp.num_planes;
  197. if (max > VIDEO_MAX_PLANES)
  198. max = VIDEO_MAX_PLANES;
  199. for (i = 0; i < max; i++) {
  200. if (i > 0)
  201. tprints(", ");
  202. tprintf("{sizeimage=%u, bytesperline=%u}",
  203. f->fmt.pix_mp.plane_fmt[i].sizeimage,
  204. f->fmt.pix_mp.plane_fmt[i].bytesperline);
  205. }
  206. tprintf("], num_planes=%u}",
  207. (unsigned) f->fmt.pix_mp.num_planes);
  208. break;
  209. }
  210. #endif
  211. /* OUTPUT_OVERLAY since Linux v2.6.22-rc1~1118^2~179 */
  212. #if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
  213. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  214. #endif
  215. case V4L2_BUF_TYPE_VIDEO_OVERLAY: {
  216. struct_v4l2_clip clip;
  217. tprints(prefix);
  218. tprintf("fmt.win={left=%d, top=%d, width=%u, height=%u, field=",
  219. ARGS_RECT(f->fmt.win.w));
  220. printxval(v4l2_fields, f->fmt.win.field, "V4L2_FIELD_???");
  221. tprintf(", chromakey=%#x, clips=", f->fmt.win.chromakey);
  222. ret = print_array(tcp, ptr_to_kulong(f->fmt.win.clips),
  223. f->fmt.win.clipcount, &clip, sizeof(clip),
  224. tfetch_mem, print_v4l2_clip, 0);
  225. tprintf(", clipcount=%u, bitmap=", f->fmt.win.clipcount);
  226. printaddr(ptr_to_kulong(f->fmt.win.bitmap));
  227. #ifdef HAVE_STRUCT_V4L2_WINDOW_GLOBAL_ALPHA
  228. tprintf(", global_alpha=%#x", f->fmt.win.global_alpha);
  229. #endif
  230. tprints("}");
  231. break;
  232. }
  233. case V4L2_BUF_TYPE_VBI_CAPTURE:
  234. case V4L2_BUF_TYPE_VBI_OUTPUT:
  235. tprints(prefix);
  236. tprintf("fmt.vbi={sampling_rate=%u, offset=%u, "
  237. "samples_per_line=%u, sample_format=",
  238. f->fmt.vbi.sampling_rate, f->fmt.vbi.offset,
  239. f->fmt.vbi.samples_per_line);
  240. print_pixelformat(f->fmt.vbi.sample_format, v4l2_pix_fmts);
  241. tprintf(", start=[%u, %u], count=[%u, %u], ",
  242. f->fmt.vbi.start[0], f->fmt.vbi.start[1],
  243. f->fmt.vbi.count[0], f->fmt.vbi.count[1]);
  244. tprints("flags=");
  245. printxval(v4l2_vbi_flags, f->fmt.vbi.flags, "V4L2_VBI_???");
  246. tprints("}");
  247. break;
  248. /* both since Linux v2.6.14-rc2~64 */
  249. #if HAVE_DECL_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
  250. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  251. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: {
  252. unsigned int i, j;
  253. tprints(prefix);
  254. tprints("fmt.sliced={service_set=");
  255. printxval(v4l2_sliced_flags, f->fmt.sliced.service_set,
  256. "V4L2_SLICED_???");
  257. tprintf(", io_size=%u, service_lines=[",
  258. f->fmt.sliced.io_size);
  259. for (i = 0; i < ARRAY_SIZE(f->fmt.sliced.service_lines); i++) {
  260. if (i > 0)
  261. tprints(", ");
  262. tprints("[");
  263. for (j = 0;
  264. j < ARRAY_SIZE(f->fmt.sliced.service_lines[0]);
  265. j++) {
  266. if (j > 0)
  267. tprints(", ");
  268. tprintf("%#x",
  269. f->fmt.sliced.service_lines[i][j]);
  270. }
  271. tprints("]");
  272. }
  273. tprints("]}");
  274. break;
  275. }
  276. #endif
  277. /* since Linux v4.4-rc1~118^2~14 */
  278. #if HAVE_DECL_V4L2_BUF_TYPE_SDR_OUTPUT
  279. case V4L2_BUF_TYPE_SDR_OUTPUT:
  280. #endif
  281. /* since Linux v3.15-rc1~85^2~213 */
  282. #if HAVE_DECL_V4L2_BUF_TYPE_SDR_CAPTURE
  283. case V4L2_BUF_TYPE_SDR_CAPTURE:
  284. tprints(prefix);
  285. tprints("fmt.sdr={pixelformat=");
  286. print_pixelformat(f->fmt.sdr.pixelformat, v4l2_sdr_fmts);
  287. # ifdef HAVE_STRUCT_V4L2_SDR_FORMAT_BUFFERSIZE
  288. tprintf(", buffersize=%u",
  289. f->fmt.sdr.buffersize);
  290. # endif
  291. tprints("}");
  292. break;
  293. #endif
  294. }
  295. return ret;
  296. }
  297. static int
  298. print_v4l2_format(struct tcb *const tcp, const kernel_ulong_t arg,
  299. const bool is_get)
  300. {
  301. struct_v4l2_format f;
  302. if (entering(tcp)) {
  303. tprints(", ");
  304. if (umove_or_printaddr(tcp, arg, &f))
  305. return RVAL_IOCTL_DECODED;
  306. tprints("{type=");
  307. printxval(v4l2_buf_types, f.type, "V4L2_BUF_TYPE_???");
  308. if (is_get)
  309. return 0;
  310. if (!print_v4l2_format_fmt(tcp, ", ", &f)) {
  311. tprints("}");
  312. return RVAL_IOCTL_DECODED;
  313. }
  314. return 0;
  315. }
  316. if (!syserror(tcp) && !umove(tcp, arg, &f))
  317. print_v4l2_format_fmt(tcp, is_get ? ", " : " => ", &f);
  318. tprints("}");
  319. return RVAL_IOCTL_DECODED;
  320. }
  321. #include "xlat/v4l2_memories.h"
  322. static int
  323. print_v4l2_requestbuffers(struct tcb *const tcp, const kernel_ulong_t arg)
  324. {
  325. struct v4l2_requestbuffers reqbufs;
  326. if (entering(tcp)) {
  327. tprints(", ");
  328. if (umove_or_printaddr(tcp, arg, &reqbufs))
  329. return RVAL_IOCTL_DECODED;
  330. tprintf("{type=");
  331. printxval(v4l2_buf_types, reqbufs.type, "V4L2_BUF_TYPE_???");
  332. tprints(", memory=");
  333. printxval(v4l2_memories, reqbufs.memory, "V4L2_MEMORY_???");
  334. tprintf(", count=%u", reqbufs.count);
  335. return 0;
  336. }
  337. if (!syserror(tcp)) {
  338. tprints(" => ");
  339. if (!umove(tcp, arg, &reqbufs))
  340. tprintf("%u", reqbufs.count);
  341. else
  342. tprints("???");
  343. }
  344. tprints("}");
  345. return RVAL_IOCTL_DECODED;
  346. }
  347. #include "xlat/v4l2_buf_flags.h"
  348. static int
  349. print_v4l2_buffer(struct tcb *const tcp, const unsigned int code,
  350. const kernel_ulong_t arg)
  351. {
  352. struct_v4l2_buffer b;
  353. if (entering(tcp)) {
  354. tprints(", ");
  355. if (umove_or_printaddr(tcp, arg, &b))
  356. return RVAL_IOCTL_DECODED;
  357. tprints("{type=");
  358. printxval(v4l2_buf_types, b.type, "V4L2_BUF_TYPE_???");
  359. if (code != VIDIOC_DQBUF)
  360. tprintf(", index=%u", b.index);
  361. return 0;
  362. }
  363. if (!syserror(tcp) && !umove(tcp, arg, &b)) {
  364. if (code == VIDIOC_DQBUF)
  365. tprintf(", index=%u", b.index);
  366. tprints(", memory=");
  367. printxval(v4l2_memories, b.memory, "V4L2_MEMORY_???");
  368. if (b.memory == V4L2_MEMORY_MMAP) {
  369. tprintf(", m.offset=%#x", b.m.offset);
  370. } else if (b.memory == V4L2_MEMORY_USERPTR) {
  371. tprints(", m.userptr=");
  372. printaddr(b.m.userptr);
  373. }
  374. tprintf(", length=%u, bytesused=%u, flags=",
  375. b.length, b.bytesused);
  376. printflags(v4l2_buf_flags, b.flags, "V4L2_BUF_FLAG_???");
  377. if (code == VIDIOC_DQBUF) {
  378. tprints(", timestamp = ");
  379. MPERS_FUNC_NAME(print_struct_timeval)(&b.timestamp);
  380. }
  381. tprints(", ...");
  382. }
  383. tprints("}");
  384. return RVAL_IOCTL_DECODED;
  385. }
  386. static int
  387. print_v4l2_framebuffer(struct tcb *const tcp, const kernel_ulong_t arg)
  388. {
  389. struct_v4l2_framebuffer b;
  390. tprints(", ");
  391. if (!umove_or_printaddr(tcp, arg, &b)) {
  392. tprintf("{capability=%#x, flags=%#x, base=",
  393. b.capability, b.flags);
  394. printaddr(ptr_to_kulong(b.base));
  395. tprints("}");
  396. }
  397. return RVAL_IOCTL_DECODED;
  398. }
  399. static int
  400. print_v4l2_buf_type(struct tcb *const tcp, const kernel_ulong_t arg)
  401. {
  402. int type;
  403. tprints(", ");
  404. if (!umove_or_printaddr(tcp, arg, &type)) {
  405. tprints("[");
  406. printxval(v4l2_buf_types, type, "V4L2_BUF_TYPE_???");
  407. tprints("]");
  408. }
  409. return RVAL_IOCTL_DECODED;
  410. }
  411. #include "xlat/v4l2_streaming_capabilities.h"
  412. #include "xlat/v4l2_capture_modes.h"
  413. static int
  414. print_v4l2_streamparm(struct tcb *const tcp, const kernel_ulong_t arg,
  415. const bool is_get)
  416. {
  417. struct v4l2_streamparm s;
  418. if (entering(tcp)) {
  419. tprints(", ");
  420. if (umove_or_printaddr(tcp, arg, &s))
  421. return RVAL_IOCTL_DECODED;
  422. tprints("{type=");
  423. printxval(v4l2_buf_types, s.type, "V4L2_BUF_TYPE_???");
  424. switch (s.type) {
  425. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  426. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  427. if (is_get)
  428. return 0;
  429. tprints(", ");
  430. break;
  431. default:
  432. tprints("}");
  433. return RVAL_IOCTL_DECODED;
  434. }
  435. } else {
  436. if (syserror(tcp) || umove(tcp, arg, &s) < 0) {
  437. tprints("}");
  438. return RVAL_IOCTL_DECODED;
  439. }
  440. tprints(is_get ? ", " : " => ");
  441. }
  442. if (s.type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  443. tprints("parm.capture={capability=");
  444. printflags(v4l2_streaming_capabilities,
  445. s.parm.capture.capability, "V4L2_CAP_???");
  446. tprints(", capturemode=");
  447. printflags(v4l2_capture_modes,
  448. s.parm.capture.capturemode, "V4L2_MODE_???");
  449. tprintf(", timeperframe=" FMT_FRACT,
  450. ARGS_FRACT(s.parm.capture.timeperframe));
  451. tprintf(", extendedmode=%u, readbuffers=%u}",
  452. s.parm.capture.extendedmode,
  453. s.parm.capture.readbuffers);
  454. } else {
  455. tprints("parm.output={capability=");
  456. printflags(v4l2_streaming_capabilities,
  457. s.parm.output.capability, "V4L2_CAP_???");
  458. tprintf(", outputmode=%u", s.parm.output.outputmode);
  459. tprintf(", timeperframe=" FMT_FRACT,
  460. ARGS_FRACT(s.parm.output.timeperframe));
  461. tprintf(", extendedmode=%u, writebuffers=%u}",
  462. s.parm.output.extendedmode,
  463. s.parm.output.writebuffers);
  464. }
  465. if (entering(tcp)) {
  466. return 0;
  467. } else {
  468. tprints("}");
  469. return RVAL_IOCTL_DECODED;
  470. }
  471. }
  472. static int
  473. print_v4l2_standard(struct tcb *const tcp, const kernel_ulong_t arg)
  474. {
  475. struct_v4l2_standard s;
  476. if (entering(tcp)) {
  477. tprints(", ");
  478. if (umove_or_printaddr(tcp, arg, &s))
  479. return RVAL_IOCTL_DECODED;
  480. tprintf("{index=%u", s.index);
  481. return 0;
  482. }
  483. if (!syserror(tcp) && !umove(tcp, arg, &s)) {
  484. PRINT_FIELD_CSTRING(", ", s, name);
  485. tprintf(", frameperiod=" FMT_FRACT,
  486. ARGS_FRACT(s.frameperiod));
  487. tprintf(", framelines=%d", s.framelines);
  488. }
  489. tprints("}");
  490. return RVAL_IOCTL_DECODED;
  491. }
  492. #include "xlat/v4l2_input_types.h"
  493. static int
  494. print_v4l2_input(struct tcb *const tcp, const kernel_ulong_t arg)
  495. {
  496. struct_v4l2_input i;
  497. if (entering(tcp)) {
  498. tprints(", ");
  499. if (umove_or_printaddr(tcp, arg, &i))
  500. return RVAL_IOCTL_DECODED;
  501. tprintf("{index=%u", i.index);
  502. return 0;
  503. }
  504. if (!syserror(tcp) && !umove(tcp, arg, &i)) {
  505. PRINT_FIELD_CSTRING(", ", i, name);
  506. tprints(", type=");
  507. printxval(v4l2_input_types, i.type, "V4L2_INPUT_TYPE_???");
  508. }
  509. tprints("}");
  510. return RVAL_IOCTL_DECODED;
  511. }
  512. /*
  513. * We include it here and not before print_v4l2_ext_controls as we need
  514. * V4L2_CTRL_CLASS_* definitions for V4L2_CID_*_BASE ones.
  515. */
  516. #include "xlat/v4l2_control_classes.h"
  517. #include "xlat/v4l2_control_id_bases.h"
  518. #include "xlat/v4l2_control_ids.h"
  519. static void
  520. print_v4l2_cid(const uint32_t cid)
  521. {
  522. const char *id_name = xlookup(v4l2_control_ids, cid);
  523. if (id_name) {
  524. print_xlat_ex(cid, id_name, XLAT_STYLE_DEFAULT);
  525. return;
  526. }
  527. uint64_t class_id = cid;
  528. const char *class_str = xlookup_le(v4l2_control_classes, &class_id);
  529. if (!class_str || (cid - class_id) >= 0x10000) {
  530. print_xlat_ex(cid, "V4L2_CID_???", PXF_DEFAULT_STR);
  531. return;
  532. }
  533. char *tmp_str;
  534. if (asprintf(&tmp_str, "%s+%#" PRIx64,
  535. class_str, cid - class_id) < 0)
  536. tmp_str = NULL;
  537. print_xlat_ex(cid, tmp_str, XLAT_STYLE_DEFAULT);
  538. free(tmp_str);
  539. }
  540. static int
  541. print_v4l2_control(struct tcb *const tcp, const kernel_ulong_t arg,
  542. const bool is_get)
  543. {
  544. struct v4l2_control c;
  545. if (entering(tcp)) {
  546. tprints(", ");
  547. if (umove_or_printaddr(tcp, arg, &c))
  548. return RVAL_IOCTL_DECODED;
  549. tprints("{id=");
  550. print_v4l2_cid(c.id);
  551. if (!is_get)
  552. tprintf(", value=%d", c.value);
  553. return 0;
  554. }
  555. if (!syserror(tcp) && !umove(tcp, arg, &c)) {
  556. tprints(is_get ? ", " : " => ");
  557. tprintf("value=%d", c.value);
  558. }
  559. tprints("}");
  560. return RVAL_IOCTL_DECODED;
  561. }
  562. #include "xlat/v4l2_tuner_types.h"
  563. #include "xlat/v4l2_tuner_capabilities.h"
  564. #include "xlat/v4l2_tuner_rxsubchanses.h"
  565. #include "xlat/v4l2_tuner_audmodes.h"
  566. static int
  567. print_v4l2_tuner(struct tcb *const tcp, const kernel_ulong_t arg,
  568. const bool is_get)
  569. {
  570. struct v4l2_tuner c;
  571. if (entering(tcp)) {
  572. tprints(", ");
  573. if (umove_or_printaddr(tcp, arg, &c))
  574. return RVAL_IOCTL_DECODED;
  575. tprintf("{index=%u", c.index);
  576. if (is_get)
  577. return 0;
  578. tprints(", ");
  579. } else {
  580. if (syserror(tcp) || umove(tcp, arg, &c) < 0) {
  581. tprints("}");
  582. return RVAL_IOCTL_DECODED;
  583. }
  584. tprints(is_get ? ", " : " => ");
  585. }
  586. PRINT_FIELD_CSTRING("", c, name);
  587. tprints(", type=");
  588. printxval(v4l2_tuner_types, c.type, "V4L2_TUNER_TYPE_???");
  589. tprints(", capability=");
  590. printxval(v4l2_tuner_capabilities, c.capability,
  591. "V4L2_TUNER_CAP_???");
  592. tprintf(", rangelow=%u, rangehigh=%u, rxsubchans=",
  593. c.rangelow, c.rangehigh);
  594. printxval(v4l2_tuner_rxsubchanses, c.rxsubchans,
  595. "V4L2_TUNER_SUB_???");
  596. tprints(", audmode=");
  597. printxval(v4l2_tuner_audmodes, c.audmode,
  598. "V4L2_TUNER_MODE_???");
  599. tprintf(", signal=%d, afc=%d", c.signal, c.afc);
  600. if (entering(tcp)) {
  601. return 0;
  602. } else {
  603. tprints("}");
  604. return RVAL_IOCTL_DECODED;
  605. }
  606. }
  607. #include "xlat/v4l2_control_types.h"
  608. #include "xlat/v4l2_control_flags.h"
  609. static int
  610. print_v4l2_queryctrl(struct tcb *const tcp, const kernel_ulong_t arg)
  611. {
  612. struct v4l2_queryctrl c;
  613. if (entering(tcp)) {
  614. tprints(", ");
  615. if (umove_or_printaddr(tcp, arg, &c))
  616. return RVAL_IOCTL_DECODED;
  617. tprints("{id=");
  618. } else {
  619. if (syserror(tcp) || umove(tcp, arg, &c) < 0) {
  620. tprints("}");
  621. return RVAL_IOCTL_DECODED;
  622. }
  623. if (get_tcb_priv_ulong(tcp))
  624. tprints(" => ");
  625. }
  626. if (entering(tcp) || get_tcb_priv_ulong(tcp)) {
  627. #ifdef V4L2_CTRL_FLAG_NEXT_CTRL
  628. const unsigned long next = c.id & V4L2_CTRL_FLAG_NEXT_CTRL;
  629. set_tcb_priv_ulong(tcp, next);
  630. if (next) {
  631. print_xlat(V4L2_CTRL_FLAG_NEXT_CTRL);
  632. tprints("|");
  633. c.id &= ~V4L2_CTRL_FLAG_NEXT_CTRL;
  634. }
  635. #endif
  636. printxval(v4l2_control_ids, c.id, "V4L2_CID_???");
  637. }
  638. if (exiting(tcp)) {
  639. tprints(", type=");
  640. printxval(v4l2_control_types, c.type, "V4L2_CTRL_TYPE_???");
  641. PRINT_FIELD_CSTRING(", ", c, name);
  642. tprintf(", minimum=%d, maximum=%d, step=%d"
  643. ", default_value=%d, flags=",
  644. c.minimum, c.maximum, c.step, c.default_value);
  645. printflags(v4l2_control_flags, c.flags, "V4L2_CTRL_FLAG_???");
  646. tprints("}");
  647. }
  648. return entering(tcp) ? 0 : RVAL_IOCTL_DECODED;
  649. }
  650. static int
  651. print_v4l2_cropcap(struct tcb *const tcp, const kernel_ulong_t arg)
  652. {
  653. struct v4l2_cropcap c;
  654. if (entering(tcp)) {
  655. tprints(", ");
  656. if (umove_or_printaddr(tcp, arg, &c))
  657. return RVAL_IOCTL_DECODED;
  658. tprints("{type=");
  659. printxval(v4l2_buf_types, c.type, "V4L2_BUF_TYPE_???");
  660. return 0;
  661. }
  662. if (!syserror(tcp) && !umove(tcp, arg, &c)) {
  663. tprintf(", bounds=" FMT_RECT
  664. ", defrect=" FMT_RECT
  665. ", pixelaspect=" FMT_FRACT,
  666. ARGS_RECT(c.bounds),
  667. ARGS_RECT(c.defrect),
  668. ARGS_FRACT(c.pixelaspect));
  669. }
  670. tprints("}");
  671. return RVAL_IOCTL_DECODED;
  672. }
  673. static int
  674. print_v4l2_crop(struct tcb *const tcp, const kernel_ulong_t arg,
  675. const bool is_get)
  676. {
  677. struct v4l2_crop c;
  678. if (entering(tcp)) {
  679. tprints(", ");
  680. if (umove_or_printaddr(tcp, arg, &c))
  681. return RVAL_IOCTL_DECODED;
  682. tprints("{type=");
  683. printxval(v4l2_buf_types, c.type, "V4L2_BUF_TYPE_???");
  684. if (is_get)
  685. return 0;
  686. tprintf(", c=" FMT_RECT, ARGS_RECT(c.c));
  687. } else {
  688. if (!syserror(tcp) && !umove(tcp, arg, &c))
  689. tprintf(", c=" FMT_RECT, ARGS_RECT(c.c));
  690. }
  691. tprints("}");
  692. return RVAL_IOCTL_DECODED;
  693. }
  694. #ifdef VIDIOC_S_EXT_CTRLS
  695. static bool
  696. print_v4l2_ext_control(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
  697. {
  698. const struct_v4l2_ext_control *p = elem_buf;
  699. tprints("{id=");
  700. printxval(v4l2_control_ids, p->id, "V4L2_CID_???");
  701. # if HAVE_DECL_V4L2_CTRL_TYPE_STRING
  702. tprintf(", size=%u", p->size);
  703. if (p->size > 0) {
  704. tprints(", string=");
  705. printstrn(tcp, ptr_to_kulong(p->string), p->size);
  706. } else
  707. # endif
  708. tprintf(", value=%d, value64=%" PRId64, p->value, (int64_t) p->value64);
  709. tprints("}");
  710. return true;
  711. }
  712. static int
  713. print_v4l2_ext_controls(struct tcb *const tcp, const kernel_ulong_t arg,
  714. const bool is_get)
  715. {
  716. struct_v4l2_ext_controls c;
  717. if (entering(tcp)) {
  718. tprints(", ");
  719. if (umove_or_printaddr(tcp, arg, &c))
  720. return RVAL_IOCTL_DECODED;
  721. tprints("{ctrl_class=");
  722. printxval(v4l2_control_classes, c.ctrl_class,
  723. "V4L2_CTRL_CLASS_???");
  724. tprintf(", count=%u", c.count);
  725. if (!c.count) {
  726. tprints("}");
  727. return RVAL_IOCTL_DECODED;
  728. }
  729. if (is_get)
  730. return 0;
  731. tprints(", ");
  732. } else {
  733. if (umove(tcp, arg, &c) < 0) {
  734. tprints("}");
  735. return RVAL_IOCTL_DECODED;
  736. }
  737. tprints(is_get ? ", " : " => ");
  738. }
  739. tprints("controls=");
  740. struct_v4l2_ext_control ctrl;
  741. bool fail = !print_array(tcp, ptr_to_kulong(c.controls), c.count,
  742. &ctrl, sizeof(ctrl),
  743. tfetch_mem_ignore_syserror,
  744. print_v4l2_ext_control, 0);
  745. if (exiting(tcp) && syserror(tcp))
  746. tprintf(", error_idx=%u", c.error_idx);
  747. if (exiting(tcp) || fail) {
  748. tprints("}");
  749. return RVAL_IOCTL_DECODED;
  750. }
  751. /* entering */
  752. return 0;
  753. }
  754. #endif /* VIDIOC_S_EXT_CTRLS */
  755. #ifdef VIDIOC_ENUM_FRAMESIZES
  756. # include "xlat/v4l2_framesize_types.h"
  757. static int
  758. print_v4l2_frmsizeenum(struct tcb *const tcp, const kernel_ulong_t arg)
  759. {
  760. struct v4l2_frmsizeenum s;
  761. if (entering(tcp)) {
  762. tprints(", ");
  763. if (umove_or_printaddr(tcp, arg, &s))
  764. return RVAL_IOCTL_DECODED;
  765. tprintf("{index=%u, pixel_format=", s.index);
  766. print_pixelformat(s.pixel_format, v4l2_pix_fmts);
  767. return 0;
  768. }
  769. if (!syserror(tcp) && !umove(tcp, arg, &s)) {
  770. tprints(", type=");
  771. printxval(v4l2_framesize_types, s.type, "V4L2_FRMSIZE_TYPE_???");
  772. switch (s.type) {
  773. case V4L2_FRMSIZE_TYPE_DISCRETE:
  774. tprintf(", discrete={width=%u, height=%u}",
  775. s.discrete.width, s.discrete.height);
  776. break;
  777. case V4L2_FRMSIZE_TYPE_STEPWISE:
  778. tprintf(", stepwise={min_width=%u, max_width=%u, "
  779. "step_width=%u, min_height=%u, max_height=%u, "
  780. "step_height=%u}",
  781. s.stepwise.min_width, s.stepwise.max_width,
  782. s.stepwise.step_width, s.stepwise.min_height,
  783. s.stepwise.max_height, s.stepwise.step_height);
  784. break;
  785. }
  786. }
  787. tprints("}");
  788. return RVAL_IOCTL_DECODED;
  789. }
  790. #endif /* VIDIOC_ENUM_FRAMESIZES */
  791. #ifdef VIDIOC_ENUM_FRAMEINTERVALS
  792. # include "xlat/v4l2_frameinterval_types.h"
  793. static int
  794. print_v4l2_frmivalenum(struct tcb *const tcp, const kernel_ulong_t arg)
  795. {
  796. struct v4l2_frmivalenum f;
  797. if (entering(tcp)) {
  798. tprints(", ");
  799. if (umove_or_printaddr(tcp, arg, &f))
  800. return RVAL_IOCTL_DECODED;
  801. tprintf("{index=%u, pixel_format=", f.index);
  802. print_pixelformat(f.pixel_format, v4l2_pix_fmts);
  803. tprintf(", width=%u, height=%u", f.width, f.height);
  804. return 0;
  805. }
  806. if (!syserror(tcp) && !umove(tcp, arg, &f)) {
  807. tprints(", type=");
  808. printxval(v4l2_frameinterval_types, f.type,
  809. "V4L2_FRMIVAL_TYPE_???");
  810. switch (f.type) {
  811. case V4L2_FRMIVAL_TYPE_DISCRETE:
  812. tprintf(", discrete=" FMT_FRACT,
  813. ARGS_FRACT(f.discrete));
  814. break;
  815. case V4L2_FRMIVAL_TYPE_STEPWISE:
  816. case V4L2_FRMSIZE_TYPE_CONTINUOUS:
  817. tprintf(", stepwise={min=" FMT_FRACT ", max="
  818. FMT_FRACT ", step=" FMT_FRACT "}",
  819. ARGS_FRACT(f.stepwise.min),
  820. ARGS_FRACT(f.stepwise.max),
  821. ARGS_FRACT(f.stepwise.step));
  822. break;
  823. }
  824. }
  825. tprints("}");
  826. return RVAL_IOCTL_DECODED;
  827. }
  828. #endif /* VIDIOC_ENUM_FRAMEINTERVALS */
  829. #ifdef VIDIOC_CREATE_BUFS
  830. static int
  831. print_v4l2_create_buffers(struct tcb *const tcp, const kernel_ulong_t arg)
  832. {
  833. static const char fmt[] = "{index=%u, count=%u}";
  834. static char outstr[sizeof(fmt) + sizeof(int) * 6];
  835. struct_v4l2_create_buffers b;
  836. if (entering(tcp)) {
  837. tprints(", ");
  838. if (umove_or_printaddr(tcp, arg, &b))
  839. return RVAL_IOCTL_DECODED;
  840. tprintf("{count=%u, memory=", b.count);
  841. printxval(v4l2_memories, b.memory, "V4L2_MEMORY_???");
  842. tprints(", format={type=");
  843. printxval(v4l2_buf_types, b.format.type,
  844. "V4L2_BUF_TYPE_???");
  845. print_v4l2_format_fmt(tcp, ", ",
  846. (struct_v4l2_format *) &b.format);
  847. tprints("}}");
  848. return 0;
  849. }
  850. if (syserror(tcp) || umove(tcp, arg, &b))
  851. return RVAL_IOCTL_DECODED;
  852. xsprintf(outstr, fmt, b.index, b.count);
  853. tcp->auxstr = outstr;
  854. return RVAL_IOCTL_DECODED | RVAL_STR;
  855. }
  856. #endif /* VIDIOC_CREATE_BUFS */
  857. MPERS_PRINTER_DECL(int, v4l2_ioctl, struct tcb *const tcp,
  858. const unsigned int code, const kernel_ulong_t arg)
  859. {
  860. if (!verbose(tcp))
  861. return RVAL_DECODED;
  862. switch (code) {
  863. case VIDIOC_QUERYCAP: /* R */
  864. return print_v4l2_capability(tcp, arg);
  865. case VIDIOC_ENUM_FMT: /* RW */
  866. return print_v4l2_fmtdesc(tcp, arg);
  867. case VIDIOC_G_FMT: /* RW */
  868. case VIDIOC_S_FMT: /* RW */
  869. case VIDIOC_TRY_FMT: /* RW */
  870. return print_v4l2_format(tcp, arg, code == VIDIOC_G_FMT);
  871. case VIDIOC_REQBUFS: /* RW */
  872. return print_v4l2_requestbuffers(tcp, arg);
  873. case VIDIOC_QUERYBUF: /* RW */
  874. case VIDIOC_QBUF: /* RW */
  875. case VIDIOC_DQBUF: /* RW */
  876. return print_v4l2_buffer(tcp, code, arg);
  877. case VIDIOC_G_FBUF: /* R */
  878. if (entering(tcp))
  879. return 0;
  880. ATTRIBUTE_FALLTHROUGH;
  881. case VIDIOC_S_FBUF: /* W */
  882. return print_v4l2_framebuffer(tcp, arg);
  883. case VIDIOC_STREAMON: /* W */
  884. case VIDIOC_STREAMOFF: /* W */
  885. return print_v4l2_buf_type(tcp, arg);
  886. case VIDIOC_G_PARM: /* RW */
  887. case VIDIOC_S_PARM: /* RW */
  888. return print_v4l2_streamparm(tcp, arg, code == VIDIOC_G_PARM);
  889. case VIDIOC_G_STD: /* R */
  890. if (entering(tcp))
  891. return 0;
  892. ATTRIBUTE_FALLTHROUGH;
  893. case VIDIOC_S_STD: /* W */
  894. tprints(", ");
  895. printnum_int64(tcp, arg, "%#" PRIx64);
  896. break;
  897. case VIDIOC_ENUMSTD: /* RW */
  898. return print_v4l2_standard(tcp, arg);
  899. case VIDIOC_ENUMINPUT: /* RW */
  900. return print_v4l2_input(tcp, arg);
  901. case VIDIOC_G_CTRL: /* RW */
  902. case VIDIOC_S_CTRL: /* RW */
  903. return print_v4l2_control(tcp, arg, code == VIDIOC_G_CTRL);
  904. case VIDIOC_G_TUNER: /* RW */
  905. case VIDIOC_S_TUNER: /* RW */
  906. return print_v4l2_tuner(tcp, arg, code == VIDIOC_G_TUNER);
  907. case VIDIOC_QUERYCTRL: /* RW */
  908. return print_v4l2_queryctrl(tcp, arg);
  909. case VIDIOC_G_INPUT: /* R */
  910. if (entering(tcp))
  911. return 0;
  912. ATTRIBUTE_FALLTHROUGH;
  913. case VIDIOC_S_INPUT: /* RW */
  914. tprints(", ");
  915. printnum_int(tcp, arg, "%u");
  916. break;
  917. case VIDIOC_CROPCAP: /* RW */
  918. return print_v4l2_cropcap(tcp, arg);
  919. case VIDIOC_G_CROP: /* RW */
  920. case VIDIOC_S_CROP: /* W */
  921. return print_v4l2_crop(tcp, arg, code == VIDIOC_G_CROP);
  922. #ifdef VIDIOC_S_EXT_CTRLS
  923. case VIDIOC_S_EXT_CTRLS: /* RW */
  924. case VIDIOC_TRY_EXT_CTRLS: /* RW */
  925. case VIDIOC_G_EXT_CTRLS: /* RW */
  926. return print_v4l2_ext_controls(tcp, arg,
  927. code == VIDIOC_G_EXT_CTRLS);
  928. #endif /* VIDIOC_S_EXT_CTRLS */
  929. #ifdef VIDIOC_ENUM_FRAMESIZES
  930. case VIDIOC_ENUM_FRAMESIZES: /* RW */
  931. return print_v4l2_frmsizeenum(tcp, arg);
  932. #endif /* VIDIOC_ENUM_FRAMESIZES */
  933. #ifdef VIDIOC_ENUM_FRAMEINTERVALS
  934. case VIDIOC_ENUM_FRAMEINTERVALS: /* RW */
  935. return print_v4l2_frmivalenum(tcp, arg);
  936. #endif /* VIDIOC_ENUM_FRAMEINTERVALS */
  937. #ifdef VIDIOC_CREATE_BUFS
  938. case VIDIOC_CREATE_BUFS: /* RW */
  939. return print_v4l2_create_buffers(tcp, arg);
  940. #endif /* VIDIOC_CREATE_BUFS */
  941. default:
  942. return RVAL_DECODED;
  943. }
  944. return RVAL_IOCTL_DECODED;
  945. }