Esempio n. 1
0
        private BluetopiaError RespondWithNoLinkKey(long addrI)
        {
            BluetopiaError ret;
            var            rsp = new Structs.GAP_Authentication_Information(
                StackConsts.GAP_Authentication_Type_t.atLinkKey);

            Debug.Assert(rsp._Authentication_Data_Length == 0, "!Null is zero len.");
            Debug.WriteLine("  Sending Auth Response: -ve (no linkkey)");
            ret = _factory.Api.GAP_Authentication_Response(
                _factory.StackId, addrI, ref rsp);
            Debug.Assert(BluetopiaUtils.IsSuccess(ret),
                         "GAP_Authentication_Response Negative=Non-data ret: " + ret);
            return(ret);
        }
Esempio n. 2
0
        //private void RespondWithPinCode_Runner(object state)
        //{
        //    RespondWithPinCode((ResponderInfo)state);
        //}

        private BluetopiaError RespondWithPinCode(ResponderInfo rspInfo)
        {
            BluetopiaError ret;
            var            rsp = new Structs.GAP_Authentication_Information(
                StackConsts.GAP_Authentication_Type_t.atPINCode,
                rspInfo.PPItem._pin, _factory.ApiVersion);

            //, "Zero len Pins not allowed.
            Debug.WriteLine("  Sending Auth Response: PinCode");
            Debug.WriteLine("    " + rsp.DebugToString());
            ret = _factory.Api.GAP_Authentication_Response(
                _factory.StackId, rspInfo.AddrI, ref rsp);
            Debug.Assert(BluetopiaUtils.IsSuccess(ret),
                         "GAP_Authentication_Response: " + ret);
            return(ret);
        }
Esempio n. 3
0
        private BluetopiaError RespondWithLinkKey(long addrI, byte[] key)
        {
            BluetopiaError ret;
            var            rsp = new Structs.GAP_Authentication_Information(
                StackConsts.GAP_Authentication_Type_t.atLinkKey,
                key, _factory.ApiVersion);

            Debug.Assert(rsp._Authentication_Data_Length != 0, "Zero len LinkKeys not allowed.");
            Debug.WriteLine("  Sending Auth Response: LinkKey)");
            Debug.WriteLine("    len: " + rsp._Authentication_Data_Length);
            ret = _factory.Api.GAP_Authentication_Response(
                _factory.StackId, addrI, ref rsp);
            Debug.Assert(BluetopiaUtils.IsSuccess(ret),
                         "GAP_Authentication_Response Negative=Non-data ret: " + ret);
            return(ret);
        }
Esempio n. 4
0
        //--
        #region IBluetoothSecurity Members

        public bool PairRequest(BluetoothAddress device, string pin)
        {
            // Verify and store the pin
            // TODO null PIN
            PinPairItem pairItem = SetPinPairItem_willLock(device, pin);
            // Add event etc.
            ManualResetEvent waitComplete;

            lock (_pins) {
                if (pairItem._eventForPairRequest != null)
                {
                    // HACK handle overlapping requests.  Fail the former?
                    pairItem.success = false;
                    pairItem._eventForPairRequest.Set();
                }
                waitComplete = new ManualResetEvent(false);
                pairItem._eventForPairRequest = waitComplete;
            }
            // Run
            BluetopiaError ret;
            var            foo = false;

            if (foo)
            {
                ret = _factory.Api.GAP_Authenticate_Remote_Device(
                    _factory.StackId, BluetopiaUtils.BluetoothAddressAsInteger(device), _AuthenticateCallback, 0);
            }
            else
            {
                ret = _factory.Api.GAP_Initiate_Bonding(_factory.StackId,
                                                        BluetopiaUtils.BluetoothAddressAsInteger(device),
                                                        StackConsts.GAP_Bonding_Type.Dedicated,
                                                        _AuthenticateCallback, 0);
            }
            if (!BluetopiaUtils.IsSuccess(ret))
            {
                return(false);
            }
            // Need to wait for completion.
            const int timeout = 3 * 60 * 1000;

            waitComplete.WaitOne(timeout, false);
            lock (_pins) {
                RemovePinPairItem__mustByInLock(device, pin, waitComplete);
                return(pairItem.success == true);
            }
        }
Esempio n. 5
0
        void ReadVersionsOnce()
        {
            if (_readVersions)
            {
                return;
            }
            _readVersions = true; // Just do once even if error
            BluetopiaError ret;

            try {
                StackConsts.HCI_ERROR_CODE hciStatus;
                ret = _fcty.Api.HCI_Read_Local_Version_Information(_fcty.StackId,
                                                                   out hciStatus, out _hciVersion, out _hciRev,
                                                                   out _lmpVersion, out _manuf, out _lmpSubver);
            } catch (MissingMethodException) { // Function added later to the SDK.
                ret = BluetopiaError.UNSUPPORTED_PLATFORM_ERROR;
            }
            BluetopiaUtils.Assert(ret, "HCI_Read_Local_Version_Information");
            if (!BluetopiaUtils.IsSuccess(ret))
            {
                _hciVersion = HciVersion.Unknown;
                _lmpVersion = LmpVersion.Unknown;
                _manuf      = Manufacturer.Unknown;
                _hciRev     = _lmpSubver = 0;
            }
            var arr = new byte[8];

            try {
                StackConsts.HCI_ERROR_CODE hciStatus;
                ret = _fcty.Api.HCI_Read_Local_Supported_Features(_fcty.StackId,
                                                                  out hciStatus, arr);
            } catch (MissingMethodException) { // Function added later to the SDK.
                ret = BluetopiaError.UNSUPPORTED_PLATFORM_ERROR;
            }
            BluetopiaUtils.Assert(ret, "HCI_Read_Local_Version_Information");
            if (BluetopiaUtils.IsSuccess(ret))
            {
                _lmpFeatures = (LmpFeatures)BitConverter.ToInt64(arr, 0);
            }
            else
            {
                _lmpFeatures = LmpFeatures.None;
            }
        }