//---- internal string CreatePort(BluetoothAddress addr) { if (IsSet(_waitConnect)) { throw new InvalidOperationException("Already used."); } _addr = addr; byte[] bd_addr = WidcommUtils.FromBluetoothAddress(addr); byte[] tcharzServiceName = { 0, 0 }; var inUse = Interlocked.CompareExchange(ref _sfInConnect, 1, 0); if (inUse != 0) { throw new InvalidOperationException("Widcomm only allows one SPP Connect attempt at a time."); } SPP_CLIENT_RETURN_CODE ret = (SPP_CLIENT_RETURN_CODE)(-1); _singleThreader.AddCommand(new WidcommPortSingleThreader.MiscNoReturnCommand( () => ret = NativeMethods.SppClient_CreateConnection( _pSppCli, bd_addr, tcharzServiceName) )).WaitCompletion(); Debug.WriteLine("SppClient_CreateConnection ret: " + ret); int timeout = 30000; bool signalled = _waitConnect.WaitOne(timeout, false); // Eeek want to set this even when we got NO callback........ // Do for now because Win32 is not working at all...... Interlocked.Exchange(ref _sfInConnect, 0); if (!signalled) { throw CommonSocketExceptions.Create_NoResultCode( WidcommSppSocketExceptions.SocketError_Misc, "CreatePort failed (time-out)."); } MemoryBarrier(); if (_statusState != SPP_STATE_CODE.CONNECTED) { throw WidcommSppSocketExceptions.Create(_statusState, "CreatePort"); } if (_statusComPort == null) { throw CommonSocketExceptions.Create_NoResultCode( WidcommSppSocketExceptions.SocketError_Misc, "CreatePort did not complete (cpn)."); } // // TODO Move these into the native-event handler. //string comPort = MakePortName(_statusComPort.Value); //_comNum = _statusComPort.Value; //_comPortName = comPort; Debug.Assert(_comPortName != null, "_comPortName IS null"); Debug.Assert(WidcommUtils.ToBluetoothAddress(_statusBda) == addr, "addr NOT equal, is: " + WidcommUtils.ToBluetoothAddress(_statusBda)); return(_comPortName); }
private void StartInquiry() // We are inside the lock. { // BTW InquiryLength is set-up in BeginInquiry. Debug.WriteLine(WidcommUtils.GetTime4Log() + ": calling StartInquiry."); bool success = m_btIf.StartInquiry(); Debug.WriteLine(WidcommUtils.GetTime4Log() + ": StartInquiry ret: " + success); if (!success) { throw CommonSocketExceptions.Create_StartInquiry("StartInquiry"); } }
internal void SetSecurityLevelServer(BTM_SEC securityLevel, byte[] serviceName) { const bool isServerTrue = true; bool success = m_RfCommIf.SetSecurityLevel(serviceName, securityLevel, isServerTrue); if (!success) { throw new IOException(WidcommRfcommStreamBase.WrappingIOExceptionMessage, CommonSocketExceptions.Create_NoResultCode( CommonSocketExceptions.SocketError_SetSecurityLevel_Client_Fail, "SetSecurityLevel")); } }
//-------------------------------------------------------------- internal int SetScnForLocalServer(Guid serviceGuid, int scn) { bool success = m_RfCommIf.ClientAssignScnValue(serviceGuid, scn); if (!success) { throw new IOException(WidcommRfcommStreamBase.WrappingIOExceptionMessage, CommonSocketExceptions.Create_NoResultCode( CommonSocketExceptions.SocketError_SetSecurityLevel_Client_Fail, "SetScnForLocalServer")); } int scnAssigned = m_RfCommIf.GetScn(); Utils.MiscUtils.Trace_WriteLine("Server GetScn returned port: {0}", scnAssigned); Debug.Assert(scnAssigned != 0); return(scnAssigned); }
//-------------------------------------------------------------- internal void SetScnForPeerServer(Guid serviceGuid, int scn) { bool success = m_RfCommIf.ClientAssignScnValue(serviceGuid, scn); if (!success) { throw new IOException(WidcommRfcommStreamBase.WrappingIOExceptionMessage, CommonSocketExceptions.Create_NoResultCode( CommonSocketExceptions.SocketError_SetSecurityLevel_Client_Fail, "SetScnForPeerServer")); } }
//-- #if !HIDE_WIDCOMM_WIDCOMM_EXCEPTIONS internal static SocketException Create_StartDiscovery(WBtRc ee) { return(CommonSocketExceptions.Create_NoResultCode(CommonSocketExceptions.SocketError_StartDiscovery_Failed, "StartDiscoverySDP" + ((ee == unchecked ((WBtRc)(-1)) /*|| ee == WBtRc.WBT_SUCCESS*/) ? string.Empty : string.Format(System.Globalization.CultureInfo.InvariantCulture, ", {0} = 0x{1:X}", ee, (uint)ee)))); }