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 $
7 * $FreeBSD: src/usr.sbin/pccard/pccardd/server.c,v 1.2.2.1 2000/08/26 15:49:48 ume Exp $
8 * $DragonFly: src/usr.sbin/pccard/pccardd/Attic/server.c,v 1.2 2003/06/17 04:29:59 dillon Exp $
13 #include <sys/types.h>
14 #include <sys/ioctl.h>
15 #include <sys/socket.h>
28 for (sp = slots; sp; sp = sp->next)
32 sprintf(buf, "%2d", i);
40 /* Search the list until we find the slot or get to the end */
41 for (sp = slots; sp && sp->slot != slot; sp = sp->next)
48 cardname(char *buf, int slot)
51 char *manuf, *vers, *drv, *stat;
53 /* Look for the slot */
54 if ( (sp = find_slot(slot)) == NULL)
57 /* Fill in the information in the buff */
60 manuf = sp->cis->manuf;
62 if (sp->config && sp->config->driver &&
63 sp->config->driver->name)
64 drv = sp->config->driver->name;
68 manuf = vers = drv = "";
83 sprintf(buf, "%d~%s~%s~%s~%s", slot, manuf, vers, drv, stat);
87 cardpwr(int slot, int pwon)
91 /* Look for the slot */
92 if ( (sp = find_slot(slot)) == NULL)
95 if (ioctl(sp->fd, PIOCSVIR, &pwon) < 0)
96 logerr("invaild arguments for cardpwr");
101 static struct sockaddr_un sun;
110 stat_changed(struct slot *sp)
118 cardname(buf, sp->slot);
120 if (sendto(sock, buf, len, 0, (struct sockaddr *) & sun, slen) != len) {
121 logerr("sendto failed");
129 char buf[512], obuf[512];
136 len = recvfrom(sock, buf, sizeof(buf),
137 0, (struct sockaddr *)&sun, &slen);
139 logerr("recvfrom failed");
142 switch (buf[0]) { /* Protocol implementation */
143 case 'S': /* How many slots? */
146 case 'N': /* Card name request */
147 sscanf(buf + 1, "%d", &snum);
148 if (snum >= 0 && snum <= MAXSLOT)
149 cardname(obuf, snum);
151 logerr("Illegal slot requests for N command");
153 case 'P': /* Virtual insertion request */
154 sscanf(buf + 1, "%d", &snum);
155 if (snum >= 0 && snum <= MAXSLOT) {
156 logmsg("slot %d: spring has come", snum);
159 logerr("Illegal slot requests for P command");
161 case 'Q': /* Virtual removal request */
162 sscanf(buf + 1, "%d", &snum);
163 if (snum >= 0 && snum <= MAXSLOT) {
164 logmsg("slot %d: hibernation", snum);
167 logerr("Illegal slot requests for Q command");
170 logerr("Unknown control message from socket");
175 if (sendto(sock, obuf, len, 0, (struct sockaddr *)&sun, slen)
177 logerr("sendto failed");
180 } else if (sendto(sock, 0, 0, 0, (struct sockaddr *)&sun, slen)
182 logerr("sendto failed");