Example #1
0
 /// <summary>
 /// This function revokes the personal identification number (PIN) for the Bluetooth device.
 /// </summary>
 /// <remarks><para>On Windows CE platforms this calls <c>BthRevokePIN</c>,
 /// its MSDN remarks say:
 /// </para>
 /// <para>&#x201C;When the PIN is revoked, it is removed from registry.
 /// The active connection to the device is not necessary, nor is the presence
 /// of the Bluetooth controller.&#x201D;
 /// </para>
 /// <para>On Windows CE platforms this removes any pending BluetoothWin32Authentication object but does not remove the PIN for an already authenticated device.
 /// Use RemoveDevice to ensure a pairing is completely removed.</para>
 /// <para>See also
 /// <see cref="M:InTheHand.Net.Bluetooth.BluetoothSecurity.SetPin(InTheHand.Net.BluetoothAddress,System.String)"/>
 /// </para>
 /// </remarks>
 /// <param name="device">The remote device.</param>
 /// <returns>True on success, else False.</returns>
 /// <seealso cref="M:InTheHand.Net.Bluetooth.BluetoothSecurity.SetPin(InTheHand.Net.BluetoothAddress,System.String)"/>
 public bool RevokePin(BluetoothAddress device)
 {
     if (device.IsNull)
     {
         throw new ArgumentNullException("device");
     }
     if (authenticators.ContainsKey(device))
     {
         BluetoothAuthentication bwa = (BluetoothAuthentication)authenticators[device];
         authenticators.Remove(device);
         bwa.Dispose();
         return(true);
     }
     return(false);
 }
Example #2
0
 /// <summary>
 /// This function stores the personal identification number (PIN) for the Bluetooth device.
 /// </summary>
 /// <param name="device">Address of remote device.</param>
 /// <param name="pin">Pin, alphanumeric string of between 1 and 16 ASCII characters.</param>
 /// <remarks><para>On Windows CE platforms this calls <c>BthSetPIN</c>,
 /// its MSDN remarks say:
 /// </para>
 /// <para>&#x201C;Stores the pin for the Bluetooth device identified in pba.
 /// The active connection to the device is not necessary, nor is the presence
 /// of the Bluetooth controller. The PIN is persisted in the registry until
 /// BthRevokePIN is called.
 /// </para>
 /// <para>&#x201C;While the PIN is stored, it is supplied automatically
 /// after the PIN request is issued by the authentication mechanism, so the
 /// user will not be prompted for it. Typically, for UI-based devices, you
 /// would set the PIN for the duration of authentication, and then revoke
 /// it after authentication is complete.&#x201D;
 /// </para>
 /// <para>See also
 /// <see cref="M:InTheHand.Net.Bluetooth.BluetoothSecurity.RevokePin(InTheHand.Net.BluetoothAddress)"/>
 /// </para>
 /// </remarks>
 /// <returns>True on success, else False.</returns>
 /// <seealso cref="M:InTheHand.Net.Bluetooth.BluetoothSecurity.RevokePin(InTheHand.Net.BluetoothAddress)"/>
 public bool SetPin(BluetoothAddress device, string pin)
 {
     if (device.IsNull)
     {
         throw new ArgumentNullException("device");
     }
     if (pin == null)
     {
         throw new ArgumentNullException("pin");
     }
     //remove existing listener
     if (authenticators.ContainsKey(device))
     {
         BluetoothAuthentication bwa = (BluetoothAuthentication)authenticators[device];
         authenticators.Remove(device);
         bwa.Dispose();
     }
     authenticators.Add(device, new BluetoothAuthentication(device, pin));
     return(true);
 }
Example #3
0
        public void SetPin(BluetoothAddress device, string pin)
        {
#if WinXP
            if (pin != null)
            {
                m_authenticator = new BluetoothAuthentication(device, pin);
            }
            else
            {
                if (m_authenticator != null)
                {
                    m_authenticator.Dispose();
                }
            }
#else
            byte[] link = new byte[32];

            //copy remote device address
            if (device != null)
            {
                Buffer.BlockCopy(device.ToByteArray(), 0, link, 8, 6);
            }

            //copy PIN
            if (pin != null & pin.Length > 0)
            {
                if (pin.Length > 16)
                {
                    throw new ArgumentOutOfRangeException("PIN must be between 1 and 16 ASCII characters");
                }
                //copy pin bytes
                byte[] pinbytes = System.Text.Encoding.ASCII.GetBytes(pin);
                Buffer.BlockCopy(pinbytes, 0, link, 16, pin.Length);
                BitConverter.GetBytes(pin.Length).CopyTo(link, 0);
            }

            m_socket.SetSocketOption(BluetoothSocketOptionLevel.RFComm, BluetoothSocketOptionName.SetPin, link);
#endif
        }