|
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 "debug.h" |
|
17 |
|
18 #include <e32math.h> |
|
19 #include <e32svr.h> |
|
20 #include "comreadwrite.h" |
|
21 #include "tranp.h" |
|
22 #include "tranpprot.h" |
|
23 #include "SCEP.H" |
|
24 #include "COMMANDP.H" |
|
25 #include "ABSTRACT.H" |
|
26 #include "SCONREQC.H" |
|
27 #include "SCONCONC.H" |
|
28 #include "SRPSCOMM.H" |
|
29 #include "GLOBAL.H" |
|
30 #include "BFTP.H" |
|
31 |
|
32 |
|
33 SCEP::SCEP() |
|
34 { |
|
35 } |
|
36 |
|
37 /* |
|
38 * Method description: Leavable constructor for the SCEP layer |
|
39 * |
|
40 */ |
|
41 |
|
42 SCEP* SCEP::NewL(CTranpProtocol* aTranpProtocol, BFTP* a_oBFTP, const MTranpNotification* aNotifier) |
|
43 { |
|
44 DEBUG_OPEN(); |
|
45 SCEPPRINT(_L("SCEP::NewL()\n")); |
|
46 |
|
47 SCEP* self = new(ELeave) SCEP(); |
|
48 CleanupStack::PushL(self); |
|
49 self->ConstructL(aTranpProtocol, a_oBFTP, aNotifier); |
|
50 CleanupStack::Pop(); |
|
51 return self; |
|
52 } |
|
53 |
|
54 /* |
|
55 * Method description: Second part of the SCEP construction - creates the CommandProcessor and CComReadWrite. |
|
56 * |
|
57 * Parameter: Pointer to the BFTP class |
|
58 * |
|
59 */ |
|
60 |
|
61 void SCEP::ConstructL(CTranpProtocol* aTranpProtocol, BFTP* a_oBFTP, const MTranpNotification* aNotifier) |
|
62 { |
|
63 |
|
64 SCEPPRINT(_L("SCEP::ConstructL()\n")); |
|
65 iNotifier = const_cast<MTranpNotification*>(aNotifier); |
|
66 iState = EWaiting; |
|
67 |
|
68 m_uiMaxPDU = 4; |
|
69 |
|
70 m_oCommandP = new(ELeave) CommandProcessor(); |
|
71 iComReadWrite = CComReadWrite::NewL(*this); |
|
72 |
|
73 m_oBFTP = a_oBFTP; |
|
74 iTranpProtocol = aTranpProtocol; |
|
75 |
|
76 m_packet = NULL; |
|
77 m_iPicSize = 0; |
|
78 } |
|
79 |
|
80 SCEP::~SCEP() |
|
81 { |
|
82 delete m_oCommandP; |
|
83 delete iComReadWrite; |
|
84 //delete m_packet; Ownership now belongs to TTranpPicture Object |
|
85 } |
|
86 |
|
87 /* |
|
88 * Method description: Pump - receives and sends data, should be called periodically. Due to the way IrTran-P and |
|
89 * serial communication works, it also tries to check when it has received a complete SCEP |
|
90 * packet. This should be handled in a differerent (and more nice) way. |
|
91 * |
|
92 * Returns: An integer containing the progress from 0 to 100 |
|
93 */ |
|
94 |
|
95 void SCEP::Abort() |
|
96 { |
|
97 iComReadWrite->Cancel(); |
|
98 iComReadWrite->Signal(KErrNone); |
|
99 } |
|
100 |
|
101 TInt SCEP::Pump() |
|
102 { |
|
103 // Set up the IR port connection with a null write |
|
104 //delete m_packet; |
|
105 //m_packet = NULL; |
|
106 //iState = EWaiting; |
|
107 //iSCEPFrame.SetLength(0); |
|
108 iComReadWrite->Open(); |
|
109 return 0; |
|
110 } |
|
111 |
|
112 void SCEP::ReceiveComplete(TDesC8& aBuffer) |
|
113 { |
|
114 SCEPPRINT_2(_L("SCEP::ReceiveComplete(%d)\n"),aBuffer.Length()); |
|
115 |
|
116 iSCEPFrame.Append(aBuffer); // Add new data to cached packet |
|
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 } |
|
256 |
|
257 void SCEP::SendComplete() |
|
258 { |
|
259 // Post Read Request |
|
260 SCEPPRINT(_L("SCEP: Send Complete\n")); |
|
261 iComReadWrite->Receive(); |
|
262 } |
|
263 |
|
264 void SCEP::SendError(TInt aError) |
|
265 { |
|
266 SCEPPRINT_2(_L("SCEP: Send Error %d\n"), aError); |
|
267 iNotifier->Error(aError); |
|
268 iState = EError; |
|
269 } |
|
270 |
|
271 void SCEP::ReceiveError(TInt aError) |
|
272 { |
|
273 SCEPPRINT_2(_L("SCEP: Receive Error %d\n"), aError); |
|
274 iNotifier->Error(aError); |
|
275 iState = EError; |
|
276 } |
|
277 void SCEP::Error(TInt aError) |
|
278 { |
|
279 SCEPPRINT_2(_L("SCEP: Error %d\n"), aError); |
|
280 iNotifier->Error(aError); |
|
281 iState = EError; |
|
282 } |
|
283 |
|
284 |
|
285 /* |
|
286 * Method description: Called from BFTP when a connection request should be sent |
|
287 * |
|
288 */ |
|
289 |
|
290 void SCEP::SCONreqL() |
|
291 { |
|
292 SCONreqCommand* command = new(ELeave) SCONreqCommand(iComReadWrite); |
|
293 command->SetPMID(m_PMID.Des()); |
|
294 command->SetSMID(m_SMID.Des()); |
|
295 command->SetPDU(m_uiMaxPDU); |
|
296 command->Create(); |
|
297 //IrTranpUtil::HexOut(command->GetData()); |
|
298 m_oCommandP->Add(command); |
|
299 } |
|
300 |
|
301 /* |
|
302 * Method description: Called from BFTP when a connection confirmed should be sent |
|
303 * |
|
304 */ |
|
305 |
|
306 void SCEP::SCONconL() |
|
307 { |
|
308 SCONconCommand* command = new(ELeave) SCONconCommand(iComReadWrite); |
|
309 command->SetPMID(m_PMID.Des()); |
|
310 command->SetSMID(m_SMID.Des()); |
|
311 command->SetPDU(m_uiMaxPDU); |
|
312 command->Create(); |
|
313 // IrTranpUtil::HexOut(command->GetData()); |
|
314 m_oCommandP->Add(command); |
|
315 } |
|
316 |
|
317 /* |
|
318 * Method description: Called from BFTP when a common BFTP packet should be sent |
|
319 * |
|
320 */ |
|
321 |
|
322 void SCEP::SCEPSendCommand(TDes8& a_userData, TUint8 a_pduType) |
|
323 { |
|
324 SRPSCommand* command = new (ELeave) SRPSCommand(iComReadWrite); |
|
325 command->SetPMID(m_PMID.Des()); |
|
326 command->SetSMID(m_SMID.Des()); |
|
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 } |
|
336 |
|
337 /* |
|
338 * Method description: Private method called when a Connection Request packet should be parsed |
|
339 * |
|
340 * Parameter: a_Header - pointer to the packet buffer |
|
341 * Parameter: offset - where in the buffer to start parsing |
|
342 */ |
|
343 |
|
344 void SCEP::SCEPConRequest(TDes8& a_Header, TInt offset) |
|
345 { |
|
346 SCEPPRINT(_L("Inside SCEPConRequest\n")); |
|
347 |
|
348 TInt length = a_Header.Length(); |
|
349 |
|
350 while(offset<length) |
|
351 { |
|
352 if(a_Header[offset] == KTranpInfTypeVer) |
|
353 // case IrTranpUtil::InfTypeVer: |
|
354 { |
|
355 offset+=2; |
|
356 } |
|
357 else if(a_Header[offset] == KTranpInfTypeNeg) |
|
358 { |
|
359 // Negotiation information |
|
360 // TUint8 length = a_Header[offset+1]; |
|
361 // TUint8 InfVer = a_Header[offset+2]; |
|
362 // TUint8 CFLG = a_Header[offset+3]; |
|
363 |
|
364 //TPtr8 SMID((unsigned char*)a_Header.Ptr()+offset+4, 8, a_Header.MaxLength()); |
|
365 TPtr8 PMID((unsigned char*)a_Header.Ptr()+offset+12, 8, a_Header.MaxLength()); |
|
366 |
|
367 m_PMID = PMID; |
|
368 // m_SMID = SMID; // We want to keep ours |
|
369 |
|
370 NegInf(a_Header, offset+20); |
|
371 |
|
372 offset+=(length+2); |
|
373 } |
|
374 else if(a_Header[offset] == KTranpInfTypeExt) |
|
375 { |
|
376 // Ehh .. dunno .. "extend in the future" |
|
377 offset+=4; |
|
378 } |
|
379 else |
|
380 { |
|
381 // Error Not a Valid SCEP connection request... |
|
382 SCEPPRINT(_L("Not a Valid SCEPConRequest\n")); |
|
383 iNotifier->Error(KErrIrtranpPeerDoesNotHaveIrtranp); //KErrIrtranpPeerDoesNotHaveIrtranp |
|
384 break; |
|
385 } |
|
386 } |
|
387 SCEPPRINT(_L("Exiting SCEPConRequest\n")); |
|
388 } |
|
389 |
|
390 /* |
|
391 * Method description: Private method called when a commond Data packet should be parsed |
|
392 * |
|
393 * Parameter: a_Header - pointer to the packet buffer |
|
394 * Parameter: offset - where in the packet to start parsing |
|
395 */ |
|
396 |
|
397 void SCEP::SCEPDataCommand(TDes8& a_Header, TInt offset) |
|
398 { |
|
399 SCEPPRINT(_L("Inside SCEPDataCommand\n")); |
|
400 |
|
401 if(a_Header[offset] == KTranpInfTypeUser) |
|
402 { |
|
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 |
|
548 /* |
|
549 * Method description: Adds segmented packets into a complete packet |
|
550 * |
|
551 * Parameter: a_Header - pointer to the segment |
|
552 * Parameter: a_offset - where in the segment data to be assembled is |
|
553 */ |
|
554 |
|
555 void SCEP::AddSegment(TDes8& a_Header, TInt a_offset) |
|
556 { |
|
557 SCEPPRINT(_L("Entered AddSegment\n")); |
|
558 TPtr8 temp((unsigned char*)a_Header.Ptr()+a_offset, a_Header.Length()-a_offset, a_Header.MaxLength()); |
|
559 TPtr8 temp2 = m_packet->Des(); |
|
560 temp2.Append(temp); |
|
561 SCEPPRINT(_L("Exited AddSegment\n")); |
|
562 } |
|
563 |
|
564 /* |
|
565 * Method description: Private method called to parse an SCEP disconnetion packet |
|
566 * |
|
567 * Parameter: a_Header - pointer to the packet |
|
568 * Parameter: offset - where in the packet to start parsing |
|
569 */ |
|
570 |
|
571 void SCEP::SCEPDisconnect(TDes8& a_Header, TInt offset) |
|
572 { |
|
573 SCEPPRINT(_L("SCEP: SCEPDisconnect\n")); |
|
574 SCEPPRINT_2(_L("SCEP: %d -> EDisconnected\r\n"), iState); |
|
575 |
|
576 if(a_Header[offset] == KTranpInfTypeRsn) |
|
577 { |
|
578 TUint16 reason = IrTranpUtil::DExtract(a_Header, offset+2); |
|
579 if(reason == KTranpDisPDUrsnUR) |
|
580 { |
|
581 SCEPPRINT(_L("SCEP: Disconnect: Unspecified Reason\n")); |
|
582 iState = EDisconnected; |
|
583 |
|
584 } |
|
585 else if(reason == KTranpDisPDUrsnUD) |
|
586 { |
|
587 SCEPPRINT(_L("SCEP: Disconnect: User Disconnect\n")); |
|
588 iState = EDisconnected; |
|
589 |
|
590 } |
|
591 else if(reason == KTranpDisPDUrsnPD) |
|
592 { |
|
593 SCEPPRINT(_L("SCEP: Disconnect: Provider Disconnect\n")); |
|
594 iState = EDisconnected; |
|
595 |
|
596 } |
|
597 else |
|
598 { |
|
599 // reserved |
|
600 } |
|
601 } |
|
602 else |
|
603 { |
|
604 // oops |
|
605 } |
|
606 SCEPPRINT(_L("SCEP: Exiting SCEPDisconnect\n")); |
|
607 return; |
|
608 } |
|
609 |
|
610 /* |
|
611 * Method description: Private method called when parsing a Connection Confirmed packet |
|
612 * |
|
613 * Parameter: a_Header - pointer to the packet |
|
614 * Parameter: offset - where in the packet to start parsing |
|
615 */ |
|
616 |
|
617 void SCEP::SCEPConConfirm(TDes8& a_Header, TInt offset) |
|
618 { |
|
619 SCEPPRINT(_L("Inside SCEPConConfirm\n")); |
|
620 |
|
621 TInt length = a_Header.Length(); |
|
622 |
|
623 while(offset<length) |
|
624 { |
|
625 if(a_Header[offset] == KTranpInfTypeVer) |
|
626 { |
|
627 // Should always be 01? |
|
628 offset+=2; |
|
629 } |
|
630 else if(a_Header[offset] == KTranpInfTypeNeg) |
|
631 { |
|
632 // Negotiation information |
|
633 TUint8 length = a_Header[offset+1]; |
|
634 // TUint8 InfVer = a_Header[offset+2]; |
|
635 // TUint8 CFLG = a_Header[offset+3]; |
|
636 |
|
637 TPtr8 PMID((unsigned char*)a_Header.Ptr()+offset+4, 8, a_Header.MaxLength()); |
|
638 TPtr8 SMID((unsigned char*)a_Header.Ptr()+offset+12, 8, a_Header.MaxLength()); |
|
639 |
|
640 m_PMID = PMID; |
|
641 m_SMID = SMID; |
|
642 |
|
643 NegInf(a_Header, offset+20); |
|
644 offset+=(length+2); |
|
645 } |
|
646 else if(a_Header[offset] == KTranpInfTypeExt) |
|
647 { |
|
648 // "extend in the future" |
|
649 |
|
650 SCEPPRINT(_L("InfTypeExt appeared in ConConfirm - error in protocol\n")); |
|
651 // Should not appear in a ConConfirm! |
|
652 offset+=4; |
|
653 } |
|
654 else //default |
|
655 { |
|
656 } |
|
657 } // End of While loop |
|
658 } |
|
659 |
|
660 /* |
|
661 * Method description: Private method called when parsing the Command-section of a packet |
|
662 * |
|
663 * Parameter: a_Header - pointer to the packet |
|
664 * Parameter: a_offset - where in the packet the command is |
|
665 */ |
|
666 |
|
667 void SCEP::DoCommand(const TDesC8& a_Header, TInt a_offset) |
|
668 { |
|
669 SCEPPRINT(_L("SCEP: DoCommand\n")); |
|
670 |
|
671 if(a_Header[a_offset] != 0x58) // Always 0x58 at the start of a command |
|
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 } |
|
708 |
|
709 /* |
|
710 * Method description: Private method called to parse the NegInf section of a packet |
|
711 * |
|
712 * Parameter: a_Header - pointer to the packet |
|
713 * Parameter: a_offset - where in the packet the NegInf is |
|
714 */ |
|
715 |
|
716 void SCEP::NegInf(TDes8& a_Header, TInt a_offset) |
|
717 { |
|
718 SCEPPRINT(_L("SCEP: NegInf\n")); |
|
719 |
|
720 if(a_Header[a_offset] != KTranpNegVer) |
|
721 { |
|
722 return; // skip the NegInf totally |
|
723 } |
|
724 TInt length = a_Header.Length(); |
|
725 while(a_offset<length) // Parse all NegContent attributes |
|
726 { |
|
727 TBuf<8> l(8); |
|
728 l.Num(a_offset); |
|
729 TBuf<8> k(8); |
|
730 k.Num(length); |
|
731 |
|
732 TBufC8<4> temp; |
|
733 TPtr8 temp2 = temp.Des(); |
|
734 for(TInt j=0;j<3;j++) // we don't like it .. hardcoded |
|
735 { |
|
736 temp2.Append(a_Header[a_offset+1+j]); |
|
737 } |
|
738 |
|
739 TInt valueOffset = a_offset+1+temp.Length(); |
|
740 if(temp.Compare(KTranpFR) == 0) |
|
741 { |
|
742 SCEPPRINT(_L("SCEP: Found FR attribute\n")); |
|
743 // pump whitespace |
|
744 if(a_Header[valueOffset] == ' ') |
|
745 { |
|
746 valueOffset++; |
|
747 } |
|
748 |
|
749 m_uiMaxPDU = a_Header[valueOffset]; |
|
750 |
|
751 // Now skip CRLF - pump |
|
752 TBool found = FALSE; |
|
753 while(found == FALSE) |
|
754 { |
|
755 if(a_Header[valueOffset] == KTranpLF) // Why look for both CR and LF? LF always follows CR .. |
|
756 { |
|
757 found = TRUE; |
|
758 } |
|
759 else |
|
760 valueOffset++; |
|
761 } |
|
762 } |
|
763 else if(temp.Compare(KTranpID) == 0) |
|
764 { |
|
765 SCEPPRINT(_L("SCEP: Found ID attribute\n")); |
|
766 TBool found = FALSE; |
|
767 TPtr8 temp = m_szPIS.Des(); |
|
768 temp.Zero(); |
|
769 do |
|
770 { |
|
771 if(a_Header[valueOffset] != KTranpCR) |
|
772 { |
|
773 temp.Append(a_Header[valueOffset++]); |
|
774 } |
|
775 else |
|
776 { |
|
777 found = TRUE; |
|
778 valueOffset+=2; // skip LF too |
|
779 } |
|
780 } |
|
781 while(found == FALSE); |
|
782 } |
|
783 else if(temp.Compare(KTranpNM) == 0) |
|
784 { |
|
785 SCEPPRINT(_L("SCEP: Found NM attribute\n")); |
|
786 TBool found = FALSE; |
|
787 TPtr8 temp = m_szUserName.Des(); |
|
788 temp.Zero(); |
|
789 do |
|
790 { |
|
791 if(a_Header[valueOffset] != KTranpCR) |
|
792 { |
|
793 temp.Append(a_Header[valueOffset++]); |
|
794 } |
|
795 else |
|
796 { |
|
797 found = TRUE; |
|
798 valueOffset+=2; // skip LF too |
|
799 } |
|
800 } |
|
801 while(found == FALSE); |
|
802 } |
|
803 else if(temp.Compare(KTranpPW) == 0) |
|
804 { |
|
805 SCEPPRINT(_L("SCEP: Found PW attribute\n")); |
|
806 TBool found = FALSE; |
|
807 TPtr8 temp = m_szPassword.Des(); |
|
808 temp.Zero(); |
|
809 do |
|
810 { |
|
811 if(a_Header[valueOffset] != KTranpCR) |
|
812 { |
|
813 temp.Append(a_Header[valueOffset++]); |
|
814 } |
|
815 else |
|
816 { |
|
817 found = TRUE; |
|
818 valueOffset+=2; // skip LF too |
|
819 } |
|
820 } |
|
821 while(found == FALSE); |
|
822 } |
|
823 else |
|
824 { |
|
825 // Something that wasn't an attribute |
|
826 } |
|
827 a_offset = valueOffset; |
|
828 |
|
829 } |
|
830 iState = EConnected; |
|
831 //iNotifier->Connected(); |
|
832 SCEPPRINT(_L("SCEP: Exiting NegInf\n")); |
|
833 } |
|
834 |
|
835 // |
|
836 // Method description: Private method called when a packet has been received. Here is where the parsing begins. |
|
837 // Also creates the necessary reply-commands at SCEP level. |
|
838 // |
|
839 // Parameter: a_TempBuffer - the packet itself |
|
840 // |
|
841 |
|
842 void SCEP::ParseCommand(TDes8& a_TempBuffer) |
|
843 { |
|
844 SCEPPRINT(_L("SCEP: ParseCommand\n")); |
|
845 // parse the incoming buffer and see what command we're talking about. Return an instance of such a command. |
|
846 |
|
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 } |
|
890 |
|
891 // |
|
892 // Method description: Sets the Primary Machine ID |
|
893 // |
|
894 // Parameter: a_PMID - the new Machine ID |
|
895 // |
|
896 |
|
897 void SCEP::SetPMID(const TDesC8& aPMID) |
|
898 { |
|
899 m_PMID = aPMID; |
|
900 } |
|
901 |
|
902 // |
|
903 // Method description: Sets the Secondary Machine ID |
|
904 // |
|
905 // Parameter: a_SMID - the new Machine ID |
|
906 // |
|
907 |
|
908 void SCEP::SetSMID(const TDesC8& aSMID) |
|
909 { |
|
910 m_SMID = aSMID; |
|
911 } |
|
912 |
|
913 // |
|
914 // Method description: Sets the maximum receivable PDU size |
|
915 // |
|
916 // Parameter: a_PDU - the new PDU size |
|
917 // |
|
918 void SCEP::SetPDU(TUint8 a_PDU) |
|
919 { |
|
920 m_uiMaxPDU = a_PDU; |
|
921 } |
|
922 |