1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2019, Joyent, Inc.
14  */
15 
16 /*
17  * Verify that we can grab a basic exclusive lock through an ioctl on the slot.
18  * Then that we can release it afterwards.
19  */
20 
21 #include <err.h>
22 #include <stdlib.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <strings.h>
27 #include <unistd.h>
28 
29 #include <sys/usb/clients/ccid/uccid.h>
30 
31 int
32 main(int argc, char *argv[])
33 {
34 	int fd;
35 	uint_t i;
36 	uccid_cmd_txn_begin_t begin;
37 	uccid_cmd_txn_end_t end;
38 
39 	if (argc != 2) {
40 		errx(EXIT_FAILURE, "missing required ccid path");
41 	}
42 
43 	if ((fd = open(argv[1], O_RDWR)) < 0) {
44 		err(EXIT_FAILURE, "failed to open %s", argv[1]);
45 	}
46 
47 	bzero(&begin, sizeof (begin));
48 	bzero(&end, sizeof (end));
49 
50 	begin.uct_version = UCCID_CURRENT_VERSION;
51 	end.uct_version = UCCID_CURRENT_VERSION;
52 	end.uct_flags = UCCID_TXN_END_RELEASE;
53 
54 	for (i = 0; i < 10; i++) {
55 		if (ioctl(fd, UCCID_CMD_TXN_BEGIN, &begin) != 0) {
56 			err(EXIT_FAILURE, "failed to issue begin ioctl");
57 		}
58 
59 		if (ioctl(fd, UCCID_CMD_TXN_END, &end) != 0) {
60 			err(EXIT_FAILURE, "failed to issue end ioctl");
61 		}
62 	}
63 
64 	return (0);
65 }
66