By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,261 Members | 1,317 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,261 IT Pros & Developers. It's quick & easy.

HBAAPI.dll - possible interop problem

P: n/a
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_GetAdapterName, it
all goes wrong. I've tried variously switching between int32 and uint32,
also using ByVal for the index (produces a "Unhandled Exception:
System.NullReferenceException: 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_GetAdapterName 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_ERROR As Int32 = 1 '/* Error */
Public HBA_Status_ERROR_NOT_SUPPORTED As Int32 = 2 '/* Function
not supported.*/
Public HBA_Status_ERROR_INVALID_HANDLE As Int32 = 3 '/* invalid
handle */
Public HBA_Status_ERROR_ARG As Int32 = 4 '/* Bad
argument */
Public HBA_Status_ERROR_ILLEGAL_WWN As Int32 = 5 '/* WWN not
recognized */
Public HBA_Status_ERROR_ILLEGAL_INDEX As Int32 = 6 '/* Index not
recognized */
Public HBA_Status_ERROR_MORE_DATA As Int32 = 7 '/* Larger
buffer required */
Public HBA_Status_ERROR_STALE_DATA As Int32 = 8
Public HBA_Status_SCSI_CHECK_CONDITION As Int32 = 9
Public HBA_Status_ERROR_BUSY As Int32 = 10
Public HBA_Status_ERROR_TRY_AGAIN As Int32 = 11
Public HBA_Status_ERROR_ADAPTER_REMOVED As Int32 = 12

'/* 4.2.3 Port Operational Modes Values */

Public HBA_PortType As Int32 = 0

Public HBA_PortType_UNKNOWN As Int32 = 1 '/* Unknown */
Public HBA_PortType_OTHER As Int32 = 2 '/* Other */
Public HBA_PortType_NOTPRESENT As Int32 = 3 '/* Not present */
Public HBA_PortType_NPORT As Int32 = 5 '/* Fabric */
Public HBA_PortType_NLPORT As Int32 = 6 '/* Public Loop */
Public HBA_PortType_FLPORT As Int32 = 7
Public HBA_PortType_FPORT As Int32 = 8 '/* Fabric Port */
Public HBA_PortType_EPORT As Int32 = 9 '/* Fabric expansion
port */
Public HBA_PortType_GPORT As Int32 = 10 '/* Generic Fabric
Port */
Public HBA_PortType_LPORT As Int32 = 20 '/* Private Loop */
Public HBA_PortType_PTP As Int32 = 21 '/* Point to Point */

Public HBA_PortState As Int32 = 0
Public HBA_PortState_UNKNOWN As Int32 = 1 '/* Unknown */
Public HBA_PortState_ONLINE As Int32 = 2 '/* Operational */
Public HBA_PortState_OFFLINE As Int32 = 3 '/* User Offline */
Public HBA_PortState_BYPASSED As Int32 = 4 '/* Bypassed */
Public HBA_PortState_DIAGNOSTICS As Int32 = 5 '/* In diagnostics
mode */
Public HBA_PortState_LINKDOWN As Int32 = 6 '/* Link Down */
Public HBA_PortState_ERROR As Int32 = 7 '/* Port Error */
Public HBA_PortState_LOOPBACK As Int32 = 8 '/* Loopback */

Public HBA_PortSpeed As Int32 = 0
Public HBA_PortSpeed_UNKNOWN As Int32 = 0 '/* Unknown -
transceiver incable of reporting */
Public HBA_PortSpeed_1GBIT As Int32 = 1 '/* 1 GBit/sec */
Public HBA_PortSpeed_2GBIT As Int32 = 2 '/* 2 GBit/sec */
Public HBA_PortSpeed_10GBIT As Int32 = 4 '/* 10 GBit/sec */
Public HBA_PortSpeed_NOT_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.WriteLine("*** ***")
Console.WriteLine("Running version " &
HBAView_Class.HBA_GetVersion() & " of the HBA API library.")
Console.WriteLine("*** " & HBAView_Class.HBA_LoadLibrary() & " ***")
HBA_Count = HBAView_Class.HBA_GetNumberOfAdapters()
Console.WriteLine("*** HBA_GetNumberOfAdapters : " & HBA_Count & "
***")

Dim HBA_AdapterDetails As New HBAView_Class.HBA_AdapterAttributes()

For HBA_Count_Loop = 0 To HBA_Count - 1
Console.WriteLine("*** Num=" & HBA_Count_Loop)
HBA_Status =
HBAView_Class.HBA_GetAdapterName(System.Convert.To UInt32(HBA_Count_Loop),
HBA_Name)
Console.WriteLine("*** " & "HBA_GetAdapterName HBA_Status=" &
HBA_Status & " ***")
Console.WriteLine("*** Adapter " & HBA_Count_Loop + 1 & "
HBA_GetAdapterName : " & HBA_Name & " ***")
'HBA_Handle = HBAView_Class.HBA_OpenAdapter(HBA_Name)
HBA_Handle = HBAView_Class.HBA_OpenAdapter("QLogic-ql2300-1")
Console.WriteLine("*** Adapter " & HBA_Count_Loop + 1 & "
HBA_OpenAdapter : " & HBA_Handle & " ***")
HBA_Handle_Save = HBA_Handle
HBA_Status = HBAView_Class.HBA_GetAdapterAttributes(HBA_Handle,
HBA_AdapterDetails)
'HBA_Status = HBAView_Class.HBA_GetAdapterAttributes(HBA_Handle,
HBA_Test)
Console.WriteLine("*** " & "HBA_GetAdapterAttributes
HBA_Status=" & HBA_Status & " ***")
'Console.WriteLine("*** " & HBA_Test & " ***")
Console.WriteLine("*** Adapter " & HBA_Count_Loop + 1 & "
Manufacturer : " & HBA_AdapterDetails.Manufacturer & " ***")

Console.WriteLine("*** Adapter " & HBA_Count_Loop + 1 & " Model
: " & HBA_AdapterDetails.Model & " ***")
HBA_Status = HBAView_Class.HBA_CloseAdapter(HBA_Handle_Save)
Console.WriteLine("*** " & "HBA_CloseAdapter HBA_Status=" &
HBA_Status & " ***")
Next HBA_Count_Loop
Console.WriteLine("*** HBA_FreeLibrary : " &
HBAView_Class.HBA_FreeLibrary() & " ***")
Console.WriteLine("*** ***")

End Sub

End Module


Imports System.Runtime.InteropServices

Public Class HBAView_Class

'/* 4.2.7 Adapter Attributes */
Public Structure HBA_AdapterAttributes
Dim Manufacturer As String '64 Emulex
Dim SerialNumber As String '64 A12345
Dim Model As String '256 QLA2200
Dim ModelDescription As String '256 Agilent TachLite
Dim NodeWWN As String '8 HBA_WWN
Dim NodeSymbolicName As String '256 From GS-3
Dim HardwareVersion As String '256 Vendor use
Dim DriverVersion As String '256 Vendor use
Dim OptionROMVersion As String '256 Vendor use - i.e. hardware
boot ROM
Dim FirmwareVersion As String '256 Vendor use
Dim VendorSpecificID As Int32 ' Vendor specific
Dim NumberOfPorts As Int32 '
Dim DriverName As String '256 Binary path and/or name of
driver file.
End Structure

<DllImport("hbaapi.dll")> _
Public Shared Function _
HBA_GetVersion() As Int32
End Function
<DllImport("hbaapi.dll")> _
Public Shared Function _
HBA_LoadLibrary() As Int32
End Function
<DllImport("hbaapi.dll")> _
Public Shared Function _
HBA_FreeLibrary() As Int32
End Function
<DllImport("hbaapi.dll")> _
Public Shared Function _
HBA_GetNumberOfAdapters() As Int32
End Function
<DllImport("hbaapi.dll")> _
Public Shared Function _
HBA_GetAdapterName(ByRef AdapterIndex As UInt32, ByRef AdapterName
As String) As Int32
End Function
<DllImport("hbaapi.dll")> _
Public Shared Function _
HBA_OpenAdapter(ByRef AdapterName As String) As Int32
End Function
<DllImport("hbaapi.dll")> _
Public Shared Function _
HBA_CloseAdapter(ByRef HandleName As Int32) As Int32
End Function
<DllImport("hbaapi.dll")> _
Public Shared Function _
HBA_GetAdapterAttributes(ByRef HandleName As Int32, ByRef
HBA_AdapterAttrib As HBA_AdapterAttributes) As Int32
End Function

End Class
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.