2 * pccardd UNIX-domain socket interface
3 * Copyright (C) 1996 by Tatsumi Hosokawa <hosokawa@mt.cs.keio.ac.jp>
5 * $Id: server.c,v 1.3 1999/02/07 08:02:44 kuriyama Exp $
9 static const char rcsid[] =
10 "$FreeBSD: src/usr.sbin/pccard/pccardd/server.c,v 1.2.2.1 2000/08/26 15:49:48 ume Exp $";
15 #include <sys/types.h>
16 #include <sys/ioctl.h>
17 #include <sys/socket.h>
30 for (sp = slots; sp; sp = sp->next)
34 sprintf(buf, "%2d", i);
42 /* Search the list until we find the slot or get to the end */
43 for (sp = slots; sp && sp->slot != slot; sp = sp->next)
50 cardname(char *buf, int slot)
53 char *manuf, *vers, *drv, *stat;
55 /* Look for the slot */
56 if ( (sp = find_slot(slot)) == NULL)
59 /* Fill in the information in the buff */
62 manuf = sp->cis->manuf;
64 if (sp->config && sp->config->driver &&
65 sp->config->driver->name)
66 drv = sp->config->driver->name;
70 manuf = vers = drv = "";
85 sprintf(buf, "%d~%s~%s~%s~%s", slot, manuf, vers, drv, stat);
89 cardpwr(int slot, int pwon)
93 /* Look for the slot */
94 if ( (sp = find_slot(slot)) == NULL)
97 if (ioctl(sp->fd, PIOCSVIR, &pwon) < 0)
98 logerr("invaild arguments for cardpwr");
103 static struct sockaddr_un sun;
112 stat_changed(struct slot *sp)
120 cardname(buf, sp->slot);
122 if (sendto(sock, buf, len, 0, (struct sockaddr *) & sun, slen) != len) {
123 logerr("sendto failed");
131 char buf[512], obuf[512];
138 len = recvfrom(sock, buf, sizeof(buf),
139 0, (struct sockaddr *)&sun, &slen);
141 logerr("recvfrom failed");
144 switch (buf[0]) { /* Protocol implementation */
145 case 'S': /* How many slots? */
148 case 'N': /* Card name request */
149 sscanf(buf + 1, "%d", &snum);
150 if (snum >= 0 && snum <= MAXSLOT)
151 cardname(obuf, snum);
153 logerr("Illegal slot requests for N command");
155 case 'P': /* Virtual insertion request */
156 sscanf(buf + 1, "%d", &snum);
157 if (snum >= 0 && snum <= MAXSLOT) {
158 logmsg("slot %d: spring has come", snum);
161 logerr("Illegal slot requests for P command");
163 case 'Q': /* Virtual removal request */
164 sscanf(buf + 1, "%d", &snum);
165 if (snum >= 0 && snum <= MAXSLOT) {
166 logmsg("slot %d: hibernation", snum);
169 logerr("Illegal slot requests for Q command");
172 logerr("Unknown control message from socket");
177 if (sendto(sock, obuf, len, 0, (struct sockaddr *)&sun, slen)
179 logerr("sendto failed");
182 } else if (sendto(sock, 0, 0, 0, (struct sockaddr *)&sun, slen)
184 logerr("sendto failed");