internal static BluesoleilDeviceInfo CreateFromHandleFromStored(uint hDev, BluesoleilFactory factory) { var result = new BluesoleilDeviceInfo(hDev, factory); result._remembered = true; return(result); }
internal List <IBluetoothDeviceInfo> GetRememberedDevices(bool authenticated, bool remembered) { if (!remembered && !authenticated) { //Debug.Fail("Why call me?? No work to do!"); return(new List <IBluetoothDeviceInfo>()); } const uint AnyCod = 0; UInt32[] handlesList = new UInt32[1000]; int num = Api.Btsdk_GetStoredDevicesByClass(AnyCod, handlesList, handlesList.Length); var result = new List <IBluetoothDeviceInfo>(); for (int i = 0; i < num; ++i) { var hDev = handlesList[i]; BluesoleilDeviceInfo dev = BluesoleilDeviceInfo.CreateFromHandleFromStored(hDev, this); Debug.Assert(dev.Remembered, "NOT dev.Remembered but FromStored!"); if (remembered || (authenticated && dev.Authenticated)) { result.Add(dev); } }//for return(result); }
//---- internal static BluesoleilDeviceInfo CreateFromGivenAddress(BluetoothAddress addr, BluesoleilFactory factory) { UInt32 hDev; byte[] bd_addr = BluesoleilUtils.FromBluetoothAddress(addr); bool remembered; hDev = factory.Api.Btsdk_GetRemoteDeviceHandle(bd_addr); if (hDev != StackConsts.BTSDK_INVALID_HANDLE) { remembered = true; } else { // Presumably this means that the device isn't known. // Does this add it forever? -- no??? hDev = factory.Api.Btsdk_AddRemoteDevice(bd_addr); if (hDev == StackConsts.BTSDK_INVALID_HANDLE) { BluesoleilUtils.CheckAndThrow(BtSdkError.SDK_UNINIT, "Btsdk_Get/AddRemoteDevice"); } remembered = false; } var result = new BluesoleilDeviceInfo(hDev, factory); result._remembered = remembered; Debug.Assert(addr.Equals(result.DeviceAddress), "Address changed in create! was: " + addr + ", now: " + result.DeviceAddress); return(result); }
bool IBluetoothSecurity.RemoveDevice(BluetoothAddress device) { BluesoleilDeviceInfo bdi = BluesoleilDeviceInfo.CreateFromGivenAddress(device, _factory); // TO-DO We don't need to do Btsdk_UnPairDevice also do we? BtSdkError ret = _factory.Api.Btsdk_DeleteRemoteDeviceByHandle(bdi.Handle); return(ret == BtSdkError.OK); }
internal static BluesoleilDeviceInfo CreateFromHandleFromInquiry(uint hDev, BluesoleilFactory factory) { var result = new BluesoleilDeviceInfo(hDev, factory); Debug.Assert(result._remembered == false, "NOT !_remembered, we don't set it, does the stack set it?"); if (result.Authenticated) { result._remembered = true; } return(result); }
bool IBluetoothSecurity.PairRequest(BluetoothAddress device, string pin) { //if (pin != null) { // throw new NotImplementedException("Only support pin 'null'/'Nothing' to show the UI dialog."); // BluesoleilDeviceInfo bdi = BluesoleilDeviceInfo.CreateFromGivenAddress(device, _factory); BTDEVHDL hDev = bdi.Handle; _factory.RegisterCallbacksOnce(); try { if (pin != null) { SetPin(hDev, pin); } BtSdkError ret = _factory.Api.Btsdk_PairDevice(hDev); // TODO Do we have to wait here for completion??? return(ret == BtSdkError.OK); } finally { if (pin != null) { RevokePin(hDev); } } }
internal static BluesoleilDeviceInfo CreateFromHandleFromConnection(uint hDev, BluesoleilFactory factory) { var result = new BluesoleilDeviceInfo(hDev, factory); return(result); }
public override void Connect(BluetoothEndPoint remoteEP) { if (remoteEP.Port != 0 && remoteEP.Port != -1) { throw new NotSupportedException("Don't support connect to particular port. Please can someone tell me how."); } // _factory.SdkInit(); _factory.RegisterCallbacksOnce(); // Need to use event DISC_IND to close the Stream/SerialPort. // BluesoleilDeviceInfo bdi = BluesoleilDeviceInfo.CreateFromGivenAddress(remoteEP.Address, _factory); UInt32 hDev = bdi.Handle; UInt32 hConn; byte channel; int comPort; ConnectRfcomm(remoteEP, hDev, out hConn, out channel, out comPort); //if (_HasPort(remoteEP)) { // ConnectRfcomm(remoteEP, hDev, out hConn, out channel, out comPort); //} else { // UInt16? svcClass16; // if (!ServiceRecordUtilities.IsUuid16Value(remoteEP.Service)) { // svcClass16 = null; // } else { // svcClass16 = (UInt16)ServiceRecordUtilities.GetAsUuid16Value(remoteEP.Service); // } // UInt16[] specialClasses = { }; // if (svcClass16.HasValue && IsIn(svcClass16.Value, specialClasses)) { // throw new NotImplementedException("Internal Error: Should not use this code."); //// The original method we used for connecting did not work for //// profiles that BlueSoleil has support for -- returning no COM //// port but enabling per-profile support //// We have a second way, which seems to work in those cases //// but it is more complex -- we manually allocate the port etc //// (also it doesn't give us the remote RFCOMM channel). //// Use the first method for now except in special cases... // //UInt32 comSerialNum; // //UInt32? comSerialNum; // //ConnectRfcommPreAllocateComPort(svcClass16.Value, hDev, // // out hConn, out channel, out comPort // // //, out comSerialNum // // ); // } else { // ConnectRfcomm(remoteEP, hDev, out hConn, out channel, out comPort); // } //} _remoteEp = new BluetoothEndPoint(remoteEP.Address, BluetoothService.Empty, channel); // var serialPort = CreateSerialPort(); if (BufferSize.HasValue) { serialPort.ReadBufferSize = BufferSize.Value; serialPort.WriteBufferSize = BufferSize.Value; } serialPort.PortName = "COM" + comPort; serialPort.Handshake = Handshake.RequestToSend; serialPort.Open(); //((System.ComponentModel.IComponent)serialPort).Disposed // += delegate { System.Windows.Forms.MessageBox.Show("BlueSoleil's SerialPort disposed"); }; // // We pass '_hConn' as the Stream handles calling // Btsdk_Disconnect to close the RFCOMM connection. var strm = new BlueSoleilSerialPortNetworkStream(serialPort, hConn, this, _factory); _stream = strm; int liveCount = _factory.AddConnection(hConn, strm); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "BlueSoleilClient.Connect LiveConns count: {0}.", liveCount)); // TODO who handles closing the connection if opening the port fails }
//---- protected override IBluetoothDeviceInfo CreateDeviceInfo(UInt32 item) { IBluetoothDeviceInfo bdi = BluesoleilDeviceInfo.CreateFromHandleFromInquiry(item, _fcty); return(bdi); }
//---- protected override IBluetoothDeviceInfo GetBluetoothDeviceInfo(BluetoothAddress address) { return(BluesoleilDeviceInfo.CreateFromGivenAddress(address, this)); }