IBluetoothDriver.cs 4.0 KB

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