summaryrefslogtreecommitdiffstats
path: root/src/hardware
diff options
context:
space:
mode:
authorPeter Schiffer <pschiffe@redhat.com>2013-06-05 17:49:08 +0200
committerPeter Schiffer <pschiffe@redhat.com>2013-06-06 13:40:05 +0200
commit91e01015001072515ba308e347b8997af36d8953 (patch)
tree4d57a83c75b6200181b1eec06f624d432e1f393c /src/hardware
parent730113b3e9e7eefa05b3094fb55a550fead5d2f7 (diff)
downloadopenlmi-providers-91e01015001072515ba308e347b8997af36d8953.tar.gz
openlmi-providers-91e01015001072515ba308e347b8997af36d8953.tar.xz
openlmi-providers-91e01015001072515ba308e347b8997af36d8953.zip
Hardware: Added chassis ports provider
New providers: * LMI_PortPhysicalConnectorProvider * LMI_PortPhysicalConnectorContainerProvider
Diffstat (limited to 'src/hardware')
-rw-r--r--src/hardware/LMI_Hardware.h1
-rw-r--r--src/hardware/LMI_PortPhysicalConnectorContainerProvider.c270
-rw-r--r--src/hardware/LMI_PortPhysicalConnectorProvider.c270
-rw-r--r--src/hardware/dmidecode.c165
-rw-r--r--src/hardware/dmidecode.h23
5 files changed, 729 insertions, 0 deletions
diff --git a/src/hardware/LMI_Hardware.h b/src/hardware/LMI_Hardware.h
index 2d09c00..bb070f3 100644
--- a/src/hardware/LMI_Hardware.h
+++ b/src/hardware/LMI_Hardware.h
@@ -34,5 +34,6 @@
#define BASEBOARD_CLASS_NAME "Baseboard"
#define MEMORY_SLOT_CLASS_NAME "MemorySlot"
#define MEMORY_PHYS_PKG_CLASS_NAME "MemoryPhysicalPackage"
+#define PORT_PHYS_CONN_CLASS_NAME "PortPhysicalConnector"
#endif /* LMI_HARDWARE_H_ */
diff --git a/src/hardware/LMI_PortPhysicalConnectorContainerProvider.c b/src/hardware/LMI_PortPhysicalConnectorContainerProvider.c
new file mode 100644
index 0000000..85fb16d
--- /dev/null
+++ b/src/hardware/LMI_PortPhysicalConnectorContainerProvider.c
@@ -0,0 +1,270 @@
+/*
+ * Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Peter Schiffer <pschiffe@redhat.com>
+ */
+
+#include <konkret/konkret.h>
+#include "LMI_PortPhysicalConnectorContainer.h"
+#include "LMI_Hardware.h"
+#include "globals.h"
+#include "dmidecode.h"
+
+static const CMPIBroker* _cb;
+
+static void LMI_PortPhysicalConnectorContainerInitialize()
+{
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorContainerCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorContainerEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ return KDefaultEnumerateInstanceNames(
+ _cb, mi, cc, cr, cop);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorContainerEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ LMI_PortPhysicalConnectorContainer lmi_port_container;
+ LMI_PortPhysicalConnectorRef lmi_port;
+ LMI_ChassisRef lmi_chassis;
+ const char *ns = KNameSpace(cop);
+ unsigned i;
+ DmiChassis dmi_chassis;
+ DmiPort *dmi_ports = NULL;
+ unsigned dmi_ports_nb = 0;
+
+ if (dmi_get_chassis(&dmi_chassis) != 0) {
+ goto done;
+ }
+ if (dmi_get_ports(&dmi_ports, &dmi_ports_nb) != 0 || dmi_ports_nb < 1) {
+ goto done;
+ }
+
+ 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);
+ }
+
+ for (i = 0; i < dmi_ports_nb; i++) {
+ LMI_PortPhysicalConnectorContainer_Init(&lmi_port_container, _cb, ns);
+
+ LMI_PortPhysicalConnectorRef_Init(&lmi_port, _cb, ns);
+ LMI_PortPhysicalConnectorRef_Set_CreationClassName(&lmi_port,
+ ORGID "_" PORT_PHYS_CONN_CLASS_NAME);
+ LMI_PortPhysicalConnectorRef_Set_Tag(&lmi_port, dmi_ports[i].name);
+
+ LMI_PortPhysicalConnectorContainer_Set_GroupComponent(
+ &lmi_port_container, &lmi_chassis);
+ LMI_PortPhysicalConnectorContainer_Set_PartComponent(
+ &lmi_port_container, &lmi_port);
+
+ KReturnInstance(cr, lmi_port_container);
+ }
+
+done:
+ dmi_free_chassis(&dmi_chassis);
+ dmi_free_ports(&dmi_ports, &dmi_ports_nb);
+
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorContainerGetInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ return KDefaultGetInstance(
+ _cb, mi, cc, cr, cop, properties);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorContainerCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorContainerModifyInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci,
+ const char**properties)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorContainerDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorContainerExecQuery(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* lang,
+ const char* query)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorContainerAssociationCleanup(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorContainerAssociators(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* resultClass,
+ const char* role,
+ const char* resultRole,
+ const char** properties)
+{
+ return KDefaultAssociators(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ LMI_PortPhysicalConnectorContainer_ClassName,
+ assocClass,
+ resultClass,
+ role,
+ resultRole,
+ properties);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorContainerAssociatorNames(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* resultClass,
+ const char* role,
+ const char* resultRole)
+{
+ return KDefaultAssociatorNames(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ LMI_PortPhysicalConnectorContainer_ClassName,
+ assocClass,
+ resultClass,
+ role,
+ resultRole);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorContainerReferences(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* role,
+ const char** properties)
+{
+ return KDefaultReferences(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ LMI_PortPhysicalConnectorContainer_ClassName,
+ assocClass,
+ role,
+ properties);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorContainerReferenceNames(
+ CMPIAssociationMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* assocClass,
+ const char* role)
+{
+ return KDefaultReferenceNames(
+ _cb,
+ mi,
+ cc,
+ cr,
+ cop,
+ LMI_PortPhysicalConnectorContainer_ClassName,
+ assocClass,
+ role);
+}
+
+CMInstanceMIStub(
+ LMI_PortPhysicalConnectorContainer,
+ LMI_PortPhysicalConnectorContainer,
+ _cb,
+ LMI_PortPhysicalConnectorContainerInitialize())
+
+CMAssociationMIStub(
+ LMI_PortPhysicalConnectorContainer,
+ LMI_PortPhysicalConnectorContainer,
+ _cb,
+ LMI_PortPhysicalConnectorContainerInitialize())
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "LMI_PortPhysicalConnectorContainer",
+ "LMI_PortPhysicalConnectorContainer",
+ "instance association")
diff --git a/src/hardware/LMI_PortPhysicalConnectorProvider.c b/src/hardware/LMI_PortPhysicalConnectorProvider.c
new file mode 100644
index 0000000..4027928
--- /dev/null
+++ b/src/hardware/LMI_PortPhysicalConnectorProvider.c
@@ -0,0 +1,270 @@
+/*
+ * Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Peter Schiffer <pschiffe@redhat.com>
+ */
+
+#include <konkret/konkret.h>
+#include "LMI_PortPhysicalConnector.h"
+#include "LMI_Hardware.h"
+#include "globals.h"
+#include "dmidecode.h"
+
+CMPIUint16 get_connectorlayout(const char *dmi_val);
+
+static const CMPIBroker* _cb = NULL;
+
+static void LMI_PortPhysicalConnectorInitialize()
+{
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ return KDefaultEnumerateInstanceNames(
+ _cb, mi, cc, cr, cop);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ LMI_PortPhysicalConnector lmi_port;
+ const char *ns = KNameSpace(cop);
+ CMPIUint16 conn_layout;
+ char instance_id[INSTANCE_ID_LEN];
+ unsigned i;
+ DmiPort *dmi_ports = NULL;
+ unsigned dmi_ports_nb = 0;
+
+ if (dmi_get_ports(&dmi_ports, &dmi_ports_nb) != 0 || dmi_ports_nb < 1) {
+ goto done;
+ }
+
+ for (i = 0; i < dmi_ports_nb; i++) {
+ LMI_PortPhysicalConnector_Init(&lmi_port, _cb, ns);
+
+ LMI_PortPhysicalConnector_Set_CreationClassName(&lmi_port,
+ ORGID "_" PORT_PHYS_CONN_CLASS_NAME);
+ LMI_PortPhysicalConnector_Set_Caption(&lmi_port, "Physical Port");
+ LMI_PortPhysicalConnector_Set_Description(&lmi_port,
+ "This object represents one physical port on the chassis.");
+
+ snprintf(instance_id, INSTANCE_ID_LEN,
+ ORGID ":" ORGID "_" PORT_PHYS_CONN_CLASS_NAME ":%s",
+ dmi_ports[i].name);
+ conn_layout = get_connectorlayout(dmi_ports[i].type);
+
+ LMI_PortPhysicalConnector_Set_Tag(&lmi_port, dmi_ports[i].name);
+ LMI_PortPhysicalConnector_Set_ConnectorLayout(&lmi_port, conn_layout);
+ LMI_PortPhysicalConnector_Set_ElementName(&lmi_port, dmi_ports[i].name);
+ LMI_PortPhysicalConnector_Set_Name(&lmi_port, dmi_ports[i].name);
+ LMI_PortPhysicalConnector_Set_InstanceID(&lmi_port, instance_id);
+
+ if (conn_layout == LMI_PortPhysicalConnector_ConnectorLayout_Other) {
+ if (strcmp(dmi_ports[i].type, "Other") != 0) {
+ LMI_PortPhysicalConnector_Set_ConnectorDescription(&lmi_port,
+ dmi_ports[i].type);
+ } else if (strcmp(dmi_ports[i].port_type, "Other") != 0) {
+ LMI_PortPhysicalConnector_Set_ConnectorDescription(&lmi_port,
+ dmi_ports[i].port_type);
+ } else {
+ LMI_PortPhysicalConnector_Set_ConnectorDescription(&lmi_port,
+ dmi_ports[i].name);
+ }
+ }
+ if (strstr(dmi_ports[i].type, "male") &&
+ !strstr(dmi_ports[i].type, "female")) {
+ LMI_PortPhysicalConnector_Set_ConnectorGender(&lmi_port,
+ LMI_PortPhysicalConnector_ConnectorGender_Male);
+ } else {
+ LMI_PortPhysicalConnector_Set_ConnectorGender(&lmi_port,
+ LMI_PortPhysicalConnector_ConnectorGender_Female);
+ }
+
+ KReturnInstance(cr, lmi_port);
+ }
+
+done:
+ dmi_free_ports(&dmi_ports, &dmi_ports_nb);
+
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorGetInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ return KDefaultGetInstance(
+ _cb, mi, cc, cr, cop, properties);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorModifyInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci,
+ const char** properties)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorExecQuery(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* lang,
+ const char* query)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+CMInstanceMIStub(
+ LMI_PortPhysicalConnector,
+ LMI_PortPhysicalConnector,
+ _cb,
+ LMI_PortPhysicalConnectorInitialize())
+
+static CMPIStatus LMI_PortPhysicalConnectorMethodCleanup(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_PortPhysicalConnectorInvokeMethod(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* meth,
+ const CMPIArgs* in,
+ CMPIArgs* out)
+{
+ return LMI_PortPhysicalConnector_DispatchMethod(
+ _cb, mi, cc, cr, cop, meth, in, out);
+}
+
+/*
+ * Get connector layout according to the dmidecode.
+ * @param dmi_val from dmidecode
+ * @return CIM id of connector layout
+ */
+CMPIUint16 get_connectorlayout(const char *dmi_val)
+{
+ if (!dmi_val || !strlen(dmi_val)) {
+ return 0; /* Unknown */
+ }
+
+ static struct {
+ CMPIUint16 cim_val; /* CIM value */
+ char *dmi_val; /* dmidecode value */
+ } values[] = {
+ {0, "Unknown"},
+ {1, "Other"},
+ /*
+ {2, "RS232"},
+ */
+ {3, "BNC"},
+ {4, "RJ-11"},
+ {5, "RJ-45"},
+ {6, "DB-9 male"},
+ {6, "DB-9 female"},
+ /*
+ {7, "Slot"},
+ {8, "SCSI High Density"},
+ {9, "SCSI Low Density"},
+ {10, "Ribbon"},
+ {11, "AUI"},
+ {12, "Fiber SC"},
+ {13, "Fiber ST"},
+ {14, "FDDI-MIC"},
+ {15, "Fiber-RTMJ"},
+ {16, "PCI"},
+ {17, "PCI-X"},
+ {18, "PCI-E"},
+ {19, "PCI-E x1"},
+ {20, "PCI-E x2"},
+ {21, "PCI-E x4"},
+ {22, "PCI-E x8"},
+ {23, "PCI-E x16"},
+ {24, "PCI-E x32"},
+ {25, "PCI-E x64"},
+ */
+ };
+
+ size_t i, val_length = sizeof(values) / sizeof(values[0]);
+
+ for (i = 0; i < val_length; i++) {
+ if (strcmp(dmi_val, values[i].dmi_val) == 0) {
+ return values[i].cim_val;
+ }
+ }
+
+ return 1; /* Other */
+}
+
+CMMethodMIStub(
+ LMI_PortPhysicalConnector,
+ LMI_PortPhysicalConnector,
+ _cb,
+ LMI_PortPhysicalConnectorInitialize())
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "LMI_PortPhysicalConnector",
+ "LMI_PortPhysicalConnector",
+ "instance method")
diff --git a/src/hardware/dmidecode.c b/src/hardware/dmidecode.c
index 4023cf3..cbee376 100644
--- a/src/hardware/dmidecode.c
+++ b/src/hardware/dmidecode.c
@@ -1484,3 +1484,168 @@ void dmi_free_baseboard(DmiBaseboard *baseboard)
free(baseboard->version);
baseboard->version = NULL;
}
+
+
+/******************************************************************************
+ * DmiPorts
+ */
+
+/*
+ * Initialize DmiPort attributes.
+ * @param port
+ */
+void init_dmiports_struct(DmiPort *port)
+{
+ port->name = NULL;
+ port->type = NULL;
+ port->port_type = NULL;
+}
+
+/*
+ * Check attributes of port structure and fill in defaults if needed.
+ * @param port
+ * @return 0 if success, negative value otherwise
+ */
+short check_dmiport_attributes(DmiPort *port)
+{
+ short ret = -1;
+
+ if (!port->name) {
+ if (!(port->name = strdup("Port"))) {
+ ret = -2;
+ goto done;
+ }
+ }
+ if (!port->type) {
+ if (!(port->type = strdup("Unknown"))) {
+ ret = -3;
+ goto done;
+ }
+ }
+ if (!port->port_type) {
+ if (!(port->port_type = strdup("Unknown"))) {
+ ret = -4;
+ goto done;
+ }
+ }
+
+ ret = 0;
+
+done:
+ if (ret != 0) {
+ warn("Failed to allocate memory.");
+ }
+
+ return ret;
+}
+
+short dmi_get_ports(DmiPort **ports, unsigned *ports_nb)
+{
+ short ret = -1;
+ int curr_port = -1;
+ unsigned i, buffer_size = 0;
+ char **buffer = NULL, *buf;
+
+ *ports_nb = 0;
+
+ /* get dmidecode output */
+ if (run_command("dmidecode -t 8", &buffer, &buffer_size) != 0) {
+ ret = -2;
+ goto done;
+ }
+
+ /* count ports */
+ for (i = 0; i < buffer_size; i++) {
+ if (strncmp(buffer[i], "Handle 0x", 9) == 0) {
+ (*ports_nb)++;
+ }
+ }
+
+ /* if no port was found */
+ if (*ports_nb < 1) {
+ warn("Dmidecode didn't recognize any port.");
+ ret = -3;
+ goto done;
+ }
+
+ /* allocate memory for ports */
+ *ports = (DmiPort *)calloc(*ports_nb, sizeof(DmiPort));
+ if (!(*ports)) {
+ warn("Failed to allocate memory.");
+ ret = -4;
+ goto done;
+ }
+
+ /* parse information about ports */
+ for (i = 0; i < buffer_size; i++) {
+ if (strncmp(buffer[i], "Handle 0x", 9) == 0) {
+ curr_port++;
+ init_dmiports_struct(&(*ports)[curr_port]);
+ continue;
+ }
+ /* ignore first useless lines */
+ if (curr_port < 0) {
+ continue;
+ }
+ /* Name */
+ buf = copy_string_part_after_delim(buffer[i], "External Reference Designator: ");
+ if (buf) {
+ (*ports)[curr_port].name = buf;
+ buf = NULL;
+ continue;
+ }
+ /* Type */
+ buf = copy_string_part_after_delim(buffer[i], "External Connector Type: ");
+ if (buf) {
+ (*ports)[curr_port].type = buf;
+ buf = NULL;
+ continue;
+ }
+ /* Port Type */
+ buf = copy_string_part_after_delim(buffer[i], "Port Type: ");
+ if (buf) {
+ (*ports)[curr_port].port_type = buf;
+ buf = NULL;
+ continue;
+ }
+ }
+
+ /* fill in default attributes if needed */
+ for (i = 0; i < *ports_nb; i++) {
+ if (check_dmiport_attributes(&(*ports)[i]) != 0) {
+ ret = -5;
+ goto done;
+ }
+ }
+
+ ret = 0;
+
+done:
+ free_2d_buffer(&buffer, &buffer_size);
+
+ if (ret != 0) {
+ dmi_free_ports(ports, ports_nb);
+ }
+
+ return ret;
+}
+
+void dmi_free_ports(DmiPort **ports, unsigned *ports_nb)
+{
+ unsigned i;
+
+ if (*ports_nb > 0) {
+ for (i = 0; i < *ports_nb; i++) {
+ free((*ports)[i].name);
+ (*ports)[i].name = NULL;
+ free((*ports)[i].type);
+ (*ports)[i].type = NULL;
+ free((*ports)[i].port_type);
+ (*ports)[i].port_type = NULL;
+ }
+ free(*ports);
+ }
+
+ *ports_nb = 0;
+ *ports = NULL;
+}
diff --git a/src/hardware/dmidecode.h b/src/hardware/dmidecode.h
index d3f8bd4..5423c93 100644
--- a/src/hardware/dmidecode.h
+++ b/src/hardware/dmidecode.h
@@ -118,6 +118,13 @@ typedef struct _DmiBaseboard {
char *version; /* Version */
} DmiBaseboard;
+/* Baseboard Port from dmidecode. */
+typedef struct _DmiPort {
+ char *name; /* Name */
+ char *type; /* Type */
+ char *port_type; /* Port Type */
+} DmiPort;
+
/*
* Get array of processors according to the dmidecode program.
* @param cpu array of cpus, this function will allocate necessary memory,
@@ -192,5 +199,21 @@ short dmi_get_baseboard(DmiBaseboard *baseboard);
*/
void dmi_free_baseboard(DmiBaseboard *baseboard);
+/*
+ * Get array of baseboard ports according to the dmidecode program.
+ * @param ports array of ports, this function will allocate necessary memory,
+ * but caller is responsible for freeing it
+ * @param ports_nb number of ports
+ * @return 0 if success, negative value otherwise
+ */
+short dmi_get_ports(DmiPort **ports, unsigned *ports_nb);
+
+/*
+ * Free array of port structures.
+ * @param ports array of ports
+ * @param ports_nb number of ports
+ */
+void dmi_free_ports(DmiPort **ports, unsigned *ports_nb);
+
#endif /* DMIDECODE_H_ */