示例#1
0
        void ReadVersionInfo(WindowsRadioHandle handle,
                             ref LmpVersion lmpV, ref int lmpSubv, ref HciVersion hciV, ref int hciRev, ref LmpFeatures lmpFeatures)
        {
            // Windows 7 IOCTL
            var buf = new byte[300];
            int bytesReturned;
            var success = NativeMethods.DeviceIoControl(handle,
                                                        NativeMethods.MsftWin32BthIOCTL.IOCTL_BTH_GET_LOCAL_INFO,
                                                        IntPtr.Zero, 0,
                                                        buf, buf.Length, out bytesReturned, IntPtr.Zero);

            if (!success)
            {
                int gle = Marshal.GetLastWin32Error();
                Debug.WriteLine(string.Format(CultureInfo.InvariantCulture,
                                              "INFO: IOCTL_BTH_GET_LOCAL_INFO failure: {0} = 0x{0:X}.", gle));
            }
            else
            {
                const int OffsetOf_flags         = 272;
                const int OffsetOf_hciRevision   = OffsetOf_flags + 4;
                const int OffsetOf_hciVersion    = OffsetOf_hciRevision + 2;
                const int OffsetOf_radioInfo     = OffsetOf_hciVersion + 1; //????? pad??
                const int OffsetOf_lmpFeatures   = OffsetOf_radioInfo;
                const int OffsetOf_mfg           = OffsetOf_radioInfo + 8;
                const int OffsetOf_lmpSubversion = OffsetOf_mfg + 2;
                const int OffsetOf_lmpVersion    = OffsetOf_lmpSubversion + 2;
                const int OffsetOf_END           = OffsetOf_lmpVersion + 1;
                const int ExpectedSize           = 292;
                Debug.Assert(OffsetOf_END == ExpectedSize,
                             "OffsetOf_END: " + OffsetOf_END + ", ExpectedSize: " + ExpectedSize);
                hciRev  = BitConverter.ToUInt16(buf, OffsetOf_hciRevision);
                hciV    = (HciVersion)buf[OffsetOf_hciVersion];
                lmpSubv = BitConverter.ToUInt16(buf, OffsetOf_lmpSubversion);
                lmpV    = (LmpVersion)buf[OffsetOf_lmpVersion];
                var dbg_mfg = BitConverter.ToUInt16(buf, OffsetOf_mfg);
                Debug.Assert(lmpSubv == radio.lmpSubversion,
                             "_lmpSubv: " + lmpSubv + ", radio.lmpSubversion: " + radio.lmpSubversion);
                Debug.Assert(dbg_mfg == unchecked ((ushort)radio.manufacturer),
                             "dbg_mfg: " + dbg_mfg + ", radio.manufacturer: " + radio.manufacturer);
                Debug.WriteLine(string.Format(CultureInfo.InvariantCulture,
                                              "hciSubvers: {0}, hciVersion: {1}, lmpSubversion : {2}, lmpVersion: {3}",
                                              hciRev, hciV, lmpSubv, lmpV));
                var flags = (LOCAL_FLAGS)BitConverter.ToUInt32(buf, OffsetOf_flags);
                lmpFeatures = (LmpFeatures)BitConverter.ToInt64(buf, OffsetOf_lmpFeatures);
#if DEBUG
                var msgFl = "IOCTL_BTH_GET_LOCAL_INFO flags: '"
                            + flags + "' 0x" + flags.ToString("X");
                //Debug.WriteLine(msgFl);
                //Console.WriteLine(msgFl);
                //
                var msgFe = "IOCTL_BTH_GET_LOCAL_INFO lmpFeatures: '"
                            + lmpFeatures + "' 0x" + lmpFeatures.ToString("X");
                Debug.WriteLine(msgFe);
                //Console.WriteLine(msgFe);
                LmpFeaturesUtils.FindUndefinedValues(lmpFeatures);
                //LmpFeaturesUtils.FindUnsetValues(lmpFeatures);
#endif
            }
        }
示例#2
0
 internal static extern bool DeviceIoControl(
     WindowsRadioHandle hDevice,
     uint dwIoControlCode,
     IntPtr InBuffer,
     int nInBufferSize,
     byte[] OutBuffer,
     int nOutBufferSize,
     out int pBytesReturned,
     IntPtr lpOverlapped);
示例#3
0
        internal WindowsBluetoothRadio(WindowsRadioHandle handleW)
        {
            this._handle = handleW;

            Debug.WriteLine("WindowsBluetoothRadio..ctor h=" + Handle.ToString("X"));
            radio        = new BLUETOOTH_RADIO_INFO();
            radio.dwSize = 520;
            System.Diagnostics.Debug.Assert(System.Runtime.InteropServices.Marshal.SizeOf(radio) == radio.dwSize, "BLUETOOTH_RADIO_INFO SizeOf == dwSize");

            int hresult = NativeMethods.BluetoothGetRadioInfo(_handle, ref radio);

            if (hresult != 0)
            {
                throw new System.ComponentModel.Win32Exception(hresult, "Error retrieving Radio information.");
            }

            ReadVersionInfo(_handle, ref _lmpV, ref _lmpSubv, ref _hciV, ref _hciRev, ref _lmpFeatures);
        }
示例#4
0
        /*struct _BTH_LOCAL_RADIO_INFO
         * {
         *  BTH_DEVICE_INFO localInfo;
         *  UInt32 flags;
         *  UInt16 hciRevision;
         *  Byte hciVersion;
         *  BTH_RADIO_INFO radioInfo;
         * }
         *
         * struct BTH_RADIO_INFO
         * {
         *  UInt64 lmpSupportedFeatures;
         *  UInt16 mfg;
         *  UInt16 lmpSubversion;
         *  Byte lmpVersion;
         * }*/
        #endregion

        #region Primary Radio
        internal static IBluetoothRadio GetPrimaryRadio()
        {
            //get a single radio
            IntPtr handle     = IntPtr.Zero;
            IntPtr findhandle = IntPtr.Zero;

            BLUETOOTH_FIND_RADIO_PARAMS bfrp;

            bfrp.dwSize = 4;
            System.Diagnostics.Debug.Assert(System.Runtime.InteropServices.Marshal.SizeOf(bfrp) == bfrp.dwSize, "BLUETOOTH_FIND_RADIO_PARAMS SizeOf == dwSize");

            findhandle = NativeMethods.BluetoothFindFirstRadio(ref bfrp, out handle);

            if (findhandle != IntPtr.Zero)
            {
                NativeMethods.BluetoothFindRadioClose(findhandle);
            }
            if (handle != IntPtr.Zero)
            {
                var hw = new WindowsRadioHandle(handle);
                return(new WindowsBluetoothRadio(hw));
            }
            throw new PlatformNotSupportedException("No Radio.");
        }
示例#5
0
 internal static extern bool BluetoothIsDiscoverable(WindowsRadioHandle hRadio);
示例#6
0
 internal static extern bool BluetoothIsConnectable(WindowsRadioHandle hRadio);
示例#7
0
 internal static extern int BluetoothGetRadioInfo(WindowsRadioHandle hRadio, ref BLUETOOTH_RADIO_INFO pRadioInfo);
示例#8
0
 internal static extern bool BluetoothEnableIncomingConnections(WindowsRadioHandle hRadio, bool fEnabled);
示例#9
0
 internal static extern bool BluetoothEnableDiscovery(WindowsRadioHandle hRadio, bool fEnabled);