Delete now-unused portion of pccardd. OLDCARD is gone from the kernel.

This commit is contained in:
Warner Losh 2006-10-18 20:48:05 +00:00
parent a8a3bce91e
commit 876e9ce41a
9 changed files with 0 additions and 3595 deletions

View File

@ -1,15 +0,0 @@
# Makefile for pccardd
# $FreeBSD$
.PATH: ${.CURDIR}/../pccardc
PROG= pccardd
MAN= pccard.conf.5 pccardd.8
SRCS= pccardd.c cardd.c file.c util.c readcis.c printcis.c server.c
CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../pccardc
DPADD= ${LIBUTIL}
LDADD= -lutil
.include <bsd.prog.mk>

File diff suppressed because it is too large Load Diff

View File

@ -1,211 +0,0 @@
/*
* Copyright (c) 1995 Andrew McRae. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*
* Common include file for PCMCIA daemon
*/
#include <bitstring.h>
#include <pccard/cardinfo.h>
#include <pccard/cis.h>
#include "readcis.h"
#ifndef EXTERN
#define EXTERN extern
#endif
struct cmd {
struct cmd *next;
char *line; /* Command line */
int macro; /* Contains macros */
};
struct card_config {
struct card_config *next;
unsigned char index_type;
unsigned char index;
struct driver *driver;
int irq;
int flags;
char inuse;
};
struct ether {
struct ether *next;
int type;
int value;
};
#define ETHTYPE_GENERIC 0
#define ETHTYPE_ATTR2 1
struct card {
struct card *next;
char *manuf;
char *version;
char *add_info1;
char *add_info2;
u_char func_id;
int deftype;
struct ether *ether; /* For net cards, ether at offset */
int reset_time; /* Reset time */
int iosize; /* I/O window size (ignore location) */
struct card_config *config; /* List of configs */
struct cmd *insert; /* Insert commands */
struct cmd *remove; /* Remove commands */
char *logstr; /* String for logger */
};
struct driver {
struct driver *next;
char *name;
char *kernel; /* Kernel driver base name */
int unit; /* Unit of driver */
/*
* The rest of the structure is allocated dynamically.
* Once allocated, it stays allocated.
*/
struct card *card; /* Current card, if any */
struct card_config *config; /* Config back ptr */
unsigned int mem; /* Allocated host address (if any) */
int inuse;
};
/*
* Defines one allocation block i.e a starting address
* and size. Used for either memory or I/O ports
*/
struct allocblk {
struct allocblk *next;
int addr; /* Address */
int size; /* Size */
int flags; /* Flags for block */
int cardaddr; /* Card address */
};
/*
* Slot structure - data held for each slot.
*/
struct slot {
struct slot *next;
int fd;
int mask;
int slot;
char *name;
enum cardstate state;
struct cis *cis;
struct card *card; /* Current card */
struct card_config *config; /* Current configuration */
struct cis_config *card_config;
char devname[16];
u_int manufacturer;
u_int product;
u_int prodext;
unsigned char eaddr[6]; /* If any */
char manufstr[DEV_MAX_CIS_LEN];
char versstr[DEV_MAX_CIS_LEN];
char cis3str[DEV_MAX_CIS_LEN];
char cis4str[DEV_MAX_CIS_LEN];
struct allocblk io; /* I/O block spec */
struct allocblk mem; /* Memory block spec */
int irq; /* Irq value */
int flags; /* Resource assignment flags */
};
/*
* Slot resource assignment/configuration flags
*/
#define IO_ASSIGNED 0x1
#define MEM_ASSIGNED 0x2
#define IRQ_ASSIGNED 0x4
#define EADDR_CONFIGED 0x8
#define WL_CONFIGED 0x10
#define AFLAGS (IO_ASSIGNED | MEM_ASSIGNED | IRQ_ASSIGNED)
#define CFLAGS (EADDR_CONFIGED | WL_CONFIGED)
EXTERN struct slot *slots, *current_slot;
EXTERN int slen;
EXTERN struct allocblk *pool_ioblks; /* I/O blocks in the pool */
EXTERN struct allocblk *pool_mem; /* Memory in the pool */
EXTERN int pool_irq[16]; /* IRQ allocations */
EXTERN int irq_init[16]; /* initial IRQ allocations */
EXTERN struct driver *drivers; /* List of drivers */
EXTERN struct card *cards;
EXTERN struct card *last_card;
EXTERN bitstr_t *mem_avail;
EXTERN bitstr_t *mem_init;
EXTERN bitstr_t *io_avail;
EXTERN bitstr_t *io_init;
EXTERN int pccard_init_sleep; /* Time to sleep on init */
EXTERN int use_kern_irq;
EXTERN int debug_level;
/* cardd.c functions */
void dump_config_file(void);
struct slot *readslots(void);
void slot_change(struct slot *);
/* util.c functions */
unsigned long alloc_memory(int);
int bit_fns(bitstr_t *, int, int, int, int);
void die(char *);
void execute(struct cmd *, struct slot *);
void logmsg(const char *, ...);
void log_setup(void);
void logerr(char *);
char *newstr();
void reset_slot(struct slot *);
void *xmalloc(int);
/* file.c functions */
void readfile(char *);
/* server.c functions */
void set_socket(int);
void stat_changed(struct slot *);
void process_client(void);
#define IOPORTS 0x1000 /* allow most of the low ports */
#define MEMUNIT 0x1000
#define MEMSTART 0xA0000
#define MEMEND 0x100000
#define MEMBLKS ((MEMEND-MEMSTART)/MEMUNIT)
#define MEM2BIT(x) (((x)-MEMSTART)/MEMUNIT)
#define BIT2MEM(x) (((x)*MEMUNIT)+MEMSTART)
#define MAXINCLUDES 10
#define MAXERRORS 10
/*
* Config index types
*/
#define NORMAL_INDEX 0
#define DEFAULT_INDEX 1
#define AUTO_INDEX 2
#define DT_VERS 0
#define DT_FUNC 1

