コード例 #1
0
ファイル: WidcommBtInterface.cs プロジェクト: jehy/32feet.NET
        //----------
        public List_IBluetoothDeviceInfo GetKnownRemoteDeviceEntries()
        {
            List <REM_DEV_INFO> list = new List <REM_DEV_INFO>();
            REM_DEV_INFO        info = new REM_DEV_INFO();
            int    cb   = System.Runtime.InteropServices.Marshal.SizeOf(typeof(REM_DEV_INFO));
            IntPtr pBuf = System.Runtime.InteropServices.Marshal.AllocHGlobal(cb);

            try {
                REM_DEV_INFO_RETURN_CODE ret = m_btIf.GetRemoteDeviceInfo(ref info, pBuf, cb);
                Utils.MiscUtils.Trace_WriteLine("GRDI: ret: {0}=0x{0:X}", ret);
                while (ret == REM_DEV_INFO_RETURN_CODE.SUCCESS)
                {
                    list.Add(info); // COPY it into the list
                    ret = m_btIf.GetNextRemoteDeviceInfo(ref info, pBuf, cb);
                    Utils.MiscUtils.Trace_WriteLine("GnRDI: ret: {0}=0x{0:X}", ret);
                }//while
                if (ret != REM_DEV_INFO_RETURN_CODE.EOF)
                {
                    throw WidcommSocketExceptions.Create(ret, "Get[Next]RemoteDeviceInfo");
                }
                //
                List_IBluetoothDeviceInfo bdiList = new List_IBluetoothDeviceInfo(list.Count);
                foreach (REM_DEV_INFO cur in list)
                {
                    IBluetoothDeviceInfo bdi = WidcommBluetoothDeviceInfo.CreateFromStoredRemoteDeviceInfo(cur, m_factory);
                    bdiList.Add(bdi);
                }
                return(bdiList);
            } finally {
                System.Runtime.InteropServices.Marshal.FreeHGlobal(pBuf);
            }
        }
コード例 #2
0
ファイル: WidcommBtInterface.cs プロジェクト: jehy/32feet.NET
        public List_IBluetoothDeviceInfo ReadKnownDevicesFromRegistry()
        {
            // Multiple keys, one per device, named with address e.g. 00:11:22:33:44:55
            // Each with values: BRCMStack DWORD, Code DWORD, DevClass DWORD, etc etc
            //
            List_IBluetoothDeviceInfo devices = new List_IBluetoothDeviceInfo();

            using (RegistryKey rkDevices = Registry.LocalMachine.OpenSubKey(DevicesRegPath)) {
                if (rkDevices == null)
                {
                    // The Registry key is created when the first device is stored,
                    // so on a new device it doesn't exist. So return an empty list.
                    return(devices);
                    // IOException is what GetValueKind throws.
                    //throw new System.IO.IOException("Widcomm 'Devices' key not found in the Registry.");
                }
                foreach (string itemName in rkDevices.GetSubKeyNames())
                {
                    using (RegistryKey rkItem = rkDevices.OpenSubKey(itemName)) {
                        WidcommBluetoothDeviceInfo bdi = ReadDeviceFromRegistryAndCheckAndSetIfPaired_(
                            itemName, rkItem, m_factory);
                        devices.Add(bdi);
                    }
                }//for
            }
            return(devices);
        }
コード例 #3
0
        /// <summary>
        /// Used when loading a stack stored/remembered/maybe-paired device.
        /// </summary>
        internal static WidcommBluetoothDeviceInfo CreateFromStoredRemoteDeviceInfo(REM_DEV_INFO rdi, WidcommBluetoothFactoryBase factory)
        {
            WidcommBluetoothDeviceInfo bdi = new WidcommBluetoothDeviceInfo(rdi, factory);

            bdi.m_remembered = true;
            return(bdi);
        }
コード例 #4
0
        //--------
        internal static WidcommBluetoothDeviceInfo CreateFromGivenAddressNoLookup(BluetoothAddress address, WidcommBluetoothFactoryBase factory)
        {
            REM_DEV_INFO rdi = new REM_DEV_INFO();

            rdi.bda = WidcommUtils.FromBluetoothAddress(address);
            WidcommBluetoothDeviceInfo bdi = new WidcommBluetoothDeviceInfo(rdi, factory);

            return(bdi);
        }
コード例 #5
0
 //--------------------------------------------------------------
 /// <summary>
 /// Called after reading the device from the Registry, to find if it is paired.
 /// </summary>
 internal static void CheckAndSetIfPaired(WidcommBluetoothDeviceInfo bdi, WidcommBluetoothFactoryBase factory)
 {
     Debug.Assert(bdi.m_remembered == true, "should be already marked as rembered");
     Debug.Assert(!bdi.m_remDevInfo.b_paired, "why rechecking?");
     if (!bdi.m_remDevInfo.b_paired)
     {
         bool paired = factory.GetWidcommBtInterface().BondQuery(bdi.m_remDevInfo.bda);
         bdi.m_remDevInfo.b_paired = paired;
     }
 }
コード例 #6
0
ファイル: WidcommBtInterface.cs プロジェクト: jehy/32feet.NET
            //----
            internal void HandleDeviceResponded(byte[] bdAddr, byte[] devClass,
                                                byte[] deviceName, bool connected)
            {
                Utils.MiscUtils.Trace_WriteLine("HandleDeviceResponded");
                var bdi = WidcommBluetoothDeviceInfo.CreateFromHandleDeviceResponded(
                    bdAddr, deviceName, devClass, connected, m_factory);

                Utils.MiscUtils.Trace_WriteLine("HDR: {0} {1} {2} {3}",
                                                ToStringQuotedOrNull(bdAddr), ToStringQuotedOrNull(devClass),
                                                ToStringQuotedOrNull(deviceName), connected);
                HandleInquiryResultInd(bdi);
                Utils.MiscUtils.Trace_WriteLine("exit HDR");
            }
