A WDM IEEE 1394 Configuration ROM Decoder
by William F. Alexander



Listing One
Device \\.\1394BUS0 in diagnostic mode
Found 1 devices on \\.\DUMPROMD
Device List:
Name = DumpRomD000, Port = 0000, Bus = 03FF, Node = 0000

Selected device: index=0,Name=\\.\DumpRomD000,Port=0000,Bus=03FF,Node=0000

Raw Data Dump of the Configuration ROM

1394 Addr Off    Data
-------------    --------  --------  --------  -------- 
FFFF:F0000400    04302F55  31333934  00FF5002  00A0B800  
FFFF:F0000410    00005009  0006E8D7  0C0083C0  0300A0B8  
FFFF:F0000420    81000011  0400500A  81000015  D1000001  
FFFF:F0000430    000C6208  1200609E  13010483  3C002600  
FFFF:F0000440    5400C000  3A401E08  3800609E  390104D8  
FFFF:F0000450    3B000000  3D000000  14000000  17000000  
FFFF:F0000460    8100000E  000568A5  00000000  00000000  
FFFF:F0000470    4C534920  4C6F6769  63000000  0006EBEF  
FFFF:F0000480    00000000  00000000  4C534920  35303120  
FFFF:F0000490    72657620  42330000  000AE09E  00000000  
FFFF:F00004A0    00000000  53594D31  33465735  30302D44  
FFFF:F00004B0    49534B20  44524956  45000000  00000000  
FFFF:F00004C0    00000000  

Decode of the Configuration ROM

1394 Addr Off Quadlet  Meaning
------------- -------- --------------------------------------------------

Confiruation ROM Header
FFFF:F0000400 04302F55 info_length=04, crc_length=30, rom_crc_value=2F55

Bus_Info_Block
FFFF:F0000404 31333934 bus_name=31333934 ("1394")
FFFF:F0000408 00FF5002 irmc=0, cmc=0, isc=0, bmc=0, cyc_clk_acc=FF, max_rec=5
FFFF:F000040C 00A0B800 node_vendor_id=00A0B8, chip_id_hi=00
FFFF:F0000410 00005009 chip_id_lo=00005009

Root_Directory
FFFF:F0000414 0006E8D7 length=0006, crc=E8D7
FFFF:F0000418 0C0083C0 Node_Capabilities spt 64 fix lst drg 
FFFF:F000041C 0300A0B8 Module_Vendor_Id 00A0B8
FFFF:F0000420 81000011 Textual_Descriptor leaf ind_off=000011 (FFFF:F0000464)
FFFF:F0000424 0400500A Module_Hw_Version 00500A
FFFF:F0000428 81000015 Textual_Descriptor leaf ind_off=000015 (FFFF:F000047C)
FFFF:F000042C D1000001 Unit_Directory directory ind_off=000001 (FFFF:F0000430)

Unit_Directory directory referenced from FFFF:F000042C
FFFF:F0000430 000C6208 length=000C, crc=6208
FFFF:F0000434 1200609E Unit_Spec_Id 00609E
FFFF:F0000438 13010483 Unit_Sw_Version 010483
FFFF:F000043C 3C002600 Firmware_Revision 002600
FFFF:F0000440 5400C000 Management_Agent crc_offset=00C000 (FFFF:F0030000)
FFFF:F0000444 3A401E08 Unit_Characteristics 401E08
FFFF:F0000448 3800609E Command_Set_Spec_Id 00609E
FFFF:F000044C 390104D8 Command_Set 0104D8
FFFF:F0000450 3B000000 Commanmd_Set_Revision 000000
FFFF:F0000454 3D000000 key=3D (UNKNOWN) value = 000000
FFFF:F0000458 14000000 Logical_Unit_Number o=0, device_type=00, lun=0000
FFFF:F000045C 17000000 Model_Id value = 000000
FFFF:F0000460 8100000E Textual_Descriptor leaf ind_off=00000E (FFFF:F0000498)

Textual_Descriptor leaf referenced from FFFF:F0000420
FFFF:F0000464 000568A5 length=0005, crc=68A5
FFFF:F0000468 00000000 ....
FFFF:F000046C 00000000 ....
FFFF:F0000470 4C534920 LSI 
FFFF:F0000474 4C6F6769 Logi
FFFF:F0000478 63000000 c...

Textual_Descriptor leaf referenced from FFFF:F0000428
FFFF:F000047C 0006EBEF length=0006, crc=EBEF
FFFF:F0000480 00000000 ....
FFFF:F0000484 00000000 ....
FFFF:F0000488 4C534920 LSI 
FFFF:F000048C 35303120 501 
FFFF:F0000490 72657620 rev 
FFFF:F0000494 42330000 B3..

