Add regex(3) matching feature for card line strings.
- This feature will be enabled only if the string is enclosed by '/' something like; card "SunDisk" "/.*/" - Also added matching additional information strings followed by version string. This is for the card which is difficult to idendentify by only the manufacturer and card version strings matching. card "MACNICA" "MIRACLE SCSI" "mPS100" "D.0" Reviewed by: imp Obtained from: PAO
This commit is contained in:
parent
de4b89bf91
commit
6ebef682a8
@ -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;
|
||||
|
@ -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 */
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user