コード例 #7
0
        /// <summary>
        /// Used when a device is discovered during Inquiry.
        /// </summary>
        /// -
        /// <remarks>
        /// <para>When the result of Inquiry and get-stack-stored-devices are merged,
        /// the remembered/authenticated flags may get set then (with <see cref="M:SetAuthenticated"/>).
        /// </para>
        /// </remarks>
        internal static WidcommBluetoothDeviceInfo CreateFromHandleDeviceResponded(byte[] bdAddr,
                                                                                   byte[] deviceName, byte[] devClass, bool connected, WidcommBluetoothFactoryBase factory)
        {
            REM_DEV_INFO rdi = new REM_DEV_INFO();

            rdi.bda         = bdAddr;
            rdi.bd_name     = deviceName;
            rdi.b_connected = connected;
            rdi.dev_class   = devClass;
            WidcommBluetoothDeviceInfo bdi = new WidcommBluetoothDeviceInfo(rdi, factory);

            //bdi.m_inquiryTime = DateTime.UtcNow;
            return(bdi);
        }
コード例 #8
0
        internal static WidcommBluetoothDeviceInfo CreateFromGivenAddress(BluetoothAddress address, WidcommBluetoothFactoryBase factory)
        {
            REM_DEV_INFO rdi = new REM_DEV_INFO();

            rdi.bda = WidcommUtils.FromBluetoothAddress(address);
            WidcommBluetoothDeviceInfo bdi = factory.GetWidcommBtInterface()
                                             .ReadDeviceFromRegistryAndCheckAndSetIfPaired(address, factory);

            if (bdi == null)
            {
                bdi = CreateFromGivenAddressNoLookup(address, factory);
            }
            return(bdi);
        }
コード例 #9
0
ファイル: WidcommBtInterface.cs プロジェクト: jehy/32feet.NET
        private static WidcommBluetoothDeviceInfo CreateFromStoredRemoteDeviceInfo(
            BluetoothAddress devAddress, byte[] devName, byte[] devClass,
            WidcommBluetoothFactoryBase factory)
        {
            REM_DEV_INFO rdi = new REM_DEV_INFO();

            rdi.bda       = WidcommUtils.FromBluetoothAddress(devAddress);
            rdi.bd_name   = devName;
            rdi.dev_class = devClass;
            // rdi.b_connected = ...
            // rdi.b_paired = ...
            WidcommBluetoothDeviceInfo bdi = WidcommBluetoothDeviceInfo.CreateFromStoredRemoteDeviceInfo(rdi, factory);
            string nameStr = bdi.DeviceName;

            Debug.Assert(nameStr.Length == 0 || nameStr[nameStr.Length - 1] != 0, "null terminator!!");
            int idxDbg;

            Debug.Assert((idxDbg = nameStr.IndexOf((char)0)) == -1, "null terminator!! at: " + idxDbg);
            return(bdi);
        }
コード例 #10
0
ファイル: WidcommBtInterface.cs プロジェクト: jehy/32feet.NET
 internal WidcommBluetoothDeviceInfo ReadDeviceFromRegistryAndCheckAndSetIfPaired(BluetoothAddress address,
                                                                                  WidcommBluetoothFactoryBase factory)
 {
     using (RegistryKey rkDevices = Registry.LocalMachine.OpenSubKey(DevicesRegPath)) {
         if (rkDevices == null)
         {
             // The Registry key is created when the first device is stored,
             // so on a new device it doesn't exist. So return an empty list.
             return(null);
         }
         string itemName = address.ToString("C");
         using (RegistryKey rkItem = rkDevices.OpenSubKey(itemName)) {
             if (rkItem == null)
             {
                 return(null);
             }
             WidcommBluetoothDeviceInfo bdi = ReadDeviceFromRegistryAndCheckAndSetIfPaired_(itemName, rkItem, factory);
             return(bdi);
         }
     }
 }
コード例 #11
0
ファイル: WidcommBtInterface.cs プロジェクト: jehy/32feet.NET
        private WidcommBluetoothDeviceInfo ReadDeviceFromRegistryAndCheckAndSetIfPaired_(
            string itemName, RegistryKey rkItem, WidcommBluetoothFactoryBase factory)
        {
            BluetoothAddress address = BluetoothAddress.Parse(itemName);

            Debug.Assert(GetWidcommDeviceKeyName(address).Equals(itemName, StringComparison.OrdinalIgnoreCase),
                         "itemName not colons?: " + itemName);
            //
            byte[] devName, devClass;
            try {
                devName  = Registry_ReadBinaryValue(rkItem, "Name");
                devClass = Registry_ReadBinaryValue(rkItem, "DevClass");
            } catch (IOException) { // "The specified registry key does not exist."
                Debug.WriteLine("Partial device info in Registry for: {0}.", itemName);
                return(null);
            }
            Int32?trusted = Registry_ReadDwordValue_Optional(rkItem, "TrustedMask");
            WidcommBluetoothDeviceInfo bdi = CreateFromStoredRemoteDeviceInfo(address, devName, devClass, factory);

            WidcommBluetoothDeviceInfo.CheckAndSetIfPaired(bdi, factory);
            return(bdi);
        }
コード例 #12
0
 protected override IBluetoothDeviceInfo GetBluetoothDeviceInfo(BluetoothAddress address)
 {
     EnsureLoaded();
     return(WidcommBluetoothDeviceInfo.CreateFromGivenAddress(address, this));
 }