bluetooth/btstack/rfcomm/rfcommstates.cpp
branchRCL_3
changeset 56 015fa7494bd2
parent 45 99439b07e980
equal deleted inserted replaced
49:10183c6d2913 56:015fa7494bd2
    97 		aSAP.iSocket->Error(aErr, aType);
    97 		aSAP.iSocket->Error(aErr, aType);
    98 		}
    98 		}
    99 
    99 
   100 	if(aType & MSocketNotify::EErrorFatal)
   100 	if(aType & MSocketNotify::EErrorFatal)
   101 		{
   101 		{
       
   102 		aSAP.iProtocol.ControlPlane().ModifyPhysicalLink(EUndoOverridePark, aSAP.iRemoteDev);
   102 		ChangeState(aSAP, CRfcommStateFactory::EError);
   103 		ChangeState(aSAP, CRfcommStateFactory::EError);
   103 		}
   104 		}
   104 	return aErr;
   105 	return aErr;
   105 	}
   106 	}
   106 
   107 
   654 	/**
   655 	/**
   655 	   Take this SAP off the mux, since once it's in error state we
   656 	   Take this SAP off the mux, since once it's in error state we
   656 	   don't want to get any more notifications from the mux
   657 	   don't want to get any more notifications from the mux
   657 	**/
   658 	**/
   658 	{
   659 	{
   659 	// Depending where we came from we may have applied either a
       
   660 	// park override or an all LPM override.  We remove both these
       
   661 	// overrides because it's safe to remove an override that 
       
   662 	// hasn't been applied.
       
   663 	// Note that although park is one of the LPMs the different
       
   664 	// levels of override are managed separately, so an
       
   665 	// UndoOverrideLPM does not remove an explicit park only 
       
   666 	// override.
       
   667 	aSAP.iProtocol.ControlPlane().ModifyPhysicalLink(EUndoOverridePark, aSAP.iRemoteDev);
       
   668 	aSAP.iProtocol.ControlPlane().ModifyPhysicalLink(EUndoOverrideLPM, aSAP.iRemoteDev);
       
   669 
   660 
   670 	aSAP.DeregisterCodService();	// See if there is a Service to remove for CodMan
   661 	aSAP.DeregisterCodService();	// See if there is a Service to remove for CodMan
   671 	
   662 	
   672 	if(aSAP.iMux)
   663 	if(aSAP.iMux)
   673 		{
   664 		{
   701 		{
   692 		{
   702 		aSAP.iNotifyNewDataCallback->Cancel();
   693 		aSAP.iNotifyNewDataCallback->Cancel();
   703 		}
   694 		}
   704 	aSAP.iNewDataToNotify=0;
   695 	aSAP.iNewDataToNotify=0;
   705 	aSAP.iDataBuffer.Reset();
   696 	aSAP.iDataBuffer.Reset();
   706 	
       
   707 	// Depending where we came from we may have applied either a
       
   708 	// park override or an all LPM override.  We remove both these
       
   709 	// overrides because it's safe to remove an override that 
       
   710 	// hasn't been applied.
       
   711 	// Note that although park is one of the LPMs the different
       
   712 	// levels of override are managed separately, so an
       
   713 	// UndoOverrideLPM does not remove an explicit park only 
       
   714 	// override.
       
   715 	aSAP.iProtocol.ControlPlane().ModifyPhysicalLink(EUndoOverridePark, aSAP.iRemoteDev);
   697 	aSAP.iProtocol.ControlPlane().ModifyPhysicalLink(EUndoOverridePark, aSAP.iRemoteDev);
   716 	aSAP.iProtocol.ControlPlane().ModifyPhysicalLink(EUndoOverrideLPM, aSAP.iRemoteDev);
       
   717 
       
   718 	if(aSAP.iMux)
   698 	if(aSAP.iMux)
   719 		{
   699 		{
   720 		aSAP.iMux->DetachSAP(aSAP);
   700 		aSAP.iMux->DetachSAP(aSAP);
   721 		}
   701 		}
   722 	aSAP.DeregisterCodService();	// See if there is a Service to remove for CodMan
   702 	aSAP.DeregisterCodService();	// See if there is a Service to remove for CodMan
       
   703 		
   723 	}
   704 	}
   724 
   705 
   725 void TRfcommStateClosed::Error(CRfcommSAP& /*aSAP*/, TInt /*aErr*/, 
   706 void TRfcommStateClosed::Error(CRfcommSAP& /*aSAP*/, TInt /*aErr*/, 
   726 							   CRfcommSAP::TErrorTypes /*aType*/)
   707 							   CRfcommSAP::TErrorTypes /*aType*/)
   727 	/**
   708 	/**
   748 		SignalError(aSAP, KErrRfcommBadAddress, MSocketNotify::EErrorConnect);
   729 		SignalError(aSAP, KErrRfcommBadAddress, MSocketNotify::EErrorConnect);
   749 		return;
   730 		return;
   750 		}
   731 		}
   751 
   732 
   752 	aSAP.RegisterCodService();	// See if there is a Service set for CodMan
   733 	aSAP.RegisterCodService();	// See if there is a Service set for CodMan
   753 	
   734 		
   754 	// Override LPM while we do some sigalling to ensure it can complete in 
       
   755 	// a timely fashion.
       
   756 	aSAP.iProtocol.ControlPlane().ModifyPhysicalLink(EOverrideLPM, aSAP.iRemoteDev);
       
   757 
       
   758 	// First get a Mux.
   735 	// First get a Mux.
   759 	ChangeState(aSAP, CRfcommStateFactory::EWaitForMux);
   736 	ChangeState(aSAP, CRfcommStateFactory::EWaitForMux);
   760 	}
   737 	}
   761 
   738 
   762 TInt TRfcommStateClosed::PassiveOpen(CRfcommSAP& aSAP, 
   739 TInt TRfcommStateClosed::PassiveOpen(CRfcommSAP& aSAP, 
  1334 		newSAP->iDLCI=aDLCI;
  1311 		newSAP->iDLCI=aDLCI;
  1335 		newSAP->iServerChannel=aMux.MakeServerChannel(aDLCI);
  1312 		newSAP->iServerChannel=aMux.MakeServerChannel(aDLCI);
  1336 		newSAP->iRemoteDev=aMux.RemoteBTAddr();
  1313 		newSAP->iRemoteDev=aMux.RemoteBTAddr();
  1337 		//  Must come after registering the remote address with the new SAP because we will need 
  1314 		//  Must come after registering the remote address with the new SAP because we will need 
  1338 		//  the remote address  to find a link in LinkMgrProtocol to override LPM on
  1315 		//  the remote address  to find a link in LinkMgrProtocol to override LPM on
  1339 		newSAP->iProtocol.ControlPlane().ModifyPhysicalLink(EOverrideLPM, newSAP->iRemoteDev);
  1316 		newSAP->iProtocol.ControlPlane().ModifyPhysicalLink(EOverrideLPMWithTimeout, newSAP->iRemoteDev);
  1340 		newSAP->iUserDefinedMTU=aSAP.iUserDefinedMTU;	//	We take our cues as
  1317 		newSAP->iUserDefinedMTU=aSAP.iUserDefinedMTU;	//	We take our cues as
  1341 														//	regards max MTU from
  1318 														//	regards max MTU from
  1342 														//	the listening SAP.
  1319 														//	the listening SAP.
  1343 		
  1320 		
  1344 		newSAP->iMux=&aMux;
  1321 		newSAP->iMux=&aMux;
  1759 		SignalError(aSAP, err, MSocketNotify::EErrorConnect);
  1736 		SignalError(aSAP, err, MSocketNotify::EErrorConnect);
  1760 		ChangeState(aSAP, CRfcommStateFactory::EClosed);
  1737 		ChangeState(aSAP, CRfcommStateFactory::EClosed);
  1761 		return;
  1738 		return;
  1762 		}
  1739 		}
  1763 	
  1740 	
  1764 	// Depending where we came from we may have applied either a
       
  1765 	// park override or an all LPM override.  We remove both these
       
  1766 	// overrides because it's safe to remove an override that 
       
  1767 	// hasn't been applied.
       
  1768 	// Note that although park is one of the LPMs the different
       
  1769 	// levels of override are managed separately, so an
       
  1770 	// UndoOverrideLPM does not remove an explicit park only 
       
  1771 	// override.
       
  1772 	aSAP.iProtocol.ControlPlane().ModifyPhysicalLink(EUndoOverridePark, aSAP.iRemoteDev);
  1741 	aSAP.iProtocol.ControlPlane().ModifyPhysicalLink(EUndoOverridePark, aSAP.iRemoteDev);
  1773 	aSAP.iProtocol.ControlPlane().ModifyPhysicalLink(EUndoOverrideLPM, aSAP.iRemoteDev);
       
  1774 
       
  1775 	aSAP.iSocket->ConnectComplete();
  1742 	aSAP.iSocket->ConnectComplete();
  1776 	aSAP.CTS(EFalse);			//	So that we block should anyone try to write
  1743 	aSAP.CTS(EFalse);			//	So that we block should anyone try to write
  1777 								//	anything through this SAP before we get MSC
  1744 								//	anything through this SAP before we get MSC
  1778 								//	from remote side.
  1745 								//	from remote side.
  1779 	aSAP.iReceivedMSC=EFalse;	//	Until we receive an MSC, we consider any 
  1746 	aSAP.iReceivedMSC=EFalse;	//	Until we receive an MSC, we consider any 
  1810 void TRfcommStateOpen::Shutdown(CRfcommSAP& aSAP)
  1777 void TRfcommStateOpen::Shutdown(CRfcommSAP& aSAP)
  1811 	/**
  1778 	/**
  1812 	   Shutdown the open channel gracefully
  1779 	   Shutdown the open channel gracefully
  1813 	**/
  1780 	**/
  1814 	{
  1781 	{
  1815 	// Only override park for disconnect.  We need to be able
       
  1816 	// to send the signalling, but we don't care if it takes
       
  1817 	// ages.  No point starting a sniff bun-fight.
       
  1818 	aSAP.iProtocol.ControlPlane().ModifyPhysicalLink(EOverridePark, aSAP.iRemoteDev);
  1782 	aSAP.iProtocol.ControlPlane().ModifyPhysicalLink(EOverridePark, aSAP.iRemoteDev);
  1819 	aSAP.iClosePending=ETrue;
  1783 	aSAP.iClosePending=ETrue;
  1820 	ChangeState(aSAP, CRfcommStateFactory::EDisconnect);
  1784 	ChangeState(aSAP, CRfcommStateFactory::EDisconnect);
  1821 	}
  1785 	}
  1822 
  1786 
  1830 	{
  1794 	{
  1831 	//	Send a DISC using the DLCI based overload which ensures that
  1795 	//	Send a DISC using the DLCI based overload which ensures that
  1832 	//	the queued DISC frame does not get deleted when the SAP gets 
  1796 	//	the queued DISC frame does not get deleted when the SAP gets 
  1833 	//	removed from the muxer
  1797 	//	removed from the muxer
  1834 	__ASSERT_DEBUG(aSAP.iMux!=NULL,PanicInState(ERfcommNullMux));
  1798 	__ASSERT_DEBUG(aSAP.iMux!=NULL,PanicInState(ERfcommNullMux));
  1835 	
       
  1836 	// Only override park for disconnect.  We need to be able
       
  1837 	// to send the signalling, but we don't care if it takes
       
  1838 	// ages.  No point starting a sniff bun-fight.
       
  1839 	aSAP.iProtocol.ControlPlane().ModifyPhysicalLink(EOverridePark, aSAP.iRemoteDev);
  1799 	aSAP.iProtocol.ControlPlane().ModifyPhysicalLink(EOverridePark, aSAP.iRemoteDev);
  1840 	aSAP.iMux->SendDISC(aSAP.DLCI());  // Disassociated from the SAP
  1800 	aSAP.iMux->SendDISC(aSAP.DLCI());  // Disassociated from the SAP
  1841 	ChangeState(aSAP, CRfcommStateFactory::EClosed);
  1801 	ChangeState(aSAP, CRfcommStateFactory::EClosed);
  1842 	}
  1802 	}
  1843 
  1803