//--------------------------------------------------------------------------- // // SCSI Target Emulator RaSCSI Reloaded // for Raspberry Pi // // Copyright (C) 2001-2006 PI.(ytanaka@ipc-tokai.or.jp) // Copyright (C) 2014-2020 GIMONS // Copyright (C) akuker // // Licensed under the BSD 3-Clause License. // See LICENSE file in the project root folder. // // [ SCSI Host Bridge for the Sharp X68000 ] // // Note: This requires a special driver on the host system and will only // work with the Sharp X68000 operating system. //--------------------------------------------------------------------------- #pragma once #include "interfaces/byte_writer.h" #include "primary_device.h" #include "ctapdriver.h" #include "cfilesystem.h" #include #include using namespace std; class SCSIBR : public PrimaryDevice, public ByteWriter { static constexpr const array bcast_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; public: explicit SCSIBR(int lun) : PrimaryDevice(SCBR, lun) {} ~SCSIBR() override = default; bool Init(const unordered_map&) override; // Commands vector InquiryInternal() const override; int GetMessage10(const vector&, vector&); bool WriteBytes(const vector&, vector&, uint32_t) override; void TestUnitReady() override; void GetMessage10(); void SendMessage10(); private: int GetMacAddr(vector&) const; // Get MAC address void SetMacAddr(const vector&); // Set MAC address void ReceivePacket(); // Receive a packet void GetPacketBuf(vector&, int); // Get a packet void SendPacket(const vector&, int); // Send a packet CTapDriver tap; // TAP driver bool m_bTapEnable = false; // TAP valid flag array mac_addr = {}; // MAC Address int packet_len = 0; // Receive packet size array packet_buf; // Receive packet buffer bool packet_enable = false; // Received packet valid int ReadFsResult(vector&) const; // Read filesystem (result code) int ReadFsOut(vector&) const; // Read filesystem (return data) int ReadFsOpt(vector&) const; // Read file system (optional data) void WriteFs(int, vector&); // File system write (execute) void WriteFsOpt(const vector&, int); // File system write (optional data) // Command handlers void FS_InitDevice(vector&); // $40 - boot void FS_CheckDir(vector&); // $41 - directory check void FS_MakeDir(vector&); // $42 - create directory void FS_RemoveDir(vector&); // $43 - delete directory void FS_Rename(vector&); // $44 - change filename void FS_Delete(vector&); // $45 - delete file void FS_Attribute(vector&); // $46 - get/set file attributes void FS_Files(vector&); // $47 - file search void FS_NFiles(vector&); // $48 - find next file void FS_Create(vector&); // $49 - create file void FS_Open(vector&); // $4A - open file void FS_Close(vector&); // $4B - close file void FS_Read(vector&); // $4C - read file void FS_Write(vector&); // $4D - write file void FS_Seek(vector&); // $4E - seek file void FS_TimeStamp(vector&); // $4F - get/set file time void FS_GetCapacity(vector&); // $50 - get capacity void FS_CtrlDrive(vector&); // $51 - drive status check/control void FS_GetDPB(vector&); // $52 - get DPB void FS_DiskRead(vector&); // $53 - read sector void FS_DiskWrite(vector&); // $54 - write sector void FS_Ioctrl(vector&); // $55 - IOCTRL void FS_Flush(vector&); // $56 - flush cache void FS_CheckMedia(vector&); // $57 - check media void FS_Lock(vector&); // $58 - get exclusive control CFileSys fs; // File system accessor uint32_t fsresult = 0; // File system access result code array fsout; // File system access result buffer uint32_t fsoutlen = 0; // File system access result buffer size array fsopt; // File system access buffer uint32_t fsoptlen = 0; // File system access buffer size };