1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <linux/major.h>
4 #include <fcntl.h>
5 #include <unistd.h>
6 #include <stdio.h>
7 
8 #include "ip2.h"
9 #include "i2ellis.h"
10 
11 char nm[256];
12 i2eBordStr Board[2];
13 
14 static void ex_details(i2eBordStrPtr);
15 
main(int argc,char * argv[])16 int main (int argc, char *argv[])
17 {
18 	int board, box, port;
19 	int fd;
20 	int dev;
21 	i2eBordStrPtr pB  = Board;
22 
23 	// Remove all IP2 devices
24 
25 	for ( board = 0; board < 4; ++board )
26 	{
27 		sprintf ( nm, "/dev/ip2ipl%d", board );
28 		unlink ( nm );
29 		sprintf ( nm, "/dev/ip2stat%d", board );
30 		unlink ( nm );
31 	}
32 
33 	for ( port = 0; port < 256; ++port  )
34 	{
35 		sprintf ( nm, "/dev/ttyF%d", port );
36 		unlink ( nm );
37 		sprintf ( nm, "/dev/cuf%d", port );
38 		unlink ( nm );
39 	}
40 
41 	// Now create management devices, and use the status device to determine how
42 	// port devices need to exist, and then create them.
43 
44 	for ( board = 0; board < 4; ++board )
45 	{
46 		printf("Board %d: ", board );
47 
48 		sprintf ( nm, "/dev/ip2ipl%d", board );
49 		mknod ( nm, S_IFCHR|0666, (IP2_IPL_MAJOR << 8) | board * 4 );
50 		sprintf ( nm, "/dev/ip2stat%d", board );
51 		mknod ( nm, S_IFCHR|0666, (IP2_IPL_MAJOR << 8) | board * 4 + 1 );
52 
53 		fd = open ( nm, O_RDONLY );
54 		if ( !fd )
55 		{
56 			printf ( "Unable to open status device %s\n", nm );
57 			exit ( 1 );
58 		}
59 		if ( ioctl ( fd,  65, Board ) < 0 )
60 		{
61 			printf ( "not present\n" );
62 			close ( fd );
63 			unlink ( nm );
64 			sprintf ( nm, "/dev/ip2ipl%d", board );
65 			unlink ( nm );
66 		}
67 		else
68 		{
69 			switch( pB->i2ePom.e.porID & ~POR_ID_RESERVED )
70 			{
71 			case POR_ID_FIIEX: ex_details ( pB );       break;
72 			case POR_ID_II_4:  printf ( "ISA-4" );      break;
73 			case POR_ID_II_8:  printf ( "ISA-8 std" );  break;
74 			case POR_ID_II_8R: printf ( "ISA-8 RJ11" ); break;
75 
76 			default:
77 				printf ( "Unknown board type, ID = %x", pB->i2ePom.e.porID );
78 			}
79 
80 			for ( box = 0; box < ABS_MAX_BOXES; ++box )
81 			{
82 				for ( port = 0; port < ABS_BIGGEST_BOX; ++port )
83 				{
84 					if ( pB->i2eChannelMap[box] & ( 1 << port ) )
85 					{
86 						dev = port
87 							 + box * ABS_BIGGEST_BOX
88 							 + board * ABS_BIGGEST_BOX * ABS_MAX_BOXES;
89 
90 						sprintf ( nm, "/dev/ttyF%d", dev );
91 						mknod ( nm, S_IFCHR|0666, (IP2_TTY_MAJOR << 8) | dev );
92 						sprintf ( nm, "/dev/cuf%d", dev );
93 						mknod ( nm, S_IFCHR|0666, (IP2_CALLOUT_MAJOR << 8) | dev );
94 
95 						printf(".");
96 					}
97 				}
98 			}
99 			printf("\n");
100 		}
101 	}
102 }
103 
ex_details(i2eBordStrPtr pB)104 static void ex_details ( i2eBordStrPtr pB )
105 {
106 	int            box;
107 	int            i;
108 	int            ports = 0;
109 	int            boxes = 0;
110 
111 	for( box = 0; box < ABS_MAX_BOXES; ++box )
112 	{
113 		if( pB->i2eChannelMap[box] != 0 ) ++boxes;
114 		for( i = 0; i < ABS_BIGGEST_BOX; ++i )
115 		{
116 			if( pB->i2eChannelMap[box] & 1<< i ) ++ports;
117 		}
118 	}
119 
120 	printf("EX bx=%d pt=%d %d bit", boxes, ports, pB->i2eDataWidth16 ? 16 : 8 );
121 }
122 
123 
124