/* * Remove usb entries that are handled by usb-storage. */ void int_fix_usb_scsi(hd_data_t *hd_data) { hd_t *hd_scsi, *hd_usb; for(hd_usb = hd_data->hd; hd_usb; hd_usb= hd_usb->next) { if( hd_usb->bus.id == bus_usb && hd_usb->sysfs_id && search_str_list(hd_usb->drivers, "usb-storage") ) { for(hd_scsi = hd_data->hd; hd_scsi; hd_scsi = hd_scsi->next) { if( hd_scsi->bus.id == bus_scsi && hd_scsi->sysfs_device_link && search_str_list(hd_scsi->drivers, "usb-storage") ) { if(!strncmp(hd_scsi->sysfs_device_link, hd_usb->sysfs_id, strlen(hd_usb->sysfs_id))) { hd_set_hw_class(hd_scsi, hw_usb); free_mem(hd_scsi->unique_id); hd_scsi->unique_id = hd_usb->unique_id; hd_usb->unique_id = NULL; add_res_entry(&hd_scsi->res, hd_usb->res); hd_usb->res = NULL; if(!hd_scsi->modalias) { hd_scsi->modalias = hd_usb->modalias; hd_usb->modalias = NULL; } if(!hd_scsi->vendor.id) hd_scsi->vendor.id = hd_usb->vendor.id; if(!hd_scsi->device.id) hd_scsi->device.id = hd_usb->device.id; if(!hd_scsi->serial) { hd_scsi->serial = hd_usb->serial; hd_usb->serial = NULL; } if(!hd_scsi->driver_info) { hd_scsi->driver_info = hd_usb->driver_info; hd_usb->driver_info = NULL; } new_id(hd_data, hd_scsi); hd_usb->tag.remove = 1; } } } } } remove_tagged_hd_entries(hd_data); }
void hd_scan_net(hd_data_t *hd_data) { unsigned u; int if_type, if_carrier; hd_t *hd, *hd_card; char *s, *t, *hw_addr; hd_res_t *res, *res1, *res2; uint64_t ul0; str_list_t *sf_class, *sf_class_e; char *sf_cdev = NULL, *sf_dev = NULL; char *sf_drv_name, *sf_drv; if(!hd_probe_feature(hd_data, pr_net)) return; hd_data->module = mod_net; /* some clean-up */ remove_hd_entries(hd_data); hd_data->net = free_str_list(hd_data->net); PROGRESS(1, 0, "get network data"); sf_class = read_dir("/sys/class/net", 'l'); if(!sf_class) sf_class = read_dir("/sys/class/net", 'd'); if(!sf_class) { ADD2LOG("sysfs: no such class: net\n"); return; } for(sf_class_e = sf_class; sf_class_e; sf_class_e = sf_class_e->next) { str_printf(&sf_cdev, 0, "/sys/class/net/%s", sf_class_e->str); hd_card = NULL; ADD2LOG( " net interface: name = %s, path = %s\n", sf_class_e->str, hd_sysfs_id(sf_cdev) ); if_type = -1; if(hd_attr_uint(get_sysfs_attr_by_path(sf_cdev, "type"), &ul0, 0)) { if_type = ul0; ADD2LOG(" type = %d\n", if_type); } if_carrier = -1; if(hd_attr_uint(get_sysfs_attr_by_path(sf_cdev, "carrier"), &ul0, 0)) { if_carrier = ul0; ADD2LOG(" carrier = %d\n", if_carrier); } hw_addr = NULL; if((s = get_sysfs_attr_by_path(sf_cdev, "address"))) { hw_addr = canon_str(s, strlen(s)); ADD2LOG(" hw_addr = %s\n", hw_addr); } sf_dev = new_str(hd_read_sysfs_link(sf_cdev, "device")); if(sf_dev) { ADD2LOG(" net device: path = %s\n", hd_sysfs_id(sf_dev)); } sf_drv_name = NULL; sf_drv = hd_read_sysfs_link(sf_dev, "driver"); if(sf_drv) { sf_drv_name = strrchr(sf_drv, '/'); if(sf_drv_name) sf_drv_name++; ADD2LOG( " net driver: name = %s, path = %s\n", sf_drv_name, hd_sysfs_id(sf_drv) ); } hd = add_hd_entry(hd_data, __LINE__, 0); hd->base_class.id = bc_network_interface; hd->sub_class.id = sc_nif_other; res1 = NULL; if(hw_addr && strspn(hw_addr, "0:") != strlen(hw_addr)) { res1 = new_mem(sizeof *res1); res1->hwaddr.type = res_hwaddr; res1->hwaddr.addr = new_str(hw_addr); add_res_entry(&hd->res, res1); } res2 = NULL; if(if_carrier >= 0) { res = new_mem(sizeof *res); res->link.type = res_link; res->link.state = if_carrier ? 1 : 0; add_res_entry(&hd->res, res); } hd->unix_dev_name = new_str(sf_class_e->str); hd->sysfs_id = new_str(hd_sysfs_id(sf_cdev)); if(sf_drv_name) { add_str_list(&hd->drivers, sf_drv_name); } else if(hd->res) { get_driverinfo(hd_data, hd); } switch(if_type) { case ARPHRD_ETHER: /* eth */ hd->sub_class.id = sc_nif_ethernet; break; case ARPHRD_LOOPBACK: /* lo */ hd->sub_class.id = sc_nif_loopback; break; case ARPHRD_SIT: /* sit */ hd->sub_class.id = sc_nif_sit; break; case ARPHRD_FDDI: /* fddi */ hd->sub_class.id = sc_nif_fddi; break; case ARPHRD_IEEE802_TR: /* tr */ hd->sub_class.id = sc_nif_tokenring; break; #if 0 case ARPHRD_IEEE802: /* fc */ hd->sub_class.id = sc_nif_fc; break; #endif default: hd->sub_class.id = sc_nif_other; } if(!strcmp(hd->unix_dev_name, "lo")) { hd->sub_class.id = sc_nif_loopback; } else if(sscanf(hd->unix_dev_name, "eth%u", &u) == 1) { hd->sub_class.id = sc_nif_ethernet; hd->slot = u; } else if(sscanf(hd->unix_dev_name, "tr%u", &u) == 1) { hd->sub_class.id = sc_nif_tokenring; hd->slot = u; } else if(sscanf(hd->unix_dev_name, "fddi%u", &u) == 1) { hd->sub_class.id = sc_nif_fddi; hd->slot = u; } else if(sscanf(hd->unix_dev_name, "ctc%u", &u) == 1) { hd->sub_class.id = sc_nif_ctc; hd->slot = u; } else if(sscanf(hd->unix_dev_name, "iucv%u", &u) == 1) { hd->sub_class.id = sc_nif_iucv; hd->slot = u; } else if(sscanf(hd->unix_dev_name, "hsi%u", &u) == 1) { hd->sub_class.id = sc_nif_hsi; hd->slot = u; } else if(sscanf(hd->unix_dev_name, "qeth%u", &u) == 1) { hd->sub_class.id = sc_nif_qeth; hd->slot = u; } else if(sscanf(hd->unix_dev_name, "escon%u", &u) == 1) { hd->sub_class.id = sc_nif_escon; hd->slot = u; } else if(sscanf(hd->unix_dev_name, "myri%u", &u) == 1) { hd->sub_class.id = sc_nif_myrinet; hd->slot = u; } else if(sscanf(hd->unix_dev_name, "sit%u", &u) == 1) { hd->sub_class.id = sc_nif_sit; /* ipv6 over ipv4 tunnel */ hd->slot = u; } else if(sscanf(hd->unix_dev_name, "wlan%u", &u) == 1) { hd->sub_class.id = sc_nif_wlan; hd->slot = u; } else if(sscanf(hd->unix_dev_name, "xp%u", &u) == 1) { hd->sub_class.id = sc_nif_xp; hd->slot = u; } else if(sscanf(hd->unix_dev_name, "usb%u", &u) == 1) { hd->sub_class.id = sc_nif_usb; hd->slot = u; } /* ##### add more interface names here */ else { for(s = hd->unix_dev_name; *s; s++) if(isdigit(*s)) break; if(*s && (u = strtoul(s, &s, 10), !*s)) { hd->slot = u; } } hd->bus.id = bus_none; hd_card = NULL; if(sf_dev) { s = new_str(hd_sysfs_id(sf_dev)); hd->sysfs_device_link = new_str(s); hd_card = hd_find_sysfs_id(hd_data, s); // try one above, if not found if(!hd_card) { t = strrchr(s, '/'); if(t) { *t = 0; hd_card = hd_find_sysfs_id(hd_data, s); } } /* if one card has several interfaces (as with PS3), check interface names, too */ if( hd_card && hd_card->unix_dev_name && hd->unix_dev_name && strcmp(hd->unix_dev_name, hd_card->unix_dev_name) ) { hd_card = hd_find_sysfs_id_devname(hd_data, s, hd->unix_dev_name); } s = free_mem(s); if(hd_card) { hd->attached_to = hd_card->idx; /* for cards with strange pci classes */ hd_set_hw_class(hd_card, hw_network_ctrl); /* add hw addr to network card */ if(res1) { u = 0; for(res = hd_card->res; res; res = res->next) { if( res->any.type == res_hwaddr && !strcmp(res->hwaddr.addr, res1->hwaddr.addr) ) { u = 1; break; } } if(!u) { res = new_mem(sizeof *res); res->hwaddr.type = res_hwaddr; res->hwaddr.addr = new_str(res1->hwaddr.addr); add_res_entry(&hd_card->res, res); } } /* * add interface names... * but not wmasterX (bnc #441778) */ if(if_type != 801) add_if_name(hd_card, hd); } } if(!hd_card && hw_addr) { /* try to find card based on hwaddr (for prom-based cards) */ for(hd_card = hd_data->hd; hd_card; hd_card = hd_card->next) { if( hd_card->base_class.id != bc_network || hd_card->sub_class.id != 0 ) continue; for(res = hd_card->res; res; res = res->next) { if( res->any.type == res_hwaddr && !strcmp(hw_addr, res->hwaddr.addr) ) break; } if(res) { hd->attached_to = hd_card->idx; break; } } } hw_addr = free_mem(hw_addr); /* fix card type */ if(hd_card) { if( (hd_card->base_class.id == 0 && hd_card->sub_class.id == 0) || (hd_card->base_class.id == bc_network && hd_card->sub_class.id == 0x80) ) { switch(hd->sub_class.id) { case sc_nif_ethernet: hd_card->base_class.id = bc_network; hd_card->sub_class.id = 0; break; case sc_nif_usb: hd_card->base_class.id = bc_network; hd_card->sub_class.id = 0x91; break; } } } sf_dev = free_mem(sf_dev); } sf_cdev = free_mem(sf_cdev); sf_class = free_str_list(sf_class); if(hd_is_sgi_altix(hd_data)) add_xpnet(hd_data); add_uml(hd_data); add_kma(hd_data); /* add link status info & dump eeprom */ for(hd = hd_data->hd ; hd; hd = hd->next) { if( hd->module == hd_data->module && hd->base_class.id == bc_network_interface ) { char *buf = NULL; str_list_t *sl0, *sl; if(hd_probe_feature(hd_data, pr_net_eeprom) && hd->unix_dev_name) { PROGRESS(2, 0, "eeprom dump"); str_printf(&buf, 0, "|/usr/sbin/ethtool -e %s 2>/dev/null", hd->unix_dev_name); if((sl0 = read_file(buf, 0, 0))) { ADD2LOG("----- %s %s -----\n", hd->unix_dev_name, "EEPROM dump"); for(sl = sl0; sl; sl = sl->next) { ADD2LOG("%s", sl->str); } ADD2LOG("----- %s end -----\n", "EEPROM dump"); free_str_list(sl0); } free(buf); } for(res = hd->res; res; res = res->next) { if(res->any.type == res_link) break; } if(!res) get_linkstate(hd_data, hd); if(!(hd_card = hd_get_device_by_idx(hd_data, hd->attached_to))) continue; for(res = hd->res; res; res = res->next) { if(res->any.type == res_link) break; } if(res) { for(res1 = hd_card->res; res1; res1 = res1->next) { if(res1->any.type == res_link) break; } if(res && !res1) { res1 = new_mem(sizeof *res1); res1->link.type = res_link; res1->link.state = res->link.state; add_res_entry(&hd_card->res, res1); } } } } }
void get_input_devices(hd_data_t *hd_data) { hd_t *hd; str_list_t *input, *sl, *sl1; char *s; unsigned ok, u, is_mouse, is_joystick; unsigned bus, vendor, product, version; unsigned mouse_buttons, mouse_wheels; char *name = NULL, *handlers = NULL, *key = NULL, *rel = NULL, *abso = NULL; size_t len; str_list_t *handler_list; hd_dev_num_t dev_num = { type: 'c', range: 1 }; input = read_file("/proc/bus/input/devices", 0, 0); ADD2LOG("----- /proc/bus/input/devices -----\n"); for(sl = input; sl; sl = sl->next) { ADD2LOG(" %s", sl->str); } ADD2LOG("----- /proc/bus/input/devices end -----\n"); for(ok = 0, sl = input; sl; sl = sl->next) { if(*sl->str == '\n') { ADD2LOG("bus = %u, name = %s\n", bus, name); if(handlers) ADD2LOG(" handlers = %s\n", handlers); if(key) ADD2LOG(" key = %s\n", key); if(rel) ADD2LOG(" rel = %s\n", rel); if(abso) ADD2LOG(" abs = %s\n", abso); mouse_buttons = 0; if(key) { for(u = BTN_MOUSE; u < BTN_MOUSE + 8; u++) { if(test_bit(key, u)) mouse_buttons++; } } ADD2LOG(" mouse buttons = %u\n", mouse_buttons); mouse_wheels = 0; if(rel) { for(u = REL_HWHEEL; u <= REL_MAX; u++) { if(test_bit(rel, u)) mouse_wheels++; } } ADD2LOG(" mouse wheels = %u\n", mouse_wheels); if(ok && handlers) { handler_list = hd_split(' ', handlers); is_mouse = strstr(handlers, "mouse") ? 1 : 0; is_joystick = strstr(handlers, "js") ? 1 : 0; if( // HP Virtual Management Device vendor == 0x03f0 && product == 0x1126 && mouse_buttons >= 3 ) is_mouse = 1; ADD2LOG(" is_mouse = %u\n", is_mouse); ADD2LOG(" is_joystick = %u\n", is_joystick); if(bus == BUS_USB) { s = NULL; for(sl1 = handler_list; sl1; sl1 = sl1->next) { if(sscanf(sl1->str, "mouse%u", &u) == 1) { str_printf(&s, 0, "/dev/input/mouse%u", u); break; } } if(!s && (is_mouse || is_joystick)) for(sl1 = handler_list; sl1; sl1 = sl1->next) { if(sscanf(sl1->str, "event%u", &u) == 1) { str_printf(&s, 0, "/dev/input/event%u", u); break; } } if(s) { for(hd = hd_data->hd; hd; hd = hd->next) { if( (hd->unix_dev_name2 && !strcmp(hd->unix_dev_name2, s)) || (hd->unix_dev_name && !strcmp(hd->unix_dev_name, s)) ) { if(!hd->base_class.id) { if (is_mouse) { hd->base_class.id = bc_mouse; hd->sub_class.id = sc_mou_usb; } else if (is_joystick) { hd->base_class.id = bc_joystick; } } if (is_mouse) { hd_set_hw_class(hd, hw_mouse); hd->compat_vendor.id = MAKE_ID(TAG_SPECIAL, 0x0210); hd->compat_device.id = MAKE_ID(TAG_SPECIAL, (mouse_wheels << 4) + mouse_buttons); } else if (is_joystick) { hd_set_hw_class(hd, hw_joystick); /* add buttons and axis details */ add_joystick_details(hd_data, hd, key, abso); } if(hd->unix_dev_name) add_str_list(&hd->unix_dev_names, hd->unix_dev_name); if(hd->unix_dev_name2) add_str_list(&hd->unix_dev_names, hd->unix_dev_name2); for(sl1 = handler_list; sl1; sl1 = sl1->next) { if(sscanf(sl1->str, "event%u", &u) == 1) { str_printf(&s, 0, "/dev/input/event%u", u); if(!search_str_list(hd->unix_dev_names, s)) add_str_list(&hd->unix_dev_names, s); s = free_mem(s); } /* add /dev/input/jsN joystick device name */ else if (is_joystick) { if(sscanf(sl1->str, "js%u", &u) == 1) { str_printf(&s, 0, "/dev/input/js%u", u); if(!search_str_list(hd->unix_dev_names, s)) add_str_list(&hd->unix_dev_names, s); if(!hd->unix_dev_name2) hd->unix_dev_name2 = new_str(s); s = free_mem(s); } } } break; } } } s = free_mem(s); } else { // keyboard if(search_str_list(handler_list, "kbd") && test_bit(key, KEY_1)) { hd = add_hd_entry(hd_data, __LINE__, 0); hd->base_class.id = bc_keyboard; hd->sub_class.id = sc_keyboard_kbd; hd->bus.id = bus_ps2; hd->vendor.id = MAKE_ID(0, vendor); hd->device.id = MAKE_ID(0, product); hd->compat_vendor.id = MAKE_ID(TAG_SPECIAL, 0x0211); hd->compat_device.id = MAKE_ID(TAG_SPECIAL, 0x0001); hd->device.name = new_str(name); for(sl1 = handler_list; sl1; sl1 = sl1->next) { if(sscanf(sl1->str, "event%u", &u) == 1) { str_printf(&hd->unix_dev_name, 0, "/dev/input/event%u", u); dev_num.major = 13; dev_num.minor = 64 + u; hd->unix_dev_num = dev_num; break; } } } // mouse else if(is_mouse) { hd = add_hd_entry(hd_data, __LINE__, 0); hd->vendor.id = MAKE_ID(0, vendor); hd->device.id = MAKE_ID(0, product); hd->compat_vendor.id = MAKE_ID(TAG_SPECIAL, 0x0210); hd->compat_device.id = MAKE_ID(TAG_SPECIAL, (mouse_wheels << 4) + mouse_buttons); hd->base_class.id = bc_mouse; if(bus == BUS_ADB) { hd->sub_class.id = sc_mou_bus; hd->bus.id = bus_adb; } else { hd->sub_class.id = sc_mou_ps2; hd->bus.id = bus_ps2; } hd->device.name = new_str(name); #if 0 /* Synaptics/Alps TouchPad */ if( vendor == 2 && (product == 7 || product == 8) && test_bit(abso, ABS_X) && test_bit(abso, ABS_Y) && test_bit(abso, ABS_PRESSURE) && test_bit(key, BTN_TOOL_FINGER) ) { } #endif hd->unix_dev_name = new_str(DEV_MICE); dev_num.major = 13; dev_num.minor = 63; hd->unix_dev_num = dev_num; for(sl1 = handler_list; sl1; sl1 = sl1->next) { if(sscanf(sl1->str, "mouse%u", &u) == 1) { str_printf(&hd->unix_dev_name2, 0, "/dev/input/mouse%u", u); dev_num.major = 13; dev_num.minor = 32 + u; hd->unix_dev_num2 = dev_num; break; } } add_str_list(&hd->unix_dev_names, hd->unix_dev_name); add_str_list(&hd->unix_dev_names, hd->unix_dev_name2); for(sl1 = handler_list; sl1; sl1 = sl1->next) { if(sscanf(sl1->str, "event%u", &u) == 1) { s = NULL; str_printf(&s, 0, "/dev/input/event%u", u); add_str_list(&hd->unix_dev_names, s); s = free_mem(s); break; } } } // joystick else if(is_joystick) { hd = add_hd_entry(hd_data, __LINE__, 0); hd->vendor.id = MAKE_ID(0, vendor); hd->device.id = MAKE_ID(0, product); hd_set_hw_class(hd, hw_joystick); hd->base_class.id = bc_joystick; hd->device.name = new_str(name); // gameport? (see <linux/input.h>) if (bus == BUS_GAMEPORT) hd->bus.id = bus_gameport; /* add buttons and axis details */ add_joystick_details(hd_data, hd, key, abso); // add eventX device for(sl1 = handler_list; sl1; sl1 = sl1->next) { if(sscanf(sl1->str, "event%u", &u) == 1) { str_printf(&hd->unix_dev_name, 0, "/dev/input/event%u", u); dev_num.major = 13; dev_num.minor = 64 + u; hd->unix_dev_num = dev_num; break; } } // add jsX device for(sl1 = handler_list; sl1; sl1 = sl1->next) { if(sscanf(sl1->str, "js%u", &u) == 1) { str_printf(&hd->unix_dev_name2, 0, "/dev/input/js%u", u); break; } } add_str_list(&hd->unix_dev_names, hd->unix_dev_name); add_str_list(&hd->unix_dev_names, hd->unix_dev_name2); } else { ADD2LOG("unknown non-USB input device\n"); } } handler_list = free_str_list(handler_list); } ok = 0; name = free_mem(name); handlers = free_mem(handlers); key = free_mem(key); rel = free_mem(rel); abso = free_mem(abso); } if(sscanf(sl->str, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x", &bus, &vendor, &product, &version) == 4) { ok = 1; continue; } if(!strncmp(sl->str, INP_NAME, sizeof INP_NAME - 1)) { s = sl->str + sizeof INP_NAME; len = strlen(s); if(len > 2) { name = canon_str(s, len - 2); } continue; } if(!strncmp(sl->str, INP_HANDLERS, sizeof INP_HANDLERS - 1)) { s = sl->str + sizeof INP_HANDLERS - 1; handlers = canon_str(s, strlen(s)); continue; } if(!strncmp(sl->str, INP_KEY, sizeof INP_KEY - 1)) { s = sl->str + sizeof INP_KEY - 1; key = canon_str(s, strlen(s)); key = all_bits(key); continue; } if(!strncmp(sl->str, INP_REL, sizeof INP_REL - 1)) { s = sl->str + sizeof INP_REL - 1; rel = canon_str(s, strlen(s)); rel = all_bits(rel); continue; } if(!strncmp(sl->str, INP_ABS, sizeof INP_ABS - 1)) { s = sl->str + sizeof INP_ABS - 1; abso = canon_str(s, strlen(s)); abso = all_bits(abso); continue; } } free_str_list(input); } char *all_bits(char *str) { str_list_t *sl, *sl0; char *s = NULL; unsigned long u; if(!str) return NULL; sl = sl0 = hd_split(' ', str); for(; sl; sl = sl->next) { u = strtoul(sl->str, NULL, 16); str_printf(&s, -1, "%0*lx", (int) sizeof (unsigned long) * 2, u); } free_str_list(sl0); free_mem(str); return s; }