IBluetoothDriver.cs
1 using Ryujinx.HLE.HOS.Ipc; 2 using Ryujinx.HLE.HOS.Kernel.Threading; 3 using Ryujinx.HLE.HOS.Services.Bluetooth.BluetoothDriver; 4 using Ryujinx.HLE.HOS.Services.Settings; 5 using Ryujinx.Horizon.Common; 6 using System; 7 8 namespace Ryujinx.HLE.HOS.Services.Bluetooth 9 { 10 [Service("btdrv")] 11 class IBluetoothDriver : IpcService 12 { 13 #pragma warning disable CS0414, IDE0052 // Remove unread private member 14 private string _unknownLowEnergy; 15 #pragma warning restore CS0414, IDE0052 16 17 public IBluetoothDriver(ServiceCtx context) { } 18 19 [CommandCmif(46)] 20 // InitializeBluetoothLe() -> handle<copy> 21 public ResultCode InitializeBluetoothLe(ServiceCtx context) 22 { 23 NxSettings.Settings.TryGetValue("bluetooth_debug!skip_boot", out object debugMode); 24 25 int initializeEventHandle; 26 27 if ((bool)debugMode) 28 { 29 if (BluetoothEventManager.InitializeBleDebugEventHandle == 0) 30 { 31 BluetoothEventManager.InitializeBleDebugEvent = new KEvent(context.Device.System.KernelContext); 32 33 if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.InitializeBleDebugEvent.ReadableEvent, out BluetoothEventManager.InitializeBleDebugEventHandle) != Result.Success) 34 { 35 throw new InvalidOperationException("Out of handles!"); 36 } 37 } 38 39 if (BluetoothEventManager.UnknownBleDebugEventHandle == 0) 40 { 41 BluetoothEventManager.UnknownBleDebugEvent = new KEvent(context.Device.System.KernelContext); 42 43 if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.UnknownBleDebugEvent.ReadableEvent, out BluetoothEventManager.UnknownBleDebugEventHandle) != Result.Success) 44 { 45 throw new InvalidOperationException("Out of handles!"); 46 } 47 } 48 49 if (BluetoothEventManager.RegisterBleDebugEventHandle == 0) 50 { 51 BluetoothEventManager.RegisterBleDebugEvent = new KEvent(context.Device.System.KernelContext); 52 53 if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.RegisterBleDebugEvent.ReadableEvent, out BluetoothEventManager.RegisterBleDebugEventHandle) != Result.Success) 54 { 55 throw new InvalidOperationException("Out of handles!"); 56 } 57 } 58 59 initializeEventHandle = BluetoothEventManager.InitializeBleDebugEventHandle; 60 } 61 else 62 { 63 _unknownLowEnergy = "low_energy"; 64 65 if (BluetoothEventManager.InitializeBleEventHandle == 0) 66 { 67 BluetoothEventManager.InitializeBleEvent = new KEvent(context.Device.System.KernelContext); 68 69 if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.InitializeBleEvent.ReadableEvent, out BluetoothEventManager.InitializeBleEventHandle) != Result.Success) 70 { 71 throw new InvalidOperationException("Out of handles!"); 72 } 73 } 74 75 if (BluetoothEventManager.UnknownBleEventHandle == 0) 76 { 77 BluetoothEventManager.UnknownBleEvent = new KEvent(context.Device.System.KernelContext); 78 79 if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.UnknownBleEvent.ReadableEvent, out BluetoothEventManager.UnknownBleEventHandle) != Result.Success) 80 { 81 throw new InvalidOperationException("Out of handles!"); 82 } 83 } 84 85 if (BluetoothEventManager.RegisterBleEventHandle == 0) 86 { 87 BluetoothEventManager.RegisterBleEvent = new KEvent(context.Device.System.KernelContext); 88 89 if (context.Process.HandleTable.GenerateHandle(BluetoothEventManager.RegisterBleEvent.ReadableEvent, out BluetoothEventManager.RegisterBleEventHandle) != Result.Success) 90 { 91 throw new InvalidOperationException("Out of handles!"); 92 } 93 } 94 95 initializeEventHandle = BluetoothEventManager.InitializeBleEventHandle; 96 } 97 98 context.Response.HandleDesc = IpcHandleDesc.MakeCopy(initializeEventHandle); 99 100 return ResultCode.Success; 101 } 102 } 103 }