Subject: kern/11659: pcmcia/devlist2h.awk generates invalid c-code in pcmciadevs_data.h
To: None <gnats-bugs@gnats.netbsd.org>
From: None <kivinen@ssh.fi>
List: netbsd-bugs
Date: 12/07/2000 05:31:15
>Number:         11659
>Category:       kern
>Synopsis:       pcmciadevs_data.h contains invalid c-code
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 07 05:31:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Tero Kivinen
>Release:        NetBSD-current Dec 6 2000
>Organization:
SSH Communications Security
>Environment:
System: NetBSD kaakeli.ssh.fi 1.5L NetBSD 1.5L (KAAKELI) #22: Thu Dec 7 01:39:27 EET 2000 root@kaakeli.ssh.fi:/usr/src/sys/arch/i386/compile/KAAKELI i386
Architecture: i386
Machine: i386
>Description:

	Sys/dev/pcmcia/pcmciadevs_data.h contains invalid c-code.
	There is two bugs in the awk code that generates the file. The
	first adds extra } at end of each product string. Second one
	generates fields in invalid order for those devices whose
	product id is not known.

	Also there is no definition of the pcmcia_knowndev structure
	itself.

	It would also be better to export pcmciadevs.h,
	pcmciadevs_data.h, cardbusdevs.h and cardbusdevs_data.h, as
	they can be usefull in the usermode programs. I have a
	loadable kernel module (with ~20 line patch to pcmcia.c and
	cardbus.c) that will send card attach and detach notifications
	from kernel to user mode daemon. Currently the daemon only
	prints out debug info, but I plan to run suitable shell script
	when the card is attached/detached, so I can run ifconfig up /
	dhclient etc stuff there.

	The debugging info include the vendor and product names, thus
	I need the pcmciadevs_data.h and cardbusdevs_data.h files for
	that:

	kaakeli (6:12) ~>./cardwatchd
	pcmcia card wi0 attached to pcmcia0
	Manufacturer Lucent Technologies (0x156), product = WaveLAN/IEEE (0x2)
	pcmcia card wi0 detached
	pcmcia card ne0 attached to pcmcia0
	Manufacturer I-O DATA (0x1bf), product = I-O DATA PCLA/TE (0x2216)
	pcmcia card ne0 detached
	...

>How-To-Repeat:

	Try to compile following file:

	#include <stdio.h>
	#include <fcntl.h>
	#include <sys/param.h>
	#include <sys/proc.h>
	#include <sys/device.h>
	#include <dev/pcmcia/pcmciavar.h>
	
	struct pcmcia_knowndev {
	  int32_t vendor;
	  int32_t product;
	  struct {
	    const char *cis[4];
	  } cis;
	  int32_t flags;
	  const char *vendor_name;
	  const char *product_name;
	};
	
	#include "pcmciadevs.h"
	#define PCMCIA_VENDOR_UNKNOWN -1
	#define PCMCIA_KNOWNDEV_NOPROD -1
	#include "pcmciadevs_data.h"
		

>Fix:

	Here is patch:
----------------------------------------------------------------------
--- devlist2h.awk.orig	Thu Dec  7 06:00:07 2000
+++ devlist2h.awk	Thu Dec  7 05:49:30 2000
@@ -202,20 +202,19 @@
 		}
 		printf("\t    PCMCIA_CIS_%s_%s,\n", 
 		    products[i, 1], products[i, 2]) > dfile
-		printf("\t    ") > dfile
-		printf("0") > dfile
-		printf(",\n") > dfile
+		printf("\t    0,\n") > dfile
 
 		vendi = vendorindex[products[i, 1]];
 		printf("\t    \"%s\",\n", vendors[vendi, 3]) > dfile
-		printf("\t    \"%s\"\t},\n", products[i, 5]) > dfile
+		printf("\t    \"%s\"\n", products[i, 5]) > dfile
 		printf("\t},\n") > dfile
 	}
 	for (i = 1; i <= nvendors; i++) {
 		printf("\t{\n") > dfile
-		printf("\t    PCMCIA_VENDOR_%s, 0,\n", vendors[i, 1]) > dfile
+		printf("\t    PCMCIA_VENDOR_%s,\n", vendors[i, 1]) > dfile
 		printf("\t    PCMCIA_KNOWNDEV_NOPROD,\n") > dfile
 		printf("\t    PCMCIA_CIS_INVALID,\n") > dfile
+		printf("\t    0,\n") > dfile
 		printf("\t    \"%s\",\n", vendors[i, 3]) > dfile
 		printf("\t    NULL,\n") > dfile
 		printf("\t},\n") > dfile

>Release-Note:
>Audit-Trail:
>Unformatted: