public bool SetSecurityLevel(byte[] p_service_name, BTM_SEC security_level, bool is_server) { Debug.Assert(!m_SSL_secLevel.HasValue, "Duplicate call to SetSecurityLevel!"); m_SSL_secLevel = security_level; m_SSL_isServer = is_server; return(SUCCESS); }
//-------------------------------------------------------------- internal static BTM_SEC ToBTM_SEC(bool isServer, bool authenticate, bool encrypt) { BTM_SEC ret = BTM_SEC.NONE; // Note for authenticate=true we set AUTHENTICATE, and not also AUTHORIZE. if (!isServer) { if (encrypt) { ret |= BTM_SEC.OUT_ENCRYPT; // "BTM_SEC_OUT_AUTHENTICATE has to be set" ret |= BTM_SEC.OUT_AUTHENTICATE; } if (authenticate) { ret |= BTM_SEC.OUT_AUTHENTICATE; } } else { if (encrypt) { ret |= BTM_SEC.IN_ENCRYPT; // "BTM_SEC_IN_AUTHENTICATE has to be set.)" ret |= BTM_SEC.IN_AUTHENTICATE; } if (authenticate) { ret |= BTM_SEC.IN_AUTHENTICATE; } } Utils.MiscUtils.Trace_WriteLine("{0}; {1},{2}-> {3}", isServer, authenticate, encrypt, ret); return(ret); }
public bool SetSecurityLevel(byte[] p_service_name, BTM_SEC securityLevel, bool isServer) { WidcommPortSingleThreader.MiscReturnCommand <bool> cmd = _st.AddCommand( new WidcommPortSingleThreader.MiscReturnCommand <bool>(delegate { return(_child.SetSecurityLevel(p_service_name, securityLevel, isServer)); })); return(cmd.WaitCompletion()); }
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")); } }
protected override void SetupListener(BluetoothEndPoint bep, int requestedScn, out BluetoothEndPoint liveLocalEP) { SetupRfcommIf(); int scn = m_RfCommIf.SetScnForLocalServer(bep.Service, requestedScn); BTM_SEC secLevel = WidcommUtils.ToBTM_SEC(true, m_authenticate, m_encrypt); m_RfCommIf.SetSecurityLevelServer(secLevel, new byte[] { (byte)'h', (byte)'a', (byte)'c', (byte)'k', (byte)'S', (byte)'v', (byte)'r', } ); liveLocalEP = new BluetoothEndPoint(BluetoothAddress.None, BluetoothService.Empty, scn); }
internal static extern bool L2CapIf_SetSecurityLevel(PL2CapIf pObj, // TODO change to byte[] string p_service_name, BTM_SEC security_level, [MarshalAs(UnmanagedType.Bool)] bool is_server);
void MultipleConnection_(bool auth, bool encrypt, BTM_SEC expectedSecurityLevel) { TestWcLsnrBluetoothFactory f = new TestWcLsnrBluetoothFactory(); TestLsnrRfCommIf commIf = new TestLsnrRfCommIf(); f.queueIRfCommIf.Enqueue(commIf); TestLsnrRfcommPort port0 = new TestLsnrRfcommPort(); f.queueIRfCommPort.Enqueue(port0); port0.SetOpenServerResult(PORT_RETURN_CODE.SUCCESS); BluetoothFactory.SetFactory(f); // BluetoothListener lsnr = new BluetoothListener(BluetoothService.VideoSource); if (auth) { lsnr.Authenticate = true; } if (encrypt) { lsnr.Encrypt = true; } Assert.AreEqual(auth, lsnr.Authenticate, ".Authenticate 1"); Assert.AreEqual(encrypt, lsnr.Encrypt, ".Encrypt 1"); lsnr.Start(); IAsyncResult ar; commIf.AssertSetSecurityLevel(expectedSecurityLevel, true); // ar = lsnr.BeginAcceptBluetoothClient(null, null); port0.AssertOpenServerCalledAndClear(29);//adter Start? TestLsnrRfcommPort port1 = new TestLsnrRfcommPort(); f.queueIRfCommPort.Enqueue(port1); port1.SetOpenServerResult(PORT_RETURN_CODE.SUCCESS); port0.NewEvent(PORT_EV.CONNECTED); TestsApmUtils.SafeNoHangWaitShort(ar, "Accept"); Assert.IsTrue(ar.IsCompleted, "IsCompleted"); BluetoothClient cli0 = lsnr.EndAcceptBluetoothClient(ar); // ar = lsnr.BeginAcceptBluetoothClient(null, null); port1.AssertOpenServerCalledAndClear(29);//adter Start? TestLsnrRfcommPort port2 = new TestLsnrRfcommPort(); port2.SetOpenServerResult(PORT_RETURN_CODE.SUCCESS); f.queueIRfCommPort.Enqueue(port2); port1.NewEvent(PORT_EV.CONNECTED); TestsApmUtils.SafeNoHangWaitShort(ar, "Accept"); Assert.IsTrue(ar.IsCompleted, "IsCompleted"); BluetoothClient cli1 = lsnr.EndAcceptBluetoothClient(ar); // ar = lsnr.BeginAcceptBluetoothClient(null, null); port2.AssertOpenServerCalledAndClear(29);//adter Start? TestLsnrRfcommPort port3 = new TestLsnrRfcommPort(); port3.SetOpenServerResult(PORT_RETURN_CODE.SUCCESS); f.queueIRfCommPort.Enqueue(port3); port2.NewEvent(PORT_EV.CONNECTED); TestsApmUtils.SafeNoHangWaitShort(ar, "Accept"); Assert.IsTrue(ar.IsCompleted, "IsCompleted"); BluetoothClient cli2 = lsnr.EndAcceptBluetoothClient(ar); // ar = lsnr.BeginAcceptBluetoothClient(null, null); port3.AssertOpenServerCalledAndClear(29);//adter Start? TestLsnrRfcommPort port4 = new TestLsnrRfcommPort(); f.queueIRfCommPort.Enqueue(port4); port4.SetOpenServerResult(PORT_RETURN_CODE.SUCCESS); port3.NewEvent(PORT_EV.CONNECTED); TestsApmUtils.SafeNoHangWaitShort(ar, "Accept"); Assert.IsTrue(ar.IsCompleted, "IsCompleted"); BluetoothClient cli3 = lsnr.EndAcceptBluetoothClient(ar); // TestSdpService2 sdpSvc = f.GetTestSdpService(); Assert.AreEqual(0, sdpSvc.NumDisposeCalls, "NumDisposeCalls"); lsnr.Stop(); Assert.AreEqual(1, sdpSvc.NumDisposeCalls, "NumDisposeCalls"); Assert.AreEqual(auth, lsnr.Authenticate, ".Authenticate 2"); Assert.AreEqual(encrypt, lsnr.Encrypt, ".Encrypt 2"); // Assert.IsTrue(cli0.Connected, "0 cli.Connected"); Assert.AreEqual(0, f.queueIRfCommPort.Count, "Used both ports"); port4.AssertCloseCalledOnce("4 acceptor closed"); cli0.Close(); port0.AssertCloseCalledOnce("0 accepted connection now closed"); // Assert.IsTrue(cli1.Connected, "1 cli.Connected"); cli1.Close(); port1.AssertCloseCalledOnce("1 accepted connection now closed"); // Assert.IsTrue(cli2.Connected, "2 cli.Connected"); cli2.Close(); port2.AssertCloseCalledOnce("2 accepted connection now closed"); // Assert.IsTrue(cli3.Connected, "3 cli.Connected"); cli3.Close(); port3.AssertCloseCalledOnce("3 accepted connection now closed"); }
public bool SetSecurityLevel(byte[] serviceName, BTM_SEC securityLevel, bool isServer) { string serviceNameX = "foo"; // HACK serviceNameX return(WidcommL2CapClient.NativeMethods.L2CapIf_SetSecurityLevel(_pIf, serviceNameX, securityLevel, isServer)); }
public bool SetSecurityLevel(byte[] serviceName, BTM_SEC securityLevel, bool isServer) { return(NativeMethods.RfCommIf_SetSecurityLevel(m_pRfCommIf, serviceName, securityLevel, isServer)); }
internal static extern bool RfCommIf_SetSecurityLevel(IntPtr pRfCommPort, byte[] serviceName, BTM_SEC securityLevel, [MarshalAs(UnmanagedType.Bool)] bool isServer);
internal void AssertSetSecurityLevel(BTM_SEC expectedSecurityLevel, bool expectedIsServer) { Assert.AreEqual(expectedSecurityLevel, m_SSL_secLevel, "SetSecurityLevel-BTM_SEC"); Assert.AreEqual(expectedIsServer, m_SSL_isServer, "SetSecurityLevel-isServer"); }