IBluetoothDriver.cs 4.5 KB

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