File diff suppressed because it is too large Load Diff

View File

@ -1,312 +0,0 @@
.\"
.\" Copyright (c) 1994 Andrew McRae. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the author may not be used to endorse or promote products
.\" derived from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd November 2, 1994
.Dt PCCARD.CONF 5
.Os
.Sh NAME
.Nm pccard.conf
.Nd
.Xr pccardd 8
configuration file
.Sh DESCRIPTION
The
.Nm
file is the configuration file for the
.Xr pccardd 8
PC-CARD slot management daemon.
It provides information to allow card
identification, and the matching of drivers (along
with driver resources) to the PC-CARD cards.
.Pp
There are four basic elements within the configuration file;
An optional
.Em "resource pool"
preceding the other sections,
and one or more
.Em "card identifiers" ,
and
.Em "device instances" .
The latter two may appear in any order, and may be
interspersed as desired.
.Pp
The
.Pa /etc/pccard.conf
file is included from the file
.Pa /etc/defaults/pccard.conf ,
which contains the default resource pool settings and
pccard identifiers database.
The user specific configuration can be specified in
.Pa /etc/pccard.conf
when the user wishes to override these defaults and/or
add additional entries.
.Pp
Each PC-CARD card contains configuration tuples that provide
the manufacturer and card version; these are used
to identify the card specification in the configuration
file, and from this find a driver that can be used to
interface to the particular card.
There is a many-to-one mapping
between cards to drivers i.e a single driver may interface to
multiple types of cards.
To aid this, card parameters may be
specified separately from the driver to initialize the card or
extract (in the case of a network card) an Ethernet address.
.Pp
Once a driver is allocated to a card, it stays
allocated to that particular card.
However, multiple instances of the same type of driver can be
configured, so that if two cards are plugged in that map to a
similar type of driver, other driver instances of the same name
can be configured.
.Pp
The
.Em insert
and
.Em remove
commands allow a shell command line to be executed.
The command to be executed is the rest of the line after
the keyword.
The line can be continued using a backslash.
A simple
macro substitution allows the current kernel device name
.Em ( $device )
and
network card Ethernet address
.Em ( $ether )
to be inserted into the command line.
.Xr pccardd 8
uses the
.Xr system 3
subroutine to execute the command line.
.Pp
.Xr pccardd 8
will use syslog to announce the insertion and removal of cards.
It uses either the string set by the
.Em logstr
command, or the manufacturer and card version strings if none has
been set.
.Pp
Numeric values may be expressed as octal, hex or decimal.
If a decimal number has
.Em k
or
.Em K
appended to it, the value is multiplied by 1024.
Names may be
quoted using double quotes if spaces are required.
A hash character comments out the rest of the line.
.Ss "Resource pool"
The (optional) section specifies a pool of system resources
such as ISA bus memory address space, Input/Output ports and
interrupt request numbers.
This resource pool is used
to allocate address space and interrupt numbers dynamically
according to the requirements specified in each driver
description.
.Pp
The syntax of the resources is as follows:
.Pp
.Dl io Ar start - end ...
.Dl memory Ar address size ...
.Dl irq Ar irq-number ...
.Pp
Each of the statements define I/O, memory or IRQ
blocks that can be used to allocate to drivers when
they are initialized.
.Pp
The syntax of the debuglevel parameter:
.Pp
.Dl debuglevel Ar level
.Pp
Multiple lines of any of the above statements may be
present to allow separate blocks of each resource to be
defined.
.Ss "Card Identifiers"
The syntax for card identifiers is:
.Pp
.Dl card Ar manufacturer version [ add_info1 [ add_info2 ]]
.Dl config Ar index driver interrupt [ flags ]
.Dl ether Ar offset
.Dl reset Ar time
.Dl iosize Ar size
.Dl memsize Ar size
.Dl insert Ar command
.Dl remove Ar command
.Dl logstr Ar string
.Pp
The first line is mandatory;
the latter statements are optional and can appear in
any order.
There may be multiple
.Em config
lines.
The
.Em card
parameters are the Manufacturer name, card version and
additional information add_info1, add_info2 that
is used to match the values from the card's CIS memory.
These parameters can be described in extended regular expression
.Xr regex 3
if the string is enclosed by '/' like "/.*/".
Each of the expressions is evaluated with a character '^' at top.
.Pp
The
.Em config
parameters select the particular card's configuration index
from the range available in the card's CIS, the driver that
is to be associated with this configuration, and the interrupt
level (if any) to be assigned.
An optional set of flags may
be assigned.
In
.Ar index ,
specify either
.Dq auto
or
.Dq default
or the range available in the card's CIS.
.Dq auto
allows to allocate resources automatically with information
from the CIS and status of using I/O resources.
.Pp
The optional
.Em ether
keyword is used when network cards have their physical Ethernet address
located within the attribute memory of the card.
The parameter of this
statement indicates the offset within the attribute memory of the
Ethernet address.
This value can be used within insert/remove
commands using the
.Em $ether
macro.
.Pp
The optional
.Em reset
keyword specifies reset duration at a card insertion in
.Ar time
milliseconds.
Default is 100msec.
.Pp
.Em iosize
and
.Em memsize
keywords are used with cards whose resources such as I/O ports and
shared memory block are not specified in the CIS tuple.
.Pp
The
.Em insert
and
.Em remove
sections allow shell commands to be specified that are executed
when the card is inserted or removed.
Multiple
.Em insert
and
.Em remove
commands are allowed, and they are executed in the order they
are listed.
.Pp
The
.Em logstr
command allows the user to set the string to be logged when this card is
inserted or removed.
If
.Em logstr
is not specified, then the manufacturer and
card version strings from the CIS are used to synthesize the string issued.
.Ss "Wildcard entries"
Following two wildcard entries of card identifiers are available
for generic type of the cards:
.Pp
.Dl generic serial
.Dl generic fixed_disk
.Pp
The keyword
.Em serial
matches
.Dq Functional ID: Serial port/modem
and
.Em fixed_disk
matches
.Dq Fixed disk card .
The syntax is the same as for
.Em "card identifiers"
but uses
.Dq generic
instead of
.Dq card
in the first line.
These are defined at the bottom of
.Nm
so unmatched cards use the generic entries.
The alias
.Dq function
can be used instead of
.Dq generic ,
this is supported due to historical reasons.
.Sh FILES
.Bl -tag -width /etc/defaults/pccard.conf -compact
.It Pa /etc/defaults/pccard.conf
The
.Xr pccardd 8
default configuration file.
.It Pa /etc/pccard.conf
The
user configuration file.
.El
.Sh EXAMPLES
A typical configuration file may look like this:
.Bd -literal
#
# Sample configuration file.
#
# Pool parameters.
#
io 0x280 - 0x2F0 0x300 - 0x360
irq 5 6 8 9 10 15
memory 0xd4000 96k
memory 0xc4000 32k
#
# Card database.
#
card "RPTI LTD." "EP400" # NE2000 clone
ether 0x110
config 0x21 "ed0" 5
insert ifconfig $device physical $ether
insert ifconfig $device bean
remove ifconfig $device down
card "XYZZY" "FAX/1.0"
config 0x30 "sio1" 11
insert echo start getty
remove echo stop getty
.Ed
.Sh SEE ALSO
.Xr pccardd 8

