#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <dev/ieee1394/fwiso_ioctl.h>


main(int argc, char **argv)
{
	int fd;
	int mode;
	int tag;
	int channel;
	struct fwiso_if isoif;
	const static char *modename[FWISO_MODE_MAX + 1] = {
		"RAW", "DV", "DV_RAW", "MPEG2TS", "unknown"
	};

	if ((fd = open("/dev/fwiso0", O_RDONLY, 0)) < 0) {
		perror("opening /dev/fwiso0");
		exit(1);
	}

	if (ioctl(fd, FWISOGETIF, &isoif) < 0) {
		perror("ioctl FWISOGETIF");
		exit(1);
	}

	if (ioctl(fd, FWISOGETMODE, &mode) < 0) {
		perror("ioctl FWISOGETMODE");
		exit(1);
	}

	if (ioctl(fd, FWISOGETCHANNEL, &channel) < 0) {
		perror("ioctl FWISOGETCHANNEL");
		exit(1);
	}

	if (ioctl(fd, FWISOGETTAG, &tag) < 0) {
		perror("ioctl FWISOGETTAG");
		exit(1);
	}

	if (mode < 0 || mode > FWISO_MODE_MAX) {
		mode = FWISO_MODE_MAX;
	}

	printf("%s: mode FWISO_MODE_%s channel %d tag%s%s%s%s\n",
	    isoif.fi_name, modename[mode], channel,
	    tag & FWISO_TAG0 ? " TAG0" : "",
	    tag & FWISO_TAG1 ? " TAG1" : "",
	    tag & FWISO_TAG2 ? " TAG2" : "",
	    tag & FWISO_TAG3 ? " TAG3" : "");

	close(fd);
}

