summaryrefslogtreecommitdiffstats
path: root/loader/pcmcia.c
blob: 8a70996c6100210a93336903aeb7e61b9c7c2591 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <fcntl.h>
#include <kudzu/kudzu.h>
#include <newt.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>

#include "../isys/imount.h"
#include "../isys/isys.h"

#include "lang.h"
#include "loader.h"
#include "log.h"
#include "modules.h"
#include "windows.h"

int probe_main (int argc, char ** argv);
int cardmgr_main (int argc, char ** argv);

int startPcmcia(char * floppyDevice, moduleList modLoaded, moduleDeps modDeps, 
		moduleInfoSet modInfo, char * pcicPtr, int flags) {
    pid_t child;
    struct device ** devices, ** device;
    char * probeArgs[] = { "/sbin/probe", NULL };
    char * cardmgrArgs[] = { "/sbin/cardmgr", "-o", "-m", "/modules", "-d", 
			NULL };
    int p[2];
    char buf[4096];
    int i, status;
    char * pcic = NULL;
    char * line = NULL;
    int rc;
    char * title = _("PC Card"); 
    char * text = _("Initializing PC Card Devices...");

    logMessage("in startPcmcia()");

    devices = probeDevices(CLASS_SOCKET, BUS_PCI, PROBE_ALL);
    if (devices) {
	logMessage("found cardbus pci adapter");
	pcic = "yenta_socket";

	for (device = devices; *device; device++)
	    freeDevice(*device);

	free(devices);
    } else {
	pipe(p);

	if (!(child = fork())) {
	    close(p[0]);
	    dup2(p[1], 1);
	    close(p[1]);
	    exit(probe_main(1, probeArgs));
	}

	close(p[1]);
	
	waitpid(child, NULL, 0);

	i = read(p[0], buf, sizeof(buf));
	close(p[0]);
	buf[i] = '\0';

	logMessage("pcmcia probe returned: |%s|", buf);
     
	/* So this is totally counter-intuitive. Just remember that probe
	   stops printing output once it finds a pcic, so this is actually
	   correct */

	line = strtok(buf, "\r\n");

	do {
	    if (!strstr(line, "not found"))
	    {
		if (strstr(line, "TCIC"))
		    pcic = "tcic";
		else
		    pcic = "i82365";
	    }
	} while((line = strtok(NULL, "\r\n")));
    }

    if (!pcic)
    {
	logMessage("no pcic controller found");
	return 0;
    }

    logMessage("need to load %s", pcic);

    winStatus(40, 3, title, text);
    if (mlLoadModule("pcmcia_core", NULL, modLoaded, modDeps, 
		     NULL, modInfo, flags)) {
	logMessage("failed to load pcmcia_core -- ask for pcmciadd");
	rc = 1;
	newtPopWindow();
    } else {
	rc = 0;
    }

    while (rc) {
	rc = newtWinChoice(_("PCMCIA"), _("OK"), _("Cancel"),
		      _("Please insert your PCMCIA driver disk "
			"into your floppy drive now."));
	if (rc == 2) return LOADER_BACK;

	devMakeInode(floppyDevice, "/tmp/floppy");

	rc = 1;
	if (doPwMount("/tmp/floppy", "/modules", "ext2", 1, 0, NULL, 
		      NULL)) {
	    newtWinMessage(_("Error"), _("OK"), _("Failed to mount disk."));
	} else {
	    int fd;

	    fd = open("/modules/rhdd-6.1", O_RDONLY);
	    if (fd >= 0) {
		char buf[30];
		int i;

		i = read(fd, buf, 30);
		buf[23] = '\0';
		logMessage("read %s", buf);
		if (i == 23 && !strcmp(buf, "PCMCIA Driver Diskette\n")) {
		    winStatus(40, 3, title, text);
		    if (mlLoadModule("pcmcia_core", NULL, modLoaded, modDeps, 
				     NULL, modInfo, flags)) {
			newtPopWindow();
			newtWinMessage(_("Error"), _("OK"),
				_("That floppy does not look like a "
				  "Red Hat PCMCIA driver disk."));
		    }

		    rc = 0;
		}

		close(fd);
	    }

	    if (rc)
		umount("/modules");
	}
    }

    if (mlLoadModule(pcic, NULL, modLoaded, modDeps, NULL, 
		     modInfo, flags)) {
	logMessage("failed to load pcic");
	umount("/modules");
	return LOADER_ERROR;
    }

    if (mlLoadModule("ds", NULL, modLoaded, modDeps, NULL, 
		     modInfo, flags)) {
	logMessage("failed to load ds");
	umount("/modules");
	return LOADER_ERROR;
    }

    if (!(child = fork())) {
	exit(cardmgr_main(5, cardmgrArgs));
    }

    logMessage("cardmgr running as pid %d", child);

    waitpid(child, &status, 0);

    logMessage("cardmgr returned 0x%x", status);

    newtPopWindow();
    umount("/modules");

    strcpy(pcicPtr, pcic);
    
    return 0;
}