/src/lldpd/src/daemon/dmi-linux.c
Line | Count | Source |
1 | | /* -*- mode: c; c-file-style: "openbsd" -*- */ |
2 | | /* |
3 | | * Copyright (c) 2009 Vincent Bernat <bernat@luffy.cx> |
4 | | * |
5 | | * Permission to use, copy, modify, and/or distribute this software for any |
6 | | * purpose with or without fee is hereby granted, provided that the above |
7 | | * copyright notice and this permission notice appear in all copies. |
8 | | * |
9 | | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
10 | | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
11 | | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
12 | | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
13 | | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
14 | | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
15 | | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 | | */ |
17 | | |
18 | | #include "lldpd.h" |
19 | | #include <unistd.h> |
20 | | |
21 | | #ifdef ENABLE_LLDPMED |
22 | | /* Fill in inventory stuff: |
23 | | - hardware version: /sys/class/dmi/id/product_version |
24 | | - firmware version: /sys/class/dmi/id/bios_version |
25 | | - software version: `uname -r` |
26 | | - serial number: /sys/class/dmi/id/product_serial |
27 | | - manufacturer: /sys/class/dmi/id/sys_vendor |
28 | | - model: /sys/class/dmi/id/product_name |
29 | | - asset: /sys/class/dmi/id/chassis_asset_tag |
30 | | */ |
31 | | |
32 | | static char * |
33 | | dmi_get(const char *file) |
34 | 0 | { |
35 | 0 | int dmi, s; |
36 | 0 | char buffer[100] = {}; |
37 | |
|
38 | 0 | log_debug("localchassis", "DMI request for file %s", file); |
39 | 0 | if ((dmi = priv_open(file)) < 0) { |
40 | 0 | log_debug("localchassis", "cannot get DMI file %s", file); |
41 | 0 | return NULL; |
42 | 0 | } |
43 | 0 | if ((s = read(dmi, buffer, sizeof(buffer))) == -1) { |
44 | 0 | log_debug("localchassis", "cannot read DMI file %s", file); |
45 | 0 | close(dmi); |
46 | 0 | return NULL; |
47 | 0 | } |
48 | 0 | close(dmi); |
49 | 0 | buffer[sizeof(buffer) - 1] = '\0'; |
50 | 0 | if ((s > 0) && (buffer[s - 1] == '\n')) buffer[s - 1] = '\0'; |
51 | 0 | if (strlen(buffer)) return strdup(buffer); |
52 | 0 | return NULL; |
53 | 0 | } |
54 | | |
55 | | char * |
56 | | dmi_hw() |
57 | 0 | { |
58 | 0 | return dmi_get(SYSFS_CLASS_DMI "product_version"); |
59 | 0 | } |
60 | | |
61 | | char * |
62 | | dmi_fw() |
63 | 0 | { |
64 | 0 | return dmi_get(SYSFS_CLASS_DMI "bios_version"); |
65 | 0 | } |
66 | | |
67 | | char * |
68 | | dmi_sn() |
69 | 0 | { |
70 | 0 | return dmi_get(SYSFS_CLASS_DMI "product_serial"); |
71 | 0 | } |
72 | | |
73 | | char * |
74 | | dmi_manuf() |
75 | 0 | { |
76 | 0 | return dmi_get(SYSFS_CLASS_DMI "sys_vendor"); |
77 | 0 | } |
78 | | |
79 | | char * |
80 | | dmi_model() |
81 | 0 | { |
82 | 0 | return dmi_get(SYSFS_CLASS_DMI "product_name"); |
83 | 0 | } |
84 | | |
85 | | char * |
86 | | dmi_asset() |
87 | 0 | { |
88 | 0 | return dmi_get(SYSFS_CLASS_DMI "chassis_asset_tag"); |
89 | 0 | } |
90 | | #endif |