bluetooth/btstack/rfcomm/rfcommmuxer.cpp
branchRCL_3
changeset 49 10183c6d2913
parent 23 32ba20339036
equal deleted inserted replaced
45:99439b07e980 49:10183c6d2913
  2345 
  2345 
  2346 	   @return Error code
  2346 	   @return Error code
  2347 	**/
  2347 	**/
  2348 	{
  2348 	{
  2349 	LOG1(_L("RFCOMM: Sending SABM for DLCI %d"), aDLCI); 
  2349 	LOG1(_L("RFCOMM: Sending SABM for DLCI %d"), aDLCI); 
       
  2350 	// We always expect a response for a SABM, so this frame should
       
  2351 	// be associated with a SAP or be sent by the mux channel.
       
  2352 	__ASSERT_DEBUG(aSAP || (aDLCI == KMuxDLCI), Panic(ERfCommNothingToHandleResponse));
       
  2353 	
  2350 	CRfcommCtrlFrame* frm=NewFrame(aSAP);
  2354 	CRfcommCtrlFrame* frm=NewFrame(aSAP);
  2351 	
  2355 	
  2352 	if(!frm)
  2356 	if(!frm)
  2353 		return KErrNoMemory;
  2357 		return KErrNoMemory;
  2354 
  2358 
  2399 	}
  2403 	}
  2400 
  2404 
  2401 TInt CRfcommMuxer::TransmitDISC(TUint8 aDLCI, CRfcommSAP* aSAP)
  2405 TInt CRfcommMuxer::TransmitDISC(TUint8 aDLCI, CRfcommSAP* aSAP)
  2402 	{
  2406 	{
  2403 	LOG1(_L("RFCOMM: Sending DISC for DLCI %d"), aDLCI); 
  2407 	LOG1(_L("RFCOMM: Sending DISC for DLCI %d"), aDLCI); 
       
  2408 	// In setting the response needed flag we assume that only SAPs 
       
  2409 	// will send a DISC, not the mux channel.  If this changes in the 
       
  2410 	// future then the condition on setting the response needed flag 
       
  2411 	// needs reconsidering to deal with this.
       
  2412 	__ASSERT_DEBUG(aDLCI != KMuxDLCI, Panic(ERfCommDiscSentOnMuxDlci));
       
  2413 
  2404 	CRfcommCtrlFrame* frm=NewFrame(aSAP);
  2414 	CRfcommCtrlFrame* frm=NewFrame(aSAP);
  2405 	if(!frm)
  2415 	if(!frm)
  2406 		return KErrNoMemory;
  2416 		return KErrNoMemory;
  2407 
  2417 
       
  2418 	// We only wait for a response for a DISC if there's going to 
       
  2419 	// be something still around to receive it, otherwise we'll just 
       
  2420 	// ignore the response when it comes in.
       
  2421 	frm->SetResponseNeeded(aSAP ? ETrue : EFalse);
       
  2422 	
  2408 	// DISC always has Final set
  2423 	// DISC always has Final set
  2409 	frm->SetResponseNeeded(ETrue);
       
  2410 	frm->SetControl(KDISCCtrlField | KPollFinalBitmask);
  2424 	frm->SetControl(KDISCCtrlField | KPollFinalBitmask);
  2411 	frm->SetAddress(BuildAddr(aDLCI, ETrue));  // C/R set
  2425 	frm->SetAddress(BuildAddr(aDLCI, ETrue));  // C/R set
  2412 	EnqueFrame(frm);
  2426 	EnqueFrame(frm);
  2413 	return KErrNone;
  2427 	return KErrNone;
  2414 	}
  2428 	}
  2448 	{
  2462 	{
  2449 	CRfcommMuxCtrlFrame* frm = 0;
  2463 	CRfcommMuxCtrlFrame* frm = 0;
  2450 	
  2464 	
  2451 	__ASSERT_DEBUG(aLen == KRPNCommandLength || aLen == KRPNRequestLength || 
  2465 	__ASSERT_DEBUG(aLen == KRPNCommandLength || aLen == KRPNRequestLength || 
  2452 				   aLen == KRPNResponseLength,	Panic(ERfcommInvalidRPNLength));
  2466 				   aLen == KRPNResponseLength,	Panic(ERfcommInvalidRPNLength));
       
  2467 	// We never expect an RPN on the mux channel
       
  2468 	__ASSERT_DEBUG(aDLCI != KMuxDLCI, Panic(ERfCommUnexpectedCommandOnMuxChannel));
       
  2469 	
       
  2470 	// We always expect a response for an RPN command frame, so this frame should
       
  2471 	// be associated with a SAP.
       
  2472 	__ASSERT_DEBUG(!aCommand || aSAP, Panic(ERfCommNothingToHandleResponse));
       
  2473 
  2453 	LOG(_L("RFCOMM: Creating RPN frame"));
  2474 	LOG(_L("RFCOMM: Creating RPN frame"));
  2454 	frm=NewSignalFrame(aLen, aCommand, aSAP);
  2475 	frm=NewSignalFrame(aLen, aCommand, aSAP);
  2455 	if(!frm)
  2476 	if(!frm)
  2456 		return KErrNoMemory;
  2477 		return KErrNoMemory;
  2457 	
  2478 	
  2677 	  @endverbatim
  2698 	  @endverbatim
  2678 	 **/
  2699 	 **/
  2679 	{
  2700 	{
  2680 	LOG3(_L("RFCOMM: Sending PN %S for dlci %d (MTU=%d)"), 
  2701 	LOG3(_L("RFCOMM: Sending PN %S for dlci %d (MTU=%d)"), 
  2681 		(aCommand?&KCommandText:&KResponseText) , aDLCI, aParams.iMaxFrameSize);
  2702 		(aCommand?&KCommandText:&KResponseText) , aDLCI, aParams.iMaxFrameSize);
       
  2703 	// We never expect to send a PN on the mux channel, however to aid interop 
       
  2704 	// with shoddy remotes we tolerate responding to one
       
  2705 	__ASSERT_DEBUG(((aDLCI != KMuxDLCI) || !aCommand), Panic(ERfCommUnexpectedCommandOnMuxChannel));
       
  2706 	
       
  2707 	// We always expect a response for a PN command frame, so this frame should
       
  2708 	// be associated with a SAP.
       
  2709 	__ASSERT_DEBUG(!aCommand || aSAP, Panic(ERfCommNothingToHandleResponse));
       
  2710 
  2682 	CRfcommMuxCtrlFrame* frm=NewSignalFrame(KRPNCommandLength, aCommand, aSAP);
  2711 	CRfcommMuxCtrlFrame* frm=NewSignalFrame(KRPNCommandLength, aCommand, aSAP);
  2683 
  2712 
  2684 	if(!frm)
  2713 	if(!frm)
  2685 		return KErrNoMemory;
  2714 		return KErrNoMemory;
  2686 
  2715 
  2799 	**/
  2828 	**/
  2800 	{
  2829 	{
  2801 	LOG3(_L("RFCOMM: SendMSC %S DLCI %d, Signals %x"),
  2830 	LOG3(_L("RFCOMM: SendMSC %S DLCI %d, Signals %x"),
  2802 		(aCommand?&KCommandText:&KResponseText), aDLCI, aSignals);
  2831 		(aCommand?&KCommandText:&KResponseText), aDLCI, aSignals);
  2803 	
  2832 	
       
  2833 	// We never expect an MSC on the mux channel
       
  2834 	__ASSERT_DEBUG(aDLCI != KMuxDLCI, Panic(ERfCommUnexpectedCommandOnMuxChannel));
       
  2835 	
       
  2836 	// We always expect a response for an MSC command frame, so this frame should
       
  2837 	// be associated with a SAP.
       
  2838 	__ASSERT_DEBUG(!aCommand || aSAP, Panic(ERfCommNothingToHandleResponse));
       
  2839 	
  2804 	CRfcommMuxCtrlFrame* frm=NewSignalFrame(KMSCCommandLength, aCommand, aSAP);
  2840 	CRfcommMuxCtrlFrame* frm=NewSignalFrame(KMSCCommandLength, aCommand, aSAP);
  2805 	if(!frm)
  2841 	if(!frm)
  2806 		return KErrNoMemory;
  2842 		return KErrNoMemory;
  2807 
  2843 
  2808 	frm->SetDLCI(aDLCI);	//	For use when matching DM responses to mux control command frames
  2844 	frm->SetDLCI(aDLCI);	//	For use when matching DM responses to mux control command frames
  2842 							   CRfcommSAP* aSAP)
  2878 							   CRfcommSAP* aSAP)
  2843 	/**
  2879 	/**
  2844 	   Send out a RLS signalling command
  2880 	   Send out a RLS signalling command
  2845 	**/
  2881 	**/
  2846 	{
  2882 	{
       
  2883 	// We never expect an RLS on the mux channel
       
  2884 	__ASSERT_DEBUG(aDLCI != KMuxDLCI, Panic(ERfCommUnexpectedCommandOnMuxChannel));
       
  2885 	
       
  2886 	// We always expect a response for an RLS command frame, so this frame should
       
  2887 	// be associated with a SAP.
       
  2888 	__ASSERT_DEBUG(!aCommand || aSAP, Panic(ERfCommNothingToHandleResponse));
       
  2889 	
  2847 	CRfcommMuxCtrlFrame* frm=NewSignalFrame(KRLSCommandLength, aCommand, aSAP);
  2890 	CRfcommMuxCtrlFrame* frm=NewSignalFrame(KRLSCommandLength, aCommand, aSAP);
  2848 	if(!frm)
  2891 	if(!frm)
  2849 		return KErrNoMemory;
  2892 		return KErrNoMemory;
  2850 
  2893 
  2851 	frm->SetDLCI(aDLCI);	//	For use when matching DM responses to mux control command frames
  2894 	frm->SetDLCI(aDLCI);	//	For use when matching DM responses to mux control command frames