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
            }
        }
Exemple #2
0
 internal BTH_RADIO_INFO(Version fakeSetAllUnknown)
 {
     _lmpSupportedFeatures = 0;
     _mfg           = Manufacturer.Unknown;
     _lmpSubversion = 0;
     _lmpVersion    = LmpVersion.Unknown;
 }
Exemple #3
0
 internal BTH_RADIO_INFO(LmpVersion lmpVersion, UInt16 lmpSubversion, Manufacturer mfg, UInt64 lmpSupportedFeatures)
 {
     _lmpSupportedFeatures = unchecked ((LmpFeatures)lmpSupportedFeatures);
     _mfg           = mfg;
     _lmpSubversion = lmpSubversion;
     _lmpVersion    = lmpVersion;
 }
Exemple #4
0
 public RadioVersions(LmpVersion lmpVersion, ushort lmpSubversion,
                      LmpFeatures lmpSupportedFeatures, Manufacturer mfg)
 {
     this.LmpVersion      = lmpVersion;
     LmpSubversion        = lmpSubversion;
     LmpSupportedFeatures = lmpSupportedFeatures;
     Manufacturer         = mfg;
 }
Exemple #5
0
 BluetopiaError IBluetopiaApi.HCI_Read_Local_Version_Information(uint BluetoothStackID,
                                                                 out StackConsts.HCI_ERROR_CODE StatusResult,
                                                                 out HciVersion HCI_VersionResult, out ushort HCI_RevisionResult,
                                                                 out LmpVersion LMP_VersionResult, out Manufacturer Manufacturer_NameResult, out ushort LMP_SubversionResult)
 {
     return(NativeMethods.HCI_Read_Local_Version_Information(BluetoothStackID,
                                                             out StatusResult, out HCI_VersionResult, out HCI_RevisionResult,
                                                             out LMP_VersionResult, out Manufacturer_NameResult, out LMP_SubversionResult));
 }
        //private IntPtr msgQueueHandle;
        //private IntPtr notificationHandle;


        #region Constructor
        internal WindowsBluetoothRadio(IntPtr handle)
        {
            //get version/manufacturer
            byte      CHECK0 = 0;
            byte      hv;
            byte      CHECK1 = 0;
            ushort    hr;
            byte      CHECK2 = 0;
            byte      lv;
            byte      CHECK3 = 0;
            ushort    ls;
            byte      CHECK4 = 0;
            ushort    man;
            byte      CHECK5            = 0;
            const int HciFeaturesLength = 8;
            var       fea    = new byte[HciFeaturesLength];
            byte      CHECK6 = 0;

            int hresult = NativeMethods.BthReadLocalVersion(out hv, out hr, out lv, out ls, out man, fea);

            Debug.Assert((CHECK0 == 0) && (CHECK1 == 0) && (CHECK2 == 0) && (CHECK3 == 0) && (CHECK4 == 0) && (CHECK5 == 0) && (CHECK6 == 0));
            if (hresult == 0)
            {
                manufacturer = (Manufacturer)man;
                _hciV        = (HciVersion)hv;
                _hciRev      = hr;
                _lmpV        = (LmpVersion)lv;
                _lmpSubv     = ls;
                var feaI = BitConverter.ToInt64(fea, 0); // ?? ordering ??
                _lmpFeatures = (LmpFeatures)feaI;
                var msgFe = "BtRadio lmpFeatures: '"
                            + _lmpFeatures + "' 0x" + _lmpFeatures.ToString("X");
                Debug.WriteLine(msgFe);
            }
            else
            {
                manufacturer = Manufacturer.Unknown;
                _hciV        = HciVersion.Unknown;
                _lmpV        = LmpVersion.Unknown;
            }

            //setup message queue

            /*NativeMethods.MSGQUEUEOPTIONS mqo = new NativeMethods.MSGQUEUEOPTIONS();
             * mqo.dwFlags = 0;
             * mqo.cbMaxMessage = 72;
             * mqo.bReadAccess = true;
             * mqo.dwSize = System.Runtime.InteropServices.Marshal.SizeOf(mqo);
             * msgQueueHandle = NativeMethods.CreateMsgQueue("InTheHand.Net.Bluetooth.BluetoothRadio", ref mqo);
             *
             * notificationHandle = NativeMethods.RequestBluetoothNotifications(NativeMethods.BTE_CLASS.CONNECTIONS | NativeMethods.BTE_CLASS.DEVICE | NativeMethods.BTE_CLASS.PAIRING | NativeMethods.BTE_CLASS.STACK, msgQueueHandle);
             *
             * System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(EventThread));
             * t.IsBackground = true;
             * t.Start();*/
        }
Exemple #7
0
 //--
 #region HCIAPI.h
 BluetopiaError IBluetopiaApi.HCI_Read_Local_Version_Information(uint BluetoothStackID,
                                                                 out StackConsts.HCI_ERROR_CODE StatusResult,
                                                                 out HciVersion HCI_VersionResult, out ushort HCI_RevisionResult,
                                                                 out LmpVersion LMP_VersionResult, out Manufacturer Manufacturer_NameResult, out ushort LMP_SubversionResult)
 {
     StatusResult            = 0;
     HCI_VersionResult       = HciVersion.Unknown;
     LMP_VersionResult       = LmpVersion.Unknown;
     HCI_RevisionResult      = LMP_SubversionResult = 0xFFFF;
     Manufacturer_NameResult = Manufacturer.Unknown;
     return(BluetopiaError.UNSUPPORTED_PLATFORM_ERROR);
 }
Exemple #8
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;
            }
        }
        public static string LmpVerToString(this LmpVersion version)
        {
            switch (version)
            {
            case LmpVersion.v1_0_b: return("Bluetooth Core Specification 1.0b");

            case LmpVersion.v1_1: return("Bluetooth Core Specification 1.1");

            case LmpVersion.v1_2: return("Bluetooth Core Specification 1.2");

            case LmpVersion.v2_0wEdr: return("Bluetooth Core Specification 2.0 + EDR");

            case LmpVersion.v2_1wEdr: return("Bluetooth Core Specification 2.1 + EDR");

            case LmpVersion.v3_0wHS: return("Bluetooth Core Specification 3.0 + HS");

            case LmpVersion.v4_0: return("Bluetooth Core Specification 4.0");

            case LmpVersion.Unknown:
            default:
                return("Version Unknown");
            }
        }
Exemple #10
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("Hci: " + HciVersion.ToString() + " Lmp: " + LmpVersion.ToString() + " Manufacturer: " + Manufacturer.ToString());
 }
Exemple #11
0
 internal static extern int BthReadRemoteVersion(byte[] pba, out LmpVersion plmp_version,
                                                 out ushort plmp_subversion, out Manufacturer pmanufacturer, out LmpFeatures plmp_features);
Exemple #12
0
 internal static extern BluetopiaError HCI_Read_Local_Version_Information(uint BluetoothStackID,
                                                                          out StackConsts.HCI_ERROR_CODE StatusResult,
                                                                          out HciVersion HCI_VersionResult, out ushort HCI_RevisionResult,
                                                                          out LmpVersion LMP_VersionResult, out Manufacturer Manufacturer_NameResult, out ushort LMP_SubversionResult);