summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/pccard/pccardd/cardd.c52
-rw-r--r--usr.sbin/pccard/pccardd/cardd.h2
-rw-r--r--usr.sbin/pccard/pccardd/file.c30
-rw-r--r--usr.sbin/pccard/pccardd/pccard.conf.510
4 files changed, 82 insertions, 12 deletions
diff --git a/usr.sbin/pccard/pccardd/cardd.c b/usr.sbin/pccard/pccardd/cardd.c
index e8e1622..c8a5756 100644
--- a/usr.sbin/pccard/pccardd/cardd.c
+++ b/usr.sbin/pccard/pccardd/cardd.c
@@ -36,6 +36,7 @@ static const char rcsid[] =
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
+#include <regex.h>
#include <sys/ioctl.h>
#include "cardd.h"
@@ -208,17 +209,44 @@ card_removed(struct slot *sp)
/* CIS string comparison */
+#define REGCOMP_FLAGS (REG_EXTENDED | REG_NOSUB)
+#define REGEXEC_FLAGS (0)
+
static int
cis_strcmp(char *db, char *cis)
{
+ int res, err;
+ char buf[256];
+ regex_t rx;
+ char * p;
size_t n;
if (!db || !cis) {
return -1;
}
n = strlen(db);
- return strncmp(db, cis, n);
- /* XXX Add code for regex CIS string comparison here */
+ if (n > 2 && db[0] == '/' && db[n-1] == '/') {
+ /* matching by regex */
+ db++;
+ } else {
+ /* otherwise, matching by strncmp() */
+ return strncmp(db, cis, n);
+ }
+ p = xmalloc(n);
+ strncpy(p + 1, db, n-2);
+ *p = '^';
+ db = p;
+ if ((err = regcomp(&rx, p, REGCOMP_FLAGS))) {
+ regerror(err, &rx, buf, sizeof buf);
+ logmsg("Warning: REGEX error for\"%s\" -- %s\n", p, buf);
+ regfree(&rx);
+ free(p);
+ return -1;
+ }
+ res = regexec(&rx, cis, 0, NULL, REGEXEC_FLAGS);
+ regfree(&rx);
+ free(p);
+ return res;
}
/*
@@ -252,11 +280,23 @@ card_inserted(struct slot *sp)
case DT_VERS:
if (cis_strcmp(cp->manuf, sp->cis->manuf) == 0 &&
cis_strcmp(cp->version, sp->cis->vers) == 0) {
+ if (cp->add_info1 != NULL &&
+ cis_strcmp(cp->add_info1, sp->cis->add_info1) != 0) {
+ break;
+ }
+ if (cp->add_info2 != NULL &&
+ cis_strcmp(cp->add_info2, sp->cis->add_info2) != 0) {
+ break;
+ }
+
logmsg("Card \"%s\"(\"%s\") "
- "matched \"%s\" (\"%s\") ",
- sp->cis->manuf, sp->cis->vers,
- cp->manuf, cp->version
- );
+ "[%s] [%s] "
+ "matched \"%s\" (\"%s\") "
+ "[%s] [%s] ",
+ sp->cis->manuf, sp->cis->vers,
+ sp->cis->add_info1, sp->cis->add_info2,
+ cp->manuf, cp->version,
+ cp->add_info1, cp->add_info2);
goto escape;
}
break;
diff --git a/usr.sbin/pccard/pccardd/cardd.h b/usr.sbin/pccard/pccardd/cardd.h
index d983fcc..675cc5a 100644
--- a/usr.sbin/pccard/pccardd/cardd.h
+++ b/usr.sbin/pccard/pccardd/cardd.h
@@ -67,6 +67,8 @@ 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 */
diff --git a/usr.sbin/pccard/pccardd/file.c b/usr.sbin/pccard/pccardd/file.c
index 4857faf..0ed7e95 100644
--- a/usr.sbin/pccard/pccardd/file.c
+++ b/usr.sbin/pccard/pccardd/file.c
@@ -123,10 +123,14 @@ delete_card(struct card *cp)
struct cmd *cmdp, *cmd_next;
/* free characters */
- if (cp->manuf[0] != NULL)
+ if (cp->manuf != NULL)
free(cp->manuf);
- if (cp->version[0] != NULL)
+ if (cp->version != NULL)
free(cp->version);
+ if (cp->add_info1 != NULL)
+ free(cp->add_info1);
+ if (cp->add_info2 != NULL)
+ free(cp->add_info2);
/* free structures */
for (etherp = cp->ether; etherp; etherp = ether_next) {
@@ -395,6 +399,7 @@ static void
parse_card(int deftype)
{
char *man, *vers, *tmp;
+ char *add_info;
unsigned char index_type;
struct card *cp;
int i, iosize;
@@ -408,13 +413,30 @@ parse_card(int deftype)
case DT_VERS:
man = newstr(next_tok());
vers = newstr(next_tok());
+ add_info = newstr(next_tok());
+ if (keyword(add_info)) {
+ pusht = 1;
+ free(add_info);
+ cp->add_info1 = NULL;
+ cp->add_info2 = NULL;
+ } else {
+ cp->add_info1 = add_info;
+ add_info = newstr(next_tok());
+ if (keyword(add_info)) {
+ pusht = 1;
+ free(add_info);
+ cp->add_info2 = NULL;
+ } else {
+ cp->add_info2 = add_info;
+ }
+ }
cp->manuf = man;
cp->version = vers;
cp->func_id = 0;
break;
case DT_FUNC:
- cp->manuf = "";
- cp->version = "";
+ cp->manuf = NULL;
+ cp->version = NULL;
cp->func_id = (u_char) func_tok();
break;
default:
diff --git a/usr.sbin/pccard/pccardd/pccard.conf.5 b/usr.sbin/pccard/pccardd/pccard.conf.5
index b1b26df..0f27bf2 100644
--- a/usr.sbin/pccard/pccardd/pccard.conf.5
+++ b/usr.sbin/pccard/pccardd/pccard.conf.5
@@ -141,7 +141,7 @@ defined.
.Ss "Card Identifiers"
The syntax for card identifiers is:
.Pp
-.Dl card Ar manufacturer version
+.Dl card Ar manufacturer version [ add_info1 [ add_info2 ]]
.Dl config Ar index driver interrupt [ flags ]
.Dl ether Ar offset
.Dl insert Ar command
@@ -155,8 +155,14 @@ There may be multiple
lines.
The
.Em card
-parameters are the Manufacturer name and card version that
+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 parameter 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
OpenPOWER on IntegriCloud