View File

@ -1,190 +0,0 @@
.\"
.\" Copyright (c) 1994 Andrew McRae. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the author may not be used to endorse or promote products
.\" derived from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd November 1, 1994
.Dt PCCARDD 8
.Os
.Sh NAME
.Nm pccardd
.Nd PC-CARD (PCMCIA) management daemon
.Sh SYNOPSIS
.Nm
.Op Fl d
.Op Fl v
.Op Fl x
.Op Fl z
.Op Fl i Ar IRQ
.Op Fl I
.Op Fl f Ar configfile
.Op Fl s Ar socket
.Sh DESCRIPTION
The
.Nm
utility is normally started at boot time, and manages the insertion
and removal of PC-CARD cards.
.Pp
When started,
.Nm
will read the configuration file (default name
.Pa /etc/defaults/pccard.conf
which includes
.Pa /etc/pccard.conf
as the user configuration file)
and scans the available PC-CARD slots for cards.
The
.Nm
utility then waits for
.Em "card events" ,
such as the insertion of a new card or the removal
of a card.
.Pp
When a card is inserted, the following
actions are taken:
.Bl -enum
.It
The kernel driver detects the card insertion and applies
power to the card.
.It
The
.Nm
utility reads the
.Em CIS
data from the attribute memory of the card, and uses
the manufacturer name and card version to match
the card description in the configuration file.
.It
Once matched, a driver is allocated.
.It
Once a free driver and device instance is located,
.Nm
will (if required) allocate resources such as an ISA memory
block and Input/Output ports from a common pool.
.It
The PC-CARD slot is configured with the I/O and memory
contexts allocated, and the kernel driver is attached to
this card.
.It
If the attach succeeds, then specific shell commands
may be executed to configure the device, such as
.Xr ifconfig 8
to set up a network interface.
Separate commands may be specified
for each card, driver or device, and are executed in that order.
.El
.Pp
When
.Nm
detects that a card has been removed, the following sequence occurs:
.Bl -enum
.It
The shell commands associated with card removal are executed.
These
are intended to reset any device associated with the removed card.
Separate commands may exist for card, driver and device instances.
.It
The PC-CARD slot resources are freed.
.El
.Pp
Once a card/driver instance is configured, the resources
bound to that instance are remembered, and if the card is removed
and reinserted, the same driver is allocated.
The reasons are mostly historical.
.Pp
SIGHUP causes
.Nm
to reload the configuration files.
.Pp
The start options understood by
.Nm
are:
.Bl -tag -width Ds
.It Fl d
Do not run as a daemon, but run in the foreground and
display error messages.
.It Fl v
After reading the configuration file, print out a summary
of it.
.It Fl x
Exits immediately after the cards have been probed and attached.
This is primarily useful in embedded applications where it is
desirable to use
.Nm
to start PC-CARD devices but prohibitive memory-wise to leave the
.Nm
process running.
.It Fl z
Delays running as a daemon until after the cards have been probed and attached.
.It Fl I
Do not get a list of free IRQs from kernel.
.It Fl i Ar IRQ
Configures an available IRQ.
It overrides the "irq" line in
.Pa /etc/defaults/pccard.conf
and
.Pa /etc/pccard.conf .
.It Fl f Ar configfile
Specifies a different configuration file to be used
in placed of the default file
.Pa /etc/defaults/pccard.conf .
The file format is detailed in
.Xr pccard.conf 5 ,
and lists the PC-CARD cards recognized by
.Nm ,
and the kernel drivers and devices that are used to
interface to the card.
.It Fl s Ar socket
Specifies a path to a control socket.
The default is
.Pa /var/tmp/.pccardd .
.El
.Sh FILES
.Bl -tag -width /etc/defaults/pccard.conf -compact
.It Pa /etc/defaults/pccard.conf
default configuration file
.It Pa /etc/pccard.conf
user configuration file
.It Pa /var/tmp/.pccardd
default control socket
.It Pa /var/run/pccardd.pid
process id of the currently running
.Nm
.El
.Sh SEE ALSO
.Xr pccard.conf 5 ,
.Xr ifconfig 8
.Sh AUTHORS
Developed by
.An Andrew McRae Aq andrew@mega.com.au .
.Sh BUGS
The
.Nm
utility can set up card parameters, but cannot guarantee that
particular drivers can work with the card.
.Pp
Removing cards may cause problems if system resources
have been associated with the card, such as network
mounted file systems.

