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 /* file name : sece.h */ 30 /* file contents : Capability Exchange Signalling Entity */ 31 /* : Management Header */ 32 /* draw : '96.11.11 */ 33 /*----------------------------------------------------------------------*/ 34 /* amendment : */ 35 /* Copyright (C) 1996 NTT DoCoMo */ 36 /************************************************************************/ 37 #ifndef _SECE_H_ 38 #define _SECE_H_ 39 40 #include "oscl_base.h" 41 #include "sebase.h" 42 #include "oscl_timer.h" 43 #include "h245def.h" 44 #include "h245inf.h" 45 46 enum CESource { CE_USER, CE_PROTOCOL }; 47 enum CECause 48 { 49 CE_UNSPECIFIED = 0, 50 CE_UNDEFINED_TABLE_ENTRY_USED, 51 CE_DESCRIPTOR_CAPACITY_EXCEEDED, 52 CE_TABLE_ENTRY_CAPACITY_EXCEEDED 53 }; 54 enum CEDirection { CE_OUTGOING, CE_INCOMING }; 55 56 ////////////////////////////////////////////////////////////////////////// 57 ////////////////////////////////////////////////////////////////////////// 58 class CEObserver 59 { 60 public: ~CEObserver()61 virtual ~CEObserver() {} 62 virtual void CETransferIndication(OsclSharedPtr<S_TerminalCapabilitySet> tcs) = 0; 63 virtual void CETransferConfirm() = 0; 64 virtual void CERejectIndication(CESource source, CECause cause, CEDirection direction) = 0; 65 }; 66 67 ////////////////////////////////////////////////////////////////////////// 68 ////////////////////////////////////////////////////////////////////////// 69 class CE : public SEBase, public OsclTimerObserver 70 { 71 private: 72 enum CEState { IDLE, AWAITING_RESPONSE }; // states 73 74 public: CE()75 CE() : 76 Observer(NULL), 77 OutgoingState(IDLE), 78 IncomingState(IDLE), 79 OutSeqNum(0), 80 InSeqNum(0xff) 81 {} 82 ~CE()83 ~CE() {} 84 Reset()85 void Reset() 86 { 87 Print("Reset CE\n"); 88 OutgoingState = IDLE; 89 IncomingState = IDLE; 90 OutSeqNum = 0; 91 InSeqNum = 0xff; 92 ResetTimer(); 93 } 94 SetObserver(CEObserver * observer)95 void SetObserver(CEObserver *observer) 96 { 97 Observer = observer; 98 } 99 100 // Primitives TransferRequest(PS_TerminalCapabilitySet tcs)101 void TransferRequest(PS_TerminalCapabilitySet tcs) 102 { 103 Print("Received CE Transfer Request\n"); 104 switch (OutgoingState) 105 { 106 case IDLE: 107 OutgoingIdle(tcs); 108 break; 109 case AWAITING_RESPONSE: 110 default: 111 break; 112 } 113 } 114 TransferResponse()115 void TransferResponse() 116 { 117 Print("Received CE Transfer Response\n"); 118 switch (IncomingState) 119 { 120 case IDLE: 121 break; 122 case AWAITING_RESPONSE: 123 IncomingAwaitingResponse(); 124 break; 125 default: 126 break; 127 } 128 } 129 130 void RejectRequest(CECause cause, uint16 highestEntryProcessed = 0) 131 { 132 Print("Received CE Reject Request\n"); 133 switch (IncomingState) 134 { 135 case IDLE: 136 break; 137 case AWAITING_RESPONSE: 138 IncomingAwaitingResponse(cause, highestEntryProcessed); 139 break; 140 default: 141 break; 142 } 143 } 144 145 // Outgoing Message Handlers Handler(PS_TerminalCapabilitySetAck tcsa)146 void Handler(PS_TerminalCapabilitySetAck tcsa) 147 { 148 Print("Received TCSAck \n"); 149 switch (OutgoingState) 150 { 151 case IDLE: 152 break; 153 case AWAITING_RESPONSE: 154 OutgoingAwaitingResponse(tcsa); 155 break; 156 default: 157 break; 158 } 159 } 160 Handler(PS_TerminalCapabilitySetReject tcsr)161 void Handler(PS_TerminalCapabilitySetReject tcsr) 162 { 163 Print("Received TCSReject\n"); 164 switch (OutgoingState) 165 { 166 case IDLE: 167 break; 168 case AWAITING_RESPONSE: 169 OutgoingAwaitingResponse(tcsr); 170 break; 171 default: 172 break; 173 } 174 } 175 HandlerTimeout()176 void HandlerTimeout() 177 { 178 Print("Received TCS Timeout\n"); 179 switch (OutgoingState) 180 { 181 case IDLE: 182 break; 183 case AWAITING_RESPONSE: 184 OutgoingAwaitingResponseTimeout(); 185 break; 186 default: 187 break; 188 } 189 } 190 191 // Incoming Message Handlers Handler(OsclSharedPtr<S_TerminalCapabilitySet> tcs)192 void Handler(OsclSharedPtr<S_TerminalCapabilitySet> tcs) 193 { 194 Print("Received TCS\n"); 195 switch (IncomingState) 196 { 197 case IDLE: 198 IncomingIdle(tcs); 199 break; 200 case AWAITING_RESPONSE: 201 IncomingAwaitingResponse(tcs); 202 break; 203 default: 204 break; 205 } 206 } 207 Handler(PS_TerminalCapabilitySetRelease tcsr)208 void Handler(PS_TerminalCapabilitySetRelease tcsr) 209 { 210 Print("Received TCSRelease\n"); 211 switch (IncomingState) 212 { 213 case IDLE: 214 break; 215 case AWAITING_RESPONSE: 216 IncomingAwaitingResponse(tcsr); 217 break; 218 default: 219 break; 220 } 221 } 222 TimeoutOccurred(int32 timerID,int32 timeoutInfo)223 void TimeoutOccurred(int32 timerID, int32 timeoutInfo) 224 { 225 Print(" CE::TimeoutOccurred"); 226 OSCL_UNUSED_ARG(timerID); 227 OSCL_UNUSED_ARG(timeoutInfo); 228 HandlerTimeout(); 229 } 230 231 private: 232 CE(const CE&); 233 CE& operator=(const CE&); 234 235 CEObserver *Observer; 236 CEState OutgoingState; 237 CEState IncomingState; 238 uint8 OutSeqNum; 239 uint8 InSeqNum; 240 SetTimer()241 void SetTimer() 242 { 243 RequestTimer(101, 0, TimerDuration, this); 244 } ResetTimer()245 void ResetTimer() 246 { 247 CancelTimer(101); 248 } 249 OutgoingIdle(PS_TerminalCapabilitySet tcs)250 void OutgoingIdle(PS_TerminalCapabilitySet tcs) 251 { 252 OutSeqNum++; 253 SetTimer(); 254 OutgoingState = AWAITING_RESPONSE; 255 SendTerminalCapabilitySet(tcs); 256 } 257 OutgoingAwaitingResponse(PS_TerminalCapabilitySetAck tcsa)258 void OutgoingAwaitingResponse(PS_TerminalCapabilitySetAck tcsa) 259 { 260 if (tcsa->sequenceNumber == OutSeqNum) 261 { 262 ResetTimer(); 263 OutgoingState = IDLE; 264 if (Observer) Observer->CETransferConfirm(); 265 } 266 } 267 OutgoingAwaitingResponse(PS_TerminalCapabilitySetReject tcsr)268 void OutgoingAwaitingResponse(PS_TerminalCapabilitySetReject tcsr) 269 { 270 if (tcsr->sequenceNumber == OutSeqNum) 271 { 272 ResetTimer(); 273 OutgoingState = IDLE; 274 if (Observer) Observer->CERejectIndication(CE_USER, (CECause)tcsr->tcsRejectCause.index, CE_OUTGOING); 275 } 276 } 277 OutgoingAwaitingResponseTimeout()278 void OutgoingAwaitingResponseTimeout() 279 { 280 OutgoingState = IDLE; 281 SendTerminalCapabilitySetRelease(); 282 if (Observer) Observer->CERejectIndication(CE_PROTOCOL, CE_UNSPECIFIED, CE_OUTGOING); 283 } 284 IncomingIdle(OsclSharedPtr<S_TerminalCapabilitySet> tcs)285 void IncomingIdle(OsclSharedPtr<S_TerminalCapabilitySet> tcs) 286 { 287 InSeqNum = tcs->sequenceNumber; 288 IncomingState = AWAITING_RESPONSE; 289 if (Observer) Observer->CETransferIndication(tcs); 290 } 291 292 // handles TransferResponse IncomingAwaitingResponse()293 void IncomingAwaitingResponse() 294 { 295 IncomingState = IDLE; 296 SendTerminalCapabilitySetAck(); 297 } 298 299 // handles RejectRequest IncomingAwaitingResponse(CECause cause,uint16 highestEntryProcessed)300 void IncomingAwaitingResponse(CECause cause, uint16 highestEntryProcessed) 301 { 302 IncomingState = IDLE; 303 SendTerminalCapabilitySetReject(cause, highestEntryProcessed); 304 } 305 IncomingAwaitingResponse(PS_TerminalCapabilitySetRelease tcsr)306 void IncomingAwaitingResponse(PS_TerminalCapabilitySetRelease tcsr) 307 { 308 OSCL_UNUSED_ARG(tcsr); 309 IncomingState = IDLE; 310 if (Observer) Observer->CERejectIndication(CE_PROTOCOL, CE_UNSPECIFIED, CE_INCOMING); 311 } 312 IncomingAwaitingResponse(OsclSharedPtr<S_TerminalCapabilitySet> tcs)313 void IncomingAwaitingResponse(OsclSharedPtr<S_TerminalCapabilitySet> tcs) 314 { 315 InSeqNum = tcs->sequenceNumber; 316 IncomingState = AWAITING_RESPONSE; 317 if (Observer) Observer->CERejectIndication(CE_USER, CE_UNSPECIFIED, CE_INCOMING); 318 if (Observer) Observer->CETransferIndication(tcs); 319 } 320 SendTerminalCapabilitySet(PS_TerminalCapabilitySet tcs)321 void SendTerminalCapabilitySet(PS_TerminalCapabilitySet tcs) 322 { 323 Print(" Sending TCS\n"); 324 tcs->sequenceNumber = OutSeqNum; 325 MessageSend(H245_MSG_REQ, MSGTYP_CE, (uint8*)tcs); 326 } 327 SendTerminalCapabilitySetAck()328 void SendTerminalCapabilitySetAck() 329 { 330 Print(" Sending TCS Ack\n"); 331 S_TerminalCapabilitySetAck tcsa ; 332 tcsa.sequenceNumber = InSeqNum; 333 MessageSend(H245_MSG_RPS, MSGTYP_CE_ACK, (uint8*)&tcsa); 334 } 335 SendTerminalCapabilitySetRelease()336 void SendTerminalCapabilitySetRelease() 337 { 338 Print(" Sending TCS Release\n"); 339 S_TerminalCapabilitySetRelease tcsr; 340 oscl_memset((int8*)&tcsr, 0, sizeof(S_TerminalCapabilitySetRelease)) ; 341 MessageSend(H245_MSG_IDC, MSGTYP_CE_RLS, (uint8*)&tcsr); 342 } 343 SendTerminalCapabilitySetReject(CECause cause,uint16 highestEntryProcessed)344 void SendTerminalCapabilitySetReject(CECause cause, uint16 highestEntryProcessed) 345 { 346 Print(" Sending TCS Reject\n"); 347 S_TerminalCapabilitySetReject tcsr; 348 S_TableEntryCapacityExceeded tece; 349 350 tcsr.sequenceNumber = InSeqNum; 351 tcsr.tcsRejectCause.index = (uint16)cause; 352 if (cause == CE_TABLE_ENTRY_CAPACITY_EXCEEDED) 353 { 354 tcsr.tcsRejectCause.tableEntryCapacityExceeded = &tece; 355 tcsr.tcsRejectCause.tableEntryCapacityExceeded->index = (uint16)(highestEntryProcessed ? 0 : 1); 356 tcsr.tcsRejectCause.tableEntryCapacityExceeded->highestEntryNumberProcessed = highestEntryProcessed; 357 } 358 MessageSend(H245_MSG_RPS, MSGTYP_CE_RJT, (uint8*)&tcsr); 359 } 360 }; 361 362 #endif /* _SECE_ */ 363