diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hardware/LMI_BaseboardContainerProvider.c | 6 | ||||
-rw-r--r-- | src/hardware/LMI_ChassisComputerSystemPackageProvider.c | 6 | ||||
-rw-r--r-- | src/hardware/LMI_ChassisProvider.c | 23 | ||||
-rw-r--r-- | src/hardware/LMI_PhysicalBatteryContainerProvider.c | 6 | ||||
-rw-r--r-- | src/hardware/LMI_PortPhysicalConnectorContainerProvider.c | 6 | ||||
-rw-r--r-- | src/hardware/LMI_ProcessorChipContainerProvider.c | 6 | ||||
-rw-r--r-- | src/hardware/LMI_SystemSlotContainerProvider.c | 6 | ||||
-rw-r--r-- | src/hardware/dmidecode.c | 90 | ||||
-rw-r--r-- | src/hardware/dmidecode.h | 12 |
9 files changed, 119 insertions, 42 deletions
diff --git a/src/hardware/LMI_BaseboardContainerProvider.c b/src/hardware/LMI_BaseboardContainerProvider.c index 15e58a5..22dee90 100644 --- a/src/hardware/LMI_BaseboardContainerProvider.c +++ b/src/hardware/LMI_BaseboardContainerProvider.c @@ -73,11 +73,7 @@ static CMPIStatus LMI_BaseboardContainerEnumInstances( LMI_ChassisRef_Init(&lmi_chassis, _cb, ns); LMI_ChassisRef_Set_CreationClassName(&lmi_chassis, ORGID "_" CHASSIS_CLASS_NAME); - if (strcmp(dmi_chassis.serial_number, "Not Specified") == 0) { - LMI_ChassisRef_Set_Tag(&lmi_chassis, "0"); - } else { - LMI_ChassisRef_Set_Tag(&lmi_chassis, dmi_chassis.serial_number); - } + LMI_ChassisRef_Set_Tag(&lmi_chassis, dmi_get_chassis_tag(&dmi_chassis)); LMI_BaseboardRef_Init(&lmi_baseboard, _cb, ns); LMI_BaseboardRef_Set_CreationClassName(&lmi_baseboard, diff --git a/src/hardware/LMI_ChassisComputerSystemPackageProvider.c b/src/hardware/LMI_ChassisComputerSystemPackageProvider.c index d0fc004..2f8e082 100644 --- a/src/hardware/LMI_ChassisComputerSystemPackageProvider.c +++ b/src/hardware/LMI_ChassisComputerSystemPackageProvider.c @@ -79,11 +79,7 @@ static CMPIStatus LMI_ChassisComputerSystemPackageEnumInstances( LMI_ChassisRef_Init(&lmi_chassis, _cb, ns); LMI_ChassisRef_Set_CreationClassName(&lmi_chassis, ORGID "_" CHASSIS_CLASS_NAME); - if (strcmp(dmi_chassis.serial_number, "Not Specified") == 0) { - LMI_ChassisRef_Set_Tag(&lmi_chassis, "0"); - } else { - LMI_ChassisRef_Set_Tag(&lmi_chassis, dmi_chassis.serial_number); - } + LMI_ChassisRef_Set_Tag(&lmi_chassis, dmi_get_chassis_tag(&dmi_chassis)); LMI_ChassisComputerSystemPackage_SetObjectPath_Dependent( &lmi_chassis_cs_pkg, o); diff --git a/src/hardware/LMI_ChassisProvider.c b/src/hardware/LMI_ChassisProvider.c index 2ef7342..3214d58 100644 --- a/src/hardware/LMI_ChassisProvider.c +++ b/src/hardware/LMI_ChassisProvider.c @@ -59,7 +59,7 @@ static CMPIStatus LMI_ChassisEnumInstances( { LMI_Chassis lmi_chassis; const char *ns = KNameSpace(cop); - char instance_id[INSTANCE_ID_LEN]; + char instance_id[INSTANCE_ID_LEN], *tag; DmiChassis dmi_chassis; if (dmi_get_chassis(&dmi_chassis) != 0) { @@ -76,17 +76,13 @@ static CMPIStatus LMI_ChassisEnumInstances( LMI_Chassis_Set_Description(&lmi_chassis, "This object represents physical chassis of the system."); - if (strcmp(dmi_chassis.serial_number, "Not Specified") == 0) { - LMI_Chassis_Set_Tag(&lmi_chassis, "0"); - LMI_Chassis_Set_InstanceID(&lmi_chassis, - ORGID ":" ORGID "_" CHASSIS_CLASS_NAME ":0"); - } else { - LMI_Chassis_Set_Tag(&lmi_chassis, dmi_chassis.serial_number); - snprintf(instance_id, INSTANCE_ID_LEN, - ORGID ":" ORGID "_" CHASSIS_CLASS_NAME ":%s", - dmi_chassis.serial_number); - LMI_Chassis_Set_InstanceID(&lmi_chassis, instance_id); - } + tag = dmi_get_chassis_tag(&dmi_chassis); + snprintf(instance_id, INSTANCE_ID_LEN, + ORGID ":" ORGID "_" CHASSIS_CLASS_NAME ":%s", tag); + + LMI_Chassis_Set_Tag(&lmi_chassis, tag); + LMI_Chassis_Set_InstanceID(&lmi_chassis, instance_id); + if (strcmp(dmi_chassis.type, "Unknown") == 0 || strcmp(dmi_chassis.type, "Other") == 0) { LMI_Chassis_Set_Name(&lmi_chassis, "System Chassis"); @@ -102,6 +98,9 @@ static CMPIStatus LMI_ChassisEnumInstances( LMI_Chassis_Set_SKU(&lmi_chassis, dmi_chassis.sku_number); LMI_Chassis_Set_Version(&lmi_chassis, dmi_chassis.version); LMI_Chassis_Set_LockPresent(&lmi_chassis, dmi_chassis.has_lock); + LMI_Chassis_Set_Model(&lmi_chassis, dmi_chassis.model); + LMI_Chassis_Set_ProductName(&lmi_chassis, dmi_chassis.product_name); + LMI_Chassis_Set_UUID(&lmi_chassis, dmi_chassis.uuid); if (dmi_chassis.power_cords) { LMI_Chassis_Set_NumberOfPowerCords(&lmi_chassis, dmi_chassis.power_cords); diff --git a/src/hardware/LMI_PhysicalBatteryContainerProvider.c b/src/hardware/LMI_PhysicalBatteryContainerProvider.c index 46bcad4..890cd93 100644 --- a/src/hardware/LMI_PhysicalBatteryContainerProvider.c +++ b/src/hardware/LMI_PhysicalBatteryContainerProvider.c @@ -74,11 +74,7 @@ static CMPIStatus LMI_PhysicalBatteryContainerEnumInstances( LMI_ChassisRef_Init(&lmi_chassis, _cb, ns); LMI_ChassisRef_Set_CreationClassName(&lmi_chassis, ORGID "_" CHASSIS_CLASS_NAME); - if (strcmp(dmi_chassis.serial_number, "Not Specified") == 0) { - LMI_ChassisRef_Set_Tag(&lmi_chassis, "0"); - } else { - LMI_ChassisRef_Set_Tag(&lmi_chassis, dmi_chassis.serial_number); - } + LMI_ChassisRef_Set_Tag(&lmi_chassis, dmi_get_chassis_tag(&dmi_chassis)); for (i = 0; i < dmi_batt_nb; i++) { LMI_PhysicalBatteryContainer_Init(&lmi_batt_container, _cb, ns); diff --git a/src/hardware/LMI_PortPhysicalConnectorContainerProvider.c b/src/hardware/LMI_PortPhysicalConnectorContainerProvider.c index 85fb16d..d54f678 100644 --- a/src/hardware/LMI_PortPhysicalConnectorContainerProvider.c +++ b/src/hardware/LMI_PortPhysicalConnectorContainerProvider.c @@ -74,11 +74,7 @@ static CMPIStatus LMI_PortPhysicalConnectorContainerEnumInstances( LMI_ChassisRef_Init(&lmi_chassis, _cb, ns); LMI_ChassisRef_Set_CreationClassName(&lmi_chassis, ORGID "_" CHASSIS_CLASS_NAME); - if (strcmp(dmi_chassis.serial_number, "Not Specified") == 0) { - LMI_ChassisRef_Set_Tag(&lmi_chassis, "0"); - } else { - LMI_ChassisRef_Set_Tag(&lmi_chassis, dmi_chassis.serial_number); - } + LMI_ChassisRef_Set_Tag(&lmi_chassis, dmi_get_chassis_tag(&dmi_chassis)); for (i = 0; i < dmi_ports_nb; i++) { LMI_PortPhysicalConnectorContainer_Init(&lmi_port_container, _cb, ns); diff --git a/src/hardware/LMI_ProcessorChipContainerProvider.c b/src/hardware/LMI_ProcessorChipContainerProvider.c index 49a9bae..b300121 100644 --- a/src/hardware/LMI_ProcessorChipContainerProvider.c +++ b/src/hardware/LMI_ProcessorChipContainerProvider.c @@ -74,11 +74,7 @@ static CMPIStatus LMI_ProcessorChipContainerEnumInstances( LMI_ChassisRef_Init(&lmi_chassis, _cb, ns); LMI_ChassisRef_Set_CreationClassName(&lmi_chassis, ORGID "_" CHASSIS_CLASS_NAME); - if (strcmp(dmi_chassis.serial_number, "Not Specified") == 0) { - LMI_ChassisRef_Set_Tag(&lmi_chassis, "0"); - } else { - LMI_ChassisRef_Set_Tag(&lmi_chassis, dmi_chassis.serial_number); - } + LMI_ChassisRef_Set_Tag(&lmi_chassis, dmi_get_chassis_tag(&dmi_chassis)); for (i = 0; i < dmi_cpus_nb; i++) { LMI_ProcessorChipContainer_Init(&lmi_cpu_chip_container, _cb, ns); diff --git a/src/hardware/LMI_SystemSlotContainerProvider.c b/src/hardware/LMI_SystemSlotContainerProvider.c index c752fbe..7a25254 100644 --- a/src/hardware/LMI_SystemSlotContainerProvider.c +++ b/src/hardware/LMI_SystemSlotContainerProvider.c @@ -74,11 +74,7 @@ static CMPIStatus LMI_SystemSlotContainerEnumInstances( LMI_ChassisRef_Init(&lmi_chassis, _cb, ns); LMI_ChassisRef_Set_CreationClassName(&lmi_chassis, ORGID "_" CHASSIS_CLASS_NAME); - if (strcmp(dmi_chassis.serial_number, "Not Specified") == 0) { - LMI_ChassisRef_Set_Tag(&lmi_chassis, "0"); - } else { - LMI_ChassisRef_Set_Tag(&lmi_chassis, dmi_chassis.serial_number); - } + LMI_ChassisRef_Set_Tag(&lmi_chassis, dmi_get_chassis_tag(&dmi_chassis)); for (i = 0; i < dmi_slots_nb; i++) { LMI_SystemSlotContainer_Init(&lmi_slot_container, _cb, ns); diff --git a/src/hardware/dmidecode.c b/src/hardware/dmidecode.c index a171707..a4c1050 100644 --- a/src/hardware/dmidecode.c +++ b/src/hardware/dmidecode.c @@ -1177,6 +1177,10 @@ void init_dmi_chassis_struct(DmiChassis *chassis) chassis->version = NULL; chassis->has_lock = 0; chassis->power_cords = 0; + chassis->asset_tag = NULL; + chassis->model = NULL; + chassis->product_name = NULL; + chassis->uuid = NULL; } /* @@ -1218,6 +1222,30 @@ short check_dmi_chassis_attributes(DmiChassis *chassis) goto done; } } + if (!chassis->asset_tag) { + if (!(chassis->asset_tag = strdup(""))) { + ret = -7; + goto done; + } + } + if (!chassis->model) { + if (!(chassis->model = strdup(""))) { + ret = -8; + goto done; + } + } + if (!chassis->product_name) { + if (!(chassis->product_name = strdup(""))) { + ret = -9; + goto done; + } + } + if (!chassis->uuid) { + if (!(chassis->uuid = strdup(""))) { + ret = -10; + goto done; + } + } ret = 0; @@ -1259,6 +1287,13 @@ short dmi_get_chassis(DmiChassis *chassis) buf = NULL; continue; } + /* Asset Tag */ + buf = copy_string_part_after_delim(buffer[i], "Asset Tag: "); + if (buf) { + chassis->asset_tag = buf; + buf = NULL; + continue; + } /* Type */ buf = copy_string_part_after_delim(buffer[i], "Type: "); if (buf) { @@ -1309,6 +1344,36 @@ short dmi_get_chassis(DmiChassis *chassis) } } + free_2d_buffer(&buffer, &buffer_size); + + /* get additional dmidecode output for chassis */ + if (run_command("dmidecode -t 1", &buffer, &buffer_size) == 0 + && buffer_size > 4) { + for (i = 0; i < buffer_size; i++) { + /* Model */ + buf = copy_string_part_after_delim(buffer[i], "Version: "); + if (buf) { + chassis->model = buf; + buf = NULL; + continue; + } + /* Product Name */ + buf = copy_string_part_after_delim(buffer[i], "Product Name: "); + if (buf) { + chassis->product_name = buf; + buf = NULL; + continue; + } + /* UUID */ + buf = copy_string_part_after_delim(buffer[i], "UUID: "); + if (buf) { + chassis->uuid = buf; + buf = NULL; + continue; + } + } + } + /* fill in default attributes if needed */ if (check_dmi_chassis_attributes(chassis) != 0) { ret = -4; @@ -1339,6 +1404,31 @@ void dmi_free_chassis(DmiChassis *chassis) chassis->sku_number = NULL; free(chassis->version); chassis->version = NULL; + free(chassis->asset_tag); + chassis->asset_tag = NULL; + free(chassis->model); + chassis->model = NULL; + free(chassis->product_name); + chassis->product_name = NULL; + free(chassis->uuid); + chassis->uuid = NULL; +} + +char *dmi_get_chassis_tag(DmiChassis *chassis) +{ + char *ret; + + if (strlen(chassis->asset_tag) > 0 + && strcmp(chassis->asset_tag, "Not Specified") != 0) { + ret = chassis->asset_tag; + } else if (strlen(chassis->serial_number) > 0 + && strcmp(chassis->serial_number, "Not Specified") != 0) { + ret = chassis->serial_number; + } else { + ret = "0"; + } + + return ret; } diff --git a/src/hardware/dmidecode.h b/src/hardware/dmidecode.h index a29d90d..d139f38 100644 --- a/src/hardware/dmidecode.h +++ b/src/hardware/dmidecode.h @@ -108,6 +108,10 @@ typedef struct _DmiChassis { char *version; /* Chassis Version */ short has_lock; /* Has chassis lock? 0 or 1 */ unsigned power_cords; /* Number of Power Cords */ + char *asset_tag; /* Asset Tag */ + char *model; /* Model (Version field in dmidecode) */ + char *product_name; /* Product Name */ + char *uuid; /* UUID */ } DmiChassis; /* Baseboard from dmidecode. */ @@ -215,6 +219,14 @@ short dmi_get_chassis(DmiChassis *chassis); void dmi_free_chassis(DmiChassis *chassis); /* + * Get best available chassis tag from given chassis. Return value should not + * be freed. + * @param chassis + * @return tag + */ +char *dmi_get_chassis_tag(DmiChassis *chassis); + +/* * Get baseboard structure according to the dmidecode program. * @param baseboard structure, this function will allocate * necessary memory, but caller is responsible for freeing it |