Textual_Descriptor leaf referenced from FFFF:F0000460
FFFF:F0000498 000AE09E length=000A, crc=E09E
FFFF:F000049C 00000000 ....
FFFF:F00004A0 00000000 ....
FFFF:F00004A4 53594D31 SYM1
FFFF:F00004A8 33465735 3FW5
FFFF:F00004AC 30302D44 00-D
FFFF:F00004B0 49534B20 ISK 

FFFF:F00004B4 44524956 DRIV
FFFF:F00004B8 45000000 E...
FFFF:F00004BC 00000000 ....
FFFF:F00004C0 00000000 ....



Listing Two
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  DiagnoseAllAdapters
//      Puts/Takes all 1394 controllers into/out of diagnostics mode
//  Entry:
//      hWnd    Window handle
//      bMode   Mode flag
//              TRUE = turn on diagnostic mode
//              FALSE = turn off diagnostic mode
//  Exit:
//      TRUE    All 1394 adapters are in/out of diagnostic mode
//      FALSE   operation failed
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BOOL
DiagnoseAllAdapters (
    HWND hWnd, 
    BOOL bMode)
{
    //#define DEBUGFLAGS DebugThisRoutine

    BOOL            retcode;
    HANDLE          hDev;
    DWORD           dwRet;
    DWORD           dwBytesRet;
    CHAR            DeviceName[STRING_SIZE];
    DWORD           index;
    DWORD           numAdaptersToggled;

    DBOUT (DBG_LF_ENTRY, "DiagnoseAllAdapters\r\n");

    // Assume failure
    retcode = FALSE;

    // Get 1394 bus class driver's symbolic name
    strcpy (DeviceName, BUS_SYMBOLIC_LINK);
    pDiagnosticDeviceName = DeviceName;

    // Find all of the host controllers
    for(index = 0, numAdaptersToggled = 0; index < 10; index++)
    {
        // Create next host controller name
        pDiagnosticDeviceName[11] = (char)('0' + index);
        // try to open it
        //MyPrintf ("Attempting to open 1394 adapter %s  ...",
                                           pDiagnosticDeviceName);
        hDev = CreateFile(
                    pDiagnosticDeviceName,
                    GENERIC_WRITE | GENERIC_READ,
                    FILE_SHARE_WRITE | FILE_SHARE_READ,
                    NULL,
                    OPEN_EXISTING,
                    0,
                    NULL);
        if(hDev == INVALID_HANDLE_VALUE)
        {
            continue;
        }
        // Put into or take out of diagnostic mode
        dwRet = DeviceIoctl( hWnd, hDev, DeviceName,
            (bMode) ? IOCTL_1394_TOGGLE_ENUM_TEST_ON : 
            IOCTL_1394_TOGGLE_ENUM_TEST_OFF, NULL, 0, NULL, 0, &dwBytesRet);
        if (!dwRet)
        {
            dwRet = GetLastError();
            MyPrintf ("\r\nError = 0x%08X\r\n");
        }
        else
        {
            numAdaptersToggled++;
            if (bMode == TRUE)
                MyPrintf ("Device %s in diagnostic mode\r\n", DeviceName);
            else
             MyPrintf ("Device %s out of diagnostic mode\r\n", DeviceName);
        }
        // Close the current host controller
        CloseHandle(hDev);
    }
    // Did we toggle any adapters?
    if (numAdaptersToggled != 0)
        retcode = TRUE;
    DBOUT1 (DBG_LF_EXIT, "DiagnoseAllAdapters exit, retcode = %s\r\n",
                                          retcode==TRUE?"TRUE":"FALSE");
    return (retcode);

    #define DEBUGFLAGS DebugFlags
}