View File

@ -1,285 +0,0 @@
/*
* Copyright (c) 1995 Andrew McRae. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/stat.h>
#define EXTERN
#include "cardd.h"
char *config_file = "/etc/defaults/pccard.conf";
static char *pid_file = "/var/run/pccardd.pid";
/*
* pathname of UNIX-domain socket
*/
static char *socket_name = "/var/tmp/.pccardd";
static char *sock = 0;
static int server_sock;
/* SIGHUP signal handler */
static void
restart(void)
{
bitstr_t bit_decl(io_inuse, IOPORTS);
bitstr_t bit_decl(mem_inuse, MEMBLKS);
int irq_inuse[16];
int i;
struct sockaddr_un sun;
bit_nclear(io_inuse, 0, IOPORTS-1);
bit_nclear(mem_inuse, 0, MEMBLKS-1);
bzero(irq_inuse, sizeof(irq_inuse));
/* compare the initial and current state of resource pool */
for (i = 0; i < IOPORTS; i++) {
if (bit_test(io_init, i) == 1 && bit_test(io_avail, i) == 0) {
if (debug_level >= 1) {
logmsg("io 0x%x seems to be in use\n", i);
}
bit_set(io_inuse, i);
}
}
for (i = 0; i < MEMBLKS; i++) {
if (bit_test(mem_init, i) == 1 && bit_test(mem_avail, i) == 0) {
if (debug_level >= 1) {
logmsg("mem 0x%x seems to be in use\n", i);
}
bit_set(mem_inuse, i);
}
}
for (i = 0; i < 16; i++) {
if (irq_init[i] == 1 && pool_irq[i] == 0) {
if (debug_level >= 1) {
logmsg("irq %d seems to be in use\n", i);
}
irq_inuse[i] = 1;
}
}
readfile(config_file);
/* reflect used resources to managed resource pool */
for (i = 0; i < IOPORTS; i++) {
if (bit_test(io_inuse, i) == 1) {
bit_clear(io_avail, i);
}
}
for (i = 0; i < MEMBLKS; i++) {
if (bit_test(mem_inuse, i) == 1) {
bit_clear(mem_avail, i);
}
}
for (i = 0; i < 16; i++) {
if (irq_inuse[i] == 1) {
pool_irq[i] = 0;
}
}
close(server_sock);
if ((server_sock = socket(PF_LOCAL, SOCK_DGRAM, 0)) < 0)
die("socket failed");
bzero(&sun, sizeof(sun));
sun.sun_family = AF_UNIX;
if (sock) {
socket_name = sock;
}
strcpy(sun.sun_path, socket_name);
slen = SUN_LEN(&sun);
(void)unlink(socket_name);
if (bind(server_sock, (struct sockaddr *) & sun, slen) < 0)
die("bind failed");
chown(socket_name, 0, 5); /* XXX - root.operator */
chmod(socket_name, 0660);
set_socket(server_sock);
}
/* SIGTERM/SIGINT signal handler */
static void
term(int sig)
{
logmsg("pccardd terminated: signal %d received", sig);
(void)unlink(pid_file);
exit(0);
}
static void
write_pid()
{
FILE *fp = fopen(pid_file, "w");
if (fp) {
fprintf(fp, "%d\n", getpid());
fclose(fp);
}
}
int doverbose = 0;
/*
* mainline code for cardd
*/
int
main(int argc, char *argv[])
{
struct slot *sp;
int count, dodebug = 0;
int probeonly = 0;
int delay = 0;
int irq_arg[16];
int irq_specified = 0;
int i;
struct sockaddr_un sun;
#define COM_OPTS ":Idf:i:s:vxz"
bzero(irq_arg, sizeof(irq_arg));
use_kern_irq = 1;
debug_level = 0;
pccard_init_sleep = 5000000;
cards = last_card = 0;
while ((count = getopt(argc, argv, COM_OPTS)) != -1) {
switch (count) {
case 'I':
use_kern_irq = 0;
break;
case 'd':
setbuf(stdout, 0);
setbuf(stderr, 0);
dodebug = 1;
break;
case 'v':
doverbose = 1;
break;
case 'f':
config_file = optarg;
break;
case 'i':
/* configure available irq */
if (sscanf(optarg, "%d", &i) != 1) {
fprintf(stderr, "%s: -i number\n", argv[0]);
exit(1);
}
irq_arg[i] = 1;
irq_specified = 1;
break;
case 's':
sock = optarg;
break;
case 'x':
probeonly = 1;
break;
case 'z':
delay = 1;
break;
case ':':
die("no config file argument");
break;
case '?':
die("illegal option");
break;
}
}
#ifdef DEBUG
dodebug = 1;
#endif
io_avail = bit_alloc(IOPORTS); /* Only supports ISA ports */
io_init = bit_alloc(IOPORTS);
/* Mem allocation done in MEMUNIT units. */
mem_avail = bit_alloc(MEMBLKS);
mem_init = bit_alloc(MEMBLKS);
readfile(config_file);
if (irq_specified) {
bcopy(irq_arg, pool_irq, sizeof(irq_arg));
bcopy(irq_arg, irq_init, sizeof(irq_arg));
}
if (doverbose)
dump_config_file();
log_setup();
if (!dodebug && !delay && !probeonly)
if (daemon(0, 0))
die("fork failed");
slots = readslots();
if (slots == 0)
die("no PC-CARD slots");
if (probeonly)
exit(0);
if (delay)
if (daemon(0, 0))
die("fork failed");
logmsg("pccardd started", NULL);
write_pid();
if ((server_sock = socket(PF_LOCAL, SOCK_DGRAM, 0)) < 0)
die("socket failed");
bzero(&sun, sizeof(sun));
sun.sun_family = AF_UNIX;
if (sock) {
socket_name = sock;
}
strcpy(sun.sun_path, socket_name);
slen = SUN_LEN(&sun);
(void)unlink(socket_name);
if (bind(server_sock, (struct sockaddr *) & sun, slen) < 0)
die("bind failed");
chown(socket_name, 0, 5); /* XXX - root.operator */
chmod(socket_name, 0660);
set_socket(server_sock);
(void)signal(SIGINT, dodebug ? term : SIG_IGN);
(void)signal(SIGTERM, term);
(void)signal(SIGHUP, (void (*)(int))restart);
for (;;) {
fd_set rmask, emask;
FD_ZERO(&emask);
FD_ZERO(&rmask);
for (sp = slots; sp; sp = sp->next)
FD_SET(sp->fd, &emask);
FD_SET(server_sock, &rmask);
count = select(32, &rmask, 0, &emask, 0);
if (count == -1) {
logerr("select");
continue;
}
if (count) {
for (sp = slots; sp; sp = sp->next)
if (FD_ISSET(sp->fd, &emask))
slot_change(sp);
if (FD_ISSET(server_sock, &rmask))
process_client();
}
}
}

