Merge branch 'vendor/WPA_SUPPLICANT'
[dragonfly.git] / share / examples / kld / cdev / test / testcdev.c
1 /* 08 Nov 1998*/
2 /*
3  * testmisc.c
4  *
5  * Test program to call the sample loaded kld device driver.
6  *
7  * 05 Jun 93    Rajesh Vaidheeswarran           Original
8  *
9  *
10  * Copyright (c) 1993 Rajesh Vaidheeswarran.
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. All advertising materials mentioning features or use of this software
22  *    must display the following acknowledgement:
23  *      This product includes software developed by Rajesh Vaidheeswarran.
24  * 4. The name Rajesh Vaidheeswarran may not be used to endorse or promote
25  *    products derived from this software without specific prior written
26  *    permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY RAJESH VAIDHEESWARRAN ``AS IS'' AND ANY
29  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE RAJESH VAIDHEESWARRAN BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  * Copyright (c) 1993 Terrence R. Lambert.
41  * All rights reserved.
42  *
43  * Redistribution and use in source and binary forms, with or without
44  * modification, are permitted provided that the following conditions
45  * are met:
46  * 1. Redistributions of source code must retain the above copyright
47  *    notice, this list of conditions and the following disclaimer.
48  * 2. Redistributions in binary form must reproduce the above copyright
49  *    notice, this list of conditions and the following disclaimer in the
50  *    documentation and/or other materials provided with the distribution.
51  * 3. All advertising materials mentioning features or use of this software
52  *    must display the following acknowledgement:
53  *      This product includes software developed by Terrence R. Lambert.
54  * 4. The name Terrence R. Lambert may not be used to endorse or promote
55  *    products derived from this software without specific prior written
56  *    permission.
57  *
58  * THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``AS IS'' AND ANY
59  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61  * ARE DISCLAIMED.  IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
62  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68  * SUCH DAMAGE.
69  *
70  *
71  * $FreeBSD: src/share/examples/kld/cdev/test/testcdev.c,v 1.2.2.2 2000/12/11 01:03:26 obrien Exp $
72  * $DragonFly: src/share/examples/kld/cdev/test/testcdev.c,v 1.2 2003/06/17 04:36:57 dillon Exp $
73  */
74
75 #include <stdio.h>
76 #include <stdlib.h>
77 #include <fcntl.h>
78 #include <paths.h>
79 #include <string.h>
80 #include <unistd.h>
81 #include <sys/ioccom.h>
82
83 #define CDEV_IOCTL1     _IOR('C', 1, u_int)
84 #define CDEV_DEVICE     "cdev"
85
86 static char writestr[] = "Hello kernel!";
87 static char buf[512+1];
88
89 int
90 main(int argc, char *argv[])
91 {
92         int kernel_fd;
93         int one;
94         int len;
95
96         if ((kernel_fd = open("/dev/" CDEV_DEVICE, O_RDWR)) == -1) {
97                 perror("/dev/" CDEV_DEVICE);
98                 exit(1);
99         }
100
101         /* Send ioctl */
102         if (ioctl(kernel_fd, CDEV_IOCTL1, &one) == -1) {
103                 perror("CDEV_IOCTL1");
104         }
105         else {
106                 printf("Sent ioctl CDEV_IOCTL1 to device %s%s\n", _PATH_DEV,
107                     CDEV_DEVICE);
108         }
109
110         len = strlen(writestr) + 1;
111
112         /* Write operation */
113         if (write(kernel_fd, writestr, len) == -1) {
114                 perror("write()");
115         }
116         else {
117                 printf("Written \"%s\" string to device /dev/" CDEV_DEVICE "\n",
118                     writestr);
119         }
120
121         /* Read operation */
122         if (read(kernel_fd, buf, len) == -1) {
123                 perror("read()");
124         }
125         else {
126                 printf("Read \"%s\" string from device /dev/" CDEV_DEVICE "\n",
127                     buf);
128         }
129
130         exit(0);
131 }