这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » STM32 » 读取USB HDD(USB移动硬盘信息)序列号的代码

共2条 1/1 1 跳转至

读取USB HDD(USB移动硬盘信息)序列号的代码

高工
2017-12-24 12:14:31     打赏

读取USB HDD(USB移动硬盘)序列号的代码,型号及分位。

使用Visual Studio 2010编译成功。

代码使用了CrystalDiskInfo中的代码smartata.c中相关代码:

如下的连接解释了为何使用scsi的相关代码,需要USB IC的数据转换。


实现代码如下:


[cpp] view plain copy
  1. // DiskInfo.cpp : Defines the entry point for the console application.  

  2. //  

  3.   

  4. #include "stdafx.h"  

  5. #include <stdio.h>  

  6. #include <stdlib.h>  

  7. #include <windows.h>  

  8. #include <winioctl.h>  

  9. #include <stddef.h>  

  10. #include <memory.h>  

  11.   

  12. #define IOCTL_STORAGE_QUERY_PROPERTY   CTL_CODE(IOCTL_STORAGE_BASE, 0x0500, METHOD_BUFFERED, FILE_ANY_ACCESS)  

  13.   

  14. typedef struct _IDENTIFY_DEVICE{  

  15.         WORD        GeneralConfiguration;                   //0  

  16.         WORD        LogicalCylinders;                       //1 Obsolete  

  17.         WORD        SpecificConfiguration;                  //2  

  18.         WORD        LogicalHeads;                           //3 Obsolete  

  19.         WORD        Retired1[2];                            //4-5  

  20.         WORD        LogicalSectors;                         //6 Obsolete  

  21.         DWORD       ReservedForCompactFlash;                //7-8  

  22.         WORD        Retired2;                               //9  

  23.         CHAR        SerialNumber[20];                       //10-19  

  24.         WORD        Retired3;                               //20  

  25.         WORD        BufferSize;                             //21 Obsolete  

  26. //      WORD        Obsolute4;                              //22  

  27.         CHAR        FirmwareRev[8];                         //23-26  

  28.         CHAR        Model[40];                              //27-46  

  29.         WORD        MaxNumPerInterupt;                      //47  

  30.         WORD        Reserved1;                              //48  

  31.         WORD        Capabilities1;                          //49  

  32.         WORD        Capabilities2;                          //50  

  33.         DWORD       Obsolute5;                              //51-52  

  34.         WORD        Field88and7064;                         //53  

  35.         WORD        Obsolute6[5];                           //54-58  

  36.         WORD        MultSectorStuff;                        //59  

  37.         DWORD       TotalAddressableSectors;                //60-61  

  38.         WORD        Obsolute7;                              //62  

  39.         WORD        MultiWordDma;                           //63  

  40.         WORD        PioMode;                                //64  

  41.         WORD        MinMultiwordDmaCycleTime;               //65  

  42.         WORD        RecommendedMultiwordDmaCycleTime;       //66  

  43.         WORD        MinPioCycleTimewoFlowCtrl;              //67  

  44.         WORD        MinPioCycleTimeWithFlowCtrl;            //68  

  45.         WORD        Reserved2[6];                           //69-74  

  46.         WORD        QueueDepth;                             //75  

  47.         WORD        SerialAtaCapabilities;                  //76  

  48.         WORD        SerialAtaAdditionalCapabilities;        //77  

  49.         WORD        SerialAtaFeaturesSupported;             //78  

  50.         WORD        SerialAtaFeaturesEnabled;               //79  

  51.         WORD        MajorVersion;                           //80  

  52.         WORD        MinorVersion;                           //81  

  53.         WORD        CommandSetSupported1;                   //82  

  54.         WORD        CommandSetSupported2;                   //83  

  55.         WORD        CommandSetSupported3;                   //84  

  56.         WORD        CommandSetEnabled1;                     //85  

  57.         WORD        CommandSetEnabled2;                     //86  

  58.         WORD        CommandSetDefault;                      //87  

  59.         WORD        UltraDmaMode;                           //88  

  60.         WORD        TimeReqForSecurityErase;                //89  

  61.         WORD        TimeReqForEnhancedSecure;               //90  

  62.         WORD        CurrentPowerManagement;                 //91  

  63.         WORD        MasterPasswordRevision;                 //92  

  64.         WORD        HardwareResetResult;                    //93  

  65.         WORD        AcoustricManagement;                    //94  

  66.         WORD        StreamMinRequestSize;                   //95  

  67.         WORD        StreamingTimeDma;                       //96  

  68.         WORD        StreamingAccessLatency;                 //97  

  69.         DWORD       StreamingPerformance;                   //98-99  

  70.         ULONGLONG   MaxUserLba;                             //100-103  

  71.         WORD        StremingTimePio;                        //104  

  72.         WORD        Reserved3;                              //105  

  73.         WORD        SectorSize;                             //106  

  74.         WORD        InterSeekDelay;                         //107  

  75.         WORD        IeeeOui;                                //108  

  76.         WORD        UniqueId3;                              //109  

  77.         WORD        UniqueId2;                              //110  

  78.         WORD        UniqueId1;                              //111  

  79.         WORD        Reserved4[4];                           //112-115  

  80.         WORD        Reserved5;                              //116  

  81.         DWORD       WordsPerLogicalSector;                  //117-118  

  82.         WORD        Reserved6[8];                           //119-126  

  83.         WORD        RemovableMediaStatus;                   //127  

  84.         WORD        SecurityStatus;                         //128  

  85.         WORD        VendorSpecific[31];                     //129-159  

  86.         WORD        CfaPowerMode1;                          //160  

  87.         WORD        ReservedForCompactFlashAssociation[7];  //161-167  

  88.         WORD        DeviceNominalFormFactor;                //168  

  89.         WORD        DataSetManagement;                      //169  

  90.         WORD        AdditionalProductIdentifier[4];         //170-173  

  91.         WORD        Reserved7[2];                           //174-175  

  92.         CHAR        CurrentMediaSerialNo[60];               //176-205  

  93.         WORD        SctCommandTransport;                    //206  

  94.         WORD        ReservedForCeAta1[2];                   //207-208  

  95.         WORD        AlignmentOfLogicalBlocks;               //209  

  96.         DWORD       WriteReadVerifySectorCountMode3;        //210-211  

  97.         DWORD       WriteReadVerifySectorCountMode2;        //212-213  

  98.         WORD        NvCacheCapabilities;                    //214  

  99.         DWORD       NvCacheSizeLogicalBlocks;               //215-216  

  100.         WORD        NominalMediaRotationRate;               //217  

  101.         WORD        Reserved8;                              //218  

  102.         WORD        NvCacheOptions1;                        //219  

  103.         WORD        NvCacheOptions2;                        //220  

  104.         WORD        Reserved9;                              //221  

  105.         WORD        TransportMajorVersionNumber;            //222  

  106.         WORD        TransportMinorVersionNumber;            //223  

  107.         WORD        ReservedForCeAta2[10];                  //224-233  

  108.         WORD        MinimumBlocksPerDownloadMicrocode;      //234  

  109.         WORD        MaximumBlocksPerDownloadMicrocode;      //235  

  110.         WORD        Reserved10[19];                         //236-254  

  111.         WORD        IntegrityWord;                          //255  

  112. }IDENTIFY_DEVICE;  

  113.   

  114. typedef enum _COMMAND_TYPE  

  115.     {  

  116.         CMD_TYPE_PHYSICAL_DRIVE = 0,  

  117.         CMD_TYPE_SCSI_MINIPORT,  

  118.         CMD_TYPE_SILICON_IMAGE,  

  119.         CMD_TYPE_SAT,               // SAT = SCSI_ATA_TRANSLATION  

  120.         CMD_TYPE_SUNPLUS,  

  121.         CMD_TYPE_IO_DATA,  

  122.         CMD_TYPE_LOGITEC,  

  123.         CMD_TYPE_JMICRON,  

  124.         CMD_TYPE_CYPRESS,  

  125.         CMD_TYPE_PROLIFIC,          // Not imprement  

  126.         CMD_TYPE_CSMI,              // CSMI = Common Storage Management Interface  

  127.         CMD_TYPE_CSMI_PHYSICAL_DRIVE, // CSMI = Common Storage Management Interface   

  128.         CMD_TYPE_WMI,  

  129.         CMD_TYPE_DEBUG  

  130. }COMMAND_TYPE;  

  131.   

  132. // retrieve the properties of a storage device or adapter.  

  133. typedef enum _STORAGE_QUERY_TYPE {  

  134.   PropertyStandardQuery = 0,  

  135.   PropertyExistsQuery,  

  136.   PropertyMaskQuery,  

  137.   PropertyQueryMaxDefined  

  138. } STORAGE_QUERY_TYPE, *PSTORAGE_QUERY_TYPE;  

  139.   

  140.   

  141. // retrieve the properties of a storage device or adapter.  

  142.   

  143. typedef struct _STORAGE_PROPERTY_QUERY {  

  144.   STORAGE_PROPERTY_ID  PropertyId;  

  145.   STORAGE_QUERY_TYPE  QueryType;  

  146.   UCHAR  AdditionalParameters[1];  

  147. } STORAGE_PROPERTY_QUERY, *PSTORAGE_PROPERTY_QUERY;  

  148.   

  149. #define FILE_DEVICE_SCSI                            0x0000001b  

  150. #define IOCTL_SCSI_MINIPORT_IDENTIFY                ((FILE_DEVICE_SCSI << 16) + 0x0501)  

  151. #define IOCTL_SCSI_MINIPORT_READ_SMART_ATTRIBS      ((FILE_DEVICE_SCSI << 16) + 0x0502)  

  152. #define IOCTL_SCSI_MINIPORT_READ_SMART_THRESHOLDS   ((FILE_DEVICE_SCSI << 16) + 0x0503)  

  153. #define IOCTL_SCSI_MINIPORT_ENABLE_SMART            ((FILE_DEVICE_SCSI << 16) + 0x0504)  

  154. #define IOCTL_SCSI_MINIPORT_DISABLE_SMART           ((FILE_DEVICE_SCSI << 16) + 0x0505)  

  155.   

  156. #define IOCTL_SCSI_BASE                 FILE_DEVICE_CONTROLLER  

  157. #define IOCTL_SCSI_PASS_THROUGH         CTL_CODE(IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)  

  158.   

  159. //  

  160. // Define values for pass-through DataIn field.  

  161. //  

  162. #define SCSI_IOCTL_DATA_OUT          0  

  163. #define SCSI_IOCTL_DATA_IN           1  

  164. #define SCSI_IOCTL_DATA_UNSPECIFIED  2  

  165.   

  166. //  

  167. // Define the SCSI pass through structure.  

  168. //  

  169. typedef struct _SCSI_PASS_THROUGH {  

  170.     USHORT Length;  

  171.     UCHAR ScsiStatus;  

  172.     UCHAR PathId;  

  173.     UCHAR TargetId;  

  174.     UCHAR Lun;  

  175.     UCHAR CdbLength;  

  176.     UCHAR SenseInfoLength;  

  177.     UCHAR DataIn;  

  178.     ULONG DataTransferLength;  

  179.     ULONG TimeOutValue;  

  180.     ULONG_PTR DataBufferOffset;  

  181.     ULONG SenseInfoOffset;  

  182.     UCHAR Cdb[16];  

  183. }SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;  

  184.   

  185. typedef struct _SCSI_PASS_THROUGH_WITH_BUFFERS {  

  186. SCSI_PASS_THROUGH Spt;  

  187. ULONG             Filler;      // realign buffers to double word boundary  

  188. UCHAR             SenseBuf[32];  

  189. UCHAR             DataBuf[512];  

  190. } SCSI_PASS_THROUGH_WITH_BUFFERS, *PSCSI_PASS_THROUGH_WITH_BUFFERS;  

  191.   

  192. static void dump_buffer(const char* title, const unsigned char* buffer, int len)  

  193. {  

  194.    int i = 0;  

  195.    int j;  

  196.   

  197.    printf ("\n-- %s --\n", title);  

  198.    if (len > 0)  

  199.    {  

  200.       printf ("%8.8s "" ");  

  201.       for (j = 0; j < 16; ++j)  

  202.       {  

  203.         printf (" %2X", j);  

  204.       }  

  205.       printf ("  ");  

  206.       for (j = 0; j < 16; ++j)  

  207.       {  

  208.         printf ("%1X", j);  

  209.       }  

  210.       printf ("\n");  

  211.    }  

  212.    while (i < len)  

  213.    {  

  214.       printf("%08x ", i);  

  215.       for (j = 0; j < 16; ++j)  

  216.       {  

  217.      if ((i + j) < len)  

  218.         printf (" %02x", (int) buffer[i +j]);  

  219.      else  

  220.         printf ("   ");  

  221.       }  

  222.       printf ("  ");  

  223.       for (j = 0; j < 16; ++j)  

  224.       {  

  225.      if ((i + j) < len)  

  226.         printf ("%c", isprint (buffer[i + j]) ? buffer [i + j] : '.');  

  227.      else  

  228.         printf (" ");  

  229.       }  

  230.       printf ("\n");  

  231.       i += 16;  

  232.    }  

  233.    printf ("-- DONE --\n");  

  234. }  

  235.   

  236. void ChangeByteOrder(PCHAR szString, USHORT uscStrSize)  

  237. {  

  238.     USHORT i;  

  239.     CHAR temp;  

  240.   

  241.     for (i = 0; i < uscStrSize; i+=2)  

  242.     {  

  243.         temp = szString[i];  

  244.         szString[i] = szString[i+1];  

  245.         szString[i+1] = temp;  

  246.     }  

  247. }  

  248.   

  249. BOOL DoIdentifyDeviceSat(HANDLE physicalDriveId, BYTE target, IDENTIFY_DEVICE* data, COMMAND_TYPE type)  

  250. {  

  251.     BOOL    bRet;  

  252.     HANDLE  hIoCtrl;  

  253.     DWORD   dwReturned;  

  254.     DWORD   length;  

  255.   

  256.     SCSI_PASS_THROUGH_WITH_BUFFERS sptwb;  

  257.   

  258.     if(data == NULL)  

  259.     {  

  260.         printf("Data\n");  

  261.         return  FALSE;  

  262.     }  

  263.   

  264.     ZeroMemory(data, sizeof(IDENTIFY_DEVICE));  

  265.   

  266.     hIoCtrl = physicalDriveId;  

  267.     if(hIoCtrl == INVALID_HANDLE_VALUE)  

  268.     {  

  269.         printf("Handle\n");  

  270.         return  FALSE;  

  271.     }  

  272.   

  273.     ZeroMemory(&sptwb,sizeof(SCSI_PASS_THROUGH_WITH_BUFFERS));  

  274.   

  275.     sptwb.Spt.Length = sizeof(SCSI_PASS_THROUGH);  

  276.     sptwb.Spt.PathId = 0;  

  277.     sptwb.Spt.TargetId = 0;  

  278.     sptwb.Spt.Lun = 0;  

  279.     sptwb.Spt.SenseInfoLength = 24;  

  280.     sptwb.Spt.DataIn = SCSI_IOCTL_DATA_IN;  

  281.     sptwb.Spt.DataTransferLength = IDENTIFY_BUFFER_SIZE;  

  282.     sptwb.Spt.TimeOutValue = 2;  

  283.     sptwb.Spt.DataBufferOffset = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS, DataBuf);  

  284.     sptwb.Spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS, SenseBuf);  

  285.   

  286.     if(type == CMD_TYPE_SAT)  

  287.     {  

  288.         sptwb.Spt.CdbLength = 12;  

  289.         sptwb.Spt.Cdb[0] = 0xA1;//ATA PASS THROUGH(12) OPERATION CODE(A1h)  

  290.         sptwb.Spt.Cdb[1] = (4 << 1) | 0; //MULTIPLE_COUNT=0,PROTOCOL=4(PIO Data-In),Reserved  

  291.         sptwb.Spt.Cdb[2] = (1 << 3) | (1 << 2) | 2;//OFF_LINE=0,CK_COND=0,Reserved=0,T_DIR=1(ToDevice),BYTE_BLOCK=1,T_LENGTH=2  

  292.         sptwb.Spt.Cdb[3] = 0;//FEATURES (7:0)  

  293.         sptwb.Spt.Cdb[4] = 1;//SECTOR_COUNT (7:0)  

  294.         sptwb.Spt.Cdb[5] = 0;//LBA_LOW (7:0)  

  295.         sptwb.Spt.Cdb[6] = 0;//LBA_MID (7:0)  

  296.         sptwb.Spt.Cdb[7] = 0;//LBA_HIGH (7:0)  

  297.         sptwb.Spt.Cdb[8] = target;  

  298.         sptwb.Spt.Cdb[9] = 0xEC;//COMMAND  

  299.     }  

  300.     else if(type == CMD_TYPE_SUNPLUS)  

  301.     {  

  302.         sptwb.Spt.CdbLength = 12;  

  303.         sptwb.Spt.Cdb[0] = 0xF8;  

  304.         sptwb.Spt.Cdb[1] = 0x00;  

  305.         sptwb.Spt.Cdb[2] = 0x22;  

  306.         sptwb.Spt.Cdb[3] = 0x10;  

  307.         sptwb.Spt.Cdb[4] = 0x01;  

  308.         sptwb.Spt.Cdb[5] = 0x00;   

  309.         sptwb.Spt.Cdb[6] = 0x01;   

  310.         sptwb.Spt.Cdb[7] = 0x00;   

  311.         sptwb.Spt.Cdb[8] = 0x00;  

  312.         sptwb.Spt.Cdb[9] = 0x00;  

  313.         sptwb.Spt.Cdb[10] = target;   

  314.         sptwb.Spt.Cdb[11] = 0xEC; // ID_CMD  

  315.     }  

  316.     else if(type == CMD_TYPE_IO_DATA)  

  317.     {  

  318.         sptwb.Spt.CdbLength = 12;  

  319.         sptwb.Spt.Cdb[0] = 0xE3;  

  320.         sptwb.Spt.Cdb[1] = 0x00;  

  321.         sptwb.Spt.Cdb[2] = 0x00;  

  322.         sptwb.Spt.Cdb[3] = 0x01;  

  323.         sptwb.Spt.Cdb[4] = 0x01;  

  324.         sptwb.Spt.Cdb[5] = 0x00;   

  325.         sptwb.Spt.Cdb[6] = 0x00;   

  326.         sptwb.Spt.Cdb[7] = target;  

  327.         sptwb.Spt.Cdb[8] = 0xEC;  // ID_CMD  

  328.         sptwb.Spt.Cdb[9] = 0x00;  

  329.         sptwb.Spt.Cdb[10] = 0x00;   

  330.         sptwb.Spt.Cdb[11] = 0x00;  

  331.     }  

  332.     else if(type == CMD_TYPE_LOGITEC)  

  333.     {  

  334.         sptwb.Spt.CdbLength = 10;  

  335.         sptwb.Spt.Cdb[0] = 0xE0;  

  336.         sptwb.Spt.Cdb[1] = 0x00;  

  337.         sptwb.Spt.Cdb[2] = 0x00;  

  338.         sptwb.Spt.Cdb[3] = 0x00;  

  339.         sptwb.Spt.Cdb[4] = 0x00;  

  340.         sptwb.Spt.Cdb[5] = 0x00;   

  341.         sptwb.Spt.Cdb[6] = 0x00;   

  342.         sptwb.Spt.Cdb[7] = target;   

  343.         sptwb.Spt.Cdb[8] = 0xEC;  // ID_CMD  

  344.         sptwb.Spt.Cdb[9] = 0x4C;  

  345.     }  

  346.     else if(type == CMD_TYPE_JMICRON)  

  347.     {  

  348.         sptwb.Spt.CdbLength = 12;  

  349.         sptwb.Spt.Cdb[0] = 0xDF;  

  350.         sptwb.Spt.Cdb[1] = 0x10;  

  351.         sptwb.Spt.Cdb[2] = 0x00;  

  352.         sptwb.Spt.Cdb[3] = 0x02;  

  353.         sptwb.Spt.Cdb[4] = 0x00;  

  354.         sptwb.Spt.Cdb[5] = 0x00;   

  355.         sptwb.Spt.Cdb[6] = 0x01;   

  356.         sptwb.Spt.Cdb[7] = 0x00;   

  357.         sptwb.Spt.Cdb[8] = 0x00;  

  358.         sptwb.Spt.Cdb[9] = 0x00;  

  359.         sptwb.Spt.Cdb[10] = target;   

  360.         sptwb.Spt.Cdb[11] = 0xEC; // ID_CMD  

  361.     }  

  362.     else if(type == CMD_TYPE_CYPRESS)  

  363.     {  

  364.         sptwb.Spt.CdbLength = 16;  

  365.         sptwb.Spt.Cdb[0] = 0x24;  

  366.         sptwb.Spt.Cdb[1] = 0x24;  

  367.         sptwb.Spt.Cdb[2] = 0x00;  

  368.         sptwb.Spt.Cdb[3] = 0xBE;  

  369.         sptwb.Spt.Cdb[4] = 0x01;  

  370.         sptwb.Spt.Cdb[5] = 0x00;   

  371.         sptwb.Spt.Cdb[6] = 0x00;   

  372.         sptwb.Spt.Cdb[7] = 0x01;   

  373.         sptwb.Spt.Cdb[8] = 0x00;  

  374.         sptwb.Spt.Cdb[9] = 0x00;  

  375.         sptwb.Spt.Cdb[10] = 0x00;   

  376.         sptwb.Spt.Cdb[11] = target;  

  377.         sptwb.Spt.Cdb[12] = 0xEC; // ID_CMD  

  378.         sptwb.Spt.Cdb[13] = 0x00;  

  379.         sptwb.Spt.Cdb[14] = 0x00;  

  380.         sptwb.Spt.Cdb[15] = 0x00;  

  381.     }  

  382.     else  

  383.     {  

  384.         return FALSE;  

  385.     }  

  386.   

  387.     length = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS, DataBuf) + sptwb.Spt.DataTransferLength;  

  388.   

  389.     bRet = DeviceIoControl(hIoCtrl, IOCTL_SCSI_PASS_THROUGH,   

  390.         &sptwb, sizeof(SCSI_PASS_THROUGH),  

  391.         &sptwb, length, &dwReturned, NULL);  

  392.   

  393.     CloseHandle(hIoCtrl);  

  394.       

  395.     if(bRet == FALSE || dwReturned != length)  

  396.     {  

  397.         return  FALSE;  

  398.     }  

  399.   

  400.     memcpy(data, sptwb.DataBuf, sizeof(IDENTIFY_DEVICE));  

  401.   

  402.     return  TRUE;  

  403. }  

  404.   

  405.   

  406. int main(int argc, char *argv[]) {  

  407.     HANDLE hDevice=NULL;  

  408.     STORAGE_PROPERTY_QUERY      sQuery;  

  409.     STORAGE_DEVICE_DESCRIPTOR*  pDescriptor;  

  410.     char *model, *firmware, *serialnumber;  

  411.     char usb_hdd_model[41], usb_hdd_firmware[9], usb_hdd_Serialnumber[21];  

  412.     IDENTIFY_DEVICE identify = {0};  

  413.     char pcbData[4096];  

  414.     int dwLen = 4096;  

  415.     DWORD   dwRet;  

  416.     BOOL    bRet;  

  417.   

  418.     hDevice=CreateFileA("\\\\.\\PhysicalDrive1",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);  

  419.     if(hDevice==INVALID_HANDLE_VALUE)  

  420.     {     

  421.         fprintf(stderr, "CreateFile()\n");  

  422.         exit(1);      

  423.     }  

  424.   

  425.     memset(pcbData, 0, 4096);  

  426.     sQuery.PropertyId = StorageDeviceProperty;  

  427.     sQuery.QueryType  = PropertyStandardQuery;  

  428.       

  429.     bRet = DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY, &sQuery, sizeof(STORAGE_PROPERTY_QUERY), pcbData,dwLen,&dwRet,NULL);  

  430.     if(bRet){  

  431.         pDescriptor = (STORAGE_DEVICE_DESCRIPTOR*)pcbData;  

  432.         if(pDescriptor->BusType == BusTypeUsb)  

  433.         {  

  434.             printf("USB-Type\n");  

  435.         }  

  436.           

  437.         if(pDescriptor->ProductIdOffset)  

  438.         {  

  439.             model = (char*)pDescriptor + pDescriptor->ProductIdOffset;  

  440.             printf("Model: %s\n", model);  

  441.         }  

  442.         if(pDescriptor->ProductRevisionOffset)  

  443.         {  

  444.             firmware = (char*)pDescriptor + pDescriptor->ProductRevisionOffset;  

  445.             printf("Firmware: %s\n", firmware);  

  446.         }  

  447.         if(pDescriptor->SerialNumberOffset)  

  448.         {  

  449.             serialnumber = (char*)pDescriptor + pDescriptor->SerialNumberOffset;  

  450.             printf("Serial number: %s\n", serialnumber);  

  451.         }  

  452.     }  

  453. /* 

  454.         CMD_TYPE_SAT,               // SAT = SCSI_ATA_TRANSLATION 

  455.         CMD_TYPE_SUNPLUS, 

  456.         CMD_TYPE_IO_DATA, 

  457.         CMD_TYPE_LOGITEC, 

  458.         CMD_TYPE_JMICRON, 

  459.         CMD_TYPE_CYPRESS, 

  460. */  

  461.     if(DoIdentifyDeviceSat(hDevice, 0xa0, &identify, CMD_TYPE_SAT)){  

  462.         printf("0xA0-CMD_TYPE_SAT-Return ok");  

  463.     }     

  464.     else if(DoIdentifyDeviceSat(hDevice, 0xa0, &identify, CMD_TYPE_SUNPLUS)){  

  465.         printf("0xA0-CMD_TYPE_SUNPLUS-Return ok");  

  466.     }  

  467.     else if(DoIdentifyDeviceSat(hDevice, 0xa0, &identify, CMD_TYPE_IO_DATA)){  

  468.         printf("0xA0-CMD_TYPE_IO_DATA-Return ok");  

  469.     }  

  470.     else if(DoIdentifyDeviceSat(hDevice, 0xa0, &identify, CMD_TYPE_LOGITEC)){  

  471.         printf("0xA0-CMD_TYPE_LOGITEC-Return ok");  

  472.     }  

  473.     else if(DoIdentifyDeviceSat(hDevice, 0xa0, &identify, CMD_TYPE_JMICRON)){  

  474.         printf("0xA0-CMD_TYPE_JMICRON-Return ok");  

  475.     }  

  476.     else if(DoIdentifyDeviceSat(hDevice, 0xb0, &identify, CMD_TYPE_SAT)){  

  477.         printf("0xB0-CMD_TYPE_SAT-Return ok");  

  478.     }     

  479.     else if(DoIdentifyDeviceSat(hDevice, 0xb0, &identify, CMD_TYPE_SUNPLUS)){  

  480.         printf("0xB0-CMD_TYPE_SUNPLUS-Return ok");  

  481.     }  

  482.     else if(DoIdentifyDeviceSat(hDevice, 0xb0, &identify, CMD_TYPE_IO_DATA)){  

  483.         printf("0xB0-CMD_TYPE_IO_DATA-Return ok");  

  484.     }  

  485.     else if(DoIdentifyDeviceSat(hDevice, 0xb0, &identify, CMD_TYPE_LOGITEC)){  

  486.         printf("0xB0-CMD_TYPE_LOGITEC-Return ok");  

  487.     }  

  488.     else if(DoIdentifyDeviceSat(hDevice, 0xb0, &identify, CMD_TYPE_JMICRON)){  

  489.         printf("0xB0-CMD_TYPE_JMICRON-Return ok");  

  490.     }else{  

  491.         printf("Return ng\n");  

  492.     }  

  493.   

  494. #define debug 0  

  495. #if debug  

  496.     dump_buffer("data", (const unsigned char *)&identify, sizeof(IDENTIFY_DEVICE));  

  497. #endif  

  498.   

  499.     memcpy(usb_hdd_model, identify.Model, 40);  

  500.     ChangeByteOrder(usb_hdd_model, 40);  

  501.     usb_hdd_model[40]='\0';  

  502.   

  503.     memcpy(usb_hdd_firmware, identify.FirmwareRev, 8);  

  504.     ChangeByteOrder(usb_hdd_firmware, 8);  

  505.     usb_hdd_firmware[8]='\0';  

  506.   

  507.     memcpy(usb_hdd_Serialnumber, identify.SerialNumber, 20);  

  508.     ChangeByteOrder(usb_hdd_Serialnumber, 20);  

  509.     usb_hdd_Serialnumber[20]='\0';  

  510.   

  511.     printf("\nUSB-HDD   Model  name: %s", usb_hdd_model);  

  512.     printf("\nUSB-HDD Firmware  Rev: %s", usb_hdd_firmware);  

  513.     printf("\nUSB-HDD Serial number: %s", usb_hdd_Serialnumber);  

  514.     return 0;  

  515. }  




专家
2017-12-25 08:52:32     打赏
2楼

谢谢分享源码。


共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]