IBtmUserCore.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel.Common;
  4. using Ryujinx.HLE.HOS.Kernel.Threading;
  5. namespace Ryujinx.HLE.HOS.Services.BluetoothManager.BtmUser
  6. {
  7. class IBtmUserCore : IpcService
  8. {
  9. public KEvent _bleScanEvent;
  10. public int _bleScanEventHandle;
  11. public KEvent _bleConnectionEvent;
  12. public int _bleConnectionEventHandle;
  13. public KEvent _bleServiceDiscoveryEvent;
  14. public int _bleServiceDiscoveryEventHandle;
  15. public KEvent _bleMtuConfigEvent;
  16. public int _bleMtuConfigEventHandle;
  17. public IBtmUserCore() { }
  18. [CommandHipc(0)] // 5.0.0+
  19. // AcquireBleScanEvent() -> (byte<1>, handle<copy>)
  20. public ResultCode AcquireBleScanEvent(ServiceCtx context)
  21. {
  22. KernelResult result = KernelResult.Success;
  23. if (_bleScanEventHandle == 0)
  24. {
  25. _bleScanEvent = new KEvent(context.Device.System.KernelContext);
  26. result = context.Process.HandleTable.GenerateHandle(_bleScanEvent.ReadableEvent, out _bleScanEventHandle);
  27. if (result != KernelResult.Success)
  28. {
  29. // NOTE: We use a Logging instead of an exception because the call return a boolean if succeed or not.
  30. Logger.Error?.Print(LogClass.ServiceBsd, "Out of handles!");
  31. }
  32. }
  33. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_bleScanEventHandle);
  34. context.ResponseData.Write(result == KernelResult.Success ? 1 : 0);
  35. return ResultCode.Success;
  36. }
  37. [CommandHipc(17)] // 5.0.0+
  38. // AcquireBleConnectionEvent() -> (byte<1>, handle<copy>)
  39. public ResultCode AcquireBleConnectionEvent(ServiceCtx context)
  40. {
  41. KernelResult result = KernelResult.Success;
  42. if (_bleConnectionEventHandle == 0)
  43. {
  44. _bleConnectionEvent = new KEvent(context.Device.System.KernelContext);
  45. result = context.Process.HandleTable.GenerateHandle(_bleConnectionEvent.ReadableEvent, out _bleConnectionEventHandle);
  46. if (result != KernelResult.Success)
  47. {
  48. // NOTE: We use a Logging instead of an exception because the call return a boolean if succeed or not.
  49. Logger.Error?.Print(LogClass.ServiceBsd, "Out of handles!");
  50. }
  51. }
  52. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_bleConnectionEventHandle);
  53. context.ResponseData.Write(result == KernelResult.Success ? 1 : 0);
  54. return ResultCode.Success;
  55. }
  56. [CommandHipc(26)] // 5.0.0+
  57. // AcquireBleServiceDiscoveryEvent() -> (byte<1>, handle<copy>)
  58. public ResultCode AcquireBleServiceDiscoveryEvent(ServiceCtx context)
  59. {
  60. KernelResult result = KernelResult.Success;
  61. if (_bleServiceDiscoveryEventHandle == 0)
  62. {
  63. _bleServiceDiscoveryEvent = new KEvent(context.Device.System.KernelContext);
  64. result = context.Process.HandleTable.GenerateHandle(_bleServiceDiscoveryEvent.ReadableEvent, out _bleServiceDiscoveryEventHandle);
  65. if (result != KernelResult.Success)
  66. {
  67. // NOTE: We use a Logging instead of an exception because the call return a boolean if succeed or not.
  68. Logger.Error?.Print(LogClass.ServiceBsd, "Out of handles!");
  69. }
  70. }
  71. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_bleServiceDiscoveryEventHandle);
  72. context.ResponseData.Write(result == KernelResult.Success ? 1 : 0);
  73. return ResultCode.Success;
  74. }
  75. [CommandHipc(33)] // 5.0.0+
  76. // AcquireBleMtuConfigEvent() -> (byte<1>, handle<copy>)
  77. public ResultCode AcquireBleMtuConfigEvent(ServiceCtx context)
  78. {
  79. KernelResult result = KernelResult.Success;
  80. if (_bleMtuConfigEventHandle == 0)
  81. {
  82. _bleMtuConfigEvent = new KEvent(context.Device.System.KernelContext);
  83. result = context.Process.HandleTable.GenerateHandle(_bleMtuConfigEvent.ReadableEvent, out _bleMtuConfigEventHandle);
  84. if (result != KernelResult.Success)
  85. {
  86. // NOTE: We use a Logging instead of an exception because the call return a boolean if succeed or not.
  87. Logger.Error?.Print(LogClass.ServiceBsd, "Out of handles!");
  88. }
  89. }
  90. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_bleMtuConfigEventHandle);
  91. context.ResponseData.Write(result == KernelResult.Success ? 1 : 0);
  92. return ResultCode.Success;
  93. }
  94. }
  95. }