Пример #1
0
        /// <summary>
        /// Intiates pairing for a remote device
        /// with SSP if it is available.
        /// </summary>
        /// -
        /// <param name="device">Remote device with which to pair.</param>
        /// <param name="authenticationRequirement">
        /// Note: not supported by all platforms.
        /// </param>
        /// -
        /// <returns>Whether the operation was successful.</returns>
        bool /*IBluetoothSecurity.*/ PairRequest(BluetoothAddress device,
                                                 BluetoothAuthenticationRequirements authenticationRequirement)
        {
#if NETCF
            return(((IBluetoothSecurity)this).PairRequest(device, null));
#else
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }
            if (device.ToInt64() == 0)
            {
                throw new ArgumentNullException("device", "A non-blank address must be specified.");
            }

            //use other constructor to ensure struct size is set
            BLUETOOTH_DEVICE_INFO bdi = new BLUETOOTH_DEVICE_INFO(device.ToInt64());

            byte[] btOobData = null;
            int    result    = NativeMethods.BluetoothAuthenticateDeviceEx(IntPtr.Zero, IntPtr.Zero,
                                                                           ref bdi, btOobData, authenticationRequirement);

            if (result != 0)
            {
                //determine error cause from "result"...
                // ERROR_INVALID_PARAMETER      87
                // WAIT_TIMEOUT                258
                // ERROR_NOT_AUTHENTICATED    1244
                Debug.WriteLine("PairRequest/BADEx failed with: " + result);
                return(false);
            }
            return(true);
#endif
        }
 private void ShutupCompiler()
 {
     this.deviceInfo                 = new BLUETOOTH_DEVICE_INFO();
     this.authenticationMethod       = BluetoothAuthenticationMethod.Legacy;
     this.ioCapability               = BluetoothIoCapability.Undefined;
     this.authenticationRequirements = BluetoothAuthenticationRequirements.MITMProtectionNotDefined;
     this.Numeric_Value_Passkey      = 0;
 }
 internal BluetoothAuthenticationEventArgs(BLUETOOTH_DEVICE_INFO device,
                                           ref BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS?authCallbackParams)
     : this(device)
 {
     _authMethod = authCallbackParams.Value.authenticationMethod;
     _authReq    = authCallbackParams.Value.authenticationRequirements;
     _authIoCapa = authCallbackParams.Value.ioCapability;
     const uint MaxSixDigitDecimal = 999999;
     Debug.Assert(authCallbackParams.Value.Numeric_Value_Passkey <= MaxSixDigitDecimal);
     _numberOrPasskey = checked ((int)authCallbackParams.Value.Numeric_Value_Passkey);
 }
 /// <summary>
 /// Initialize an instance of <see cref="T:InTheHand.Net.Bluetooth.BluetoothWin32AuthenticationEventArgs"/>.
 /// </summary>
 /// -
 /// <param name="device">The device information to store in the event args.
 /// </param>
 public BluetoothAuthenticationEventArgs(BluetoothDeviceInfo device)
 {
     if (device == null)
     {
         throw new ArgumentNullException("device");
     }
     m_device         = device;
     _authMethod      = BluetoothAuthenticationMethod.Legacy;
     _authReq         = BluetoothAuthenticationRequirements.MITMProtectionNotDefined;
     _authIoCapa      = BluetoothIoCapability.Undefined;
     _numberOrPasskey = null; // Keep compiler happy on CF2 build.
 }
 internal BluetoothAuthenticationEventArgs(int errorCode, BluetoothAuthenticationEventArgs previousEa)
 {
     if (previousEa == null)
     {
         throw new ArgumentNullException("previousEa");
     }
     m_device         = previousEa.Device;
     _authIoCapa      = previousEa._authIoCapa;
     _authMethod      = previousEa._authMethod;
     _authReq         = previousEa._authReq;
     _numberOrPasskey = previousEa._numberOrPasskey;
     m_attemptNumber  = previousEa.AttemptNumber + 1;
     //
     m_errorCode = errorCode;
 }
Пример #6
0
        //----
        void DoTestSsbProps(BluetoothAuthenticationMethod am, BluetoothAuthenticationRequirements req,
                            BluetoothIoCapability ioCapa, bool?expectedJustWorksValue)
        {
            var cbParams = new BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS();

            cbParams.authenticationMethod       = am;
            cbParams.authenticationRequirements = req;
            cbParams.ioCapability = ioCapa;
            var e = Create_EA(cbParams);

            //
            Assert.AreEqual(am, e.AuthenticationMethod, "am");
            Assert.AreEqual(req, e.AuthenticationRequirements, "req");
            Assert.AreEqual(ioCapa, e.IoCapability, "ioCapa");
            Assert.AreEqual(expectedJustWorksValue, e.JustWorksNumericComparison, "jw");
        }
Пример #7
0
        public static int AuthDeviceExFakeOob(BluetoothAddress device, byte[] oobData)
        {
            var bdi = new BLUETOOTH_DEVICE_INFO(device.ToInt64());
            //
            IntPtr hwndParent = IntPtr.Zero;
            IntPtr hRadio     = IntPtr.Zero;
            BluetoothAuthenticationRequirements authReq
                = BluetoothAuthenticationRequirements.MITMProtectionNotRequired;
            var result = NativeMethods.BluetoothAuthenticateDeviceEx(hwndParent,
                                                                     hRadio, ref bdi, oobData, authReq);

            if (result != 0)
            {
                //determine error cause from "result"...
                // ERROR_INVALID_PARAMETER      87
                // WAIT_TIMEOUT                258
                // ERROR_NOT_AUTHENTICATED    1244
                // E_FAIL               0x80004005

                //<--return false;
            }
            //<--return true;
            return(result);
        }
Пример #8
0
 internal static extern int BluetoothAuthenticateDeviceEx(IntPtr hwndParentIn, IntPtr hRadioIn, ref BLUETOOTH_DEVICE_INFO pbtdiInout, byte[] pbtOobData, BluetoothAuthenticationRequirements authenticationRequirement);