summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Hatch <jhatch@multitech.com>2020-12-18 12:16:50 -0600
committerJeff Hatch <jhatch@multitech.com>2020-12-18 12:16:50 -0600
commit7c0fe5b37fbc717b03754ff0f7e2349990f7e4f1 (patch)
tree3d088932174342a90e37b693d0dd71bd6a55d050
parent0dbb4ef906dad01bce313f7de51ad2253599ca97 (diff)
parentf3626b3090ceb81bb16f4a8a5f21486347b690de (diff)
downloadmts-io-sysfs-7c0fe5b37fbc717b03754ff0f7e2349990f7e4f1.tar.gz
mts-io-sysfs-7c0fe5b37fbc717b03754ff0f7e2349990f7e4f1.tar.bz2
mts-io-sysfs-7c0fe5b37fbc717b03754ff0f7e2349990f7e4f1.zip
Merge branch 'ms/MTX-3769_new_capa_tpm' into 'master'
[MTX-3769] Conduit 300: New Capability - TPM See merge request !3
-rw-r--r--include/Utility/Utility.h23
-rw-r--r--src/Device/Device.cpp5
2 files changed, 27 insertions, 1 deletions
diff --git a/include/Utility/Utility.h b/include/Utility/Utility.h
index bd6019e..8d68baa 100644
--- a/include/Utility/Utility.h
+++ b/include/Utility/Utility.h
@@ -3,6 +3,7 @@
#include "General.h"
#include "Version.h"
+#include <glob.h>
/**********************************************************************
* COPYRIGHT 2020 MULTI-TECH SYSTEMS, INC.
@@ -56,4 +57,26 @@ inline mode_t fileType(std::string file) {
}
}
+/*
+ findFileGlob() function has been added for generic file name search.
+ For example: one device has file /dev/tpm0, another one has /dev/tpm3.
+ And as a search parameter, you can specify the filepath with wildcard,
+ findFileGlob("/dev/tpm*"). The function will find the required file.
+*/
+
+inline mode_t findFileGlob(std::string file) {
+ struct stat buf = {};
+ glob_t gl;
+ mode_t result = -1;
+
+ if (0 == glob(file.c_str(), 0, NULL, &gl)) {
+ if (0 < gl.gl_pathc && 0 == stat(gl.gl_pathv[0], &buf)) {
+ result = buf.st_mode & S_IFMT;
+ }
+ globfree(&gl);
+ }
+
+ return result;
+}
+
#endif /* UTILITIES_H_ */
diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp
index b4ec3c5..23cdf8d 100644
--- a/src/Device/Device.cpp
+++ b/src/Device/Device.cpp
@@ -32,7 +32,7 @@ std::map<std::string, bool> Device::capabilityList = {{"adc", false},{"battery",
{"cell", false},{"cellWwan", false},{"din", false},{"dout", false},{"externalSerialPort", false},
{"gpio", false},{"gps", false},{"lora", false},{"loraNetworkServer", false},
{"nodeRed", false},{"rs232", false},{"rs422", false},{"rs485", false},{"serial", false},
- {"supercap", false},{"wifi", false},{"docker", false}};
+ {"supercap", false},{"wifi", false},{"docker", false},{"tpm", false}};
std::map<std::string, std::string> Device::ethSwitchList;
@@ -245,6 +245,9 @@ void Device::mapFileToCapability() {
if (fileType("/usr/bin/docker") == S_IFREG) { /* Docker is a regular file */
capabilityList["docker"] = true;
}
+ if (findFileGlob("/dev/tpm*") == S_IFCHR) { /* tpm* is a character device */
+ capabilityList["tpm"] = true;
+ }
}
void Device::mapMacAddress2() {