HostRadio
September 20, 2024 · View on GitHub
Namespace: Nefarius.Utilities.Bluetooth
Represents a Bluetooth Host Radio.
public sealed class HostRadio : System.IDisposable
Inheritance Object → HostRadio
Implements IDisposable
Remarks:
Windows currently only supports one exclusive online Bluetooth host radio active at the same time. This class can be extended in the future, should this limit ever get lifted.
Properties
AllDevices
Gets all remote devices.
public IEnumerable<RemoteDevice> AllDevices { get; }
Property Value
AuthenticatedDevices
Gets all authenticated devices.
public IEnumerable<RemoteDevice> AuthenticatedDevices { get; }
Property Value
ConnectedDevices
Gets all connected devices.
public IEnumerable<RemoteDevice> ConnectedDevices { get; }
Property Value
DeviceInterface
Device Interface GUID.
public static Guid DeviceInterface { get; }
Property Value
HumanInterfaceDeviceServiceClassUuid
HID Service Class GUID.
public static Guid HumanInterfaceDeviceServiceClassUuid { get; }
Property Value
IsAvailable
Gets whether a host radio is available (and can be enabled).
public static bool IsAvailable { get; }
Property Value
IsEnabled
Gets whether a host radio is enabled.
public static bool IsEnabled { get; }
Property Value
IsOperable
Gets whether a host radio is available and enabled.
public static bool IsOperable { get; }
Property Value
RememberedDevices
Gets all remembered devices.
public IEnumerable<RemoteDevice> RememberedDevices { get; }
Property Value
UnknownDevices
Gets all unknown devices.
public IEnumerable<RemoteDevice> UnknownDevices { get; }
Property Value
Constructors
HostRadio(Boolean)
Creates a new instance of HostRadio.
public HostRadio(bool autoEnable)
Parameters
autoEnable Boolean
True to automatically enable the radio if currently disabled, false will throw an exception.
You can also use HostRadio.IsAvailable to avoid this exception.
Exceptions
HostRadioException
Radio handle access has failed.
Methods
DisableRadio()
Disables the host radio.
public void DisableRadio()
Exceptions
Remarks:
This causes the FDO of the radio bus driver to report all its child devices as absent (basically tearing down the entire stack, excluding itself). This has the same effect as a user switching off Bluetooth from the Windows UI.
DisableService(Guid, String)
Disables advertising a specified service.
public void DisableService(Guid serviceGuid, string serviceName)
Parameters
serviceGuid Guid
The GUID of the service to expose. This should match the GUID in the server-side INF file.
serviceName String
The service name.
Exceptions
AdjustProcessPrivilegesException
Remarks:
This method requires administrative privileges.
DisconnectRemoteDevice(String)
Instruct host radio to disconnect a given remote device.
public void DisconnectRemoteDevice(string address)
Parameters
address String
A parseable MAC address string.
Remarks:
See https://learn.microsoft.com/en-us/dotnet/api/system.net.networkinformation.physicaladdress.parse for valid string formats.
DisconnectRemoteDevice(RemoteDevice)
Instruct host radio to disconnect a given remote device.
public void DisconnectRemoteDevice(RemoteDevice device)
Parameters
device RemoteDevice
The RemoteDevice to disconnect.
DisconnectRemoteDevice(PhysicalAddress)
Instruct host radio to disconnect a given remote device.
public void DisconnectRemoteDevice(PhysicalAddress device)
Parameters
device PhysicalAddress
The MAC address of the remote device.
Dispose()
public void Dispose()
EnableRadio()
Enables the host radio.
public void EnableRadio()
Exceptions
Remarks:
This causes the FDO of the radio bus driver to enumerate all its child devices and mark them as present. This has the same effect as a user switching on Bluetooth from the Windows UI.
EnableService(Guid, String)
Enables advertising a specified service.
public void EnableService(Guid serviceGuid, string serviceName)
Parameters
serviceGuid Guid
The GUID of the service to expose. This should match the GUID in the server-side INF file.
serviceName String
The service name.
Exceptions
AdjustProcessPrivilegesException
Remarks:
This method requires administrative privileges.
GetServiceStateForDevice(PhysicalAddress, Guid, ref Boolean)
Gets the state of a specified service.
public bool GetServiceStateForDevice(PhysicalAddress address, Guid serviceGuid, ref Boolean enabled)
Parameters
address PhysicalAddress
The remote device address.
serviceGuid Guid
The service GUID.
enabled Boolean&
True if the service is enabled, false otherwise.
Returns
True if the supplied device was found, false otherwise.
Exceptions
RestartRadio()
Restarts the host radio.
public void RestartRadio()
RestartRadioDevice()
Restarts the radio bus device. For USB devices this is achieved by requesting a port cycle from the attached hub.
public static void RestartRadioDevice()
Exceptions
T:Nefarius.Utilities.DeviceManagement.Exceptions.UsbPnPDeviceConversionException
Remarks:
Requires administrative privileges. Currently only USB devices are supported.
SetServiceStateForDevice(PhysicalAddress, Guid, Boolean)
Sets the state of a specified service to either enabled or disabled.
public void SetServiceStateForDevice(PhysicalAddress address, Guid serviceGuid, bool enabled)
Parameters
address PhysicalAddress
The remote device address.
serviceGuid Guid
The service GUID.
enabled Boolean
True to set to enabled, false to disable.