summaryrefslogtreecommitdiffstats
path: root/data/mnet/GP10/Host/cc/src/SmsLeg.cpp
blob: 9b2710c42b5232fc7365d6fd1e91dee002357927 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
// *******************************************************************
//
// (c) Copyright Cisco Systems Inc. 2000
// All Rights Reserved
//
// *******************************************************************

// *******************************************************************
//
// Version     : 1.0
// Status      : Under development
// File        : SmsLeg.cpp
// Author(s)   : Igal Gutkin
// Create Date : 01-20-2000
// Description : 
//
// *******************************************************************

// *******************************************************************
// Include Files.
// *******************************************************************
//

#include <vxworks.h>
#include <string.h>
#include <taskLib.h>


#include "Logging\vcmodules.h"

#include "CC/CCSessionHandler.h"

#include "CC/SmsCommonDef.h"
#include "CC/SmsLeg.h"

extern bool callTrace;

// *******************************************************************
// 
// *******************************************************************


// *******************************************************************
// SmsLeg class
// *******************************************************************

// Definition of the static data member
UINT32 SmsLeg::lastVbRefNum_ (0);


SmsLeg::SmsLeg (CCSessionHandler *session,
                int               callId ,
                MSG_Q_ID          qid    ,
                short             legNum )
            : CallLeg ()
{
  DBG_FUNC ("SmsLeg::SmsLeg (...)", CC_SMS_LAYER);
  DBG_ENTER();

    msgBuilder = new SmsMsgBuilder (*this);

    initData ();

    // Init parent class data
    CallLeg::parent     = session;
    CallLeg::callIndex  = callId ;
    CallLeg::msgQId     = qid    ;
    CallLeg::callLegNum = legNum ;

    if (callLegNum == SMS_MO_LEG_NUM)
        InitMoLeg (); // MO SMS Leg
    else
        InitMtLeg (); // MT SMS leg

  DBG_LEAVE();
}


void SmsLeg::initData ()
{
  DBG_FUNC  ("SmsLeg::initData", CC_SMS_LAYER);
  DBG_ENTER ();

        //Init parent class
        CallLeg::initData ();

        // Reset local data
        resetTi        ();
        resetVbRefNum  ();
        setRemRelCause (CNI_RIL3_RP_CAUSE_PROTOCOL_ERROR_UNSPECIFIED);

  DBG_LEAVE();
}


bool SmsLeg::InitMoLeg ()
{
  DBG_FUNC  ("SmsLeg::InitMoLeg", CC_SMS_LAYER);
  DBG_ENTER ();

    legType_ = SMS_MO_LEG;
    smsFsm_  = new SmsMoHalfCall (*this);

  DBG_LEAVE();
  return true;
}


bool SmsLeg::InitMtLeg ()
{
  DBG_FUNC ("SmsLeg::InitMtLeg", CC_SMS_LAYER);
  DBG_ENTER();

    legType_ = SMS_MT_LEG;
    smsFsm_  = new SmsMtHalfCall (*this);

  DBG_LEAVE();
  return   (true);
}


SmsLeg::~SmsLeg ()
{
    // Allocated memory cleanup

    if (smsFsm_)
        delete smsFsm_;
    if (msgBuilder)
        delete msgBuilder;
}


void SmsLeg::cleanup (T_CNI_RIL3_CAUSE_VALUE cause)
{
  DBG_FUNC  ("SmsLeg::cleanup", CC_SMS_LAYER);
  DBG_ENTER ();

    smsFsm_->cleanup (cause);

    initData();

  DBG_LEAVE();
  return;
}


