irda/irdastack/irtranp/BFTP.CPP
changeset 0 29b1cd4cb562
child 11 20fda83a6398
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32svr.h>
       
    17 #include <e32cons.h>
       
    18 #include <e32base.h>
       
    19 #include "debug.h"
       
    20 #include "GLOBAL.H"
       
    21 #include "comreadwrite.h"
       
    22 #include "SCEP.H"
       
    23 #include "tranp.h"
       
    24 #include "BFTP.H"
       
    25 #include "tranpprot.h"
       
    26 
       
    27 BFTP::BFTP() : iPicture(NULL,0), iUPFPicture(NULL,0)
       
    28 	{
       
    29 	}
       
    30 
       
    31  BFTP* BFTP::NewL(CTranpProtocol* aTranpProtocol, const MTranpNotification* aNotifier)
       
    32 	{
       
    33 	DEBUG_OPEN();
       
    34 	BFTPPRINT(_L("BFTP::NewL()\n"));
       
    35 	BFTP* self = new(ELeave) BFTP();
       
    36 	CleanupStack::PushL(self);
       
    37 	self->ConstructL(aTranpProtocol, aNotifier);
       
    38 	CleanupStack::Pop();
       
    39 	return self;
       
    40 	}
       
    41 
       
    42  void BFTP::ConstructL(CTranpProtocol* aTranpProtocol, const MTranpNotification* aNotifier)
       
    43 	{
       
    44 	BFTPPRINT(_L("BFTP::ConstructL()\n"));
       
    45 	iTranpProtocol = aTranpProtocol;
       
    46 	m_oSCEP = SCEP::NewL(aTranpProtocol,this,aNotifier);
       
    47 	}
       
    48 
       
    49  BFTP::~BFTP()
       
    50 	{
       
    51 	delete m_oSCEP;
       
    52 	}
       
    53 
       
    54 /*
       
    55 * Method description:	Called from SCEP with a buffer containing a Request PDU
       
    56 *
       
    57 * Parameter:			a_Header - TPtr pointing the command buffer
       
    58 * Parameter:			a_offset - the offset into the buffer where we should start parsing
       
    59 */
       
    60 
       
    61 void BFTP::ReqPDU(const TDesC8& a_Header, TInt a_offset)
       
    62 	{
       
    63 	BFTPPRINT(_L("BFTP: ReqPDU\n"));
       
    64 	
       
    65 	TUint16 AttNum = IrTranpUtil::DExtract(a_Header, a_offset);
       
    66 	a_offset+=2;
       
    67 	
       
    68 	for(TInt i=0;i<AttNum;i++) // Loop all AttNames
       
    69 		{
       
    70 		TBuf8<4> attName; // BFTP Attribute name
       
    71 		for(TInt j=0;j<4;j++) // we don't like it .. hardcoded
       
    72 			{
       
    73 			attName.Append(a_Header[a_offset+j]);
       
    74 			}
       
    75 		
       
    76 		a_offset+=4;
       
    77 		
       
    78 		if(attName.Compare(KTranpFIL0) == 0)
       
    79 			{
       
    80 			TUint32 length = IrTranpUtil::LExtract(a_Header, a_offset);
       
    81 			BFTPPRINT(_L("BFTP: Attribute FIL0\n"));
       
    82 			
       
    83 			m_FileName.SetLength(0);
       
    84 			m_FileName.Append((unsigned char*)a_Header.Ptr() + a_offset + 6, length-2);
       
    85 			
       
    86 			a_offset+=(length+4);
       
    87 			}
       
    88 		else if(attName.Compare(KTranpLFL0) == 0)
       
    89 			{
       
    90 			TUint32 length = IrTranpUtil::LExtract(a_Header, a_offset);
       
    91 			BFTPPRINT(_L("BFTP: Attribute LFL0\n"));
       
    92 
       
    93 			iLongFilename.Append((unsigned char*)a_Header.Ptr() + a_offset + 6, length-2);
       
    94 
       
    95 			a_offset+=(length+4);
       
    96 			}
       
    97 		else if(attName.Compare(KTranpTIM0) == 0)
       
    98 			{
       
    99 			TUint32 length = IrTranpUtil::LExtract(a_Header, a_offset);
       
   100 			BFTPPRINT(_L("BFTP: Attribute TIM0\n"));
       
   101 			a_offset+=(length+4);
       
   102 			}
       
   103 		else if(attName.Compare(KTranpTYP0) == 0)
       
   104 			{
       
   105 			TUint32 length = IrTranpUtil::LExtract(a_Header, a_offset);
       
   106 			BFTPPRINT(_L("BFTP: Attribute TYP0\n"));
       
   107 			a_offset+=(length+4);
       
   108 			}
       
   109 		else if(attName.Compare(KTranpTMB0) == 0)
       
   110 			{
       
   111 			TUint32 length = IrTranpUtil::LExtract(a_Header, a_offset);
       
   112 			BFTPPRINT(_L("BFTP: Attribute TMB0\n"));
       
   113 			a_offset+=(length+4);
       
   114 			}
       
   115 		else if(attName.Compare(KTranpBDY0) == 0)
       
   116 			{
       
   117 			TUint32 length = IrTranpUtil::LExtract(a_Header, a_offset);
       
   118 			BFTPPRINT(_L("BFTP: Attribute BDY0\n"));
       
   119 			
       
   120 			//iPicture.Set((unsigned char*)a_Header.Ptr() + a_offset + 6 + KTranpUPFHeader, length-2, length-2);
       
   121 			iUPFPicture.Set((unsigned char*)a_Header.Ptr() + a_offset + 6, length-2, length-2);
       
   122 			
       
   123 			iTranpProtocol->SetPicture(iPicture, m_FileName, iUPFPicture, iLongFilename);
       
   124 
       
   125 			a_offset+=(length+4);
       
   126 			/**/
       
   127 			TBuf8<256> userData;
       
   128 		
       
   129 			// AttNum
       
   130 			userData.Append(0x00);
       
   131 			userData.Append(0x01);
       
   132 			// attName
       
   133 			userData.Append(KTranpRPL0);
       
   134 			// AttLength
       
   135 			userData.Append(0x00);
       
   136 			userData.Append(0x00);
       
   137 			userData.Append(0x00);
       
   138 			userData.Append(2 + m_FileName.Length());
       
   139 			// AttType
       
   140 			userData.Append(0x01);
       
   141 			// AFLG
       
   142 			userData.Append(0x00);
       
   143 			// AttValue
       
   144 			userData.Append(m_FileName);
       
   145 			
       
   146 			TUint8 pduType = KTranpPduTypeRplAck;
       
   147 			m_oSCEP->SCEPSendCommand(userData, pduType); // We want SCEP to send a packet with this command
       
   148 			}
       
   149 		else if(attName.Compare(KTranpCMD0) == 0)
       
   150 			{
       
   151 			TUint32 length = IrTranpUtil::LExtract(a_Header, a_offset);
       
   152 			BFTPPRINT(_L("BFTP: Attribute CMD0\n"));
       
   153 			a_offset+=(length+4);
       
   154 			}
       
   155 		else if(attName.Compare(KTranpWHT0) == 0)
       
   156 			{
       
   157 			TUint32 length = IrTranpUtil::LExtract(a_Header, a_offset);
       
   158 			BFTPPRINT(_L("BFTP: Attribute WHT0\n"));
       
   159 			
       
   160 			// how to avoid copying of the information we put in the command??? Don't avoid it for now.
       
   161 			TPtr8 queryType((unsigned char*)a_Header.Ptr() + a_offset+6, 4, 4);
       
   162 
       
   163 			TBuf8<256> userData;
       
   164 			//TPtr8 userDataPtr = userData.Des();
       
   165 			
       
   166 			if (queryType.Compare(KTranpRIMG) == 0)
       
   167 				{
       
   168 				//This reply is for an RIMG query
       
   169 				// Its instructs the peer to send the image in its orginal lattice size
       
   170 
       
   171 				// AttNum
       
   172 				userData.Append(0x00);
       
   173 				userData.Append(0x01);
       
   174 				// AttName
       
   175 				userData.Append(KTranpBDY0);
       
   176 				// AttLength
       
   177 				userData.Append(0x00);
       
   178 				userData.Append(0x00);
       
   179 				userData.Append(0x00);
       
   180 				userData.Append(0x0d);
       
   181 				// AttType
       
   182 				userData.Append(0x00);
       
   183 				// AFLG
       
   184 				userData.Append(0x00);
       
   185 				
       
   186 				/*userData.Append(0x00);// <tag-pix-aspect> 3 bytes
       
   187 				userData.Append(0x01);
       
   188 				userData.Append(0x01);	*/
       
   189 
       
   190 				switch(iLatticeSize)
       
   191 					{
       
   192 				case EQVGA:
       
   193 					//QVGA:=320x240  (0x0140 x 0x00f0)
       
   194 //					userData.Append(0x01);// <tag-org-size>     5 bytes
       
   195 //					userData.Append(0x40); // width [2 bytes]
       
   196 //					userData.Append(0x01);
       
   197 //					userData.Append(0xf0);// height [2 bytes]
       
   198 //					userData.Append(0x00);
       
   199 				
       
   200 					userData.Append(0x02);// <tag-acc-size>     6 bytes
       
   201 					userData.Append(0x01);// <num-acc-size>
       
   202 					userData.Append(0x40);// width [2 bytes]
       
   203 					userData.Append(0x01);
       
   204 					userData.Append(0xf0);// height [2 bytes]
       
   205 					userData.Append(0x00);
       
   206 				break;
       
   207 				case EVGA :
       
   208 					// VGA:=640x480 ( 0x0280 x 0x01e0)
       
   209 //					userData.Append(0x01);// <tag-org-size>     5 bytes
       
   210 //					userData.Append(0x80); // width [2 bytes]
       
   211 //					userData.Append(0x02);
       
   212 //					userData.Append(0xe0);// height [2 bytes]
       
   213 //					userData.Append(0x01);
       
   214 				
       
   215 					userData.Append(0x02);// <tag-acc-size>     6 bytes
       
   216 					userData.Append(0x01);// <num-acc-size>
       
   217 					userData.Append(0x80); // width [2 bytes]
       
   218 					userData.Append(0x02);
       
   219 					userData.Append(0xe0);// height [2 bytes]
       
   220 					userData.Append(0x01);
       
   221 				break;
       
   222 				case ESVGA:
       
   223 					// SVGA:=800x600 (0x0320 x 0x0258)
       
   224 //					userData.Append(0x01);// <tag-org-size>     5 bytes
       
   225 //					userData.Append(0x20);// width [2 bytes]
       
   226 //					userData.Append(0x03);
       
   227 //					userData.Append(0x58);// height [2 bytes]
       
   228 //					userData.Append(0x02);
       
   229 				
       
   230 					userData.Append(0x02);// <tag-acc-size>     6 bytes
       
   231 					userData.Append(0x01);// <num-acc-size>
       
   232 					userData.Append(0x20);// width [2 bytes]
       
   233 					userData.Append(0x03);
       
   234 					userData.Append(0x58);// height [2 bytes]
       
   235 					userData.Append(0x02);
       
   236 					break;
       
   237 				case EXGA:
       
   238 					// XGA:=1024x768 ( 0x0400 x 0x0300)
       
   239 //					userData.Append(0x01);// <tag-org-size>     5 bytes
       
   240 //					userData.Append(0x00);// width [2 bytes]
       
   241 //					userData.Append(0x04);
       
   242 //					userData.Append(0x00);// height [2 bytes]
       
   243 //					userData.Append(0x30);
       
   244 				
       
   245 					userData.Append(0x02);// <tag-acc-size>     6 bytes
       
   246 					userData.Append(0x01);// <num-acc-size>
       
   247 					userData.Append(0x00);// width [2 bytes]
       
   248 					userData.Append(0x04);
       
   249 					userData.Append(0x00);// height [2 bytes]
       
   250 					userData.Append(0x03);	
       
   251 					break;
       
   252 				case ESXGA: 
       
   253 					// SXGA:=1280x960 (0x0500 x 0x03c0)
       
   254 //					userData.Append(0x01);// <tag-org-size>     5 bytes
       
   255 //					userData.Append(0x00);// width [2 bytes]
       
   256 //					userData.Append(0x05);
       
   257 //					userData.Append(0xc0);// height [2 bytes]
       
   258 //					userData.Append(0x03);
       
   259 				
       
   260 					userData.Append(0x02);// <tag-acc-size>     6 bytes
       
   261 					userData.Append(0x01);// <num-acc-size>
       
   262 					userData.Append(0x00);// width [2 bytes]
       
   263 					userData.Append(0x05);
       
   264 					userData.Append(0xc0);// height [2 bytes]
       
   265 					userData.Append(0x03);
       
   266 				break;
       
   267 				case EFREE:
       
   268 					// FREE:=m x n
       
   269 				default:
       
   270 					// Send in orginal size
       
   271 //					userData.Append(0x01);// <tag-org-size>     5 bytes
       
   272 //					userData.Append(0xFF);
       
   273 //					userData.Append(0xFF);
       
   274 //					userData.Append(0xFF);
       
   275 //					userData.Append(0xFF);
       
   276 				
       
   277 					userData.Append(0x02);// <tag-acc-size>     6 bytes
       
   278 					userData.Append(0x01);// <num-acc-size>
       
   279 					userData.Append(0xFF);// width [2 bytes]
       
   280 					userData.Append(0xFF);
       
   281 					userData.Append(0xFF);// height [2 bytes]
       
   282 					userData.Append(0xFF);	
       
   283 					};
       
   284 
       
   285 				/*userData.Append(0x03);// <tag-org-samp>   3 bytes
       
   286 				userData.Append(0xC4);
       
   287 				userData.Append(0x20);
       
   288 				
       
   289 				userData.Append(0x04);// <tag-acc-samp>   3 bytes
       
   290 				userData.Append(0xC4);
       
   291 				userData.Append(0x20);*/
       
   292 				
       
   293 				userData.Append(0x05);//<tag-acc-filesize> 5 bytes
       
   294 				userData.Append(0xFF);
       
   295 				userData.Append(0xFF);
       
   296 				userData.Append(0xFF);
       
   297 				userData.Append(0xFF);	
       
   298 				}
       
   299 			else if (queryType.Compare(KTranpRINF) == 0)
       
   300 				{
       
   301 				// This  reply is for an RINF query
       
   302 				userData.Append(0x00);
       
   303 				userData.Append(0x01);
       
   304 				// AttName
       
   305 				userData.Append(KTranpBDY0);
       
   306 				// AttLength
       
   307 				userData.Append(0x00);
       
   308 				userData.Append(0x00);
       
   309 				userData.Append(0x00);
       
   310 				userData.Append(0x08);
       
   311 				// AttType
       
   312 				userData.Append(0x00);
       
   313 				// AFLG
       
   314 				userData.Append(0x00);
       
   315 				// AttValue
       
   316 				userData.Append(0x10); // memory
       
   317 				userData.Append(0xff);
       
   318 				userData.Append(0xff);
       
   319 				userData.Append(0x11); // battery
       
   320 				userData.Append(0xff);
       
   321 				userData.Append(0xff);	
       
   322 				}
       
   323 			else if (queryType.Compare(KTranpRCMD) == 0)
       
   324 				{
       
   325                 // This  reply is for an RINF query
       
   326 				userData.Append(0x00);
       
   327 				userData.Append(0x01);
       
   328 				// AttName
       
   329 				userData.Append(KTranpBDY0);
       
   330 				// AttLength
       
   331 				userData.Append(0x00);
       
   332 				userData.Append(0x00);
       
   333 				userData.Append(0x00);
       
   334 				userData.Append(0x07);
       
   335 				// AttType
       
   336 				userData.Append(0x00);
       
   337 				// AFLG
       
   338 				userData.Append(0x00);
       
   339 				// AttValue
       
   340 				userData.Append(0x20); // tag-opt-func
       
   341                 userData.Append(0x00);
       
   342 				userData.Append(0x01);
       
   343 				userData.Append(0x00);
       
   344 				userData.Append(0x01); // func-multi-command
       
   345 				}
       
   346 
       
   347 			a_offset+=(length+4);
       
   348 
       
   349 			TUint8 pduType = KTranpPduTypeRplAck;
       
   350 			m_oSCEP->SCEPSendCommand(userData, pduType); // We want SCEP to send a packet with this command
       
   351 			}
       
   352 		else if(attName.Compare(KTranpERR0) == 0)
       
   353 			{
       
   354 			TUint32 length = IrTranpUtil::LExtract(a_Header, a_offset);
       
   355 			BFTPPRINT(_L("BFTP: Attribute ERR0\n"));
       
   356 			a_offset+=(length+4);
       
   357 			}
       
   358 		else if(attName.Compare(KTranpRPL0) == 0)
       
   359 			{
       
   360 			TUint32 length = IrTranpUtil::LExtract(a_Header, a_offset);
       
   361 			BFTPPRINT(_L("BFTP: Attribute RPL0\n"));
       
   362 			a_offset+=(length+4);
       
   363 			}
       
   364 	}
       
   365 	
       
   366 	BFTPPRINT(_L("BFTP: Exiting ReqPDU\n"));
       
   367 }
       
   368 
       
   369 /*
       
   370 * Method description:	Called from the application with a picture to send
       
   371 *
       
   372 * Parameter:			a_picture - TPtr pointing to the picture
       
   373 * Parameter:			a_fileName - filename of the picture
       
   374 */
       
   375 
       
   376 void BFTP::Put(TPtr8* /*a_picture*/, TPtr /*a_fileName*/)
       
   377 	{
       
   378 	// Not fully implemented as of now
       
   379 	}
       
   380 
       
   381 /*
       
   382 * Method description:	Called from the application, returns a TPtr with length>0 when picture is ready.
       
   383 *						Use Pump() (returnvalue = progress from 0 to 100) to run the module!
       
   384 *
       
   385 * Returns:				Pointer to a TPtr pointing to the picture
       
   386 */
       
   387 
       
   388 // TPtr8* BFTP::Get()
       
   389 //	{
       
   390 //	return m_oPicture;	// Null if no picture has been received yet
       
   391 //	}
       
   392 
       
   393 	/*
       
   394 	* Method description:	Called from the application, returns a pointer to the filename
       
   395 	*
       
   396 	* Returns:				Pointer to the filename
       
   397 */
       
   398 
       
   399 // TPtr8 BFTP::GetFileName()
       
   400 void BFTP::GetFileName()
       
   401 	{
       
   402 	// Deprecated Function - No Longer used
       
   403 	return ;//m_FileName.Des();
       
   404 	}
       
   405 
       
   406 /*
       
   407 * Method description:	Runs the module, call at intervals like 200 ms
       
   408 *
       
   409 * Returns:				Integer containing the progress from 0 to 100
       
   410 */
       
   411 
       
   412 TInt BFTP::Pump(TLatticeSize aLatticeSize)
       
   413 	{
       
   414 	iLatticeSize = aLatticeSize;
       
   415 	return m_oSCEP->Pump();
       
   416 	}
       
   417 
       
   418 void BFTP::Abort()
       
   419 	{
       
   420 	m_oSCEP->Abort();
       
   421 	}
       
   422 
       
   423 /*
       
   424 * Method description:	Passing through initialization data to SCEP
       
   425 *
       
   426 * Parameter:			a_oPMID - Primary Machine ID
       
   427 */
       
   428 
       
   429 void BFTP::SetPMID(const TDesC8& aPMID)
       
   430 	{
       
   431 	m_oSCEP->SetPMID(aPMID);
       
   432 	}
       
   433 
       
   434 /*
       
   435 * Method description:	Passing through initialization data to SCEP
       
   436 *
       
   437 * Parameter:			a_oSMID - Secondary Machine ID
       
   438 */
       
   439 
       
   440 void BFTP::SetSMID(const TDesC8& aSMID)
       
   441 	{
       
   442 	m_oSCEP->SetSMID(aSMID);
       
   443 	}
       
   444 
       
   445 /*
       
   446 * Method description:	Passing through initialization data to SCEP
       
   447 *
       
   448 * Parameter:			a_iPDU - Maximum receivable PDU size
       
   449 */
       
   450 
       
   451 void BFTP::SetPDU(TUint8 a_iPDU)
       
   452 	{
       
   453 	m_oSCEP->SetPDU(a_iPDU);
       
   454 	}
       
   455