I am attempting to utilise the HBAAPI.dll that can be found at
http://hbaapi.sourceforge.net/ (which is also used in hbaverify at
http://hbaverify.sourceforge.net/) as I need to get a small subset of the
data that it provides. However, although I can get the initialisations to
work, I cannot manage to get responses that require data to pass to the dll.
(The latest API details are at :
ftp://ftp.t11.org/t11/pub/sm/hba/05-056v0.pdf)
The basic functions work fine e.g HBA_GetVersion and HBA_LoadLibrary .
However once I attempt to pass values to the dll e.g. HBA_GetAdapterN ame, it
all goes wrong. I've tried variously switching between int32 and uint32,
also using ByVal for the index (produces a "Unhandled Exception:
System.NullRefe renceException: Object reference not set to an instance of an
object." error) and using ByRef (produces a status code indicating an
'invalid index'). The HBAVerify code works fine on my test system and I
cannot see what differs in the way that I am calling the dll from my VB.Net
code.
Can anyone suggest what might be wrong with the HBA_GetAdapterN ame function,
given that the dll is meant to be called from C.
Cheers,
Vizzybit.
My code is as follows (all HBAAPI functions are not yet currently
implemented, just enought for testing) :
Option Strict On
Imports System
Imports System.Runtime. InteropServices
Module HBAView
' sundry fields for VB translation and processing
Public Blank As String = ""
Public HBA_Count As Int32 = 0
Public HBA_Count_Loop As Int32 = 0
Public HBA_Name As String = ""
Public HBA_Handle_Save As Int32 = 0
'/* 4.2.1 Handle to Device */
Public HBA_Handle As Int32 = 0
'/* 4.2.2 Status Return Values */
Public HBA_Status As Int32 = 0
Public HBA_Status_OK As Int32 = 0
Public HBA_Status_ERRO R As Int32 = 1 '/* Error */
Public HBA_Status_ERRO R_NOT_SUPPORTED As Int32 = 2 '/* Function
not supported.*/
Public HBA_Status_ERRO R_INVALID_HANDL E As Int32 = 3 '/* invalid
handle */
Public HBA_Status_ERRO R_ARG As Int32 = 4 '/* Bad
argument */
Public HBA_Status_ERRO R_ILLEGAL_WWN As Int32 = 5 '/* WWN not
recognized */
Public HBA_Status_ERRO R_ILLEGAL_INDEX As Int32 = 6 '/* Index not
recognized */
Public HBA_Status_ERRO R_MORE_DATA As Int32 = 7 '/* Larger
buffer required */
Public HBA_Status_ERRO R_STALE_DATA As Int32 = 8
Public HBA_Status_SCSI _CHECK_CONDITIO N As Int32 = 9
Public HBA_Status_ERRO R_BUSY As Int32 = 10
Public HBA_Status_ERRO R_TRY_AGAIN As Int32 = 11
Public HBA_Status_ERRO R_ADAPTER_REMOV ED As Int32 = 12
'/* 4.2.3 Port Operational Modes Values */
Public HBA_PortType As Int32 = 0
Public HBA_PortType_UN KNOWN As Int32 = 1 '/* Unknown */
Public HBA_PortType_OT HER As Int32 = 2 '/* Other */
Public HBA_PortType_NO TPRESENT As Int32 = 3 '/* Not present */
Public HBA_PortType_NP ORT As Int32 = 5 '/* Fabric */
Public HBA_PortType_NL PORT As Int32 = 6 '/* Public Loop */
Public HBA_PortType_FL PORT As Int32 = 7
Public HBA_PortType_FP ORT As Int32 = 8 '/* Fabric Port */
Public HBA_PortType_EP ORT As Int32 = 9 '/* Fabric expansion
port */
Public HBA_PortType_GP ORT As Int32 = 10 '/* Generic Fabric
Port */
Public HBA_PortType_LP ORT As Int32 = 20 '/* Private Loop */
Public HBA_PortType_PT P As Int32 = 21 '/* Point to Point */
Public HBA_PortState As Int32 = 0
Public HBA_PortState_U NKNOWN As Int32 = 1 '/* Unknown */
Public HBA_PortState_O NLINE As Int32 = 2 '/* Operational */
Public HBA_PortState_O FFLINE As Int32 = 3 '/* User Offline */
Public HBA_PortState_B YPASSED As Int32 = 4 '/* Bypassed */
Public HBA_PortState_D IAGNOSTICS As Int32 = 5 '/* In diagnostics
mode */
Public HBA_PortState_L INKDOWN As Int32 = 6 '/* Link Down */
Public HBA_PortState_E RROR As Int32 = 7 '/* Port Error */
Public HBA_PortState_L OOPBACK As Int32 = 8 '/* Loopback */
Public HBA_PortSpeed As Int32 = 0
Public HBA_PortSpeed_U NKNOWN As Int32 = 0 '/* Unknown -
transceiver incable of reporting */
Public HBA_PortSpeed_1 GBIT As Int32 = 1 '/* 1 GBit/sec */
Public HBA_PortSpeed_2 GBIT As Int32 = 2 '/* 2 GBit/sec */
Public HBA_PortSpeed_1 0GBIT As Int32 = 4 '/* 10 GBit/sec */
Public HBA_PortSpeed_N OT_NEGOTIATED As Int32 = 5 '/* Speed not
established */
'/* 4.2.4 Class of Service Values - See GS-2 Spec.*/
Public HBA_COS As Int32 = 0
Sub Main()
Console.WriteLi ne("*** ***")
Console.WriteLi ne("Running version " &
HBAView_Class.H BA_GetVersion() & " of the HBA API library.")
Console.WriteLi ne("*** " & HBAView_Class.H BA_LoadLibrary( ) & " ***")
HBA_Count = HBAView_Class.H BA_GetNumberOfA dapters()
Console.WriteLi ne("*** HBA_GetNumberOf Adapters : " & HBA_Count & "
***")
Dim HBA_AdapterDeta ils As New HBAView_Class.H BA_AdapterAttri butes()
For HBA_Count_Loop = 0 To HBA_Count - 1
Console.WriteLi ne("*** Num=" & HBA_Count_Loop)
HBA_Status =
HBAView_Class.H BA_GetAdapterNa me(System.Conve rt.ToUInt32(HBA _Count_Loop),
HBA_Name)
Console.WriteLi ne("*** " & "HBA_GetAdapter Name HBA_Status=" &
HBA_Status & " ***")
Console.WriteLi ne("*** Adapter " & HBA_Count_Loop + 1 & "
HBA_GetAdapterN ame : " & HBA_Name & " ***")
'HBA_Handle = HBAView_Class.H BA_OpenAdapter( HBA_Name)
HBA_Handle = HBAView_Class.H BA_OpenAdapter( "QLogic-ql2300-1")
Console.WriteLi ne("*** Adapter " & HBA_Count_Loop + 1 & "
HBA_OpenAdapter : " & HBA_Handle & " ***")
HBA_Handle_Save = HBA_Handle
HBA_Status = HBAView_Class.H BA_GetAdapterAt tributes(HBA_Ha ndle,
HBA_AdapterDeta ils)
'HBA_Status = HBAView_Class.H BA_GetAdapterAt tributes(HBA_Ha ndle,
HBA_Test)
Console.WriteLi ne("*** " & "HBA_GetAdapter Attributes
HBA_Status=" & HBA_Status & " ***")
'Console.WriteL ine("*** " & HBA_Test & " ***")
Console.WriteLi ne("*** Adapter " & HBA_Count_Loop + 1 & "
Manufacturer : " & HBA_AdapterDeta ils.Manufacture r & " ***")
Console.WriteLi ne("*** Adapter " & HBA_Count_Loop + 1 & " Model
: " & HBA_AdapterDeta ils.Model & " ***")
HBA_Status = HBAView_Class.H BA_CloseAdapter (HBA_Handle_Sav e)
Console.WriteLi ne("*** " & "HBA_CloseAdapt er HBA_Status=" &
HBA_Status & " ***")
Next HBA_Count_Loop
Console.WriteLi ne("*** HBA_FreeLibrary : " &
HBAView_Class.H BA_FreeLibrary( ) & " ***")
Console.WriteLi ne("*** ***")
End Sub
End Module
Imports System.Runtime. InteropServices
Public Class HBAView_Class
'/* 4.2.7 Adapter Attributes */
Public Structure HBA_AdapterAttr ibutes
Dim Manufacturer As String '64 Emulex
Dim SerialNumber As String '64 A12345
Dim Model As String '256 QLA2200
Dim ModelDescriptio n As String '256 Agilent TachLite
Dim NodeWWN As String '8 HBA_WWN
Dim NodeSymbolicNam e As String '256 From GS-3
Dim HardwareVersion As String '256 Vendor use
Dim DriverVersion As String '256 Vendor use
Dim OptionROMVersio n As String '256 Vendor use - i.e. hardware
boot ROM
Dim FirmwareVersion As String '256 Vendor use
Dim VendorSpecificI D As Int32 ' Vendor specific
Dim NumberOfPorts As Int32 '
Dim DriverName As String '256 Binary path and/or name of
driver file.
End Structure
<DllImport("hba api.dll")> _
Public Shared Function _
HBA_GetVersion( ) As Int32
End Function
<DllImport("hba api.dll")> _
Public Shared Function _
HBA_LoadLibrary () As Int32
End Function
<DllImport("hba api.dll")> _
Public Shared Function _
HBA_FreeLibrary () As Int32
End Function
<DllImport("hba api.dll")> _
Public Shared Function _
HBA_GetNumberOf Adapters() As Int32
End Function
<DllImport("hba api.dll")> _
Public Shared Function _
HBA_GetAdapterN ame(ByRef AdapterIndex As UInt32, ByRef AdapterName
As String) As Int32
End Function
<DllImport("hba api.dll")> _
Public Shared Function _
HBA_OpenAdapter (ByRef AdapterName As String) As Int32
End Function
<DllImport("hba api.dll")> _
Public Shared Function _
HBA_CloseAdapte r(ByRef HandleName As Int32) As Int32
End Function
<DllImport("hba api.dll")> _
Public Shared Function _
HBA_GetAdapterA ttributes(ByRef HandleName As Int32, ByRef
HBA_AdapterAttr ib As HBA_AdapterAttr ibutes) As Int32
End Function
End Class