#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;

	/*
	 * 1st argument: tag
	 * 2nd argument: channel
	 */

	tag = FWISO_TAG1;
	channel = 63;
	switch (argc) {
	case 3:
		channel = atoi(argv[2]);
		if (channel < 0 || channel > 64) {
			fprintf(stderr, "fwisochmod: channel [0:64]\n");
			exit(1);
		}
		fprintf(stderr, "channel set %d\n", channel);
	case 2:			/* fallthrough */
		tag = atoi(argv[1]);
		if (tag < 0 > tag > 7) {
			fprintf(stderr, "fwisochmod: tag [0:7]\n");
			exit(1);
		}
		fprintf(stderr, "tag set %d\n", tag);
		break;
	}

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

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

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

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

	close(fd);
}

