irda/irdastack/irtranp/SCEP.CPP
branchRCL_3
changeset 11 20fda83a6398
parent 0 29b1cd4cb562
equal deleted inserted replaced
10:8a27654f7b62 11:20fda83a6398
   107 	//iSCEPFrame.SetLength(0);
   107 	//iSCEPFrame.SetLength(0);
   108 	iComReadWrite->Open();
   108 	iComReadWrite->Open();
   109 	return 0;
   109 	return 0;
   110 	}
   110 	}
   111 
   111 
   112 void SCEP::ReceiveComplete(TDesC8& aBuffer)
   112 void SCEP::ReceiveComplete(TDesC8& /*aBuffer*/)
   113 	{
   113 /** No Longer used.
   114 	SCEPPRINT_2(_L("SCEP::ReceiveComplete(%d)\n"),aBuffer.Length());
   114 
   115 
   115 irda client libraries left in to avoid breaks */
   116 	iSCEPFrame.Append(aBuffer); // Add new data to cached packet
   116 	{
   117 
       
   118 	TBool loopagain;
       
   119 	do
       
   120 		{
       
   121 		loopagain = EFalse;
       
   122 		
       
   123 		if ((iSCEPFrame[0]==0x00)&&(iSCEPFrame.Length()>=3))
       
   124 			{
       
   125 			TInt tempLength = 0;
       
   126 			TInt additionalLength = 0;
       
   127 			TInt lengthPos = 3;
       
   128 
       
   129 			if ((iSCEPFrame[1]==KTranpMsgTypeCER) && (iSCEPFrame[2]==KTranpInfTypeVer))
       
   130 				{
       
   131 				lengthPos = 5;
       
   132 				additionalLength = 4; // ... and that same packet has 4 trailing bytes
       
   133 				}
       
   134 				
       
   135 			if (iSCEPFrame.Length()>lengthPos+2)// Otherwise we might miss out on the last packet
       
   136 				{
       
   137 				if(iSCEPFrame[0] == 0x00) // Let's guess it's an SCEP header - HARDCODED AND UGLY!!!
       
   138 					{
       
   139 					tempLength = iSCEPFrame[lengthPos];
       
   140 					if(tempLength == 0xff)
       
   141 						{
       
   142 						tempLength = IrTranpUtil::DExtract(iSCEPFrame, lengthPos+1);
       
   143 						lengthPos = 5;
       
   144 						}
       
   145 					SCEPPRINT_2(_L("tempLength = %d"), tempLength);
       
   146 					}
       
   147 
       
   148 				tempLength += ((lengthPos+1) + additionalLength);
       
   149 				
       
   150 				SCEPPRINT_3(_L("iSCEPFrame.length(%d) >= templength(%d)"),iSCEPFrame.Length(),tempLength);
       
   151 
       
   152 					switch (iSCEPFrame[1])
       
   153 					{
       
   154 				case KTranpMsgTypeCER: // MsgType = Connection establishment request
       
   155 				case KTranpMsgTypeCEC: // MsgType = Connection establishment confirmation
       
   156 				case KTranpMsgTypeData: // Data (Command)
       
   157 				case KTranpMsgTypeDisc: // Disconnection
       
   158 					{
       
   159 					switch (iSCEPFrame[2])
       
   160 						{
       
   161 					case KTranpInfTypeVer: // Version of MsgType
       
   162 					case KTranpInfTypeNeg: // Negotiation Information
       
   163 					case KTranpInfTypeUser: // UserData
       
   164 					case KTranpInfTypeExt: // Extend in the future
       
   165 					case KTranpInfTypeRsn: // Reason
       
   166 						break;
       
   167 					default:
       
   168 						// bogus frame
       
   169 						SCEPPRINT(_L("SCEP::Bogus Inf Type in frame\n"));
       
   170 						iSCEPFrame.SetLength(0);
       
   171 						}
       
   172 					}
       
   173 					break;
       
   174 				default:
       
   175 					// bogus frame
       
   176 					SCEPPRINT(_L("SCEP::Bogus Msg Type in frame\n"));
       
   177 					iSCEPFrame.SetLength(0);
       
   178 					}
       
   179 
       
   180 				if(iSCEPFrame.Length() >= tempLength) // yes, complete packet
       
   181 					{
       
   182 					TInt oldLength = iSCEPFrame.Length();
       
   183 					iSCEPFrame.SetLength(tempLength); // We only want exactly one packet
       
   184 					ParseCommand(iSCEPFrame);
       
   185 					
       
   186 					iSCEPFrame.SetLength(oldLength);
       
   187 					iSCEPFrame.Delete(0, tempLength); // The surplus data belongs to the next packet
       
   188 					SCEPPRINT(_L("\r\n***\r\n"));
       
   189 					//IrTranpUtil::HexOut(iSCEPFrame);
       
   190 					SCEPPRINT(_L("***\r\n"));
       
   191 					loopagain = (oldLength > tempLength) ? ETrue : EFalse;
       
   192 					}		
       
   193 				}	
       
   194 			}
       
   195 		else
       
   196 			{
       
   197 			SCEPPRINT(_L("SCEP:: Bogus Frame header\n"));
       
   198 			iSCEPFrame.SetLength(0);
       
   199 			}
       
   200 		} while (loopagain);
       
   201 
       
   202 
       
   203 	// let the commandprocessor send whatever's in queue
       
   204 	
       
   205 	m_oCommandP->DoCommand();
       
   206 
       
   207 	if ( (!(iComReadWrite->IsActive())) && !(iState == EError) ) //Make sure that thre is always an outstanding request
       
   208 		iComReadWrite->Receive(); 
       
   209 
       
   210 	switch(iState)
       
   211 		{
       
   212 	case EConnected:
       
   213 		iNotifier->Connected();
       
   214 		iState = EProgress;
       
   215 		SCEPPRINT(_L("SCEP: EConnected -> EProgress\r\n"));
       
   216 		break;
       
   217 	case EDisconnected:
       
   218 		iNotifier->Disconnected();
       
   219 		iComReadWrite->Close();
       
   220 		iState = EWaiting;
       
   221 		SCEPPRINT(_L("SCEP: EDisconnected -> EWaiting\r\n"));
       
   222 		break;
       
   223 	case EProgress:
       
   224 		{
       
   225 		SCEPPRINT(_L("SCEP: EProgress\r\n"));
       
   226 
       
   227 		TInt32 progress = 0;
       
   228 		if(m_packet!=NULL)
       
   229 			{
       
   230 			if(m_packet->Length() != 0)
       
   231 				{
       
   232 				Math::Int(progress, m_packet->Length()*100 / m_iPicSize);
       
   233 				}
       
   234 			iNotifier->ProgressIndication(progress);
       
   235 			}
       
   236 		}
       
   237 		break;
       
   238 	case EWaiting:
       
   239 		SCEPPRINT(_L("SCEP: EWaiting\r\n"));
       
   240 		break;
       
   241 	case EError:
       
   242 		SCEPPRINT(_L("SCEP: EError\r\n"));
       
   243 		break;
       
   244 	case ECommunicationInt:
       
   245 		SCEPPRINT(_L("SCEP: ECommunicationInt\r\n"));
       
   246 		iNotifier->Disconnected();
       
   247 		iComReadWrite->Close();
       
   248 		iState = EWaiting;
       
   249 		break;
       
   250 	default:
       
   251 		SCEPPRINT(_L("SCEP: Unknown state\r\n"));
       
   252 		break;
       
   253 		}
       
   254 	SCEPPRINT(_L("SCEP: Exit ReceiveComplete\r\n"));
       
   255 	}
   117 	}
   256 
   118 
   257 void SCEP::SendComplete()
   119 void SCEP::SendComplete()
   258 	{
   120 	{
   259 	// Post Read Request
   121 	// Post Read Request
   317 /*
   179 /*
   318 * Method description:	Called from BFTP when a common BFTP packet should be sent
   180 * Method description:	Called from BFTP when a common BFTP packet should be sent
   319 *
   181 *
   320 */
   182 */
   321 
   183 
   322 void SCEP::SCEPSendCommand(TDes8& a_userData, TUint8 a_pduType)
   184 void SCEP::SCEPSendCommand(TDes8& /*a_userData*/, TUint8 /*a_pduType*/)
   323 	{
   185 /** No Longer used.
   324 	SRPSCommand* command = new (ELeave) SRPSCommand(iComReadWrite);
   186 
   325 	command->SetPMID(m_PMID.Des());
   187 irda client libraries left in to avoid breaks */
   326 	command->SetSMID(m_SMID.Des());
   188 	{
   327 	command->SetDPID(m_DPID);
       
   328 	command->SetSPID(m_SPID);
       
   329 	command->SetCmdId(m_CmdId);
       
   330 	command->SetPDUType(a_pduType);
       
   331 	command->SetUserData(a_userData);
       
   332 	command->Create();
       
   333 //	IrTranpUtil::HexOut(command->GetData());
       
   334 	m_oCommandP->Add(command);
       
   335 	}
   189 	}
   336 
   190 
   337 /*
   191 /*
   338 * Method description:	Private method called when a Connection Request packet should be parsed
   192 * Method description:	Private method called when a Connection Request packet should be parsed
   339 *
   193 *
   392 *
   246 *
   393 * Parameter:			a_Header - pointer to the packet buffer
   247 * Parameter:			a_Header - pointer to the packet buffer
   394 * Parameter:			offset - where in the packet to start parsing
   248 * Parameter:			offset - where in the packet to start parsing
   395 */
   249 */
   396 
   250 
   397 void SCEP::SCEPDataCommand(TDes8& a_Header, TInt offset)
   251 void SCEP::SCEPDataCommand(TDes8& /*a_Header*/, TInt /*offset*/)
   398 	{
   252 /** No Longer used.
   399 	SCEPPRINT(_L("Inside SCEPDataCommand\n"));
   253 
   400 	
   254 irda client libraries left in to avoid breaks */
   401 	if(a_Header[offset] == KTranpInfTypeUser)
   255 	{
   402 		{
   256 	}
   403 		// Always InfTypeUser when in SCEPDataCommand
       
   404 		TInt packetLength = a_Header[offset+1];
       
   405 		if(packetLength == 0xff)
       
   406 			{
       
   407 			// since length1 was 0xff, look at length2
       
   408 			packetLength = ((a_Header[offset+2] << 8) + (a_Header[offset+3])); // 16bit
       
   409 			offset+=4; // include inftype and length2
       
   410 			}
       
   411 		else
       
   412 			{
       
   413 			offset+=2; // include inftype and length1
       
   414 			}
       
   415 		
       
   416 		// TUint8 InfVer = a_Header[offset];
       
   417 		TUint8 DFLG = a_Header[offset+1];
       
   418 		// TUint16 length3 = IrTranpUtil::DExtract(a_Header, offset+2);
       
   419 		
       
   420 		if(DFLG == KTranpDFLGrcon)
       
   421 			{
       
   422 			// Reject to request connection
       
   423 			SCEPPRINT(_L("Connection rejected\n"));
       
   424 			}
       
   425 		else if(DFLG == KTranpDFLGnseg)
       
   426 			{
       
   427 			// PDU not segmented (single PDU)
       
   428 			DoCommand(a_Header, offset+4);
       
   429 			//					break;
       
   430 			}
       
   431 		else if(DFLG == KTranpDFLGfPDU)
       
   432 			{
       
   433 			// First segmented PDU
       
   434 			// We do all reassembling in SCEP, and then send the complete (big) packet to bFTP
       
   435 			// restno * PDU must be able to hold the complete packet, right?
       
   436 			
       
   437 			// Ownership of this data [m_packet] belongs to the TTranpPicture object
       
   438 			// so must ask the correct object to delete its heap.
       
   439 			// If we were already building a packet, get rid of it
       
   440 			iTranpProtocol->DeleteHeapData();
       
   441 			
       
   442 			TUint32 seqno = IrTranpUtil::LExtract(a_Header, offset+4);
       
   443 			TUint32 restno = IrTranpUtil::LExtract(a_Header, offset+8);
       
   444 			
       
   445 			TUint32 PDUSize;
       
   446 			switch(m_uiMaxPDU)
       
   447 				{
       
   448 				case '1':
       
   449 					{
       
   450 					PDUSize = 512;
       
   451 					break;
       
   452 					}
       
   453 				case '2':
       
   454 					{
       
   455 					PDUSize = 1024;
       
   456 					break;
       
   457 					}
       
   458 				case '3':
       
   459 					{
       
   460 					PDUSize = 2048;
       
   461 					break;
       
   462 					}
       
   463 				case '4':
       
   464 					{
       
   465 					PDUSize = 4096;
       
   466 					break;
       
   467 					}
       
   468 				default:
       
   469 					{
       
   470 					PDUSize = 512;
       
   471 					break;
       
   472 					}
       
   473 				}
       
   474 			
       
   475 			// This should not leave and report an error back...
       
   476 			//__UHEAP_FAILNEXT(1);
       
   477 			TRAPD( err , m_packet = HBufC8::NewL(PDUSize*restno)); // should be enough
       
   478 			if (err != KErrNone)
       
   479 				{
       
   480 				iNotifier->Error(err);
       
   481 				iState = EError;
       
   482 				return;
       
   483 				}
       
   484 			else
       
   485 				iTranpProtocol->SetHeapData(m_packet);
       
   486 			
       
   487 			m_iPicSize = PDUSize*restno;
       
   488 			
       
   489 			SCEPPRINT(_L("ResizeL went well\n"));
       
   490 			
       
   491 			m_seq = seqno;
       
   492 			AddSegment(a_Header, offset+12);
       
   493 			}
       
   494 		else if(DFLG == KTranpDFLGiPDU)
       
   495 			{
       
   496 			// Intermediate segmented PDUs
       
   497 			
       
   498 			TUint32 seqno = IrTranpUtil::LExtract(a_Header, offset+4);
       
   499 			if(seqno == m_seq+1)
       
   500 				{
       
   501 				AddSegment(a_Header, offset+12);
       
   502 				m_seq++;
       
   503 				}
       
   504 			else
       
   505 				{
       
   506 				SCEPPRINT(_L("Error in intermediate PDU\n"));
       
   507 				}
       
   508 			}
       
   509 		else if(DFLG == KTranpDFLGlPDU)
       
   510 			{
       
   511 			// Last segmented PDU
       
   512 			
       
   513 			m_seq++;
       
   514 			TUint32 restno = IrTranpUtil::LExtract(a_Header, offset+8);
       
   515 			if(restno == 1)
       
   516 				{
       
   517 				AddSegment(a_Header, offset+12);
       
   518 				//TPtr8 packetPtr = m_packet->Des();
       
   519 				DoCommand(*m_packet, 0); // Now let's play
       
   520                 iNotifier->ProgressIndication(100); // Makes sure 100% is reached
       
   521 		        iNotifier->GetComplete();
       
   522                 TPtr8 temp2 = m_packet->Des();
       
   523 	            temp2.Zero();
       
   524 				}
       
   525 			else
       
   526 				{
       
   527 				SCEPPRINT(_L("Error in last PDU\n"));
       
   528 				}
       
   529 			}
       
   530 		else if(DFLG == KTranpDFLGcint)
       
   531 			{
       
   532 			SCEPPRINT(_L("Communication interrupted\n"));
       
   533 			iState = ECommunicationInt;
       
   534 			}
       
   535 		else
       
   536 			{
       
   537 			// Ooops.
       
   538 			}
       
   539 		}
       
   540 	else 
       
   541 		{
       
   542 		// oops
       
   543 		}
       
   544 			
       
   545 	SCEPPRINT(_L("Exiting SCEPDataCommand\n"));
       
   546 }
       
   547 
   257 
   548 /*
   258 /*
   549 * Method description:	Adds segmented packets into a complete packet
   259 * Method description:	Adds segmented packets into a complete packet
   550 *
   260 *
   551 * Parameter:			a_Header - pointer to the segment
   261 * Parameter:			a_Header - pointer to the segment
   662 *
   372 *
   663 * Parameter:			a_Header - pointer to the packet
   373 * Parameter:			a_Header - pointer to the packet
   664 * Parameter:			a_offset - where in the packet the command is
   374 * Parameter:			a_offset - where in the packet the command is
   665 */
   375 */
   666 
   376 
   667 void SCEP::DoCommand(const TDesC8& a_Header, TInt a_offset)
   377 void SCEP::DoCommand(const TDesC8& /*a_Header*/, TInt /*a_offset*/)
   668 	{
   378 /** No Longer used.
   669 	SCEPPRINT(_L("SCEP: DoCommand\n"));
   379 
   670 	
   380 irda client libraries left in to avoid breaks */
   671 	if(a_Header[a_offset] != 0x58) // Always 0x58 at the start of a command
   381 	{
   672 		{
       
   673 		SCEPPRINT(_L("SCEP: Command did not start with 0x58\n"));
       
   674 		return;
       
   675 		}
       
   676 	
       
   677 	TUint8 switchVar = (TUint8)(a_Header[a_offset+1] & 0xc0); // we only want the two highest bits for PDU type
       
   678 	if(switchVar == KTranpPduTypeReq)
       
   679 		{
       
   680 		// Don't care about the MachineIDs for now
       
   681 		SCEPPRINT(_L("SCEP: PduTypeReq\n"));
       
   682 
       
   683 		m_SPID = IrTranpUtil::DExtract(a_Header, 22 + a_offset);
       
   684 		m_DPID = IrTranpUtil::DExtract(a_Header, 24 + a_offset);
       
   685 		m_CmdId = IrTranpUtil::DExtract(a_Header,26 + a_offset);
       
   686 		// Pass SCEP packet Payload to BFTP layer
       
   687 		m_oBFTP->ReqPDU(a_Header, a_offset + 28); // hardcoded, but always 28
       
   688 		}
       
   689 	else if(switchVar == KTranpPduTypeRplAck)
       
   690 		{
       
   691 		SCEPPRINT(_L("SCEP: PduTypeRplAck\n"));
       
   692 		}
       
   693 	else if(switchVar == KTranpPduTypeRplNack)
       
   694 		{
       
   695 		SCEPPRINT(_L("SCEP: PduTypeRplNack\n"));
       
   696 		}
       
   697 	else if(switchVar == KTranpPduTypeAbt)
       
   698 		{
       
   699 		SCEPPRINT(_L("SCEP: PduTypeAbt\n"));
       
   700 		}
       
   701 	else
       
   702 		{
       
   703 		SCEPPRINT(_L("SCEP: PduType Broken\n"));
       
   704 		}
       
   705 	
       
   706 	SCEPPRINT(_L("SCEP: Exiting DoCommand\n"));
       
   707 	}
   382 	}
   708 
   383 
   709 /*
   384 /*
   710 * Method description:	Private method called to parse the NegInf section of a packet
   385 * Method description:	Private method called to parse the NegInf section of a packet
   711 *
   386 *
   837 //						Also creates the necessary reply-commands at SCEP level.
   512 //						Also creates the necessary reply-commands at SCEP level.
   838 //
   513 //
   839 // Parameter:			a_TempBuffer - the packet itself
   514 // Parameter:			a_TempBuffer - the packet itself
   840 //
   515 //
   841 
   516 
   842 void SCEP::ParseCommand(TDes8& a_TempBuffer)
   517 void SCEP::ParseCommand(TDes8& /*a_TempBuffer*/)
   843 	{
   518 /** No Longer used.
   844 	SCEPPRINT(_L("SCEP: ParseCommand\n"));
   519 
   845 	// parse the incoming buffer and see what command we're talking about. Return an instance of such a command.
   520 irda client libraries left in to avoid breaks */
   846 	
   521 	{
   847 	// Look at the first bytes, see what command it might be, call the correct private method and let it take care of the rest?
       
   848 	
       
   849 	if(a_TempBuffer[1] == KTranpMsgTypeCER)
       
   850 		// MsgType = Connection establishment request
       
   851 		{
       
   852 		SCEPPRINT(_L("SCEP: Got a connection request"));
       
   853 		SCEPConRequest(a_TempBuffer, 2);
       
   854 		
       
   855 		// Create and add a SCEPConConfirm!
       
   856 		SCONconL();
       
   857 		}
       
   858 	else if(a_TempBuffer[1] == KTranpMsgTypeCEC)
       
   859 		// MsgType = Connection establishment confirmation
       
   860 		{
       
   861 		SCEPPRINT(_L("SCEP: Got a connect ack"));
       
   862 		SCEPConConfirm(a_TempBuffer, 2);
       
   863 		}
       
   864 	else if(a_TempBuffer[1] == KTranpMsgTypeData)
       
   865 		// Data (Command)
       
   866 		{
       
   867 		SCEPPRINT(_L("SCEP: Got a data packet\n"));
       
   868 		SCEPDataCommand(a_TempBuffer, 2);
       
   869 		}
       
   870 	else if(a_TempBuffer[1] == KTranpMsgTypeDisc)
       
   871 		// Disconnection
       
   872 		{
       
   873 		SCEPPRINT(_L("SCEP: Got a disconnect packet\n"));
       
   874 		SCEPDisconnect(a_TempBuffer, 2);
       
   875 		if (m_packet != NULL)
       
   876 			m_iPicSize = m_packet->Length(); // Otherwise we'll never get to 100%
       
   877 		iSCEPFrame.Zero();
       
   878 		}
       
   879 	else
       
   880 		{
       
   881 		SCEPPRINT(_L("SCEP: Wacko! Default!\n"));
       
   882 		// Reserved
       
   883 		}
       
   884 	
       
   885 	
       
   886 	SCEPPRINT(_L("SCEP: Exiting ParseCommand\n"));
       
   887 	
       
   888 	return;
       
   889 	}
   522 	}
   890 
   523 
   891 //
   524 //
   892 // Method description:	Sets the Primary Machine ID
   525 // Method description:	Sets the Primary Machine ID
   893 //
   526 //