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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  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_STRUCT_V4L2_FORMAT_FMT_PIX_MP
  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. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  213. case V4L2_BUF_TYPE_VIDEO_OVERLAY: {
  214. struct_v4l2_clip clip;
  215. tprints(prefix);
  216. tprintf("fmt.win={left=%d, top=%d, width=%u, height=%u, field=",
  217. ARGS_RECT(f->fmt.win.w));
  218. printxval(v4l2_fields, f->fmt.win.field, "V4L2_FIELD_???");
  219. tprintf(", chromakey=%#x, clips=", f->fmt.win.chromakey);
  220. ret = print_array(tcp, ptr_to_kulong(f->fmt.win.clips),
  221. f->fmt.win.clipcount, &clip, sizeof(clip),
  222. tfetch_mem, print_v4l2_clip, 0);
  223. tprintf(", clipcount=%u, bitmap=", f->fmt.win.clipcount);
  224. printaddr(ptr_to_kulong(f->fmt.win.bitmap));
  225. #ifdef HAVE_STRUCT_V4L2_WINDOW_GLOBAL_ALPHA
  226. tprintf(", global_alpha=%#x", f->fmt.win.global_alpha);
  227. #endif
  228. tprints("}");
  229. break;
  230. }
  231. case V4L2_BUF_TYPE_VBI_CAPTURE:
  232. case V4L2_BUF_TYPE_VBI_OUTPUT:
  233. tprints(prefix);
  234. tprintf("fmt.vbi={sampling_rate=%u, offset=%u, "
  235. "samples_per_line=%u, sample_format=",
  236. f->fmt.vbi.sampling_rate, f->fmt.vbi.offset,
  237. f->fmt.vbi.samples_per_line);
  238. print_pixelformat(f->fmt.vbi.sample_format, v4l2_pix_fmts);
  239. tprintf(", start=[%u, %u], count=[%u, %u], ",
  240. f->fmt.vbi.start[0], f->fmt.vbi.start[1],
  241. f->fmt.vbi.count[0], f->fmt.vbi.count[1]);
  242. tprints("flags=");
  243. printxval(v4l2_vbi_flags, f->fmt.vbi.flags, "V4L2_VBI_???");
  244. tprints("}");
  245. break;
  246. /* both since Linux v2.6.14-rc2~64 */
  247. #if HAVE_STRUCT_V4L2_FORMAT_FMT_SLICED
  248. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  249. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: {
  250. unsigned int i, j;
  251. tprints(prefix);
  252. tprints("fmt.sliced={service_set=");
  253. printxval(v4l2_sliced_flags, f->fmt.sliced.service_set,
  254. "V4L2_SLICED_???");
  255. tprintf(", io_size=%u, service_lines=[",
  256. f->fmt.sliced.io_size);
  257. for (i = 0; i < ARRAY_SIZE(f->fmt.sliced.service_lines); i++) {
  258. if (i > 0)
  259. tprints(", ");
  260. tprints("[");
  261. for (j = 0;
  262. j < ARRAY_SIZE(f->fmt.sliced.service_lines[0]);
  263. j++) {
  264. if (j > 0)
  265. tprints(", ");
  266. tprintf("%#x",
  267. f->fmt.sliced.service_lines[i][j]);
  268. }
  269. tprints("]");
  270. }
  271. tprints("]}");
  272. break;
  273. }
  274. #endif
  275. #if HAVE_STRUCT_V4L2_FORMAT_FMT_SDR
  276. /* since Linux v4.4-rc1~118^2~14 */
  277. case V4L2_BUF_TYPE_SDR_OUTPUT:
  278. /* since Linux v3.15-rc1~85^2~213 */
  279. case V4L2_BUF_TYPE_SDR_CAPTURE:
  280. tprints(prefix);
  281. tprints("fmt.sdr={pixelformat=");
  282. print_pixelformat(f->fmt.sdr.pixelformat, v4l2_sdr_fmts);
  283. # ifdef HAVE_STRUCT_V4L2_SDR_FORMAT_BUFFERSIZE
  284. tprintf(", buffersize=%u",
  285. f->fmt.sdr.buffersize);
  286. # endif
  287. tprints("}");
  288. break;
  289. #endif
  290. }
  291. return ret;
  292. }
  293. static int
  294. print_v4l2_format(struct tcb *const tcp, const kernel_ulong_t arg,
  295. const bool is_get)
  296. {
  297. struct_v4l2_format f;
  298. if (entering(tcp)) {
  299. tprints(", ");
  300. if (umove_or_printaddr(tcp, arg, &f))
  301. return RVAL_IOCTL_DECODED;
  302. tprints("{type=");
  303. printxval(v4l2_buf_types, f.type, "V4L2_BUF_TYPE_???");
  304. if (is_get)
  305. return 0;
  306. if (!print_v4l2_format_fmt(tcp, ", ", &f)) {
  307. tprints("}");
  308. return RVAL_IOCTL_DECODED;
  309. }
  310. return 0;
  311. }
  312. if (!syserror(tcp) && !umove(tcp, arg, &f))
  313. print_v4l2_format_fmt(tcp, is_get ? ", " : " => ", &f);
  314. tprints("}");
  315. return RVAL_IOCTL_DECODED;
  316. }
  317. #include "xlat/v4l2_memories.h"
  318. static int
  319. print_v4l2_requestbuffers(struct tcb *const tcp, const kernel_ulong_t arg)
  320. {
  321. struct v4l2_requestbuffers reqbufs;
  322. if (entering(tcp)) {
  323. tprints(", ");
  324. if (umove_or_printaddr(tcp, arg, &reqbufs))
  325. return RVAL_IOCTL_DECODED;
  326. tprintf("{type=");
  327. printxval(v4l2_buf_types, reqbufs.type, "V4L2_BUF_TYPE_???");
  328. tprints(", memory=");
  329. printxval(v4l2_memories, reqbufs.memory, "V4L2_MEMORY_???");
  330. tprintf(", count=%u", reqbufs.count);
  331. return 0;
  332. }
  333. if (!syserror(tcp)) {
  334. tprints(" => ");
  335. if (!umove(tcp, arg, &reqbufs))
  336. tprintf("%u", reqbufs.count);
  337. else
  338. tprints("???");
  339. }
  340. tprints("}");
  341. return RVAL_IOCTL_DECODED;
  342. }
  343. #include "xlat/v4l2_buf_flags.h"
  344. static int
  345. print_v4l2_buffer(struct tcb *const tcp, const unsigned int code,
  346. const kernel_ulong_t arg)
  347. {
  348. struct_v4l2_buffer b;
  349. if (entering(tcp)) {
  350. tprints(", ");
  351. if (umove_or_printaddr(tcp, arg, &b))
  352. return RVAL_IOCTL_DECODED;
  353. tprints("{type=");
  354. printxval(v4l2_buf_types, b.type, "V4L2_BUF_TYPE_???");
  355. if (code != VIDIOC_DQBUF)
  356. tprintf(", index=%u", b.index);
  357. return 0;
  358. }
  359. if (!syserror(tcp) && !umove(tcp, arg, &b)) {
  360. if (code == VIDIOC_DQBUF)
  361. tprintf(", index=%u", b.index);
  362. tprints(", memory=");
  363. printxval(v4l2_memories, b.memory, "V4L2_MEMORY_???");
  364. if (b.memory == V4L2_MEMORY_MMAP) {
  365. tprintf(", m.offset=%#x", b.m.offset);
  366. } else if (b.memory == V4L2_MEMORY_USERPTR) {
  367. tprints(", m.userptr=");
  368. printaddr(b.m.userptr);
  369. }
  370. tprintf(", length=%u, bytesused=%u, flags=",
  371. b.length, b.bytesused);
  372. printflags(v4l2_buf_flags, b.flags, "V4L2_BUF_FLAG_???");
  373. if (code == VIDIOC_DQBUF) {
  374. tprints(", timestamp = ");
  375. MPERS_FUNC_NAME(print_struct_timeval)(&b.timestamp);
  376. }
  377. tprints(", ...");
  378. }
  379. tprints("}");
  380. return RVAL_IOCTL_DECODED;
  381. }
  382. static int
  383. print_v4l2_framebuffer(struct tcb *const tcp, const kernel_ulong_t arg)
  384. {
  385. struct_v4l2_framebuffer b;
  386. tprints(", ");
  387. if (!umove_or_printaddr(tcp, arg, &b)) {
  388. tprintf("{capability=%#x, flags=%#x, base=",
  389. b.capability, b.flags);
  390. printaddr(ptr_to_kulong(b.base));
  391. tprints("}");
  392. }
  393. return RVAL_IOCTL_DECODED;
  394. }
  395. static int
  396. print_v4l2_buf_type(struct tcb *const tcp, const kernel_ulong_t arg)
  397. {
  398. int type;
  399. tprints(", ");
  400. if (!umove_or_printaddr(tcp, arg, &type)) {
  401. tprints("[");
  402. printxval(v4l2_buf_types, type, "V4L2_BUF_TYPE_???");
  403. tprints("]");
  404. }
  405. return RVAL_IOCTL_DECODED;
  406. }
  407. #include "xlat/v4l2_streaming_capabilities.h"
  408. #include "xlat/v4l2_capture_modes.h"
  409. static int
  410. print_v4l2_streamparm(struct tcb *const tcp, const kernel_ulong_t arg,
  411. const bool is_get)
  412. {
  413. struct v4l2_streamparm s;
  414. if (entering(tcp)) {
  415. tprints(", ");
  416. if (umove_or_printaddr(tcp, arg, &s))
  417. return RVAL_IOCTL_DECODED;
  418. tprints("{type=");
  419. printxval(v4l2_buf_types, s.type, "V4L2_BUF_TYPE_???");
  420. switch (s.type) {
  421. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  422. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  423. if (is_get)
  424. return 0;
  425. tprints(", ");
  426. break;
  427. default:
  428. tprints("}");
  429. return RVAL_IOCTL_DECODED;
  430. }
  431. } else {
  432. if (syserror(tcp) || umove(tcp, arg, &s) < 0) {
  433. tprints("}");
  434. return RVAL_IOCTL_DECODED;
  435. }
  436. tprints(is_get ? ", " : " => ");
  437. }
  438. if (s.type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  439. tprints("parm.capture={capability=");
  440. printflags(v4l2_streaming_capabilities,
  441. s.parm.capture.capability, "V4L2_CAP_???");
  442. tprints(", capturemode=");
  443. printflags(v4l2_capture_modes,
  444. s.parm.capture.capturemode, "V4L2_MODE_???");
  445. tprintf(", timeperframe=" FMT_FRACT,
  446. ARGS_FRACT(s.parm.capture.timeperframe));
  447. tprintf(", extendedmode=%u, readbuffers=%u}",
  448. s.parm.capture.extendedmode,
  449. s.parm.capture.readbuffers);
  450. } else {
  451. tprints("parm.output={capability=");
  452. printflags(v4l2_streaming_capabilities,
  453. s.parm.output.capability, "V4L2_CAP_???");
  454. tprintf(", outputmode=%u", s.parm.output.outputmode);
  455. tprintf(", timeperframe=" FMT_FRACT,
  456. ARGS_FRACT(s.parm.output.timeperframe));
  457. tprintf(", extendedmode=%u, writebuffers=%u}",
  458. s.parm.output.extendedmode,
  459. s.parm.output.writebuffers);
  460. }
  461. if (entering(tcp)) {
  462. return 0;
  463. } else {
  464. tprints("}");
  465. return RVAL_IOCTL_DECODED;
  466. }
  467. }
  468. static int
  469. print_v4l2_standard(struct tcb *const tcp, const kernel_ulong_t arg)
  470. {
  471. struct_v4l2_standard s;
  472. if (entering(tcp)) {
  473. tprints(", ");
  474. if (umove_or_printaddr(tcp, arg, &s))
  475. return RVAL_IOCTL_DECODED;
  476. tprintf("{index=%u", s.index);
  477. return 0;
  478. }
  479. if (!syserror(tcp) && !umove(tcp, arg, &s)) {
  480. PRINT_FIELD_CSTRING(", ", s, name);
  481. tprintf(", frameperiod=" FMT_FRACT,
  482. ARGS_FRACT(s.frameperiod));
  483. tprintf(", framelines=%d", s.framelines);
  484. }
  485. tprints("}");
  486. return RVAL_IOCTL_DECODED;
  487. }
  488. #include "xlat/v4l2_input_types.h"
  489. static int
  490. print_v4l2_input(struct tcb *const tcp, const kernel_ulong_t arg)
  491. {
  492. struct_v4l2_input i;
  493. if (entering(tcp)) {
  494. tprints(", ");
  495. if (umove_or_printaddr(tcp, arg, &i))
  496. return RVAL_IOCTL_DECODED;
  497. tprintf("{index=%u", i.index);
  498. return 0;
  499. }
  500. if (!syserror(tcp) && !umove(tcp, arg, &i)) {
  501. PRINT_FIELD_CSTRING(", ", i, name);
  502. tprints(", type=");
  503. printxval(v4l2_input_types, i.type, "V4L2_INPUT_TYPE_???");
  504. }
  505. tprints("}");
  506. return RVAL_IOCTL_DECODED;
  507. }
  508. /*
  509. * We include it here and not before print_v4l2_ext_controls as we need
  510. * V4L2_CTRL_CLASS_* definitions for V4L2_CID_*_BASE ones.
  511. */
  512. #include "xlat/v4l2_control_classes.h"
  513. #include "xlat/v4l2_control_id_bases.h"
  514. #include "xlat/v4l2_control_ids.h"
  515. static void
  516. print_v4l2_cid(const uint32_t cid)
  517. {
  518. const char *id_name = xlookup(v4l2_control_ids, cid);
  519. if (id_name) {
  520. print_xlat_ex(cid, id_name, XLAT_STYLE_DEFAULT);
  521. return;
  522. }
  523. uint64_t class_id = cid;
  524. const char *class_str = xlookup_le(v4l2_control_classes, &class_id);
  525. if (!class_str || (cid - class_id) >= 0x10000) {
  526. print_xlat_ex(cid, "V4L2_CID_???", PXF_DEFAULT_STR);
  527. return;
  528. }
  529. char *tmp_str;
  530. if (asprintf(&tmp_str, "%s+%#" PRIx64,
  531. class_str, cid - class_id) < 0)
  532. tmp_str = NULL;
  533. print_xlat_ex(cid, tmp_str, XLAT_STYLE_DEFAULT);
  534. free(tmp_str);
  535. }
  536. static int
  537. print_v4l2_control(struct tcb *const tcp, const kernel_ulong_t arg,
  538. const bool is_get)
  539. {
  540. struct v4l2_control c;
  541. if (entering(tcp)) {
  542. tprints(", ");
  543. if (umove_or_printaddr(tcp, arg, &c))
  544. return RVAL_IOCTL_DECODED;
  545. tprints("{id=");
  546. print_v4l2_cid(c.id);
  547. if (!is_get)
  548. tprintf(", value=%d", c.value);
  549. return 0;
  550. }
  551. if (!syserror(tcp) && !umove(tcp, arg, &c)) {
  552. tprints(is_get ? ", " : " => ");
  553. tprintf("value=%d", c.value);
  554. }
  555. tprints("}");
  556. return RVAL_IOCTL_DECODED;
  557. }
  558. #include "xlat/v4l2_tuner_types.h"
  559. #include "xlat/v4l2_tuner_capabilities.h"
  560. #include "xlat/v4l2_tuner_rxsubchanses.h"
  561. #include "xlat/v4l2_tuner_audmodes.h"
  562. static int
  563. print_v4l2_tuner(struct tcb *const tcp, const kernel_ulong_t arg,
  564. const bool is_get)
  565. {
  566. struct v4l2_tuner c;
  567. if (entering(tcp)) {
  568. tprints(", ");
  569. if (umove_or_printaddr(tcp, arg, &c))
  570. return RVAL_IOCTL_DECODED;
  571. tprintf("{index=%u", c.index);
  572. if (is_get)
  573. return 0;
  574. tprints(", ");
  575. } else {
  576. if (syserror(tcp) || umove(tcp, arg, &c) < 0) {
  577. tprints("}");
  578. return RVAL_IOCTL_DECODED;
  579. }
  580. tprints(is_get ? ", " : " => ");
  581. }
  582. PRINT_FIELD_CSTRING("", c, name);
  583. tprints(", type=");
  584. printxval(v4l2_tuner_types, c.type, "V4L2_TUNER_TYPE_???");
  585. tprints(", capability=");
  586. printxval(v4l2_tuner_capabilities, c.capability,
  587. "V4L2_TUNER_CAP_???");
  588. tprintf(", rangelow=%u, rangehigh=%u, rxsubchans=",
  589. c.rangelow, c.rangehigh);
  590. printxval(v4l2_tuner_rxsubchanses, c.rxsubchans,
  591. "V4L2_TUNER_SUB_???");
  592. tprints(", audmode=");
  593. printxval(v4l2_tuner_audmodes, c.audmode,
  594. "V4L2_TUNER_MODE_???");
  595. tprintf(", signal=%d, afc=%d", c.signal, c.afc);
  596. if (entering(tcp)) {
  597. return 0;
  598. } else {
  599. tprints("}");
  600. return RVAL_IOCTL_DECODED;
  601. }
  602. }
  603. #include "xlat/v4l2_control_types.h"
  604. #include "xlat/v4l2_control_flags.h"
  605. static int
  606. print_v4l2_queryctrl(struct tcb *const tcp, const kernel_ulong_t arg)
  607. {
  608. struct v4l2_queryctrl c;
  609. if (entering(tcp)) {
  610. tprints(", ");
  611. if (umove_or_printaddr(tcp, arg, &c))
  612. return RVAL_IOCTL_DECODED;
  613. tprints("{id=");
  614. } else {
  615. if (syserror(tcp) || umove(tcp, arg, &c) < 0) {
  616. tprints("}");
  617. return RVAL_IOCTL_DECODED;
  618. }
  619. if (get_tcb_priv_ulong(tcp))
  620. tprints(" => ");
  621. }
  622. if (entering(tcp) || get_tcb_priv_ulong(tcp)) {
  623. #ifdef V4L2_CTRL_FLAG_NEXT_CTRL
  624. const unsigned long next = c.id & V4L2_CTRL_FLAG_NEXT_CTRL;
  625. set_tcb_priv_ulong(tcp, next);
  626. if (next) {
  627. print_xlat(V4L2_CTRL_FLAG_NEXT_CTRL);
  628. tprints("|");
  629. c.id &= ~V4L2_CTRL_FLAG_NEXT_CTRL;
  630. }
  631. #endif
  632. printxval(v4l2_control_ids, c.id, "V4L2_CID_???");
  633. }
  634. if (exiting(tcp)) {
  635. tprints(", type=");
  636. printxval(v4l2_control_types, c.type, "V4L2_CTRL_TYPE_???");
  637. PRINT_FIELD_CSTRING(", ", c, name);
  638. tprintf(", minimum=%d, maximum=%d, step=%d"
  639. ", default_value=%d, flags=",
  640. c.minimum, c.maximum, c.step, c.default_value);
  641. printflags(v4l2_control_flags, c.flags, "V4L2_CTRL_FLAG_???");
  642. tprints("}");
  643. }
  644. return entering(tcp) ? 0 : RVAL_IOCTL_DECODED;
  645. }
  646. static int
  647. print_v4l2_cropcap(struct tcb *const tcp, const kernel_ulong_t arg)
  648. {
  649. struct v4l2_cropcap c;
  650. if (entering(tcp)) {
  651. tprints(", ");
  652. if (umove_or_printaddr(tcp, arg, &c))
  653. return RVAL_IOCTL_DECODED;
  654. tprints("{type=");
  655. printxval(v4l2_buf_types, c.type, "V4L2_BUF_TYPE_???");
  656. return 0;
  657. }
  658. if (!syserror(tcp) && !umove(tcp, arg, &c)) {
  659. tprintf(", bounds=" FMT_RECT
  660. ", defrect=" FMT_RECT
  661. ", pixelaspect=" FMT_FRACT,
  662. ARGS_RECT(c.bounds),
  663. ARGS_RECT(c.defrect),
  664. ARGS_FRACT(c.pixelaspect));
  665. }
  666. tprints("}");
  667. return RVAL_IOCTL_DECODED;
  668. }
  669. static int
  670. print_v4l2_crop(struct tcb *const tcp, const kernel_ulong_t arg,
  671. const bool is_get)
  672. {
  673. struct v4l2_crop c;
  674. if (entering(tcp)) {
  675. tprints(", ");
  676. if (umove_or_printaddr(tcp, arg, &c))
  677. return RVAL_IOCTL_DECODED;
  678. tprints("{type=");
  679. printxval(v4l2_buf_types, c.type, "V4L2_BUF_TYPE_???");
  680. if (is_get)
  681. return 0;
  682. tprintf(", c=" FMT_RECT, ARGS_RECT(c.c));
  683. } else {
  684. if (!syserror(tcp) && !umove(tcp, arg, &c))
  685. tprintf(", c=" FMT_RECT, ARGS_RECT(c.c));
  686. }
  687. tprints("}");
  688. return RVAL_IOCTL_DECODED;
  689. }
  690. #ifdef VIDIOC_S_EXT_CTRLS
  691. static bool
  692. print_v4l2_ext_control(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
  693. {
  694. const struct_v4l2_ext_control *p = elem_buf;
  695. tprints("{id=");
  696. printxval(v4l2_control_ids, p->id, "V4L2_CID_???");
  697. # if HAVE_STRUCT_V4L2_EXT_CONTROL_STRING
  698. tprintf(", size=%u", p->size);
  699. if (p->size > 0) {
  700. tprints(", string=");
  701. printstrn(tcp, ptr_to_kulong(p->string), p->size);
  702. } else
  703. # endif
  704. tprintf(", value=%d, value64=%" PRId64, p->value, (int64_t) p->value64);
  705. tprints("}");
  706. return true;
  707. }
  708. static int
  709. print_v4l2_ext_controls(struct tcb *const tcp, const kernel_ulong_t arg,
  710. const bool is_get)
  711. {
  712. struct_v4l2_ext_controls c;
  713. if (entering(tcp)) {
  714. tprints(", ");
  715. if (umove_or_printaddr(tcp, arg, &c))
  716. return RVAL_IOCTL_DECODED;
  717. tprints("{ctrl_class=");
  718. printxval(v4l2_control_classes, c.ctrl_class,
  719. "V4L2_CTRL_CLASS_???");
  720. tprintf(", count=%u", c.count);
  721. if (!c.count) {
  722. tprints("}");
  723. return RVAL_IOCTL_DECODED;
  724. }
  725. if (is_get)
  726. return 0;
  727. tprints(", ");
  728. } else {
  729. if (umove(tcp, arg, &c) < 0) {
  730. tprints("}");
  731. return RVAL_IOCTL_DECODED;
  732. }
  733. tprints(is_get ? ", " : " => ");
  734. }
  735. tprints("controls=");
  736. struct_v4l2_ext_control ctrl;
  737. bool fail = !print_array(tcp, ptr_to_kulong(c.controls), c.count,
  738. &ctrl, sizeof(ctrl),
  739. tfetch_mem_ignore_syserror,
  740. print_v4l2_ext_control, 0);
  741. if (exiting(tcp) && syserror(tcp))
  742. tprintf(", error_idx=%u", c.error_idx);
  743. if (exiting(tcp) || fail) {
  744. tprints("}");
  745. return RVAL_IOCTL_DECODED;
  746. }
  747. /* entering */
  748. return 0;
  749. }
  750. #endif /* VIDIOC_S_EXT_CTRLS */
  751. #ifdef VIDIOC_ENUM_FRAMESIZES
  752. # include "xlat/v4l2_framesize_types.h"
  753. static int
  754. print_v4l2_frmsizeenum(struct tcb *const tcp, const kernel_ulong_t arg)
  755. {
  756. struct v4l2_frmsizeenum s;
  757. if (entering(tcp)) {
  758. tprints(", ");
  759. if (umove_or_printaddr(tcp, arg, &s))
  760. return RVAL_IOCTL_DECODED;
  761. tprintf("{index=%u, pixel_format=", s.index);
  762. print_pixelformat(s.pixel_format, v4l2_pix_fmts);
  763. return 0;
  764. }
  765. if (!syserror(tcp) && !umove(tcp, arg, &s)) {
  766. tprints(", type=");
  767. printxval(v4l2_framesize_types, s.type, "V4L2_FRMSIZE_TYPE_???");
  768. switch (s.type) {
  769. case V4L2_FRMSIZE_TYPE_DISCRETE:
  770. tprintf(", discrete={width=%u, height=%u}",
  771. s.discrete.width, s.discrete.height);
  772. break;
  773. case V4L2_FRMSIZE_TYPE_STEPWISE:
  774. tprintf(", stepwise={min_width=%u, max_width=%u, "
  775. "step_width=%u, min_height=%u, max_height=%u, "
  776. "step_height=%u}",
  777. s.stepwise.min_width, s.stepwise.max_width,
  778. s.stepwise.step_width, s.stepwise.min_height,
  779. s.stepwise.max_height, s.stepwise.step_height);
  780. break;
  781. }
  782. }
  783. tprints("}");
  784. return RVAL_IOCTL_DECODED;
  785. }
  786. #endif /* VIDIOC_ENUM_FRAMESIZES */
  787. #ifdef VIDIOC_ENUM_FRAMEINTERVALS
  788. # include "xlat/v4l2_frameinterval_types.h"
  789. static int
  790. print_v4l2_frmivalenum(struct tcb *const tcp, const kernel_ulong_t arg)
  791. {
  792. struct v4l2_frmivalenum f;
  793. if (entering(tcp)) {
  794. tprints(", ");
  795. if (umove_or_printaddr(tcp, arg, &f))
  796. return RVAL_IOCTL_DECODED;
  797. tprintf("{index=%u, pixel_format=", f.index);
  798. print_pixelformat(f.pixel_format, v4l2_pix_fmts);
  799. tprintf(", width=%u, height=%u", f.width, f.height);
  800. return 0;
  801. }
  802. if (!syserror(tcp) && !umove(tcp, arg, &f)) {
  803. tprints(", type=");
  804. printxval(v4l2_frameinterval_types, f.type,
  805. "V4L2_FRMIVAL_TYPE_???");
  806. switch (f.type) {
  807. case V4L2_FRMIVAL_TYPE_DISCRETE:
  808. tprintf(", discrete=" FMT_FRACT,
  809. ARGS_FRACT(f.discrete));
  810. break;
  811. case V4L2_FRMIVAL_TYPE_STEPWISE:
  812. case V4L2_FRMSIZE_TYPE_CONTINUOUS:
  813. tprintf(", stepwise={min=" FMT_FRACT ", max="
  814. FMT_FRACT ", step=" FMT_FRACT "}",
  815. ARGS_FRACT(f.stepwise.min),
  816. ARGS_FRACT(f.stepwise.max),
  817. ARGS_FRACT(f.stepwise.step));
  818. break;
  819. }
  820. }
  821. tprints("}");
  822. return RVAL_IOCTL_DECODED;
  823. }
  824. #endif /* VIDIOC_ENUM_FRAMEINTERVALS */
  825. #ifdef VIDIOC_CREATE_BUFS
  826. static int
  827. print_v4l2_create_buffers(struct tcb *const tcp, const kernel_ulong_t arg)
  828. {
  829. static const char fmt[] = "{index=%u, count=%u}";
  830. static char outstr[sizeof(fmt) + sizeof(int) * 6];
  831. struct_v4l2_create_buffers b;
  832. if (entering(tcp)) {
  833. tprints(", ");
  834. if (umove_or_printaddr(tcp, arg, &b))
  835. return RVAL_IOCTL_DECODED;
  836. tprintf("{count=%u, memory=", b.count);
  837. printxval(v4l2_memories, b.memory, "V4L2_MEMORY_???");
  838. tprints(", format={type=");
  839. printxval(v4l2_buf_types, b.format.type,
  840. "V4L2_BUF_TYPE_???");
  841. print_v4l2_format_fmt(tcp, ", ",
  842. (struct_v4l2_format *) &b.format);
  843. tprints("}}");
  844. return 0;
  845. }
  846. if (syserror(tcp) || umove(tcp, arg, &b))
  847. return RVAL_IOCTL_DECODED;
  848. xsprintf(outstr, fmt, b.index, b.count);
  849. tcp->auxstr = outstr;
  850. return RVAL_IOCTL_DECODED | RVAL_STR;
  851. }
  852. #endif /* VIDIOC_CREATE_BUFS */
  853. MPERS_PRINTER_DECL(int, v4l2_ioctl, struct tcb *const tcp,
  854. const unsigned int code, const kernel_ulong_t arg)
  855. {
  856. if (!verbose(tcp))
  857. return RVAL_DECODED;
  858. switch (code) {
  859. case VIDIOC_QUERYCAP: /* R */
  860. return print_v4l2_capability(tcp, arg);
  861. case VIDIOC_ENUM_FMT: /* RW */
  862. return print_v4l2_fmtdesc(tcp, arg);
  863. case VIDIOC_G_FMT: /* RW */
  864. case VIDIOC_S_FMT: /* RW */
  865. case VIDIOC_TRY_FMT: /* RW */
  866. return print_v4l2_format(tcp, arg, code == VIDIOC_G_FMT);
  867. case VIDIOC_REQBUFS: /* RW */
  868. return print_v4l2_requestbuffers(tcp, arg);
  869. case VIDIOC_QUERYBUF: /* RW */
  870. case VIDIOC_QBUF: /* RW */
  871. case VIDIOC_DQBUF: /* RW */
  872. return print_v4l2_buffer(tcp, code, arg);
  873. case VIDIOC_G_FBUF: /* R */
  874. if (entering(tcp))
  875. return 0;
  876. ATTRIBUTE_FALLTHROUGH;
  877. case VIDIOC_S_FBUF: /* W */
  878. return print_v4l2_framebuffer(tcp, arg);
  879. case VIDIOC_STREAMON: /* W */
  880. case VIDIOC_STREAMOFF: /* W */
  881. return print_v4l2_buf_type(tcp, arg);
  882. case VIDIOC_G_PARM: /* RW */
  883. case VIDIOC_S_PARM: /* RW */
  884. return print_v4l2_streamparm(tcp, arg, code == VIDIOC_G_PARM);
  885. case VIDIOC_G_STD: /* R */
  886. if (entering(tcp))
  887. return 0;
  888. ATTRIBUTE_FALLTHROUGH;
  889. case VIDIOC_S_STD: /* W */
  890. tprints(", ");
  891. printnum_int64(tcp, arg, "%#" PRIx64);
  892. break;
  893. case VIDIOC_ENUMSTD: /* RW */
  894. return print_v4l2_standard(tcp, arg);
  895. case VIDIOC_ENUMINPUT: /* RW */
  896. return print_v4l2_input(tcp, arg);
  897. case VIDIOC_G_CTRL: /* RW */
  898. case VIDIOC_S_CTRL: /* RW */
  899. return print_v4l2_control(tcp, arg, code == VIDIOC_G_CTRL);
  900. case VIDIOC_G_TUNER: /* RW */
  901. case VIDIOC_S_TUNER: /* RW */
  902. return print_v4l2_tuner(tcp, arg, code == VIDIOC_G_TUNER);
  903. case VIDIOC_QUERYCTRL: /* RW */
  904. return print_v4l2_queryctrl(tcp, arg);
  905. case VIDIOC_G_INPUT: /* R */
  906. if (entering(tcp))
  907. return 0;
  908. ATTRIBUTE_FALLTHROUGH;
  909. case VIDIOC_S_INPUT: /* RW */
  910. tprints(", ");
  911. printnum_int(tcp, arg, "%u");
  912. break;
  913. case VIDIOC_CROPCAP: /* RW */
  914. return print_v4l2_cropcap(tcp, arg);
  915. case VIDIOC_G_CROP: /* RW */
  916. case VIDIOC_S_CROP: /* W */
  917. return print_v4l2_crop(tcp, arg, code == VIDIOC_G_CROP);
  918. #ifdef VIDIOC_S_EXT_CTRLS
  919. case VIDIOC_S_EXT_CTRLS: /* RW */
  920. case VIDIOC_TRY_EXT_CTRLS: /* RW */
  921. case VIDIOC_G_EXT_CTRLS: /* RW */
  922. return print_v4l2_ext_controls(tcp, arg,
  923. code == VIDIOC_G_EXT_CTRLS);
  924. #endif /* VIDIOC_S_EXT_CTRLS */
  925. #ifdef VIDIOC_ENUM_FRAMESIZES
  926. case VIDIOC_ENUM_FRAMESIZES: /* RW */
  927. return print_v4l2_frmsizeenum(tcp, arg);
  928. #endif /* VIDIOC_ENUM_FRAMESIZES */
  929. #ifdef VIDIOC_ENUM_FRAMEINTERVALS
  930. case VIDIOC_ENUM_FRAMEINTERVALS: /* RW */
  931. return print_v4l2_frmivalenum(tcp, arg);
  932. #endif /* VIDIOC_ENUM_FRAMEINTERVALS */
  933. #ifdef VIDIOC_CREATE_BUFS
  934. case VIDIOC_CREATE_BUFS: /* RW */
  935. return print_v4l2_create_buffers(tcp, arg);
  936. #endif /* VIDIOC_CREATE_BUFS */
  937. default:
  938. return RVAL_DECODED;
  939. }
  940. return RVAL_IOCTL_DECODED;
  941. }