Compare commits

...
Author SHA1 Message Date
Adam Honse af2355f4c9 Add XPG Spectrix S20G to detectors for S40G 2024-05-11 17:53:27 -05:00
2 changed files with 85 additions and 29 deletions
@@ -1,30 +1,21 @@
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include "Detector.h"
#include "ENESMBusController.h"
#include "ENESMBusInterface_SpectrixS40G_Linux.h"
#include "LogManager.h"
#include "RGBController.h"
#include "RGBController_ENESMBus.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
/******************************************************************************************\
* *
* DetectSpectrixS40GControllers *
* *
* Detects ENE SMBus controllers on XPG Spectrix S40G NVMe devices *
* *
\******************************************************************************************/
void DetectSpectrixS40GControllers()
void DetectSpectrixControllers(char * model)
{
/*---------------------------------------------------------------------*\
| Search for /dev/nvmeX nodes with model matching "XPG SPECTRIX S40G" |
\*---------------------------------------------------------------------*/
/*-----------------------------------------------------*\
| Search for /dev/nvmeX nodes with given model |
\*-----------------------------------------------------*/
unsigned int nvme_idx = 0;
while(1)
@@ -50,19 +41,19 @@ void DetectSpectrixS40GControllers()
if(read(nvme_model_fd, nvme_dev_buf, 1024) < 0)
{
LOG_WARNING("[XPG Spectrix S40G] Probing %d, failed to read NVMe model", nvme_idx);
LOG_WARNING("[XPG Spectrix SSD] Probing %d, failed to read NVMe model", nvme_idx);
}
else
{
LOG_DEBUG("[XPG Spectrix S40G] Probing %d, model: %s", nvme_idx, nvme_dev_buf);
LOG_DEBUG("[XPG Spectrix SSD] Probing %d, model: %s", nvme_idx, nvme_dev_buf);
}
close(nvme_model_fd);
/*-------------------------------------------------*\
| Check if this NVMe device is a SPECTRIX S40G |
| Check if this NVMe device is the right model |
\*-------------------------------------------------*/
if(strncmp(nvme_dev_buf, "XPG SPECTRIX S40G", 17) == 0)
if(strncmp(nvme_dev_buf, model, strlen(model)) == 0)
{
snprintf(nvme_dev_buf, 1024, "/dev/nvme%d", nvme_idx);
@@ -84,6 +75,33 @@ void DetectSpectrixS40GControllers()
nvme_idx++;
}
} /* DetectSpectrixS40GControllers() */
} /* DetectSpectrixControllers() */
REGISTER_DETECTOR( "XPG Spectrix S40G", DetectSpectrixS40GControllers);
/******************************************************************************************\
* *
* DetectSpectrixS20GControllers *
* *
* Detects ENE SMBus controllers on XPG Spectrix S20G NVMe devices *
* *
\******************************************************************************************/
void DetectSpectrixS20GControllers()
{
DetectSpectrixControllers("XPG SPECTRIX S20G");
}
/******************************************************************************************\
* *
* DetectSpectrixS40GControllers *
* *
* Detects ENE SMBus controllers on XPG Spectrix S40G NVMe devices *
* *
\******************************************************************************************/
void DetectSpectrixS40GControllers()
{
DetectSpectrixControllers("XPG SPECTRIX S40G");
}
REGISTER_DETECTOR("XPG Spectrix S20G", DetectSpectrixS20GControllers);
REGISTER_DETECTOR("XPG Spectrix S40G", DetectSpectrixS40GControllers);
@@ -27,7 +27,7 @@
* *
\******************************************************************************************/
int Search(wchar_t *dev_name)
int Search(wchar_t *dev_name, const wchar_t *dev_identifier)
{
wchar_t buff[DEVBUFSIZE] = L"";
int wchar_count;
@@ -41,7 +41,7 @@ int Search(wchar_t *dev_name)
for(int i = 0; i < wchar_count; i++)
{
if(wcsstr(buff + i, L"SCSI#Disk&Ven_NVMe&Prod_XPG_SPECTRIX_S40#"))
if(wcsstr(buff + i, dev_identifier))
{
wcsncpy(dev_name, buff + i, MAX_PATH);
(dev_name)[MAX_PATH - 1] = '\0';
@@ -81,6 +81,43 @@ HANDLE OpenDevice(wchar_t buff[MAX_PATH])
return(hDevice);
}
/******************************************************************************************\
* *
* DetectSpectrixS42GControllers *
* *
* Detects ENE SMBus controllers on XPG Spectrix S20G NVMe devices *
* *
* Tests for the existance of a file descriptor matching *
* SCSI#Disk&Ven_NVMe&Prod_XPG_SPECTRIX_S20# on Windows machines *
* *
\******************************************************************************************/
void DetectSpectrixS20GControllers()
{
/*-------------------------------------------------------------------------------------------------*\
| https://docs.microsoft.com/en-us/windows-hardware/drivers/install/identifiers-for-scsi-devices |
\*-------------------------------------------------------------------------------------------------*/
wchar_t dev_name[MAX_PATH];
if(Search(dev_name, L"SCSI#Disk&Ven_NVMe&Prod_XPG_SPECTRIX_S20#"))
{
HANDLE nvme_fd = OpenDevice(dev_name);
if(nvme_fd != INVALID_HANDLE_VALUE)
{
ENESMBusInterface_SpectrixS40G* interface = new ENESMBusInterface_SpectrixS40G(nvme_fd, dev_name);
ENESMBusController* controller = new ENESMBusController(interface, 0x67);
RGBController_ENESMBus* rgb_controller = new RGBController_ENESMBus(controller);
rgb_controller->name = "XPG Spectrix S20G";
rgb_controller->type = DEVICE_TYPE_STORAGE;
rgb_controller->vendor = "XPG";
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
} /* DetectSpectrixS20GControllers() */
/******************************************************************************************\
* *
* DetectSpectrixS40GControllers *
@@ -99,7 +136,7 @@ void DetectSpectrixS40GControllers()
\*-------------------------------------------------------------------------------------------------*/
wchar_t dev_name[MAX_PATH];
if(Search(dev_name))
if(Search(dev_name, L"SCSI#Disk&Ven_NVMe&Prod_XPG_SPECTRIX_S40#"))
{
HANDLE nvme_fd = OpenDevice(dev_name);
@@ -119,4 +156,5 @@ void DetectSpectrixS40GControllers()
} /* DetectSpectrixS40GControllers() */
REGISTER_DETECTOR( "XPG Spectrix S40G", DetectSpectrixS40GControllers);
REGISTER_DETECTOR("XPG Spectrix S20G", DetectSpectrixS20GControllers);
REGISTER_DETECTOR("XPG Spectrix S40G", DetectSpectrixS40GControllers);