diff options
| author | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
| commit | 76424950e373d3b04ac3dd13019151bfba3e8423 (patch) | |
| tree | 4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/board | |
Add the files
Diffstat (limited to 'src/detection/board')
| -rw-r--r-- | src/detection/board/board.h | 13 | ||||
| -rw-r--r-- | src/detection/board/board_android.c | 9 | ||||
| -rw-r--r-- | src/detection/board/board_apple.c | 32 | ||||
| -rw-r--r-- | src/detection/board/board_bsd.c | 15 | ||||
| -rw-r--r-- | src/detection/board/board_linux.c | 26 | ||||
| -rw-r--r-- | src/detection/board/board_nbsd.c | 20 | ||||
| -rw-r--r-- | src/detection/board/board_nosupport.c | 5 | ||||
| -rw-r--r-- | src/detection/board/board_windows.c | 46 |
8 files changed, 166 insertions, 0 deletions
diff --git a/src/detection/board/board.h b/src/detection/board/board.h new file mode 100644 index 0000000..c092a7f --- /dev/null +++ b/src/detection/board/board.h @@ -0,0 +1,13 @@ +#pragma once + +#include "fastfetch.h" +#include "modules/board/option.h" + +typedef struct FFBoardResult { + FFstrbuf name; + FFstrbuf vendor; + FFstrbuf version; + FFstrbuf serial; +} FFBoardResult; + +const char* ffDetectBoard(FFBoardResult* board); diff --git a/src/detection/board/board_android.c b/src/detection/board/board_android.c new file mode 100644 index 0000000..b5978d1 --- /dev/null +++ b/src/detection/board/board_android.c @@ -0,0 +1,9 @@ +#include "board.h" +#include "common/settings.h" + +const char* ffDetectBoard(FFBoardResult* board) { + if (!ffSettingsGetAndroidProperty("ro.product.board", &board->name)) { + ffSettingsGetAndroidProperty("ro.board.platform", &board->name); + } + return NULL; +} diff --git a/src/detection/board/board_apple.c b/src/detection/board/board_apple.c new file mode 100644 index 0000000..e7c4d38 --- /dev/null +++ b/src/detection/board/board_apple.c @@ -0,0 +1,32 @@ +#include "board.h" + +#include "common/apple/cf_helpers.h" + +const char* ffDetectBoard(FFBoardResult* result) { + FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t service = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceMatching("IOPlatformExpertDevice")); + if (!service) { + return "No IOPlatformExpertDevice found"; + } + + FF_CFTYPE_AUTO_RELEASE CFTypeRef boardId = IORegistryEntryCreateCFProperty(service, CFSTR("board-id"), kCFAllocatorDefault, kNilOptions); + if (boardId) { + ffCfStrGetString(boardId, &result->name); + } else { + io_name_t name; + if (IORegistryEntryGetName(service, name) == kIOReturnSuccess) { + ffStrbufSetS(&result->name, name); + } + } + + FF_CFTYPE_AUTO_RELEASE CFStringRef version = IORegistryEntryCreateCFProperty(service, CFSTR("version"), kCFAllocatorDefault, kNilOptions); + if (version) { + ffCfStrGetString(version, &result->version); + } + + FF_CFTYPE_AUTO_RELEASE CFTypeRef manufacturer = IORegistryEntryCreateCFProperty(service, CFSTR("manufacturer"), kCFAllocatorDefault, kNilOptions); + if (manufacturer) { + ffCfStrGetString(manufacturer, &result->vendor); + } + + return NULL; +} diff --git a/src/detection/board/board_bsd.c b/src/detection/board/board_bsd.c new file mode 100644 index 0000000..2e0e417 --- /dev/null +++ b/src/detection/board/board_bsd.c @@ -0,0 +1,15 @@ +#include "board.h" +#include "common/settings.h" +#include "common/smbios.h" + +const char* ffDetectBoard(FFBoardResult* result) { + ffSettingsGetFreeBSDKenv("smbios.planar.product", &result->name); + ffCleanUpSmbiosValue(&result->name); + ffSettingsGetFreeBSDKenv("smbios.planar.serial", &result->serial); + ffCleanUpSmbiosValue(&result->serial); + ffSettingsGetFreeBSDKenv("smbios.planar.maker", &result->vendor); + ffCleanUpSmbiosValue(&result->vendor); + ffSettingsGetFreeBSDKenv("smbios.planar.version", &result->version); + ffCleanUpSmbiosValue(&result->version); + return NULL; +} diff --git a/src/detection/board/board_linux.c b/src/detection/board/board_linux.c new file mode 100644 index 0000000..52b3df2 --- /dev/null +++ b/src/detection/board/board_linux.c @@ -0,0 +1,26 @@ +#include "board.h" +#include "common/io.h" +#include "common/smbios.h" + +const char* ffDetectBoard(FFBoardResult* board) { + if (ffGetSmbiosValue("/sys/devices/virtual/dmi/id/board_name", "/sys/class/dmi/id/board_name", &board->name)) { + ffGetSmbiosValue("/sys/devices/virtual/dmi/id/board_serial", "/sys/class/dmi/id/board_serial", &board->serial); + ffGetSmbiosValue("/sys/devices/virtual/dmi/id/board_vendor", "/sys/class/dmi/id/board_vendor", &board->vendor); + ffGetSmbiosValue("/sys/devices/virtual/dmi/id/board_version", "/sys/class/dmi/id/board_version", &board->version); + } else if (ffReadFileBuffer("/sys/firmware/devicetree/base/smbios/smbios/baseboard/product", &board->name)) { + ffStrbufTrimRight(&board->name, '\0'); + if (ffReadFileBuffer("/sys/firmware/devicetree/base/smbios/smbios/baseboard/manufacturer", &board->vendor)) { + ffStrbufTrimRight(&board->vendor, '\0'); + } + } else if (ffReadFileBuffer("/sys/firmware/devicetree/base/board", &board->name)) { + ffStrbufTrimRightSpace(&board->name); + } else if (ffReadFileBuffer("/sys/firmware/devicetree/base/compatible", &board->vendor)) { + uint32_t comma = ffStrbufFirstIndexC(&board->vendor, ','); + if (comma < board->vendor.length) { + ffStrbufSetS(&board->name, board->vendor.chars + comma + 1); + ffStrbufTrimRightSpace(&board->name); + ffStrbufSubstrBefore(&board->vendor, comma); + } + } + return NULL; +} diff --git a/src/detection/board/board_nbsd.c b/src/detection/board/board_nbsd.c new file mode 100644 index 0000000..cc3ff93 --- /dev/null +++ b/src/detection/board/board_nbsd.c @@ -0,0 +1,20 @@ +#include "board.h" +#include "common/sysctl.h" +#include "common/smbios.h" + +const char* ffDetectBoard(FFBoardResult* board) { + if (ffSysctlGetString("machdep.dmi.board-product", &board->name) == NULL) { + ffCleanUpSmbiosValue(&board->name); + } + if (ffSysctlGetString("machdep.dmi.board-version", &board->version) == NULL) { + ffCleanUpSmbiosValue(&board->version); + } + if (ffSysctlGetString("machdep.dmi.board-vendor", &board->vendor) == NULL) { + ffCleanUpSmbiosValue(&board->vendor); + } + if (ffSysctlGetString("machdep.dmi.board-serial", &board->serial) == NULL) { + ffCleanUpSmbiosValue(&board->serial); + } + + return NULL; +} diff --git a/src/detection/board/board_nosupport.c b/src/detection/board/board_nosupport.c new file mode 100644 index 0000000..befc630 --- /dev/null +++ b/src/detection/board/board_nosupport.c @@ -0,0 +1,5 @@ +#include "board.h" + +const char* ffDetectBoard(FF_A_UNUSED FFBoardResult* board) { + return "Not supported on this platform"; +} diff --git a/src/detection/board/board_windows.c b/src/detection/board/board_windows.c new file mode 100644 index 0000000..079e64d --- /dev/null +++ b/src/detection/board/board_windows.c @@ -0,0 +1,46 @@ +#include "board.h" +#include "common/smbios.h" + +typedef struct FFSmbiosBaseboard { + FFSmbiosHeader Header; + + uint8_t Manufacturer; // string + uint8_t Product; // string + uint8_t Version; // string + uint8_t SerialNumber; // string + uint8_t AssetTag; // string + uint8_t FeatureFlags; // bit field + uint8_t LocationInChassis; // string + uint16_t ChassisHandle; // varies + uint8_t BoardType; // enum + uint8_t NumberOfContainedObjectHandles; // varies + uint16_t ContainedObjectHandles[]; // varies +} FF_A_PACKED FFSmbiosBaseboard; + +static_assert(offsetof(FFSmbiosBaseboard, ContainedObjectHandles) == 0x0F, + "FFSmbiosBaseboard: Wrong struct alignment"); + +const char* ffDetectBoard(FFBoardResult* board) { + const FFSmbiosHeaderTable* smbiosTable = ffGetSmbiosHeaderTable(); + if (!smbiosTable) { + return "Failed to get SMBIOS data"; + } + + const FFSmbiosBaseboard* data = (const FFSmbiosBaseboard*) (*smbiosTable)[FF_SMBIOS_TYPE_BASEBOARD_INFO]; + if (!data) { + return "Baseboard information section is not found in SMBIOS data"; + } + + const char* strings = (const char*) data + data->Header.Length; + + ffStrbufSetStatic(&board->name, ffSmbiosLocateString(strings, data->Product)); + ffCleanUpSmbiosValue(&board->name); + ffStrbufSetStatic(&board->serial, ffSmbiosLocateString(strings, data->SerialNumber)); + ffCleanUpSmbiosValue(&board->serial); + ffStrbufSetStatic(&board->vendor, ffSmbiosLocateString(strings, data->Manufacturer)); + ffCleanUpSmbiosValue(&board->vendor); + ffStrbufSetStatic(&board->version, ffSmbiosLocateString(strings, data->Version)); + ffCleanUpSmbiosValue(&board->version); + + return NULL; +} |