{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void StateChangedCallback(int result, int state, IntPtr userData);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void AuthenticationRequestedCallback(int result, AuthenticationInfoType authType, string deviceName, string remoteAddr, string passKey, IntPtr userData);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void NameChangedCallback(string deviceName, IntPtr userData);
internal static extern int SetDiscoveryStateChangedCallback(DiscoveryStateChangedCallback discoveryChangedCb, IntPtr userData);
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_device_discovery_state_changed_cb")]
internal static extern int UnsetDiscoveryStateChangedCallback();
+ [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_passkey_confirmation_reply")]
+ internal static extern int PasskeyConfirmationReply(bool confirmationReply);
+ [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_authentication_req_cb")]
+ internal static extern int SetAuthenticationRequestedCallback(AuthenticationRequestedCallback stateChangedCb, IntPtr userData);
+ [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_authentication_req_cb")]
+ internal static extern int UnsetAuthenticationRequestedCallback();
//Bluetooth Device
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_create_bond")]
}
/// <summary>
+ /// The AuthenticationChanged event is raised when the Bluetooth adapter authentication is changed.
+ /// </summary>
+ /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when the Bluetooth is not enabled.</exception>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ static public event EventHandler<AuthenticationRequestedEventArgs> AuthenticationChanged
+ {
+ add
+ {
+ try
+ {
+ BluetoothAdapterImpl.Instance.AuthenticationChanged += value;
+ }
+ catch (TypeInitializationException e)
+ {
+ throw e.InnerException;
+ }
+ }
+ remove
+ {
+ try
+ {
+ BluetoothAdapterImpl.Instance.AuthenticationChanged -= value;
+ }
+ catch (TypeInitializationException e)
+ {
+ throw e.InnerException;
+ }
+ }
+ }
+
+ /// <summary>
/// The NameChanged event is raised when the Bluetooth adapter name is changed.
/// </summary>
/// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
private event EventHandler<VisibilityModeChangedEventArgs> _visibilityModeChanged;
private event EventHandler<VisibilityDurationChangedEventArgs> _visibilityDurationChanged;
private event EventHandler<DiscoveryStateChangedEventArgs> _discoveryStateChanged;
+ private event EventHandler<AuthenticationRequestedEventArgs> _authenticationRequested;
private Interop.Bluetooth.StateChangedCallback _stateChangedCallback;
private Interop.Bluetooth.NameChangedCallback _nameChangedCallback;
private Interop.Bluetooth.VisibilityDurationChangedCallback _visibilitydurationChangedCallback;
private Interop.Bluetooth.DiscoveryStateChangedCallback _discoveryStateChangedCallback;
private Interop.Bluetooth.BondedDeviceCallback _bondedDeviceCallback;
+ private Interop.Bluetooth.AuthenticationRequestedCallback _authenticationRequestedCallback;
private static readonly BluetoothAdapterImpl _instance = new BluetoothAdapterImpl();
private bool disposed = false;
}
}
+ internal event EventHandler<AuthenticationRequestedEventArgs> AuthenticationChanged
+ {
+ add
+ {
+ if (_authenticationRequested == null)
+ {
+ RegisterAuthenticationRequestedEvent();
+ }
+ _authenticationRequested += value;
+ }
+ remove
+ {
+ _authenticationRequested -= value;
+ if (_stateChanged == null)
+ {
+ UnregisterAuthenticationRequestedEvent();
+ }
+ }
+ }
+
internal event EventHandler<NameChangedEventArgs> NameChanged
{
add
}
}
+ private void RegisterAuthenticationRequestedEvent()
+ {
+ _authenticationRequestedCallback = (int result, AuthenticationInfoType authType, string deviceName, string remoteAddr, string passKey, IntPtr userData) =>
+ {
+ if (_authenticationRequested != null)
+ {
+ AuthenticationInfoType at = authType;
+ BluetoothError res = (BluetoothError)result;
+ _authenticationRequested(null, new AuthenticationRequestedEventArgs(res, at, deviceName, remoteAddr, passKey));
+ }
+ };
+ int ret = Interop.Bluetooth.SetAuthenticationRequestedCallback(_authenticationRequestedCallback, IntPtr.Zero);
+ if (ret != (int)BluetoothError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to set authentication request callback, Error - " + (BluetoothError)ret);
+ }
+ }
+
+ private void UnregisterAuthenticationRequestedEvent()
+ {
+ int ret = Interop.Bluetooth.UnsetAuthenticationRequestedCallback();
+ if (ret != (int)BluetoothError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to unset authentication request callback, Error - " + (BluetoothError)ret);
+ }
+ }
+
private void RegisterNameChangedEvent()
{
_nameChangedCallback = (string deviceName, IntPtr userData) =>
}
}
+ internal void PasskeyConfirmationReply(bool confirmationReply)
+ {
+ int ret = Interop.Bluetooth.PasskeyConfirmationReply(confirmationReply);
+ if (ret != (int)BluetoothError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to passkey confirmation reply, Error - " + (BluetoothError)ret);
+ BluetoothErrorFactory.ThrowBluetoothException(ret);
+ }
+ }
+
internal BluetoothServerSocket CreateServerSocket(string serviceUuid)
{
int socketFd;
/// </summary>
Output
}
+
+ /// <summary>
+ /// Enumeration for the authentication info type.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public enum AuthenticationInfoType
+ {
+ /// <summary>
+ /// PIN display event to user for entering PIN in keyboard
+ /// </summary>
+ AuthKeyboardPasskeyDisplay = 0,
+ /// <summary>
+ /// Legacy PIN or PASSKEY request event
+ /// </summary>
+ AuthPinRequest,
+ /// <summary>
+ /// PASSKEY confirmation event to match PASSKEY in remote device
+ /// </summary>
+ AuthPasskeyConfirmRequest,
+ }
}
}
/// <summary>
+ /// An extended EventArgs class contains the changed Bluetooth authentication.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class AuthenticationRequestedEventArgs : EventArgs
+ {
+ private AuthenticationInfoType _authType;
+ private BluetoothError _result;
+ private string _deviceName;
+ private string _remoteAddr;
+ private string _passKey;
+
+ internal AuthenticationRequestedEventArgs(BluetoothError result, AuthenticationInfoType type, string deviceName, string remoteAddr, string passKey)
+ {
+ _authType = type;
+ _result = result;
+ _deviceName = deviceName;
+ _remoteAddr = remoteAddr;
+ _passKey = passKey;
+ }
+
+ /// <summary>
+ /// The authentication of Bluetooth.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public AuthenticationInfoType Authentication
+ {
+ get
+ {
+ return _authType;
+ }
+ }
+
+ /// <summary>
+ /// The BluetoothError result.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public BluetoothError Result
+ {
+ get
+ {
+ return _result;
+ }
+ }
+
+ /// <summary>
+ /// The name of the device.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public string DeviceName
+ {
+ get
+ {
+ return _deviceName;
+ }
+ }
+
+ /// <summary>
+ /// The Remote address of the device.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public string RemoteAddr
+ {
+ get
+ {
+ return _remoteAddr;
+ }
+ }
+
+ /// <summary>
+ /// The pass key of the device.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public string PassKey
+ {
+ get
+ {
+ return _passKey;
+ }
+ }
+ }
+
+ /// <summary>
/// An extended EventArgs class contains the changed Bluetooth name.
/// </summary>
/// <since_tizen> 3 </since_tizen>