bool SmsLeg::setupOrig (T_CNI_RIL3_SI_TI ti)
{
  // false to reject the setup
  bool retVal;

  DBG_FUNC ("SmsLeg::setupOrig", CC_SMS_LAYER);
  DBG_ENTER();

    if (getSmsLegType() != SMS_MO_LEG)
    {
        DBG_ERROR ("SMS Error: SMS leg %d is of wrong type (MT).\n", 
                   (callLegNum - SMS_LEGNUM_OFFSET));
        return (isIdle()); // keep current state of the Leg
    }

    if (smsFsm_->invokeHandler (SMS_EVENT_MM_EST_IND, NULL_PTR, ti) == false)
    {  // returns true if the connection is rejected and the leg is released (reverse logic), 
       // otherwise mark the leg as Busy

        setBusy ();
        retVal = true;

        if (callTrace)
        {
            char callTaskName[20];

            sprintf (callTaskName, "Sms-%d EntryId-%d\0 MO", callIndex, entryId()); 

            DBG_FUNC(callTaskName, CC_LAYER);
        }
    }
    else
        retVal = false;

  DBG_LEAVE();
  return   (retVal);
}


void SmsLeg::setupTerm (VOIP_CALL_HANDLE voipCallHandle, int  index      ,
                        int              refValue      , bool callWaiting)
{
  DBG_FUNC ("SmsLeg::setupTerm", CC_SMS_LAYER);
  DBG_ENTER();

    if (isIdle())
    {
        /* voipCallHandle and callWaiting are not in use for the SMS */
        /* CDR parameters */
        cdrIndex     = index   ;
        callRefValue = refValue;

        setBusy ();
    }

  DBG_LEAVE();
}


bool SmsLeg::isHoAllowed ()
{
    // HO is allowed when SMS is Idle or in the stage of active signalling
    return (isIdle() || getHc()->isActive());
}


int SmsLeg::handleTimeoutMsg (IntraL3Msg_t *smsTimerMsg)
{
  int retVal = 0;

  DBG_FUNC ("SmsLeg::handleTimeoutMsg", CC_SMS_LAYER);
  DBG_ENTER();

    if (!isIdle())
    {
        /* Pass timer message to the FSM
           Returns 0 if the leg is keep going, 
           otherwise returns disconnect cause value  */
        retVal = handleMsg (SMS_EVENT_TIMEOUT, NULL_PTR, 0);
    }
    else
    {
        DBG_ERROR ("SMS Leg %d Error: Unexpected Timeout Message.\n", 
                   (callLegNum - SMS_LEGNUM_OFFSET)                  );
    }

  DBG_LEAVE();
  return   (retVal);
}


bool SmsLeg::handleL2Msg (T_CNI_RIL3MD_CCMM_MSG& l2InMsg, JCCEvent_t event)
{  // L2 service messages (without PDU)
  bool retVal;

  DBG_FUNC  ("SmsLeg::handleL2Msg", CC_SMS_LAYER);
  DBG_ENTER ();

    retVal = handleMsg (event, &l2InMsg, 0);

  DBG_LEAVE ();
  return    (retVal);
}


bool SmsLeg::handleMmMsg (IntraL3Msg_t& msInMsg, JCCEvent_t event)
{  // Handle MM service messages
  bool retVal = false;

  DBG_FUNC  ("SmsLeg::handleMmMsg", CC_SMS_LAYER);
  DBG_ENTER ();

    // don't forward late MM Release Ind (in fact confirmation)
    if (!(isIdle() && event == SMS_EVENT_MM_REL_IND))
    {
        // Don't check TI here 
        retVal = handleMsg (event, &msInMsg, 0);
    }

  DBG_LEAVE ();
  return    (retVal);
}


bool SmsLeg::handleMsMsg (T_CNI_RIL3SMS_CP_MSG& msInMsg, JCCEvent_t event)
{
  bool retVal;

  DBG_FUNC  ("SmsLeg::handleMsMsg", CC_SMS_LAYER);
  DBG_ENTER ();

    // Don't check TI here 
    retVal = handleMsg (event, &msInMsg, 0);

  DBG_LEAVE ();
  return    (retVal);
}


bool SmsLeg::handleVbMsg (SmsVblinkMsg_t& netInMsg, JCCEvent_t event)
{
  bool retVal;
    
  DBG_FUNC  ("SmsLeg::handleVbMsg", CC_SMS_LAYER);
  DBG_ENTER ();

    retVal = handleMsg (event, &netInMsg, netInMsg.hdr.status);

  DBG_LEAVE ();
  return    (retVal);
}


