----------------------------------File Seperator------------------------------------------------------ // boms_defs.h #ifndef _BOMS_DEFS_H_ #define _BOMS_DEFS_H_ /* ** BOMS defitions for write blocker and impersonator projects ** ** This software released under Creative Commons 2.5 Share & share alike. ** ** Created by Philip A. Polstra, Sr. ** ** Part of the USB Mass Storage Device impersonator as presented at DEFCON 20 ** Based on USB Write blocker presented at Blackhat Europe 2012 */ // define the Command Block Wrapper for BOMS typedef struct _boms_cbw_t { unsigned char sig[4]; // "USBC" unsigned long tag; // used to associate CBW with CSW unsigned long dataTransferLength; // bytes for data transport phase unsigned char flags; // b7=0 OUT, b7=1 IN, all others zero unsigned char res1:4; // reserved must be zero unsigned char lun:4; unsigned char res2:3; // reserved must be zero unsigned char cbLength:5; //bytes in CB that actually mean anything union { unsigned char raw[16]; struct { unsigned char command; unsigned char parameters[15]; } formated; } cb; } boms_cbw_t; // define the Command Status Wrapper for BOMS typedef struct _boms_csw_t { unsigned char sig[4]; //"USBS" unsigned long tag; unsigned long residue; unsigned char status; // 0x00=success 0x01=failure 0x02=phase error } boms_csw_t; typedef union { unsigned char raw[18]; struct { unsigned char responseCode:7; //0x70 current error unsigned char valid:1; // 1=INFORMATION field valid unsigned char obsolete; unsigned char senseKey:4; // 0x05 for illegal request unsigned char resvered:1; unsigned char ili:1; // incorrect length indicator unsigned char eom:1; // end of media for streaming devices unsigned char filemark:1; // for streaming devices unsigned long information; // device specific info unsigned char addSenseLen; // additional bytes that follow 244 max unsigned long cmdSpecInfo; // command specific info unsigned char asc; // additional sense code 0x20 for illegal command unsigned char ascq; // additional sense code qualifier 0-unused unsigned char fruc; // field replaceable unit code set to 0 unsigned char senseKeySpecific[3]; //senses key spec info if b7=1 } formated; } request_sense_response_t; #endif ----------------------------------File Seperator------------------------------------------------------ // drives.h /* This file is based on Stephen J. Gowdy's list * It is used in the endpoint security bypass device by Philip A. Polstra, Sr. * March 2012 * This software released under Creative Commons 2.5 Share & share alike. ** Part of the USB Mass Storage Device impersonator as presented at DEFCON 20 ** Based on USB Write blocker presented at Blackhat Europe 2012 * # # List of USB ID's # # Maintained by Stephen J. Gowdy # If you have any new entries, please submit them via # http://www.linux-usb.org/usb-ids.html # or send entries as patches (diff -u old new) in the # body of your email (a bot will attempt to deal with it). # The latest version can be obtained from # http://www.linux-usb.org/usb.ids # # Version: 2012.02.08 # Date: 2012-02-08 20:34:02 # # Vendors, devices and interfaces. Please keep sorted. # Syntax: # vendor vendor_name # device device_name <-- single tab # interface interface_name <-- two tabs */ rom unsigned short vidPid[] = { 0x0204, // Chipsbank Microelectronics Co., Ltd 0x6025, // CBM2080 Flash drive controller 0x0204, // Chipsbank Microelectronics Co., Ltd 0x6026, // CBM1180 Flash drive controller 0x0324, // OCZ Technology Inc 0xbc06, // OCZ ATV USB 2.0 Flash Drive 0x0324, // OCZ Technology Inc 0xbc08, // OCZ Rally2/ATV USB 2.0 Flash Drive 0x0325, // OCZ Technology Inc 0xac02, // ATV Turbo / Rally2 Dual Channel USB 2.0 Flash Drive 0x03ee, // Mitsumi 0x0000, // CD-R/RW Drive 0x03ee, // Mitsumi 0x6901, // SmartDisk FDD 0x03ee, // Mitsumi 0x6902, // Floppy Disk Drive 0x0402, // ALi Corp. 0x5635, // M5635 Flash Card Reader 0x0404, // NCR Corp. 0x0323, // 5932-USB Enhanced Keyboard, Flash-Recovery/Download 0x0404, // NCR Corp. 0x0325, // 5953-USB Enhanced Dynakey Flash-Recovery/Download 0x0404, // NCR Corp. 0x032b, // K016/K018: USB-MSR Flash-Recovery/Download 0x0409, // NEC Corp. 0x002c, // Clik!-USB Drive 0x0411, // BUFFALO INC. (formerly MelCo., Inc.) 0x0089, // Buffalo RUF-C/U2 Flash Drive 0x0411, // BUFFALO INC. (formerly MelCo., Inc.) 0x00db, // External Hard Drive HD-PF32OU2 [Buffalo Ministation] 0x0411, // BUFFALO INC. (formerly MelCo., Inc.) 0x0157, // External Hard Drive HD-PEU2 0x0413, // Leadtek Research, Inc. 0x6126, // WinFast DTV Dongle BDA Driver 0x0416, // Winbond Electronics Corp. 0x0961, // AVL Flash Card Reader 0x041e, // Creative Technology, Ltd 0x410f, // NOMAD MuVo^2 (Flash) 0x0421, // Nokia Mobile Phones 0x0103, // ADL Flashing Engine AVALON Parent 0x0421, // Nokia Mobile Phones 0x0104, // ADL Re-Flashing Engine Parent 0x0426, // Integrated Device Technology, Inc. 0x0426, // WDM Driver 0x0457, // Silicon Integrated Systems Corp. 0x0150, // Super Talent 1GB Flash Drive 0x0457, // Silicon Integrated Systems Corp. 0x0151, // Super Flash 1GB / GXT 64MB Flash Drive 0x045e, // Microsoft Corp. 0x00ce, // Generic PPC Flash device 0x045e, // Microsoft Corp. 0x029c, // Xbox360 HD-DVD Drive 0x045e, // Microsoft Corp. 0x029d, // Xbox360 HD-DVD Drive 0x0471, // Philips (or NXP) 0x0844, // SA2111/02 1GB Flash Audio Player 0x0474, // Sanyo Electric Co., Ltd 0x0401, // Optical Drive 0x047f, // Plantronics, Inc. 0x0101, // Bulk Driver 0x047f, // Plantronics, Inc. 0x0301, // Bulk Driver 0x0480, // Toshiba America Info. Systems, Inc. 0xa007, // External Disk USB 3.0 0x0483, // SGS Thomson Microelectronics 0x2302, // Portable Flash Device (PFD) 0x0499, // Yamaha Corp. 0x6001, // CRW2200UX Lightspeed 2 External CD-RW Drive 0x04b4, // Cypress Semiconductor Corp. 0x4616, // Flash Disk (TPP) 0x04bb, // I-O Data Device, Inc. 0x0c01, // FM-10 Pro Disk 0x04d8, // Microchip Technology, Inc. 0x000b, // PIC18F2550 (32K Flashable 10 Channel, 10 Bit A/D USB Microcontroller) 0x04d8, // Microchip Technology, Inc. 0xfbba, // DiscFerret Magnetic Disc Analyser (bootloader mode) 0x04d8, // Microchip Technology, Inc. 0xfbbb, // DiscFerret Magnetic Disc Analyser (active mode) 0x04da, // Panasonic (Matsushita) 0x0b01, // CD-R/RW Drive 0x04da, // Panasonic (Matsushita) 0x0b03, // SuperDisk 240MB 0x04da, // Panasonic (Matsushita) 0x0d01, // CD-R Drive KXL-840AN 0x04da, // Panasonic (Matsushita) 0x0d09, // CD-R Drive KXL-RW32AN 0x04da, // Panasonic (Matsushita) 0x0d0a, // CD-R Drive KXL-CB20AN 0x04da, // Panasonic (Matsushita) 0x1500, // MFSUSB Driver 0x04da, // Panasonic (Matsushita) 0x2317, // DVC USB-SERIAL Driver for WinXP 0x04e6, // SCM Microsystems, Inc. 0x0005, // eUSB SmartMedia/CompactFlash Card Reader 0x04e6, // SCM Microsystems, Inc. 0x000a, // eUSB CompactFlash Adapter 0x04e6, // SCM Microsystems, Inc. 0x1010, // USBAT-2 CompactFlash Card Reader 0x04e8, // Samsung Electronics Co., Ltd 0x0100, // Kingston Flash Drive (128MB) 0x04e8, // Samsung Electronics Co., Ltd 0x0110, // Connect3D Flash Drive 0x04e8, // Samsung Electronics Co., Ltd 0x0111, // Connect3D Flash Drive 0x04e8, // Samsung Electronics Co., Ltd 0x60c4, // M2 Portable Hard Drive USB 3.0 0x04e8, // Samsung Electronics Co., Ltd 0x689a, // LTE Storage Driver [CMC2xx] 0x04e8, // Samsung Electronics Co., Ltd 0xe022, // SERI E02 SCOM 6200 Flash Load Disk 0x04f9, // Brother Industries, Ltd 0x0132, // MFC-5200C RemovableDisk 0x04f9, // Brother Industries, Ltd 0x013e, // MFC-4420C RemovableDisk 0x04f9, // Brother Industries, Ltd 0x013f, // MFC-4820C RemovableDisk 0x04f9, // Brother Industries, Ltd 0x0144, // DCP-4020C RemovableDisk 0x04f9, // Brother Industries, Ltd 0x0163, // MFC-410CN RemovableDisk 0x04f9, // Brother Industries, Ltd 0x0166, // MFC-610CLN RemovableDisk 0x04f9, // Brother Industries, Ltd 0x0169, // DCP-110C RemovableDisk 0x04f9, // Brother Industries, Ltd 0x016b, // DCP-310CN RemovableDisk 0x04f9, // Brother Industries, Ltd 0x0174, // MFC-3340CN RemovableDisk 0x04f9, // Brother Industries, Ltd 0x01ae, // DCP-750CW RemovableDisk 0x04f9, // Brother Industries, Ltd 0x01be, // DCP-750CN RemovableDisk 0x04fc, // Sunplus Technology Co., Ltd 0x5720, // Card Reader Driver 0x0506, // 3Com Corp. 0x0100, // HomeConnect ADSL Modem Driver 0x050d, // Belkin Components 0x0249, // USB 2 Flash Media Device 0x0525, // Netchip Technology, Inc. 0xa141, // (OME) PocketZip 40 MP3 Player Driver 0x052b, // Tekom Technologies, Inc. 0x2203, // Sound Vision Stream Driver 0x0543, // ViewSonic Corp. 0x1e60, // TA310 - ATSC/NTSC/PAL Driver(PCM4) 0x0546, // Polaroid Corp. 0xdccf, // Sound Vision Stream Driver 0x0548, // Tyan Computer Corp. 0x1005, // EZ Cart II GameBoy Flash Programmer 0x054c, // Sony Corp. 0x002c, // USB Floppy Disk Drive 0x054c, // Sony Corp. 0x01d0, // DVD+RW External Drive DRU-700A 0x054c, // Sony Corp. 0x023b, // DVD+RW External Drive DRU-800UL 0x054c, // Sony Corp. 0x0243, // MicroVault Flash Drive 0x054c, // Sony Corp. 0x02a5, // MicroVault Flash Drive 0x055d, // Samsung Electro-Mechanics Co. 0x2020, // Floppy Disk Drive 0x056e, // Elecom Co., Ltd 0x6008, // Flash Disk 0x057b, // Y-E Data, Inc. 0x0000, // FlashBuster-U Floppy 0x057b, // Y-E Data, Inc. 0x0020, // HEXA Media Drive 6-in-1 Card Reader Writer 0x058c, // In Focus Systems 0x0007, // Flash 0x058f, // Alcor Micro Corp. 0x1234, // Flash Drive 0x058f, // Alcor Micro Corp. 0x6232, // Hi-Speed 16-in-1 Flash Card Reader/Writer 0x058f, // Alcor Micro Corp. 0x6362, // Flash Card Reader/Writer 0x058f, // Alcor Micro Corp. 0x6366, // Multi Flash Reader 0x058f, // Alcor Micro Corp. 0x6387, // Transcend JetFlash Flash Drive 0x058f, // Alcor Micro Corp. 0x9320, // Micro Storage Driver for Win98 0x058f, // Alcor Micro Corp. 0x9321, // Micro Storage Driver for Win98 0x058f, // Alcor Micro Corp. 0x9331, // Micro Storage Driver for Win98 0x058f, // Alcor Micro Corp. 0x9380, // Flash Drive 0x058f, // Alcor Micro Corp. 0x9382, // Acer/Sweex Flash drive 0x058f, // Alcor Micro Corp. 0x9384, // qdi U2Disk T209M 0x059b, // Iomega Corp. 0x0021, // Win98 Disk Controller 0x059b, // Iomega Corp. 0x0034, // Zip 100 Driver 0x059b, // Iomega Corp. 0x0053, // CDRW55292EXT CD-RW External Drive 0x059b, // Iomega Corp. 0x005f, // CDRW64892EXT3-C CD-RW 52x24x52x External Drive 0x059b, // Iomega Corp. 0x007e, // Mini 256MB/512MB Flash Drive [IOM2D5] 0x059b, // Iomega Corp. 0x00db, // FotoShow Zip 250 Driver 0x059b, // Iomega Corp. 0x027a, // LPHD250-U [Portable Hard Drive Silver Series 250 Go] 0x059b, // Iomega Corp. 0x0470, // Prestige Portable Hard Drive 0x059b, // Iomega Corp. 0x047a, // Select Portable Hard Drive 0x059b, // Iomega Corp. 0x0579, // eGo Portable Hard Drive 0x059b, // Iomega Corp. 0x1052, // DVD+RW External Drive 0x059f, // LaCie, Ltd 0x0201, // StudioDrive USB2 0x059f, // LaCie, Ltd 0x0202, // StudioDrive USB2 0x059f, // LaCie, Ltd 0x0203, // StudioDrive USB2 0x059f, // LaCie, Ltd 0x0211, // PocketDrive 0x059f, // LaCie, Ltd 0x0212, // PocketDrive 0x059f, // LaCie, Ltd 0x0213, // PocketDrive USB2 0x059f, // LaCie, Ltd 0x0323, // LaCie d2 Drive USB2 0x059f, // LaCie, Ltd 0x0421, // Big Disk G465 0x059f, // LaCie, Ltd 0x0641, // Mobile Hard Drive 0x059f, // LaCie, Ltd 0x1010, // Desktop Hard Drive 0x059f, // LaCie, Ltd 0x1019, // Desktop Hard Drive 0x059f, // LaCie, Ltd 0x1021, // Little Disk 0x059f, // LaCie, Ltd 0x102a, // Rikiki Hard Drive 0x059f, // LaCie, Ltd 0xa601, // HardDrive 0x05ab, // In-System Design 0x0130, // Compact Flash and Microdrive Reader (TPP) 0x05ab, // In-System Design 0x0300, // Portable Hard Drive (TPP) 0x05ab, // In-System Design 0x0301, // Portable Hard Drive V2 0x05ab, // In-System Design 0x0350, // Portable Hard Drive (TPP) 0x05ab, // In-System Design 0x0351, // Portable Hard Drive V2 0x05ac, // Apple, Inc. 0xffff, // Bluetooth in DFU mode - Driver 0x05da, // Microtek International, Inc. 0x1043, // Take-It 1300 DSC Bulk Driver 0x05dc, // Lexar Media, Inc. 0x0001, // jumpSHOT CompactFlash Reader 0x05dc, // Lexar Media, Inc. 0x0081, // RBC Compact Flash Drive 0x05dc, // Lexar Media, Inc. 0x00a7, // JumpDrive Impact 0x05dc, // Lexar Media, Inc. 0x0100, // JumpDrive PRO 0x05dc, // Lexar Media, Inc. 0x0200, // JumpDrive 2.0 Pro 0x05dc, // Lexar Media, Inc. 0x0301, // JumpDrive Classic 0x05dc, // Lexar Media, Inc. 0x0310, // JumpDrive 0x05dc, // Lexar Media, Inc. 0x0311, // JumpDrive Classic 0x05dc, // Lexar Media, Inc. 0x0320, // JumpDrive 0x05dc, // Lexar Media, Inc. 0x0330, // JumpDrive Expression 0x05dc, // Lexar Media, Inc. 0x0340, // JumpDrive TAD 0x05dc, // Lexar Media, Inc. 0x0410, // JumpDrive 0x05dc, // Lexar Media, Inc. 0x0411, // JumpDrive 0x05dc, // Lexar Media, Inc. 0x0420, // JumpDrive 0x05dc, // Lexar Media, Inc. 0x0421, // JumpDrive 0x05dc, // Lexar Media, Inc. 0xa300, // JumpDrive2 0x05dc, // Lexar Media, Inc. 0xa400, // JumpDrive trade; Pro 40-501 0x05dc, // Lexar Media, Inc. 0xa410, // JumpDrive 128MB/256MB 0x05dc, // Lexar Media, Inc. 0xa411, // JumpDrive Traveler 0x05dc, // Lexar Media, Inc. 0xa420, // JumpDrive Pro 0x05dc, // Lexar Media, Inc. 0xa421, // JumpDrive Pro II 0x05dc, // Lexar Media, Inc. 0xa422, // JumpDrive Micro Pro 0x05dc, // Lexar Media, Inc. 0xa430, // JumpDrive Secure 0x05dc, // Lexar Media, Inc. 0xa431, // JumpDrive Secure II 0x05dc, // Lexar Media, Inc. 0xa432, // JumpDrive Classic 0x05dc, // Lexar Media, Inc. 0xa440, // JumpDrive Lightning 0x05dc, // Lexar Media, Inc. 0xa450, // JumpDrive TouchGuard 0x05dc, // Lexar Media, Inc. 0xa501, // JumpDrive Classic 0x05dc, // Lexar Media, Inc. 0xa510, // JumpDrive Sport 0x05dc, // Lexar Media, Inc. 0xa530, // JumpDrive Expression 0x05dc, // Lexar Media, Inc. 0xa531, // JumpDrive Secure II 0x05dc, // Lexar Media, Inc. 0xa560, // JumpDrive FireFly 0x05dc, // Lexar Media, Inc. 0xa701, // JumpDrive FireFly 0x05dc, // Lexar Media, Inc. 0xa731, // JumpDrive FireFly 0x05dc, // Lexar Media, Inc. 0xa790, // JumpDrive 2GB 0x05e3, // Genesys Logic, Inc. 0x0700, // SIIG US2256 CompactFlash Card Reader 0x05e3, // Genesys Logic, Inc. 0x070a, // Pen Flash 0x05e3, // Genesys Logic, Inc. 0x070f, // Pen Flash 0x05e3, // Genesys Logic, Inc. 0x0723, // GL827L SD/MMC/MS Flash Card Reader 0x05e3, // Genesys Logic, Inc. 0x07a0, // Pen Flash 0x05e3, // Genesys Logic, Inc. 0xa700, // Pen Flash 0x0619, // Seiko Instruments, Inc. 0x0101, // SLP-100 Driver 0x0619, // Seiko Instruments, Inc. 0x0102, // SLP-200 Driver 0x0619, // Seiko Instruments, Inc. 0x0103, // SLP-100N Driver 0x0619, // Seiko Instruments, Inc. 0x0104, // SLP-200N Driver 0x0619, // Seiko Instruments, Inc. 0x0105, // SLP-240 Driver 0x0619, // Seiko Instruments, Inc. 0x0501, // SLP-440 Driver 0x0619, // Seiko Instruments, Inc. 0x0502, // SLP-450 Driver 0x061a, // Veridicom International, Inc. 0x8200, // VKI-A Fingerprint Sensor/Flash Storage (dumb) 0x061a, // Veridicom International, Inc. 0x9200, // VKI-B Fingerprint Sensor/Flash Storage (smart) 0x0644, // TEAC Corp. 0x1000, // CD-ROM Drive 0x0667, // Aiwa Co., Ltd 0x0fa1, // TD-U8000 Tape Drive 0x066b, // Linksys, Inc. 0x010a, // Melco MCR-U2 SmartMedia / CompactFlash Reader 0x0677, // Aiwa Co., Ltd 0x0fa1, // TD-U8000 Tape Drive 0x067b, // Prolific Technology, Inc. 0x2315, // Flash Disk Embedded Hub 0x067b, // Prolific Technology, Inc. 0x2316, // Flash Disk Security Device 0x067b, // Prolific Technology, Inc. 0x2515, // Flash Disk Embedded Hub 0x067b, // Prolific Technology, Inc. 0x3400, // Hi-Speed Flash Disk with TruePrint AES3400 0x067b, // Prolific Technology, Inc. 0x3500, // Hi-Speed Flash Disk with TruePrint AES3500 0x0693, // Hagiwara Sys-Com Co., Ltd 0x0002, // FlashGate SmartMedia Card Reader 0x0693, // Hagiwara Sys-Com Co., Ltd 0x0003, // FlashGate CompactFlash Card Reader 0x0693, // Hagiwara Sys-Com Co., Ltd 0x0005, // FlashGate 0x0693, // Hagiwara Sys-Com Co., Ltd 0x0007, // FlashGate ME (Authenticated) 0x06d6, // Aashima Technology B.V. 0x003f, // Trust 735S POWERC@M ZOOM, WDM DSC Bulk Driver 0x0718, // Imation Corp. 0x0002, // SuperDisk 120MB 0x0718, // Imation Corp. 0x0003, // SuperDisk 120MB (Authenticated) 0x0718, // Imation Corp. 0x0060, // Flash Drive 0x0718, // Imation Corp. 0x0061, // Flash Drive 0x0718, // Imation Corp. 0x0062, // Flash Drive 0x0718, // Imation Corp. 0x0063, // Swivel Flash Drive 0x0718, // Imation Corp. 0x0064, // Flash Drive 0x0718, // Imation Corp. 0x0065, // Flash Drive 0x0718, // Imation Corp. 0x0066, // Flash Drive 0x0718, // Imation Corp. 0x0067, // Flash Drive 0x0718, // Imation Corp. 0x0068, // Flash Drive 0x0718, // Imation Corp. 0x0084, // Flash Drive Mini 0x0718, // Imation Corp. 0x0582, // Revo Flash Drive 0x0718, // Imation Corp. 0xd000, // Disc Stakka CD/DVD Manager 0x072f, // Advanced Card Systems, Ltd 0x1000, // PLDT Drive 0x072f, // Advanced Card Systems, Ltd 0x1001, // PLDT Drive 0x0781, // SanDisk Corp. 0x0001, // SDDR-05a ImageMate CompactFlash Reader 0x0781, // SanDisk Corp. 0x0002, // SDDR-31 ImageMate II CompactFlash Reader 0x0781, // SanDisk Corp. 0x0005, // SDDR-05b (CF II) ImageMate CompactFlash Reader 0x0781, // SanDisk Corp. 0x1234, // Cruzer Mini Flash Drive 0x0781, // SanDisk Corp. 0x5150, // SDCZ2 Cruzer Mini Flash Drive (thin) 0x0781, // SanDisk Corp. 0x5151, // Cruzer Micro Flash Drive 0x0781, // SanDisk Corp. 0x5153, // Cruzer Flash Drive 0x0781, // SanDisk Corp. 0x540e, // Cruzer Contour Flash Drive 0x0781, // SanDisk Corp. 0x7101, // Pen Flash 0x0781, // SanDisk Corp. 0x7104, // Cruzer Micro Mini 256MB Flash Drive 0x0781, // SanDisk Corp. 0x7112, // Cruzer Micro 128MB Flash Drive 0x0781, // SanDisk Corp. 0x7113, // Cruzer Micro 256MB Flash Drive 0x0781, // SanDisk Corp. 0x8181, // Pen Flash 0x0781, // SanDisk Corp. 0x8185, // SDCZ2 Cruzer Mini Flash Drive (older, thick) 0x07ab, // Freecom Technologies 0xfcf8, // Freecom Classic SL Network Drive 0x07ab, // Freecom Technologies 0xfcfe, // Hard Drive 80GB 0x07af, // Microtech 0x0006, // CameraMate SmartMedia and CompactFlash Card Reader [eusb/shuttle] 0x07b8, // AboCom Systems Inc 0xb02c, // BCM92045DG-Flash with trace filter 0x07b8, // AboCom Systems Inc 0xb02d, // BCM92045DG-Flash with trace filter 0x07b8, // AboCom Systems Inc 0xb02e, // BCM92045DG-Flash with trace filter 0x07b8, // AboCom Systems Inc 0xb030, // BCM92045DG-Flash with trace filter 0x07b8, // AboCom Systems Inc 0xb031, // BCM92045DG-Flash with trace filter 0x07b8, // AboCom Systems Inc 0xb032, // BCM92045DG-Flash with trace filter 0x07b8, // AboCom Systems Inc 0xb033, // BCM92045DG-Flash with trace filter 0x07b8, // AboCom Systems Inc 0xe4f0, // Card Reader Driver 0x07c4, // Datafab Systems, Inc. 0xa000, // CompactFlash Card Reader 0x07c4, // Datafab Systems, Inc. 0xa001, // CompactFlash & SmartMedia Card Reader [eusb] 0x07c4, // Datafab Systems, Inc. 0xa002, // Disk Drive 0x07c4, // Datafab Systems, Inc. 0xa004, // USB to MMC Class Drive 0x07c4, // Datafab Systems, Inc. 0xa005, // CompactFlash & SmartMedia Card Reader 0x07c4, // Datafab Systems, Inc. 0xa007, // Memory Stick Class Drive 0x07c4, // Datafab Systems, Inc. 0xa107, // USB to Memory Stick (LC1) Drive 0x07c4, // Datafab Systems, Inc. 0xa109, // LC1 CompactFlash & SmartMedia Card Reader 0x07c4, // Datafab Systems, Inc. 0xa400, // CompactFlash & Microdrive Reader 0x07c4, // Datafab Systems, Inc. 0xb00a, // USB to CF+SD Drive(LC1) 0x07d0, // Dazzle 0x2001, // eUSB CompactFlash Reader 0x07f7, // Century Corp. 0x011e, // Century USB Disk Enclosure 0x07ff, // Unknown 0x00ff, // Portable Hard Drive 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x1002, // Eumex 504PC (FlashLoad) 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x1004, // TA33 (FlashLoad) 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x1006, // Eumex 604PC HomeNet (FlashLoad) 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x1008, // Eumex 704PC DSL (FlashLoad) 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x100a, // Eumex 724PC DSL (FlashLoad) 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x100c, // OpenCom 30 (FlashLoad) 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x100e, // BeeTel Home 100 (FlashLoad) 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x1012, // USB2DECT (FlashLoad) 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x1014, // Eumex 704PC LAN (FlashLoad) 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x101a, // Eumex 504 SE (Flash-Mode) 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x1022, // OpenCom 40 (FlashLoad) 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x1024, // OpenCom 45 (FlashLoad) 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x102c, // Eumex 604PC HomeNet [FlashLoad] 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x1030, // Eumex 704PC DSL [FlashLoad] 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x1032, // OpenCom 40 [FlashLoad] 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x1034, // OpenCom 30 plus (FlashLoad) 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x1042, // Eumex 220PC (FlashMode) 0x086c, // DeTeWe - Deutsche Telephonwerke AG & Co. 0x1056, // Eumex 220 Version 2 ISDN TA (Flash-Mode) 0x0871, // SanDisk, Inc. 0x0001, // SDDR-01 Compact Flash Reader 0x0871, // SanDisk, Inc. 0x0002, // SDDR-31 Compact Flash Reader 0x0871, // SanDisk, Inc. 0x0005, // SDDR-05 Compact Flash Reader 0x08ca, // Aiptek International, Inc. 0x0100, // Pen Drive 0x08ca, // Aiptek International, Inc. 0x0105, // Mega DV(Disk) 0x08ca, // Aiptek International, Inc. 0x2043, // Pocket DV5100M (Disk) 0x08ea, // Ericsson, Inc., Blue Ridge Labs 0xabba, // USB Driver for Bluetooth Wireless Technology 0x08ec, // M-Systems Flash Disk Pioneers 0x0001, // TravelDrive 2C 0x08ec, // M-Systems Flash Disk Pioneers 0x0002, // TravelDrive 2C 0x08ec, // M-Systems Flash Disk Pioneers 0x0005, // TravelDrive 2C 0x08ec, // M-Systems Flash Disk Pioneers 0x0008, // TravelDrive 2C 0x08ec, // M-Systems Flash Disk Pioneers 0x0010, // DiskOnKey 0x08ec, // M-Systems Flash Disk Pioneers 0x0011, // DiskOnKey 0x08ec, // M-Systems Flash Disk Pioneers 0x0012, // TravelDrive 2C 0x08ec, // M-Systems Flash Disk Pioneers 0x0014, // TravelDrive 2C 0x08ec, // M-Systems Flash Disk Pioneers 0x0020, // TravelDrive 0x08ec, // M-Systems Flash Disk Pioneers 0x0021, // TravelDrive 0x08ec, // M-Systems Flash Disk Pioneers 0x0022, // TravelDrive 0x08ec, // M-Systems Flash Disk Pioneers 0x0023, // TravelDrive 0x08ec, // M-Systems Flash Disk Pioneers 0x0024, // TravelDrive 0x08ec, // M-Systems Flash Disk Pioneers 0x0025, // TravelDrive 0x08ec, // M-Systems Flash Disk Pioneers 0x0026, // TravelDrive 0x08ec, // M-Systems Flash Disk Pioneers 0x0027, // TravelDrive 0x08ec, // M-Systems Flash Disk Pioneers 0x0028, // TravelDrive 0x08ec, // M-Systems Flash Disk Pioneers 0x0029, // TravelDrive 0x08ec, // M-Systems Flash Disk Pioneers 0x0030, // TravelDrive 0x08ec, // M-Systems Flash Disk Pioneers 0x0822, // TravelDrive 2C 0x08ec, // M-Systems Flash Disk Pioneers 0x0834, // M-Disk 220 0x08ec, // M-Systems Flash Disk Pioneers 0x0998, // Kingston Data Traveler2.0 Disk Driver 0x08ec, // M-Systems Flash Disk Pioneers 0x0999, // Kingston Data Traveler2.0 Disk Driver 0x08ec, // M-Systems Flash Disk Pioneers 0x1000, // TravelDrive 2C 0x08ec, // M-Systems Flash Disk Pioneers 0x2000, // TravelDrive 2C 0x08ec, // M-Systems Flash Disk Pioneers 0x2038, // TravelDrive 0x08ec, // M-Systems Flash Disk Pioneers 0x2039, // TravelDrive 0x08ec, // M-Systems Flash Disk Pioneers 0x204a, // TravelDrive 0x08ec, // M-Systems Flash Disk Pioneers 0x204b, // TravelDrive 0x0901, // VST Technologies 0x0001, // Hard Drive Adapter (TPP) 0x0901, // VST Technologies 0x0002, // SigmaDrive Adapter (TPP) 0x090a, // Trumpion Microelectronics, Inc. 0x1001, // T33520 Flash Card Controller 0x090a, // Trumpion Microelectronics, Inc. 0x1540, // Digitex Container Flash Disk 0x090c, // Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) 0x6000, // SD/SDHC Card Reader (SG365 / FlexiDrive XC+) 0x0917, // SmartDisk Corp. 0x0204, // FlashTrax Storage 0x0930, // Toshiba Corp. 0x642f, // TravelDrive 0x0930, // Toshiba Corp. 0x6506, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x6507, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x6508, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x6509, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x6510, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x6517, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x6518, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x651a, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x651b, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x651c, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x651d, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x651e, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x651f, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x6520, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x6521, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x6522, // TravelDrive 2C 0x0930, // Toshiba Corp. 0x6523, // TravelDrive 0x0930, // Toshiba Corp. 0x6524, // TravelDrive 0x0930, // Toshiba Corp. 0x6525, // TravelDrive 0x0930, // Toshiba Corp. 0x6526, // TravelDrive 0x0930, // Toshiba Corp. 0x6527, // TravelDrive 0x0930, // Toshiba Corp. 0x6528, // TravelDrive 0x0930, // Toshiba Corp. 0x6529, // TravelDrive 0x0930, // Toshiba Corp. 0x652a, // TravelDrive 0x0930, // Toshiba Corp. 0x652b, // TravelDrive 0x0930, // Toshiba Corp. 0x652c, // TravelDrive 0x0930, // Toshiba Corp. 0x652d, // TravelDrive 0x0930, // Toshiba Corp. 0x652f, // TravelDrive 0x0930, // Toshiba Corp. 0x6530, // TravelDrive 0x0930, // Toshiba Corp. 0x6531, // TravelDrive 0x0930, // Toshiba Corp. 0x6534, // TravelDrive 0x0930, // Toshiba Corp. 0x653e, // Flash Memory 0x0930, // Toshiba Corp. 0x6540, // TransMemory Flash Memory 0x0930, // Toshiba Corp. 0x6545, // Kingston DataTraveler 102 Flash Drive / HEMA Flash Drive 2 GB / PNY Attache 4GB Stick 0x0951, // Kingston Technology 0x1600, // DataTraveler II Pen Drive 0x0951, // Kingston Technology 0x1601, // DataTraveler II+ Pen Drive 0x0951, // Kingston Technology 0x1603, // DataTraveler 1GB/2GB Pen Drive 0x0951, // Kingston Technology 0x1613, // DataTraveler DT101C Flash Drive 0x0951, // Kingston Technology 0x1624, // DataTraveler G2 4GB Pen Drive 0x0951, // Kingston Technology 0x162a, // DataTraveler 112 4GB Pen Drive 0x0984, // Apricorn 0x0200, // Hard Drive Storage (TPP) 0x09ef, // Xitel 0x0101, // MD-Port DG2 MiniDisc Interface 0x0a12, // Cambridge Silicon Radio, Ltd 0x0101, // Casira with BlueCore2-Flash Module 0x0a12, // Cambridge Silicon Radio, Ltd 0x0103, // Casira with BlueCore3-Flash Module 0x0a16, // Trek Technology (S) PTE, Ltd 0x1111, // ThumbDrive 0x0a4d, // Evolution Electronics, Ltd 0x0064, // MK-225 Driver 0x0a4d, // Evolution Electronics, Ltd 0x0065, // MK-225C Driver 0x0a4d, // Evolution Electronics, Ltd 0x0066, // MK-225C Driver 0x0a4d, // Evolution Electronics, Ltd 0x0067, // MK-425C Driver 0x0a4d, // Evolution Electronics, Ltd 0x0078, // MK-37 Driver 0x0a4d, // Evolution Electronics, Ltd 0x0079, // MK-37C Driver 0x0a4d, // Evolution Electronics, Ltd 0x007a, // MK-37C Driver 0x0a4d, // Evolution Electronics, Ltd 0x008d, // MK-249C Driver 0x0a4d, // Evolution Electronics, Ltd 0x008f, // MK-449C Driver 0x0a4d, // Evolution Electronics, Ltd 0x0090, // Keystation 49e Driver 0x0a4d, // Evolution Electronics, Ltd 0x0091, // Keystation 61es Driver 0x0a4d, // Evolution Electronics, Ltd 0x00a0, // MK-361 Driver 0x0a4d, // Evolution Electronics, Ltd 0x00a1, // MK-361C Driver 0x0a4d, // Evolution Electronics, Ltd 0x00a2, // MK-361C Driver 0x0a4d, // Evolution Electronics, Ltd 0x00b5, // Keystation Pro 88 Driver 0x0a4d, // Evolution Electronics, Ltd 0x00d2, // E-Keys Driver 0x0a4d, // Evolution Electronics, Ltd 0x00f0, // UC-16 Driver 0x0a4d, // Evolution Electronics, Ltd 0x00f1, // X-Session Driver 0x0a53, // Portable Peripheral Co., Ltd 0x2013, // Media Drive A6 Scanner 0x0a53, // Portable Peripheral Co., Ltd 0x2014, // Media Drive A6 Scanner 0x0a6b, // Green House Co., Ltd 0x0001, // Compact Flash R/W with MP3 player 0x0a6b, // Green House Co., Ltd 0x000f, // FlashDisk 0x0a8e, // Japan Aviation Electronics Industry, Ltd 0x2011, // Filter Driver For JAE XMC R/W 0x0aa6, // Perception Digital, Ltd 0x1501, // Store 'n' Go HD Drive 0x0ac9, // Micro Solutions, Inc. 0x0011, // Backpack 40GB Hard Drive 0x0aec, // Neodio Technologies Corp. 0x2102, // CompactFlash Card Reader 0x0aec, // Neodio Technologies Corp. 0x2201, // SmartMedia+CompactFlash Card Reader 0x0aec, // Neodio Technologies Corp. 0x2204, // CompactFlash+MMC/SD Card Reader 0x0aec, // Neodio Technologies Corp. 0x2205, // CompactFlash+MemoryStick Card Reader 0x0aec, // Neodio Technologies Corp. 0x2301, // SmartMedia+CompactFlash+MMC/SD Card Reader 0x0aec, // Neodio Technologies Corp. 0x2302, // SmartMedia+CompactFlash+MemoryStick Card Reader 0x0aec, // Neodio Technologies Corp. 0x2304, // CompactFlash+MMC/SD+MemoryStick Card Reader 0x0b86, // Exputer Systems, Inc. 0x5100, // XMC5100 Zippy Drive 0x0b86, // Exputer Systems, Inc. 0x5110, // XMC5110 Flash Drive 0x0b86, // Exputer Systems, Inc. 0x5200, // XMC5200 Zippy Drive 0x0b86, // Exputer Systems, Inc. 0x5201, // XMC5200 Zippy Drive 0x0b86, // Exputer Systems, Inc. 0x5202, // XMC5200 Zippy Drive 0x0b86, // Exputer Systems, Inc. 0x5280, // XMC5280 Storage Drive 0x0bf1, // Intracom S.A. 0x0001, // netMod Driver Ver 2.4.17 (CAPI) 0x0bf1, // Intracom S.A. 0x0002, // netMod Driver Ver 2.4 (CAPI) 0x0bf1, // Intracom S.A. 0x0003, // netMod Driver Ver 2.4 (CAPI) 0x0c0b, // Dura Micro, Inc. (Acomdata) 0x27cb, // 6-in-1 Flash Reader and Writer 0x0c45, // Microdia 0x1060, // iFlash SM-Direct Card Reader 0x0c76, // JMTek, LLC. 0x0005, // Transcend Flash disk 0x0c76, // JMTek, LLC. 0x0006, // Transcend JetFlash 0x0caf, // Buslink 0x2515, // Flash Disk Embedded Hub 0x0caf, // Buslink 0x2516, // Flash Disk Security Device 0x0caf, // Buslink 0x3a00, // Hard Drive 0x0ccd, // TerraTec Electronic GmbH 0x0015, // Flash Update for TerraTec PHASE 26 0x0d49, // Maxtor 0x3000, // Drive 0x0d49, // Maxtor 0x3010, // 3000LE Drive 0x0d49, // Maxtor 0x5000, // 5000XT Drive 0x0d49, // Maxtor 0x5010, // 5000LE Drive 0x0d49, // Maxtor 0x5020, // Mobile Hard Disk Drive 0x0d49, // Maxtor 0x7410, // Mobile Hard Disk Drive (1TB) 0x0d62, // Darfon Electronics Corp. 0x0004, // Filter Driver 0x0d64, // DXG Technology Corp. 0x3105, // Dual Mode Digital Camera Disk 0x0d7d, // Phison Electronics Corp. 0x0100, // PS1001/1011/1006/1026 Flash Disk 0x0d7d, // Phison Electronics Corp. 0x0110, // Gigabyte FlexDrive 0x0d7d, // Phison Electronics Corp. 0x0120, // Disk Pro 64MB 0x0d7d, // Phison Electronics Corp. 0x0124, // GIGABYTE Disk 0x0d7d, // Phison Electronics Corp. 0x1300, // Flash Disk 0x0d7d, // Phison Electronics Corp. 0x1320, // PS2031 Flash Disk 0x0d7d, // Phison Electronics Corp. 0x1400, // Attache 256MB USB 2.0 Flash Drive 0x0d7d, // Phison Electronics Corp. 0x1420, // PS2044 Pen Drive 0x0d7d, // Phison Electronics Corp. 0x1470, // Vosonic X's-Drive II+ VP2160 0x0d7d, // Phison Electronics Corp. 0x1620, // USB Disk Pro 0x0d7d, // Phison Electronics Corp. 0x1900, // USB Thumb Drive 0x0d98, // Mars Semiconductor Corp. 0x1007, // Discovery Kids Digital Camera 0x0db0, // Micro Star International 0x4011, // Medion Flash XL V2.0 Card Reader 0x0db0, // Micro Star International 0x6982, // Medion Flash XL Card Reader 0x0dbf, // Jess-Link International 0x0707, // ZIV Drive 0x0dc3, // Athena Smartcard Solutions, Inc. 0x0801, // ASEDrive III 0x0dc3, // Athena Smartcard Solutions, Inc. 0x0802, // ASEDrive IIIe 0x0dc3, // Athena Smartcard Solutions, Inc. 0x1104, // ASEDrive IIIe KB 0x0dd8, // Netac Technology Co., Ltd 0xe007, // OnlyDisk U222 Pendrive 0x0dd8, // Netac Technology Co., Ltd 0xf607, // OnlyDisk U208 1G flash drive [U-SAFE] 0x0dda, // Integrated Circuit Solution, Inc. 0x0003, // Flash Disk 0x0dda, // Integrated Circuit Solution, Inc. 0x1001, // Multi-Flash Disk 0x0ea0, // Ours Technology, Inc. 0x2168, // Transcend JetFlash 2.0 / Astone USB Drive 0x0ea0, // Ours Technology, Inc. 0x6803, // OTI-6803 Flash Disk 0x0ea0, // Ours Technology, Inc. 0x6808, // OTI-6808 Flash Disk 0x0ea0, // Ours Technology, Inc. 0x6828, // OTI-6828 Flash Disk 0x0ecd, // Lite-On IT Corp. 0xa100, // LDW-411SX DVD/CD Rewritable Drive 0x0ed1, // WinMaxGroup 0x6660, // Flash Disk 64M-C 0x0ed1, // WinMaxGroup 0x6680, // Flash Disk 64M-B 0x0ef5, // PointChips 0x2202, // Flash Disk 0x0ef5, // PointChips 0x2366, // Flash Disk 0x0f5d, // NewAge International, LLC 0x9455, // Compact Drive 0x0f6e, // INTELLIGENT SYSTEMS 0x0201, // GameBoy Advance Flash Gang Writer 0x1019, // Elitegroup Computer Systems (ECS) 0x0c55, // Flash Reader, Desknote UCR-61S2B 0x1043, // iCreate Technologies Corp. 0x8006, // Flash Disk 32-256 MB 0x1043, // iCreate Technologies Corp. 0x8012, // Flash Disk 256 MB 0x104d, // Newport Corporation 0x1003, // Model-52 LED Light Source Power Supply and Driver 0x1058, // Western Digital Technologies, Inc. 0x1001, // External Hard Disk [Elements] 0x1065, // CCYU Technology 0x2136, // EasyDisk ED1064 0x10fd, // Anubis Electronics, Ltd 0xde00, // WinFast WalkieTV WDM Capture Driver. 0x116f, // Silicon 10 Technology Corp. 0x0005, // Flash Card Reader 0x116f, // Silicon 10 Technology Corp. 0xc108, // Flash Card Reader 0x116f, // Silicon 10 Technology Corp. 0xc109, // Flash Card Reader 0x125f, // A-DATA Technology Co., Ltd. 0xc81a, // Flash drive 0x125f, // A-DATA Technology Co., Ltd. 0xc93a, // 4GB Pen Drive 0x126f, // TwinMOS 0x1325, // Mobile Disk 0x126f, // TwinMOS 0x2168, // Mobile Disk III 0x1291, // Qualcomm Flarion Technologies, Inc. / Leadtek Research, Inc. 0x0010, // FDM 2xxx Flash-OFDM modem 0x1291, // Qualcomm Flarion Technologies, Inc. / Leadtek Research, Inc. 0x0011, // LR7F06/LR7F14 Flash-OFDM modem 0x12f7, // Memorex Products, Inc. 0x1e23, // TravelDrive 2007 Flash Drive 0x1307, // Transcend Information, Inc. 0x0163, // 256MB/512MB/1GB Flash Drive 0x1307, // Transcend Information, Inc. 0x0165, // 2GB/4GB Flash Drive 0x1307, // Transcend Information, Inc. 0x1169, // TS2GJF210 JetFlash 210 2GB 0x1370, // Swissbit 0x6828, // Victorinox Flash Drive 0x13d3, // IMC Networks 0x3212, // DTV-DVB UDTT704C - DVBT/NTSC/PAL Driver(PCM4) 0x13d3, // IMC Networks 0x3213, // DTV-DVB UDTT704D - DVBT/NTSC/PAL Driver (PCM4) 0x13d3, // IMC Networks 0x3214, // DTV-DVB UDTT704F -(MiniCard) DVBT/NTSC/PAL Driver(Without HID) 0x13d3, // IMC Networks 0x3215, // DTV-DVB UDAT7240 - ATSC/NTSC/PAL Driver(PCM4) 0x13d3, // IMC Networks 0x3216, // DTV-DVB UDTT 7047-USB 2.0 DVB-T Driver 0x13d3, // IMC Networks 0x3219, // DTV-DVB UDTT7049 - DVB-T Driver(Without HID) 0x13d3, // IMC Networks 0x3220, // DTV-DVB UDTT 7047M-USB 2.0 DVB-T Driver 0x13d3, // IMC Networks 0x3236, // DTV-DVB UDTT 7047A-USB 2.0 DVB-T Driver 0x13d3, // IMC Networks 0x3237, // DTV-DVB UDTT 704J - dual DVB-T Driver 0x13d3, // IMC Networks 0x3239, // DTV-DVB UDTT704D - DVBT/NTSC/PAL Driver(Without HID) 0x13d3, // IMC Networks 0x3240, // DTV-DVB UDXTTM6010 - A/D Driver(Without HID) 0x13d3, // IMC Networks 0x3241, // DTV-DVB UDXTTM6010 - A/D Driver(Without HID) 0x13d3, // IMC Networks 0x3242, // DTV-DVB UDAT7240LP - ATSC/NTSC/PAL Driver(Without HID) 0x13d3, // IMC Networks 0x3243, // DTV-DVB UDXTTM6010 - A/D Driver(Without HID) 0x13d3, // IMC Networks 0x3244, // DTV-DVB UDTT 7047Z-USB 2.0 DVB-T Driver 0x13fd, // Initio Corporation 0x1840, // Shintaro SH23SDOCK Hard Drive Docker [INIC-1608L] 0x13fe, // Kingston Technology Company Inc. 0x1a00, // 512MB/1GB Flash Drive 0x13fe, // Kingston Technology Company Inc. 0x1a23, // 512MB Flash Drive 0x13fe, // Kingston Technology Company Inc. 0x1d00, // DataTraveler 2.0 1GB/4GB Flash Drive / Patriot Xporter 4GB Flash Drive 0x13fe, // Kingston Technology Company Inc. 0x1e00, // Flash Drive 2 GB [ICIDU 2 GB] 0x13fe, // Kingston Technology Company Inc. 0x1f00, // DataTraveler 2.0 4GB Flash Drive / Patriot Xporter 32GB (PEF32GUSB) Flash Drive 0x13fe, // Kingston Technology Company Inc. 0x3800, // Rage XT Flash Drive 0x1462, // Micro Star International 0x5512, // MegaStick-1 Flash Stick 0x1514, // Actel 0x2003, // FlashPro3 Programmer 0x1514, // Actel 0x2004, // FlashPro3 Programmer 0x1514, // Actel 0x2005, // FlashPro3 Programmer 0x1516, // CompUSA 0x1603, // Flash Drive 0x1516, // CompUSA 0x8628, // Pen Drive 0x152d, // JMicron Technology Corp. / JMicron USA Technology Corp. 0x2336, // Hard Disk Drive 0x154b, // PNY 0x0010, // USB 2.0 Flash Drive 0x15a4, // Afatech Technologies, Inc. 0x1336, // SDHC/MicroSD/MMC/MS/M2/CF/XD Flash Card Reader 0x1687, // Kingmax Digital Inc. 0x5289, // FlashDisk 0x1687, // Kingmax Digital Inc. 0x6211, // FlashDisk 0x16c0, // VOTI 0x0484, // Teensyduino Disk 0x18a5, // Verbatim, Ltd 0x0214, // Portable Hard Drive 0x18a5, // Verbatim, Ltd 0x0216, // External Hard Drive 0x18a5, // Verbatim, Ltd 0x0218, // External Hard Drive 0x18a5, // Verbatim, Ltd 0x0227, // Pocket Hard Drive 0x1976, // Chipsbrand Microelectronics (HK) Co., Ltd. 0x6025, // Flash Drive 512 MB 0x1b1c, // Corsair 0x0890, // Flash Padlock 0x1b1c, // Corsair 0x1a90, // Flash Voyager GT 0x22b8, // Motorola PCS 0x0833, // 2386C-HT820 [Flash Mode] 0x22b8, // Motorola PCS 0x2823, // Flash Interface 0x22b8, // Motorola PCS 0x6026, // Flash RAM Downloader/miniOS 0x2304, // Pinnacle Systems, Inc. 0x0228, // PCTV DVB-T Flash Stick 0x3538, // Power Quotient International Co., Ltd 0x0001, // Travel Flash 0x3538, // Power Quotient International Co., Ltd 0x0042, // Cool Drive U339 Flash Disk 0x3538, // Power Quotient International Co., Ltd 0x0054, // Flash Drive (2GB) 0x413c, // Dell Computer Corp. 0x8105, // U2 in HID - Driver 0x4146, // USBest Technology 0x9281, // Iomega Micro Mini 128MB Flash Drive 0x4146, // USBest Technology 0xba01, // Intuix Flash Drive 0x4586, // Panram 0x1026, // Crystal Bar Flash Drive 0x4971, // SimpleTech 0xce17, // 1TB SimpleDrive II USB External Hard Drive 0x55aa, // OnSpec Electronic, Inc. 0x0015, // Hard Drive 0x55aa, // OnSpec Electronic, Inc. 0x0102, // SuperDisk 0x55aa, // OnSpec Electronic, Inc. 0x0103, // IDE Hard Drive 0x55aa, // OnSpec Electronic, Inc. 0xb000, // USB to CompactFlash Card Reader 0x55aa, // OnSpec Electronic, Inc. 0xb200, // Compact Flash Reader 0x8086, // Intel Corp. 0xf1a5, // Z-U130 [Value Solid State Drive] 0x8341, // EGO Systems, Inc. 0x2000 // Flashdisk }; ----------------------------------File Seperator------------------------------------------------------ /* ** Filename: USBSlaveBoms_iomux.c ** ** Automatically created by Application Wizard 1.4.2 ** ** Part of solution USBSlaveBoms in project USBSlaveBoms ** ** Based on USBSlaveHIDKbd example by FTDI ** ** Modifications by Philip A. Polstra, Sr. ** ** Part of the USB Mass Storage Device impersonator as presented at DEFCON 20 ** Based on USB Write blocker presented at Blackhat Europe 2012 *** */ #include "vos.h" #include "Timers.h" #include "main.h" void iomux_setup(void) { unsigned char packageType; tmr_context_t tmrCtx; // timer context for timer to sequence VID/PID packageType = vos_get_package_type(); // This is for the smaller package. This is probably what you want // for a couple of reasons. First off the LCD doesn't fit on a // Vinco shield very well. Also, you can leave off the buttons // and LCD if you don't want all the functionality, those items // will simply be ignored. If you leave out the LCD then you could // still build a pretty compact device with just a button and LEDs // for the write protect functionality. if (packageType == VINCULUM_II_32_PIN) { // Debugger to pin 11 as Bi-Directional. vos_iomux_define_bidi(199, IOMUX_IN_DEBUGGER, IOMUX_OUT_DEBUGGER); // GPIO_Port_E_1 to pin 12 as Input. vos_iomux_define_input(12, IOMUX_IN_GPIO_PORT_E_1); //VID+ button // GPIO_Port_E_2 to pin 14 as Input. vos_iomux_define_input(14, IOMUX_IN_GPIO_PORT_E_2); //VID- button // GPIO_Port_E_3 to pin 15 as Input. vos_iomux_define_input(15, IOMUX_IN_GPIO_PORT_E_3); //write protect button // GPIO_Port_B_0 to pin 23 as Output. vos_iomux_define_output(23, IOMUX_OUT_GPIO_PORT_B_0); //LCD DB4 // GPIO_Port_B_1 to pin 24 as Output. vos_iomux_define_output(24, IOMUX_OUT_GPIO_PORT_B_1); //LCD DB5 // GPIO_Port_B_2 to pin 25 as Output. vos_iomux_define_output(25, IOMUX_OUT_GPIO_PORT_B_2); //LCD DB6 // GPIO_Port_B_3 to pin 26 as Output. vos_iomux_define_output(26, IOMUX_OUT_GPIO_PORT_B_3); //LCD DB7 // GPIO_Port_B_4 to pin 29 as Output. vos_iomux_define_output(29, IOMUX_OUT_GPIO_PORT_B_4); //LCD RS // GPIO_Port_B_5 to pin 30 as Output. vos_iomux_define_output(30, IOMUX_OUT_GPIO_PORT_B_5); //LCD E // GPIO_Port_B_6 to pin 31 as Output. vos_iomux_define_output(31, IOMUX_OUT_GPIO_PORT_B_6); //Green LED // GPIO_Port_B_7 to pin 32 as Output. vos_iomux_define_output(32, IOMUX_OUT_GPIO_PORT_B_7); //Red LED } // This is for people who hate to solder and want to base their device // on the Vinco. Personally, I think that basing your device off the // 32-pin V2DIP1-32 is a better idea. Note that setup for pins 40 // and 41 is only needed for the Vinco, so if you are running // a dev board with a 64-pin chip it is not really needed. if (packageType == VINCULUM_II_64_PIN) { // Debugger to pin 11 as Bi-Directional. vos_iomux_define_bidi(199, IOMUX_IN_DEBUGGER, IOMUX_OUT_DEBUGGER); // GPIO_Port_E_1 to pin 12 as Input. vos_iomux_define_input(12, IOMUX_IN_GPIO_PORT_E_1); //VID+ button // GPIO_Port_E_2 to pin 13 as Input. vos_iomux_define_input(13, IOMUX_IN_GPIO_PORT_E_2); //VID- button // GPIO_Port_E_3 to pin 14 as Input. vos_iomux_define_input(14, IOMUX_IN_GPIO_PORT_E_3); //write protect button // for Vinco need to set pins to output for LED and power on host // both are active low vos_iomux_define_output(40, IOMUX_OUT_GPIO_PORT_E_5); // USB host LED vos_iomux_define_output(41, IOMUX_OUT_GPIO_PORT_E_6); // USB host power // GPIO_Port_B_0 to pin 24 as Output. vos_iomux_define_output(24, IOMUX_OUT_GPIO_PORT_B_0); //LCD DB4 // GPIO_Port_B_1 to pin 25 as Output. vos_iomux_define_output(25, IOMUX_OUT_GPIO_PORT_B_1); //LCD DB5 // GPIO_Port_B_2 to pin 26 as Output. vos_iomux_define_output(26, IOMUX_OUT_GPIO_PORT_B_2); //LCD DB6 // GPIO_Port_B_3 to pin 27 as Output. vos_iomux_define_output(27, IOMUX_OUT_GPIO_PORT_B_3); //LCD DB7 // GPIO_Port_B_4 to pin 28 as Output. vos_iomux_define_output(28, IOMUX_OUT_GPIO_PORT_B_4); //LCD RS // GPIO_Port_B_5 to pin 29 as Output. vos_iomux_define_output(29, IOMUX_OUT_GPIO_PORT_B_5); //LCD E // GPIO_Port_B_6 to pin 31 as Output. vos_iomux_define_output(31, IOMUX_OUT_GPIO_PORT_B_6); //Green LED // GPIO_Port_B_7 to pin 32 as Output. vos_iomux_define_output(32, IOMUX_OUT_GPIO_PORT_B_7); //Red LED } // setup the timer used to cycle through VID/PID tmrCtx.timer_identifier = TIMER_0; tmr_init(TIMER0, &tmrCtx); } ----------------------------------File Seperator------------------------------------------------------ /* ** Filename: main.c ** ** Automatically created by Application Wizard 1.4.2 ** ** Part of solution BH-EU in project USB-Writeblocker ** ** Based on USBSlaveHIDKbd example by FTDI ** Some ideas also borrowed from examples from John Hyde's USB by Design ** ** Modifications by Philip A. Polstra, Sr. ** ** Part of the USB Mass Storage Device impersonator as presented at DEFCON 20 ** Based on USB Write blocker presented at Blackhat Europe 2012 ** ** Comments: ** ** Important: Sections between markers "FTDI:S*" and "FTDI:E*" will be overwritten by ** the Application Wizard */ #include "stdlib.h" #include "string.h" #include "main.h" #include "GPIO.h" #include "Timers.h" #include "USBSlaveBomsDrv.h" #include "USBHostBomsDrv.h" //Thread prototypes vos_tcb_t *tcbHostIn, *tcbHostOut, *tcbHostEnum, *tcbTimer, *tcbButtons; void handleCbw(); void hostEnum(); void timer(); void handleButtons(); // Handles to the devices we need to pull this off VOS_HANDLE hUSBHOST_2; // host port VOS_HANDLE hUSBHOSTBOMS; // device for talking mass storage VOS_HANDLE hUSBSLAVE_1; // slave port - one attached to PC VOS_HANDLE hUSBSLAVEBOMS; VOS_HANDLE hGPIO_PORT_E; // GPIO B is used for buttons VOS_HANDLE hTimer; // timer is set and reest on successful mounting VOS_HANDLE hGPIO_PORT_B; // port B for LCD display unsigned short blockSize=512; // default to 512 unsigned long deviceCapacity; // capacity for our actual drive unsigned short maxLuns=1; // default to 1 vos_mutex_t vidPidMutex; // mutex for current vid/pid unsigned char illegalRequest=0; // this flag is set after an illegal request unsigned char writeProtect=1; // this flag is for enabling or disabling write protect extern usbSlaveBoms_context *slaveBomsCtx; extern usbhostBoms_context_t *hostBomsCtx; extern unsigned int currentVidPidIndex; extern unsigned short vidPid[]; /* Declaration for IOMUx setup function */ void iomux_setup(void); // LCD control signals #define lcd_rs 0x10 #define lcd_e 0x20 // LED port masks #define led_green 0x80 #define led_red 0x40 void light_red_led(VOS_HANDLE hLED) { unsigned char toggle; // first we read port to not mess up the LCD display vos_dev_read(hLED, &toggle, 1, NULL); toggle &= (~led_green); toggle |= led_red; vos_dev_write(hLED, &toggle, 1, NULL); } void light_green_led(VOS_HANDLE hLED) { unsigned char toggle; vos_dev_read(hLED, &toggle, 1, NULL); toggle &= (~led_red); toggle |= led_green; vos_dev_write(hLED, &toggle, 1, NULL); } // Send a command to our LCD display void write_lcd_cmd(VOS_HANDLE hLCD, unsigned char byte) { unsigned char cmd, leds; // first read state to not mess up LEDs on same port leds = writeProtect?led_green:led_red; // Write High nibble data to LCD cmd = (((byte >> 4) &0x0F) | lcd_e); cmd = (cmd &(~lcd_rs)) | leds; // Select Registers vos_dev_write(hLCD,&cmd,1,NULL); // Toggle 'E' pin cmd &= (~lcd_e); vos_dev_write(hLCD,&cmd,1,NULL); // Write Low nibble data to LCD cmd = ((byte &0x0F) | lcd_e); cmd = (cmd &(~lcd_rs)) | leds; // Select Registers vos_dev_write(hLCD,&cmd,1,NULL); // Toggle 'E' pin cmd &= (~lcd_e); vos_dev_write(hLCD,&cmd,1,NULL); vos_delay_msecs(1); } // Send data to LCD display void write_lcd_data(VOS_HANDLE hLCD, unsigned char byte) { unsigned char cmd, leds; // first read state to not mess up LEDs on same port leds = writeProtect?led_green:led_red; // Write High nibble data to LCD cmd = (((byte >> 4)&0x0F) | lcd_rs); cmd = (cmd | lcd_e) | leds; // Select DDRAM vos_dev_write(hLCD,&cmd,1,NULL); // Toggle 'E' pin cmd &= (~lcd_e); vos_dev_write(hLCD,&cmd,1,NULL); // Write Low nibble data to LCD cmd = ((byte & 0x0F) | lcd_rs); cmd = (cmd | lcd_e) | leds; // Select DDRAM vos_dev_write(hLCD,&cmd,1,NULL); // Toggle 'E' pin cmd &= (~lcd_e); vos_dev_write(hLCD,&cmd,1,NULL); vos_delay_msecs(1); } // Write a string at the current cursor position void write_lcd_str(VOS_HANDLE hLCD, char *str) { while(*str != '\0') { write_lcd_data(hLCD, (unsigned char*)*str); ++str; } } // Attempt to init the LCD display void lcd_ini(VOS_HANDLE hLCD) { vos_delay_msecs(100); // Send Reset command write_lcd_cmd(hLCD, 0x03); vos_delay_msecs(2); // Send Function Set write_lcd_cmd(hLCD, 0x28); vos_delay_msecs(2); write_lcd_cmd(hLCD, 0x28); vos_delay_msecs(2); // Send Display control command write_lcd_cmd(hLCD, 0x0C); vos_delay_msecs(2); // Send Display Clear command write_lcd_cmd(hLCD, 0x01); vos_delay_msecs(2); // Send Entry Mode Set command write_lcd_cmd(hLCD, 0x06); vos_delay_msecs(2); } // Clear LCD and reset cursor void lcd_clear(VOS_HANDLE hLcd) { // Send Display Clear command write_lcd_cmd(hLcd, 0x01); vos_delay_msecs(2); } // Write to the top line of our display void write_lcd_line1(VOS_HANDLE hLcd, char* str) { // Set 1-st line address write_lcd_cmd(hLcd, (0x01 | 0x80)); // Send string to LCD write_lcd_str(hLcd, str); } // Write to the bottom line of our display void write_lcd_line2(VOS_HANDLE hLcd, char* str) { // Set 2-nd line address write_lcd_cmd(hLcd, (0x40 | 0x80)); // Send string to LCD write_lcd_str(hLcd, str); } void update_lcd_vidpid() { char *str1, *str2; char *vid, *pid; itoa((int)vidPid[currentVidPidIndex], vid, 16); itoa((int)vidPid[currentVidPidIndex+1], pid, 16); str1 = "Current VID/PID "; str2 = " "; strcat(str2, vid); strcat(str2, "/"); strcat(str2, pid); write_lcd_line1(hGPIO_PORT_B, str1); write_lcd_line2(hGPIO_PORT_B, str2); } /* Main code - entry point to firmware */ void main(void) { // these are needed by VOS to intialize General Purpose IO ports gpio_context_t gpioContextE, gpioContextB; // USB Host configuration context usbhost_context_t usbhostContext; // initialize the VOS kernel vos_init(50, VOS_TICK_INTERVAL, VOS_NUMBER_DEVICES); vos_set_clock_frequency(VOS_48MHZ_CLOCK_FREQUENCY); vos_set_idle_thread_tcb_size(512); // map the pins to appropriate ports iomux_setup(); // set up the button ports gpioContextE.port_identifier = GPIO_PORT_E; gpio_init(VOS_DEV_GPIO_PORT_E, &gpioContextE); // initialize the LCD port gpioContextB.port_identifier = GPIO_PORT_B; gpio_init(VOS_DEV_GPIO_PORT_B, &gpioContextB); // must be called to initialize slave port usbslave_init(0, VOS_DEV_USBSLAVE_1); usbslaveboms_init(VOS_DEV_USBSLAVEBOMS); // Initialize USB Host usbhostContext.if_count = 4; usbhostContext.ep_count = 8; usbhostContext.xfer_count = 4; usbhostContext.iso_xfer_count = 0; usbhost_init(-1, VOS_DEV_USBHOST_2, &usbhostContext); usbhostBoms_init(VOS_DEV_USBHOSTBOMS); // this mutex is used to control access to the current VID/PID index vos_init_mutex(&vidPidMutex, 0); // create some threads // Note: additonal threads are created by our USB slave driver and VOS tcbHostIn = vos_create_thread_ex(27, 1024, handleCbw, "Handle_CBW", 0); tcbHostEnum = vos_create_thread_ex(28, 1024, hostEnum, "Host_Enum", 0); tcbTimer = vos_create_thread_ex(20, 512, timer, "Timer", 0); tcbButtons = vos_create_thread_ex(19, 512, handleButtons, "Handle Buttons", 0); // this call starts the scheduler and never returns vos_start_scheduler(); main_loop: goto main_loop; } // Gets the connect state of host port // If the host port is not set up it returns disconnected unsigned char usbhost_connect_state(VOS_HANDLE hUSB) { unsigned char connectstate = PORT_STATE_DISCONNECTED; usbhost_ioctl_cb_t hc_iocb; if (hUSB) { hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_GET_CONNECT_STATE; hc_iocb.get = &connectstate; vos_dev_ioctl(hUSB, &hc_iocb); } return connectstate; } // Open all the drivers required by our application void open_drivers(void) { gpio_ioctl_cb_t gpio_iocb; unsigned char leds; hGPIO_PORT_E = vos_dev_open(VOS_DEV_GPIO_PORT_E); // power up Vinco USB Host // This is a poorly documented "feature" of Vinco board // Pins 40 & 41 of VNC2 chip must be set low to enable power // on host port and turn on LED // this must happen before we want to enumerate the flash drive gpio_iocb.ioctl_code = VOS_IOCTL_GPIO_SET_MASK; gpio_iocb.value = 0x60; // set power and LED as output vos_dev_ioctl(hGPIO_PORT_E, &gpio_iocb); leds = 0x00; vos_dev_write(hGPIO_PORT_E, &leds, 1, NULL); // set up port B for LCD display and for 2 status LEDs hGPIO_PORT_B = vos_dev_open(VOS_DEV_GPIO_PORT_B); gpio_iocb.ioctl_code = VOS_IOCTL_GPIO_SET_MASK; gpio_iocb.value = 0xff; // set all of Port B to output LCD & 2 LEDs vos_dev_ioctl(hGPIO_PORT_B, &gpio_iocb); // open our USB ports hUSBHOST_2 = vos_dev_open(VOS_DEV_USBHOST_2); hUSBHOSTBOMS = vos_dev_open(VOS_DEV_USBHOSTBOMS); hUSBSLAVE_1 = vos_dev_open(VOS_DEV_USBSLAVE_1); hUSBSLAVEBOMS = vos_dev_open(VOS_DEV_USBSLAVEBOMS); } void attach_drivers(void) { common_ioctl_cb_t bomsAttach; // attach BOMS to USB Host port B bomsAttach.ioctl_code = VOS_IOCTL_USBHOSTBOMS_ATTACH; bomsAttach.set.data = (void *) hUSBHOST_2; vos_dev_ioctl(hUSBHOSTBOMS, &bomsAttach); // attach BOMS to USB Slave port A bomsAttach.ioctl_code = VOS_IOCTL_USBSLAVEBOMS_ATTACH; bomsAttach.set.data = (void *) hUSBSLAVE_1; vos_dev_ioctl(hUSBSLAVEBOMS, &bomsAttach); } void close_drivers(void) { vos_dev_close(hUSBHOST_2); vos_dev_close(hUSBHOSTBOMS); vos_dev_close(hUSBSLAVE_1); vos_dev_close(hUSBSLAVEBOMS); vos_dev_close(hGPIO_PORT_E); } /* Application Threads */ // This timer is used to determine if our device has successfully connected // When the device is first enumerated this timer is set. This thread then // blocks till the timer expires. When the timer expires we increment the // index into our VID/PID list. If the device is connected the timer is // cancelled. void timer() { tmr_ioctl_cb_t tmr_iocb; // here we set up the timer, but don't start it // timer is started by the USB slave driver when someone // starts talking to it hTimer = vos_dev_open(TIMER0); tmr_iocb.ioctl_code = VOS_IOCTL_TIMER_SET_TICK_SIZE; tmr_iocb.param = TIMER_TICK_MS; vos_dev_ioctl(hTimer, &tmr_iocb); tmr_iocb.ioctl_code = VOS_IOCTL_TIMER_SET_COUNT; tmr_iocb.param = 1000; // 1s vos_dev_ioctl(hTimer, &tmr_iocb); tmr_iocb.ioctl_code = VOS_IOCTL_TIMER_SET_DIRECTION; tmr_iocb.param = TIMER_COUNT_DOWN; vos_dev_ioctl(hTimer, &tmr_iocb); tmr_iocb.ioctl_code = VOS_IOCTL_TIMER_SET_MODE; tmr_iocb.param = TIMER_MODE_SINGLE_SHOT; vos_dev_ioctl(hTimer, &tmr_iocb); // if our device is connected this never gets past blocking call while (1) { tmr_iocb.ioctl_code = VOS_IOCTL_TIMER_WAIT_ON_COMPLETE; vos_dev_ioctl(hTimer, &tmr_iocb); vos_lock_mutex(&vidPidMutex); currentVidPidIndex += 2; if (currentVidPidIndex > sizeof(vidPid)) currentVidPidIndex = 0; vos_unlock_mutex(&vidPidMutex); } } // This is the main thread. It enumerates the attached drive and // forwards commands to the drive if they are safe of if write // blocking is disabled. void hostEnum() { unsigned char i; unsigned char status; unsigned char buf[64]; unsigned short num_read; unsigned int handle; char *str1; // line one of display char *str2; // line two of display usbhostBoms_ioctl_t generic_iocb; usbhost_device_handle_ex ifDev; usbhost_ioctl_cb_t hc_iocb; usbhost_ioctl_cb_class_t hc_iocb_class; usbhostBoms_ioctl_cb_attach_t genericAtt; gpio_ioctl_cb_t gpio_iocb2; num_read = 0; // just here to set breakpoint open_drivers(); attach_drivers(); // enumerate flash drive then connect slave // display welcome greeting lcd_ini(hGPIO_PORT_B); lcd_clear(hGPIO_PORT_B); vos_delay_msecs(100); // delay a tad to reliably clear screen str1 = "All UR Endpoint"; write_lcd_line1(hGPIO_PORT_B, str1); str2 = " R belong 2 us"; write_lcd_line2(hGPIO_PORT_B, str2); // now give them a chance to change the VID/PID vos_delay_msecs(1000); str1 = "Enter VID/PID "; write_lcd_line1(hGPIO_PORT_B, str1); str2 = "or wait 4 auto "; write_lcd_line2(hGPIO_PORT_B, str2); vos_delay_msecs(10000); // during this time the user can press buttons do { // see if bus available if (usbhost_connect_state(hUSBHOST_2) == PORT_STATE_ENUMERATED) { hc_iocb_class.dev_class = USB_CLASS_MASS_STORAGE; hc_iocb_class.dev_subclass = USB_SUBCLASS_MASS_STORAGE_SCSI; hc_iocb_class.dev_protocol = USB_PROTOCOL_MASS_STORAGE_BOMS; // user ioctl to find first hub device hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_FIND_HANDLE_BY_CLASS; hc_iocb.handle.dif = NULL; hc_iocb.set = &hc_iocb_class; hc_iocb.get = &ifDev; vos_dev_ioctl(hUSBHOST_2, &hc_iocb); genericAtt.hc_handle = hUSBHOST_2; genericAtt.ifDev = ifDev; generic_iocb.ioctl_code = VOS_IOCTL_USBHOSTBOMS_ATTACH; generic_iocb.set.att = &genericAtt; // we use a simple variable to indicate if the flash drive // is attached // this is not as elegent as using a semaphore, but // this is the only thread that updates this variable and // if the device is disconnected and reconnected that is hard // to handle with a semaphore if (vos_dev_ioctl(hUSBHOSTBOMS, &generic_iocb) == USBHOSTBOMS_OK) { slaveBomsCtx->flashConnected = 1; vos_signal_semaphore(&slaveBomsCtx->enumed); str1 = "Successfully "; write_lcd_line1(hGPIO_PORT_B, str1); str2 = " read drive "; write_lcd_line2(hGPIO_PORT_B, str2); } else { slaveBomsCtx->flashConnected = 0; str1 = "Oh Snap! UR "; write_lcd_line1(hGPIO_PORT_B, str1); str2 = "drive !enumed "; write_lcd_line2(hGPIO_PORT_B, str2); }// if attach // this code is in here so that if the drive gets disconnected // we can try to restart it // also, hopefully the the traffic every few seconds will keep // the drive from going to sleep vos_delay_msecs(2000); } // if enumerated vos_delay_msecs(10); // recheck every .01 seconds for new connect } // outer do while (1); } // The following functions forward commands and such to the attached // mass storage device. unsigned short forward_cbw_to_device(boms_cbw_t *cbw) { unsigned short num_written; usbhostBoms_write((void*)cbw, sizeof(boms_cbw_t), &num_written, hostBomsCtx); return num_written; } unsigned short receive_data_from_device(void* buffer, unsigned short expected) { unsigned short num_read; unsigned char status; status = usbhostBoms_read(buffer, expected, &num_read, hostBomsCtx); if (status == USBHOST_EP_HALTED) { // the endpoint is halted so let's halt the slave endpoint usbslaveboms_stall_bulk_in(slaveBomsCtx); } return num_read; } unsigned short forward_data_to_slave(void* buffer, unsigned short bytes) { unsigned short num_written; usbSlaveBoms_write(buffer, bytes, &num_written, slaveBomsCtx); return num_written; } unsigned short forward_data_to_slave_then_stall(void* buffer, unsigned short bytes) { unsigned short num_written; usbSlaveBoms_short_write(buffer, bytes, &num_written, slaveBomsCtx); return num_written; } unsigned short receive_csw_from_device(boms_csw_t *csw) { unsigned short num_read; usbhostBoms_read((void*)csw, 13, &num_read, hostBomsCtx); return num_read; } unsigned short forward_csw_to_slave(boms_csw_t *csw) { unsigned short num_written; usbSlaveBoms_write((void*)csw, 13, &num_written, slaveBomsCtx); return num_written; } // The handle_xxxxx functions are used to handle various requests // of our faked mass storage device. While it would be wonderful // to implement this in a nice object-oriented fashion, there are // too many variables and the microcontroller doesn't handle lots // of function calls very well so we must live with lots of cut // and paste action here. Sorry! void handle_inquiry(boms_cbw_t *cbw) { unsigned char buffer[64]; unsigned short responseSize; boms_csw_t csw; // forward the CBW to device if (forward_cbw_to_device(cbw)) { // receive response from device // note we will assume that only the standard 36 bytes will be requested if (responseSize = receive_data_from_device(&buffer[0], 36)) { // forward response to slave forward_data_to_slave(&buffer[0], responseSize); // receive CSW from device if (receive_csw_from_device(&csw)) { // forward CSW to slave forward_csw_to_slave(&csw); } } } } void handle_test_unit_ready(boms_cbw_t *cbw) { boms_csw_t csw; // forward the CBW to device if (forward_cbw_to_device(cbw)) { // receive response from device if (receive_csw_from_device(&csw)) { // forward CSW to slave forward_csw_to_slave(&csw); } } } void handle_read(boms_cbw_t *cbw) { // this same routine handles all 3 possible read commands // most likely read command is read(10) unsigned long lba; // logical block address for start block unsigned short blocks; // number of blocks to read unsigned short i; boms_csw_t csw; unsigned char *buffer; unsigned short num_read; unsigned short num_written; switch (cbw->cb.formated.command) { case BOMS_READ_6: lba = cbw->cb.raw[1]*65536 + cbw->cb.raw[2]*256 + cbw->cb.raw[3]; blocks = cbw->cb.raw[4]; break; case BOMS_READ_10: lba = cbw->cb.raw[2]*16777216 + cbw->cb.raw[3]*65536 + cbw->cb.raw[4]*256 +cbw->cb.raw[5]; blocks = cbw->cb.raw[7] * 256 + cbw->cb.raw[8]; break; case BOMS_READ_12: lba = cbw->cb.raw[2]*16777216 + cbw->cb.raw[3]*65536 + cbw->cb.raw[4]*256 +cbw->cb.raw[5]; // we are being a little bad here the number of blocks is actually a long // it is extremely unlikely that anyone would request this much at once, however blocks = cbw->cb.raw[8] * 256 + cbw->cb.raw[9]; break; } // now forward the cbw to the device forward_cbw_to_device(cbw); // receive the appropriate number of blocks from the device // forward the blocks to the slave // most requests are probably 1 block of 512 bytes // read in 512 byte chunks (packet size is 64 bytes, but VOS should handle this) // If devices with larger blocks are encountered, 512 should still work buffer = vos_malloc(blockSize); while(blocks>0) { usbhostBoms_read((void*)buffer, blockSize, &num_read, hostBomsCtx); usbSlaveBoms_write((void*)buffer, num_read, &num_written, slaveBomsCtx); blocks--; } vos_free(buffer); // receive the csw from the device receive_csw_from_device(&csw); // forward the csw to the slave forward_csw_to_slave(&csw); } void handle_read_capacity(boms_cbw_t *cbw) { boms_csw_t csw; unsigned char buffer[8]; unsigned short received; // forward cbw to device forward_cbw_to_device(cbw); // receive response from device if (received = receive_data_from_device(&buffer[0], 8)) { deviceCapacity = buffer[0]*16777216 + buffer[1]*65536 + buffer[2]*256 +buffer[3]; blockSize = buffer[4]*16777216 + buffer[5]*65536 + buffer[6]*256 +buffer[7]; // forward response to slave forward_data_to_slave(&buffer[0], received); } // receive csw from device receive_csw_from_device(&csw); // forward csw to slave forward_csw_to_slave(&csw); } void handle_report_luns(boms_cbw_t *cbw) { boms_csw_t csw; unsigned char buffer[64]; unsigned short received; // forward cbw forward_cbw_to_device(cbw); // receive response from device // response is 8 bytes + maxLuns * 8 if (received = receive_data_from_device(&buffer[0], 8 + 8 * maxLuns)) { // forward response to slave forward_data_to_slave(&buffer[0], received); } // receive csw from device receive_csw_from_device(&csw); // forward csw to slave forward_csw_to_slave(&csw); } void handle_request_sense(boms_cbw_t *cbw) { boms_csw_t csw; unsigned char bytesRequested; unsigned short bytesRead, bytesWritten; unsigned char *buffer; request_sense_response_t rsr; if (illegalRequest) { // if we are here this a a request sense that came right after an illegal // command request - perhaps somebody tried to modify our drive! // we return the appropriate error directly and a CSW // the device is never touched illegalRequest = 0; // reset so next request goes to actual device rsr.formated.responseCode =0x70; //0x70 current error rsr.formated.valid = 0; // 1=INFORMATION field valid rsr.formated.obsolete = 0; rsr.formated.senseKey = 0x05; // 0x05 for illegal request rsr.formated.resvered = 0; rsr.formated.ili = 0; // incorrect length indicator rsr.formated.eom = 0; // end of media for streaming devices rsr.formated.filemark = 0; // for streaming devices rsr.formated.information = 0; // device specific info rsr.formated.addSenseLen = 0x0a; // additional bytes that follow 244 max rsr.formated.cmdSpecInfo = 0; // command specific info rsr.formated.asc = 0x20; // additional sense code 0x20 for illegal command rsr.formated.ascq = 0; // additional sense code qualifier 0-unused rsr.formated.fruc = 0; // field replaceable unit code set to 0 rsr.formated.senseKeySpecific[0] = 0; //senses key spec info if b7=1 rsr.formated.senseKeySpecific[1] = 0; rsr.formated.senseKeySpecific[2] = 0; bytesWritten = forward_data_to_slave(&rsr, 18); // now send an appropriate CSW to indicate success of this command csw.sig[0] = 'U'; //"USBS" csw.sig[1] = 'S'; csw.sig[2] = 'B'; csw.sig[3] = 'S'; csw.tag = cbw->tag; csw.residue = 0; csw.status = 0; // 0x00=success 0x01=failure 0x02=phase error forward_csw_to_slave(&csw); } else { // forward cbw bytesRequested = cbw->cb.raw[4]; forward_cbw_to_device(cbw); buffer = vos_malloc((unsigned short)bytesRequested); // receive data from device if (bytesRead = receive_data_from_device(buffer, (unsigned short)bytesRequested)) { bytesWritten = forward_data_to_slave(buffer, bytesRead); } vos_free(buffer); // receive csw from device receive_csw_from_device(&csw); // forward csw to slave forward_csw_to_slave(&csw); } } void handle_mode_sense(boms_cbw_t *cbw) { boms_csw_t csw; unsigned short allocLength=0; unsigned char *buffer=NULL; unsigned short bytesReceived=0; // forward the cbw to the device switch (cbw->cb.formated.command) { case BOMS_MODE_SENSE_6: allocLength = cbw->cb.raw[4]; break; case BOMS_MODE_SENSE_10: allocLength = cbw->cb.raw[7]*256 + cbw->cb.raw[8]; break; } forward_cbw_to_device(cbw); // receive data from device if (allocLength) { buffer = vos_malloc(allocLength); bytesReceived = receive_data_from_device(buffer, allocLength); // forward data to slave forward_data_to_slave(buffer, bytesReceived); vos_free(buffer); } // receive csw from device receive_csw_from_device(&csw); // forward csw to slave forward_csw_to_slave(&csw); } void handle_mode_select(boms_cbw_t *cbw) { boms_csw_t csw; unsigned short allocLength=0; unsigned char *buffer=NULL; unsigned short bytesReceived=0; // forward the cbw to the device switch (cbw->cb.formated.command) { case BOMS_MODE_SELECT_6: allocLength = cbw->cb.raw[4]; break; case BOMS_MODE_SELECT_10: allocLength = cbw->cb.raw[7]*256 + cbw->cb.raw[8]; break; } forward_cbw_to_device(cbw); // receive data from device if (allocLength) { buffer = vos_malloc(allocLength); bytesReceived = receive_data_from_device(buffer, allocLength); // forward data to slave forward_data_to_slave(buffer, bytesReceived); vos_free(buffer); } // receive csw from device receive_csw_from_device(&csw); // forward csw to slave forward_csw_to_slave(&csw); } void handle_illegal_request(boms_cbw_t *cbw) { usbslave_ioctl_cb_t iocb; boms_csw_t csw; // now send the CSW csw.sig[0]='U'; csw.sig[1]='S'; csw.sig[2]='B'; csw.sig[3]='S';//"USBS" csw.tag=cbw->tag; csw.residue=0; csw.status=0x01; // 0x00=success 0x01=failure 0x02=phase error forward_csw_to_slave(&csw); // flag the error for the anticipated call to REQUEST SENSE illegalRequest=1; } void handle_illegal_write_request(boms_cbw_t *cbw) { usbslave_ioctl_cb_t iocb; boms_csw_t csw; unsigned short blocks; unsigned char *buffer; unsigned short num_read; unsigned short i; // as strange as it may seem, there is no way to tell the host to quit // instead we need to receive all this data and throw it away! switch (cbw->cb.formated.command) { case BOMS_WRITE_6: blocks = cbw->cb.raw[4]; break; case BOMS_WRITE_10: blocks = cbw->cb.raw[7] * 256 + cbw->cb.raw[8]; break; case BOMS_WRITE_12: // we are being a little bad here the number of blocks is actually a long // it is extremely unlikely that anyone would request this much at once, however blocks = cbw->cb.raw[8] * 256 + cbw->cb.raw[9]; break; } buffer = vos_malloc(512); iocb.ioctl_code = VOS_IOCTL_USBSLAVE_TRANSFER; iocb.handle = slaveBomsCtx->out_ep; iocb.request.setup_or_bulk_transfer.buffer = buffer; iocb.request.setup_or_bulk_transfer.size = 512; iocb.request.setup_or_bulk_transfer.bytes_transferred = 0; for (i = 0; i < (blocks * (512/blockSize)); i++) { // process bytes received from host vos_dev_ioctl(slaveBomsCtx->handle,&iocb); } vos_free(buffer); // now send the CSW csw.sig[0]='U'; csw.sig[1]='S'; csw.sig[2]='B'; csw.sig[3]='S';//"USBS" csw.tag=cbw->tag; csw.residue=0; csw.status=0x00; // 0x00=success 0x01=failure 0x02=phase error //forward_csw_to_slave(&csw); iocb.ioctl_code = VOS_IOCTL_USBSLAVE_TRANSFER; iocb.handle = slaveBomsCtx->in_ep; iocb.request.setup_or_bulk_transfer.buffer = &csw; iocb.request.setup_or_bulk_transfer.size = sizeof(boms_csw_t); vos_dev_ioctl(slaveBomsCtx->handle, &iocb); } void handle_write_request(boms_cbw_t *cbw) { usbslave_ioctl_cb_t iocb; boms_csw_t csw; unsigned short blocks; unsigned char *buffer; unsigned short num_read; unsigned short i; switch (cbw->cb.formated.command) { case BOMS_WRITE_6: blocks = cbw->cb.raw[4]; break; case BOMS_WRITE_10: blocks = cbw->cb.raw[7] * 256 + cbw->cb.raw[8]; break; case BOMS_WRITE_12: // we are being a little bad here the number of blocks is actually a long // it is extremely unlikely that anyone would request this much at once, however blocks = cbw->cb.raw[8] * 256 + cbw->cb.raw[9]; break; } // forward the cbw to the device forward_cbw_to_device(cbw); // create a buffer for each 512 byte block // Note: we are assuming a 512 byte block size for our attached device. // While this is a fairly good assumption, I am told that there are devices // with larger block sizes out there. If you have such a device don't // connect it or things will fail. There are plenty of 512 byte block // devices to choose from. If you don't like this limitation, feel free // to modify this code accordingly. buffer = vos_malloc(512); // receive data from device for (i = 0; i < blocks; i++) { num_read = receive_data_from_device(buffer, 512); // forward data to slave forward_data_to_slave(buffer, num_read); } vos_free(buffer); // receive csw from device receive_csw_from_device(&csw); // forward csw to slave forward_csw_to_slave(&csw); } void handle_send_diagnostic(boms_cbw_t *cbw) { usbslave_ioctl_cb_t iocb; boms_csw_t csw; // first send ZLDP to ACK the command iocb.ioctl_code = VOS_IOCTL_USBSLAVE_TRANSFER; iocb.handle = slaveBomsCtx->in_ep; iocb.request.setup_or_bulk_transfer.buffer = NULL; iocb.request.setup_or_bulk_transfer.size = 0; vos_dev_ioctl(slaveBomsCtx->handle, &iocb); // now send the CSW csw.sig[0]='U'; csw.sig[1]='S'; csw.sig[2]='B'; csw.sig[3]='S';//"USBS" csw.tag=cbw->tag; csw.residue=0; csw.status=0x00; // 0x00=success 0x01=failure 0x02=phase error forward_csw_to_slave(&csw); } void handle_start_stop_unit(boms_cbw_t *cbw) { boms_csw_t csw; // forward the CBW to device if (forward_cbw_to_device(cbw)) { // receive response from device if (receive_csw_from_device(&csw)) { // forward CSW to slave forward_csw_to_slave(&csw); } } } void handle_synchronize_cache(boms_cbw_t *cbw) { usbslave_ioctl_cb_t iocb; boms_csw_t csw; // first send ZLDP to ACK the command iocb.ioctl_code = VOS_IOCTL_USBSLAVE_TRANSFER; iocb.handle = slaveBomsCtx->in_ep; iocb.request.setup_or_bulk_transfer.buffer = NULL; iocb.request.setup_or_bulk_transfer.size = 0; vos_dev_ioctl(slaveBomsCtx->handle, &iocb); // now send the CSW csw.sig[0]='U'; csw.sig[1]='S'; csw.sig[2]='B'; csw.sig[3]='S';//"USBS" csw.tag=cbw->tag; csw.residue=0; csw.status=0x00; // 0x00=success 0x01=failure 0x02=phase error forward_csw_to_slave(&csw); } void handle_read_format_capacities(boms_cbw_t *cbw) { unsigned char *buffer; unsigned short responseSize; unsigned short allocLength; boms_csw_t csw; allocLength = cbw->cb.raw[7] * 256 + cbw->cb.raw[8]; buffer = vos_malloc(allocLength); // forward the CBW to device if (forward_cbw_to_device(cbw)) { // receive response from device if (responseSize = receive_data_from_device(buffer, allocLength)) { // forward response to slave forward_data_to_slave(&buffer[0], responseSize); // receive CSW from device if (receive_csw_from_device(&csw)) { // forward CSW to slave forward_csw_to_slave(&csw); } } } vos_free(buffer); } void handle_read_toc_pma_atip(boms_cbw_t *cbw) { unsigned char *buffer; unsigned short responseSize; unsigned short allocLength; boms_csw_t csw; allocLength = cbw->cb.raw[7] * 256 + cbw->cb.raw[8]; buffer = vos_malloc(allocLength); // forward the CBW to device if (forward_cbw_to_device(cbw)) { // receive response from device if (responseSize = receive_data_from_device(buffer, allocLength)) { // forward response to slave forward_data_to_slave(&buffer[0], responseSize); // receive CSW from device if (receive_csw_from_device(&csw)) { // forward CSW to slave forward_csw_to_slave(&csw); } } } vos_free(buffer); } // This function handles the call to prevent/allow removal // If we fail this command when prevent=1 (true) then // Windows will not cache writes. This actually leads // to better performance. void handle_prevent_allow_removal(boms_cbw_t *cbw) { usbslave_ioctl_cb_t iocb; boms_csw_t csw; // now send the CSW csw.sig[0]='U'; csw.sig[1]='S'; csw.sig[2]='B'; csw.sig[3]='S';//"USBS" csw.tag=cbw->tag; csw.residue=0; csw.status=0x01; // 0x00=success 0x01=failure 0x02=phase error forward_csw_to_slave(&csw); // flag the error for the anticipated call to REQUEST SENSE illegalRequest=1; } // This function runs in its own thread. It processes // incoming Command Block Wrappers and either passes them on // or fake it. void handleCbw() { unsigned short num_read, num_written; boms_cbw_t *cbw = vos_malloc(sizeof(boms_cbw_t)); // no point in doing anything until we can enum our attached // mass storage device vos_wait_semaphore(&slaveBomsCtx->enumed); vos_signal_semaphore(&slaveBomsCtx->enumed); while(1) { if(slaveBomsCtx) { while(slaveBomsCtx && slaveBomsCtx->flashConnected) { // get the CBW memset(cbw, 0, sizeof(boms_cbw_t)); usbSlaveBoms_readCbw(cbw, slaveBomsCtx); // TO DO: Check for valid CBW switch (cbw->cb.formated.command) { case BOMS_INQUIRY: handle_inquiry(cbw); break; case BOMS_MODE_SELECT_6: case BOMS_MODE_SELECT_10: handle_mode_select(cbw); break; case BOMS_MODE_SENSE_6: case BOMS_MODE_SENSE_10: handle_mode_sense(cbw); break; case BOMS_READ_6: case BOMS_READ_10: case BOMS_READ_12: handle_read(cbw); break; case BOMS_READ_CAPACITY: handle_read_capacity(cbw); break; case BOMS_REPORT_LUNS: handle_report_luns(cbw); break; case BOMS_REQUEST_SENSE: handle_request_sense(cbw); break; case BOMS_TEST_UNIT_READY: handle_test_unit_ready(cbw); break; case BOMS_SEND_DIAGNOSTIC: handle_send_diagnostic(cbw); break; case BOMS_START_STOP_UNIT: handle_start_stop_unit(cbw); break; case BOMS_SYCHRONIZE_CACHE: handle_synchronize_cache(cbw); break; case BOMS_READ_FORMAT_CAPACITIES: handle_read_format_capacities(cbw); break; case BOMS_PREVENT_ALLOW_REMOVAL: handle_prevent_allow_removal(cbw); break; case BOMS_READ_TOC_PMA_ATIP: handle_read_toc_pma_atip(cbw); break; case BOMS_VERIFY: case BOMS_FORMAT_UNIT: // tell them NO! by failing command handle_illegal_request(cbw); break; case BOMS_WRITE_6: case BOMS_WRITE_10: case BOMS_WRITE_12: if (writeProtect) handle_illegal_write_request(cbw); else handle_write_request(cbw); break; default: handle_illegal_request(cbw); break; } // switch } // inner while } else { vos_delay_msecs(1000); } } // outer while vos_free(cbw); } // This function runs in a low priority thread. Its only // function is to read the buttons to see if someone has pressed // them to toggle write protect or change the VID/PID. // This could have been implemented using GPIO lines with // interupt capabilities, but interupting the USB threads might // not be a great idea. Additionally, enabling interupts introduces // additional overhead. void handleButtons() { unsigned char buttonBits, leds; while (1) { vos_dev_read(hGPIO_PORT_E, &buttonBits, 1, NULL); // if this is non-zero, somebody is pushing buttons // we prioritize the write protect button then +, then - while (buttonBits) { if (buttonBits & 0x08) // write protect button pressed { // since this is pretty serious business we require // a long keypress to toggle vos_delay_msecs(1000); if(buttonBits & 0x08) { writeProtect = (~writeProtect & 0x01); leds = writeProtect?led_green:led_red; vos_dev_write(hGPIO_PORT_B, &leds, 1, NULL); } } else if(buttonBits & 0x04) // VID/PID + { vos_lock_mutex(&vidPidMutex); currentVidPidIndex += 2; if (currentVidPidIndex > sizeof(vidPid)) currentVidPidIndex = 0; vos_unlock_mutex(&vidPidMutex); update_lcd_vidpid(); } else if(buttonBits & 0x02) // VID/PID - { vos_lock_mutex(&vidPidMutex); currentVidPidIndex -= 2; if (currentVidPidIndex < 0) currentVidPidIndex = 0; vos_unlock_mutex(&vidPidMutex); update_lcd_vidpid(); } vos_dev_read(hGPIO_PORT_E, &buttonBits, 1, NULL); vos_delay_msecs(50); } vos_delay_msecs(100); } } ----------------------------------File Seperator------------------------------------------------------ /* ** Filename: USBSlaveBoms.h ** ** Automatically created by Application Wizard 1.4.2 ** ** Part of solution USBSlaveBoms in project USBSlaveBoms ** ** Based on USBSlaveHIDKbd example by FTDI ** ** Modifications by Philip A. Polstra, Sr. ** ** Part of the USB Mass Storage Device impersonator as presented at DEFCON 20 ** Based on USB Write blocker presented at Blackhat Europe 2012 ** ** Comments: ** ** Important: Sections between markers "FTDI:S*" and "FTDI:E*" will be overwritten by ** the Application Wizard */ #ifndef _USBSlaveBoms_H_ #define _USBSlaveBoms_H_ #include "vos.h" #include "USB.h" #include "USBSlave.h" #include "USBHost.h" #include "BomsDefs.h" #define VOS_NUMBER_DEVICES 7 // for additional drivers #define VOS_DEV_USBHOST_2 0 #define VOS_DEV_USBHOSTBOMS 1 #define VOS_DEV_USBSLAVE_1 2 #define VOS_DEV_USBSLAVEBOMS 3 #define VOS_DEV_GPIO_PORT_E 4 #define TIMER0 5 #define VOS_DEV_GPIO_PORT_B 6 // define standard SCSI requests to be handled #define BOMS_FORMAT_UNIT 0x04 //definitely block! #define BOMS_INQUIRY 0x12 #define BOMS_MODE_SELECT_6 0x15 #define BOMS_MODE_SELECT_10 0x55 #define BOMS_MODE_SENSE_6 0x1a #define BOMS_MODE_SENSE_10 0x5a #define BOMS_PREVENT_ALLOW_REMOVAL 0x1e #define BOMS_READ_6 0x08 #define BOMS_READ_10 0x28 #define BOMS_READ_12 0xa8 #define BOMS_READ_CAPACITY 0x25 #define BOMS_READ_FORMAT_CAPACITIES 0x23 #define BOMS_READ_TOC_PMA_ATIP 0x43 #define BOMS_REPORT_LUNS 0xa0 #define BOMS_REQUEST_SENSE 0x03 #define BOMS_SEND_DIAGNOSTIC 0x1d #define BOMS_START_STOP_UNIT 0x1b #define BOMS_SYCHRONIZE_CACHE 0x35 #define BOMS_TEST_UNIT_READY 0x00 #define BOMS_VERIFY 0x2f #define BOMS_WRITE_6 0x0a //block? #define BOMS_WRITE_10 0x2a //block? #define BOMS_WRITE_12 0xaa //block? #endif /* _USBSlaveBoms_H_ */ ----------------------------------File Seperator------------------------------------------------------ /* ** Filename: USBHostGeneric.c ** ** Automatically created by Application Wizard 1.4.2 ** ** Part of solution USBHostGeneric in project USBHostGeneric ** ** Comments: ** ** Important: Sections between markers "FTDI:S*" and "FTDI:E*" will be overwritten by ** the Application Wizard */ #include "USBHostGeneric.h" #include "USBHostGenericDrv.h" /* FTDI:STP Thread Prototypes */ vos_tcb_t *tcbFIRMWARE; void firmware(); /* FTDI:ETP */ /* FTDI:SDH Driver Handles */ VOS_HANDLE hUSBHOST_1; // USB Host Port 1 VOS_HANDLE hUART; // UART Interface Driver /* FTDI:EDH */ VOS_HANDLE hUSBHOSTGENERIC; // USB Host Generic Driver (Additional Device) /* Declaration for IOMUx setup function */ void iomux_setup(void); /* Main code - entry point to firmware */ void main(void) { /* FTDI:SDD Driver Declarations */ // UART Driver configuration context uart_context_t uartContext; // USB Host configuration context usbhost_context_t usbhostContext; /* FTDI:EDD */ /* FTDI:SKI Kernel Initialisation */ vos_init(50, VOS_TICK_INTERVAL, VOS_NUMBER_DEVICES); vos_set_clock_frequency(VOS_48MHZ_CLOCK_FREQUENCY); vos_set_idle_thread_tcb_size(512); /* FTDI:EKI */ iomux_setup(); /* FTDI:SDI Driver Initialisation */ // Initialise UART uartContext.buffer_size = VOS_BUFFER_SIZE_128_BYTES; uart_init(VOS_DEV_UART, &uartContext); // Initialise USB Host usbhostContext.if_count = 8; usbhostContext.ep_count = 16; usbhostContext.xfer_count = 2; usbhostContext.iso_xfer_count = 2; usbhost_init(VOS_DEV_USBHOST_1, -1, &usbhostContext); /* FTDI:EDI */ usbhostGeneric_init(VOS_DEV_USBHOSTGENERIC); /* FTDI:SCT Thread Creation */ tcbFIRMWARE = vos_create_thread_ex(20, 4096, firmware, "Application", 0); /* FTDI:ECT */ vos_start_scheduler(); main_loop: goto main_loop; } /* FTDI:SSP Support Functions */ unsigned char usbhost_connect_state(VOS_HANDLE hUSB) { unsigned char connectstate = PORT_STATE_DISCONNECTED; usbhost_ioctl_cb_t hc_iocb; if (hUSB) { hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_GET_CONNECT_STATE; hc_iocb.get = &connectstate; vos_dev_ioctl(hUSB, &hc_iocb); } return connectstate; } /* FTDI:ESP */ void open_drivers(void) { /* Code for opening and closing drivers - move to required places in Application Threads */ /* FTDI:SDA Driver Open */ hUSBHOST_1 = vos_dev_open(VOS_DEV_USBHOST_1); hUART = vos_dev_open(VOS_DEV_UART); /* FTDI:EDA */ } void attach_drivers(void) { /* FTDI:SUA Layered Driver Attach Function Calls */ /* FTDI:EUA */ } void close_drivers(void) { /* FTDI:SDB Driver Close */ vos_dev_close(hUSBHOST_1); vos_dev_close(hUART); /* FTDI:EDB */ } /* Application Threads */ void writeString(VOS_HANDLE hDev, char *str) { vos_dev_write(hDev, (unsigned char *) str, strlen(str), NULL); } void writeShort(VOS_HANDLE hDev, unsigned short val) { char str[4]; unsigned char ch; ch = val >> 12; ch = ch & 0x0f; if (ch > 9) str[0] = 'A' - 10 + ch; else str[0] = '0' + ch; ch = val >> 8; ch = ch & 0x0f; if (ch > 9) str[1] = 'A' - 10 + ch; else str[1] = '0' + ch; ch = val >> 4; ch = ch & 0x0f; if (ch > 9) str[2] = 'A' - 10 + ch; else str[2] = '0' + ch; ch = val & 0x0f; if (ch > 9) str[3] = 'A' - 10 + ch; else str[3] = '0' + ch; vos_dev_write(hDev, (unsigned char *) str, 4, NULL); } void firmware(void) { unsigned char i; unsigned char status; unsigned char buf[64]; unsigned short num_read; unsigned int handle; char *startMsg = "Started\r\n"; char *foundMsg = "Found\r\n"; char *vidMsg = "VID: "; char *pidMsg = "PID: "; char *crMsg = "\r\n"; common_ioctl_cb_t uart_iocb; usbhostGeneric_ioctl_t generic_iocb; usbhostGeneric_ioctl_cb_attach_t genericAtt; usbhost_device_handle_ex ifDev; usbhost_ioctl_cb_t hc_iocb; usbhost_ioctl_cb_vid_pid_t hc_iocb_vid_pid; open_drivers(); /* UART ioctl call to enable DMA and link to DMA driver */ uart_iocb.ioctl_code = VOS_IOCTL_COMMON_ENABLE_DMA; vos_dev_ioctl(hUART, &uart_iocb); writeString(hUART, startMsg); do { // see if bus available if (usbhost_connect_state(hUSBHOST_1) == PORT_STATE_ENUMERATED) { // user ioctl to find first hub device hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_NEXT_HANDLE; hc_iocb.handle.dif = NULL; hc_iocb.set = NULL; hc_iocb.get = &ifDev; if (vos_dev_ioctl(hUSBHOST_1, &hc_iocb) == USBHOST_OK) { writeString(hUART, foundMsg); hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_VID_PID; hc_iocb.handle.dif = ifDev; hc_iocb.get = &hc_iocb_vid_pid; if (vos_dev_ioctl(hUSBHOST_1, &hc_iocb) == USBHOST_OK) { writeString(hUART, vidMsg); writeShort(hUART, hc_iocb_vid_pid.vid); writeString(hUART, crMsg); writeString(hUART, pidMsg); writeShort(hUART, hc_iocb_vid_pid.pid); writeString(hUART, crMsg); } hUSBHOSTGENERIC = vos_dev_open(VOS_DEV_USBHOSTGENERIC); genericAtt.hc_handle = hUSBHOST_1; genericAtt.ifDev = ifDev; generic_iocb.ioctl_code = VOS_IOCTL_USBHOSTGENERIC_ATTACH; generic_iocb.set.att = &genericAtt; if (vos_dev_ioctl(hUSBHOSTGENERIC, &generic_iocb) == USBHOSTGENERIC_OK) { while (1) { if (vos_dev_read(hUSBHOSTGENERIC, buf, 64, &num_read) == USBHOSTGENERIC_OK) { vos_dev_write(hUART, buf, num_read, NULL); } else { break; } } ; } vos_dev_close(hUSBHOSTGENERIC); } } } while (1); } ----------------------------------File Seperator------------------------------------------------------ /* ** USBHostBomsDrv.c ** ** Based on USBHostGeneric example by FTDI ** ** Modifications by Philip A. Polstra, Sr. ** ** Part of the USB Mass Storage Device impersonator as presented at DEFCON 20 ** Based on USB Write blocker presented at Blackhat Europe 2012 *** ** Note that we could try to use the FTDI-supplied BOMS driver, but for our ** purposes we really just want to forward most of the packets. Use of the ** standard driver might make things difficult when attempting to filter packets ** to/from our flash drive. ** */ #include "vos.h" #include "USBHost.h" #include "USB.h" #include "string.h" #include "USBHostBomsDrv.h" vos_driver_t usbhostBoms_cb; // open function void usbhostBoms_open(); // close function void usbhostBoms_close(); // USB Host IOCTL function unsigned char usbhostBoms_ioctl(usbhostBoms_ioctl_t *cb, usbhostBoms_context_t *ctx); usbhostBoms_context_t *hostBomsCtx=NULL; // This function must be called before the scheduler is started. // The function registers our driver with the VOS device manager. unsigned char usbhostBoms_init(unsigned char vos_dev_num) { hostBomsCtx = vos_malloc(sizeof(usbhostBoms_context_t)); memset(hostBomsCtx, 0, sizeof(usbhostBoms_context_t)); // Set up function pointers for our driver usbhostBoms_cb.flags = 0; usbhostBoms_cb.read = usbhostBoms_read; usbhostBoms_cb.write = usbhostBoms_write; usbhostBoms_cb.ioctl = usbhostBoms_ioctl; usbhostBoms_cb.interrupt = (PF_INT) NULL; usbhostBoms_cb.open = usbhostBoms_open; usbhostBoms_cb.close = usbhostBoms_close; // OK - register with device manager vos_dev_init(vos_dev_num, &usbhostBoms_cb, hostBomsCtx); return USBHOSTBOMS_OK; } // open function void usbhostBoms_open() { } // close function void usbhostBoms_close() { } // USBHOSTBoms read function unsigned char usbhostBoms_read(char *buf, unsigned short num_to_read, unsigned short *num_read, usbhostBoms_context_t *ctx) { unsigned short actual_read = 0; unsigned char status = USBHOSTBOMS_NOT_FOUND; usbhost_xfer_t xfer; vos_semaphore_t s; if (ctx->hc) { vos_init_semaphore(&s, 0); vos_memset(&xfer, 0, sizeof(usbhost_xfer_t)); xfer.buf = buf; xfer.len = num_to_read; xfer.ep = ctx->epBulkIn; xfer.s = &s; xfer.cond_code = USBHOST_CC_NOTACCESSED; xfer.flags = USBHOST_XFER_FLAG_START_BULK_ENDPOINT_LIST | USBHOST_XFER_FLAG_ROUNDING; status = vos_dev_read(ctx->hc, (unsigned char *) &xfer, sizeof(usbhost_xfer_t), NULL); if (status == USBHOST_OK) { status = (unsigned char)USBHOSTBOMS_OK; actual_read = xfer.len; } else { status |= (unsigned char)USBHOSTBOMS_USBHOST_ERROR; } } if (num_read) { *num_read = actual_read; } return status; } // USBHOSTBoms write function unsigned char usbhostBoms_write(char *buf, unsigned short num_to_write, unsigned short *num_written, usbhostBoms_context_t *ctx) { unsigned short actual_write = 0; unsigned char status = USBHOSTBOMS_NOT_FOUND; usbhost_xfer_t xfer; vos_semaphore_t s; if (ctx->hc) { vos_memset(&xfer, 0, sizeof(usbhost_xfer_t)); vos_init_semaphore(&s, 0); xfer.buf = buf; xfer.len = num_to_write; xfer.ep = ctx->epBulkOut; xfer.s = &s; xfer.cond_code = USBHOST_CC_NOTACCESSED; xfer.flags = USBHOST_XFER_FLAG_START_BULK_ENDPOINT_LIST; status = vos_dev_write(ctx->hc, (unsigned char *) &xfer, sizeof(usbhost_xfer_t), NULL); if (status == USBHOST_OK) { status = (unsigned char)USBHOSTBOMS_OK; actual_write = xfer.len; } else { status |= (unsigned char)USBHOSTBOMS_USBHOST_ERROR; } } if (num_written) { *num_written = actual_write; } return status; } // SETUP for IOCTL call unsigned char usbhostBoms_ioctl_setup(usbhostBoms_ioctl_t *cb, usbhostBoms_context_t *ctx) { // USBHost IOCTL structure usbhost_ioctl_cb_t hc_ioctl; // setup transfer descriptor usb_deviceRequest_t desc_dev; unsigned char buf[2]; unsigned char status; // setup Boms device desc_dev.bmRequestType = USB_BMREQUESTTYPE_DEV_TO_HOST | USB_BMREQUESTTYPE_STANDARD | USB_BMREQUESTTYPE_DEVICE; desc_dev.bRequest = USB_REQUEST_CODE_GET_STATUS; desc_dev.wValue = 0; desc_dev.wIndex = 0; desc_dev.wLength = 2; hc_ioctl.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_SETUP_TRANSFER; hc_ioctl.handle.ep = ctx->epCtrl; hc_ioctl.set = &desc_dev; hc_ioctl.get = buf; status = vos_dev_ioctl(ctx->hc, &hc_ioctl); if (status == USBHOST_OK) { // return status low byte to caller cb->get.data = buf[0]; return USBHOSTBOMS_OK; } return status | USBHOSTBOMS_USBHOST_ERROR; } // attach for IOCTL call unsigned char usbhostBoms_attach(usbhostBoms_ioctl_t *cb, usbhostBoms_context_t *ctx) { usbhostBoms_ioctl_cb_attach_t *atInfo; // ioctl request block usbhost_ioctl_cb_t hc_ioctl; usbhost_ioctl_cb_class_t hc_iocb_class; unsigned char status = USBHOSTBOMS_INVALID_PARAMETER; atInfo = cb->set.data; ctx->hc = atInfo->hc_handle; hc_iocb_class.dev_class = USB_CLASS_MASS_STORAGE; hc_iocb_class.dev_subclass = USB_SUBCLASS_MASS_STORAGE_SCSI; hc_iocb_class.dev_protocol = USB_PROTOCOL_MASS_STORAGE_BOMS; // user ioctl to find first hub device hc_ioctl.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_FIND_HANDLE_BY_CLASS; hc_ioctl.handle.dif = NULL; hc_ioctl.set = &hc_iocb_class; hc_ioctl.get = &atInfo->ifDev; if (vos_dev_ioctl(ctx->hc, &hc_ioctl) != USBHOST_OK) { return USBHOSTBOMS_NOT_FOUND; } do { // user ioctl to find control endpoint on this device hc_ioctl.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_CONTROL_ENDPOINT_HANDLE; hc_ioctl.handle.dif = atInfo->ifDev; hc_ioctl.get = &ctx->epCtrl; if (vos_dev_ioctl(ctx->hc, &hc_ioctl) != USBHOST_OK) { status = (unsigned char)USBHOSTBOMS_NOT_FOUND; break; } // user ioctl to find bulk endpoint on this device hc_ioctl.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_BULK_IN_ENDPOINT_HANDLE; hc_ioctl.handle.dif = atInfo->ifDev; hc_ioctl.get = &ctx->epBulkIn; if (vos_dev_ioctl(ctx->hc, &hc_ioctl) != USBHOST_OK) { status = (unsigned char)USBHOSTBOMS_NOT_FOUND; break; } // user ioctl to find bulk endpoint on this device hc_ioctl.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_BULK_OUT_ENDPOINT_HANDLE; hc_ioctl.handle.dif = atInfo->ifDev; hc_ioctl.get = &ctx->epBulkOut; if (vos_dev_ioctl(ctx->hc, &hc_ioctl) != USBHOST_OK) { status = (unsigned char)USBHOSTBOMS_NOT_FOUND; break; } status = (unsigned char)USBHOSTBOMS_OK; } while (0); return status; } // detach for IOCTL call void usbhostBoms_detach(usbhostBoms_context_t *ctx) { // remove link to host controller and endpoints ctx->hc = NULL; ctx->epCtrl = NULL; ctx->epBulkIn = NULL; ctx->epBulkOut = NULL; } // USBHOSTBoms IOCTL function unsigned char usbhostBoms_ioctl(usbhostBoms_ioctl_t *cb, usbhostBoms_context_t *ctx) { unsigned char status = USBHOSTBOMS_INVALID_PARAMETER; switch (cb->ioctl_code) { case VOS_IOCTL_USBHOSTBOMS_STATUS: status = usbhostBoms_ioctl_setup(cb, ctx); break; case VOS_IOCTL_USBHOSTBOMS_ATTACH: status = usbhostBoms_attach(cb, ctx); break; case VOS_IOCTL_USBHOSTBOMS_DETACH: usbhostBoms_detach(ctx); status = (unsigned char)USBHOSTBOMS_OK; break; default: break; } return status; } ----------------------------------File Seperator------------------------------------------------------ /* ** USBHostBomsDrv.h ** ** Based on USBHostGeneric example by FTDI ** ** Modifications by Philip A. Polstra, Sr. ** ** Part of the USB Mass Storage Device impersonator as presented at DEFCON 20 ** Based on USB Write blocker presented at Blackhat Europe 2012 ** ** Note that we could try to use the FTDI-supplied BOMS driver, but for our ** purposes we really just want to forward most of the packets. Use of the ** standard driver might make things difficult when attempting to filter packets ** to/from our flash drive. ** */ #ifndef USBHOSTBOMSDRV_H #define USBHOSTBOMSDRV_H #include "BomsDefs.h" // include CBW and CSW defs enum USBHOSTBOMS_STATUS { USBHOSTBOMS_OK = 0, USBHOSTBOMS_INVALID_PARAMETER, USBHOSTBOMS_ERROR, USBHOSTBOMS_NOT_FOUND, USBHOSTBOMS_USBHOST_ERROR = 0x80 }; // USBHostBoms Context // // Holds a context structure required by each instance of the driver typedef struct _usbhostBoms_context_t { // host controller handle VOS_HANDLE hc; // endpoint handles usbhost_ep_handle_ex epCtrl; usbhost_ep_handle_ex epBulkIn; usbhost_ep_handle_ex epBulkOut; } usbhostBoms_context_t; #define VOS_IOCTL_USBHOSTBOMS_ATTACH 1 #define VOS_IOCTL_USBHOSTBOMS_DETACH 2 #define VOS_IOCTL_USBHOSTBOMS_STATUS 3 // USBHostBoms IOCTL attach structure typedef struct _usbhostBoms_ioctl_cb_attach_t { VOS_HANDLE hc_handle; usbhost_device_handle_ex ifDev; } usbhostBoms_ioctl_cb_attach_t; // USBHostBoms IOCTL structure typedef struct _usbhostBoms_ioctl_t { unsigned char ioctl_code; union { unsigned char *data; usbhostBoms_ioctl_cb_attach_t *att; } set; union { unsigned char *data; } get; } usbhostBoms_ioctl_t; unsigned char usbhostBoms_init(unsigned char vos_dev_num); // read function unsigned char usbhostBoms_read( char *xfer, unsigned short num_to_read, unsigned short *num_read, usbhostBoms_context_t *ctx); // write function unsigned char usbhostBoms_write( char *xfer, unsigned short num_to_write, unsigned short *num_written, usbhostBoms_context_t *ctx); #endif /* USBHOSTBOMSDRV_H */ ----------------------------------File Seperator------------------------------------------------------ /* ** Filename: USBHostGeneric.h ** ** Automatically created by Application Wizard 1.4.2 ** ** Part of solution USBHostGeneric in project USBHostGeneric ** ** Comments: ** ** Important: Sections between markers "FTDI:S*" and "FTDI:E*" will be overwritten by ** the Application Wizard */ #ifndef _USBHostGeneric_H_ #define _USBHostGeneric_H_ #include "vos.h" /* FTDI:SHF Header Files */ #include "USB.h" #include "USBHost.h" #include "ioctl.h" #include "UART.h" #include "string.h" #include "errno.h" /* FTDI:EHF */ /* FTDI:SDC Driver Constants */ #define VOS_DEV_USBHOST_1 0 #define VOS_DEV_UART 1 #define VOS_NUMBER_DEVICES 3 /* FTDI:EDC */ // Additional Device Driver #define VOS_DEV_USBHOSTGENERIC 2 /* FTDI:SXH Externs */ /* FTDI:EXH */ #endif /* _USBHostGeneric_H_ */ ----------------------------------File Seperator------------------------------------------------------ /* ** USBSlaveBomsDrv.c ** ** Based on USBSlaveHIDKbd example by FTDI ** ** Modifications by Philip A. Polstra, Sr. ** ** Part of the USB Mass Storage Device impersonator as presented at DEFCON 20 ** Based on USB Write blocker presented at Blackhat Europe 2012 ** ** */ #include "vos.h" #include "devman.h" #include "memmgmt.h" #include "ioctl.h" #include "stdlib.h" #include "string.h" #include "USB.h" #include "USBHID.h" #include "USBSlave.h" #include "USBHost.h" #include "USBSlaveBomsDrv.h" #include "USBHostBomsDrv.h" #include "Timers.h" // function prototypes unsigned char standard_request(usbSlaveBoms_context *ctx); unsigned char class_request(usbSlaveBoms_context *ctx); void set_control_ep_halt(usbSlaveBoms_context *ctx); // vidPid is in the file drives.h // see the comments in the file for the source // this is stored in ROM to avoid sucking up RAM which // is precious when you only have 16k versus a whopping // 256k of flash #include "drives.h" unsigned int currentVidPidIndex = 0; // index to the current VID/PID in use extern VOS_HANDLE hTimer; // this is the timer that triggers if device doesn't connect extern VOS_HANDLE hGPIO_PORT_B; // port B for LCD display extern vos_mutex_t vidPidMutex; // mutex for current vid/pid extern unsigned char writeProtect; // boolean write protect value unsigned char usbSlaveBoms_ioctl(common_ioctl_cb_t *cb, usbSlaveBoms_context *ctx); extern void write_lcd_line1(VOS_HANDLE hLcd, char* str); extern void write_lcd_line2(VOS_HANDLE hLcd, char* str); extern void update_lcd_vidpid(); // thread states #define UNATTACHED 0 #define ATTACHED 1 // Every USB device has an 18 byte descriptor // This descriptor is immediately retrieved by the host/hub in order // to determine how to talk to the device // Note: All USB values are little-endian (LSB first) unsigned char device_descriptor[18] = { 18, //length in bytes 1, // descriptor type 1=device 0x0, 2, // USB version BCD USB version 0, // device class 0=actual device class in interface descriptor 0, // device subclass 0=actual device class in interface descriptor 0, // device protocol 0=actual device class in interface descriptor 64, // max packet size is 64 bytes for full speed endpoints 0x4b, 0x15, // vendor id // currently spoof PNY drive 0x40, 0, // product id 0, 0x01, // device release number in BCD 1, // string descriptor index for manufacturer 2, // string descriptor index for product 3, // string descriptor index for serial number 1 // number of possible configurations }; // The configuration header is actually a composite of // configuration, interface, and endpoint descriptors // The host will typically ask for the first part of the // descriptor (first 9 bytes) which contains the total descriptor length. // The host will then make a second request for the entire descriptor unsigned char config_descriptor[32] = { // Configuration Header 9, // length 2, // descriptor type 2 = configuration 32, 0, // bytes in this and all subordinate descriptors 1, // number of interfaces 1, // configuration value 0, // index of string descriptor for configurations 0x80, // self/bus power and remote wakeup 50, // max power in milliamps /2 asking for too much can cause enum to fail // Interface 9, // length 4, // descriptor type 4 = interface 0, // interface number 0, // alternate setting - 00 is default 2, // number of endpoints other than control (1 bulk in, 1 bulk out) 8, // class type 8 for mass storage 6, // subclass 6 means SCSI transport 0x50, // interface protocol 0, // index of string descriptor for the interface // Endpoint, EP1_In 7, // length 5, // endpoint descriptor 0x81, // endpoint address bit7-1 = in 2, // attributes 2=bulk 0x40, 0x00, // max packet size 64 bytes 1, // polling interval, ignored for bulk endpoints // Endpoint, EP2_Out 7, // length 5, // endpoint descriptor 0x02, // endpoint address bit7-1 = in 2, // attributes 2=bulk 0x40, 0x00, // max packet size 1 // polling interval, ignored for bulk endpoints }; // language descriptor // Requests for string descriptor 0 return a code for the default // language. Devices could support multiple languages. In practice, // everyone seems to support US English only, even if they are from // Glasgouw, UK. unsigned char str0_descriptor[4] = { 0x04, // length 0x03, // type 3=string 0x09, 0x04 // US English }; // According to our configuration descriptor, string descriptor 2 // is a product ID. This Product descriptor was borrowed from an // actual flash drive. Alternatively, we could query the actual // information from the flash drive, but we fake it to make things // a bit simplier. These descriptors all use UNICODE unsigned char str2_descriptor[22] = { 22, // length 3, // string descriptor 0x55, 0, //USB 2.0 FD 0x53, 0, 0x42, 0, 0x20, 0, 0x32, 0, 0x2e, 0, 0x30, 0, 0x20, 0, 0x46, 0, 0x44, 0 }; // According to our configuration descriptor, string descriptor 1 // is the manufacturer. In this case we have borrowed PNY. unsigned char str1_descriptor[8] = { 8, // length 3, // string descriptor 0x50, 0, // PNY 0x4e, 0, 0x59, 0 }; // Every mass storage device is required to have a serial number // the last 12 digits must be unique. There is no other specification // on how these are assigned. Note that Windows will store this and // lots of other information in the registry. USBDevView is a nice // free utility for viewing this information. // More information on USB forensics can be found in my 44Con video // which is available on SecurityTube or youtube. unsigned char str3_descriptor[30] = { 30, // length 3, // string descriptor 0x55, 0, // UTYM0832030481 0x54, 0, 0x59, 0, 0x4d, 0, 0x30, 0, 0x38, 0, 0x33, 0, 0x32, 0, 0x30, 0, 0x33, 0, 0x30, 0, 0x34, 0, 0x38, 0, 0x31, 0 }; // global variables are evil, but sometimes when // dealing with memory-constrained microcontrollers // they are somewhat unavoidable usbSlaveBoms_context *slaveBomsCtx=NULL; extern usbhostBoms_context_t *hostBomsCtx; // These are the only 2 Class requests sent on the control endpoint // BOMS devices send requests in the CBW on the bulk out endpoint #define GET_MAX_LUN 0xfe #define BOMS_RESET 0xff // The following functions are for stalling and clearing bulk endpoints // There are some conditions which require us to stall these endpoints. // For example, if we return less data than expected to the PC we // must stall the endpoint so it doesn't hang forever waiting for the rest // of the data. void usbslaveboms_stall_bulk_in(usbSlaveBoms_context *ctx) { usbslave_ioctl_cb_t iocb; // this is a structure used by underlying VOS driver iocb.ioctl_code = VOS_IOCTL_USBSLAVE_ENDPOINT_STALL; iocb.ep = 0x81; // bulk in endpoint vos_dev_ioctl(ctx->handle, &iocb); } void usbslaveboms_stall_bulk_out(usbSlaveBoms_context *ctx) { usbslave_ioctl_cb_t iocb; // this is a structure used by underlying VOS driver iocb.ioctl_code = VOS_IOCTL_USBSLAVE_ENDPOINT_STALL; iocb.ep = 0x02; // bulk out endpoint vos_dev_ioctl(ctx->handle, &iocb); } void usbslaveboms_clear_bulk_in(usbSlaveBoms_context *ctx) { usbslave_ioctl_cb_t iocb; // this is a structure used by underlying VOS driver iocb.ioctl_code = VOS_IOCTL_USBSLAVE_ENDPOINT_CLEAR; iocb.ep = 0x81; // bulk in endpoint vos_dev_ioctl(ctx->handle, &iocb); } void usbslaveboms_clear_bulk_out(usbSlaveBoms_context *ctx) { usbslave_ioctl_cb_t iocb; // this is a structure used by underlying VOS driver iocb.ioctl_code = VOS_IOCTL_USBSLAVE_ENDPOINT_CLEAR; iocb.ep = 0x02; // bulk out endpoint vos_dev_ioctl(ctx->handle, &iocb); } // This function MUST BE CALLED BEFORE THE SCHEDULER IS STARTED // It initializes (initialises for you Brits reading this) variables // in the context structure, registers our driver with the // VOS device manager, and creates the thread for handling // requests on the control endpoint. unsigned char usbslaveboms_init(unsigned char vos_dev_num) { vos_driver_t *usbSlaveBoms_cb; slaveBomsCtx = vos_malloc(sizeof(usbSlaveBoms_context)); if (slaveBomsCtx == NULL) return USBSLAVEBOMS_ERROR; //somehow ran out of RAM usbSlaveBoms_cb = vos_malloc(sizeof(vos_driver_t)); if (usbSlaveBoms_cb == NULL) { vos_free(slaveBomsCtx); return USBSLAVEBOMS_ERROR; } // Set up function pointers for our driver usbSlaveBoms_cb->flags = 0; usbSlaveBoms_cb->read = usbSlaveBoms_read; usbSlaveBoms_cb->write = usbSlaveBoms_write; usbSlaveBoms_cb->ioctl = usbSlaveBoms_ioctl; usbSlaveBoms_cb->interrupt = (PF_INT) NULL; usbSlaveBoms_cb->open = (PF_OPEN) NULL; usbSlaveBoms_cb->close = (PF_CLOSE) NULL; // OK - register with device manager vos_dev_init(vos_dev_num, usbSlaveBoms_cb, slaveBomsCtx); // defaults to not connected and no flash drive yet slaveBomsCtx->attached = 0; slaveBomsCtx->flashConnected = 0; // create the thread that handles standard control requests slaveBomsCtx->tcbSetup = vos_create_thread_ex(31, SIZEOF_BOMS_SETUP_MEMORY, usbslaveboms_setup, "BOMSSetup", 2, slaveBomsCtx); // initialize the sempahore to 0 so that anyone waiting for // the device to enum will block vos_init_semaphore(&slaveBomsCtx->enumed, 0); if (slaveBomsCtx->tcbSetup) return USBSLAVEBOMS_OK; return USBSLAVEBOMS_ERROR; } // This function is run inside the thread created in init // It will respond to standard USB requests // some of the requests are forwarded to the flash drive when appropriate void usbslaveboms_setup(usbSlaveBoms_context *ctx) { usbslave_ioctl_cb_t iocb; // this is a structure used by underlying VOS driver usb_deviceRequest_t *devReq; // this struct is defined in usb.h and is used to store the 9 byte setup request unsigned char bmRequestType; // The request type is defined by USB standard unsigned char state = UNATTACHED; // assume unattached at the start // This will wait till the flash drive is enumed so we don't // start responding to commands right away vos_wait_semaphore(&ctx->enumed); vos_signal_semaphore(&ctx->enumed); while (1) { switch (state) { case UNATTACHED: if (!ctx->attached) vos_delay_msecs(100); // this delay is to avoid a tight loop else { state = ATTACHED; } break; case ATTACHED: if (!ctx->attached) // check to see if we somehow became unattached { state = UNATTACHED; break; } // we now make a blocking call requesting the 9 byte setup // packet on the control endpoint iocb.ioctl_code = VOS_IOCTL_USBSLAVE_WAIT_SETUP_RCVD; iocb.request.setup_or_bulk_transfer.buffer = ctx->setup_buffer; iocb.request.setup_or_bulk_transfer.size = 9; vos_dev_ioctl(ctx->handle, &iocb); // decode the raw data by pointing to our structure devReq = (usb_deviceRequest_t *) ctx->setup_buffer; // valid types here are standard, class, and vendor // BOMS devices do not have vendor specific calls // even if they did, we wouldn't support them. bmRequestType = devReq->bmRequestType & (USB_BMREQUESTTYPE_STANDARD | USB_BMREQUESTTYPE_CLASS); // we only need to handle standard and class requests for BOMS if (bmRequestType == USB_BMREQUESTTYPE_STANDARD) { standard_request(ctx); // standard request that all USB devices support } else if (bmRequestType == USB_BMREQUESTTYPE_CLASS) { class_request(ctx); // the request is specific to this device class (only 2 in our case) } break; default: asm {HALT}; // if we somehow got here the fecal matter has hit the turbine break; } } return; } // this function just marks our device as detached void usbSlaveBoms_detach(usbSlaveBoms_context *ctx) { ctx->attached = 0; return; } // this function will present our device to the PC and cause it // to be enumed. unsigned char usbSlaveBoms_attach(VOS_HANDLE handle, usbSlaveBoms_context *ctx) { usbslave_ioctl_cb_t iocb; unsigned char status = USBSLAVEBOMS_OK; // save usb slave handle ctx->handle = handle; if (!ctx->attached) { // issue connect IOCTL call here to present ourselves to the host // MUST be called before configuring endpoints // Note: If you used older versions of the VNC2 toolchain this function // was added and the need to make this call is buried in the release // notes. Upgraders of old code be warned! iocb.ioctl_code = VOS_IOCTL_USBSLAVE_CONNECT; iocb.set = (void *) 0; vos_dev_ioctl(ctx->handle,&iocb); // get endpoint handles and set max packet sizes // these should match the descriptor values! iocb.ioctl_code = VOS_IOCTL_USBSLAVE_GET_CONTROL_ENDPOINT_HANDLE; iocb.ep = USBSLAVE_CONTROL_IN; iocb.get = &ctx->in_ep0; vos_dev_ioctl(ctx->handle, &iocb); iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SET_ENDPOINT_MAX_PACKET_SIZE; iocb.handle = ctx->in_ep0; iocb.request.ep_max_packet_size = USBSLAVE_MAX_PACKET_SIZE_64; vos_dev_ioctl(ctx->handle, &iocb); iocb.ioctl_code = VOS_IOCTL_USBSLAVE_GET_CONTROL_ENDPOINT_HANDLE; iocb.ep = USBSLAVE_CONTROL_OUT; iocb.get = &ctx->out_ep0; vos_dev_ioctl(ctx->handle, &iocb); iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SET_ENDPOINT_MAX_PACKET_SIZE; iocb.handle = ctx->out_ep0; iocb.request.ep_max_packet_size = USBSLAVE_MAX_PACKET_SIZE_64; vos_dev_ioctl(ctx->handle, &iocb); iocb.ioctl_code = VOS_IOCTL_USBSLAVE_GET_BULK_IN_ENDPOINT_HANDLE; iocb.ep = USBSLAVEBOMS_IN; iocb.get = &ctx->in_ep; vos_dev_ioctl(ctx->handle, &iocb); iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SET_ENDPOINT_MAX_PACKET_SIZE; iocb.handle = ctx->in_ep; iocb.request.ep_max_packet_size = USBSLAVE_MAX_PACKET_SIZE_64; vos_dev_ioctl(ctx->handle, &iocb); iocb.ioctl_code = VOS_IOCTL_USBSLAVE_GET_BULK_OUT_ENDPOINT_HANDLE; iocb.ep = USBSLAVEBOMS_OUT; iocb.get = &ctx->out_ep; vos_dev_ioctl(ctx->handle, &iocb); iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SET_ENDPOINT_MAX_PACKET_SIZE; iocb.handle = ctx->out_ep; iocb.request.ep_max_packet_size = USBSLAVE_MAX_PACKET_SIZE_64; vos_dev_ioctl(ctx->handle, &iocb); ctx->attached = 1; // mark our device as attached and configured } return status; } // write function // This function will send up to the specified number of bytes to // the bulk in endpoint unsigned char usbSlaveBoms_write( char *xfer, unsigned short num_to_write, unsigned short *num_written, usbSlaveBoms_context *ctx) { usbslave_ioctl_cb_t iocb; if(ctx->attached) { iocb.ioctl_code = VOS_IOCTL_USBSLAVE_TRANSFER; iocb.handle = ctx->in_ep; iocb.request.setup_or_bulk_transfer.buffer = xfer; iocb.request.setup_or_bulk_transfer.size = num_to_write; vos_dev_ioctl(ctx->handle, &iocb); if (num_written) // callers who don't care might pass NULL here let's not crash! *num_written = iocb.request.setup_or_bulk_transfer.bytes_transferred; } else { return USBSLAVEBOMS_ERROR; } return USBSLAVEBOMS_OK; } // read function // This function reads up to num_to_read bytes from the bulk out endpoint. unsigned char usbSlaveBoms_read( char *xfer, unsigned short num_to_read, unsigned short *num_read, usbSlaveBoms_context *ctx) { usbslave_ioctl_cb_t iocb; if (ctx->attached) { iocb.ioctl_code = VOS_IOCTL_USBSLAVE_TRANSFER; iocb.handle = ctx->out_ep; iocb.request.setup_or_bulk_transfer.buffer = xfer; iocb.request.setup_or_bulk_transfer.size = num_to_read; vos_dev_ioctl(ctx->handle, &iocb); if (num_read) // allow caller to pass NULL if they don't care how many bytes *num_read = iocb.request.setup_or_bulk_transfer.bytes_transferred; } else { return USBSLAVEBOMS_ERROR; } return USBSLAVEBOMS_OK; } // write function // This function will send up to the specified number of bytes to // the bulk in endpoint then it will stall (short write) unsigned char usbSlaveBoms_short_write( char *xfer, unsigned short num_to_write, unsigned short *num_written, usbSlaveBoms_context *ctx) { usbslave_ioctl_cb_t iocb; if(ctx->attached) { iocb.ioctl_code = VOS_IOCTL_USBSLAVE_TRANSFER; iocb.handle = ctx->in_ep; iocb.request.setup_or_bulk_transfer.buffer = xfer; iocb.request.setup_or_bulk_transfer.size = num_to_write; vos_dev_ioctl(ctx->handle, &iocb); if (num_written) // callers who don't care might pass NULL here let's not crash! *num_written = iocb.request.setup_or_bulk_transfer.bytes_transferred; usbslaveboms_stall_bulk_in(ctx); } else { return USBSLAVEBOMS_ERROR; } return USBSLAVEBOMS_OK; } // read function // This function reads up to num_to_read bytes from the bulk out endpoint. // This function will stall the endpoint when done unsigned char usbSlaveBoms_short_read( char *xfer, unsigned short num_to_read, unsigned short *num_read, usbSlaveBoms_context *ctx) { usbslave_ioctl_cb_t iocb; if (ctx->attached) { iocb.ioctl_code = VOS_IOCTL_USBSLAVE_TRANSFER; iocb.handle = ctx->out_ep; iocb.request.setup_or_bulk_transfer.buffer = xfer; iocb.request.setup_or_bulk_transfer.size = num_to_read; vos_dev_ioctl(ctx->handle, &iocb); if (num_read) // allow caller to pass NULL if they don't care how many bytes *num_read = iocb.request.setup_or_bulk_transfer.bytes_transferred; usbslaveboms_stall_bulk_out(ctx); } else { return USBSLAVEBOMS_ERROR; } return USBSLAVEBOMS_OK; } // This function reads the 31 byte CBW from the bulk out endpoint // The value is returned directly into the boms_cbw_t structure unsigned char usbSlaveBoms_readCbw( boms_cbw_t *cbw, usbSlaveBoms_context *ctx) { usbslave_ioctl_cb_t iocb; if (ctx->attached) { iocb.ioctl_code = VOS_IOCTL_USBSLAVE_TRANSFER; iocb.handle = ctx->out_ep; iocb.request.setup_or_bulk_transfer.buffer = (unsigned char*)cbw; iocb.request.setup_or_bulk_transfer.size = 31; //CBW is 31 bytes vos_dev_ioctl(ctx->handle, &iocb); } else { return USBSLAVEBOMS_ERROR; } return USBSLAVEBOMS_OK; } // USB Slave IOCTL function unsigned char usbSlaveBoms_ioctl(common_ioctl_cb_t *cb, usbSlaveBoms_context *ctx) { unsigned char status = USBSLAVEBOMS_INVALID_PARAMETER; switch (cb->ioctl_code) { case VOS_IOCTL_USBSLAVEBOMS_ATTACH: status = usbSlaveBoms_attach((VOS_HANDLE) cb->set.data, ctx); break; case VOS_IOCTL_USBSLAVEBOMS_DETACH: usbSlaveBoms_detach(ctx); status = (unsigned char)USBSLAVEBOMS_OK; break; default: break; } return status; } // All commands on the control endpoint must be acknowledged. // This is done by sending a Zero Length Data Packet ZLDP // on the control in endpoint. void ack_request(usbSlaveBoms_context *ctx) { usbslave_ioctl_cb_t iocb; iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER; iocb.handle = ctx->in_ep0; iocb.request.setup_or_bulk_transfer.buffer = (void *) 0; iocb.request.setup_or_bulk_transfer.size = 0; vos_dev_ioctl(ctx->handle, &iocb); } // When initially attached to a host devices have no address and are // assigned an adddress after enumeration. Then the device is reset // and fully enumerated. void set_address_request(usbSlaveBoms_context *ctx, unsigned char addr) { usbslave_ioctl_cb_t iocb; iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SET_ADDRESS; iocb.set = (void *) addr; vos_dev_ioctl(ctx->handle, &iocb); ack_request(ctx); } // Most devices support only one configuration. However, every // device must respond to this call asking them to select a // configuration even if it is the default. void set_configuration_request(usbSlaveBoms_context *ctx, unsigned char config) { usbslave_ioctl_cb_t iocb; iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SET_CONFIGURATION; iocb.set = (void *) config; vos_dev_ioctl(ctx->handle, &iocb); ack_request(ctx); } // handle requests for a descriptor void get_descriptor_request(usbSlaveBoms_context *ctx) { unsigned char *buffer; // buffer for pass thru to drive usbhost_ioctl_cb_t hc_ioctl; usbslave_ioctl_cb_t iocb; usb_deviceRequest_t *devReq; unsigned char hValue; // high byte of the descriptor requested unsigned char lValue; // low byte of the descriptor requested unsigned short wLength; unsigned short siz; uint32 ul_siz; unsigned char *src; unsigned char cond; tmr_ioctl_cb_t tmr_iocb; devReq = (usb_deviceRequest_t *) ctx->setup_buffer; hValue = devReq->wValue >> 8; // shift away the low byte lValue = devReq->wValue & 0xff; // and away the high byte wLength = devReq->wLength; switch (hValue) // the high byte determines type of descriptor requested { case USB_DESCRIPTOR_TYPE_DEVICE: ul_siz = (uint32) wLength; iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER; iocb.handle = ctx->in_ep0; // update the device descriptor VID/PID from our list vos_lock_mutex(&vidPidMutex); device_descriptor[8] = vidPid[currentVidPidIndex] & 0xff; device_descriptor[9] = vidPid[currentVidPidIndex] >> 8; device_descriptor[10] = vidPid[currentVidPidIndex+1] & 0xff; device_descriptor[11] = vidPid[currentVidPidIndex+1] >> 8; vos_unlock_mutex(&vidPidMutex); //updated LCD update_lcd_vidpid(); iocb.request.setup_or_bulk_transfer.buffer = device_descriptor; iocb.request.setup_or_bulk_transfer.size = (int16) ul_siz; vos_dev_ioctl(ctx->handle, &iocb); // start this timer and if it is not killed then the next VID/PID will be selected // this is done to detect an unsuccessful enumeration which is assumed // to result from endpoint security blocking tmr_iocb.ioctl_code = VOS_IOCTL_TIMER_START; vos_dev_ioctl(hTimer, &tmr_iocb); return; break; case USB_DESCRIPTOR_TYPE_CONFIGURATION: // host will initially ask for first 9 bytes of configuration descriptor // this descriptor header has the size of the full descriptor which // is actually a composite of the configuration/interface/endpoints. // Once host knows the complete descriptor size it makes a second // request for the whole thing siz = wLength == 9?9:sizeof(config_descriptor); ul_siz = (uint32) siz; iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER; iocb.handle = ctx->in_ep0; iocb.request.setup_or_bulk_transfer.buffer = config_descriptor; iocb.request.setup_or_bulk_transfer.size = (int16) ul_siz; vos_dev_ioctl(ctx->handle, &iocb); // stop the timer because we are being asked to enumerate tmr_iocb.ioctl_code = VOS_IOCTL_TIMER_STOP; vos_dev_ioctl(hTimer, &tmr_iocb); return; case USB_DESCRIPTOR_TYPE_STRING: if (lValue == 0) // language type { src = str0_descriptor; siz = sizeof(str0_descriptor); } else if (lValue == 1) // manufacturer { src = str1_descriptor; siz = sizeof(str1_descriptor); } else if (lValue == 2) // product { src = str2_descriptor; siz = sizeof(str2_descriptor); } else if (lValue == 3) // serial number { src = str3_descriptor; siz = sizeof(str3_descriptor); } cond = (unsigned char) (wLength != siz); if (siz > wLength) // don't return more than was asked for siz = wLength; ul_siz = (uint32) siz; iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER; iocb.handle = ctx->in_ep0; iocb.request.setup_or_bulk_transfer.buffer = src; iocb.request.setup_or_bulk_transfer.size = (int16) ul_siz; vos_dev_ioctl(ctx->handle, &iocb); return; default: // if drive is connected get descriptor from it if (ctx->flashConnected) { buffer = vos_malloc(wLength); hc_ioctl.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_SETUP_TRANSFER; hc_ioctl.handle.ep = hostBomsCtx->epCtrl; hc_ioctl.set = &(ctx->setup_buffer[0]); hc_ioctl.get = buffer; // descriptor from drive vos_dev_ioctl(hostBomsCtx->hc, &hc_ioctl); iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER; iocb.handle = ctx->in_ep0; iocb.request.setup_or_bulk_transfer.buffer = buffer; iocb.request.setup_or_bulk_transfer.size = wLength; vos_dev_ioctl(ctx->handle, &iocb); vos_free(buffer); } else { // respond with Request Error set_control_ep_halt(ctx); } } } // This function will set a feature. If it is directed at an // endpoint the endpoint will stall. // Note: the endpoint passed in is the USB endpoint from the setup request // packet, not the VOS endpoint handle. Unfortunately, most of the // FTDI defined types are are just typedefs so no real type checking // is going on here. void set_feature_request(usbSlaveBoms_context *ctx, unsigned char ep) { usbslave_ioctl_cb_t iocb; usbhost_ep_handle_ex hep; // host endpoint to pass stall to usbhost_ioctl_cb_t host_ioctl_cb; ack_request(ctx); // first ack the request then decide what to do // is this directed at an endpoint or the device? if (ctx->setup_buffer[0] & USB_BMREQUESTTYPE_ENDPOINT) { // directed to an endpoint //ep 1 is IN 2 is OUT on my fake device iocb.ioctl_code = VOS_IOCTL_USBSLAVE_ENDPOINT_STALL; iocb.ep = (ep & 0x02)?ctx->out_ep:ctx->in_ep; vos_dev_ioctl(ctx->handle, &iocb); // if flash drive is attached pass along request if (ctx->flashConnected) { //need to figure out which endpoint to stall // if b7=1 then IN else OUT if (ep & 0x80) { hep = hostBomsCtx->epBulkIn; } else { hep = hostBomsCtx->epBulkOut; } host_ioctl_cb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_SET_HOST_HALT; host_ioctl_cb.handle.ep = hep; // clear halt state on endpoint vos_dev_ioctl(hostBomsCtx->hc, &host_ioctl_cb); } } else { // this is a device request host_ioctl_cb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_SETUP_TRANSFER; host_ioctl_cb.handle.ep = hostBomsCtx->epCtrl; host_ioctl_cb.set = &(ctx->setup_buffer[0]); host_ioctl_cb.get = NULL; vos_dev_ioctl(hostBomsCtx->hc, &host_ioctl_cb); } } // This function is the complement to the set_feature_request function. void clear_feature_request(usbSlaveBoms_context *ctx, unsigned char ep) { usbslave_ioctl_cb_t iocb; usbhost_ep_handle_ex hep; // host endpoint to pass stall to usbhost_ioctl_cb_t host_ioctl_cb; ack_request(ctx); // is this directed at an endpoint or the device? if (ctx->setup_buffer[0] & USB_BMREQUESTTYPE_ENDPOINT) { // directed to an endpoint //ep 1 is IN 2 is OUT on my fake device iocb.ioctl_code = VOS_IOCTL_USBSLAVE_ENDPOINT_CLEAR; iocb.ep = (ep & 0x02)?ctx->out_ep:ctx->in_ep; vos_dev_ioctl(ctx->handle, &iocb); // if flash drive is attached pass along request if (ctx->flashConnected) { //need to figure out which endpoint to clear // if b7=1 then IN else OUT if (ep & 0x80) { hep = hostBomsCtx->epBulkIn; } else { hep = hostBomsCtx->epBulkOut; } host_ioctl_cb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_CLEAR_HOST_HALT; host_ioctl_cb.handle.ep = hep; // clear halt state on endpoint vos_dev_ioctl(hostBomsCtx->hc, &host_ioctl_cb); } } else { // this is a device request host_ioctl_cb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_SETUP_TRANSFER; host_ioctl_cb.handle.ep = hostBomsCtx->epCtrl; host_ioctl_cb.set = &(ctx->setup_buffer[0]); host_ioctl_cb.get = NULL; vos_dev_ioctl(hostBomsCtx->hc, &host_ioctl_cb); } } // This function returns a 1 byte status code for our endpoint void get_ep_status(usbSlaveBoms_context *ctx, usbslave_ep_handle_t ep) { usbslave_ioctl_cb_t iocb; char state; iocb.ioctl_code = VOS_IOCTL_USBSLAVE_ENDPOINT_STATE; iocb.ep = ep; iocb.get = &state; vos_dev_ioctl(ctx->handle, &iocb); iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER; iocb.handle = ctx->out_ep0; iocb.request.setup_or_bulk_transfer.buffer = (void *) &state; iocb.request.setup_or_bulk_transfer.size = 1; vos_dev_ioctl(ctx->handle, &iocb); } // This function will halt the control endpoint. This function will only // be called when an illegal request has been passed to the device. void set_control_ep_halt(usbSlaveBoms_context *ctx) { usbslave_ioctl_cb_t iocb; ack_request(ctx); // Performs a protocol stall on endpoint 0 // Indicates that a request is unsupported iocb.ioctl_code = VOS_IOCTL_USBSLAVE_ENDPOINT_STALL; iocb.ep = 0; vos_dev_ioctl(ctx->handle, &iocb); } // This returns the device status. Only the two lowest bits // have any meaning here. B0=1 means device is self-powered. // B0 = 0 means the device is bus-powered. // B1 = 1 means that remote wakeup is enabled // This request can also be used for interface status which // should just return all zeroes or endpoint status. Endpoint // status halted/cleared is indicated by the LSB. void get_status_request(usbSlaveBoms_context *ctx) { unsigned short status = 0; usbslave_ioctl_cb_t iocb; usbhost_ioctl_cb_t hc_ioctl; // if drive is connected get status from it if (ctx->flashConnected) { hc_ioctl.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_SETUP_TRANSFER; hc_ioctl.handle.ep = hostBomsCtx->epCtrl; hc_ioctl.set = &(ctx->setup_buffer[0]); hc_ioctl.get = &status; // status returned from the drive vos_dev_ioctl(hostBomsCtx->hc, &hc_ioctl); } iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER; iocb.handle = ctx->in_ep0; iocb.request.setup_or_bulk_transfer.buffer = &status; iocb.request.setup_or_bulk_transfer.size = 2; vos_dev_ioctl(ctx->handle, &iocb); } // This function returns one byte. If the byte is zero this indicates // that the device is not ready. Non-zero means everything is OK. void get_configuration_request(usbSlaveBoms_context *ctx) { unsigned char status = 0; usbslave_ioctl_cb_t iocb; usbhost_ioctl_cb_t hc_ioctl; // if drive is connected get status from it if (ctx->flashConnected) { hc_ioctl.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_SETUP_TRANSFER; hc_ioctl.handle.ep = hostBomsCtx->epCtrl; hc_ioctl.set = &(ctx->setup_buffer[0]); hc_ioctl.get = &status; // status returned from the drive vos_dev_ioctl(hostBomsCtx->hc, &hc_ioctl); } iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER; iocb.handle = ctx->in_ep0; iocb.request.setup_or_bulk_transfer.buffer = &status; iocb.request.setup_or_bulk_transfer.size = 1; vos_dev_ioctl(ctx->handle, &iocb); } // This request should never be sent to our device, but since this // is a standard request we will accept it and just do nothing. void set_descriptor_request(usbSlaveBoms_context *ctx, unsigned short wLength) { unsigned char *buffer; usbslave_ioctl_cb_t iocb; usbhost_ioctl_cb_t hc_ioctl; ack_request(ctx); // We read in the info here but throw it away buffer = vos_malloc(wLength); iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER; iocb.handle = ctx->out_ep0; iocb.request.setup_or_bulk_transfer.buffer = buffer; iocb.request.setup_or_bulk_transfer.size = wLength; vos_dev_ioctl(ctx->handle, &iocb); vos_free(buffer); } // This function returns a single byte. We will just fake // it and return zero. void get_interface_request(usbSlaveBoms_context *ctx) { unsigned char status = 0; usbslave_ioctl_cb_t iocb; usbhost_ioctl_cb_t hc_ioctl; iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER; iocb.handle = ctx->in_ep0; iocb.request.setup_or_bulk_transfer.buffer = &status; iocb.request.setup_or_bulk_transfer.size = 1; vos_dev_ioctl(ctx->handle, &iocb); } // We just ack this request. void set_interface_request(usbSlaveBoms_context *ctx) { ack_request(ctx); } // This is the main handler function for requests coming in on // the control endpoint. These are all requests every USB device // must respond to. unsigned char standard_request(usbSlaveBoms_context *ctx) { usb_deviceRequest_t *devReq; unsigned char status = USBSLAVE_OK; unsigned char bReq; devReq = (usb_deviceRequest_t *) ctx->setup_buffer; bReq = devReq->bRequest; switch (bReq) // request is 1 byte value { case USB_REQUEST_CODE_GET_STATUS: get_status_request(ctx); break; case USB_REQUEST_CODE_SET_ADDRESS: set_address_request(ctx, devReq->wValue & 0xff); break; case USB_REQUEST_CODE_GET_DESCRIPTOR: get_descriptor_request(ctx); break; case USB_REQUEST_CODE_SET_DESCRIPTOR: set_descriptor_request(ctx, devReq->wLength); break; case USB_REQUEST_CODE_SET_CONFIGURATION: set_configuration_request(ctx, devReq->wValue & 0xff); break; case USB_REQUEST_CODE_GET_CONFIGURATION: get_configuration_request(ctx); break; case USB_REQUEST_CODE_CLEAR_FEATURE: clear_feature_request(ctx, devReq->wIndex >> 8); break; case USB_REQUEST_CODE_SET_FEATURE: set_feature_request(ctx, devReq->wIndex >> 8); break; case USB_REQUEST_CODE_GET_INTERFACE: get_interface_request(ctx); break; case USB_REQUEST_CODE_SET_INTERFACE: set_interface_request(ctx); break; default: // force a protocol stall set_control_ep_halt(ctx); break; } return status; } void class_ack(usbSlaveBoms_context *ctx) { ack_request(ctx); } void class_control_out(usbSlaveBoms_context *ctx, char *buffer, unsigned short len) { usbslave_ioctl_cb_t iocb; iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER; iocb.handle = ctx->out_ep0; iocb.request.setup_or_bulk_transfer.buffer = (void *) buffer; iocb.request.setup_or_bulk_transfer.size = len; vos_dev_ioctl(ctx->handle, &iocb); } // This is one of two class requests for BOMS devices. // If we are not connected we return 0 which is the most // common situation. Windows may not recognize higher LUNs. void get_max_lun_request(usbSlaveBoms_context *ctx) { unsigned char maxLun = 0; usbslave_ioctl_cb_t iocb; usbhost_ioctl_cb_t hc_ioctl; // if drive is connected get max lun from it if (ctx->flashConnected) { hc_ioctl.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_SETUP_TRANSFER; hc_ioctl.handle.ep = hostBomsCtx->epCtrl; hc_ioctl.set = &(ctx->setup_buffer[0]); hc_ioctl.get = &maxLun; // maximum LUN from drive vos_dev_ioctl(hostBomsCtx->hc, &hc_ioctl); } iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER; iocb.handle = ctx->in_ep0; iocb.request.setup_or_bulk_transfer.buffer = &maxLun; iocb.request.setup_or_bulk_transfer.size = 1; vos_dev_ioctl(ctx->handle, &iocb); } // The USB standards define this function. After it is called // the drive should be ready to respond to CBWs. The silly // thing about this is that the drive should always be ready // for this and if it isn't then it probable crashed long ago. void boms_reset_request(usbSlaveBoms_context *ctx) { usbhost_ioctl_cb_t hc_ioctl; ack_request(ctx); // forward this command to a drive if connected if (ctx->flashConnected) { hc_ioctl.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_SETUP_TRANSFER; hc_ioctl.handle.ep = hostBomsCtx->epCtrl; hc_ioctl.set = &(ctx->setup_buffer[0]); hc_ioctl.get = NULL; //no return value from this call vos_dev_ioctl(hostBomsCtx->hc, &hc_ioctl); } } unsigned char class_request(usbSlaveBoms_context *ctx) { usb_deviceRequest_t *devReq; usbslave_ioctl_cb_t iocb; unsigned char status = USBSLAVE_OK; unsigned char bReq; devReq = (usb_deviceRequest_t *) ctx->setup_buffer; bReq = devReq->bRequest; // force a protocol stall since there are no class requests in BOMS switch (bReq) { case GET_MAX_LUN : get_max_lun_request(ctx); break; case BOMS_RESET : boms_reset_request(ctx); break; default: set_control_ep_halt(ctx); } return status; } ----------------------------------File Seperator------------------------------------------------------ /* ** USBSlaveBomsDrv.h ** ** Based on USBSlaveHIDKbd example by FTDI ** ** Modifications by Philip A. Polstra, Sr. ** ** Part of the USB Mass Storage Device impersonator as presented at DEFCON 20 ** Based on USB Write blocker presented at Blackhat Europe 2012 *** */ #ifndef __USBSlaveBomsDrv_h__ #define __USBSlaveBomsDrv_h__ #include "ioctl.h" #include "BomsDefs.h" // This structure is used to store state information for our device // The USBSlaveDrv is a VOS device which is layered on top of the // FTDI supplied USB Slave driver // This is one of those cases where life would be much simplier if // we could program our microcontroller in C++. typedef struct _usbSlaveBoms_context { // usb slave port handle VOS_HANDLE handle; // non-zero when initialised unsigned char attached; // is the slave attached unsigned char flashConnected; // is there a flash drive installed and enumed // SETUP thread vos_tcb_t *tcbSetup; // this is a thread that handles requests on the control endpoint // endpoint handles usbslave_ep_handle_t in_ep0; // VOS requires 2 handles for the control endpoint in/out usbslave_ep_handle_t out_ep0; usbslave_ep_handle_t in_ep; // bulk in endpoint direction is relative to PC attached to our device usbslave_ep_handle_t out_ep; // bulk out endpoint // semaphore to prevent accepting requests before drive is fully enumerated vos_semaphore_t enumed; // semaphore to delay start of slave // setup buffer unsigned char setup_buffer[9]; // setup packets are always 9 bytes } usbSlaveBoms_context; // USBSLAVEFT232 IOCTL definitions #define VOS_IOCTL_USBSLAVEBOMS_ATTACH 0 #define VOS_IOCTL_USBSLAVEBOMS_DETACH 1 enum USBSLAVEBOMS_STATUS { USBSLAVEBOMS_OK = 0, USBSLAVEBOMS_INVALID_PARAMETER, USBSLAVEBOMS_ERROR }; // BULK IN endpoint number #define USBSLAVEBOMS_IN 1 // BULK OUT endpoint number #define USBSLAVEBOMS_OUT 2 // internal thread memory usage #define SIZEOF_BOMS_SETUP_MEMORY 1024 // function prototypes for "public" functions uint8 usbslaveboms_init(uint8 vos_dev_num); void usbslaveboms_setup(usbSlaveBoms_context *ctx); unsigned char usbSlaveBoms_write( char *xfer, unsigned short num_to_write, unsigned short *num_written, usbSlaveBoms_context *ctx); unsigned char usbSlaveBoms_read( char *xfer, unsigned short num_to_read, unsigned short *num_read, usbSlaveBoms_context *ctx); // Write less than expected then stall unsigned char usbSlaveBoms_short_write( char *xfer, unsigned short num_to_write, unsigned short *num_written, usbSlaveBoms_context *ctx); // Read less than expected then stall unsigned char usbSlaveBoms_short_read( char *xfer, unsigned short num_to_read, unsigned short *num_read, usbSlaveBoms_context *ctx); unsigned char usbSlaveBoms_readCbw( boms_cbw_t *cbw, usbSlaveBoms_context *ctx); void usbslaveboms_stall_bulk_in(usbSlaveBoms_context *ctx); void usbslaveboms_clear_bulk_in(usbSlaveBoms_context *ctx); void usbslaveboms_stall_bulk_out(usbSlaveBoms_context *ctx); void usbslaveboms_clear_bulk_out(usbSlaveBoms_context *ctx); #endif ----------------------------------File Seperator------------------------------------------------------