cbsref/csyrefplugins/csy27010/src/ChannelMgrCtrl.cpp
changeset 49 f50f4094acd7
equal deleted inserted replaced
48:14460bf2a402 49:f50f4094acd7
       
     1 //
       
     2 // * Copyright 2004 Neusoft America Inc.
       
     3 // * All rights reserved.
       
     4 // * This component and the accompanying materials are made available
       
     5 // * under the terms of the Eclipse Public License v1.0
       
     6 // * which accompanies this distribution, and is available
       
     7 // * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // *
       
     9 // * Contributors:
       
    10 // * Keith Collins (Neusoft America Inc.)  original software development and additional code and modifications.
       
    11 // * Thomas Gahagen (Neusoft America Inc.)  additional code and modifications.
       
    12 // * Zhen Yuan (Neusoft America Inc.)  additional code and modifications.
       
    13 // *
       
    14 // * Description:  The file contains the implementation for class CChannelMgrCtrl.
       
    15 // *               Class CChannelMgrCtrl implements a 3GPP 27.010 control channel (DLC).
       
    16 // *               A control channel is used to initialize the multiplexer and to
       
    17 // *               create/monitor DLC's.
       
    18 //
       
    19 
       
    20 // ChannelMgrCtrl.cpp
       
    21 
       
    22 /** @file ChannelMgrCtrl.cpp
       
    23  *
       
    24  * The file contains the implementation for class CChannelMgrCtrl.
       
    25  * Class CChannelMgrCtrl implements a 3GPP 27.010 control channel (DLC).
       
    26  * A control channel is used to initialize the multiplexer and to
       
    27  * create/monitor DLC's.
       
    28  */
       
    29 
       
    30 #include "ChannelMgrCtrl.h"
       
    31 #include "Portfactory.h"
       
    32 #include "Mux0710Protocol.h"
       
    33 #include "CsyMsgBufBPFrame.h"
       
    34 #include "CommFrameWriterAo.h"
       
    35 #include "CsyDebugLogger.h"
       
    36 #include "ChannelMgrBase.h"
       
    37 #include "PortC32InterfaceBase.h"
       
    38 #include "PortC32Interface.h"
       
    39 #include "ChannelMgrCmdData.h"
       
    40 #include "CsyGlobals.h"
       
    41 #include "d32comm.h"
       
    42 
       
    43 CChannelMgrCtrl* CChannelMgrCtrl::NewL(CPortFactory& aPortFactory,
       
    44 									   CMux0710Protocol& aMux0710Protocol)
       
    45 /**
       
    46  * This methods uses two phase construction and the cleanup stack to create
       
    47  * an instance of class CChannelMgrCtrl.
       
    48  *
       
    49  * @param aPortFactory - Refrence to the port factory
       
    50  * @param aMux0710Protocol - Reference to the Mux 27.010 object
       
    51  * @return Pointer to the created instance
       
    52  */
       
    53     {
       
    54 	_LOG_L4C1("CChannelMgrCtrl::NewL");
       
    55 
       
    56     CChannelMgrCtrl* p = new(ELeave) CChannelMgrCtrl(aPortFactory, aMux0710Protocol);
       
    57  	CleanupStack::PushL(p);
       
    58  	p->ConstructL();
       
    59 	CleanupStack::Pop(p);
       
    60  	return p;
       
    61 	}
       
    62 
       
    63 CChannelMgrCtrl::~CChannelMgrCtrl()
       
    64 /**
       
    65  * Destructor. Delete all resources and memory allocated by this object.
       
    66  */
       
    67 	{
       
    68 	_LOG_L4C1("CChannelMgrCtrl::~CChannelMgrCtrl");
       
    69 
       
    70 	// Disconnect the DLC Control Channel 
       
    71 	Disconnect();
       
    72 	}
       
    73 
       
    74 CChannelMgrCtrl::CChannelMgrCtrl(CPortFactory& aPortFactory,
       
    75 								 CMux0710Protocol& aMux0710Protocol)
       
    76 : CChannelMgrBase(KCtrlChannelDlcNum, aPortFactory, aMux0710Protocol)
       
    77 /**
       
    78  * Constructor.
       
    79  *
       
    80  * @param aPortFactory - Reference to the port factory
       
    81  * @param aMux0710Protocol - Reference to the 27.010 mux protocol
       
    82  */
       
    83  	{
       
    84 	}
       
    85 
       
    86 void CChannelMgrCtrl::ConstructL()
       
    87 /**
       
    88  * This method initializes the memory and data used by this object.
       
    89  */
       
    90 	{
       
    91 	_LOG_L4C1("CChannelMgrCtrl::ConstructL");
       
    92 	CChannelMgrBase::ConstructL();
       
    93 	}
       
    94 
       
    95 void CChannelMgrCtrl::ProcessRecvUihFrame(CCsyMsgBufBpFrame* aBpFrame)
       
    96 /**
       
    97  * This method is called to process a UIH frame that was received
       
    98  * on the control channel.  Based on the message type and contents
       
    99  * the channel state machine is updated and a response is issued back
       
   100  * to the baseband.
       
   101  *
       
   102  * @param aBpFrame - Pointer to the frame buffer
       
   103  */
       
   104 	{
       
   105 	_LOG_L4C2(">>CChannelMgrCtrl::ProcessRecvUihFrame [aBpFrame=0x%x]",
       
   106 		aBpFrame);
       
   107 
       
   108 	// adv option:   address | control | Type   | LengthData | Value(s)
       
   109 	// basic option: address | control | length | Type  | LengthData | Value(s)
       
   110 
       
   111 	TUint8 ctrlTypeField;
       
   112 
       
   113 #ifdef _27010ADVANCEOPTION
       
   114 	ctrlTypeField = KAdvOptionCtrlStart;   // 2
       
   115 #else
       
   116 	ctrlTypeField = KBasicOptionCtrlStart; // 3
       
   117 #endif
       
   118 
       
   119 	TUint8 frameLength = (TUint8) aBpFrame->iMsg.Length();
       
   120 	if (frameLength <= ctrlTypeField)
       
   121 		{
       
   122 		_LOG_L1C3("** Frame length %d <= minimum ctrl frame length %d **",
       
   123 			frameLength,ctrlTypeField);
       
   124 		_LOG_L4C1("<<CChannelMgrCtrl::ProcessRecvUihFrame - bad frame");
       
   125 		return;
       
   126 		}
       
   127 
       
   128 	TBool confirmBack = ETrue;
       
   129 	switch (aBpFrame->iMsg[ctrlTypeField])
       
   130 		{
       
   131 	case KCsy0710CTLUIH_DlcParamNegotiate:
       
   132 		_LOG_L4C1( "DlcParamNegotiate");
       
   133 		break;
       
   134 	case KCsy0710CTLUIH_DlcParamNegotiateRsp:
       
   135 		{
       
   136 		_LOG_L3C1("DlcParamNegotiate response");
       
   137 		confirmBack = EFalse; // No response to send back
       
   138 
       
   139 		// The position of the values field in the ctrl data
       
   140 		TUint8 firstValueFieldIndex  =
       
   141 			(TUint8) (ctrlTypeField + KPositionOfValueFieldInCtrlData);
       
   142 
       
   143 		if (frameLength > firstValueFieldIndex)
       
   144 			{
       
   145 			const TAny* msgValue =
       
   146 				reinterpret_cast<const TAny*> (&(aBpFrame->iMsg.Ptr()[firstValueFieldIndex]));
       
   147 
       
   148 			typedef struct TPnMsgValue
       
   149 				{
       
   150 				TUint8 iDlci:6;
       
   151 				TUint8 iRes1:2;
       
   152 				TUint8 iFrameType:4;
       
   153 				TUint8 iCreditFlow:4;
       
   154 				TUint8 iPrior:6;
       
   155 				TUint8 iRes2:2;
       
   156 				TUint8 iAckTimer;
       
   157 				TUint16 iFrameSize;
       
   158 				TUint8 iMaxNbrofRetrans;
       
   159 				TUint8 iCredits;
       
   160 				} TPnMsgValue;
       
   161 
       
   162 			const TPnMsgValue* pnMsgValue =
       
   163 				reinterpret_cast<const TPnMsgValue*> (msgValue);
       
   164 
       
   165 			// now we should be able to use pnMsgValue.iDlci, etc
       
   166 			if ((pnMsgValue->iDlci            == iMux0710Protocol.PreviousNegotiateDlcNum())  &&
       
   167 				(pnMsgValue->iFrameType       == KPNFrameType)          &&
       
   168 				(pnMsgValue->iCreditFlow      == KPNClBits)             &&
       
   169 				(pnMsgValue->iPrior           == KPNDlcPriority)        &&
       
   170 				(pnMsgValue->iAckTimer        == KPNAckTimer)           &&
       
   171 				(pnMsgValue->iFrameSize       == KPNMaxFrameSize)       &&
       
   172 				(pnMsgValue->iMaxNbrofRetrans == KPNMaxRetransmissions) &&
       
   173 				(pnMsgValue->iCredits         == KPNWindowSize))
       
   174 				{
       
   175 				_LOG_L3C1("ParamNegotiate passed");
       
   176 
       
   177 				TUint8 dlcNum = pnMsgValue->iDlci;
       
   178 				iPortFactory.ConnectIpNifPort(dlcNum);
       
   179 				}
       
   180 			else
       
   181 				{
       
   182 				// MAF If this fails try again or forget trying PN.
       
   183 				_LOG_L3C1("ParamNegotiate Failed");
       
   184 				}
       
   185 			}
       
   186 		else
       
   187 			{
       
   188 			_LOG_L1C3("** Frame length %d <= first ctrl value %d **",
       
   189 				frameLength,firstValueFieldIndex);
       
   190 			}
       
   191 		}
       
   192 		break;
       
   193 	case KCsy0710CTLUIH_PowerSaveCtl:
       
   194 		_LOG_L3C1("PowerSaveCtrl");
       
   195 		break;
       
   196 	case KCsy0710CTLUIH_MultCloseDown:
       
   197 		_LOG_L3C1("MultCloseDown");
       
   198 		break;
       
   199 	case KCsy0710CTLUIH_TestCmd:
       
   200 		_LOG_L3C1("TestCmd");
       
   201 		break;
       
   202 	case KCsy0710CTLUIH_FlowControlOn:
       
   203 		_LOG_L3C1("FlowControlOn");
       
   204 		break;
       
   205 	case KCsy0710CTLUIH_FlowControlOff:
       
   206 		_LOG_L3C1("FlowControlOff");
       
   207 		break;
       
   208 	case KCsy0710CTLUIH_ModemStatusRsp:
       
   209 		{
       
   210 		_LOG_L3C1("MSC response");
       
   211 		confirmBack = EFalse; // No response to send back
       
   212 
       
   213 		// From 27.010
       
   214 		// RTC	DTR	108/2	DSR	107
       
   215 		// RTR	RFR (note)	133	CTS	106
       
   216 		// IC	always 0-	-	RI	125
       
   217 		// DV	always 1-	-	DCD	109
       
   218 		// NOTE	Circuit 133, RFR (Ready for Receiving) is commonly assigned to the connector pin that is alternatively used for circuit 105, RTS. It is sometimes referred to by that name.
       
   219 
       
   220 		// The position of the values field in the ctrl data
       
   221 		TUint8 firstValueFieldIndex  =
       
   222 			(TUint8) (ctrlTypeField + KPositionOfValueFieldInCtrlData);
       
   223 		TUint8 secondValueIndex = (TUint8) (firstValueFieldIndex + 1);
       
   224 
       
   225 		if (frameLength > secondValueIndex)
       
   226 			{
       
   227 			TUint8 dlcNum = (TUint8) (((TUint8) aBpFrame->iMsg[firstValueFieldIndex]) >> 2); // remove EA and CR
       
   228 			_LOG_L4C2("dlcNum=%d", dlcNum);
       
   229 
       
   230 			TUint8 v24signals = (TUint8) aBpFrame->iMsg[secondValueIndex];
       
   231 			_LOG_L4C2("V24 Signals=0x%x", v24signals);
       
   232 
       
   233 			if (dlcNum)
       
   234 				{
       
   235 				_LOG_L3C1("For a data DLC");
       
   236 				CChannelMgrCmdData* channel = iPortFactory.FindChannelMgrByDlcNum(dlcNum);
       
   237 				channel->MscReceived(v24signals);
       
   238 				}
       
   239 			else
       
   240 				MscReceived(v24signals);
       
   241 			}
       
   242 		else
       
   243 			{
       
   244 			_LOG_L1C3("** Frame length %d <= second ctrl value %d **",
       
   245 				frameLength,secondValueIndex);
       
   246 			}
       
   247 		}
       
   248 		break;
       
   249 	case KCsy0710CTLUIH_ModemStatusCmd:
       
   250 		{
       
   251 		// The modem side has informed us of its state
       
   252 		_LOG_L3C1("MSC command");
       
   253 
       
   254 		// The position of the values field in the ctrl data
       
   255 		TUint8 firstValueFieldIndex  =
       
   256 			(TUint8) (ctrlTypeField + KPositionOfValueFieldInCtrlData);
       
   257 
       
   258 		TUint8 secondValueIndex = (TUint8) (firstValueFieldIndex + 1);
       
   259 
       
   260 		if (frameLength > secondValueIndex)
       
   261 			{
       
   262 			TUint8 dlcNum = (TUint8) (((TUint8) aBpFrame->iMsg[firstValueFieldIndex]) >> 2); // remove EA and CR
       
   263 			_LOG_L4C2("dlcNum=%d", dlcNum);
       
   264 
       
   265 			TUint8 v24signals = (TUint8) aBpFrame->iMsg[secondValueIndex];
       
   266 			_LOG_L4C2("V24 Signals=0x%x", v24signals);
       
   267 
       
   268 			if (dlcNum)
       
   269 				{
       
   270 				_LOG_L3C1( "For a data DLC");
       
   271 				CChannelMgrCmdData* channel = iPortFactory.FindChannelMgrByDlcNum(dlcNum);
       
   272 				channel->ReceivedV24Signals(v24signals);
       
   273 				}
       
   274 			else
       
   275 				{
       
   276 				_LOG_L3C1( "FC & v24 signals ignored for Ctrl Channel");
       
   277 				}
       
   278 			}
       
   279 		else
       
   280 			{
       
   281 			_LOG_L1C3("** Frame length %d <= second ctrl value %d **",
       
   282 				frameLength,secondValueIndex);
       
   283 			confirmBack = EFalse;
       
   284 			}
       
   285 		}
       
   286 		break;
       
   287 	case KCsy0710CTLUIH_NonSupportedCmdResp:
       
   288 		confirmBack = EFalse;
       
   289 		_LOG_L3C1("NonSupportedCmdResp");
       
   290 		break;
       
   291 	case KCsy0710CTLUIH_RemotePortNegotiate:
       
   292 		_LOG_L3C1("RemotePortNegotiate");
       
   293 		break;
       
   294 	case KCsy0710CTLUIH_RemoteLineStatus:
       
   295 		_LOG_L3C1("RemoteLineStatus");
       
   296 		break;
       
   297 	case KCsy0710CTLUIH_ServiceNegotiate:
       
   298 		_LOG_L3C1("ServiceNegotiate");
       
   299 		break;
       
   300 	default:
       
   301 		_LOG_L1C2("** Unknown ctrltype 0x%02x **", aBpFrame->iMsg[ctrlTypeField]);
       
   302 		break;
       
   303 		}
       
   304 
       
   305 	if (confirmBack)
       
   306 		{
       
   307 		_LOG_L3C1( "Send a response ...");
       
   308 		ConfirmCtrlFrame(aBpFrame);
       
   309 		// MAF what if send of response fails
       
   310 		}
       
   311 	else
       
   312 		{
       
   313 		iMux0710Protocol.AddFrameFreeQ(aBpFrame);
       
   314 		}
       
   315 
       
   316 	_LOG_L4C1("<<CChannelMgrCtrl::ProcessRecvUihFrame");
       
   317 	}
       
   318 
       
   319 void CChannelMgrCtrl::ConfirmCtrlFrame(CCsyMsgBufBpFrame* aBpFrame)
       
   320 /**
       
   321  * This method initializes the control channel.
       
   322  * @param a pointer to the Frame
       
   323  */
       
   324 	{
       
   325 	_LOG_L4C2(">>CChannelMgrCtrl::ConfirmCtrlFrame [aBpFrame=0x%x]",
       
   326 		aBpFrame);
       
   327 
       
   328 	// echo the UIH frame back to the BP, except clear the C/R bit (bit 1)
       
   329     // the checksum is unchanged
       
   330 	// we must also insert a start flag and end flag
       
   331 	TBuf8<4> flag;
       
   332 	flag.SetLength(1);
       
   333 	flag[0] = KCsy0710StartEndFlag;
       
   334 	aBpFrame->iMsg.Insert(0, flag);
       
   335 	TInt length = aBpFrame->iMsg.Length();
       
   336 	aBpFrame->iMsg.SetLength(length + 1);
       
   337 	aBpFrame->iMsg[length] = KCsy0710StartEndFlag;
       
   338 
       
   339 	// clear the C/R bit in the msg type field, not the frame type field
       
   340 #ifdef _27010ADVANCEOPTION
       
   341 	aBpFrame->iMsg[3] &= ~KCsy0710CRBit;
       
   342 #else
       
   343 	aBpFrame->iMsg[4] &= ~KCsy0710CRBit;
       
   344 #endif
       
   345 
       
   346 	// put the frame at the front of the baseband's queue
       
   347 	aBpFrame->CompleteWhenSent() = ETrue;
       
   348 	TInt ret = iPortFactory.GetCommWriterAo()->Write(aBpFrame, ETrue);
       
   349 	if (ret)
       
   350 		{
       
   351 		// MAF what to do here
       
   352 		_LOG_L1C2("** Failed to send response [ret=%d] **",ret);
       
   353 		}
       
   354 
       
   355 	_LOG_L4C1("<<CChannelMgrCtrl::ConfirmCtrlFrame");
       
   356 	}