View File

@ -1,188 +0,0 @@
/*
* pccardd UNIX-domain socket interface
* Copyright (C) 1996 by Tatsumi Hosokawa <hosokawa@mt.cs.keio.ac.jp>
*
* $Id: server.c,v 1.3 1999/02/07 08:02:44 kuriyama Exp $
*/
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <signal.h>
#include <setjmp.h>
#include "cardd.h"
static void
cardnum(char *buf)
{
int i = 0;
struct slot *sp;
for (sp = slots; sp; sp = sp->next)
i++;
if (i > MAXSLOT)
i = MAXSLOT;
sprintf(buf, "%2d", i);
}
static struct slot *
find_slot(int slot)
{
struct slot *sp;
/* Search the list until we find the slot or get to the end */
for (sp = slots; sp && sp->slot != slot; sp = sp->next)
continue;
return ( sp );
}
static void
cardname(char *buf, int slot)
{
struct slot *sp;
char *manuf, *vers, *drv, *stat;
/* Look for the slot */
if ( (sp = find_slot(slot)) == NULL)
return;
/* Fill in the information in the buff */
if (sp->cis) {
manuf = sp->cis->manuf;
vers = sp->cis->vers;
if (sp->config && sp->config->driver &&
sp->config->driver->name)
drv = sp->config->driver->name;
else
drv = "";
} else
manuf = vers = drv = "";
switch (sp->state) {
case empty:
stat = "0";
break;
case filled:
stat = "1";
break;
case inactive:
stat = "2";
break;
default:
stat = "9";
}
sprintf(buf, "%d~%s~%s~%s~%s", slot, manuf, vers, drv, stat);
}
static void
cardpwr(int slot, int pwon)
{
struct slot *sp;
/* Look for the slot */
if ( (sp = find_slot(slot)) == NULL)
return;
if (ioctl(sp->fd, PIOCSVIR, &pwon) < 0)
logerr("invaild arguments for cardpwr");
}
static int sock = 0;
static int slen = 0;
static struct sockaddr_un sun;
void
set_socket(int s)
{
sock = s;
}
void
stat_changed(struct slot *sp)
{
int len;
char buf[512];
if (!slen)
return;
cardname(buf, sp->slot);
len = strlen(buf);
if (sendto(sock, buf, len, 0, (struct sockaddr *) & sun, slen) != len) {
logerr("sendto failed");
slen = 0;
}
}
void
process_client(void)
{
char buf[512], obuf[512];
int len;
int snum;
if (!sock)
return;
slen = sizeof(sun);
len = recvfrom(sock, buf, sizeof(buf),
0, (struct sockaddr *)&sun, &slen);
if (len < 0)
logerr("recvfrom failed");
buf[len] = '\0';
obuf[0] = '\0';
switch (buf[0]) { /* Protocol implementation */
case 'S': /* How many slots? */
cardnum(obuf);
break;
case 'N': /* Card name request */
sscanf(buf + 1, "%d", &snum);
if (snum >= 0 && snum <= MAXSLOT)
cardname(obuf, snum);
else
logerr("Illegal slot requests for N command");
break;
case 'P': /* Virtual insertion request */
sscanf(buf + 1, "%d", &snum);
if (snum >= 0 && snum <= MAXSLOT) {
logmsg("slot %d: spring has come", snum);
cardpwr(snum, 1);
} else
logerr("Illegal slot requests for P command");
break;
case 'Q': /* Virtual removal request */
sscanf(buf + 1, "%d", &snum);
if (snum >= 0 && snum <= MAXSLOT) {
logmsg("slot %d: hibernation", snum);
cardpwr(snum, 0);
} else
logerr("Illegal slot requests for Q command");
break;
default:
logerr("Unknown control message from socket");
break;
}
len = strlen(obuf);
if (len) {
if (sendto(sock, obuf, len, 0, (struct sockaddr *)&sun, slen)
!= len) {
logerr("sendto failed");
slen = 0;
}
} else if (sendto(sock, 0, 0, 0, (struct sockaddr *)&sun, slen)
!= len) {
logerr("sendto failed");
slen = 0;
}
}

