mirror of
https://github.com/hashcat/hashcat.git
synced 2024-12-26 16:38:35 +00:00
Restyling hwmon (2021)(2)
This commit is contained in:
parent
a80ad1030e
commit
e5de44c80d
@ -314,4 +314,18 @@ typedef hm_adl_lib_t ADL_PTR;
|
||||
|
||||
void *HC_API_CALL ADL_Main_Memory_Alloc (const int iSize);
|
||||
|
||||
int adl_init (void *hashcat_ctx);
|
||||
void adl_close (void *hashcat_ctx);
|
||||
int hm_ADL_Main_Control_Destroy (void *hashcat_ctx);
|
||||
int hm_ADL_Main_Control_Create (void *hashcat_ctx, ADL_MAIN_MALLOC_CALLBACK callback, int iEnumConnectedAdapters);
|
||||
int hm_ADL_Adapter_NumberOfAdapters_Get (void *hashcat_ctx, int *lpNumAdapters);
|
||||
int hm_ADL_Adapter_AdapterInfo_Get (void *hashcat_ctx, LPAdapterInfo lpInfo, int iInputSize);
|
||||
int hm_ADL_Overdrive5_Temperature_Get (void *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex, ADLTemperature *lpTemperature);
|
||||
int hm_ADL_Overdrive6_Temperature_Get (void *hashcat_ctx, int iAdapterIndex, int *iTemperature);
|
||||
int hm_ADL_Overdrive_CurrentActivity_Get (void *hashcat_ctx, int iAdapterIndex, ADLPMActivity *lpActivity);
|
||||
int hm_ADL_Overdrive5_FanSpeed_Get (void *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex, ADLFanSpeedValue *lpFanSpeedValue);
|
||||
int hm_ADL_Overdrive6_FanSpeed_Get (void *hashcat_ctx, int iAdapterIndex, ADLOD6FanSpeedInfo *lpFanSpeedInfo);
|
||||
int hm_ADL_Overdrive_Caps (void *hashcat_ctx, int iAdapterIndex, int *od_supported, int *od_enabled, int *od_version);
|
||||
int hm_ADL_Overdrive6_TargetTemperatureData_Get (void *hashcat_ctx, int iAdapterIndex, int *cur_temp, int *default_temp);
|
||||
|
||||
#endif // _EXT_ADL_H
|
||||
|
@ -239,4 +239,15 @@ typedef struct hm_nvapi_lib
|
||||
|
||||
typedef hm_nvapi_lib_t NVAPI_PTR;
|
||||
|
||||
int nvapi_init (void *hashcat_ctx);
|
||||
void nvapi_close (void *hashcat_ctx);
|
||||
void hm_NvAPI_GetErrorMessage (NVAPI_PTR *nvapi, const NvAPI_Status NvAPI_rc, NvAPI_ShortString string);
|
||||
int hm_NvAPI_Initialize (void *hashcat_ctx);
|
||||
int hm_NvAPI_Unload (void *hashcat_ctx);
|
||||
int hm_NvAPI_EnumPhysicalGPUs (void *hashcat_ctx, NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount);
|
||||
int hm_NvAPI_GPU_GetPerfPoliciesInfo (void *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *perfPolicies_info);
|
||||
int hm_NvAPI_GPU_GetPerfPoliciesStatus (void *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *perfPolicies_status);
|
||||
int hm_NvAPI_GPU_GetBusId (void *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NvU32 *pBusId);
|
||||
int hm_NvAPI_GPU_GetBusSlotId (void *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NvU32 *pBusSlotId);
|
||||
|
||||
#endif // _EXT_NVAPI_H
|
||||
|
@ -217,4 +217,20 @@ typedef struct hm_nvml_lib
|
||||
|
||||
typedef hm_nvml_lib_t NVML_PTR;
|
||||
|
||||
int nvml_init (void *hashcat_ctx);
|
||||
void nvml_close (void *hashcat_ctx);
|
||||
const char *hm_NVML_nvmlErrorString (NVML_PTR *nvml, const nvmlReturn_t nvml_rc);
|
||||
|
||||
int hm_NVML_nvmlInit (void *hashcat_ctx);
|
||||
int hm_NVML_nvmlShutdown (void *hashcat_ctx);
|
||||
int hm_NVML_nvmlDeviceGetCount (void *hashcat_ctx, unsigned int *deviceCount);
|
||||
int hm_NVML_nvmlDeviceGetHandleByIndex (void *hashcat_ctx, unsigned int device_index, nvmlDevice_t *device);
|
||||
int hm_NVML_nvmlDeviceGetTemperature (void *hashcat_ctx, nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp);
|
||||
int hm_NVML_nvmlDeviceGetFanSpeed (void *hashcat_ctx, nvmlDevice_t device, unsigned int *speed);
|
||||
int hm_NVML_nvmlDeviceGetUtilizationRates (void *hashcat_ctx, nvmlDevice_t device, nvmlUtilization_t *utilization);
|
||||
int hm_NVML_nvmlDeviceGetClockInfo (void *hashcat_ctx, nvmlDevice_t device, nvmlClockType_t type, unsigned int *clockfreq);
|
||||
int hm_NVML_nvmlDeviceGetTemperatureThreshold (void *hashcat_ctx, nvmlDevice_t device, nvmlTemperatureThresholds_t thresholdType, unsigned int *temp);
|
||||
int hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (void *hashcat_ctx, nvmlDevice_t device, unsigned int *currLinkWidth);
|
||||
int hm_NVML_nvmlDeviceGetPciInfo (void *hashcat_ctx, nvmlDevice_t device, nvmlPciInfo_t *pci);
|
||||
|
||||
#endif // _NVML_H
|
||||
|
@ -6,6 +6,8 @@
|
||||
#ifndef _EXT_SYSFS_H
|
||||
#define _EXT_SYSFS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
static const char SYS_BUS_PCI_DEVICES[] = "/sys/bus/pci/devices";
|
||||
|
||||
typedef int HM_ADAPTER_SYSFS;
|
||||
@ -22,4 +24,15 @@ typedef struct hm_sysfs_lib
|
||||
|
||||
typedef hm_sysfs_lib_t SYSFS_PTR;
|
||||
|
||||
bool sysfs_init (void *hashcat_ctx);
|
||||
void sysfs_close (void *hashcat_ctx);
|
||||
char *hm_SYSFS_get_syspath_device (void *hashcat_ctx, const int backend_device_idx);
|
||||
char *hm_SYSFS_get_syspath_hwmon (void *hashcat_ctx, const int backend_device_idx);
|
||||
int hm_SYSFS_get_fan_speed_current (void *hashcat_ctx, const int backend_device_idx, int *val);
|
||||
int hm_SYSFS_get_temperature_current (void *hashcat_ctx, const int backend_device_idx, int *val);
|
||||
int hm_SYSFS_get_pp_dpm_sclk (void *hashcat_ctx, const int backend_device_idx, int *val);
|
||||
int hm_SYSFS_get_pp_dpm_mclk (void *hashcat_ctx, const int backend_device_idx, int *val);
|
||||
int hm_SYSFS_get_pp_dpm_pcie (void *hashcat_ctx, const int backend_device_idx, int *val);
|
||||
int hm_SYSFS_get_gpu_busy_percent (void *hashcat_ctx, const int backend_device_idx, int *val);
|
||||
|
||||
#endif // _EXT_SYSFS_H
|
||||
|
276
src/ext_ADL.c
276
src/ext_ADL.c
@ -5,9 +5,285 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "memory.h"
|
||||
#include "event.h"
|
||||
#include "ext_ADL.h"
|
||||
|
||||
#include "dynloader.h"
|
||||
|
||||
void *HC_API_CALL ADL_Main_Memory_Alloc (const int iSize)
|
||||
{
|
||||
return malloc ((size_t) iSize);
|
||||
}
|
||||
|
||||
int adl_init (void *hashcat_ctx)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
ADL_PTR *adl = (ADL_PTR *) hwmon_ctx->hm_adl;
|
||||
|
||||
memset (adl, 0, sizeof (ADL_PTR));
|
||||
|
||||
#if defined (_WIN)
|
||||
adl->lib = hc_dlopen ("atiadlxx.dll");
|
||||
|
||||
if (!adl->lib)
|
||||
{
|
||||
adl->lib = hc_dlopen ("atiadlxy.dll");
|
||||
}
|
||||
#elif defined (__CYGWIN__)
|
||||
adl->lib = hc_dlopen ("atiadlxx.dll");
|
||||
|
||||
if (!adl->lib)
|
||||
{
|
||||
adl->lib = hc_dlopen ("atiadlxy.dll");
|
||||
}
|
||||
#elif defined (_POSIX)
|
||||
adl->lib = hc_dlopen ("libatiadlxx.so");
|
||||
#endif
|
||||
|
||||
if (!adl->lib)
|
||||
{
|
||||
//if (user_options->quiet == false)
|
||||
// event_log_error (hashcat_ctx, "Load of ADL library failed. Proceeding without ADL HWMon enabled.");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
HC_LOAD_FUNC(adl, ADL_Main_Control_Destroy, ADL_MAIN_CONTROL_DESTROY, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Main_Control_Create, ADL_MAIN_CONTROL_CREATE, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Adapter_NumberOfAdapters_Get, ADL_ADAPTER_NUMBEROFADAPTERS_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Adapter_AdapterInfo_Get, ADL_ADAPTER_ADAPTERINFO_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Display_DisplayInfo_Get, ADL_DISPLAY_DISPLAYINFO_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Adapter_ID_Get, ADL_ADAPTER_ID_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Adapter_VideoBiosInfo_Get, ADL_ADAPTER_VIDEOBIOSINFO_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Overdrive5_ThermalDevices_Enum, ADL_OVERDRIVE5_THERMALDEVICES_ENUM, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Overdrive5_Temperature_Get, ADL_OVERDRIVE5_TEMPERATURE_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Overdrive6_Temperature_Get, ADL_OVERDRIVE6_TEMPERATURE_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Overdrive5_CurrentActivity_Get, ADL_OVERDRIVE5_CURRENTACTIVITY_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Overdrive5_FanSpeedInfo_Get, ADL_OVERDRIVE5_FANSPEEDINFO_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Overdrive5_FanSpeed_Get, ADL_OVERDRIVE5_FANSPEED_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Overdrive6_FanSpeed_Get, ADL_OVERDRIVE6_FANSPEED_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Adapter_Active_Get, ADL_ADAPTER_ACTIVE_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Overdrive_Caps, ADL_OVERDRIVE_CAPS, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Overdrive6_Capabilities_Get, ADL_OVERDRIVE6_CAPABILITIES_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Overdrive6_StateInfo_Get, ADL_OVERDRIVE6_STATEINFO_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Overdrive6_CurrentStatus_Get, ADL_OVERDRIVE6_CURRENTSTATUS_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Overdrive6_TargetTemperatureData_Get, ADL_OVERDRIVE6_TARGETTEMPERATUREDATA_GET, ADL, 0);
|
||||
HC_LOAD_FUNC(adl, ADL_Overdrive6_TargetTemperatureRangeInfo_Get, ADL_OVERDRIVE6_TARGETTEMPERATURERANGEINFO_GET, ADL, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void adl_close (void *hashcat_ctx)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
ADL_PTR *adl = (ADL_PTR *) hwmon_ctx->hm_adl;
|
||||
|
||||
if (adl)
|
||||
{
|
||||
if (adl->lib)
|
||||
hc_dlclose (adl->lib);
|
||||
|
||||
hcfree (adl);
|
||||
}
|
||||
}
|
||||
|
||||
int hm_ADL_Main_Control_Destroy (void *hashcat_ctx)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
ADL_PTR *adl = (ADL_PTR *) hwmon_ctx->hm_adl;
|
||||
|
||||
const int ADL_rc = adl->ADL_Main_Control_Destroy ();
|
||||
|
||||
if (ADL_rc != ADL_OK)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "ADL_Main_Control_Destroy(): %d", ADL_rc);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_ADL_Main_Control_Create (void *hashcat_ctx, ADL_MAIN_MALLOC_CALLBACK callback, int iEnumConnectedAdapters)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
ADL_PTR *adl = (ADL_PTR *) hwmon_ctx->hm_adl;
|
||||
|
||||
const int ADL_rc = adl->ADL_Main_Control_Create (callback, iEnumConnectedAdapters);
|
||||
|
||||
if (ADL_rc != ADL_OK)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "ADL_Main_Control_Create(): %d", ADL_rc);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_ADL_Adapter_NumberOfAdapters_Get (void *hashcat_ctx, int *lpNumAdapters)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
ADL_PTR *adl = (ADL_PTR *) hwmon_ctx->hm_adl;
|
||||
|
||||
const int ADL_rc = adl->ADL_Adapter_NumberOfAdapters_Get (lpNumAdapters);
|
||||
|
||||
if (ADL_rc != ADL_OK)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "ADL_Adapter_NumberOfAdapters_Get(): %d", ADL_rc);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_ADL_Adapter_AdapterInfo_Get (void *hashcat_ctx, LPAdapterInfo lpInfo, int iInputSize)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
ADL_PTR *adl = (ADL_PTR *) hwmon_ctx->hm_adl;
|
||||
|
||||
const int ADL_rc = adl->ADL_Adapter_AdapterInfo_Get (lpInfo, iInputSize);
|
||||
|
||||
if (ADL_rc != ADL_OK)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "ADL_Adapter_AdapterInfo_Get(): %d", ADL_rc);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_ADL_Overdrive5_Temperature_Get (void *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex, ADLTemperature *lpTemperature)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
ADL_PTR *adl = (ADL_PTR *) hwmon_ctx->hm_adl;
|
||||
|
||||
const int ADL_rc = adl->ADL_Overdrive5_Temperature_Get (iAdapterIndex, iThermalControllerIndex, lpTemperature);
|
||||
|
||||
if (ADL_rc != ADL_OK)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "ADL_Overdrive5_Temperature_Get(): %d", ADL_rc);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_ADL_Overdrive6_Temperature_Get (void *hashcat_ctx, int iAdapterIndex, int *iTemperature)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
ADL_PTR *adl = (ADL_PTR *) hwmon_ctx->hm_adl;
|
||||
|
||||
const int ADL_rc = adl->ADL_Overdrive6_Temperature_Get (iAdapterIndex, iTemperature);
|
||||
|
||||
if (ADL_rc != ADL_OK)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "ADL_Overdrive6_Temperature_Get(): %d", ADL_rc);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_ADL_Overdrive_CurrentActivity_Get (void *hashcat_ctx, int iAdapterIndex, ADLPMActivity *lpActivity)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
ADL_PTR *adl = (ADL_PTR *) hwmon_ctx->hm_adl;
|
||||
|
||||
const int ADL_rc = adl->ADL_Overdrive5_CurrentActivity_Get (iAdapterIndex, lpActivity);
|
||||
|
||||
if (ADL_rc != ADL_OK)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "ADL_Overdrive5_CurrentActivity_Get(): %d", ADL_rc);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_ADL_Overdrive5_FanSpeed_Get (void *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex, ADLFanSpeedValue *lpFanSpeedValue)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
ADL_PTR *adl = (ADL_PTR *) hwmon_ctx->hm_adl;
|
||||
|
||||
const int ADL_rc = adl->ADL_Overdrive5_FanSpeed_Get (iAdapterIndex, iThermalControllerIndex, lpFanSpeedValue);
|
||||
|
||||
if ((ADL_rc != ADL_OK) && (ADL_rc != ADL_ERR_NOT_SUPPORTED)) // exception allowed only here
|
||||
{
|
||||
event_log_error (hashcat_ctx, "ADL_Overdrive5_FanSpeed_Get(): %d", ADL_rc);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_ADL_Overdrive6_FanSpeed_Get (void *hashcat_ctx, int iAdapterIndex, ADLOD6FanSpeedInfo *lpFanSpeedInfo)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
ADL_PTR *adl = (ADL_PTR *) hwmon_ctx->hm_adl;
|
||||
|
||||
const int ADL_rc = adl->ADL_Overdrive6_FanSpeed_Get (iAdapterIndex, lpFanSpeedInfo);
|
||||
|
||||
if ((ADL_rc != ADL_OK) && (ADL_rc != ADL_ERR_NOT_SUPPORTED)) // exception allowed only here
|
||||
{
|
||||
event_log_error (hashcat_ctx, "ADL_Overdrive6_FanSpeed_Get(): %d", ADL_rc);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_ADL_Overdrive_Caps (void *hashcat_ctx, int iAdapterIndex, int *od_supported, int *od_enabled, int *od_version)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
ADL_PTR *adl = (ADL_PTR *) hwmon_ctx->hm_adl;
|
||||
|
||||
const int ADL_rc = adl->ADL_Overdrive_Caps (iAdapterIndex, od_supported, od_enabled, od_version);
|
||||
|
||||
if (ADL_rc != ADL_OK)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "ADL_Overdrive_Caps(): %d", ADL_rc);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_ADL_Overdrive6_TargetTemperatureData_Get (void *hashcat_ctx, int iAdapterIndex, int *cur_temp, int *default_temp)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
ADL_PTR *adl = (ADL_PTR *) hwmon_ctx->hm_adl;
|
||||
|
||||
const int ADL_rc = adl->ADL_Overdrive6_TargetTemperatureData_Get (iAdapterIndex, cur_temp, default_temp);
|
||||
|
||||
if (ADL_rc != ADL_OK)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "ADL_Overdrive6_TargetTemperatureData_Get(): %d", ADL_rc);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
233
src/ext_nvapi.c
233
src/ext_nvapi.c
@ -5,4 +5,237 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "memory.h"
|
||||
#include "event.h"
|
||||
#include "ext_nvapi.h"
|
||||
|
||||
#include "dynloader.h"
|
||||
|
||||
int nvapi_init (void *hashcat_ctx)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVAPI_PTR *nvapi = (NVAPI_PTR *) hwmon_ctx->hm_nvapi;
|
||||
|
||||
memset (nvapi, 0, sizeof (NVAPI_PTR));
|
||||
|
||||
#if defined (_WIN)
|
||||
|
||||
#if defined (_WIN64)
|
||||
nvapi->lib = hc_dlopen ("nvapi64.dll");
|
||||
#else
|
||||
nvapi->lib = hc_dlopen ("nvapi.dll");
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#if defined (__CYGWIN__)
|
||||
|
||||
#if defined (__x86_x64__)
|
||||
nvapi->lib = hc_dlopen ("nvapi64.dll");
|
||||
#else
|
||||
nvapi->lib = hc_dlopen ("nvapi.dll");
|
||||
#endif
|
||||
|
||||
#else
|
||||
nvapi->lib = hc_dlopen ("nvapi.so"); // uhm yes, but .. yeah
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
if (!nvapi->lib)
|
||||
{
|
||||
//if (user_options->quiet == false)
|
||||
// event_log_error (hashcat_ctx, "Load of NVAPI library failed. Proceeding without NVAPI HWMon enabled.");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
HC_LOAD_FUNC(nvapi, nvapi_QueryInterface, NVAPI_QUERYINTERFACE, NVAPI, 0);
|
||||
HC_LOAD_ADDR(nvapi, NvAPI_Initialize, NVAPI_INITIALIZE, nvapi_QueryInterface, 0x0150E828U, NVAPI, 0);
|
||||
HC_LOAD_ADDR(nvapi, NvAPI_Unload, NVAPI_UNLOAD, nvapi_QueryInterface, 0xD22BDD7EU, NVAPI, 0);
|
||||
HC_LOAD_ADDR(nvapi, NvAPI_GetErrorMessage, NVAPI_GETERRORMESSAGE, nvapi_QueryInterface, 0x6C2D048CU, NVAPI, 0);
|
||||
HC_LOAD_ADDR(nvapi, NvAPI_EnumPhysicalGPUs, NVAPI_ENUMPHYSICALGPUS, nvapi_QueryInterface, 0xE5AC921FU, NVAPI, 0);
|
||||
HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesInfo, NVAPI_GPU_GETPERFPOLICIESINFO, nvapi_QueryInterface, 0x409D9841U, NVAPI, 0);
|
||||
HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesStatus, NVAPI_GPU_GETPERFPOLICIESSTATUS, nvapi_QueryInterface, 0x3D358A0CU, NVAPI, 0);
|
||||
HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetBusId, NVAPI_GPU_GETBUSID, nvapi_QueryInterface, 0x1BE0B8E5U, NVAPI, 0);
|
||||
HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetBusSlotId, NVAPI_GPU_GETBUSSLOTID, nvapi_QueryInterface, 0x2A0A350FU, NVAPI, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nvapi_close (void *hashcat_ctx)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVAPI_PTR *nvapi = (NVAPI_PTR *) hwmon_ctx->hm_nvapi;
|
||||
|
||||
if (nvapi)
|
||||
{
|
||||
if (nvapi->lib)
|
||||
hc_dlclose (nvapi->lib);
|
||||
|
||||
hcfree (nvapi);
|
||||
}
|
||||
}
|
||||
|
||||
void hm_NvAPI_GetErrorMessage (NVAPI_PTR *nvapi, const NvAPI_Status NvAPI_rc, NvAPI_ShortString string)
|
||||
{
|
||||
nvapi->NvAPI_GetErrorMessage (NvAPI_rc, string);
|
||||
}
|
||||
|
||||
int hm_NvAPI_Initialize (void *hashcat_ctx)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVAPI_PTR *nvapi = (NVAPI_PTR *) hwmon_ctx->hm_nvapi;
|
||||
|
||||
const NvAPI_Status NvAPI_rc = (NvAPI_Status) nvapi->NvAPI_Initialize ();
|
||||
|
||||
if (NvAPI_rc == NVAPI_LIBRARY_NOT_FOUND) return -1;
|
||||
|
||||
if (NvAPI_rc != NVAPI_OK)
|
||||
{
|
||||
NvAPI_ShortString string = { 0 };
|
||||
|
||||
hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
|
||||
|
||||
event_log_error (hashcat_ctx, "NvAPI_Initialize(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NvAPI_Unload (void *hashcat_ctx)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVAPI_PTR *nvapi = (NVAPI_PTR *) hwmon_ctx->hm_nvapi;
|
||||
|
||||
const NvAPI_Status NvAPI_rc = (NvAPI_Status) nvapi->NvAPI_Unload ();
|
||||
|
||||
if (NvAPI_rc != NVAPI_OK)
|
||||
{
|
||||
NvAPI_ShortString string = { 0 };
|
||||
|
||||
hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
|
||||
|
||||
event_log_error (hashcat_ctx, "NvAPI_Unload(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NvAPI_EnumPhysicalGPUs (void *hashcat_ctx, NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVAPI_PTR *nvapi = (NVAPI_PTR *) hwmon_ctx->hm_nvapi;
|
||||
|
||||
const NvAPI_Status NvAPI_rc = (NvAPI_Status) nvapi->NvAPI_EnumPhysicalGPUs (nvGPUHandle, pGpuCount);
|
||||
|
||||
if (NvAPI_rc != NVAPI_OK)
|
||||
{
|
||||
NvAPI_ShortString string = { 0 };
|
||||
|
||||
hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
|
||||
|
||||
event_log_error (hashcat_ctx, "NvAPI_EnumPhysicalGPUs(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NvAPI_GPU_GetPerfPoliciesInfo (void *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *perfPolicies_info)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVAPI_PTR *nvapi = (NVAPI_PTR *) hwmon_ctx->hm_nvapi;
|
||||
|
||||
const NvAPI_Status NvAPI_rc = (NvAPI_Status) nvapi->NvAPI_GPU_GetPerfPoliciesInfo (hPhysicalGpu, perfPolicies_info);
|
||||
|
||||
if (NvAPI_rc != NVAPI_OK)
|
||||
{
|
||||
NvAPI_ShortString string = { 0 };
|
||||
|
||||
hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
|
||||
|
||||
event_log_error (hashcat_ctx, "NvAPI_GPU_GetPerfPoliciesInfo(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NvAPI_GPU_GetPerfPoliciesStatus (void *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *perfPolicies_status)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVAPI_PTR *nvapi = (NVAPI_PTR *) hwmon_ctx->hm_nvapi;
|
||||
|
||||
const NvAPI_Status NvAPI_rc = (NvAPI_Status) nvapi->NvAPI_GPU_GetPerfPoliciesStatus (hPhysicalGpu, perfPolicies_status);
|
||||
|
||||
if (NvAPI_rc != NVAPI_OK)
|
||||
{
|
||||
NvAPI_ShortString string = { 0 };
|
||||
|
||||
hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
|
||||
|
||||
event_log_error (hashcat_ctx, "NvAPI_GPU_GetPerfPoliciesStatus(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NvAPI_GPU_GetBusId (void *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NvU32 *pBusId)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVAPI_PTR *nvapi = (NVAPI_PTR *) hwmon_ctx->hm_nvapi;
|
||||
|
||||
const NvAPI_Status NvAPI_rc = (NvAPI_Status) nvapi->NvAPI_GPU_GetBusId (hPhysicalGpu, pBusId);
|
||||
|
||||
if (NvAPI_rc != NVAPI_OK)
|
||||
{
|
||||
NvAPI_ShortString string = { 0 };
|
||||
|
||||
hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
|
||||
|
||||
event_log_error (hashcat_ctx, "NvAPI_GPU_GetBusId(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NvAPI_GPU_GetBusSlotId (void *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NvU32 *pBusSlotId)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVAPI_PTR *nvapi = (NVAPI_PTR *) hwmon_ctx->hm_nvapi;
|
||||
|
||||
const NvAPI_Status NvAPI_rc = (NvAPI_Status) nvapi->NvAPI_GPU_GetBusSlotId (hPhysicalGpu, pBusSlotId);
|
||||
|
||||
if (NvAPI_rc != NVAPI_OK)
|
||||
{
|
||||
NvAPI_ShortString string = { 0 };
|
||||
|
||||
hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
|
||||
|
||||
event_log_error (hashcat_ctx, "NvAPI_GPU_GetBusSlotId(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
386
src/ext_nvml.c
386
src/ext_nvml.c
@ -5,4 +5,390 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "memory.h"
|
||||
#include "shared.h"
|
||||
#include "event.h"
|
||||
#include "ext_nvml.h"
|
||||
|
||||
#include "dynloader.h"
|
||||
|
||||
#if defined (__CYGWIN__)
|
||||
#include <sys/cygwin.h>
|
||||
#endif
|
||||
|
||||
int nvml_init (void *hashcat_ctx)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVML_PTR *nvml = (NVML_PTR *) hwmon_ctx->hm_nvml;
|
||||
|
||||
memset (nvml, 0, sizeof (NVML_PTR));
|
||||
|
||||
#if defined (_WIN)
|
||||
|
||||
nvml->lib = hc_dlopen ("nvml.dll");
|
||||
|
||||
if (!nvml->lib)
|
||||
{
|
||||
DWORD BufferSize = 1024;
|
||||
|
||||
DWORD Type = REG_SZ;
|
||||
|
||||
char *Buffer = (char *) hcmalloc (BufferSize + 1);
|
||||
|
||||
HKEY hKey = 0;
|
||||
|
||||
if (RegOpenKeyExA (HKEY_LOCAL_MACHINE, "SOFTWARE\\NVIDIA Corporation\\Global\\NVSMI", 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
|
||||
{
|
||||
if (RegQueryValueExA (hKey, "NVSMIPATH", NULL, &Type, (LPBYTE)Buffer, &BufferSize) == ERROR_SUCCESS)
|
||||
{
|
||||
Buffer[BufferSize] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (user_options->quiet == false)
|
||||
// event_log_error (hashcat_ctx, "NVML library load failed. Proceeding without NVML HWMon enabled.");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
RegCloseKey (hKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (user_options->quiet == false)
|
||||
// event_log_error (hashcat_ctx, "NVML library load failed. Proceeding without NVML HWMon enabled.");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcat (Buffer, "\\nvml.dll");
|
||||
|
||||
nvml->lib = hc_dlopen (Buffer);
|
||||
|
||||
hcfree (Buffer);
|
||||
}
|
||||
|
||||
#elif defined (__CYGWIN__)
|
||||
|
||||
nvml->lib = hc_dlopen ("nvml.dll");
|
||||
|
||||
if (!nvml->lib)
|
||||
{
|
||||
HCFILE nvml_lib;
|
||||
|
||||
if (hc_fopen (&nvml_lib, "/proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/NVIDIA Corporation/Global/NVSMI/NVSMIPATH", "rb") == false)
|
||||
{
|
||||
//if (user_options->quiet == false)
|
||||
// event_log_error (hashcat_ctx, "NVML library load failed: %m. Proceeding without NVML HWMon enabled.");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *nvml_winpath, *nvml_cygpath;
|
||||
|
||||
nvml_winpath = (char *) hcmalloc (100);
|
||||
|
||||
hc_fread (nvml_winpath, 100, 1, &nvml_lib);
|
||||
|
||||
hc_fclose (&nvml_lib);
|
||||
|
||||
ssize_t size = cygwin_conv_path (CCP_WIN_A_TO_POSIX | CCP_PROC_CYGDRIVE, nvml_winpath, NULL, 0);
|
||||
|
||||
if (size > 0)
|
||||
{
|
||||
nvml_cygpath = (char *) hcmalloc (size + 9);
|
||||
|
||||
cygwin_conv_path (CCP_WIN_A_TO_POSIX | CCP_PROC_CYGDRIVE, nvml_winpath, nvml_cygpath, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (user_options->quiet == false)
|
||||
// event_log_error (hashcat_ctx, "Could not find NVML on this system. Proceeding without NVML HWMon enabled.");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcat (nvml_cygpath, "/nvml.dll");
|
||||
|
||||
nvml->lib = hc_dlopen (nvml_cygpath);
|
||||
}
|
||||
|
||||
#elif defined (_POSIX)
|
||||
|
||||
nvml->lib = hc_dlopen ("libnvidia-ml.so");
|
||||
|
||||
if (!nvml->lib)
|
||||
{
|
||||
nvml->lib = hc_dlopen ("libnvidia-ml.so.1");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (!nvml->lib)
|
||||
{
|
||||
//if (user_options->quiet == false)
|
||||
// event_log_error (hashcat_ctx, "NVML library load failed. Proceeding without NVML HWMon enabled.");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
HC_LOAD_FUNC(nvml, nvmlErrorString, NVML_ERROR_STRING, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlInit, NVML_INIT, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlShutdown, NVML_SHUTDOWN, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlDeviceGetCount, NVML_DEVICE_GET_COUNT, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlDeviceGetName, NVML_DEVICE_GET_NAME, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlDeviceGetHandleByIndex, NVML_DEVICE_GET_HANDLE_BY_INDEX, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlDeviceGetTemperature, NVML_DEVICE_GET_TEMPERATURE, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlDeviceGetFanSpeed, NVML_DEVICE_GET_FAN_SPEED, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlDeviceGetUtilizationRates, NVML_DEVICE_GET_UTILIZATION_RATES, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlDeviceGetClockInfo, NVML_DEVICE_GET_CLOCKINFO, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlDeviceGetTemperatureThreshold, NVML_DEVICE_GET_THRESHOLD, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlDeviceGetCurrPcieLinkGeneration, NVML_DEVICE_GET_CURRPCIELINKGENERATION, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlDeviceGetCurrPcieLinkWidth, NVML_DEVICE_GET_CURRPCIELINKWIDTH, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlDeviceGetCurrentClocksThrottleReasons, NVML_DEVICE_GET_CURRENTCLOCKSTHROTTLEREASONS, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlDeviceGetSupportedClocksThrottleReasons, NVML_DEVICE_GET_SUPPORTEDCLOCKSTHROTTLEREASONS, NVML, 0);
|
||||
HC_LOAD_FUNC(nvml, nvmlDeviceGetPciInfo, NVML_DEVICE_GET_PCIINFO, NVML, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nvml_close (void *hashcat_ctx)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVML_PTR *nvml = (NVML_PTR *) hwmon_ctx->hm_nvml;
|
||||
|
||||
if (nvml)
|
||||
{
|
||||
if (nvml->lib)
|
||||
hc_dlclose (nvml->lib);
|
||||
|
||||
hcfree (nvml);
|
||||
}
|
||||
}
|
||||
|
||||
const char *hm_NVML_nvmlErrorString (NVML_PTR *nvml, const nvmlReturn_t nvml_rc)
|
||||
{
|
||||
return nvml->nvmlErrorString (nvml_rc);
|
||||
}
|
||||
|
||||
int hm_NVML_nvmlInit (void *hashcat_ctx)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVML_PTR *nvml = (NVML_PTR *) hwmon_ctx->hm_nvml;
|
||||
|
||||
const nvmlReturn_t nvml_rc = (nvmlReturn_t) nvml->nvmlInit ();
|
||||
|
||||
if (nvml_rc != NVML_SUCCESS && nvml_rc != NVML_ERROR_DRIVER_NOT_LOADED)
|
||||
{
|
||||
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
|
||||
|
||||
event_log_error (hashcat_ctx, "nvmlInit(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NVML_nvmlShutdown (void *hashcat_ctx)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVML_PTR *nvml = (NVML_PTR *) hwmon_ctx->hm_nvml;
|
||||
|
||||
const nvmlReturn_t nvml_rc = (nvmlReturn_t) nvml->nvmlShutdown ();
|
||||
|
||||
if (nvml_rc != NVML_SUCCESS && nvml_rc != NVML_ERROR_DRIVER_NOT_LOADED)
|
||||
{
|
||||
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
|
||||
|
||||
event_log_error (hashcat_ctx, "nvmlShutdown(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NVML_nvmlDeviceGetCount (void *hashcat_ctx, unsigned int *deviceCount)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVML_PTR *nvml = (NVML_PTR *) hwmon_ctx->hm_nvml;
|
||||
|
||||
const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetCount (deviceCount);
|
||||
|
||||
if (nvml_rc != NVML_SUCCESS && nvml_rc != NVML_ERROR_DRIVER_NOT_LOADED)
|
||||
{
|
||||
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
|
||||
|
||||
event_log_error (hashcat_ctx, "nvmlDeviceGetCount(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NVML_nvmlDeviceGetHandleByIndex (void *hashcat_ctx, unsigned int device_index, nvmlDevice_t *device)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVML_PTR *nvml = (NVML_PTR *) hwmon_ctx->hm_nvml;
|
||||
|
||||
const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetHandleByIndex (device_index, device);
|
||||
|
||||
if (nvml_rc != NVML_SUCCESS)
|
||||
{
|
||||
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
|
||||
|
||||
event_log_error (hashcat_ctx, "nvmlDeviceGetHandleByIndex(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NVML_nvmlDeviceGetTemperature (void *hashcat_ctx, nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVML_PTR *nvml = (NVML_PTR *) hwmon_ctx->hm_nvml;
|
||||
|
||||
const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetTemperature (device, sensorType, temp);
|
||||
|
||||
if (nvml_rc != NVML_SUCCESS)
|
||||
{
|
||||
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
|
||||
|
||||
event_log_error (hashcat_ctx, "nvmlDeviceGetTemperature(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NVML_nvmlDeviceGetFanSpeed (void *hashcat_ctx, nvmlDevice_t device, unsigned int *speed)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVML_PTR *nvml = (NVML_PTR *) hwmon_ctx->hm_nvml;
|
||||
|
||||
const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetFanSpeed (device, speed);
|
||||
|
||||
if (nvml_rc != NVML_SUCCESS)
|
||||
{
|
||||
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
|
||||
|
||||
event_log_error (hashcat_ctx, "nvmlDeviceGetFanSpeed(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NVML_nvmlDeviceGetUtilizationRates (void *hashcat_ctx, nvmlDevice_t device, nvmlUtilization_t *utilization)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVML_PTR *nvml = (NVML_PTR *) hwmon_ctx->hm_nvml;
|
||||
|
||||
const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetUtilizationRates (device, utilization);
|
||||
|
||||
if (nvml_rc != NVML_SUCCESS)
|
||||
{
|
||||
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
|
||||
|
||||
event_log_error (hashcat_ctx, "nvmlDeviceGetUtilizationRates(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NVML_nvmlDeviceGetClockInfo (void *hashcat_ctx, nvmlDevice_t device, nvmlClockType_t type, unsigned int *clockfreq)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVML_PTR *nvml = (NVML_PTR *) hwmon_ctx->hm_nvml;
|
||||
|
||||
const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetClockInfo (device, type, clockfreq);
|
||||
|
||||
if (nvml_rc != NVML_SUCCESS)
|
||||
{
|
||||
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
|
||||
|
||||
event_log_error (hashcat_ctx, "nvmlDeviceGetClockInfo(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NVML_nvmlDeviceGetTemperatureThreshold (void *hashcat_ctx, nvmlDevice_t device, nvmlTemperatureThresholds_t thresholdType, unsigned int *temp)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVML_PTR *nvml = (NVML_PTR *) hwmon_ctx->hm_nvml;
|
||||
|
||||
const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetTemperatureThreshold (device, thresholdType, temp);
|
||||
|
||||
if (nvml_rc != NVML_SUCCESS)
|
||||
{
|
||||
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
|
||||
|
||||
event_log_error (hashcat_ctx, "nvmlDeviceGetTemperatureThreshold(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (void *hashcat_ctx, nvmlDevice_t device, unsigned int *currLinkWidth)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVML_PTR *nvml = (NVML_PTR *) hwmon_ctx->hm_nvml;
|
||||
|
||||
const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetCurrPcieLinkWidth (device, currLinkWidth);
|
||||
|
||||
if (nvml_rc != NVML_SUCCESS)
|
||||
{
|
||||
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
|
||||
|
||||
event_log_error (hashcat_ctx, "nvmlDeviceGetCurrPcieLinkWidth(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_NVML_nvmlDeviceGetPciInfo (void *hashcat_ctx, nvmlDevice_t device, nvmlPciInfo_t *pci)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
NVML_PTR *nvml = (NVML_PTR *) hwmon_ctx->hm_nvml;
|
||||
|
||||
const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetPciInfo (device, pci);
|
||||
|
||||
if (nvml_rc != NVML_SUCCESS)
|
||||
{
|
||||
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
|
||||
|
||||
event_log_error (hashcat_ctx, "nvmlDeviceGetPciInfo(): %s", string);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
436
src/ext_sysfs.c
436
src/ext_sysfs.c
@ -4,4 +4,440 @@
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "memory.h"
|
||||
#include "shared.h"
|
||||
#include "event.h"
|
||||
#include "folder.h"
|
||||
#include "ext_sysfs.h"
|
||||
|
||||
bool sysfs_init (void *hashcat_ctx)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
SYSFS_PTR *sysfs = (SYSFS_PTR *) hwmon_ctx->hm_sysfs;
|
||||
|
||||
memset (sysfs, 0, sizeof (SYSFS_PTR));
|
||||
|
||||
char *path;
|
||||
|
||||
hc_asprintf (&path, "%s", SYS_BUS_PCI_DEVICES);
|
||||
|
||||
const bool r = hc_path_read (path);
|
||||
|
||||
hcfree (path);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void sysfs_close (void *hashcat_ctx)
|
||||
{
|
||||
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
|
||||
|
||||
SYSFS_PTR *sysfs = (SYSFS_PTR *) hwmon_ctx->hm_sysfs;
|
||||
|
||||
if (sysfs)
|
||||
{
|
||||
hcfree (sysfs);
|
||||
}
|
||||
}
|
||||
|
||||
char *hm_SYSFS_get_syspath_device (void *hashcat_ctx, const int backend_device_idx)
|
||||
{
|
||||
backend_ctx_t *backend_ctx = ((hashcat_ctx_t *) hashcat_ctx)->backend_ctx;
|
||||
|
||||
hc_device_param_t *device_param = &backend_ctx->devices_param[backend_device_idx];
|
||||
|
||||
char *syspath;
|
||||
|
||||
hc_asprintf (&syspath, "%s/0000:%02x:%02x.%01x", SYS_BUS_PCI_DEVICES, device_param->pcie_bus, device_param->pcie_device, device_param->pcie_function);
|
||||
|
||||
return syspath;
|
||||
}
|
||||
|
||||
char *hm_SYSFS_get_syspath_hwmon (void *hashcat_ctx, const int backend_device_idx)
|
||||
{
|
||||
char *syspath = hm_SYSFS_get_syspath_device (hashcat_ctx, backend_device_idx);
|
||||
|
||||
if (syspath == NULL)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "hm_SYSFS_get_syspath_device() failed.");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *hwmon = (char *) hcmalloc (HCBUFSIZ_TINY);
|
||||
|
||||
snprintf (hwmon, HCBUFSIZ_TINY, "%s/hwmon", syspath);
|
||||
|
||||
char *hwmonN = first_file_in_directory (hwmon);
|
||||
|
||||
if (hwmonN == NULL)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "First_file_in_directory() failed.");
|
||||
|
||||
hcfree (syspath);
|
||||
|
||||
hcfree (hwmon);
|
||||
hcfree (hwmonN);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
snprintf (hwmon, HCBUFSIZ_TINY, "%s/hwmon/%s", syspath, hwmonN);
|
||||
|
||||
hcfree (syspath);
|
||||
|
||||
hcfree (hwmonN);
|
||||
|
||||
return hwmon;
|
||||
}
|
||||
|
||||
int hm_SYSFS_get_fan_speed_current (void *hashcat_ctx, const int backend_device_idx, int *val)
|
||||
{
|
||||
char *syspath = hm_SYSFS_get_syspath_hwmon (hashcat_ctx, backend_device_idx);
|
||||
|
||||
if (syspath == NULL) return -1;
|
||||
|
||||
char *path_cur;
|
||||
char *path_max;
|
||||
|
||||
hc_asprintf (&path_cur, "%s/pwm1", syspath);
|
||||
hc_asprintf (&path_max, "%s/pwm1_max", syspath);
|
||||
|
||||
hcfree (syspath);
|
||||
|
||||
HCFILE fp_cur;
|
||||
|
||||
if (hc_fopen (&fp_cur, path_cur, "r") == false)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "%s: %s", path_cur, strerror (errno));
|
||||
|
||||
hcfree (path_cur);
|
||||
hcfree (path_max);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pwm1_cur = 0;
|
||||
|
||||
if (hc_fscanf (&fp_cur, "%d", &pwm1_cur) != 1)
|
||||
{
|
||||
hc_fclose (&fp_cur);
|
||||
|
||||
event_log_error (hashcat_ctx, "%s: unexpected data.", path_cur);
|
||||
|
||||
hcfree (path_cur);
|
||||
hcfree (path_max);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
hc_fclose (&fp_cur);
|
||||
|
||||
HCFILE fp_max;
|
||||
|
||||
if (hc_fopen (&fp_max, path_max, "r") == false)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "%s: %s", path_max, strerror (errno));
|
||||
|
||||
hcfree (path_cur);
|
||||
hcfree (path_max);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pwm1_max = 0;
|
||||
|
||||
if (hc_fscanf (&fp_max, "%d", &pwm1_max) != 1)
|
||||
{
|
||||
hc_fclose (&fp_max);
|
||||
|
||||
event_log_error (hashcat_ctx, "%s: unexpected data.", path_max);
|
||||
|
||||
hcfree (path_cur);
|
||||
hcfree (path_max);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
hc_fclose (&fp_max);
|
||||
|
||||
if (pwm1_max == 0)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "%s: pwm1_max cannot be 0.", path_max);
|
||||
|
||||
hcfree (path_cur);
|
||||
hcfree (path_max);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
const float p1 = (float) pwm1_max / 100.0F;
|
||||
|
||||
const float pwm1_percent = (float) pwm1_cur / p1;
|
||||
|
||||
*val = (int) pwm1_percent;
|
||||
|
||||
hcfree (path_cur);
|
||||
hcfree (path_max);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_SYSFS_get_temperature_current (void *hashcat_ctx, const int backend_device_idx, int *val)
|
||||
{
|
||||
char *syspath = hm_SYSFS_get_syspath_hwmon (hashcat_ctx, backend_device_idx);
|
||||
|
||||
if (syspath == NULL) return -1;
|
||||
|
||||
char *path;
|
||||
|
||||
hc_asprintf (&path, "%s/temp1_input", syspath);
|
||||
|
||||
hcfree (syspath);
|
||||
|
||||
HCFILE fp;
|
||||
|
||||
if (hc_fopen (&fp, path, "r") == false)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
|
||||
|
||||
hcfree (path);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int temperature = 0;
|
||||
|
||||
if (hc_fscanf (&fp, "%d", &temperature) != 1)
|
||||
{
|
||||
hc_fclose (&fp);
|
||||
|
||||
event_log_error (hashcat_ctx, "%s: unexpected data.", path);
|
||||
|
||||
hcfree (path);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
hc_fclose (&fp);
|
||||
|
||||
*val = temperature / 1000;
|
||||
|
||||
hcfree (path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_SYSFS_get_pp_dpm_sclk (void *hashcat_ctx, const int backend_device_idx, int *val)
|
||||
{
|
||||
char *syspath = hm_SYSFS_get_syspath_device (hashcat_ctx, backend_device_idx);
|
||||
|
||||
if (syspath == NULL) return -1;
|
||||
|
||||
char *path;
|
||||
|
||||
hc_asprintf (&path, "%s/pp_dpm_sclk", syspath);
|
||||
|
||||
hcfree (syspath);
|
||||
|
||||
HCFILE fp;
|
||||
|
||||
if (hc_fopen (&fp, path, "r") == false)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
|
||||
|
||||
hcfree (path);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int clockfreq = 0;
|
||||
|
||||
while (!hc_feof (&fp))
|
||||
{
|
||||
char buf[HCBUFSIZ_TINY] = { 0 };
|
||||
|
||||
char *ptr = hc_fgets (buf, sizeof (buf), &fp);
|
||||
|
||||
if (ptr == NULL) continue;
|
||||
|
||||
size_t len = strlen (ptr);
|
||||
|
||||
if (len < 2) continue;
|
||||
|
||||
if (ptr[len - 2] != '*') continue;
|
||||
|
||||
int profile = 0;
|
||||
|
||||
int rc = sscanf (ptr, "%d: %dMHz", &profile, &clockfreq);
|
||||
|
||||
if (rc == 2) break;
|
||||
}
|
||||
|
||||
hc_fclose (&fp);
|
||||
|
||||
*val = clockfreq;
|
||||
|
||||
hcfree (path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_SYSFS_get_pp_dpm_mclk (void *hashcat_ctx, const int backend_device_idx, int *val)
|
||||
{
|
||||
char *syspath = hm_SYSFS_get_syspath_device (hashcat_ctx, backend_device_idx);
|
||||
|
||||
if (syspath == NULL) return -1;
|
||||
|
||||
char *path;
|
||||
|
||||
hc_asprintf (&path, "%s/pp_dpm_mclk", syspath);
|
||||
|
||||
hcfree (syspath);
|
||||
|
||||
HCFILE fp;
|
||||
|
||||
if (hc_fopen (&fp, path, "r") == false)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
|
||||
|
||||
hcfree (path);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int clockfreq = 0;
|
||||
|
||||
while (!hc_feof (&fp))
|
||||
{
|
||||
char buf[HCBUFSIZ_TINY];
|
||||
|
||||
char *ptr = hc_fgets (buf, sizeof (buf), &fp);
|
||||
|
||||
if (ptr == NULL) continue;
|
||||
|
||||
size_t len = strlen (ptr);
|
||||
|
||||
if (len < 2) continue;
|
||||
|
||||
if (ptr[len - 2] != '*') continue;
|
||||
|
||||
int profile = 0;
|
||||
|
||||
int rc = sscanf (ptr, "%d: %dMHz", &profile, &clockfreq);
|
||||
|
||||
if (rc == 2) break;
|
||||
}
|
||||
|
||||
hc_fclose (&fp);
|
||||
|
||||
*val = clockfreq;
|
||||
|
||||
hcfree (path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_SYSFS_get_pp_dpm_pcie (void *hashcat_ctx, const int backend_device_idx, int *val)
|
||||
{
|
||||
char *syspath = hm_SYSFS_get_syspath_device (hashcat_ctx, backend_device_idx);
|
||||
|
||||
if (syspath == NULL) return -1;
|
||||
|
||||
char *path;
|
||||
|
||||
hc_asprintf (&path, "%s/current_link_width", syspath);
|
||||
|
||||
hcfree (syspath);
|
||||
|
||||
HCFILE fp;
|
||||
|
||||
if (hc_fopen (&fp, path, "r") == false)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
|
||||
|
||||
hcfree (path);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int lanes = 0;
|
||||
|
||||
while (!hc_feof (&fp))
|
||||
{
|
||||
char buf[HCBUFSIZ_TINY];
|
||||
|
||||
char *ptr = hc_fgets (buf, sizeof (buf), &fp);
|
||||
|
||||
if (ptr == NULL) continue;
|
||||
|
||||
size_t len = strlen (ptr);
|
||||
|
||||
if (len < 2) continue;
|
||||
|
||||
int rc = sscanf (ptr, "%d", &lanes);
|
||||
|
||||
if (rc == 1) break;
|
||||
}
|
||||
|
||||
hc_fclose (&fp);
|
||||
|
||||
*val = lanes;
|
||||
|
||||
hcfree (path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hm_SYSFS_get_gpu_busy_percent (void *hashcat_ctx, const int backend_device_idx, int *val)
|
||||
{
|
||||
char *syspath = hm_SYSFS_get_syspath_device (hashcat_ctx, backend_device_idx);
|
||||
|
||||
if (syspath == NULL) return -1;
|
||||
|
||||
char *path;
|
||||
|
||||
hc_asprintf (&path, "%s/gpu_busy_percent", syspath);
|
||||
|
||||
hcfree (syspath);
|
||||
|
||||
HCFILE fp;
|
||||
|
||||
if (hc_fopen (&fp, path, "r") == false)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
|
||||
|
||||
hcfree (path);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int util = 0;
|
||||
|
||||
while (!hc_feof (&fp))
|
||||
{
|
||||
char buf[HCBUFSIZ_TINY];
|
||||
|
||||
char *ptr = hc_fgets (buf, sizeof (buf), &fp);
|
||||
|
||||
if (ptr == NULL) continue;
|
||||
|
||||
size_t len = strlen (ptr);
|
||||
|
||||
if (len < 1) continue;
|
||||
|
||||
int rc = sscanf (ptr, "%d", &util);
|
||||
|
||||
if (rc == 1) break;
|
||||
}
|
||||
|
||||
hc_fclose (&fp);
|
||||
|
||||
*val = util;
|
||||
|
||||
hcfree (path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
1317
src/hwmon.c
1317
src/hwmon.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user