# Copyright 2018 syzkaller project authors. All rights reserved.
# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

include <uapi/linux/fcntl.h>
include <uapi/linux/uinput.h>

resource fd_uinput[fd]

openat$uinput(fd const[AT_FDCWD], file ptr[in, string["/dev/uinput"]], flags flags[uinput_open_flags], mode const[0]) fd_uinput
write$uinput_user_dev(fd fd_uinput, data ptr[in, uinput_user_dev], len len[data])
write$input_event(fd fd_uinput, data ptr[in, input_event], len len[data])
ioctl$UI_GET_VERSION(fd fd_uinput, cmd const[UI_GET_VERSION], arg ptr[out, int32])
ioctl$UI_DEV_CREATE(fd fd_uinput, cmd const[UI_DEV_CREATE])
ioctl$UI_DEV_DESTROY(fd fd_uinput, cmd const[UI_DEV_DESTROY])
ioctl$UI_DEV_SETUP(fd fd_uinput, cmd const[UI_DEV_SETUP], arg ptr[in, uinput_setup])
ioctl$UI_SET_EVBIT(fd fd_uinput, cmd const[UI_SET_EVBIT], arg intptr[0:EV_MAX])
ioctl$UI_SET_KEYBIT(fd fd_uinput, cmd const[UI_SET_KEYBIT], arg intptr[0:KEY_MAX])
ioctl$UI_SET_RELBIT(fd fd_uinput, cmd const[UI_SET_RELBIT], arg intptr[0:REL_MAX])
ioctl$UI_SET_MSCBIT(fd fd_uinput, cmd const[UI_SET_MSCBIT], arg intptr[0:ABS_MAX])
ioctl$UI_SET_ABSBIT(fd fd_uinput, cmd const[UI_SET_ABSBIT], arg intptr[0:MSC_MAX])
ioctl$UI_SET_LEDBIT(fd fd_uinput, cmd const[UI_SET_LEDBIT], arg intptr[0:LED_MAX])
ioctl$UI_SET_SNDBIT(fd fd_uinput, cmd const[UI_SET_SNDBIT], arg intptr[0:SND_MAX])
ioctl$UI_SET_FFBIT(fd fd_uinput, cmd const[UI_SET_FFBIT], arg intptr[0:FF_MAX])
ioctl$UI_SET_SWBIT(fd fd_uinput, cmd const[UI_SET_SWBIT], arg intptr[0:SW_MAX])
ioctl$UI_SET_PROPBIT(fd fd_uinput, cmd const[UI_SET_PROPBIT], arg intptr[0:INPUT_PROP_MAX])
ioctl$UI_SET_PHYS(fd fd_uinput, cmd const[UI_SET_PHYS], arg ptr[in, string[uinput_names]])
ioctl$UI_BEGIN_FF_UPLOAD(fd fd_uinput, cmd const[UI_BEGIN_FF_UPLOAD], arg ptr[in, uinput_ff_upload])
ioctl$UI_BEGIN_FF_ERASE(fd fd_uinput, cmd const[UI_BEGIN_FF_ERASE], arg ptr[in, uinput_ff_erase])
ioctl$UI_END_FF_UPLOAD(fd fd_uinput, cmd const[UI_END_FF_UPLOAD], arg ptr[in, uinput_ff_upload])
ioctl$UI_END_FF_ERASE(fd fd_uinput, cmd const[UI_END_FF_ERASE], arg ptr[in, uinput_ff_erase])
ioctl$UI_GET_SYSNAME(fd fd_uinput, cmd const[UI_GET_SYSNAME_64], arg ptr[out, array[int8, 64]])
ioctl$UI_ABS_SETUP(fd fd_uinput, cmd const[UI_ABS_SETUP], arg ptr[in, uinput_abs_setup])

input_id {
	bustype	int16
	vendor	int16
	product	int16
	version	int16
}

uinput_user_dev {
	name		string[uinput_names, UINPUT_MAX_NAME_SIZE]
	id		input_id
	ff_effects_max	int32[1:FF_EFFECT_MAX]
	absmax		array[int32, ABS_CNT]
	absmin		array[int32, ABS_CNT]
	absfuzz		array[int32, ABS_CNT]
	absflat		array[int32, ABS_CNT]
}

uinput_setup {
	id		input_id
	name		string[uinput_names, UINPUT_MAX_NAME_SIZE]
	ff_effects_max	int32[1:FF_EFFECT_MAX]
}

uinput_ff_upload {
	request_id	int32[0:16]
	retval		int32
	effect		ff_effect
	old		ff_effect
}

uinput_ff_erase {
	request_id	int32[0:16]
	retval		int32
	effect_id	int32
}

uinput_abs_setup {
	code	int16
	absinfo	input_absinfo
}

uinput_names = "syz0", "syz1"
uinput_open_flags = O_RDWR, O_RDWR_NONBLOCK

define UI_GET_SYSNAME_64	UI_GET_SYSNAME(64)