Lines 56-61
Link Here
|
56 |
#include <pcmcia/cistpl.h> |
56 |
#include <pcmcia/cistpl.h> |
57 |
#include <pcmcia/ds.h> |
57 |
#include <pcmcia/ds.h> |
58 |
|
58 |
|
|
|
59 |
/* Bugfix to keep track of network interfaces name change. */ |
60 |
#include <libnetlink/ll_map.h> |
61 |
#include <netinet/in.h> |
62 |
#include <libnetlink/libnetlink.h> |
63 |
|
59 |
#include "cardmgr.h" |
64 |
#include "cardmgr.h" |
60 |
|
65 |
|
61 |
/*====================================================================*/ |
66 |
/*====================================================================*/ |
Lines 65-70
Link Here
|
65 |
int state; |
70 |
int state; |
66 |
card_info_t *card; |
71 |
card_info_t *card; |
67 |
bind_info_t *bind[MAX_BINDINGS]; |
72 |
bind_info_t *bind[MAX_BINDINGS]; |
|
|
73 |
/* For network interfaces only. */ |
74 |
int ifindex[MAX_BINDINGS]; |
68 |
mtd_ident_t *mtd[2*CISTPL_MAX_DEVICES]; |
75 |
mtd_ident_t *mtd[2*CISTPL_MAX_DEVICES]; |
69 |
cistpl_funcid_t funcid; |
76 |
cistpl_funcid_t funcid; |
70 |
cistpl_manfid_t manfid; |
77 |
cistpl_manfid_t manfid; |
Lines 97-103
Link Here
|
97 |
struct mtd_ident_t *default_mtd = NULL; |
104 |
struct mtd_ident_t *default_mtd = NULL; |
98 |
|
105 |
|
99 |
static int sockets; |
106 |
static int sockets; |
100 |
static struct socket_info_t socket[MAX_SOCKS]; |
107 |
/* Here I rename socket to cardsocket to resolve conflict with */ |
|
|
108 |
/* /usr/include/sys/socket.h:100 */ |
109 |
static struct socket_info_t cardsocket[MAX_SOCKS]; |
101 |
|
110 |
|
102 |
/* Default path for config file, device scripts */ |
111 |
/* Default path for config file, device scripts */ |
103 |
#ifdef ETC |
112 |
#ifdef ETC |
Lines 297-303
Link Here
|
297 |
return; |
306 |
return; |
298 |
} |
307 |
} |
299 |
for (i = 0; i < sockets; i++) { |
308 |
for (i = 0; i < sockets; i++) { |
300 |
s = &socket[i]; |
309 |
s = &cardsocket[i]; |
301 |
fprintf(f, "Socket %d: ", i); |
310 |
fprintf(f, "Socket %d: ", i); |
302 |
if (!(s->state & SOCKET_PRESENT)) { |
311 |
if (!(s->state & SOCKET_PRESENT)) { |
303 |
fprintf(f, "empty\n"); |
312 |
fprintf(f, "empty\n"); |
Lines 333-339
Link Here
|
333 |
|
342 |
|
334 |
static int get_tuple(int ns, cisdata_t code, ds_ioctl_arg_t *arg) |
343 |
static int get_tuple(int ns, cisdata_t code, ds_ioctl_arg_t *arg) |
335 |
{ |
344 |
{ |
336 |
socket_info_t *s = &socket[ns]; |
345 |
socket_info_t *s = &cardsocket[ns]; |
337 |
|
346 |
|
338 |
arg->tuple.DesiredTuple = code; |
347 |
arg->tuple.DesiredTuple = code; |
339 |
arg->tuple.Attributes = 0; |
348 |
arg->tuple.Attributes = 0; |
Lines 365-371
Link Here
|
365 |
|
374 |
|
366 |
static int get_pci_id(int ns, pci_id_t *id) |
375 |
static int get_pci_id(int ns, pci_id_t *id) |
367 |
{ |
376 |
{ |
368 |
socket_info_t *s = &socket[ns]; |
377 |
socket_info_t *s = &cardsocket[ns]; |
369 |
config_info_t config; |
378 |
config_info_t config; |
370 |
|
379 |
|
371 |
config.Function = config.ConfigBase = 0; |
380 |
config.Function = config.ConfigBase = 0; |
Lines 411-417
Link Here
|
411 |
|
420 |
|
412 |
static card_info_t *lookup_card(int ns) |
421 |
static card_info_t *lookup_card(int ns) |
413 |
{ |
422 |
{ |
414 |
socket_info_t *s = &socket[ns]; |
423 |
socket_info_t *s = &cardsocket[ns]; |
415 |
card_info_t *card = NULL; |
424 |
card_info_t *card = NULL; |
416 |
ds_ioctl_arg_t arg; |
425 |
ds_ioctl_arg_t arg; |
417 |
pci_id_t pci_id = { 0, 0 }; |
426 |
pci_id_t pci_id = { 0, 0 }; |
Lines 688-694
Link Here
|
688 |
|
697 |
|
689 |
static int execute_on_all(char *cmd, char *class, int sn, int fn) |
698 |
static int execute_on_all(char *cmd, char *class, int sn, int fn) |
690 |
{ |
699 |
{ |
691 |
socket_info_t *s = &socket[sn]; |
700 |
socket_info_t *s = &cardsocket[sn]; |
692 |
bind_info_t *bind; |
701 |
bind_info_t *bind; |
693 |
int i, k, ret = 0; |
702 |
int i, k, ret = 0; |
694 |
char m[10]; |
703 |
char m[10]; |
Lines 866-872
Link Here
|
866 |
|
875 |
|
867 |
static void bind_mtd(int sn) |
876 |
static void bind_mtd(int sn) |
868 |
{ |
877 |
{ |
869 |
socket_info_t *s = &socket[sn]; |
878 |
socket_info_t *s = &cardsocket[sn]; |
870 |
region_info_t region; |
879 |
region_info_t region; |
871 |
bind_info_t bind; |
880 |
bind_info_t bind; |
872 |
mtd_info_t mtd_info; |
881 |
mtd_info_t mtd_info; |
Lines 937-943
Link Here
|
937 |
|
946 |
|
938 |
static void do_insert(int sn) |
947 |
static void do_insert(int sn) |
939 |
{ |
948 |
{ |
940 |
socket_info_t *s = &socket[sn]; |
949 |
socket_info_t *s = &cardsocket[sn]; |
941 |
card_info_t *card; |
950 |
card_info_t *card; |
942 |
device_info_t **dev; |
951 |
device_info_t **dev; |
943 |
bind_info_t *bind, **tail; |
952 |
bind_info_t *bind, **tail; |
Lines 1035-1041
Link Here
|
1035 |
for (i = ret = 0; i < card->bindings; i++) { |
1044 |
for (i = ret = 0; i < card->bindings; i++) { |
1036 |
char *class = EITHER_OR(card->class[i], dev[i]->class); |
1045 |
char *class = EITHER_OR(card->class[i], dev[i]->class); |
1037 |
if (class) |
1046 |
if (class) |
1038 |
ret |= execute_on_all("start", class, sn, i); |
1047 |
{ |
|
|
1048 |
/* If we added a network interface, remember its ifindex */ |
1049 |
/* to perform stop with the current iface name, not original one. */ |
1050 |
if (!strcmp (class, "network")) |
1051 |
{ |
1052 |
struct rtnl_handle rth; |
1053 |
cardsocket[sn].ifindex[i] = 0; |
1054 |
if (rtnl_open (&rth, 0) >= 0) |
1055 |
{ |
1056 |
ll_init_map (&rth); |
1057 |
cardsocket[sn].ifindex[i] = ll_name_to_index (cardsocket[sn].bind[i]->name); |
1058 |
rtnl_close (&rth); |
1059 |
} |
1060 |
} |
1061 |
ret |= execute_on_all("start", class, sn, i); |
1062 |
} |
1039 |
} |
1063 |
} |
1040 |
beep(BEEP_TIME, (ret) ? BEEP_ERR : BEEP_OK); |
1064 |
beep(BEEP_TIME, (ret) ? BEEP_ERR : BEEP_OK); |
1041 |
|
1065 |
|
Lines 1045-1051
Link Here
|
1045 |
|
1069 |
|
1046 |
static int do_check(int sn) |
1070 |
static int do_check(int sn) |
1047 |
{ |
1071 |
{ |
1048 |
socket_info_t *s = &socket[sn]; |
1072 |
socket_info_t *s = &cardsocket[sn]; |
1049 |
card_info_t *card; |
1073 |
card_info_t *card; |
1050 |
device_info_t **dev; |
1074 |
device_info_t **dev; |
1051 |
int i; |
1075 |
int i; |
Lines 1068-1074
Link Here
|
1068 |
|
1092 |
|
1069 |
static void do_remove(int sn) |
1093 |
static void do_remove(int sn) |
1070 |
{ |
1094 |
{ |
1071 |
socket_info_t *s = &socket[sn]; |
1095 |
socket_info_t *s = &cardsocket[sn]; |
1072 |
card_info_t *card; |
1096 |
card_info_t *card; |
1073 |
device_info_t **dev; |
1097 |
device_info_t **dev; |
1074 |
bind_info_t *bind; |
1098 |
bind_info_t *bind; |
Lines 1085-1091
Link Here
|
1085 |
for (i = 0; i < card->bindings; i++) { |
1109 |
for (i = 0; i < card->bindings; i++) { |
1086 |
char *class = EITHER_OR(card->class[i], dev[i]->class); |
1110 |
char *class = EITHER_OR(card->class[i], dev[i]->class); |
1087 |
if (class) |
1111 |
if (class) |
1088 |
execute_on_all("stop", class, sn, i); |
1112 |
{ |
|
|
1113 |
/* Now we will make use of ifindex stored in do_insert() */ |
1114 |
if (!strcmp (class, "network") && cardsocket[sn].ifindex[i]) |
1115 |
{ |
1116 |
struct rtnl_handle rth; |
1117 |
if (rtnl_open (&rth, 0) >= 0) |
1118 |
{ |
1119 |
ll_init_map (&rth); |
1120 |
strncpy (cardsocket[sn].bind[i]->name, ll_index_to_name (cardsocket[sn].ifindex[i]), DEV_NAME_LEN); |
1121 |
rtnl_close (&rth); |
1122 |
} |
1123 |
} |
1124 |
execute_on_all("stop", class, sn, i); |
1125 |
} |
1089 |
} |
1126 |
} |
1090 |
|
1127 |
|
1091 |
/* unbind driver instances */ |
1128 |
/* unbind driver instances */ |
Lines 1134-1140
Link Here
|
1134 |
|
1171 |
|
1135 |
static void do_suspend(int sn) |
1172 |
static void do_suspend(int sn) |
1136 |
{ |
1173 |
{ |
1137 |
socket_info_t *s = &socket[sn]; |
1174 |
socket_info_t *s = &cardsocket[sn]; |
1138 |
card_info_t *card; |
1175 |
card_info_t *card; |
1139 |
device_info_t **dev; |
1176 |
device_info_t **dev; |
1140 |
int i; |
1177 |
int i; |
Lines 1154-1160
Link Here
|
1154 |
|
1191 |
|
1155 |
static void do_resume(int sn) |
1192 |
static void do_resume(int sn) |
1156 |
{ |
1193 |
{ |
1157 |
socket_info_t *s = &socket[sn]; |
1194 |
socket_info_t *s = &cardsocket[sn]; |
1158 |
card_info_t *card; |
1195 |
card_info_t *card; |
1159 |
device_info_t **dev; |
1196 |
device_info_t **dev; |
1160 |
int i; |
1197 |
int i; |
Lines 1180-1186
Link Here
|
1180 |
for (;;) { |
1217 |
for (;;) { |
1181 |
usleep(100000); |
1218 |
usleep(100000); |
1182 |
for (i = 0; i < sockets; i++) |
1219 |
for (i = 0; i < sockets; i++) |
1183 |
if ((ioctl(socket[i].fd, DS_GET_STATUS, &status) == 0) && |
1220 |
if ((ioctl(cardsocket[i].fd, DS_GET_STATUS, &status) == 0) && |
1184 |
(status.CardState & CS_EVENT_CARD_INSERTION)) |
1221 |
(status.CardState & CS_EVENT_CARD_INSERTION)) |
1185 |
break; |
1222 |
break; |
1186 |
if (i == sockets) break; |
1223 |
if (i == sockets) break; |
Lines 1192-1198
Link Here
|
1192 |
static void free_resources(void) |
1229 |
static void free_resources(void) |
1193 |
{ |
1230 |
{ |
1194 |
adjust_list_t *al; |
1231 |
adjust_list_t *al; |
1195 |
int fd = socket[0].fd; |
1232 |
int fd = cardsocket[0].fd; |
1196 |
|
1233 |
|
1197 |
for (al = root_adjust; al; al = al->next) { |
1234 |
for (al = root_adjust; al; al = al->next) { |
1198 |
if (al->adj.Action == ADD_MANAGED_RESOURCE) { |
1235 |
if (al->adj.Action == ADD_MANAGED_RESOURCE) { |
Lines 1214-1220
Link Here
|
1214 |
adjust_list_t *al; |
1251 |
adjust_list_t *al; |
1215 |
int ret; |
1252 |
int ret; |
1216 |
char tmp[64]; |
1253 |
char tmp[64]; |
1217 |
int fd = socket[0].fd; |
1254 |
int fd = cardsocket[0].fd; |
1218 |
|
1255 |
|
1219 |
for (al = root_adjust; al; al = al->next) { |
1256 |
for (al = root_adjust; al; al = al->next) { |
1220 |
ret = ioctl(fd, DS_ADJUST_RESOURCE_INFO, &al->adj); |
1257 |
ret = ioctl(fd, DS_ADJUST_RESOURCE_INFO, &al->adj); |
Lines 1280-1286
Link Here
|
1280 |
case SIGTERM: |
1317 |
case SIGTERM: |
1281 |
case SIGINT: |
1318 |
case SIGINT: |
1282 |
for (i = 0; i < sockets; i++) |
1319 |
for (i = 0; i < sockets; i++) |
1283 |
if ((socket[i].state & SOCKET_PRESENT) && |
1320 |
if ((cardsocket[i].state & SOCKET_PRESENT) && |
1284 |
(do_check(i) == 0)) do_remove(i); |
1321 |
(do_check(i) == 0)) do_remove(i); |
1285 |
free_resources(); |
1322 |
free_resources(); |
1286 |
exit(0); |
1323 |
exit(0); |
Lines 1316-1323
Link Here
|
1316 |
for (fd = -1, i = 0; i < MAX_SOCKS; i++) { |
1353 |
for (fd = -1, i = 0; i < MAX_SOCKS; i++) { |
1317 |
fd = open_sock(i, S_IFCHR|S_IREAD|S_IWRITE); |
1354 |
fd = open_sock(i, S_IFCHR|S_IREAD|S_IWRITE); |
1318 |
if (fd < 0) break; |
1355 |
if (fd < 0) break; |
1319 |
socket[i].fd = fd; |
1356 |
cardsocket[i].fd = fd; |
1320 |
socket[i].state = 0; |
1357 |
cardsocket[i].state = 0; |
1321 |
} |
1358 |
} |
1322 |
if ((fd < 0) && (errno != ENODEV) && (errno != ENOENT)) |
1359 |
if ((fd < 0) && (errno != ENODEV) && (errno != ENOENT)) |
1323 |
syslog(LOG_ERR, "open_sock(socket %d) failed: %m", i); |
1360 |
syslog(LOG_ERR, "open_sock(socket %d) failed: %m", i); |
Lines 1444-1450
Link Here
|
1444 |
#endif |
1481 |
#endif |
1445 |
|
1482 |
|
1446 |
for (i = max_fd = 0; i < sockets; i++) |
1483 |
for (i = max_fd = 0; i < sockets; i++) |
1447 |
max_fd = (socket[i].fd > max_fd) ? socket[i].fd : max_fd; |
1484 |
max_fd = (cardsocket[i].fd > max_fd) ? cardsocket[i].fd : max_fd; |
1448 |
|
1485 |
|
1449 |
/* First select() call: poll, don't wait */ |
1486 |
/* First select() call: poll, don't wait */ |
1450 |
tv.tv_sec = tv.tv_usec = 0; |
1487 |
tv.tv_sec = tv.tv_usec = 0; |
Lines 1456-1462
Link Here
|
1456 |
for (pass = 0; ; pass++) { |
1493 |
for (pass = 0; ; pass++) { |
1457 |
FD_ZERO(&fds); |
1494 |
FD_ZERO(&fds); |
1458 |
for (i = 0; i < sockets; i++) |
1495 |
for (i = 0; i < sockets; i++) |
1459 |
FD_SET(socket[i].fd, &fds); |
1496 |
FD_SET(cardsocket[i].fd, &fds); |
1460 |
|
1497 |
|
1461 |
while ((ret = select(max_fd+1, &fds, NULL, NULL, |
1498 |
while ((ret = select(max_fd+1, &fds, NULL, NULL, |
1462 |
((pass == 0) ? &tv : NULL))) < 0) { |
1499 |
((pass == 0) ? &tv : NULL))) < 0) { |
Lines 1469-1477
Link Here
|
1469 |
} |
1506 |
} |
1470 |
|
1507 |
|
1471 |
for (i = 0; i < sockets; i++) { |
1508 |
for (i = 0; i < sockets; i++) { |
1472 |
if (!FD_ISSET(socket[i].fd, &fds)) |
1509 |
if (!FD_ISSET(cardsocket[i].fd, &fds)) |
1473 |
continue; |
1510 |
continue; |
1474 |
ret = read(socket[i].fd, &event, 4); |
1511 |
ret = read(cardsocket[i].fd, &event, 4); |
1475 |
if ((ret == -1) && (errno != EAGAIN)) |
1512 |
if ((ret == -1) && (errno != EAGAIN)) |
1476 |
syslog(LOG_INFO, "read(%d): %m\n", i); |
1513 |
syslog(LOG_INFO, "read(%d): %m\n", i); |
1477 |
if (ret != 4) |
1514 |
if (ret != 4) |
Lines 1479-1504
Link Here
|
1479 |
|
1516 |
|
1480 |
switch (event) { |
1517 |
switch (event) { |
1481 |
case CS_EVENT_CARD_REMOVAL: |
1518 |
case CS_EVENT_CARD_REMOVAL: |
1482 |
socket[i].state = 0; |
1519 |
cardsocket[i].state = 0; |
1483 |
do_remove(i); |
1520 |
do_remove(i); |
1484 |
break; |
1521 |
break; |
1485 |
case CS_EVENT_EJECTION_REQUEST: |
1522 |
case CS_EVENT_EJECTION_REQUEST: |
1486 |
ret = do_check(i); |
1523 |
ret = do_check(i); |
1487 |
if (ret == 0) { |
1524 |
if (ret == 0) { |
1488 |
socket[i].state = 0; |
1525 |
cardsocket[i].state = 0; |
1489 |
do_remove(i); |
1526 |
do_remove(i); |
1490 |
} |
1527 |
} |
1491 |
write(socket[i].fd, &ret, 4); |
1528 |
write(cardsocket[i].fd, &ret, 4); |
1492 |
break; |
1529 |
break; |
1493 |
case CS_EVENT_CARD_INSERTION: |
1530 |
case CS_EVENT_CARD_INSERTION: |
1494 |
case CS_EVENT_INSERTION_REQUEST: |
1531 |
case CS_EVENT_INSERTION_REQUEST: |
1495 |
socket[i].state |= SOCKET_PRESENT; |
1532 |
cardsocket[i].state |= SOCKET_PRESENT; |
1496 |
case CS_EVENT_CARD_RESET: |
1533 |
case CS_EVENT_CARD_RESET: |
1497 |
socket[i].state |= SOCKET_READY; |
1534 |
cardsocket[i].state |= SOCKET_READY; |
1498 |
do_insert(i); |
1535 |
do_insert(i); |
1499 |
break; |
1536 |
break; |
1500 |
case CS_EVENT_RESET_PHYSICAL: |
1537 |
case CS_EVENT_RESET_PHYSICAL: |
1501 |
socket[i].state &= ~SOCKET_READY; |
1538 |
cardsocket[i].state &= ~SOCKET_READY; |
1502 |
break; |
1539 |
break; |
1503 |
case CS_EVENT_PM_SUSPEND: |
1540 |
case CS_EVENT_PM_SUSPEND: |
1504 |
do_suspend(i); |
1541 |
do_suspend(i); |