Exemple #1
0
        /// <summary>
        /// Inquiry command
        /// </summary>
        /// <returns>Result</returns>
        private unsafe SCSIInquiryData *Inquiry()
        {
            SCSIInquiryData *data = (SCSIInquiryData *)Heap.Alloc(sizeof(SCSIInquiryData));

            Memory.Memclear(data, sizeof(SCSIReadCapData));

            SCSIInquiry *cmd = (SCSIInquiry *)Heap.Alloc(sizeof(SCSIInquiry));

            Memory.Memclear(cmd, sizeof(SCSIInquiry));
            cmd->Opcode      = SCSI_INQUIRY;
            cmd->AllocLength = (byte)sizeof(SCSIInquiryData);

            if (!Command((byte *)cmd, (byte)sizeof(SCSIReadCap), (byte *)data, sizeof(SCSIInquiryData), true))
            {
                Heap.Free(cmd);
                Heap.Free(data);

                return(null);
            }

            Heap.Free(cmd);

            return(data);
        }
Exemple #2
0
        /// <summary>
        /// USB mass storage device initalize
        /// </summary>
        /// <returns>Success?</returns>
        private unsafe bool Initalize()
        {
            _EndPointIn  = 1;
            _EndPointOut = 2;

            //if(!GetEndpoints())
            //{
            //    Console.WriteLine("[USB-MSC] Could not find endpoints");

            //    return false;
            //}

            SCSIInquiryData *inquiryResp = Inquiry();

            if (inquiryResp == null)
            {
                Console.WriteLine("[USB-MSC] Inquiry failed");

                Heap.Free(inquiryResp);
                return(false);
            }

            // Check if device supports Direct access SBC-2 or above
            if ((inquiryResp->PeripheralInfo & 0xF) != INQUIRY_PDT_DIRECT_ACCESS)
            {
                Console.WriteLine("[USB-MSC] Unsupported device type");

                Heap.Free(inquiryResp);
                return(false);
            }

            // @TODO: We should wait till ready here with the test command

            if (!ReadCapacity())
            {
                Console.WriteLine("[USB-MSC] Cannot read capacity");

                return(false);
            }

            if (_BlockLength != SUPPORTED_BLOCK_LENGTH)
            {
                Console.Write("[USB-MSC] Unsupported block length ");
                Console.WriteNum((int)_BlockLength);
                Console.WriteLine("");
            }

            // We can mount it here :D

            int deviceNum = _DeviceNum++;

            char *name = (char *)Heap.Alloc(6);

            name[0] = 'U';
            name[1] = 'S';
            name[2] = 'B';
            name[3] = 'D';
            name[4] = (char)('0' + deviceNum);
            name[5] = '\0';
            string nameStr = Util.CharPtrToString(name);

            Node node = new Node();

            node.Read  = readImpl;
            node.Write = writeImpl;

            USBMSCCookie cookie = new USBMSCCookie(_Device, this);

            node.Cookie = cookie;

            RootPoint dev = new RootPoint(nameStr, node);

            VFS.MountPointDevFS.AddEntry(dev);

            return(true);
        }