bool SmsLeg::handleMsg (JCCEvent_t event, void *data, INT32 param1)
{
  bool                      retVal;
  T_CNI_RIL3_RP_CAUSE_VALUE cause ;

  DBG_FUNC  ("SmsLeg::handleMsg", CC_SMS_LAYER);
  DBG_ENTER ();

    if (isIdle()) // Protection: The Leg is not initiated
    {
        retVal = true; // The leg is already inactive
        DBG_WARNING ("Idle %s SMS Leg %d received event %d. The message will be discarded.\n",
                     (getSmsLegType() == SMS_MO_LEG) ? "MO":"MT", 
                     (callLegNum - SMS_LEGNUM_OFFSET)           , event);
    }
    else if (retVal = smsFsm_->invokeHandler (event, data, param1))
    {
        cause = getRemRelCause ();

        releaseRemSide (cause);
        cleanup        ((T_CNI_RIL3_CAUSE_VALUE)cause);
    }

  DBG_LEAVE ();
  return    (retVal);
}


bool SmsLeg::releaseRemSide   (T_CNI_RIL3_RP_CAUSE_VALUE cause)
{
  DBG_FUNC  ("SmsLeg::releaseRemSide", CC_SMS_LAYER);
  DBG_ENTER ();

    /* There is no Network side if reference number isn't allocated */
    if (getVbRefNum() != INVALID_VC_SMS_REF_NUM)
    { // release remote side on low layer error
        msgBuilder->sendMnSmsErrorInd (cause);
        resetVbRefNum ();
    }

  DBG_LEAVE ();
  return    (true);
}


/*===============================================================*/

void SmsLeg::printData (JCCPrintStFn fnPtr)
{
  char strLeg []   = "Sms Leg:\n";
  char strInfo[120];
    
    sprintf (strInfo, 
    "(%s SMS Leg number = %d) (Idle - %s) (SMS FSM State = %d) (TI= %d) (VB ref. num %lu).\n",
            (legType_ == SMS_MO_LEG) ? "MO"  : "MT", callLegNum         , 
            (isIdle()              ) ? "Yes" : "No", 
            smsFsm_->getState(), getTi(), getVbRefNum());

    (*fnPtr)(strLeg );
    (*fnPtr)(strInfo);
}

//static 
UINT32 SmsLeg::allocateVbRefNum ()
{
    if (++lastVbRefNum_ > MAX_VC_SMS_REF_NUM)
        lastVbRefNum_ = MIN_VC_SMS_REF_NUM;

    return (lastVbRefNum_);
}


void SmsLeg::setVbRefNum (UINT32 refNum = INVALID_VC_SMS_REF_NUM)
{
  DBG_FUNC ("SmsLeg::setVbRefNum", CC_SMS_LAYER);
  DBG_ENTER();

    // Store new ref. number in the object
    vbRefNum_ = (refNum != INVALID_VC_SMS_REF_NUM)
              ? refNum 
              : allocateVbRefNum ();

    DBG_TRACE ("SMS: Set VBLink ref.num = %u by the task %s , SMS Leg %d\n", 
               vbRefNum_, taskName(taskIdSelf()), (callLegNum - SMS_LEGNUM_OFFSET));
  DBG_LEAVE();
}


void SmsLeg::allocateTi ()
{
  /* Should be used for MT leg only */
  DBG_FUNC ("SmsLeg::AllocateTi", CC_SMS_LAYER);
  DBG_ENTER();

    if (getSmsLegType() == SMS_MT_LEG)
    {
        setTi     (callLegNum); 
        DBG_TRACE ("SMS: Allocate Ti = %d by the task %s , SMS Leg %d\n", 
                   getTi(), taskName(taskIdSelf()), (callLegNum - SMS_LEGNUM_OFFSET));
    }
    else
        DBG_ERROR ("SMS: MO Leg should use received TI. TI is not allocated.\n");

  DBG_LEAVE();
}