1 //
2 // Copyright (c) 2010-2018 Antmicro
3 //
4 //  This file is licensed under the MIT License.
5 //  Full license text is available in 'licenses/MIT.txt'.
6 //
7 using System;
8 using Antmicro.Renode.Logging;
9 using Antmicro.Renode.Utilities;
10 
11 namespace Antmicro.Renode.Core.USB.MSC
12 {
13     public class Interface : USBInterface
14     {
Interface(IUSBDevice device, byte identifier, byte subClassCode, byte protocol, string description = null)15         public Interface(IUSBDevice device,
16                                byte identifier,
17                                byte subClassCode,
18                                byte protocol,
19                                string description = null) : base(device, identifier, USBClassCode.MassStorage, subClassCode, protocol, description)
20         {
21         }
22 
HandleRequest(SetupPacket packet)23         public override BitStream HandleRequest(SetupPacket packet)
24         {
25             switch(packet.Type)
26             {
27                 case PacketType.Class:
28                     return HandleClassRequest(packet);
29                 default:
30                     device.Log(LogLevel.Warning, "Unsupported packet type: 0x{0:X}", packet.Type);
31                     return BitStream.Empty;
32             }
33         }
34 
HandleClassRequest(SetupPacket packet)35         private BitStream HandleClassRequest(SetupPacket packet)
36         {
37             switch((ClassRequests)packet.Request)
38             {
39                 case ClassRequests.GetMaxLUN:
40                     // If no LUN is associated with the device, the value returned shall be 0.
41                     return new BitStream().Append((byte)0);
42                 default:
43                     device.Log(LogLevel.Warning, "Unsupported class request: 0x{0:X}", packet.Request);
44                     return BitStream.Empty;
45             }
46         }
47 
48         private enum ClassRequests
49         {
50             GetMaxLUN = 0xFE,
51         }
52     }
53 }