IBluetoothDriver.cs 3.9 KB

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