Listing Three
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  ConfirmDeviceAttached
//      Confirms that a diagnostic 1394 device is attached and ready to go.
//  Entry:
//      hWnd            Window handle
//      szDeviceName    Name of driver device to which a 
//                      diagnotic device should be attached.
//  Exit:
//      TRUE            Device is attached and ready
//      FALSE           No devices present
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BOOL 
ConfirmDeviceAttached (
    HWND hWnd, 
    PSTR szDeviceName)
{
    //#define DEBUGFLAGS DebugThisRoutine

    BOOL            retcode;
    HANDLE          hDev;
    DWORD           dwRet, dwBytesRet;
    PNODE_INFO      pNodeInfo;
    CHAR            tmpBuff[STRING_SIZE];
    ULONG           Node = 0L;
    ULONG           i;
     int ccode;

    DBOUT (DBG_LF_ENTRY, "ConfirmDeviceAttached\r\n");

    // Assume failure
    retcode = FALSE;
    
    // set this to no device under test
    numDevices = 0;
    hDev = INVALID_HANDLE_VALUE;

    // Open the adapter
    hDev = OpenDevice(hWnd, szDeviceName, TRUE);
    if(hDev == INVALID_HANDLE_VALUE)
        goto OpenError;

    // Allocate a buffer
    pNodeInfo = (PNODE_INFO) GlobalAlloc(GPTR, MAX_INFO_BUFF_SIZE);
    if(pNodeInfo == NULL)
        goto AllocError;
    // Extract node info
    dwRet = DeviceIoctl(hWnd, hDev, szDeviceName, GET_NODE_INFO, NULL, 0, 
                               pNodeInfo, MAX_INFO_BUFF_SIZE, &dwBytesRet);
    if(dwRet == 0)
        goto NodeInfoError;
    // let's go ahead and throw this in the edit control
    // get the number of current devices
    numDevices = pNodeInfo->numEntries;
    MyPrintf ("Found %d devices on %s\r\n", numDevices, szDeviceName);

    // allocate memory for keeping info about devices around
    // if we have device info get rid of it for new
    if(pDeviceInfo != NULL)
        GlobalFree(pDeviceInfo);
    // now allocate memory for device info on all devices
    pDeviceInfo = (PDEVICE_INFO) GlobalAlloc(GPTR, 
                                   sizeof(DEVICE_INFO) * numDevices);
    i = pNodeInfo->numEntries-1;
    
    // print out node info
    if (pNodeInfo->numEntries)
        MyPrintf ("Device List:\r\n");
    while(Node < pNodeInfo->numEntries)
    {
        // save device info in our freshly allocated buffer
        pDeviceInfo[i].nodeInfo = pNodeInfo->entry[Node];
        MyPrintf (  "Name = %s, Port = %04X, Bus = %04X, Node = %04X\r\n", 
                    pDeviceInfo[i].nodeInfo.LinkName, 
                    pDeviceInfo[i].nodeInfo.RawAddress.Port, 
                    pDeviceInfo[i].nodeInfo.RawAddress.NA_Bus_Number,
                    pDeviceInfo[i].nodeInfo.RawAddress.NA_Node_Number);
        // if it's a raw device then save that in link name
        // otherwise, fill in with real name
        if(strcmp(pDeviceInfo[i].nodeInfo.LinkName, RAW_DEVICE) != 0)
        {
            // it's not a raw device so let's stick stuff on front
            strcpy(tmpBuff, DEFAULT_DEVICE_LINK);
            strcpy(&tmpBuff[4], pDeviceInfo[i].nodeInfo.LinkName);
            strcpy(pDeviceInfo[i].nodeInfo.LinkName, tmpBuff);
            pDeviceInfo[i].bRawDevice = FALSE;
        }
        else
        {
            // just copy in global symbolic link
            strcpy(pDeviceInfo[i].nodeInfo.LinkName, GLOBAL_SYMBOLIC_LINK);
            pDeviceInfo[i].bRawDevice = TRUE;
        }
        // next node
        Node++;
        i--;
    }
    // Select a device and default to the first one
    deviceUnderTest = 0;
    if (pNodeInfo->numEntries > 1)
    {
        // Display device dialog box and let use chose one
        ccode = DialogBox((HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE), "SelectDevice", hWnd, (DLGPROC) SelectDeviceDlgProc);
        if (ccode != TRUE)
            goto Exit;

    }
    // Do we have any entries?
    if (pNodeInfo->numEntries)
        retcode = TRUE;
    // Display selected device
    i = deviceUnderTest;
    MyPrintf ("\r\n\r\nSelected device:  index = %d, Name = %s, 
           Port = %04X, Bus = %04X, Node = %04X\r\n", i,
                pDeviceInfo[i].nodeInfo.LinkName, 
                pDeviceInfo[i].nodeInfo.RawAddress.Port, 
                pDeviceInfo[i].nodeInfo.RawAddress.NA_Bus_Number,
                pDeviceInfo[i].nodeInfo.RawAddress.NA_Node_Number);
Exit:
    // free up resources
    if (hDev != INVALID_HANDLE_VALUE)
        CloseHandle(hDev);
    if(pNodeInfo)
        GlobalFree(pNodeInfo);
    DBOUT1 (DBG_LF_EXIT, "ConfirmDeviceAttached exit, retcode = %s\r\n", 
                                             retcode==TRUE?"TRUE":"FALSE");
    return (retcode);
OpenError:
   MyPrintf ("\r\nConfirmDeviceAttached: Unable to open %s\r\n",szDeviceName);
   goto Exit;
AllocError:
    MyPrintf ("\r\nConfirmDeviceAttached: Unable to allocate memory\r\n");
    goto Exit;
NodeInfoError:
    MyPrintf ("\r\nConfirmDeviceAttached: 
                               Unable to read node information from %s\r\n");
    goto Exit;

    #define DEBUGFLAGS DebugFlags
}





2


