]>
git.ipfire.org Git - people/dweismueller/ipfire-2.x.git/blob - src/hwinfo/hwscan.c
75e9a792186a55eb48136945c7082c26313bf728
10 struct option options
[] = {
11 { "help", 0, NULL
, 'h' },
12 { "verbose", 0, NULL
, 'v' },
13 { "version", 0, NULL
, 400 },
14 { "show", 1, NULL
, 500 },
15 { "list", 0, NULL
, 501 },
16 { "cfg", 1, NULL
, 502 },
17 { "avail", 1, NULL
, 503 },
18 { "need", 1, NULL
, 504 },
19 { "new", 0, NULL
, 505 },
20 { "fast", 0, NULL
, 506 },
21 { "silent", 0, NULL
, 507 },
22 { "boot", 0, NULL
, 508 },
23 { "active", 1, NULL
, 509 },
24 { "only", 1, NULL
, 510 },
25 { "sys", 0, NULL
, 1000 + hw_sys
},
26 { "cpu", 0, NULL
, 1000 + hw_cpu
},
27 { "keyboard", 0, NULL
, 1000 + hw_keyboard
},
28 { "braille", 0, NULL
, 1000 + hw_braille
},
29 { "mouse", 0, NULL
, 1000 + hw_mouse
},
30 { "joystick", 0, NULL
, 1000 + hw_joystick
},
31 { "printer", 0, NULL
, 1000 + hw_printer
},
32 { "scanner", 0, NULL
, 1000 + hw_scanner
},
33 { "chipcard", 0, NULL
, 1000 + hw_chipcard
},
34 { "monitor", 0, NULL
, 1000 + hw_monitor
},
35 { "tv", 0, NULL
, 1000 + hw_tv
},
36 { "gfxcard", 0, NULL
, 1000 + hw_display
},
37 { "framebuffer", 0, NULL
, 1000 + hw_framebuffer
},
38 { "camera", 0, NULL
, 1000 + hw_camera
},
39 { "sound", 0, NULL
, 1000 + hw_sound
},
40 { "storage-ctrl", 0, NULL
, 1000 + hw_storage_ctrl
},
41 { "storage_ctrl", 0, NULL
, 1000 + hw_storage_ctrl
},
42 { "netcard", 0, NULL
, 1000 + hw_network_ctrl
},
43 { "network-ctrl", 0, NULL
, 1000 + hw_network_ctrl
},
44 { "network_ctrl", 0, NULL
, 1000 + hw_network_ctrl
},
45 { "isdn", 0, NULL
, 1000 + hw_isdn
},
46 { "modem", 0, NULL
, 1000 + hw_modem
},
47 { "network", 0, NULL
, 1000 + hw_network
},
48 { "disk", 0, NULL
, 1000 + hw_disk
},
49 { "partition", 0, NULL
, 1000 + hw_partition
},
50 { "cdrom", 0, NULL
, 1000 + hw_cdrom
},
51 { "floppy", 0, NULL
, 1000 + hw_floppy
},
52 { "update", 0, NULL
, 1000 + hw_manual
},
53 { "usb-ctrl", 0, NULL
, 1000 + hw_usb_ctrl
},
54 { "usb_ctrl", 0, NULL
, 1000 + hw_usb_ctrl
},
55 { "usb", 0, NULL
, 1000 + hw_usb
},
56 { "bios", 0, NULL
, 1000 + hw_bios
},
57 { "pci", 0, NULL
, 1000 + hw_pci
},
58 { "isapnp", 0, NULL
, 1000 + hw_isapnp
},
59 { "bridge", 0, NULL
, 1000 + hw_bridge
},
60 { "hub", 0, NULL
, 1000 + hw_hub
},
61 { "scsi", 0, NULL
, 1000 + hw_scsi
},
62 { "ide", 0, NULL
, 1000 + hw_ide
},
63 { "memory", 0, NULL
, 1000 + hw_memory
},
64 { "dvb", 0, NULL
, 1000 + hw_dvb
},
65 { "pcmcia", 0, NULL
, 1000 + hw_pcmcia
},
66 { "pcmcia_ctrl", 0, NULL
, 1000 + hw_pcmcia_ctrl
},
67 { "ieee1394", 0, NULL
, 1000 + hw_ieee1394
},
68 { "firewire", 0, NULL
, 1000 + hw_ieee1394
},
69 { "ieee1394_ctrl", 0, NULL
, 1000 + hw_ieee1394_ctrl
},
70 { "firewire_ctrl", 0, NULL
, 1000 + hw_ieee1394_ctrl
},
71 { "hotplug", 0, NULL
, 1000 + hw_hotplug
},
72 { "hotplug_ctrl", 0, NULL
, 1000 + hw_hotplug_ctrl
},
73 { "zip", 0, NULL
, 1000 + hw_zip
},
74 { "pppoe", 0, NULL
, 1000 + hw_pppoe
},
75 { "dsl", 0, NULL
, 1000 + hw_dsl
},
76 { "wlan", 0, NULL
, 1000 + hw_wlan
},
77 { "block", 0, NULL
, 1000 + hw_block
},
78 { "tape", 0, NULL
, 1000 + hw_tape
},
79 { "vbe", 0, NULL
, 1000 + hw_vbe
},
80 { "bluetooth", 0, NULL
, 1000 + hw_bluetooth
},
81 { "all", 0, NULL
, 1000 + hw_all
},
86 hd_hw_item_t scan_item
[100] = { };
87 unsigned scan_items
= 0;
94 unsigned config_cfg
:1;
95 unsigned config_avail
:1;
96 unsigned config_need
:1;
97 unsigned config_active
:1;
106 int do_scan(hd_hw_item_t
*items
);
107 int do_show(char *id
);
108 int do_list(hd_hw_item_t
*items
);
109 int do_config(int type
, char *val
, char *id
);
110 int fast_ok(hd_hw_item_t
*items
);
111 int has_item(hd_hw_item_t
*items
, hd_hw_item_t item
);
112 int has_hw_class(hd_t
*hd
, hd_hw_item_t
*items
);
115 int main(int argc
, char **argv
)
122 char *config_cfg
= NULL
;
123 char *config_avail
= NULL
;
124 char *config_need
= NULL
;
125 char *config_active
= NULL
;
132 while((i
= getopt_long(argc
, argv
, "hv", options
, NULL
)) != -1) {
139 printf("%s\n", hd_version());
158 opt
.config_avail
= 1;
159 config_avail
= optarg
;
164 config_need
= optarg
;
184 opt
.config_active
= 1;
185 config_active
= optarg
;
189 if(*optarg
) add_str_list(&opt
.only
, optarg
);
194 if(scan_items
+ 1 < sizeof scan_item
/ sizeof *scan_item
) {
195 scan_item
[scan_items
++] = i
- 1000;
205 scan_item
[scan_items
] = 0;
207 if(opt
.scan
&& !opt
.list
) {
208 if(argv
[optind
] || !scan_items
) return help(), 1;
209 rc
= do_scan(scan_item
);
211 unlink(HARDWARE_DIR
"/.update"); /* the old file */
212 unlink(HARDWARE_UNIQUE_KEYS
"/.update"); /* so we trigger a rescan */
213 if((f
= fopen(HARDWARE_UNIQUE_KEYS
"/.update", "a"))) fclose(f
);
229 if(!argv
[optind
]) return help(), 1;
230 do_config(1, config_cfg
, argv
[optind
]);
234 if(opt
.config_avail
) {
235 if(!argv
[optind
]) return help(), 1;
236 do_config(2, config_avail
, argv
[optind
]);
240 if(opt
.config_need
) {
241 if(!argv
[optind
]) return help(), 1;
242 do_config(3, config_need
, argv
[optind
]);
246 if(opt
.config_active
) {
247 if(!argv
[optind
]) return help(), 1;
248 do_config(4, config_active
, argv
[optind
]);
254 #endif /* !defined(LIBHD_TINY) */
262 "Usage: hwscan [options]\n"
263 "Show information about currently known hardware.\n"
264 " --list show list of known hardware\n"
265 " --version show libhd version\n"
266 " --silent don't show hardware config changes\n"
267 " --boot run only if we haven't been disabled via 'hwprobe=-scan'\n"
268 " --cfg=state id change 'configured' status; id is one of the\n"
269 " ids from 'hwscan --list'\n"
270 " state is one of new, no, yes\n"
271 " --avail=state id change 'available' status\n"
272 " --need=state id change 'needed' status\n"
273 " --active=state id change 'active' status\n"
274 " --hw_item probe for hw_item and update status info\n"
275 " hw_item is one of:\n"
276 " all, bios, block, bluetooth, braille, bridge, camera, cdrom, chipcard, cpu,\n"
277 " disk, dsl, dvb, floppy, framebuffer, gfxcard, hub, ide, isapnp, isdn,\n"
278 " joystick, keyboard, memory, modem, monitor, mouse, netcard, network,\n"
279 " partition, pci, pcmcia, pcmcia-ctrl, pppoe, printer, scanner, scsi, smp,\n"
280 " sound, storage-ctrl, sys, tape, tv, usb, usb-ctrl, vbe, wlan, zip\n"
286 int do_scan(hd_hw_item_t
*items
)
289 hd_status_t status
= { };
294 if(opt
.fast
) opt
.fast
= fast_ok(items
);
296 hd_data
= calloc(1, sizeof *hd_data
);
299 /* look if we have been disabled */
300 hd_clear_probe_feature(hd_data
, pr_all
);
302 hd_set_probe_feature(hd_data
, pr_scan
);
303 if(!hd_probe_feature(hd_data
, pr_scan
)) {
304 hd_free_hd_data(hd_data
);
310 hd_data
->only
= opt
.only
;
313 hd_data
->flags
.list_all
= 1;
314 hd_data
->flags
.fast
= opt
.fast
;
316 hd
= hd_list2(hd_data
, items
, 1);
318 if(hd
) found_items
= 1;
320 for(hd1
= hd
; hd1
; hd1
= hd1
->next
) {
321 err
= hd_write_config(hd_data
, hd1
);
324 "write=%d %s: (cfg=%s, avail=%s, need=%s, active=%s",
327 hd_status_value_name(hd1
->status
.configured
),
328 hd_status_value_name(hd1
->status
.available
),
329 hd_status_value_name(hd1
->status
.needed
),
330 hd_status_value_name(hd1
->status
.active
)
332 if(hd1
->unix_dev_name
) {
333 printf(", dev=%s", hd1
->unix_dev_name
);
346 "Error writing configuration for %s (%s)\n",
353 hd
= hd_free_hd_list(hd
);
356 status
.configured
= status_new
;
359 status
.reconfig
= status_yes
;
362 hd
= hd_list_with_status2(hd_data
, items
, status
);
363 if(hd
) run_config
= 1;
366 for(hd1
= hd
; hd1
; hd1
= hd1
->next
) {
368 "%s: (cfg=%s, avail=%s, need=%s, active=%s",
370 hd_status_value_name(hd1
->status
.configured
),
371 hd_status_value_name(hd1
->status
.available
),
372 hd_status_value_name(hd1
->status
.needed
),
373 hd_status_value_name(hd1
->status
.active
)
375 if(hd1
->unix_dev_name
) {
376 printf(", dev=%s", hd1
->unix_dev_name
);
384 else if(!opt
.silent
) {
385 for(hd1
= hd
; hd1
; hd1
= hd1
->next
) printf("%s\n", hd1
->unique_id
);
388 hd
= hd_free_hd_list(hd
);
390 hd_free_hd_data(hd_data
);
393 return run_config
^ 1;
397 int do_show(char *id
)
402 hd_data
= calloc(1, sizeof *hd_data
);
409 hd_manual
= hd_list(hd_data
, hw_manual
, 1, NULL
);
410 for(hd
= hd_manual
; hd
; hd
= hd
->next
) {
411 if(hd
->status
.available
!= status_yes
) continue;
412 if(!search_str_list(hd
->unix_dev_names
, id
)) continue;
417 if ( nr
== 1 ) /* > 1 means our database is not okay */
418 hd
= hd_read_config(hd_data
, _id
);
420 hd
= hd_read_config(hd_data
, id
);
424 hd_dump_entry(hd_data
, hd
, stdout
);
425 hd
= hd_free_hd_list(hd
);
428 printf("no such hardware item: %s\n", id
);
431 hd_free_hd_data(hd_data
);
438 int do_list(hd_hw_item_t
*items
)
441 hd_t
*hd
, *hd_manual
;
446 hd_data
= calloc(1, sizeof *hd_data
);
448 hd_manual
= hd_list(hd_data
, hw_manual
, 1, NULL
);
450 for(hd
= hd_manual
; hd
; hd
= hd
->next
) {
451 if(opt
.scan
&& ! has_hw_class(hd
, items
)) continue;
456 if(hd
->status
.configured
&& (s
= hd_status_value_name(hd
->status
.configured
))) {
457 sprintf(status
+ strlen(status
), "%scfg=%s", i
? ", " : "", s
);
461 if(hd
->status
.available
&& (s
= hd_status_value_name(hd
->status
.available
))) {
462 sprintf(status
+ strlen(status
), "%savail=%s", i
? ", " : "", s
);
466 if(hd
->status
.needed
&& (s
= hd_status_value_name(hd
->status
.needed
))) {
467 sprintf(status
+ strlen(status
), "%sneed=%s", i
? ", " : "", s
);
471 if(hd
->status
.active
&& (s
= hd_status_value_name(hd
->status
.active
))) {
472 sprintf(status
+ strlen(status
), "%sactive=%s", i
? ", " : "", s
);
478 s
= hd_hw_item_name(hd
->hw_class
);
481 printf("%s: %-32s %-16s %s\n", hd
->unique_id
, status
, s
, hd
->model
);
482 if(hd
->config_string
) {
483 printf(" configured as: \"%s\"\n", hd
->config_string
);
487 hd_free_hd_list(hd_manual
);
489 hd_free_hd_data(hd_data
);
496 int do_config(int type
, char *val
, char *id
)
500 hd_status_value_t status
= 0;
504 hd_data
= calloc(1, sizeof *hd_data
);
511 hd_manual
= hd_list(hd_data
, hw_manual
, 1, NULL
);
512 for(hd
= hd_manual
; hd
; hd
= hd
->next
) {
513 if(hd
->status
.available
!= status_yes
) continue;
514 if(!search_str_list(hd
->unix_dev_names
, id
)) continue;
519 hd
= hd_read_config(hd_data
, _id
);
521 hd
= hd_read_config(hd_data
, id
);
524 for(i
= 1; i
< 8; i
++) {
525 s
= hd_status_value_name(i
);
526 if(s
&& !strcmp(val
, s
)) {
532 printf("invalid status: %s\n", val
);
537 hd
->status
.configured
= status
;
541 hd
->status
.available
= status
;
545 hd
->status
.needed
= status
;
549 hd
->status
.active
= status
;
552 hd_write_config(hd_data
, hd
);
554 hd
= hd_free_hd_list(hd
);
557 printf("no such hardware item: %s\n", id
);
560 hd_free_hd_data(hd_data
);
568 * Check whether a 'fast' scan would suffice to re-check the presence
569 * of all known hardware.
571 int fast_ok(hd_hw_item_t
*items
)
577 if(!has_item(items
, hw_mouse
) && !has_item(items
, hw_storage_ctrl
)) {
581 hd_data
= calloc(1, sizeof *hd_data
);
583 hd_data
->flags
.list_all
= 1;
585 hd
= hd_list(hd_data
, hw_manual
, 1, NULL
);
587 for(hd1
= hd
; hd1
; hd1
= hd1
->next
) {
589 if(hd1
->hw_class
== hw_mouse
&& hd1
->bus
.id
== bus_serial
) {
594 if(hd1
->hw_class
== hw_storage_ctrl
&& hd1
->bus
.id
== bus_parallel
) {
600 hd_free_hd_data(hd_data
);
607 /* check if item is in items */
608 int has_item(hd_hw_item_t
*items
, hd_hw_item_t item
)
610 while(*items
) if(*items
++ == item
) return 1;
616 /* check if one of items is in hw_class */
617 int has_hw_class(hd_t
*hd
, hd_hw_item_t
*items
)
619 while(*items
) if(hd_is_hw_class(hd
, *items
++)) return 1;
625 #endif /* !defined(LIBHD_TINY) */