1 /* $NetBSD: irdaattach.c,v 1.7 2008/04/28 20:24:16 martin Exp $ */
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net).
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 * Inspired by slattach.c.
35 #include <sys/ioctl.h>
36 #include <dev/ir/irdaio.h>
49 int main(int, char **);
53 main(int argc
, char **argv
)
56 char *dev
, devbuf
[100];
57 const char *donglename
= "none";
59 tcflag_t cflag
= HUPCL
;
68 while ((ch
= getopt(argc
, argv
, "d:fhHlmnp")) != -1) {
106 if (strncmp(_PATH_DEV
, dev
, sizeof(_PATH_DEV
) - 1)) {
107 (void)snprintf(devbuf
, sizeof(devbuf
),
108 "%s%s", _PATH_DEV
, dev
);
111 if ((fd
= open(dev
, O_RDWR
| O_NDELAY
)) < 0)
113 tty
.c_cflag
= CREAD
| CS8
| cflag
;
119 cfsetspeed(&tty
, 9600);
120 if (tcsetattr(fd
, TCSADRAIN
, &tty
) < 0)
122 if (ioctl(fd
, TIOCSDTR
, 0) < 0)
124 if (ioctl(fd
, TIOCSLINED
, "irframe") < 0)
125 err(1, "TIOCSLINED");
127 if (ioctl(fd
, IRFRAMETTY_GET_DEVICE
, &frdev
) < 0)
128 err(1, "IRFRAMETTY_GET_DEVICE");
129 printf("%sirframe%d\n", _PATH_DEV
, frdev
);
131 if (strcmp(donglename
, "none") == 0)
132 dongle
= DONGLE_NONE
;
133 else if (strcmp(donglename
, "tekram") == 0)
134 dongle
= DONGLE_TEKRAM
;
135 else if (strcmp(donglename
, "jeteye") == 0)
136 dongle
= DONGLE_JETEYE
;
137 else if (strcmp(donglename
, "actisys") == 0)
138 dongle
= DONGLE_ACTISYS
;
139 else if (strcmp(donglename
, "actisys+") == 0)
140 dongle
= DONGLE_ACTISYS_PLUS
;
141 else if (strcmp(donglename
, "litelink") == 0)
142 dongle
= DONGLE_LITELINK
;
143 else if (strcmp(donglename
, "girbil") == 0)
144 dongle
= DONGLE_GIRBIL
;
146 errx(1, "Unknown dongle");
147 if (ioctl(fd
, IRFRAMETTY_SET_DONGLE
, &dongle
) < 0)
148 err(1, "IRFRAMETTY_SET_DONGLE");
151 if (opt_detach
&& daemon(0, 0) != 0)
152 err(1, "couldn't detach");
155 sigemptyset(&nsigset
);
157 sigsuspend(&nsigset
);
164 fprintf(stderr
, "usage: %s [-d donglename] [-fhHlmnp] ttyname\n",