• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 // ----------------------------------------------------------------------
19 //
20 // This Software is an original work of authorship of PacketVideo Corporation.
21 // Portions of the Software were developed in collaboration with NTT  DoCoMo,
22 // Inc. or were derived from the public domain or materials licensed from
23 // third parties.  Title and ownership, including all intellectual property
24 // rights in and to the Software shall remain with PacketVideo Corporation
25 // and NTT DoCoMo, Inc.
26 //
27 // -----------------------------------------------------------------------
28 
29 #include "srp.h"
30 #include "srp_ports.h"
31 #include "pvlogger.h"
32 
33 /************************************************************************/
34 /*  Constants                                                           */
35 /************************************************************************/
36 const SRP::SrpAction SRP::iSrpStateTable[MAX_STATUS][MAX_EVENT] =
37 {
38     /* Event No.         0                      1                   2               3               4               5                   6               7       */
39     /* Status 0 */ { SRP::ACTION_NOP,  SRP::ACTION_0_1, SRP::ACTION_0_2, SRP::ACTION_NOP,  SRP::ACTION_NOP, SRP::ACTION_NOP, SRP::ACTION_0_2, SRP::ACTION_NOP} ,
40     /* Status 1 */ { SRP::ACTION_NOP,  SRP::ACTION_1_1, SRP::ACTION_0_2, SRP::ACTION_1_3,  SRP::ACTION_1_3, SRP::ACTION_1_4, SRP::ACTION_0_2, SRP::ACTION_1_3}
41 };
42 
43 
SRP()44 OSCL_EXPORT_REF SRP::SRP() : iN400MaxCounter(N400_DEFAULT_MAX_COUNTER),  //changed max # of allowable retries from 10 to 200
45         //This was done in conjunction with lowering the SRP
46         //timeout value from 400ms to 50ms
47         iN402MaxCounter(N402_DEFAULT_MAX_COUNTER), //WNSRP counter
48         iCrcData(0),
49         iSendSeqNumber(0),
50         iRecvSeqNumber(0),
51         iStatus(STS_IDLE),
52         iCurWnsrpStatus(WNSRP_TX_SUPPORT),
53         iT401TimerValue(T401_VALUE_DEFAULT),
54         iWnsrpCommandSave(NULL),
55         iCcsrlSduSize(DEFAULT_CCSRL_SIZE),
56         iRxFrags(NULL),
57         iFreeRxFragList(NULL),
58         iPendingRxFragList(NULL),
59         iFirstCmd(true),
60         iLLPortOut(NULL),
61         iLLPortIn(NULL),
62         iULPortOut(NULL),
63         iULPortIn(NULL),
64         iTxMediaMsgPoolAlloc(NULL),
65         iTxMediaDataImplMemAlloc(NULL),
66         iTxPacketAlloc(NULL),
67         iOutstandingTxMediaMsgPoolAlloc(NULL),
68         iOutstandingTxMediaDataImplMemAlloc(NULL),
69         iRxMediaMsgPoolAlloc(NULL),
70         iRxMediaDataImplMemAlloc(NULL),
71         iRxPacketAlloc(NULL),
72         iRespMediaMsgPoolAlloc(NULL),
73         iRespMemAlloc(NULL),
74         iRespPacketAlloc(NULL),
75         iNsrpRespMemAlloc(NULL),
76         iNsrpRespPacketAlloc(NULL),
77         iNumTxMsgs(DEFAULT_SEND_QUEUE_SIZE),
78         iUseNSRP(true),
79         iFirstNSRPResp(false),
80         iHandleWNSRP(true),
81         iWNSRPTxWindow(DEFAULT_WNSRP_WINDOW),
82         iWNSRPRxWindow(DEFAULT_WNSRP_WINDOW),
83         iOldestWNSRPRetransSeqNum(0),
84         iT401Resolution(T401_RESOLUTION),
85         iObserver(NULL)
86 {
87     iLogger = PVLogger::GetLoggerObject("3g324m.h324.srp");
88 }
89 
~SRP()90 OSCL_EXPORT_REF SRP::~SRP()
91 {
92 }
93 
SrpInitL(void)94 OSCL_EXPORT_REF void SRP::SrpInitL(void)
95 {
96     iLLPortOut = OSCL_NEW(SRPLowerLayerPortOut, ());
97     OsclError::LeaveIfNull(iLLPortOut);
98     iLLPortIn  = OSCL_NEW(SRPLowerLayerPortIn, (this));
99     OsclError::LeaveIfNull(iLLPortIn);
100     iULPortOut = OSCL_NEW(SRPUpperLayerPortOut, ());
101     OsclError::LeaveIfNull(iULPortOut);
102     iULPortIn  = OSCL_NEW(SRPUpperLayerPortIn, (this));
103     OsclError::LeaveIfNull(iULPortIn);
104 
105     uint32 i;
106     iSrpCommandSave.timerID = iWNSRPTxWindow;
107 
108     iWnsrpCommandSave = OSCL_ARRAY_NEW(SRPRespTimer, iWNSRPTxWindow);
109     OsclError::LeaveIfNull(iWnsrpCommandSave);
110     for (i = 0; i < iWNSRPTxWindow; i++)
111     {
112         iWnsrpCommandSave[i].timerID = i;
113     }
114 
115     iRxFrags = OSCL_ARRAY_NEW(SRPRxData, iWNSRPRxWindow);
116     OsclError::LeaveIfNull(iRxFrags);
117     for (i = 0; i < iWNSRPRxWindow; i++)
118     {
119         FreeRxFrag(&iRxFrags[i]);
120     }
121 
122     iTxMediaMsgPoolAlloc = OSCL_NEW(OsclMemPoolFixedChunkAllocator, (iNumTxMsgs, 0, &iMemAllocator));
123     OsclError::LeaveIfNull(iTxMediaMsgPoolAlloc);
124     iTxMediaDataImplMemAlloc = OSCL_NEW(OsclMemPoolFixedChunkAllocator, (iNumTxMsgs + ((iWNSRPTxWindow + 1) * 2), 0, &iMemAllocator));
125     OsclError::LeaveIfNull(iTxMediaDataImplMemAlloc);
126     iTxPacketAlloc = OSCL_NEW(PVMFMediaFragGroupCombinedAlloc<OsclMemAllocator>, (iNumTxMsgs + ((iWNSRPTxWindow + 1) * 2), MAX_SEND_FRAGS_PER_MSG, iTxMediaDataImplMemAlloc));
127     OsclError::LeaveIfNull(iTxPacketAlloc);
128     iTxPacketAlloc->create();
129 
130     iOutstandingTxMediaMsgPoolAlloc = OSCL_NEW(OsclMemPoolFixedChunkAllocator, ((iWNSRPTxWindow + 1) * 2, 0, &iMemAllocator));
131     OsclError::LeaveIfNull(iOutstandingTxMediaMsgPoolAlloc);
132     iOutstandingTxMediaDataImplMemAlloc = OSCL_NEW(OsclMemPoolFixedChunkAllocator, ((iWNSRPTxWindow + 1) * 2, 0, &iMemAllocator));
133     OsclError::LeaveIfNull(iOutstandingTxMediaDataImplMemAlloc);
134 
135     iRxMediaMsgPoolAlloc = OSCL_NEW(OsclMemPoolFixedChunkAllocator, (iWNSRPRxWindow * 2, 0, &iMemAllocator));
136     OsclError::LeaveIfNull(iRxMediaMsgPoolAlloc);
137     iRxMediaDataImplMemAlloc = OSCL_NEW(OsclMemPoolFixedChunkAllocator, (iWNSRPRxWindow * 2, 0, &iMemAllocator));
138     OsclError::LeaveIfNull(iRxMediaDataImplMemAlloc);
139     iRxPacketAlloc = OSCL_NEW(PVMFSimpleMediaBufferCombinedAlloc, (iRxMediaDataImplMemAlloc));
140     OsclError::LeaveIfNull(iRxPacketAlloc);
141 
142     iRespMediaMsgPoolAlloc = OSCL_NEW(OsclMemPoolFixedChunkAllocator, (MAX_RESP_MSGS, 0, &iMemAllocator));
143     OsclError::LeaveIfNull(iRespMediaMsgPoolAlloc);
144     iRespMemAlloc = OSCL_NEW(OsclMemPoolFixedChunkAllocator, (MAX_RESP_MSGS, 0, &iMemAllocator));
145     OsclError::LeaveIfNull(iRespMemAlloc);
146     iRespPacketAlloc = OSCL_NEW(PVMFSimpleMediaBufferCombinedAlloc, (iRespMemAlloc));
147     OsclError::LeaveIfNull(iRespPacketAlloc);
148     iNsrpRespMemAlloc = OSCL_NEW(OsclMemPoolFixedChunkAllocator, (MAX_RESP_MSGS, 0, &iMemAllocator));
149     OsclError::LeaveIfNull(iNsrpRespMemAlloc);
150     iNsrpRespPacketAlloc = OSCL_NEW(PVMFSimpleMediaBufferCombinedAlloc, (iNsrpRespMemAlloc));
151     OsclError::LeaveIfNull(iNsrpRespPacketAlloc);
152 
153     iHdrAllocator.size((uint16) iNumTxMsgs*2, (SRP_HEADER_SIZE));
154     iHdrAllocator.SetLeaveOnAllocFailure(false);
155     iCcsrlAllocator.size((uint16) iNumTxMsgs*2, CCSRL_HEADER_SIZE + SRP_SEQUENCE_SIZE);
156     iCcsrlAllocator.SetLeaveOnAllocFailure(false);
157     iFCSAllocator.size((uint16) iNumTxMsgs*2, SRP_FCS_SIZE);
158     iFCSAllocator.SetLeaveOnAllocFailure(false);
159 
160     //Just need 1 fragment for SRP/NSRP messages and 1 for WNSRP messages
161     iMTEntryNumAllocator.size(NUM_MT_ENTRY_NUMBERS, MT_ENTRY_NUMBER_SIZE);
162     iMTEntryNumAllocator.SetLeaveOnAllocFailure(false);
163     iSrpNsrpEntryNumFrag = iMTEntryNumAllocator.get();
164     *(uint8 *)iSrpNsrpEntryNumFrag.getMemFragPtr() = SRP_NSRP_MT_ENTRY_NUMBER;
165     iWnsrpEntryNumFrag = iMTEntryNumAllocator.get();
166     *(uint8 *)iWnsrpEntryNumFrag.getMemFragPtr() = WNSRP_MT_ENTRY_NUMBER;
167 
168     iSrpWaitQueue.reserve(iNumTxMsgs);
169 
170     iFreeWnsrpCommandSave.reserve(iWNSRPTxWindow);
171     iActiveWnsrpCommandSave.reserve(iWNSRPTxWindow);
172 
173     iSrpCommandSave.T401Timer.SetFrequency(T401_RESOLUTION);
174     for (i = 0; i < iWNSRPTxWindow; i++)
175     {
176         iWnsrpCommandSave[i].T401Timer.SetFrequency(T401_RESOLUTION);
177         iFreeWnsrpCommandSave.push_back(&iWnsrpCommandSave[i]);
178     }
179 
180     //Temporary for now, should be called when tsc does a connect.
181     SrpStart();
182 }
183 
SrpReset(void)184 OSCL_EXPORT_REF void SRP::SrpReset(void)
185 {
186     //Temporary for now, should be called when tsc does a disconnect.
187     SrpStop();
188 
189     OsclRefCounterMemFrag temp;
190     iSrpNsrpEntryNumFrag = temp;
191     iWnsrpEntryNumFrag = temp;
192 
193     iActiveWnsrpCommandSave.clear();
194     iFreeWnsrpCommandSave.clear();
195 
196     iMTEntryNumAllocator.clear();
197     iHdrAllocator.clear();
198     iCcsrlAllocator.clear();
199     iFCSAllocator.clear();
200 
201     if (iTxPacketAlloc)
202     {
203         iTxPacketAlloc->removeRef();
204         iTxPacketAlloc = NULL;
205     }
206 
207     if (iTxMediaDataImplMemAlloc)
208     {
209         OSCL_DELETE(iTxMediaDataImplMemAlloc);
210         iTxMediaDataImplMemAlloc = NULL;
211     }
212 
213     if (iTxMediaMsgPoolAlloc)
214     {
215         OSCL_DELETE(iTxMediaMsgPoolAlloc);
216         iTxMediaMsgPoolAlloc = NULL;
217     }
218 
219     if (iOutstandingTxMediaDataImplMemAlloc)
220     {
221         OSCL_DELETE(iOutstandingTxMediaDataImplMemAlloc);
222         iOutstandingTxMediaDataImplMemAlloc = NULL;
223     }
224 
225     if (iOutstandingTxMediaMsgPoolAlloc)
226     {
227         OSCL_DELETE(iOutstandingTxMediaMsgPoolAlloc);
228         iOutstandingTxMediaMsgPoolAlloc = NULL;
229     }
230 
231     if (iRxPacketAlloc)
232     {
233         OSCL_DELETE(iRxPacketAlloc);
234         iRxPacketAlloc = NULL;
235     }
236 
237     if (iRxMediaDataImplMemAlloc)
238     {
239         OSCL_DELETE(iRxMediaDataImplMemAlloc);
240         iRxMediaDataImplMemAlloc = NULL;
241     }
242 
243     if (iRxMediaMsgPoolAlloc)
244     {
245         OSCL_DELETE(iRxMediaMsgPoolAlloc);
246         iRxMediaMsgPoolAlloc = NULL;
247     }
248 
249     if (iNsrpRespMemAlloc)
250     {
251         OSCL_DELETE(iNsrpRespMemAlloc);
252         iNsrpRespMemAlloc = NULL;
253     }
254 
255     if (iNsrpRespPacketAlloc)
256     {
257         OSCL_DELETE(iNsrpRespPacketAlloc);
258         iNsrpRespPacketAlloc = NULL;
259     }
260 
261     if (iRespMemAlloc)
262     {
263         OSCL_DELETE(iRespMemAlloc);
264         iRespMemAlloc = NULL;
265     }
266 
267     if (iRespPacketAlloc)
268     {
269         OSCL_DELETE(iRespPacketAlloc);
270         iRespPacketAlloc = NULL;
271     }
272 
273     if (iRespMediaMsgPoolAlloc)
274     {
275         OSCL_DELETE(iRespMediaMsgPoolAlloc);
276         iRespMediaMsgPoolAlloc = NULL;
277     }
278 
279     if (iWnsrpCommandSave)
280     {
281         OSCL_ARRAY_DELETE(iWnsrpCommandSave);
282         iWnsrpCommandSave = NULL;
283     }
284 
285     if (iRxFrags)
286     {
287         OSCL_ARRAY_DELETE(iRxFrags);
288         iRxFrags = NULL;
289     }
290 
291     if (iLLPortOut)
292     {
293         OSCL_DELETE(iLLPortOut);
294         iLLPortOut = NULL;
295     }
296 
297     if (iLLPortIn)
298     {
299         OSCL_DELETE(iLLPortIn);
300         iLLPortIn = NULL;
301     }
302 
303     if (iULPortOut)
304     {
305         OSCL_DELETE(iULPortOut);
306         iULPortOut = NULL;
307     }
308 
309     if (iULPortIn)
310     {
311         OSCL_DELETE(iULPortIn);
312         iULPortIn = NULL;
313     }
314 
315     WnsrpStatusSet(WNSRP_TX_SUPPORT);
316     iHandleWNSRP = true;
317 }
318 
319 
SrpStart(void)320 OSCL_EXPORT_REF void SRP::SrpStart(void)
321 {
322     SrpResetStats();
323 
324     iFirstCmd = true;
325 
326     /* Clear receive sequence number */
327     SrpRecvSeqClear();
328     /* Clear send sequence number */
329     SrpSendSeqClear();
330 
331     /* Clear WNSRP retry counter */
332     SrpN402Initialize();
333     /* Set status */
334     SrpStatusSet(STS_IDLE);
335 }
336 
SrpStop(void)337 OSCL_EXPORT_REF void SRP::SrpStop(void)
338 {
339     SRPRxData *pendingRxFrag;
340 
341     // Cancel any outstanding timer events
342     if (iSrpCommandSave.isTimerActive)
343     {
344         SrpT401Stop(iSrpCommandSave);
345         iSrpCommandSave.pPkt.Unbind();
346     }
347 
348     //Clear all WNSRP resp timers
349     while (!iActiveWnsrpCommandSave.empty())
350     {
351         // Stop response wait timer
352         SrpT401Stop(*iActiveWnsrpCommandSave[0]);
353 
354         // Release packet
355         iActiveWnsrpCommandSave[0]->pPkt.Unbind();
356 
357         // Remove timer from active list
358         RemoveActiveWnsrpTimer(iActiveWnsrpCommandSave[0]);
359     }
360 
361     WnsrpStatusSet(WNSRP_TX_SUPPORT);
362 
363     // Flush the queue
364     iSrpWaitQueue.clear();
365 
366     // Clear pending received packet.
367     while (iPendingRxFragList)
368     {
369         pendingRxFrag = iPendingRxFragList;
370         iPendingRxFragList = iPendingRxFragList->next;
371         FreeRxFrag(pendingRxFrag);
372     }
373 
374 
375     /* AR: Switch back to SRP mode */
376     iUseNSRP = false;
377 
378     /* Print iStats */
379     SRPStats tempStats;
380     SrpGetStats(tempStats);
381 
382     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "SRP Stats:"));
383     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "Total frames recv %d", tempStats.totalFramesRecv));
384     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "Invalid size frames recv %d", tempStats.totalInvalidSizeFramesRecv));
385     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "CRC errors recv %d", tempStats.totalCRCErrorsRecv));
386     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "Cmd frames recv %d", tempStats.totalCommandFramesRecv));
387     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "Cmd WNSRP frames recv %d", tempStats.totalWNSRPCommandFramesRecv));
388     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "Invalid CCSRL chunk recv %d", tempStats.totalInvalidCCSRLChunkRecv));
389     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "SRP resp recv %d", tempStats.totalSRPRespRecv));
390     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "NSRP resp recv %d", tempStats.totalNSRPRespRecv));
391     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "WNSRP resp recv %d", tempStats.totalWNSRPRespRecv));
392     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "H245 messages recv %d", tempStats.totalH245MessagesRecv));
393     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "CCSRL chunks recv %d", tempStats.totalCCSRLChunksRecv));
394     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "Cmd frames sent %d", tempStats.totalCommandFramesSent));
395     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "H245 messages to send %d", tempStats.totalH245MessagesToSend));
396     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "H245 messages fragmented %d", tempStats.totalH245MessagesFragmented));
397     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "CCSRL chunks sent %d", tempStats.totalCCSRLChunksSent));
398     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "Num of timeouts %d", tempStats.totalNumTimeouts));
399     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "Bytes recv %d", tempStats.totalBytesRecv));
400     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "Bytes sent %d", tempStats.totalBytesSent));
401     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "Invalid frames %d", tempStats.totalInvalidFrames));
402     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "Min response time %d", tempStats.minRespTime));
403     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "Max response time %d", tempStats.maxRespTime));
404     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STATISTIC, (0x40000020, "Ave response time %d", tempStats.aveRespTime));
405 }
406 
407 /************************************************************************/
408 /*  function name       : SrpGetEventNoFromAL1                          */
409 /*  function outline    : decide event number from received PDU         */
410 /*                                                          (H.223 AL1) */
411 /*  function discription: INT SrpGetEventNoFromAL1(                     */
412 /*                                  PVMFSharedMediaDataPtr pPkt )       */
413 /*  input data          : pPkt - pointer of received packet             */
414 /*  output data         : event number                                  */
415 /*  draw time           : '96.10.29                                     */
416 /*----------------------------------------------------------------------*/
417 /*  amendent career     :                                               */
418 /*                          Copyright (C) 1996 NTT DoCoMo               */
419 /************************************************************************/
SrpGetEventNoFromAL1(PVMFSharedMediaDataPtr pPkt)420 SRP::SrpEvent SRP::SrpGetEventNoFromAL1(PVMFSharedMediaDataPtr pPkt)
421 {
422     SrpEvent EventNo = EV_NOP;
423     uint8 *pFrame;
424     uint8 CrcWork[2];
425     OsclRefCounterMemFrag frag;
426     OsclSharedPtr<PVMFMediaDataImpl> data;
427     uint16 Crc16Check(PVMFSharedMediaDataPtr aData);
428 
429     if (pPkt->getNumFragments() != 1)
430     {
431         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_VERBOSE, (0x40000020, "SRP:SrpGetEventNoFromAL1 - fragments not equal to 1, num frags %d", pPkt->getNumFragments()));
432         return EventNo;
433     }
434 
435     if (pPkt->getFilledSize() >= MINIMUM_FRAME_SIZE)
436     {
437         pPkt->getMediaDataImpl(data);
438 
439         CrcClear();
440         CrcSetToFrame(iCrc.Crc16Check(data, true), &CrcWork[0]);
441 
442         pPkt->getMediaFragment(0, frag);
443         pFrame = (uint8 *) frag.getMemFragPtr();
444 
445         if ((CrcWork[0] == pFrame[pPkt->getFilledSize()-SRP_FCS_SIZE]) &&
446                 (CrcWork[1] == pFrame[pPkt->getFilledSize()-SRP_FCS_SIZE+1]))
447         {
448             switch (pFrame[0])
449             {
450                 case SRP_COMMAND_HEADER:
451                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP:SrpGetEventNoFromAL1 - SRP_COMMAND_HEADER, seq num %d", pFrame[1]));
452 
453                     //Disable WNSRP if 1st command frame does not start with seq num 0
454                     if ((WnsrpStatusGet() == WNSRP_TX_SUPPORT) &&
455                             iFirstCmd &&
456                             (pFrame[1] != 0))
457                     {
458                         WnsrpStatusSet(NO_WNSRP_SUPPORT);
459                     }
460 
461                     iStats.totalCommandFramesRecv++;
462 
463                     pPkt->setSeqNum((uint32) pFrame[1]);
464 
465                     //If using CCSRL method.
466                     if (iCcsrlSduSize > 0)
467                     {
468                         //Check if is a valid CCSRL chunk.
469                         if ((pFrame[2] == INTERMEDIATE_CCSRL_CHUNK) || (pFrame[2] == LAST_CCSRL_CHUNK))
470                         {
471                             EventNo = EV_COMMAND;
472                         }
473                         else
474                         {
475                             // Record invalid CCSRL chunk
476                             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP: Invalid CCSRL Chunk"));
477                             iStats.totalInvalidCCSRLChunkRecv++;
478                         }
479                     }
480                     //Else not using CCSRL method
481                     else
482                     {
483                         EventNo = EV_COMMAND;
484                     }
485 
486                     break;
487 
488                 case SRP_RESPONSE_HEADER: // No sequence number in SRP responses
489                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP:SrpGetEventNoFromAL1 - SRP_RESPONSE_HEADER"));
490 
491                     if (WnsrpStatusGet() == WNSRP_TX_SUPPORT)
492                     {
493                         SrpN402Count();
494                         if (SrpN402Check() == false)
495                         {
496                             WnsrpStatusSet(NO_WNSRP_SUPPORT);
497                         }
498                     }
499 
500                     iStats.totalSRPRespRecv++;
501 
502                     // If using NSRP
503                     if (iUseNSRP)
504                     {
505                         // If we haven't received an NSRP response yet, keep accepting SRP responses.
506                         if (!iFirstNSRPResp)
507                         {
508                             EventNo = EV_RESPONSE;
509                         }
510                     }
511                     // Else not using NSRP
512                     else
513                     {
514                         EventNo = EV_RESPONSE;
515                     }
516                     break;
517 
518                 case NSRP_RESPONSE_HEADER:
519                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP:SrpGetEventNoFromAL1 - NSRP_RESPONSE_HEADER, seq num %d", pFrame[1]));
520 
521                     if (WnsrpStatusGet() == WNSRP_TX_SUPPORT)
522                     {
523                         SrpN402Count();
524                         if (SrpN402Check() == false)
525                         {
526                             WnsrpStatusSet(NO_WNSRP_SUPPORT);
527                         }
528                     }
529 
530                     iStats.totalNSRPRespRecv++;
531 
532                     // If using NSRP, check sequence number.
533                     if (iUseNSRP)
534                     {
535                         pPkt->setSeqNum((uint32) pFrame[1]);
536 
537                         if (!iFirstNSRPResp)
538                         {
539                             iFirstNSRPResp = true;
540                         }
541 
542                         EventNo = EV_NSRP_RESPONSE;
543                     }
544                     //Else using SRP, just accept as a valid SRP response frame
545                     else
546                     {
547                         EventNo = EV_RESPONSE;
548                     }
549                     break;
550 
551                 case WNSRP_COMMAND_HEADER:
552                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP:SrpGetEventNoFromAL1 - WNSRP_COMMAND_HEADER, status %d, seq num %d", WnsrpStatusGet(), pFrame[1]));
553 
554                     if (!iHandleWNSRP)
555                     {
556                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_WARNING, (0x40000020, "SRP:SrpGetEventNoFromAL1 - WNSRP_COMMAND_HEADER, not handling WNSRP frames"));
557                         break;
558                     }
559 
560                     iStats.totalWNSRPCommandFramesRecv++;
561 
562                     pPkt->setSeqNum((uint32) pFrame[1]);
563 
564                     switch (WnsrpStatusGet())
565                     {
566                         case WNSRP_TX_SUPPORT:
567                             WnsrpStatusSet(WNSRP_FULL_SUPPORT);
568                             //Fall into next case.
569 
570                         case WNSRP_FULL_SUPPORT:
571                             //If using CCSRL method.
572                             if (iCcsrlSduSize > 0)
573                             {
574                                 //Check if is a valid CCSRL chunk.
575                                 if ((pFrame[2] == INTERMEDIATE_CCSRL_CHUNK) || (pFrame[2] == LAST_CCSRL_CHUNK))
576                                 {
577                                     EventNo = EV_WNSRP_COMMAND;
578                                 }
579                                 else
580                                 {
581                                     // Record invalid CCSRL chunk
582                                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP: Invalid CCSRL Chunk"));
583                                     iStats.totalInvalidCCSRLChunkRecv++;
584                                 }
585                             }
586                             //Else not using CCSRL method
587                             else
588                             {
589                                 EventNo = EV_WNSRP_COMMAND;
590                             }
591 
592                             break;
593 
594                         case NO_WNSRP_SUPPORT:
595                             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_WARNING, (0x40000020, "SRP:SrpGetEventNoFromAL1 - no WNSRP support"));
596                             break;
597                     }
598 
599                     break;
600 
601                 case WNSRP_RESPONSE_HEADER:
602                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP:SrpGetEventNoFromAL1 - WNSRP_RESPONSE_HEADER, status %d, seq num %d", WnsrpStatusGet(), pFrame[1]));
603 
604                     if (!iHandleWNSRP)
605                     {
606                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_WARNING, (0x40000020, "SRP:SrpGetEventNoFromAL1 - WNSRP_COMMAND_HEADER, not handling WNSRP frames"));
607                         break;
608                     }
609 
610                     iStats.totalWNSRPRespRecv++;
611 
612                     switch (WnsrpStatusGet())
613                     {
614                         case WNSRP_TX_SUPPORT:
615                             WnsrpStatusSet(WNSRP_FULL_SUPPORT);
616                             //Fall into next case.
617 
618                         case WNSRP_FULL_SUPPORT:
619                             //Set sequence number of the response.
620                             pPkt->setSeqNum((uint32) pFrame[1]);
621 
622                             EventNo = EV_WNSRP_RESPONSE;
623                             break;
624 
625                         case NO_WNSRP_SUPPORT:
626                             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_WARNING, (0x40000020, "SRP:SrpGetEventNoFromAL1 - no WNSRP support"));
627                             break;
628                     }
629                     break;
630 
631                 default:
632                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP: Unknown SRP command %d", pFrame[0]));
633                     iStats.totalInvalidFrames++;
634                     break;
635             }
636         }
637         // CRC errors.
638         else
639         {
640             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP: CRC check failed"));
641             iStats.totalCRCErrorsRecv++;
642         }
643     }
644     else
645     {
646         // Record number of frames received that have an invalid size.
647         iStats.totalInvalidSizeFramesRecv++;
648     }
649 
650     return(EventNo) ;
651 }
652 
653 /************************************************************************/
654 /*  function name       : SrpStateChange                                */
655 /*  function outline    : decide function to call given the status and  */
656 /*                        event                                         */
657 /*  function discription: INT SrpGetEventNoFromAL1( void *data )        */
658 /*  input data          : status - Status of Srp                        */
659 /*                        event - Incoming event                        */
660 /*                        data - optional state change data             */
661 /*  output data         : None                                          */
662 /*  draw time           : '96.10.29                                     */
663 /*----------------------------------------------------------------------*/
664 /*  amendent career     :                                               */
665 /*                          Copyright (C) 1996 NTT DoCoMo               */
666 /************************************************************************/
SrpStateChange(int status,int event,void * data)667 int SRP::SrpStateChange(int status, int event, void *data)
668 {
669     switch (iSrpStateTable[status][event])
670     {
671         case ACTION_NOP:
672             return (SrpNop());
673         case ACTION_0_1:
674             return (Srp_0_1());
675         case ACTION_0_2:
676             return (Srp_0_2(*(PVMFSharedMediaDataPtr *) data, event));
677 
678 
679         case ACTION_1_1:
680             return (Srp_1_1());
681         case ACTION_1_3:
682             return (Srp_1_3(*(PVMFSharedMediaDataPtr *) data, event));
683         case ACTION_1_4:
684             return (Srp_1_4(*(int32 *) data));
685         default:
686             return 0;
687     }
688 }
689 
690 /************************************************************************/
691 /*  function name       : SrpN400Check                                  */
692 /*  function outline    : N400 counter check                            */
693 /*  function discription: INT  SrpN400Check(SRPRespTimer &timer)        */
694 /*  input data          : timer - timer to check                        */
695 /*  output data         : Check result                                  */
696 /*                         OK : Not count over                          */
697 /*                         NG : Count over                              */
698 /*  draw time           : '96.10.29                                     */
699 /*----------------------------------------------------------------------*/
700 /*  amendent career     :                                               */
701 /*                          Copyright (C) 1996 NTT DoCoMo               */
702 /************************************************************************/
SrpN400Check(SRPRespTimer & timer)703 int SRP::SrpN400Check(SRPRespTimer &timer)
704 {
705     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_VERBOSE, (0x40000020, "SRP::SrpN400Check - N400Counter=%d N400MaxCounter=%d", timer.N400Counter, iN400MaxCounter));
706 
707     if (timer.N400Counter < iN400MaxCounter)
708     {
709         return true;
710     }
711     else
712     {
713         return false;
714     }
715 }
716 
717 /************************************************************************/
718 /*  function name       : SrpN402Initialize                             */
719 /*  function outline    : N402 counter initialize                       */
720 /*  function discription: void SrpN402Initialize( void )                */
721 /*  input data          : None                                          */
722 /*  output data         : None                                          */
723 /*  draw time           : '05.08.23                                     */
724 /*----------------------------------------------------------------------*/
725 /*  amendent career     :                                               */
726 /*                          Copyright (C) 2005 PacketVideo Corp.        */
727 /************************************************************************/
SrpN402Initialize()728 void SRP::SrpN402Initialize()
729 {
730     /* Clear counter */
731     iN402Counter = 0 ;
732 }
733 
734 
735 /************************************************************************/
736 /*  function name       : SrpN402Check                                  */
737 /*  function outline    : N402 counter check                            */
738 /*  function discription: INT  SrpN402Check( void )                     */
739 /*  input data          : None                                          */
740 /*  output data         : Check result                                  */
741 /*                         OK : Not count over                          */
742 /*                         NG : Count over                              */
743 /*  draw time           : '05.08.23                                     */
744 /*----------------------------------------------------------------------*/
745 /*  amendent career     :                                               */
746 /*                          Copyright (C) 2005 PacketVideo Corp.        */
747 /************************************************************************/
SrpN402Check()748 int SRP::SrpN402Check()
749 {
750     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_VERBOSE, (0x40000020, "SRP::SrpN402Check - N402Counter=%d N402MaxCounter=%d", iN402Counter, iN402MaxCounter));
751 
752     if (iN402Counter < iN402MaxCounter)
753     {
754         return true;
755     }
756     else
757     {
758         return false;
759     }
760 }
761 
762 /************************************************************************/
763 /*  function name       : CrcCalc                                       */
764 /*  function outline    : CRC calculation                               */
765 /*  function discription: void CrcCalc( PUCHAR pData, int Size )        */
766 /*  input data          : pData - object data pointer                   */
767 /*                        Size  - object data size (octet length)       */
768 /*  output data         : None                                          */
769 /*  draw time           : '96.10.29                                     */
770 /*----------------------------------------------------------------------*/
771 /*  amendent career     :                                               */
772 /*                          Copyright (C) 1996 NTT DoCoMo               */
773 /************************************************************************/
CrcCalc(uint8 * pData,int Size)774 void SRP::CrcCalc(uint8 *pData, int Size)
775 {
776     int     BitCount;
777 
778     while (Size--)  /* process for all data */
779     {
780         for (BitCount = 0 ; BitCount < 8 ; BitCount++)  /* process for 8 bit data */
781         {
782             if ((iCrcData & 0x8000) != 0)   /* MSB=1? */
783             {
784                 iCrcData <<= 1;
785                 iCrcData |= ((*pData >> BitCount) & 0x01);
786                 iCrcData ^= GX_CRC_12;
787             }
788             else
789             {
790                 iCrcData <<= 1;
791                 iCrcData |= ((*pData >> BitCount) & 0x01);
792             }
793         }
794 
795         /* update pointer of data */
796         pData++;
797     }
798     return ;
799 }
800 
801 /************************************************************************/
802 /*  function name       : CrcResultGet                                  */
803 /*  function outline    : Get result of CRC calculation                 */
804 /*  function discription: USHORT CrcResultGet( void )                   */
805 /*  input data          : None                                          */
806 /*  output data         : Result of CRC Calculation                     */
807 /*  draw time           : '96.10.29                                     */
808 /*----------------------------------------------------------------------*/
809 /*  amendent career     :                                               */
810 /*                          Copyright (C) 1996 NTT DoCoMo               */
811 /************************************************************************/
CrcResultGet(void)812 uint16 SRP::CrcResultGet(void)
813 {
814     int BitCount;
815 
816     for (BitCount = 0 ; BitCount < 16 ; BitCount++)  /* process for 16bit */
817     {
818         if ((iCrcData & 0x8000) != 0)   /* MSB=1? */
819         {
820             iCrcData <<= 1;
821             iCrcData  ^= GX_CRC_12;
822         }
823         else
824         {
825             iCrcData <<= 1;
826         }
827     }
828     return((uint16)iCrcData) ;
829 }
830 
831 /************************************************************************/
832 /*  function name       : CrcSetToFrame                                 */
833 /*  function outline    : Set CRC data to FCS area of frame             */
834 /*  function discription: void CrcSetToFrame( USHORT Crc, PUCHAR pFcs ) */
835 /*  input data          : None                                          */
836 /*  output data         : Crc - CRC data                                */
837 /*                        pFcs - FCS data pointer                       */
838 /*  draw time           : '96.10.29                                     */
839 /*----------------------------------------------------------------------*/
840 /*  amendent career     :                                               */
841 /*                          Copyright (C) 1996 NTT DoCoMo               */
842 /************************************************************************/
CrcSetToFrame(uint16 crc,uint8 * pFcs)843 void SRP::CrcSetToFrame(uint16 crc, uint8 *pFcs)
844 {
845 
846     /* Clear first fcs octet */
847     *pFcs = 0;
848 
849     *pFcs = (uint8)(crc & 0x00ff);
850     pFcs++;
851     *pFcs = (uint8)((crc & 0xff00) >> 8);
852 
853     return ;
854 }
855 
856 /************************************************************************/
857 /*  function name       : SrpCommandCreate                              */
858 /*  function outline    : Create command frame                          */
859 /*  function discription: void SrpCommandCreate(                        */
860 /*                                    PVMFSharedMediaDataPtr pPkt )     */
861 /*  input data          : pPkt - data packet to create SRP command frame*/
862 /*  output data         : None                                          */
863 /*  draw time           : '05.08.24                                     */
864 /*----------------------------------------------------------------------*/
865 /*  amendent career     :                                               */
866 /*                          Copyright (C) 2005 PacketVideo Corp.        */
867 /************************************************************************/
SrpCommandCreate(PVMFSharedMediaDataPtr pPkt,uint8 header)868 PVMFSharedMediaDataPtr SRP::SrpCommandCreate(PVMFSharedMediaDataPtr pPkt, uint8 header)
869 {
870     uint16 crc;
871     uint16 Crc16Check(PVMFSharedMediaDataPtr aData);
872     int32 error = OsclErrNone;
873     OsclSharedPtr<PVMFMediaDataImpl> srpPkt;
874     PVMFSharedMediaDataPtr txData;
875     OsclRefCounterMemFrag headerFrag;
876     OsclRefCounterMemFrag FCSFrag;
877 
878     OSCL_UNUSED_ARG(error);
879     switch (header)
880     {
881         case SRP_COMMAND_HEADER:
882         case WNSRP_COMMAND_HEADER:
883             srpPkt = iTxPacketAlloc->allocate();
884             if (!srpPkt)
885             {
886                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR,
887                                 (0x40000020, "SRP::SrpCommandCreate - Unable allocate tx media impl %d", error));
888                 return txData;
889             }
890             break;
891 
892         default:
893             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::SrpCommandCreate - Unable command type %x", header));
894             return txData;
895 
896     }
897 
898     // Allocate header fragment.
899     headerFrag = iHdrAllocator.get();
900     if (headerFrag.getMemFragPtr() == NULL)
901     {
902         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::SrpCommandCreate Unable to allocate header frag %d", error));
903         return txData;
904     }
905 
906 
907     // Allocate fcs fragment.
908     FCSFrag = iFCSAllocator.get();
909     if (FCSFrag.getMemFragPtr() == NULL)
910     {
911         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::SrpCommandCreate Unable to allocate FCS frag %d", error));
912         return txData;
913     }
914 
915 
916     //Set header value
917     *(uint8 *) headerFrag.getMemFragPtr() = header;
918     headerFrag.getMemFrag().len = SRP_HEADER_SIZE;
919 
920     // Add header to the front of the packet.
921     srpPkt->appendMediaFragment(headerFrag);
922 
923     // Add data fragments
924     for (uint32 i = 0; i < pPkt->getNumFragments(); i++)
925     {
926         pPkt->getMediaFragment(i, headerFrag);
927         srpPkt->appendMediaFragment(headerFrag);
928     }
929 
930     // Initialize crc calcuration
931     CrcClear();
932     // Calculate crc
933     crc = iCrc.Crc16Check(srpPkt);   // 16bit CRC Infomation Create
934 
935     // Set crc to fcs
936     CrcSetToFrame(crc, (uint8 *) FCSFrag.getMemFragPtr());
937     FCSFrag.getMemFrag().len = SRP_FCS_SIZE;
938 
939     // Add CRC to the end of the packet.
940     srpPkt->appendMediaFragment(FCSFrag);
941 
942     txData = PVMFMediaData::createMediaData(srpPkt, iOutstandingTxMediaMsgPoolAlloc);
943     if (!txData)
944     {
945         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::SrpCommandCreate - Unable allocate tx message %d", error))
946         return txData;
947     }
948     //If SRP
949     if (header == SRP_COMMAND_HEADER)
950     {
951         txData->setFormatSpecificInfo(iSrpNsrpEntryNumFrag);
952     }
953     //Else WNSRP
954     else
955     {
956         txData->setFormatSpecificInfo(iWnsrpEntryNumFrag);
957     }
958 
959     // Set sequence number
960     txData->setSeqNum(pPkt->getSeqNum());
961 
962     iStats.totalCCSRLChunksSent++;
963     iStats.totalCommandFramesSent++;
964 
965     /* Record initial time when chunk is sent. */
966     iInitialTimeChunkSent.set_to_current_time();
967 
968     return txData;
969 }
970 
971 /************************************************************************/
972 /*  function name       : SrpCommandClear                               */
973 /*  function outline    : Clear comand frame for re-transmittion        */
974 /*  function discription: void SrpCommandClear(SRPRespTimer &timer)     */
975 /*  input data          : timer - response timer that hold frame to be  */
976 /*                                retransmitted.                        */
977 /*  output data         : None                                          */
978 /*  draw time           : '05.08.24                                     */
979 /*----------------------------------------------------------------------*/
980 /*  amendent career     :                                               */
981 /*                          Copyright (C) 2005 PacketVideo Corp.        */
982 /************************************************************************/
SrpCommandClear(uint32 seqNum)983 void SRP::SrpCommandClear(uint32 seqNum)
984 {
985     uint32 i;
986 
987     //Find packet with same sequence number in wait queue and remove
988     for (i = 0; i < iSrpWaitQueue.size(); i++)
989     {
990         if (iSrpWaitQueue[i]->getSeqNum() == seqNum)
991         {
992             iSrpWaitQueue.erase(&iSrpWaitQueue[i]);
993             return;
994         }
995     }
996 
997     return;
998 }
999 
1000 /************************************************************************/
1001 /*  function name       : SrpResponseCreate                             */
1002 /*  function outline    : Create response frame                         */
1003 /*  function discription: void SrpResponseCreate( uint8 seqNum )        */
1004 /*  input data          : seqNum - Sequence number of response frame    */
1005 /*                        header - SRP response frame type              */
1006 /*  output data         : pointer to created response packet            */
1007 /*  draw time           : '96.10.29                                     */
1008 /*----------------------------------------------------------------------*/
1009 /*  amendent career     :                                               */
1010 /*                          Copyright (C) 1996 NTT DoCoMo               */
1011 /************************************************************************/
SrpResponseCreate(uint8 seqNum,uint8 header)1012 PVMFSharedMediaDataPtr SRP::SrpResponseCreate(uint8 seqNum, uint8 header)
1013 {
1014     OsclSharedPtr<PVMFMediaDataImpl> resp;
1015     PVMFSharedMediaDataPtr mediaData;
1016     int32 error = OsclErrNone;
1017     uint8* pEditPtr;
1018     uint16 crc;
1019     uint16 Crc16Check(uint8 *, uint16);
1020     OsclRefCounterMemFrag frag;
1021 
1022     OSCL_UNUSED_ARG(error);
1023 
1024     switch (header)
1025     {
1026         case NSRP_RESPONSE_HEADER:
1027         case WNSRP_RESPONSE_HEADER:
1028             resp = iNsrpRespPacketAlloc->allocate(SRP_HEADER_SIZE + SRP_FCS_SIZE + SRP_SEQUENCE_SIZE); /* WWU_NSRP */
1029             break;
1030 
1031         case SRP_RESPONSE_HEADER:
1032             resp = iRespPacketAlloc->allocate(SRP_HEADER_SIZE + SRP_FCS_SIZE); /* SRP */
1033             break;
1034 
1035         default:
1036             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::SrpResponseCreate - Unknown response type %d", header));
1037             return mediaData;
1038     }
1039 
1040     //Unable to allocate fragment.
1041     if (!resp)
1042     {
1043         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::SrpResponseCreate - Unable to allocate fragment %d", error));
1044         return mediaData;
1045     }
1046 
1047     resp->getMediaFragment(0, frag);
1048 
1049     pEditPtr = (uint8 *) frag.getMemFragPtr();
1050 
1051     /* Initialize crc calcuration */
1052     CrcClear() ;
1053 
1054     /* Set header octet */
1055     switch (header)
1056     {
1057         case NSRP_RESPONSE_HEADER:
1058         case WNSRP_RESPONSE_HEADER:
1059             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_VERBOSE, (0x40000020, "SRP::SrpResponseCreate - Sending NSRP or WNSRP Response, SeqNum = %d", seqNum));
1060             *pEditPtr++ = header;
1061             *pEditPtr++ = seqNum;
1062             resp->setMediaFragFilledLen(0, SRP_HEADER_SIZE + SRP_FCS_SIZE + SRP_SEQUENCE_SIZE);
1063             crc = iCrc.Crc16Check((uint8 *) frag.getMemFragPtr(), SRP_HEADER_SIZE + SRP_SEQUENCE_SIZE);      /* 16bit CRC Infomation Create     */
1064             break;
1065 
1066         case SRP_RESPONSE_HEADER:
1067             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_VERBOSE, (0x40000020, "SRP::SrpResponseCreate - Sending SRP Response"));
1068             *pEditPtr++ = header;
1069             resp->setMediaFragFilledLen(0, SRP_HEADER_SIZE + SRP_FCS_SIZE);
1070             crc = iCrc.Crc16Check((uint8 *) frag.getMemFragPtr(), SRP_HEADER_SIZE);       /* 16bit CRC Infomation Create        */
1071             break;
1072 
1073         default:
1074             return mediaData;
1075     }
1076 
1077     /* Set crc to fcs */
1078     CrcSetToFrame(crc, pEditPtr) ;
1079 
1080     mediaData = PVMFMediaData::createMediaData(resp, iRespMediaMsgPoolAlloc);
1081     if (!mediaData)
1082     {
1083         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::SrpResponseCreate - Unable to allocate msg %d", error));
1084         return mediaData;
1085     }
1086     mediaData->setSeqNum((uint32) seqNum);
1087     //If SRP
1088     switch (header)
1089     {
1090         case NSRP_RESPONSE_HEADER:
1091         case SRP_RESPONSE_HEADER:
1092             mediaData->setFormatSpecificInfo(iSrpNsrpEntryNumFrag);
1093             break;
1094 
1095         case WNSRP_RESPONSE_HEADER:
1096             mediaData->setFormatSpecificInfo(iWnsrpEntryNumFrag);
1097             break;
1098     }
1099 
1100     return mediaData;
1101 }
1102 
1103 /************************************************************************/
1104 /*  function name       : SrpMsgCopy                                    */
1105 /*  function outline    : Get SRP data from in packet and put it in the */
1106 /*                        out packet.                                   */
1107 /*  function discription: bool SrpMsgCopy(                              */
1108 /*                                      PVMFSharedMediaDataPtr inPkt)   */
1109 /*  input data          : inPkt - Pointer to incoming packet.           */
1110 /*                        outPkt - Pointer to outgoing packet.          */
1111 /*  output data         : None                                          */
1112 /*  draw time           : '96.10.29                                     */
1113 /*----------------------------------------------------------------------*/
1114 /*  amendent career     :                                               */
1115 /*                          Copyright (C) 1996 NTT DoCoMo               */
1116 /************************************************************************/
SrpMsgCopy(PVMFSharedMediaDataPtr inPkt)1117 bool SRP::SrpMsgCopy(PVMFSharedMediaDataPtr inPkt)
1118 {
1119     OsclRefCounterMemFrag frag;
1120     OsclSharedPtr<PVMFMediaDataImpl> data;
1121     SRPRxData *rxData;
1122     int32 error = OsclErrNone;
1123     OSCL_UNUSED_ARG(error);
1124     uint8 *pData;
1125     uint8* pFragPos = NULL;
1126     int fragLen = 0;
1127 
1128     inPkt->getMediaFragment(0, frag);
1129 
1130     pData = ((uint8 *) frag.getMemFragPtr()) + SRP_HEADER_SIZE + SRP_SEQUENCE_SIZE;
1131 
1132     //If using CCSRL method.
1133     if (iCcsrlSduSize > 0)
1134     {
1135         iStats.totalCCSRLChunksRecv++;
1136         pFragPos = pData + CCSRL_HEADER_SIZE;
1137         fragLen = frag.getMemFragSize() - SRP_HEADER_SIZE - SRP_SEQUENCE_SIZE - CCSRL_HEADER_SIZE - SRP_FCS_SIZE;
1138     }
1139     else
1140     {
1141         pFragPos = pData;
1142         fragLen = frag.getMemFragSize() - SRP_HEADER_SIZE - SRP_SEQUENCE_SIZE - SRP_FCS_SIZE;
1143     }
1144 
1145     //Data to large.  Pass up whatever is buffered in receive packet
1146     if (fragLen > MAX_SIZE_OF_SRP_PDU)
1147     {
1148         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::SrpMsgCopy - incoming data to large to copy %d, max %d", fragLen, MAX_SIZE_OF_SRP_PDU));
1149         return false;
1150     }
1151 
1152     rxData = GetRxFrag();
1153 
1154     if (rxData == NULL)
1155     {
1156         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::SrpMsgCopy - unable to allocate rx data frag %d", error));
1157         return false;
1158     }
1159 
1160     if (!AllocateRxPacket(data, rxData))
1161         return 0;
1162     if (!CreateMediaData(rxData, data))
1163         return 0;
1164     rxData->data->getMediaFragment(0, frag);
1165     oscl_memcpy(frag.getMemFragPtr(), pFragPos, fragLen);
1166     rxData->data->setMediaFragFilledLen(0, fragLen);
1167 
1168     rxData->seqNum = (uint8) inPkt->getSeqNum();
1169 
1170     if (iCcsrlSduSize > 0)
1171     {
1172         // Return true if last CCSRL fragment in original H245 packet.
1173         data->setMarkerInfo(((*pData == LAST_CCSRL_CHUNK) ? true : false));
1174     }
1175     else
1176     {
1177         data->setMarkerInfo(true);
1178     }
1179 
1180     //Add to rx pending list
1181     AddPendingRxFrag(rxData);
1182 
1183     return true;
1184 }
1185 
AllocateRxPacket(OsclSharedPtr<PVMFMediaDataImpl> & data,SRPRxData * rxData)1186 bool SRP::AllocateRxPacket(OsclSharedPtr<PVMFMediaDataImpl>& data, SRPRxData* rxData)
1187 {
1188     data = iRxPacketAlloc->allocate(MAX_SIZE_OF_SRP_PDU);
1189     if (!data)
1190     {
1191         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::SrpMsgCopy - Unable allocate rx message impl"));
1192         FreeRxFrag(rxData);
1193         return false;
1194     }
1195     return true;
1196 
1197 }
CreateMediaData(SRPRxData * rxData,OsclSharedPtr<PVMFMediaDataImpl> data)1198 bool SRP::CreateMediaData(SRPRxData* rxData, OsclSharedPtr<PVMFMediaDataImpl> data)
1199 {
1200     rxData->data = PVMFMediaData::createMediaData(data, iRxMediaMsgPoolAlloc);
1201     if (!(rxData->data))
1202     {
1203         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::SrpMsgCopy - Unable allocate rx message"));
1204         FreeRxFrag(rxData);
1205         return false;
1206     }
1207     return true;
1208 
1209 }
1210 
1211 
CreateMediaData(PVMFSharedMediaDataPtr & srpPkt,OsclSharedPtr<PVMFMediaDataImpl> data)1212 bool SRP::CreateMediaData(PVMFSharedMediaDataPtr& srpPkt,
1213                           OsclSharedPtr<PVMFMediaDataImpl> data)
1214 {
1215     srpPkt = PVMFMediaData::createMediaData(data, iTxMediaMsgPoolAlloc);
1216     if (!srpPkt)
1217     {
1218         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR,
1219                         (0x40000020, "SRP::UpperLayerRx - Unable allocate tx message"));
1220         return false;
1221     }
1222     return true;
1223 }
1224 
1225 /************************************************************************/
1226 /*  function name       : Srp_0_1                                       */
1227 /*  function outline    : PDU received in IDLE                          */
1228 /*  function discription: PVMFSharedMediaDataPtr Srp_0_1()              */
1229 /*  input data          : pPkt - pointer of received packet from corder */
1230 /*  output data         : None                                          */
1231 /*  draw time           : '96.10.29                                     */
1232 /*----------------------------------------------------------------------*/
1233 /*  amendent career     :                                               */
1234 /*                          Copyright (C) 1996 NTT DoCoMo               */
1235 /************************************************************************/
Srp_0_1()1236 int SRP::Srp_0_1()
1237 {
1238     PVMFSharedMediaDataPtr pSrpCommandPkt;
1239     PVMFSharedMediaDataPtr pTxPkt;
1240     PVMFSharedMediaDataPtr pFirstPkt;
1241     SRPRespTimer *pTimer;
1242 
1243     switch (WnsrpStatusGet())
1244     {
1245         case NO_WNSRP_SUPPORT:
1246         case WNSRP_TX_SUPPORT:
1247             pFirstPkt = SrpSendWaitGet(0);
1248 
1249             /* Create SRP command */
1250             pTxPkt = SrpCommandCreate(pFirstPkt, SRP_COMMAND_HEADER);
1251 
1252             /* If packet could not be created. */
1253             if (pTxPkt.GetRep() == NULL)
1254             {
1255                 return(0);
1256             }
1257 
1258             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::Srp_0_1 - lowerlayertx srp cmd seq num %d", pTxPkt->getSeqNum()));
1259 
1260             /* Send SRP command */
1261             LowerLayerTx(pTxPkt);
1262             /* Start response wait timer */
1263             SrpT401Start(iSrpCommandSave, pTxPkt);
1264 
1265             if (WnsrpStatusGet() == NO_WNSRP_SUPPORT) break;
1266             //If tx support only, must send srp frame also.
1267 
1268         case WNSRP_FULL_SUPPORT:
1269             while (!iFreeWnsrpCommandSave.empty() &&
1270                     (iActiveWnsrpCommandSave.size() < iSrpWaitQueue.size()))
1271             {
1272                 pSrpCommandPkt = SrpSendWaitGet(iActiveWnsrpCommandSave.size());
1273 
1274                 //No more outstanding frags to send
1275                 if (pSrpCommandPkt.GetRep() == NULL)
1276                 {
1277                     break;
1278                 }
1279 
1280                 /* Create WNSRP command */
1281                 pTxPkt = SrpCommandCreate(pSrpCommandPkt, WNSRP_COMMAND_HEADER);
1282 
1283                 /* If packet could not be created. */
1284                 if (pTxPkt.GetRep() == NULL)
1285                 {
1286                     return(0);
1287                 }
1288 
1289                 pTimer = GetFreeWnsrpTimer();
1290 
1291                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::Srp_0_1 - lowerlayertx wnsrp cmd seq num %d", pTxPkt->getSeqNum()));
1292 
1293                 /* Send SRP command */
1294                 LowerLayerTx(pTxPkt);
1295                 /* Start response wait timer */
1296                 SrpT401Start(*pTimer, pTxPkt);
1297 
1298                 AddActiveWnsrpTimer(pTimer);
1299             }
1300 
1301             break;
1302 
1303         default:
1304             break;
1305     }
1306 
1307     /* Set status */
1308     SrpStatusSet(STS_WAIT_RESPONSE);
1309     return (1);
1310 }
1311 
1312 /************************************************************************/
1313 /*  function name       : Srp_0_2                                       */
1314 /*  function outline    : SRP command received                          */
1315 /*                                    in IDLE or WAITING-RESPONSE       */
1316 /*  function discription: PVMFSharedMediaDataPtr Srp_0_2(               */
1317 /*                                      PVMFSharedMediaDataPtr pPkt )   */
1318 /*  input data          : pPkt - pointer of received packet from AL1C   */
1319 /*  output data         : None                                          */
1320 /*  draw time           : '96.10.29                                     */
1321 /*----------------------------------------------------------------------*/
1322 /*  amendent career     :                                               */
1323 /*                          Copyright (C) 1996 NTT DoCoMo               */
1324 /************************************************************************/
Srp_0_2(PVMFSharedMediaDataPtr pPkt,int event)1325 int SRP::Srp_0_2(PVMFSharedMediaDataPtr pPkt, int event)
1326 {
1327     PVMFSharedMediaDataPtr resp;
1328     OsclRefCounterMemFrag frag;
1329     SRPRxData *rxData;
1330     uint8 header;
1331 
1332     //If WNSRP command
1333     if (event == EV_WNSRP_COMMAND)
1334     {
1335         header = WNSRP_RESPONSE_HEADER;
1336     }
1337     //Else SRP command
1338     else
1339     {
1340         if (iUseNSRP)
1341         {
1342             header = NSRP_RESPONSE_HEADER;
1343         }
1344         else
1345         {
1346             header = SRP_RESPONSE_HEADER;
1347         }
1348     }
1349 
1350     if (iFirstCmd)
1351     {
1352         //WNSRP must always start with 0
1353         if (event == EV_WNSRP_COMMAND)
1354         {
1355             SrpRecvSeqSet(0);
1356         }
1357         else
1358         {
1359             SrpRecvSeqSet((uint8) pPkt->getSeqNum());
1360         }
1361 
1362         iFirstCmd = false;
1363     }
1364 
1365     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_VERBOSE, (0x40000020, "SRP::Srp_0_2 - Incoming SequenceNumber = %d", pPkt->getSeqNum()));
1366 
1367     if (CheckRxSeqNum(pPkt->getSeqNum(), header))
1368     {
1369         if (!SrpMsgCopy(pPkt))
1370         {
1371             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::Srp_0_2 - Unable to copy data"));
1372             return 0;
1373         }
1374 
1375         // Create SRP response
1376         resp = SrpResponseCreate((uint8) pPkt->getSeqNum(), header);
1377         if (resp.GetRep() == NULL)
1378         {
1379             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::Srp_0_2 - Unable create reponse packet"));
1380             /* If unable to create response message. */
1381             return 0;
1382         }
1383 
1384         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::Srp_0_2 - lowerlayertx srp resp seq num %d", resp->getSeqNum()));
1385 
1386         // SRP response send
1387         LowerLayerTx(resp);
1388 
1389         // Check for full H245 messages
1390         while (iPendingRxFragList &&
1391                 (iPendingRxFragList->seqNum == SrpRecvSeqGet()))
1392         {
1393             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::Srp_0_2 - upperlayertx last frag %d", iPendingRxFragList->data->getMarkerInfo()));
1394 
1395             UpperLayerTx(iPendingRxFragList->data);
1396 
1397             rxData = iPendingRxFragList;
1398             iPendingRxFragList = iPendingRxFragList->next;
1399 
1400             FreeRxFrag(rxData);
1401 
1402             SrpRecvSeqCount();
1403         }
1404     }
1405 
1406     return 1;
1407 }
1408 
1409 /************************************************************************/
1410 /*  function name       : Srp_1_1                                       */
1411 /*  function outline    : PDU received from corder in WAITING-RESPONSE  */
1412 /*  function discription: PVMFSharedMediaDataPtr Srp_1_1()              */
1413 /*  input data          : pPkt - pointer of received packet from corder */
1414 /*  output data         : None                                          */
1415 /*  draw time           : '96.10.29                                     */
1416 /*----------------------------------------------------------------------*/
1417 /*  amendent career     :                                               */
1418 /*                          Copyright (C) 1996 NTT DoCoMo               */
1419 /************************************************************************/
Srp_1_1()1420 int SRP::Srp_1_1()
1421 {
1422     PVMFSharedMediaDataPtr pTxPkt;
1423     SRPRespTimer *pTimer;
1424 
1425     switch (WnsrpStatusGet())
1426     {
1427         case NO_WNSRP_SUPPORT:
1428             //SRP mode, cannot send until response for last packet is received.
1429             break;
1430 
1431         case WNSRP_TX_SUPPORT:
1432         case WNSRP_FULL_SUPPORT:
1433             while (!iFreeWnsrpCommandSave.empty() &&
1434                     (iActiveWnsrpCommandSave.size() < iSrpWaitQueue.size()))
1435             {
1436                 /* Create WNSRP command */
1437                 pTxPkt = SrpCommandCreate(SrpSendWaitGet(iActiveWnsrpCommandSave.size()), WNSRP_COMMAND_HEADER);
1438 
1439                 /* If packet could not be created. */
1440                 if (pTxPkt.GetRep() == NULL)
1441                 {
1442                     return(0);
1443                 }
1444 
1445                 pTimer = GetFreeWnsrpTimer();
1446 
1447                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::Srp_1_1 - lowerlayertx wnsrp cmd seq num %d", pTxPkt->getSeqNum()));
1448 
1449                 /* Send SRP command */
1450                 LowerLayerTx(pTxPkt);
1451                 /* Start response wait timer */
1452                 SrpT401Start(*pTimer, pTxPkt);
1453 
1454                 AddActiveWnsrpTimer(pTimer);
1455             }
1456             break;
1457 
1458         default:
1459             break;
1460     }
1461 
1462     return (1);
1463 }
1464 
1465 /************************************************************************/
1466 /*  function name       : Srp_1_3                                       */
1467 /*  function outline    : SRP response received in WAITING-RESPONSE     */
1468 /*  function discription: PVMFSharedMediaDataPtr Srp_1_3(               */
1469 /*                                      PVMFSharedMediaDataPtr pPkt )   */
1470 /*  input data          : pPkt - pointer of received packet from AL1C   */
1471 /*  output data         : None                                          */
1472 /*  draw time           : '96.10.29                                     */
1473 /*----------------------------------------------------------------------*/
1474 /*  amendent career     :                                               */
1475 /*                          Copyright (C) 1996 NTT DoCoMo               */
1476 /************************************************************************/
Srp_1_3(PVMFSharedMediaDataPtr pPkt,int event)1477 int SRP::Srp_1_3(PVMFSharedMediaDataPtr pPkt, int event)
1478 {
1479     PVMFSharedMediaDataPtr pSrpCommandPkt;
1480     SRPRespTimer *pTimer;
1481     uint32 i;
1482     uint32 seqNum = pPkt->getSeqNum();
1483     bool isWaiting;
1484 
1485     switch (event)
1486     {
1487         case EV_WNSRP_RESPONSE:
1488             // Remove packet from waiting list
1489             SrpCommandClear(seqNum);
1490 
1491             for (isWaiting = false, i = 0; i < iActiveWnsrpCommandSave.size(); i++)
1492             {
1493                 if (seqNum == iActiveWnsrpCommandSave[i]->pPkt->getSeqNum())
1494                 {
1495                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::Srp_1_3 - wnsrp timer found %d", i));
1496 
1497                     // Resend previous WNSRP packets per section A.4.3
1498                     for (uint32 k = 0; k < i; k++)
1499                     {
1500                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::Srp_1_3 - lowerlayertx EV_WNSRP_RESPONSE wnsrp cmd seq num %d, index k %d", iActiveWnsrpCommandSave[k]->pPkt->getSeqNum(), k));
1501 
1502                         // Send SRP command
1503                         LowerLayerTx(iActiveWnsrpCommandSave[k]->pPkt);
1504                         // Stop timer
1505                         SrpT401Stop(*iActiveWnsrpCommandSave[k]);
1506                         // Restart timer
1507                         SrpT401Start(*iActiveWnsrpCommandSave[k], iActiveWnsrpCommandSave[k]->pPkt);
1508                         // Count-up retry counter
1509                         ++iActiveWnsrpCommandSave[k]->N400Counter;
1510                     }
1511 
1512                     // Stop response wait timer
1513                     SrpT401Stop(*iActiveWnsrpCommandSave[i]);
1514 
1515                     // Release packet
1516                     iActiveWnsrpCommandSave[i]->pPkt.Unbind();
1517 
1518                     // Remove timer from active list
1519                     RemoveActiveWnsrpTimer(iActiveWnsrpCommandSave[i]);
1520 
1521                     isWaiting = true;
1522                     break;
1523                 }
1524             }
1525 
1526             if (!isWaiting)
1527             {
1528                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_WARNING, (0x40000020, "SRP::Srp_1_3 - WNSRP command with seq %d not waiting for response", seqNum));
1529                 return 0;
1530             }
1531             break;
1532 
1533         case EV_NSRP_RESPONSE:
1534             // Remove packet from waiting list
1535             SrpCommandClear(seqNum);
1536 
1537             //Stop any wnsrp timers with same seq number
1538             for (i = 0; i < iActiveWnsrpCommandSave.size(); i++)
1539             {
1540                 if (seqNum == iActiveWnsrpCommandSave[i]->pPkt->getSeqNum())
1541                 {
1542                     // Stop response wait timer
1543                     SrpT401Stop(*iActiveWnsrpCommandSave[i]);
1544 
1545                     // Release packet
1546                     iActiveWnsrpCommandSave[i]->pPkt.Unbind();
1547 
1548                     // Remove timer from active list
1549                     RemoveActiveWnsrpTimer(iActiveWnsrpCommandSave[i]);
1550                     break;
1551                 }
1552             }
1553 
1554             if (iSrpCommandSave.isTimerActive)
1555             {
1556                 if (seqNum == iSrpCommandSave.pPkt->getSeqNum())
1557                 {
1558                     // Stop response wait timer
1559                     SrpT401Stop(iSrpCommandSave);
1560 
1561                     // Release packet
1562                     iSrpCommandSave.pPkt.Unbind();
1563                 }
1564                 else
1565                 {
1566                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_WARNING, (0x40000020, "SRP::Srp_1_3 - NSRP command seq %d does not match  NSRP resp seq %d", iSrpCommandSave.pPkt->getSeqNum(), seqNum));
1567                     return 0;
1568                 }
1569             }
1570             else
1571             {
1572                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_WARNING, (0x40000020, "SRP::Srp_1_3 - No command waiting for NSRP response"));
1573                 return 0;
1574             }
1575             break;
1576 
1577         case EV_RESPONSE:
1578             if (iSrpCommandSave.isTimerActive)
1579             {
1580                 //Stop oldest wnsrp timer
1581                 if (!iActiveWnsrpCommandSave.empty())
1582                 {
1583                     // Stop response wait timer
1584                     SrpT401Stop(*iActiveWnsrpCommandSave[0]);
1585 
1586                     // Release packet
1587                     iActiveWnsrpCommandSave[0]->pPkt.Unbind();
1588 
1589                     // Remove timer from active list
1590                     RemoveActiveWnsrpTimer(iActiveWnsrpCommandSave[0]);
1591                 }
1592 
1593                 // Remove packet from waiting list
1594                 SrpCommandClear(iSrpCommandSave.pPkt->getSeqNum());
1595 
1596                 // Stop response wait timer
1597                 SrpT401Stop(iSrpCommandSave);
1598 
1599                 // Release packet
1600                 iSrpCommandSave.pPkt.Unbind();
1601             }
1602             else
1603             {
1604                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_WARNING, (0x40000020, "SRP::Srp_1_3 - No command waiting for SRP response"));
1605                 return 0;
1606             }
1607             break;
1608 
1609         default:
1610             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::Srp_1_3 - Invalid response type %d", event));
1611             return 0;
1612     }
1613 
1614     switch (WnsrpStatusGet())
1615     {
1616         case NO_WNSRP_SUPPORT:
1617         case WNSRP_TX_SUPPORT:
1618             // Waiting PDU exists?
1619             if (!iSrpWaitQueue.empty())
1620             {
1621                 // Create SRP command
1622                 pSrpCommandPkt = SrpCommandCreate(SrpSendWaitGet(0), SRP_COMMAND_HEADER);
1623 
1624                 if (pSrpCommandPkt.GetRep() == NULL)
1625                 {
1626                     // Set status
1627                     SrpStatusSet(STS_IDLE);
1628                     return 0;
1629                 }
1630 
1631                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::Srp_1_3 - lowerlayertx srp cmd seq num %d", pSrpCommandPkt->getSeqNum()));
1632 
1633                 // Send SRP command
1634                 LowerLayerTx(pSrpCommandPkt);
1635                 // Start response wait timer
1636                 SrpT401Start(iSrpCommandSave, pSrpCommandPkt);
1637             }
1638 
1639             if (WnsrpStatusGet() == NO_WNSRP_SUPPORT)
1640             {
1641                 break;
1642             }
1643 
1644             //Fall through to next case
1645 
1646         case WNSRP_FULL_SUPPORT:
1647             //Check if wnsrp timer is available
1648             if (iActiveWnsrpCommandSave.size() < iSrpWaitQueue.size())
1649             {
1650                 /* Create WNSRP command */
1651                 pSrpCommandPkt = SrpCommandCreate(SrpSendWaitGet(iActiveWnsrpCommandSave.size()), WNSRP_COMMAND_HEADER);
1652 
1653                 /* If packet could not be created. */
1654                 if (pSrpCommandPkt.GetRep() == NULL)
1655                 {
1656                     return(0);
1657                 }
1658 
1659                 pTimer = GetFreeWnsrpTimer();
1660 
1661                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::Srp_1_3 - lowerlayertx WNSRP_FULL_SUPPORT wnsrp cmd seq num %d", pSrpCommandPkt->getSeqNum()));
1662 
1663                 /* Send SRP command */
1664                 LowerLayerTx(pSrpCommandPkt);
1665                 /* Start response wait timer */
1666                 SrpT401Start(*pTimer, pSrpCommandPkt);
1667 
1668                 AddActiveWnsrpTimer(pTimer);
1669             }
1670 
1671 
1672             break;
1673     }
1674 
1675     if (!iSrpCommandSave.isTimerActive && iActiveWnsrpCommandSave.empty())
1676     {
1677         // Set status
1678         SrpStatusSet(STS_IDLE);
1679     }
1680 
1681     /* Get total response time for frame. */
1682     UpdateRespStats();
1683 
1684     return(1) ;
1685 }
1686 
1687 /************************************************************************/
1688 /*  function name       : Srp_1_4                                       */
1689 /*  function outline    : Response wait timer timeout                   */
1690 /*                                            in WAITING-RESPONSE       */
1691 /*  function discription: PVMFSharedMediaDataPtr Srp_1_4(               */
1692 /*                                      PVMFSharedMediaDataPtr pPkt,    */
1693 /*                                      int32 id  )                     */
1694 /*  input data          : pPkt - pointer of timeout information         */
1695 /*                        id - id of timer that timed out               */
1696 /*  output data         : None                                          */
1697 /*  draw time           : '96.10.29                                     */
1698 /*----------------------------------------------------------------------*/
1699 /*  amendent career     :                                               */
1700 /*                          Copyright (C) 1996 NTT DoCoMo               */
1701 /************************************************************************/
Srp_1_4(int32 id)1702 int SRP::Srp_1_4(int32 id)
1703 {
1704     PVMFSharedMediaDataPtr pSrpCommandPkt;
1705     SRPRespTimer *timer;
1706 
1707     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_WARNING, (0x40000020, "SRP::Srp_1_4 - Response wait timer timeout"));
1708 
1709     if (iSrpCommandSave.timerID == id)
1710     {
1711         timer = &iSrpCommandSave;
1712     }
1713     else if ((uint32) id < iWNSRPTxWindow)
1714     {
1715         timer = FindActiveWnsrpTimer(id);
1716     }
1717     else
1718     {
1719         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::Srp_1_4 - unknown SRP timer %d", id));
1720         return 0;
1721     }
1722 
1723     // Retry over ?
1724     if (SrpN400Check(*timer) == false)
1725     {
1726         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_WARNING, (0x40000020, "SRP::Srp_1_4 - Max retry over"));
1727 
1728         // Remove command from wait queue.
1729         SrpCommandClear(timer->pPkt->getSeqNum());
1730 
1731         // Stop timer
1732         SrpT401Stop(*timer);
1733 
1734         //Release packet
1735         timer->pPkt.Unbind();
1736 
1737         // Take timer off WNSRP timer wait list (if it is a WNSRP timer)
1738         RemoveActiveWnsrpTimer(timer);
1739 
1740         // If observer exists.
1741 
1742 
1743         if (iObserver)
1744         {
1745             /* Report transmission failure to TSC.
1746                TSC will stop SRP if necessary. */
1747             iObserver->TransmissionFailure();
1748         }
1749 
1750         else
1751         {
1752             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::Srp_1_4 - No observer!"));
1753 
1754             switch (WnsrpStatusGet())
1755             {
1756                 case NO_WNSRP_SUPPORT:
1757                     // Set status
1758                     SrpStatusSet(STS_IDLE);
1759                     break;
1760 
1761                 case WNSRP_TX_SUPPORT:
1762                 case WNSRP_FULL_SUPPORT:
1763                     //If no more packets waiting to be sent.
1764                     if (!iSrpWaitQueue.empty())
1765                     {
1766                         // Set status
1767                         SrpStatusSet(STS_IDLE);
1768                     }
1769                     break;
1770             }
1771         }
1772     }
1773     else
1774     {
1775         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_WARNING, (0x40000020, "SRP::Srp_1_4 - Create and send SRP command again, seq num %d", timer->pPkt->getSeqNum()));
1776         // Send SRP command
1777         LowerLayerTx(timer->pPkt);
1778         // Count-up retry counter
1779         ++timer->N400Counter;
1780     }
1781 
1782     return 1;
1783 }
1784 
1785 /************************************************************************/
1786 /*  function name       : SrpSendWaitGet                                */
1787 /*  function outline    : Get from queue for waiting transmittion       */
1788 /*  function discription: PVMFSharedMediaDataPtr SrpSendWaitGet(        */
1789 /*                                                      uint32 index)   */
1790 /*  input data          : index - index of srp frags                    */
1791 /*  output data         : data pointer of waiting transmittion          */
1792 /*  draw time           : '05.08.25                                     */
1793 /*----------------------------------------------------------------------*/
1794 /*  amendent career     :                                               */
1795 /*                          Copyright (C) 2005 PacketVideo Corp.        */
1796 /************************************************************************/
SrpSendWaitGet(uint32 index)1797 PVMFSharedMediaDataPtr SRP::SrpSendWaitGet(uint32 index)
1798 {
1799     if (index < iSrpWaitQueue.size())
1800     {
1801         return iSrpWaitQueue[index];
1802     }
1803     else
1804     {
1805         PVMFSharedMediaDataPtr temp;
1806         return temp;
1807     }
1808 }
1809 
1810 /************************************************************************/
1811 /*  function name       : SrpSendWaitRemove                             */
1812 /*  function outline    : Remove from queue for waiting transmission    */
1813 /*  function discription: PVMFSharedMediaDataPtr SrpSendWaitRemove(     */
1814 /*                                                      uint32 index)   */
1815 /*  input data          : index - index of srp frags                    */
1816 /*  output data         : data pointer of waiting transmittion          */
1817 /*  draw time           : '05.08.25                                     */
1818 /*----------------------------------------------------------------------*/
1819 /*  amendent career     :                                               */
1820 /*                          Copyright (C) 2005 PacketVideo Corp.        */
1821 /************************************************************************/
SrpSendWaitRemove(uint32 index)1822 int SRP::SrpSendWaitRemove(uint32 index)
1823 {
1824     if (index < iSrpWaitQueue.size())
1825     {
1826         iSrpWaitQueue.erase(&iSrpWaitQueue[index]);
1827         return 1;
1828     }
1829     else
1830     {
1831         return 0;
1832     }
1833 }
1834 
1835 /************************************************************************/
1836 /*  function name       : SrpSendSeqCount                               */
1837 /*  function outline    : Count up sequence number for sending          */
1838 /*  function discription: void SrpSendSeqCount( void )                  */
1839 /*  input data          : None                                          */
1840 /*  output data         : None                                          */
1841 /*  draw time           : '96.10.29                                     */
1842 /*----------------------------------------------------------------------*/
1843 /*  amendent career     :                                               */
1844 /*                          Copyright (C) 1996 NTT DoCoMo               */
1845 /************************************************************************/
SrpSendSeqCount()1846 void SRP::SrpSendSeqCount()
1847 {
1848     if (iSendSeqNumber < 255)
1849     {
1850         ++ iSendSeqNumber;
1851     }
1852     else
1853     {
1854         iSendSeqNumber = 0;
1855     }
1856     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_VERBOSE, (0x40000020, "SRP::SrpSendSeqCount = %d", iSendSeqNumber));
1857     return;
1858 }
1859 
1860 
1861 /************************************************************************/
1862 /*  function name       : SrpRecvSeqCount                               */
1863 /*  function outline    : Count up sequence number for receiving        */
1864 /*  function discription: void SrpRecvSeqCount( void )                  */
1865 /*  input data          : None                                          */
1866 /*  output data         : None                                          */
1867 /*  draw time           : '96.10.29                                     */
1868 /*----------------------------------------------------------------------*/
1869 /*  amendent career     :                                               */
1870 /*                          Copyright (C) 1996 NTT DoCoMo               */
1871 /************************************************************************/
SrpRecvSeqCount()1872 void SRP::SrpRecvSeqCount()
1873 {
1874     if (iRecvSeqNumber < 255)
1875     {
1876         ++iRecvSeqNumber;
1877     }
1878     else
1879     {
1880         iRecvSeqNumber = 0;
1881     }
1882 
1883     if (iOldestWNSRPRetransSeqNum < 255)
1884     {
1885         ++iOldestWNSRPRetransSeqNum;
1886     }
1887     else
1888     {
1889         iOldestWNSRPRetransSeqNum = 0;
1890     }
1891 
1892     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_VERBOSE, (0x40000020, "SRP::SrpRecvSeqCount = %d, oldest retrans = %d", iRecvSeqNumber, iOldestWNSRPRetransSeqNum));
1893     return;
1894 }
1895 
1896 
1897 /************************************************************************/
1898 /*  function name       : SrpStatusSet                                  */
1899 /*  function outline    : Status number set                             */
1900 /*  function discription: void SrpStatusSet( SrpStatus newStatus )      */
1901 /*  input data          : newStatus - status number                     */
1902 /*  output data         : None                                          */
1903 /*  draw time           : '96.10.29                                     */
1904 /*----------------------------------------------------------------------*/
1905 /*  amendent career     :                                               */
1906 /*                          Copyright (C) 1996 NTT DoCoMo               */
1907 /************************************************************************/
SrpStatusSet(SrpStatus newStatus)1908 void SRP::SrpStatusSet(SrpStatus newStatus)
1909 {
1910     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_VERBOSE, (0x40000020, "SRP::SrpStatusSet - SrpStatus from %d => %d", iStatus, newStatus));
1911     iStatus = newStatus;
1912     return;
1913 }
1914 
1915 /************************************************************************/
1916 /*  function name       : WnsrpStatusSet                                */
1917 /*  function outline    : WNSRP Status number set                       */
1918 /*  function discription: void WnsrpStatusSet( WnsrpStatus newStatus )  */
1919 /*  input data          : newStatus - status number                     */
1920 /*  output data         : None                                          */
1921 /*  draw time           : '05.08.23                                     */
1922 /*----------------------------------------------------------------------*/
1923 /*  amendent career     :                                               */
1924 /*                          Copyright (C) 2005 PacketVideo Corp.        */
1925 /************************************************************************/
WnsrpStatusSet(WnsrpStatus newStatus)1926 void SRP::WnsrpStatusSet(WnsrpStatus newStatus)
1927 {
1928     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_VERBOSE, (0x40000020, "SRP::WnsrpStatusSet - WnsrpStatus from %d => %d", iCurWnsrpStatus, newStatus));
1929     iCurWnsrpStatus = newStatus;
1930 
1931     switch (iCurWnsrpStatus)
1932     {
1933         case NO_WNSRP_SUPPORT:
1934             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_INFO, (0x40000020, "SRP::WnsrpStatusSet - Remote does not support WNSRP!"));
1935             //Clear all WNSRP resp timers
1936             while (!iActiveWnsrpCommandSave.empty())
1937             {
1938                 // Stop response wait timer
1939                 SrpT401Stop(*iActiveWnsrpCommandSave[0]);
1940 
1941                 // Release packet
1942                 iActiveWnsrpCommandSave[0]->pPkt.Unbind();
1943 
1944                 // Remove timer from active list
1945                 RemoveActiveWnsrpTimer(iActiveWnsrpCommandSave[0]);
1946             }
1947 
1948             if (iObserver) iObserver->UseWNSRP(false);
1949             break;
1950 
1951         case WNSRP_FULL_SUPPORT:
1952             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_INFO, (0x40000020, "SRP::WnsrpStatusSet - Remote supports WNSRP!"));
1953             //Disable SRP tx
1954             if (iSrpCommandSave.isTimerActive)
1955             {
1956                 // Stop response wait timer
1957                 SrpT401Stop(iSrpCommandSave);
1958 
1959                 // Release packet
1960                 iSrpCommandSave.pPkt.Unbind();
1961             }
1962 
1963             //Send all WNSRP frames using the default multiplex table entry number 0
1964             *(uint8 *)iWnsrpEntryNumFrag.getMemFragPtr() = SRP_NSRP_MT_ENTRY_NUMBER;
1965 
1966             if (iObserver) iObserver->UseWNSRP(true);
1967             break;
1968         default:
1969             break;
1970     }
1971     return;
1972 }
1973 
1974 /************************************************************************/
1975 /*  function name       : SrpT401Start                                  */
1976 /*  function outline    : T401 timer start                              */
1977 /*  function discription: void SrpT401Start( SRPRespTimer &timer )      */
1978 /*  input data          : timer - timer to start                        */
1979 /*  output data         : None                                          */
1980 /*  draw time           : '05.08.24                                     */
1981 /*----------------------------------------------------------------------*/
1982 /*  amendent career     :                                               */
1983 /*                          Copyright (C) 2005 PacketVideo Corp.        */
1984 /************************************************************************/
SrpT401Start(SRPRespTimer & timer,PVMFSharedMediaDataPtr pPkt)1985 void SRP::SrpT401Start(SRPRespTimer &timer, PVMFSharedMediaDataPtr pPkt)
1986 {
1987     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "SRP::SrpT401Start - id %d, IsPrimaryTimerActive = %d", timer.timerID, timer.isTimerActive));
1988 
1989     /* Start timer that is not active. */
1990     if (!timer.isTimerActive)
1991     {
1992         timer.T401Timer.Request(timer.timerID, (int32)this, iT401TimerValue, this, true);
1993         timer.isTimerActive = true;
1994     }
1995 
1996     timer.pPkt = pPkt;
1997     timer.N400Counter = 0;
1998 
1999     return;
2000 }
2001 
2002 /************************************************************************/
2003 /*  function name       : SrpT401Stop                                   */
2004 /*  function outline    : T401 timer stop                               */
2005 /*  function discription: void SrpT401Stop( SRPRespTimer &timer )       */
2006 /*  input data          : timer - timer to stop                         */
2007 /*  output data         : None                                          */
2008 /*  draw time           : '05.08.24                                     */
2009 /*----------------------------------------------------------------------*/
2010 /*  amendent career     :                                               */
2011 /*                          Copyright (C) 2005 PacketVideo Corp.        */
2012 /************************************************************************/
SrpT401Stop(SRPRespTimer & timer)2013 void SRP::SrpT401Stop(SRPRespTimer &timer)
2014 {
2015     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::SrpT401Stop - id %d, IsPrimaryTimerActive = %d", timer.timerID, timer.isTimerActive));
2016 
2017     /* Reset active timer */
2018     if (timer.isTimerActive)
2019     {
2020         timer.T401Timer.Cancel(timer.timerID);
2021         timer.isTimerActive = false;
2022     }
2023 
2024     return;
2025 }
2026 
2027 /************************************************************************/
2028 /*  function name       : SrpT401Timeout                                */
2029 /*  function outline    : T401 timeout                                  */
2030 /*  function discription: int SrpT401Timeout(int TimerId, void *Param)  */
2031 /*  input data          : TimerId - timer id                            */
2032 /*                        Param - timer parameter                       */
2033 /*  output data         : 0 - Reset timer  to fire again                */
2034 /*                        1 - Do not reset timer                        */
2035 /*  draw time           : '96.10.29                                     */
2036 /*----------------------------------------------------------------------*/
2037 /*  amendent career     :                                               */
2038 /*                          Copyright (C) 1996 NTT DoCoMo               */
2039 /************************************************************************/
2040 // OsclTimerObserver virtual function
TimeoutOccurred(int32 timerID,int32 param)2041 void SRP::TimeoutOccurred(int32 timerID, int32 param)
2042 {
2043     OSCL_UNUSED_ARG(param);
2044     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::TimeoutOccurred, id %d, wnsrp status %d", timerID, iCurWnsrpStatus));
2045 
2046     iStats.totalNumTimeouts++;
2047 
2048     /* Process call */
2049     SrpStateChange(SrpStatusGet(), EV_TIMEOUT, (void *) &timerID);
2050 }
2051 
2052 
2053 /************************************************************************/
2054 /*  function name       : LowerLayerRx                                  */
2055 /*  function outline    : Lower Layer Receive                           */
2056 /*  function description: void LowerLayerRx(MediaPacket* pPkt)          */
2057 /*  input data          : pPkt - pointer to incoming packet             */
2058 /*  output data         : None                                          */
2059 /*  draw time           : '96.10.29                                     */
2060 /*----------------------------------------------------------------------*/
2061 /*  amendent career     :                                               */
2062 /*                          Copyright (C) 1996 NTT DoCoMo               */
2063 /************************************************************************/
LowerLayerRx(PVMFSharedMediaDataPtr pPkt)2064 void SRP::LowerLayerRx(PVMFSharedMediaDataPtr pPkt)
2065 {
2066     int32 error;
2067     OsclSharedPtr<PVMFMediaDataImpl> data;
2068     OSCL_TRY(error, data = iRxPacketAlloc->allocate(MAX_SIZE_OF_SRP_PDU));
2069     OSCL_FIRST_CATCH_ANY(error, PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::LowerLayerRx - Unable allocate rx message impl %d", error));
2070                          return);
2071 
2072     OsclRefCounterMemFrag frag;
2073     data->getMediaFragment(0, frag);
2074     uint8* pos = (uint8*)frag.getMemFragPtr();
2075     for (unsigned i = 0; i < pPkt->getNumFragments(); i++)
2076     {
2077         OsclRefCounterMemFrag src_frag;
2078         pPkt->getMediaFragment(i, src_frag);
2079         oscl_memcpy(pos, src_frag.getMemFragPtr(), src_frag.getMemFragSize());
2080         pos += src_frag.getMemFragSize();
2081     }
2082     data->setMediaFragFilledLen(0, pPkt->getFilledSize());
2083     /* Record number of frames received from lower layer. */
2084     iStats.totalFramesRecv++;
2085 
2086     /* Record number of bytes received. */
2087     iStats.totalBytesRecv += pPkt->getFilledSize();
2088 
2089     /* Process call */
2090     PVMFSharedMediaDataPtr mediaData;
2091     OSCL_TRY(error, mediaData = PVMFMediaData::createMediaData(data, iRxMediaMsgPoolAlloc));
2092     OSCL_FIRST_CATCH_ANY(error, PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::LowerLayerRx - Unable allocate rx message %d", error));
2093                          return);
2094     SrpStateChange(SrpStatusGet(), SrpGetEventNoFromAL1(mediaData), &mediaData);
2095     return;
2096 
2097 }
2098 
2099 /************************************************************************/
2100 /*  function name       : UpperLayerRx                                  */
2101 /*  function outline    : Upper Layer Receive                           */
2102 /*  function description: void UpperLayerRx(MediaPacket* pPkt)          */
2103 /*  input data          : pPkt - pointer to incoming packet             */
2104 /*  output data         : None                                          */
2105 /*  draw time           : '96.10.29                                     */
2106 /*----------------------------------------------------------------------*/
2107 /*  amendent career     :                                               */
2108 /*                          Copyright (C) 1996 NTT DoCoMo               */
2109 /************************************************************************/
UpperLayerRx(PVMFSharedMediaDataPtr pPkt)2110 void SRP::UpperLayerRx(PVMFSharedMediaDataPtr pPkt)
2111 {
2112     uint32 offset;
2113     uint8 *buf;
2114     PVMFSharedMediaDataPtr srpPkt;
2115     OsclRefCounterMemFrag newFrag;
2116     OsclRefCounterMemFrag CCSRLFrag;
2117     OsclRefCounterMemFrag frag;
2118     OsclSharedPtr<PVMFMediaDataImpl> data;
2119     uint8 seqNum;
2120     uint32 size;
2121 
2122     iStats.totalH245MessagesToSend++;
2123 
2124 
2125     // IMPORTANT: Assume upper layer is sending 1 fragment in a packet!
2126     if (pPkt->getNumFragments() != 1)
2127     {
2128         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::UpperLayerRx - Num frags of incoming message not equal to 1, %d", pPkt->getNumFragments()));
2129         return;
2130     }
2131 
2132     pPkt->getMediaFragment(0, frag);
2133 
2134     /* CCSRL */
2135     if (iCcsrlSduSize > 0)
2136     {
2137         //---------------------------------------------------------
2138         // Send the encoded message (pCodeData, GetSize) to SRP
2139         //   using the multi-chunk feature of H.324.
2140         //---------------------------------------------------------
2141         size = frag.getMemFragSize();
2142 
2143         // If queue cannot hold the number of fragments that will be needed.
2144         // If not enough messages available to send the entire message
2145         if (((size / iCcsrlSduSize) + 1) > iTxPacketAlloc->NumMsgAvail())
2146         {
2147             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::UpperLayerRx - Unable allocate enough messages, current num %d", iTxPacketAlloc->NumMsgAvail()));
2148             return;
2149         }
2150 
2151         if (size > iCcsrlSduSize)
2152         {
2153             iStats.totalH245MessagesFragmented++;
2154         }
2155 
2156         buf = (uint8 *) frag.getMemFragPtr();
2157         offset = 0;
2158 
2159         while (offset < size)
2160         {
2161             if (!Allocate(data, CCSRLFrag))
2162                 return;
2163             newFrag = frag;
2164             newFrag.getMemFrag().ptr = (buf + offset);
2165 
2166             /* Set sequence number */
2167             seqNum = (uint8)SrpSendSeqGet();
2168             SrpSendSeqCount();
2169             *(uint8 *)CCSRLFrag.getMemFrag().ptr = seqNum;
2170             CCSRLFrag.getMemFrag().len = SRP_SEQUENCE_SIZE + CCSRL_HEADER_SIZE;
2171 
2172             if ((offset + iCcsrlSduSize) >= size)
2173             {
2174                 /* Last CCSRL chunk */
2175                 *((uint8 *)CCSRLFrag.getMemFrag().ptr + 1) = LAST_CCSRL_CHUNK;
2176                 data->appendMediaFragment(CCSRLFrag);
2177 
2178                 newFrag.getMemFrag().len = size - offset;
2179 
2180                 offset += (size - offset);
2181             }
2182             else
2183             {
2184                 /* Intermediate CCSRL chunk */
2185                 *((uint8 *)CCSRLFrag.getMemFrag().ptr + 1) = INTERMEDIATE_CCSRL_CHUNK;
2186                 data->appendMediaFragment(CCSRLFrag);
2187 
2188                 newFrag.getMemFrag().len = iCcsrlSduSize;
2189 
2190                 offset += iCcsrlSduSize;
2191             }
2192 
2193             data->appendMediaFragment(newFrag);
2194             if (!CreateMediaData(srpPkt, data))
2195                 return;
2196             srpPkt->setSeqNum(seqNum);
2197 
2198             /* Queue received PDU */
2199             SrpSendWaitSet(srpPkt);
2200         }
2201     }
2202     else
2203     {
2204         // If no message available to send the entire message
2205         if (iTxPacketAlloc->NumMsgAvail() == 0)
2206         {
2207             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::UpperLayerRx - no message available"));
2208             return;
2209         }
2210         if (!Allocate(data, CCSRLFrag))
2211             return;
2212 
2213         /* Set sequence number */
2214         seqNum = (uint8) SrpSendSeqGet();
2215         SrpSendSeqCount();
2216         *(uint8 *)CCSRLFrag.getMemFrag().ptr = seqNum;
2217         CCSRLFrag.getMemFrag().len = SRP_SEQUENCE_SIZE;
2218 
2219         data->appendMediaFragment(CCSRLFrag);
2220 
2221         data->appendMediaFragment(frag);
2222 
2223         if (!CreateMediaData(srpPkt, data))
2224             return;
2225 
2226         //---------------------------------------------------------
2227         // Send the encoded message (pCodeData, GetSize) to SRP
2228         //   without using the H.324 multi-chunk method.
2229         //---------------------------------------------------------
2230 
2231         srpPkt->setSeqNum(seqNum);
2232 
2233         /* Queue received PDU */
2234         SrpSendWaitSet(srpPkt);
2235     }
2236 
2237     /* Process call */
2238     SrpStateChange(SrpStatusGet(), EV_PDU, NULL);
2239 
2240     return;
2241 }
2242 
Allocate(OsclSharedPtr<PVMFMediaDataImpl> & data,OsclRefCounterMemFrag & CCSRLFrag)2243 bool SRP::Allocate(OsclSharedPtr<PVMFMediaDataImpl>& data, OsclRefCounterMemFrag& CCSRLFrag)
2244 {
2245     data = iTxPacketAlloc->allocate();
2246 
2247     if (!data)
2248     {
2249         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR,
2250                         (0x40000020, "SRP::UpperLayerRx - Unable allocate tx media impl"));
2251         return false;
2252     }
2253 
2254     CCSRLFrag = iCcsrlAllocator.get();
2255 
2256     return (CCSRLFrag.getMemFragPtr() ? true : false);
2257 }
2258 
2259 /************************************************************************/
2260 /*  function name       : UseNSRP                                       */
2261 /*  function outline    : Set use of NSRP response frames or not.       */
2262 /*  function description: void UseNSRP( bool aUseNsrp )                 */
2263 /*  input data          : None                                          */
2264 /*  output data         : None                                          */
2265 /*  draw time           : '05.08.23                                     */
2266 /*----------------------------------------------------------------------*/
2267 /*  amendent career     :                                               */
2268 /*                          Copyright (C) 2005 PacketVideo Corp.        */
2269 /************************************************************************/
UseNSRP(bool aUseNsrp)2270 void SRP::UseNSRP(bool aUseNsrp)
2271 {
2272     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_INFO, (0x40000020, "SRP::UseNSRP - cur %d, new %d", iUseNSRP, aUseNsrp));
2273     if (aUseNsrp == iUseNSRP)
2274     {
2275         return;
2276     }
2277     iUseNSRP = aUseNsrp;
2278     iFirstNSRPResp = false;
2279     return;
2280 }
2281 
2282 /************************************************************************/
2283 /*  function name       : DisableWNSRPSupport                           */
2284 /*  function outline    : Disables all support for WNSRP.  Must be      */
2285 /*                        called before initailization.                 */
2286 /*  function description: void DisableWNSRPSupport()                    */
2287 /*  input data          : None                                          */
2288 /*  output data         : None                                          */
2289 /*  draw time           : '05.08.23                                     */
2290 /*----------------------------------------------------------------------*/
2291 /*  amendent career     :                                               */
2292 /*                          Copyright (C) 2005 PacketVideo Corp.        */
2293 /************************************************************************/
DisableWNSRPSupport()2294 void SRP::DisableWNSRPSupport()
2295 {
2296     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::DisableWNSRPSupport"));
2297 
2298     if (WnsrpStatusGet() == WNSRP_TX_SUPPORT)
2299     {
2300         WnsrpStatusSet(NO_WNSRP_SUPPORT);
2301     }
2302 
2303     iHandleWNSRP = false;
2304     return;
2305 }
2306 
2307 /************************************************************************/
2308 /*  function name       : SrpResetStats                                 */
2309 /*  function outline    : Reset statistics                              */
2310 /*  function description: void SrpResetStats( void )                    */
2311 /*  input data          : None                                          */
2312 /*  output data         : None                                          */
2313 /*  draw time           : '96.10.29                                     */
2314 /*----------------------------------------------------------------------*/
2315 /*  amendent career     :                                               */
2316 /*                          Copyright (C) 1996 NTT DoCoMo               */
2317 /************************************************************************/
SrpResetStats()2318 void SRP::SrpResetStats()
2319 {
2320     iStats.Reset();
2321     iTotalRespTime = 0;
2322 }
2323 
2324 /************************************************************************/
2325 /*  function name       : SrpGetStats                                   */
2326 /*  function outline    : Retrieve statistics                           */
2327 /*  function description: void SrpGetStats(SRPStats &aStats)            */
2328 /*  input data          : aStats - iStats object to fill                 */
2329 /*  output data         : None                                          */
2330 /*  draw time           : '96.10.29                                     */
2331 /*----------------------------------------------------------------------*/
2332 /*  amendent career     :                                               */
2333 /*                          Copyright (C) 1996 NTT DoCoMo               */
2334 /************************************************************************/
SrpGetStats(SRPStats & aStats)2335 void SRP::SrpGetStats(SRPStats &aStats)
2336 {
2337     if (iStats.totalCCSRLChunksSent > 0)
2338     {
2339         iStats.aveRespTime = iTotalRespTime / iStats.totalCCSRLChunksSent;
2340     }
2341     else
2342     {
2343         iStats.aveRespTime = 0;
2344     }
2345 
2346     aStats = iStats;
2347 }
2348 
2349 /************************************************************************/
2350 /*  function name       : UpdateRespStats                               */
2351 /*  function outline    : Update response statistics                    */
2352 /*  function description: void UpdateRespStats()                        */
2353 /*  input data          : None                                          */
2354 /*  output data         : None                                          */
2355 /*  draw time           : '96.10.29                                     */
2356 /*----------------------------------------------------------------------*/
2357 /*  amendent career     :                                               */
2358 /*                          Copyright (C) 1996 NTT DoCoMo               */
2359 /************************************************************************/
UpdateRespStats()2360 void SRP::UpdateRespStats()
2361 {
2362     TimeValue timeNow;
2363     uint32 timeDifference;
2364 
2365     timeNow.set_to_current_time();
2366 
2367     timeDifference = timeNow.to_msec() - iInitialTimeChunkSent.to_msec();
2368 
2369     if (timeDifference > iStats.maxRespTime)
2370     {
2371         iStats.maxRespTime = timeDifference;
2372     }
2373     else if (timeDifference < iStats.minRespTime)
2374     {
2375         iStats.minRespTime = timeDifference;
2376     }
2377 
2378     iTotalRespTime += timeDifference;
2379 }
2380 
2381 /************************************************************************/
2382 /*  function name       : GetFreeWnsrpTimer                             */
2383 /*  function outline    : Get free WNSRP response timer                 */
2384 /*  function description: SRPRespTimer *GetFreeWnsrpTimer()             */
2385 /*  input data          : None                                          */
2386 /*  output data         : None                                          */
2387 /*  draw time           : '05.08.26                                     */
2388 /*----------------------------------------------------------------------*/
2389 /*  amendent career     :                                               */
2390 /*                          Copyright (C) 2005 PacketVideo Corp.        */
2391 /************************************************************************/
GetFreeWnsrpTimer()2392 SRP::SRPRespTimer *SRP::GetFreeWnsrpTimer()
2393 {
2394     SRPRespTimer *timer = NULL;
2395     if (!iFreeWnsrpCommandSave.empty())
2396     {
2397         timer = iFreeWnsrpCommandSave[0];
2398         iFreeWnsrpCommandSave.erase(iFreeWnsrpCommandSave.begin());
2399     }
2400 
2401     return timer;
2402 }
2403 
2404 /************************************************************************/
2405 /*  function name       : FindActiveWnsrpTimer                          */
2406 /*  function outline    : Get free WNSRP response timer                 */
2407 /*  function description: SRPRespTimer *FindActiveWnsrpTimer(           */
2408 /*                                                      int32 timerID)  */
2409 /*  input data          : timerID - id of timer                         */
2410 /*  output data         : None                                          */
2411 /*  draw time           : '05.08.26                                     */
2412 /*----------------------------------------------------------------------*/
2413 /*  amendent career     :                                               */
2414 /*                          Copyright (C) 2005 PacketVideo Corp.        */
2415 /************************************************************************/
FindActiveWnsrpTimer(int32 timerID)2416 SRP::SRPRespTimer *SRP::FindActiveWnsrpTimer(int32 timerID)
2417 {
2418     for (uint32 i = 0; i < iActiveWnsrpCommandSave.size(); i++)
2419     {
2420         if (iActiveWnsrpCommandSave[i]->timerID == timerID)
2421         {
2422             return iActiveWnsrpCommandSave[i];
2423         }
2424     }
2425 
2426     return NULL;
2427 }
2428 
2429 /************************************************************************/
2430 /*  function name       : RemoveActiveWnsrpTimer                        */
2431 /*  function outline    : Remove an timer from the active WNSRP timer   */
2432 /*                        list                                          */
2433 /*  function description: void RemoveActiveWnsrpTimer(                  */
2434 /*                                              SRPRespTimer *timer)    */
2435 /*  input data          : timer - timer to remove                       */
2436 /*  output data         : None                                          */
2437 /*  draw time           : '05.08.26                                     */
2438 /*----------------------------------------------------------------------*/
2439 /*  amendent career     :                                               */
2440 /*                          Copyright (C) 2005 PacketVideo Corp.        */
2441 /************************************************************************/
RemoveActiveWnsrpTimer(SRPRespTimer * timer)2442 void SRP::RemoveActiveWnsrpTimer(SRPRespTimer *timer)
2443 {
2444     //Timer should be stopped before this method is called.
2445     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::RemoveActiveWnsrpTimer id %d", timer->timerID));
2446 
2447     for (uint32 i = 0; i < iActiveWnsrpCommandSave.size(); i++)
2448     {
2449         if (iActiveWnsrpCommandSave[i] == timer)
2450         {
2451             FreeWnsrpTimer(iActiveWnsrpCommandSave[i]);
2452             iActiveWnsrpCommandSave.erase(&iActiveWnsrpCommandSave[i]);
2453 
2454             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::RemoveActiveWnsrpTimer timer removed index %d", i));
2455             return;
2456         }
2457     }
2458 
2459     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::RemoveActiveWnsrpTimer timer not found"));
2460     return;
2461 }
2462 
2463 
2464 /************************************************************************/
2465 /*  function name       : FreeRxFrag                                    */
2466 /*  function outline    : Free a frag to the free list                  */
2467 /*  function description: void FreeRxFrag(SRPRxData *frag)              */
2468 /*  input data          : timer - timer to remove                       */
2469 /*  output data         : None                                          */
2470 /*  draw time           : '05.08.26                                     */
2471 /*----------------------------------------------------------------------*/
2472 /*  amendent career     :                                               */
2473 /*                          Copyright (C) 2005 PacketVideo Corp.        */
2474 /************************************************************************/
FreeRxFrag(SRPRxData * frag)2475 void SRP::FreeRxFrag(SRPRxData *frag)
2476 {
2477     frag->seqNum = 0;
2478     frag->data.Unbind();
2479 
2480     frag->next = iFreeRxFragList;
2481     iFreeRxFragList = frag;
2482 
2483     return;
2484 }
2485 
2486 /************************************************************************/
2487 /*  function name       : GetRxFrag                                     */
2488 /*  function outline    : Remove an frag from the free list             */
2489 /*  function description: SRPRxData *GetRxFrag()                        */
2490 /*  input data          : timer - timer to remove                       */
2491 /*  output data         : None                                          */
2492 /*  draw time           : '05.08.26                                     */
2493 /*----------------------------------------------------------------------*/
2494 /*  amendent career     :                                               */
2495 /*                          Copyright (C) 2005 PacketVideo Corp.        */
2496 /************************************************************************/
GetRxFrag(void)2497 SRP::SRPRxData *SRP::GetRxFrag(void)
2498 {
2499     SRPRxData *free;
2500     if (iFreeRxFragList)
2501     {
2502         free = iFreeRxFragList;
2503         iFreeRxFragList = iFreeRxFragList->next;
2504         return free;
2505     }
2506     else
2507     {
2508         return NULL;
2509     }
2510 }
2511 
2512 /************************************************************************/
2513 /*  function name       : AddPendingRxFrag                              */
2514 /*  function outline    : Add a rx frag to the pending list in order of */
2515 /*                        rx sequence number mod 256.                   */
2516 /*  function description: void AddPendingRxFrag(SRPRxData *frag)        */
2517 /*  input data          : timer - timer to remove                       */
2518 /*  output data         : None                                          */
2519 /*  draw time           : '05.08.26                                     */
2520 /*----------------------------------------------------------------------*/
2521 /*  amendent career     :                                               */
2522 /*                          Copyright (C) 2005 PacketVideo Corp.        */
2523 /************************************************************************/
AddPendingRxFrag(SRPRxData * frag)2524 void SRP::AddPendingRxFrag(SRPRxData *frag)
2525 {
2526     SRPRxData *cur = iPendingRxFragList;
2527     SRPRxData *prev = NULL;
2528 
2529     while (cur)
2530     {
2531         if (cur->seqNum > frag->seqNum)
2532         {
2533             if (prev)
2534             {
2535                 prev->next = frag;
2536                 frag->next = cur;
2537             }
2538             else
2539             {
2540                 frag->next = iPendingRxFragList;
2541                 iPendingRxFragList = frag;
2542             }
2543             return;
2544         }
2545 
2546         prev = cur;
2547         cur = cur->next;
2548     }
2549 
2550     frag->next = NULL;
2551     if (prev)
2552     {
2553         prev->next = frag;
2554     }
2555     else
2556     {
2557         iPendingRxFragList = frag;
2558     }
2559     return;
2560 }
2561 
2562 /************************************************************************/
2563 /*  function name       : CheckRxSeqNum                                 */
2564 /*  function outline    : Check Rx sequence number for against the      */
2565 /*                        pending rx frags.                             */
2566 /*  function description: bool CheckRxSeqNum(uint32 seqNum,             */
2567 /*                                                      uint8 header)   */
2568 /*  input data          : timer - timer to remove                       */
2569 /*  output data         : None                                          */
2570 /*  draw time           : '05.08.26                                     */
2571 /*----------------------------------------------------------------------*/
2572 /*  amendent career     :                                               */
2573 /*                          Copyright (C) 2005 PacketVideo Corp.        */
2574 /************************************************************************/
CheckRxSeqNum(uint32 seqNum,uint8 header)2575 bool SRP::CheckRxSeqNum(uint32 seqNum, uint8 header)
2576 {
2577     PVMFSharedMediaDataPtr resp;
2578     uint32 endSeqNum;
2579 
2580     //If WNSRP command
2581     switch (header)
2582     {
2583         case WNSRP_RESPONSE_HEADER:
2584             //Check if data is already pending to be sent up
2585             if (CheckPendingRxList(seqNum))
2586             {
2587                 /* Create WNSRP response */
2588                 resp = SrpResponseCreate((uint8) seqNum, header);
2589                 if (resp.GetRep() == NULL)
2590                 {
2591                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::CheckRxSeqNum - Unable create WNSRP reponse packet"));
2592                     /* If unable to create response message. */
2593                     return false;
2594                 }
2595 
2596                 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::CheckRxSeqNum - lowerlayertx wnsrp resp seq num %d", resp->getSeqNum()));
2597 
2598                 /* SRP response send */
2599                 LowerLayerTx(resp);
2600                 return false;
2601             }
2602 
2603             endSeqNum = (SrpRecvSeqGet() + iWNSRPRxWindow) % 256;
2604             //If rx window does not wrap
2605             if (endSeqNum > SrpRecvSeqGet())
2606             {
2607                 //If can't accept sequence number because of rx window
2608                 if ((seqNum < SrpRecvSeqGet()) ||
2609                         (seqNum > endSeqNum))
2610                 {
2611                     if (CheckWNSRPRetrans(seqNum))
2612                     {
2613                         /* Create WNSRP response */
2614                         resp = SrpResponseCreate((uint8) seqNum, header);
2615                         if (resp.GetRep() == NULL)
2616                         {
2617                             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::CheckRxSeqNum - Unable create WNSRP reponse packet"));
2618                             /* If unable to create response message. */
2619                             return false;
2620                         }
2621 
2622                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::CheckRxSeqNum - lowerlayertx wnsrp resp seq num %d", resp->getSeqNum()));
2623 
2624                         /* SRP response send */
2625                         LowerLayerTx(resp);
2626                     }
2627                     return false;
2628                 }
2629 
2630                 //Else can accept sequence number
2631             }
2632             //Else window wraps around
2633             else
2634             {
2635                 //If can accept sequence number
2636                 if ((seqNum >= SrpRecvSeqGet()) ||
2637                         (seqNum <= endSeqNum))
2638                 {
2639                     return true;
2640                 }
2641                 //Else can't accept sequence number
2642                 else
2643                 {
2644                     if (CheckWNSRPRetrans(seqNum))
2645                     {
2646                         /* Create WNSRP response */
2647                         resp = SrpResponseCreate((uint8) seqNum, header);
2648                         if (resp.GetRep() == NULL)
2649                         {
2650                             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::CheckRxSeqNum - Unable create WNSRP reponse packet"));
2651                             /* If unable to create response message. */
2652                             return false;
2653                         }
2654 
2655                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::CheckRxSeqNum - lowerlayertx wnsrp resp seq num %d", resp->getSeqNum()));
2656 
2657                         /* SRP response send */
2658                         LowerLayerTx(resp);
2659                     }
2660                     return false;
2661                 }
2662             }
2663             return true;
2664 
2665         case NSRP_RESPONSE_HEADER:
2666         case SRP_RESPONSE_HEADER:
2667             if (seqNum != SrpRecvSeqGet())
2668             {
2669                 if (((seqNum + 1) % 256) == SrpRecvSeqGet())
2670                 {
2671                     /* Create SRP response */
2672                     resp = SrpResponseCreate((uint8) seqNum, header);
2673                     if (resp.GetRep() == NULL)
2674                     {
2675                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0x40000020, "SRP::CheckRxSeqNum - Unable create SRP reponse packet"));
2676                         /* If unable to create response message. */
2677                         return false;
2678                     }
2679 
2680                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0x40000020, "SRP::CheckRxSeqNum - lowerlayertx srp resp seq num %d", resp->getSeqNum()));
2681 
2682                     /* SRP response send */
2683                     LowerLayerTx(resp);
2684                 }
2685                 return false;
2686             }
2687             return true;
2688 
2689         default:
2690             return false;
2691     }
2692 }
2693 
2694 /************************************************************************/
2695 /*  function name       : CheckPendingRxList                            */
2696 /*  function outline    : Check pending rx list against sequence number */
2697 /*  function description: bool CheckRxSeqNum(uint32 seqNum)             */
2698 /*  input data          : seqNum - sequence number to check             */
2699 /*  output data         : None                                          */
2700 /*  draw time           : '05.08.26                                     */
2701 /*----------------------------------------------------------------------*/
2702 /*  amendent career     :                                               */
2703 /*                          Copyright (C) 2005 PacketVideo Corp.        */
2704 /************************************************************************/
CheckPendingRxList(uint32 seqNum)2705 bool SRP::CheckPendingRxList(uint32 seqNum)
2706 {
2707     SRPRxData *data = iPendingRxFragList;
2708     while (data)
2709     {
2710         if (data->seqNum == seqNum)
2711         {
2712             return true;
2713         }
2714         data = data->next;
2715     }
2716     return false;
2717 }
2718 
2719 /************************************************************************/
2720 /*  function name       : CheckWNSRPRetrans                             */
2721 /*  function outline    : Check Rx sequence number for WNSRP retrans    */
2722 /*                        window.                                       */
2723 /*  function description: bool CheckWNSRPRetrans(uint32 seqNum)         */
2724 /*  input data          : timer - timer to remove                       */
2725 /*  output data         : None                                          */
2726 /*  draw time           : '05.08.26                                     */
2727 /*----------------------------------------------------------------------*/
2728 /*  amendent career     :                                               */
2729 /*                          Copyright (C) 2005 PacketVideo Corp.        */
2730 /************************************************************************/
CheckWNSRPRetrans(uint32 seqNum)2731 bool SRP::CheckWNSRPRetrans(uint32 seqNum)
2732 {
2733     //Retrans window does not wrap
2734     if (iOldestWNSRPRetransSeqNum < SrpRecvSeqGet())
2735     {
2736         if ((seqNum < SrpRecvSeqGet()) &&
2737                 (seqNum > iOldestWNSRPRetransSeqNum))
2738         {
2739             return true;
2740         }
2741     }
2742     //Retrans window wraps
2743     else if ((seqNum < SrpRecvSeqGet()) ||
2744              (seqNum > iOldestWNSRPRetransSeqNum))
2745     {
2746         return true;
2747     }
2748 
2749     return false;
2750 }
2751 
2752 
2753 
2754