View File

@ -1,273 +0,0 @@
/*
* Copyright (c) 1995 Andrew McRae. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Code cleanup, bug-fix and extension
* by:
* Tatsumi Hosokawa <hosokawa@jp.FreeBSD.org>
* Nate Williams <nate@FreeBSD.org>
*/
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#include <err.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <syslog.h>
#ifdef SYSINSTALL
#include <dialog.h>
#endif
#include "cardd.h"
static int do_log = 0;
void
log_setup(void)
{
#ifndef SYSINSTALL
do_log = 1;
openlog("pccardd", LOG_PID, LOG_DAEMON);
#endif
}
void
logmsg(const char *fmt, ...)
{
va_list ap;
char s[256];
va_start(ap, fmt);
vsnprintf(s, 256, fmt, ap);
if (do_log)
syslog(LOG_ERR, "%s", s);
else {
#ifdef SYSINSTALL
dialog_clear();
msgConfirm(s);
#else
warnx("%s", s);
#endif
}
}
void
logerr(char *msg)
{
if (do_log)
syslog(LOG_ERR, "%s: %m", msg);
else {
#ifdef SYSINSTALL
dialog_clear();
msgConfirm(msg);
#else
warn("%s", msg);
#endif
}
}
/*
* Deliver last will and testament, and die.
*/
void
die(char *msg)
{
if (do_log)
syslog(LOG_CRIT, "fatal error: %s", msg);
else {
#ifdef SYSINSTALL
char s[256];
sprintf(s, "cardd fatal error: %s\n", msg);
dialog_clear();
msgConfirm(s);
#else
warnx("fatal error: %s", msg);
#endif
}
closelog();
exit(1);
}
void *
xmalloc(int sz)
{
void *p;
p = malloc(sz);
if (p)
bzero(p, sz);
else
die("malloc failed");
return (p);
}
char *
newstr(char *p)
{
char *s;
s = strdup(p);
if (s == 0)
die("strdup failed");
return (s);
}
/*
* Find contiguous bit string (all set) of at
* least count number.
*/
int
bit_fns(bitstr_t *nm, int nbits, int min, int count, int step)
{
int i, j;
int found = 0;
for (i = min; i < nbits; i += step)
for (j = i, found = 0; j < nbits; j++)
if (bit_test(nm, j)) {
if (++found == count)
return i;
} else
break;
return (-1);
}
/*
* Allocate a block of memory and return the address.
*/
unsigned long
alloc_memory(int size)
{
int i;
i = bit_fns(mem_avail, MEMBLKS, 0, size / MEMUNIT + (size % MEMUNIT != 0), 1);
if (i < 0)
return (0);
bit_nclear(mem_avail, i, i + size / MEMUNIT + (size % MEMUNIT != 0) - 1);
return (BIT2MEM(i));
}
/*
* reset_slot - Power has been applied to the card.
* Now reset the card.
*/
void
reset_slot(struct slot *sp)
{
char c;
off_t offs;
struct mem_desc mem;
struct io_desc io;
int rw_flags;
rw_flags = MDF_ATTR;
ioctl(sp->fd, PIOCRWFLAG, &rw_flags);
#ifdef DEBUG
printf("Resetting card, writing 0x80 to offs 0x%x\n",
sp->cis->reg_addr);
#endif
offs = sp->cis->reg_addr;
lseek(sp->fd, offs, SEEK_SET);
c = 0x80;
write(sp->fd, &c, sizeof(c));
usleep(10 * 1000);
c = 0;
lseek(sp->fd, offs, SEEK_SET);
write(sp->fd, &c, sizeof(c));
/* Reset all the memory and I/O windows. */
bzero((caddr_t) & mem, sizeof(mem));
bzero((caddr_t) & io, sizeof(io));
for (mem.window = 0; mem.window < NUM_MEM_WINDOWS; mem.window++)
ioctl(sp->fd, PIOCSMEM, &mem);
for (io.window = 0; io.window < NUM_IO_WINDOWS; io.window++)
ioctl(sp->fd, PIOCSIO, &io);
}
/*
* execute - Execute the command strings.
* For the current slot (if any) perform macro
* substitutions.
*/
void
execute(struct cmd *cmdp, struct slot *sp)
{
char cmd[1024];
char *p, *cp, *lp;
for (; cmdp; cmdp = cmdp->next) {
cp = cmd;
lp = cmdp->line;
if (*lp == 0)
continue;
while ((p = strchr(lp, '$')) != 0) {
/* copy over preceding string. */
while (lp != p)
*cp++ = *lp++;
/* stringify ethernet address and place here. */
if (strncmp(p, "$ether", 6) == 0) {
sprintf(cp, "%x:%x:%x:%x:%x:%x",
sp->eaddr[0],
sp->eaddr[1],
sp->eaddr[2],
sp->eaddr[3],
sp->eaddr[4],
sp->eaddr[5]);
while (*++cp)
continue;
lp += 6;
} else
/* replace device name */
if (strncmp(p, "$device", 7) == 0) {
sprintf(cp, "%s%d",
sp->config->driver->kernel,
sp->config->driver->unit);
while (*cp)
cp++;
lp += 7;
} else
/* Copy the `$' and rescan. */
*cp++ = *lp++;
}
/* No more replacements. Copy rest of string. */
while ((*cp++ = *lp++) != 0)
continue;
#ifdef DEBUG
fprintf(stderr, "Executing [%s]\n", cmd);
#endif
system(cmd);
}
}