comparison g23m-gsm/sms/sms_for.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-F&D (8411)
4 | Modul : SMS_FOR
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : This Modul defines the functions for the formatter
18 | of the component SMS.
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef SMS_FOR_C
23 #define SMS_FOR_C
24
25 #include "config.h"
26 #include "fixedconf.h"
27 #include "condat-features.h"
28
29 #define ENTITY_SMS
30
31 /*==== INCLUDES ===================================================*/
32
33 #include <string.h>
34 #include <stdlib.h>
35 #include <stddef.h>
36 #include "typedefs.h"
37 #include "pcm.h"
38 #include "vsi.h"
39 #include "custom.h"
40 #include "gsm.h"
41 #include "message.h"
42 #include "ccdapi.h"
43 #include "prim.h"
44 #include "cus_sms.h"
45 #include "cnf_sms.h"
46 #include "mon_sms.h"
47 #include "pei.h"
48 #include "tok.h"
49 #include "sms.h"
50 #include "sms_em.h"
51
52 /*==== EXPORT ======================================================*/
53
54 /*==== PRIVAT ======================================================*/
55
56 /*==== VARIABLES ===================================================*/
57
58 #if !defined (SHARED_CCD_BUF)
59 GLOBAL UBYTE _decodedMsg [MAX_MSTRUCT_LEN_SMS];
60 #else
61 GLOBAL UBYTE * _decodedMsg;
62 GLOBAL UBYTE _CCDbuf = FALSE;
63 #endif
64
65 /*==== FUNCTIONS ===================================================*/
66
67 /*
68 +--------------------------------------------------------------------+
69 | PROJECT : GSM-PS (8410) MODULE : SMS_FOR |
70 | STATE : code ROUTINE : for_init_sms |
71 +--------------------------------------------------------------------+
72
73 PURPOSE : Initialize the formatter (void)
74 */
75
76 GLOBAL void for_init_sms (void)
77 {
78 // TRACE_FUNCTION ("for_init_sms()");
79 }
80
81 /*
82 +--------------------------------------------------------------------+
83 | PROJECT : GSM-PS (8410) MODULE : SMS_FOR |
84 | STATE : code ROUTINE : for_get_pd_ti |
85 +--------------------------------------------------------------------+
86
87 PURPOSE : Get protocol discriminator and transaction identifier if
88 the incoming message is of sufficient length to contain
89 anythiny useful, this means at least PD, TI and message type.
90 */
91
92 LOCAL BOOL for_get_pd_ti (T_sdu *p_sdu, UBYTE *p_pd, UBYTE *p_ti)
93 {
94 if (p_sdu->l_buf >= 16)
95 {
96 *p_pd = p_sdu->buf[p_sdu->o_buf >> 3] & 0x0F;
97 *p_ti = p_sdu->buf[p_sdu->o_buf >> 3] >> 4;
98 *p_ti ^= 0x8;
99
100 p_sdu->o_buf += BSIZE_TI_PD;
101 p_sdu->l_buf -= BSIZE_TI_PD;
102
103 return TRUE;
104 }
105 TRACE_EVENT ("message too short");
106 return FALSE;
107 }
108
109 /*
110 +--------------------------------------------------------------------+
111 | PROJECT : GSM-PS (8410) MODULE : SMS_FOR |
112 | STATE : code ROUTINE : for_get_new_mt_instance |
113 +--------------------------------------------------------------------+
114
115 PURPOSE : This function gets a new MT instance. Basically the same
116 is done here as in GET_NEW_SMS_INSTANCE(), but additionally
117 the special case that the CP-Layer of an old MT transaction
118 waits for the last CP-ACK before the MMSMS_RELEASE_REQ is
119 sent is handled.
120
121 */
122
123 LOCAL T_SMS_DATA * for_get_new_mt_instance (UBYTE ti)
124 {
125 GET_INSTANCE_DATA;
126
127 TRACE_FUNCTION ("for_get_new_mt_instance()");
128
129 /*
130 * Check here whether we are awaiting the last CP-ACK for a MT transaction.
131 * If so, take the new MT message as implicit CP-ACK.
132 */
133 if (sms_data NEQ NULL) /*lint !e774 (sms_data NEQ NULL) always */
134 {
135 if (sms_data->data[INST_MT].ti NEQ 0)
136 {
137 /* Old MT instance still exists */
138 sms_data->inst = INST_MT;
139 switch (SMS_INST_GET_STATE (STATE_CP))
140 {
141 case CP_WAIT_FOR_ACK:
142 #ifdef GPRS
143 case CP_GSMS_MT_WAIT_FOR_CP_ACK:
144 #endif
145 if (SMS_INST.r_flag)
146 {
147 /*
148 * No further message for the old MT instance expected. Take the
149 * MMSMS_ESTABLISH_IND as implicit CP-ACK for the old instance.
150 */
151 TRACE_EVENT ("Implicit CP-ACK");
152 cp_data_ind_cp_ack ();
153 }
154 break;
155
156 default:
157 break; /* Do nothing */
158 }
159 }
160 }
161
162 sms_data = GET_NEW_SMS_INSTANCE(ti);
163
164 return sms_data;
165 }
166
167 /*
168 +--------------------------------------------------------------------+
169 | PROJECT : GSM-PS (8410) MODULE : SMS_FOR |
170 | STATE : code ROUTINE : for_ccd_rp_error_send |
171 +--------------------------------------------------------------------+
172
173 PURPOSE : Perform CCD Error check and send rp errors
174
175 */
176
177 LOCAL BOOL for_ccd_rp_error_send (T_D_CP_DATA *cp_data,
178 T_SMS_DATA *sms_data, UBYTE rp_error)
179 {
180 BOOL rp_error_send = FALSE;
181
182 MCAST (cp_data1, U_CP_DATA);
183
184 if((SMS_INST_GET_STATE (STATE_CP)) EQ CP_MM_CONNECTION_ESTABLISHED)
185 {
186 rp_error_send = TRUE;
187 rl_build_rp_error (cp_data->cp_user_data_dl.reference,
188 rp_error,cp_data1, NULL);
189 SMS_EM_SEND_RP_ERROR;
190 cp_data_req (cp_data1);
191 cp_send_release_req (SMS_INST.ti);
192
193 FREE_SMS_INSTANCE (SMS_INST.ti);
194 }
195 return rp_error_send;
196 }
197
198 /*
199 +--------------------------------------------------------------------+
200 | PROJECT : GSM-PS (8410) MODULE : SMS_FOR |
201 | STATE : code ROUTINE : for_ccd_error_check |
202 +--------------------------------------------------------------------+
203
204 PURPOSE : Perform CCD Error check and returns errors
205
206 */
207
208 LOCAL BOOL for_ccd_error_check (UBYTE *_decodedMsg,T_sdu *buf_sdu,
209 T_SMS_DATA *sms_data,UBYTE ti)
210 {
211 ULONG ccd_err = ERR_NO_MORE_ERROR;
212 T_CCD_ERR_ENTRY *ccd_err_entry = 0;
213 UBYTE p_sdu;
214 UBYTE cp_error_cause = 0;
215 UBYTE length = 0;
216 BOOL cp_error_send = FALSE;
217 BOOL rp_error_send = FALSE;
218
219
220 /* Message offset value */
221 p_sdu = (buf_sdu->o_buf/8) - 1;
222
223 ccd_err = ccd_getFirstFault(&ccd_err_entry);
224 do
225 {
226 /*
227 * Need to set these values everytime we go through fault list of ccd
228 */
229 cp_error_send = FALSE;
230 rp_error_send = FALSE;
231 /*lint -e415 Likely access of out-of-bounds pointer*/
232 switch(ccd_err)
233 {
234 case ERR_ELEM_LEN: /* ignore message & send STATUS #96 */
235 /*
236 * This ccd error will come when there is any error in IE length.
237 * If cp user data length is greater than 249 Octets then this error
238 * is because CP Message IE, so send CP-ERROR
239 * if cp user data length is less than 249, then this ccd error is
240 * because of rp IE length, so RP-ERROR
241 */
242 switch(_decodedMsg[0])
243 {
244 case D_CP_DATA:
245 length = buf_sdu->buf[p_sdu+2];
246
247 /*
248 * If CP User data length is more than 249 then CCD error is because
249 * of CP Message IE else it will be becasue of RP message IE
250 * Send error accordingly
251 */
252 if(length < MAX_LEN_CP_USER_DATA)
253 {
254 rp_error_send = for_ccd_rp_error_send((T_D_CP_DATA *)_decodedMsg,
255 sms_data,
256 SMS_RP_CS_INV_MAND_INFO);
257 }
258 if(rp_error_send EQ FALSE)
259 {
260 cp_error_send = TRUE;
261 cp_error_cause = SMS_CP_CS_INV_MAND_INFO;
262 }
263 break;
264 /*
265 * If Message is CP-ACK or CP-ERROR then this ccd error is due to CP
266 * no need to differentiate between RP and CP, These two messages are
267 * intended for CP Layer, So send CP-ERROR
268 */
269 case B_CP_ACK:
270 case B_CP_ERROR:
271 /* This flag will become FALSE, in case there is CCD warning, so make it
272 * TRUE till we get CCD Error, especially this will happen in default case
273 */
274 cp_error_send = TRUE;
275 cp_error_cause = SMS_CP_CS_INV_MAND_INFO;
276 break;
277 }
278 break;
279
280 case ERR_COMPREH_REQUIRED: /* ignore message & send STATUS #96 */
281 /*
282 * This error will come when Comprehension bit required set is having error in
283 * IE.Comprehension bits can be set inside only CP-DATA message
284 * for RP-ERROR or RP-ACK
285 */
286 if(_decodedMsg[0] EQ D_CP_DATA)
287 {
288 /*
289 * Comprehension bit error is in RP_ERROR or RP_ACK after RP Cause element
290 */
291 rp_error_send = for_ccd_rp_error_send((T_D_CP_DATA *)_decodedMsg,
292 sms_data,
293 SMS_RP_CS_INV_MAND_INFO);
294 if(rp_error_send EQ FALSE)
295 {
296 cp_error_send = TRUE;
297 cp_error_cause = SMS_CP_CS_INV_MAND_INFO;
298 }
299 }
300 break;
301
302 case ERR_MAND_ELEM_MISS: /* ignore message & send STATUS #96 */
303 /* See bit postions to check whether it is CP or RP Error */
304 /*
305 * Checking whether this error is in CP message element or RP
306 * message element. This is required to check because both CP and RP
307 * Layer decoding is done inside same CCD function
308 */
309 /* This is for CP Message decoding error - in Length*/
310 length = (buf_sdu->l_buf/8);
311 switch(buf_sdu->buf[1])
312 {
313 case D_CP_DATA:
314 /* Evaluate length of Mandatory CP-DATA/CP-ERROR message */
315 if(length < MIN_CP_LEN)
316 {
317 cp_error_send = TRUE;
318 cp_error_cause = SMS_CP_CS_INV_MAND_INFO;
319 }
320 else
321 {
322 cp_error_send = FALSE;
323 }
324 break;
325
326 case B_CP_ERROR:/* This will not have RP DATA, so no need to check for RP */
327 /* Evaluate length of Mandatory CP-DATA/CP-ERROR message */
328 if(length < MIN_CP_LEN)
329 {
330 cp_error_send = TRUE;
331 cp_error_cause = SMS_CP_CS_INV_MAND_INFO;
332 }
333 break;
334
335 case B_CP_ACK:/* This will not have RP DATA, so no need to check for RP */
336 if(length < MIN_CP_ACK_LEN)
337 {
338 cp_error_send = TRUE;
339 cp_error_cause = SMS_CP_CS_INV_MAND_INFO;
340 }
341 break;
342
343 default:
344 cp_error_send = TRUE;
345 cp_error_cause = SMS_CP_CS_INV_MAND_INFO;
346 break;
347 }
348 break;
349
350 case ERR_INVALID_MID: /* ignore message & send STATUS #97 */
351 /*
352 * Checking whether this error is in CP message element or RP
353 * message element. This is required to check because both CP and RP
354 * Layer decoding is done inside same CCD function
355 */
356 /* See bit postions to check whether it is CP or RP Error */
357 /* This is for CP Message decoding error - in Length*/
358 if ((buf_sdu->buf[1] NEQ D_CP_DATA)||(buf_sdu->buf[1] NEQ B_CP_ACK)
359 ||(buf_sdu->buf[1] NEQ B_CP_ERROR))
360 {
361 cp_error_send = TRUE;
362 cp_error_cause = SMS_CP_CS_MSG_TYPE_NON_EXIST;
363 }
364 else
365 /* Let RP Layer Handle This ccd error, eventually RP Layer will
366 * send RP-ERROR
367 */
368 /* This is for RP Message decoding error - in Length*/
369 cp_error_send = FALSE;
370 break;
371
372 case ERR_MSG_LEN: /* ignore message & send STATUS #96 */
373 /* Send CP-ERROR, some problem with Message Length, whole message is garbled */
374 cp_error_send = TRUE;
375 cp_error_cause = SMS_CP_CS_INV_MAND_INFO;
376 break;
377
378 case ERR_LEN_MISMATCH: /* ignore message & send STATUS #96 */
379 /* Send CP-ERROR, some problem with Message Length, whole message is garbled */
380 cp_error_send = TRUE;
381 cp_error_cause = SMS_CP_CS_INV_MAND_INFO;
382 break;
383 default:
384 TRACE_EVENT_P1 ("Unexpected warnings/errors = %u", ccd_err);
385 /*
386 *Default warnings pass it to RP Layer, decoding at TP will take care of it
387 */
388 cp_error_send = FALSE;
389 break;
390 }
391 /*lint +e415 Likely access of out-of-bounds pointer*/
392 ccd_err = ccd_getNextFault(&ccd_err_entry);
393 }while(ccd_err != ERR_NO_MORE_ERROR);
394
395 if(cp_error_send)
396 {
397 cp_build_cp_error (cp_error_cause);
398 /*
399 * Check if the cmms_mode is enabled or not
400 * If enabled dont release the MM connection
401 */
402
403 if(!CMMS_ACTIVE)
404 {
405 cp_send_release_req (ti);
406 SMS_INST_SET_STATE (STATE_CP, CP_IDLE);
407 SMS_INST.r_flag = FALSE;
408 }
409 else
410 {
411 sms_data->cmms_release_pending = TRUE;
412 }
413
414 rl_error_ind (CAUSE_MAKE(DEFBY_STD, ORIGSIDE_MS,
415 SMSCP_ORIGINATING_ENTITY, cp_error_cause));
416
417
418 FREE_SMS_INSTANCE (ti);
419 }
420 /* These flags return value will decide whether to pass to rp layer further */
421 return (!rp_error_send && !cp_error_send);
422 }
423
424
425 /*---- PRIMITIVES --------------------------------------------------*/
426
427 /*
428 +--------------------------------------------------------------------+
429 | PROJECT : GSM-PS (8410) MODULE : SMS_FOR |
430 | STATE : code ROUTINE : for_mmsms_establish_ind |
431 +--------------------------------------------------------------------+
432
433 PURPOSE : Processing the primitive MMSMS_ESTABLISH_IND
434
435 */
436
437 GLOBAL void for_mmsms_establish_ind (T_MMSMS_ESTABLISH_IND *mmsms_establish_ind)
438 {
439 UBYTE ti;
440 UBYTE pd;
441 CHAR *msg_type;
442 BOOL pass_to_rp = TRUE;
443
444
445 /* Enable the PCO to correctly decode the message */
446 PPASS (mmsms_establish_ind, establish_ind, MMSMS_ESTABLISH_IND);
447
448 TRACE_FUNCTION ("for_mmsms_establish_ind()");
449
450 if (for_get_pd_ti (&establish_ind->sdu, &pd, &ti))
451 {
452 if ((ti & 0x8) AND (pd EQ PD_SMS))
453 {
454 register T_SMS_DATA *sms_data = for_get_new_mt_instance (ti);
455
456 TRACE_EVENT_P1 ("TI %u", ti);
457
458 if (sms_data)
459 {
460 #if defined (GPRS)
461 SMS_INST.downlink = SMS_DOWNLINK_MMSMS;
462 #endif
463
464 SMS_INST.cp_ack_pending = FALSE;
465
466 CCD_START;
467
468 if(ccd_decodeMsg (CCDENT_SMS,
469 DOWNLINK,
470 (T_MSGBUF *) &establish_ind->sdu,
471 (UBYTE *)_decodedMsg,
472 NOT_PRESENT_8BIT) EQ ccdError)
473 {
474 pass_to_rp = for_ccd_error_check(_decodedMsg,&establish_ind->sdu,sms_data,ti);
475 }
476
477 if(pass_to_rp)
478 {
479 switch (_decodedMsg[0])
480 {
481 case D_CP_DATA:
482 cp_est_ind_cp_data ((T_D_CP_DATA *)_decodedMsg);
483 msg_type = "D_CP_DATA";
484
485 SMS_EM_RECEIVE_CP_DATA;
486
487 break;
488
489 case B_CP_ERROR:
490 {
491 MCAST (error, B_CP_ERROR);
492
493 cp_est_ind_cp_error (error->cp_cause);
494 msg_type = "B_CP_ERROR";
495
496 SMS_EM_RECEIVE_CP_ERROR;
497
498 break;
499 }
500
501 case B_CP_ACK:
502 cp_est_ind_cp_ack ();
503 msg_type = "B_CP_ACK";
504 SMS_EM_RECEIVE_CP_ACKNOWLEDGE;
505
506 break;
507
508 default:
509 cp_est_ind_cp_unknown ();
510 msg_type = "UNKNOWN_MESSAGE";
511
512 SMS_EM_RECEIVE_UNKNOWN;
513
514 break;
515 }
516 TRACE_BINDUMP(sms_handle,
517 TC_USER4,
518 msg_type,
519 (&(establish_ind->sdu.buf[0]) + ((establish_ind->sdu.o_buf >> 3) -1)),
520 ((establish_ind->sdu.l_buf >> 3) + 1));
521 }
522 CCD_END;
523 }
524 else
525 {
526 /*
527 * no further instance available
528 */
529 CCD_START;
530
531 ccd_decodeMsg (CCDENT_SMS,
532 DOWNLINK,
533 (T_MSGBUF *) &establish_ind->sdu,
534 (UBYTE *) _decodedMsg,
535 NOT_PRESENT_8BIT);
536
537 switch (_decodedMsg[0])
538 {
539 case D_CP_DATA:
540 {
541 MCAST (d_cp_data, D_CP_DATA);
542 MCAST (cp_data, U_CP_DATA);
543 /*
544 * U_CP_DATA contains a maximum of 252 Bytes
545 */
546 PALLOC_SDU (data_req, MMSMS_DATA_REQ, LEN_U_CP_DATA);
547
548 data_req->sdu.o_buf = ENCODE_OFFSET;
549
550 rl_build_rp_error (d_cp_data->cp_user_data_dl.reference,
551 SMS_RP_CS_PROTOCOL_ERROR,
552 cp_data, NULL);
553
554 cp_data->msg_type = U_CP_DATA;
555
556 ccd_codeMsg (CCDENT_SMS,
557 UPLINK,
558 (T_MSGBUF *)&data_req->sdu,
559 (UBYTE *)cp_data,
560 NOT_PRESENT_8BIT);
561
562 cp_add_pd_ti (ti, &data_req->sdu);
563
564 TRACE_BINDUMP(sms_handle,
565 TC_USER4,
566 "U_CP_DATA",
567 (&(data_req->sdu.buf[0]) + ((data_req->sdu.o_buf >> 3) -1)),
568 ((data_req->sdu.l_buf >> 3) + 1));
569 PSENDX (MM, data_req);
570 break;
571 }
572 default:
573 TRACE_EVENT_P1 ("Unexpected Message = %u", _decodedMsg[0]);
574 break;
575 }
576 CCD_END;
577 {
578 PALLOC (release_req, MMSMS_RELEASE_REQ);
579
580 release_req->ti = ti;
581 PSENDX (MM, release_req);
582 }
583 SMS_EM_UNKNOWN_TRANSACTION;
584 }
585 }
586 else
587 {
588 TRACE_EVENT_P2 ("TI or PD wrong, PD=%d, TI=%d", pd, ti);
589 }
590 }
591 PFREE (establish_ind);
592 }
593
594 /*
595 +--------------------------------------------------------------------+
596 | PROJECT : GSM-PS (8410) MODULE : SMS_FOR |
597 | STATE : code ROUTINE : for_mmsms_data_ind |
598 +--------------------------------------------------------------------+
599
600 PURPOSE : Processing the primitive MMSMS_DATA_IND
601
602 */
603
604 GLOBAL void for_mmsms_data_ind (T_MMSMS_DATA_IND *mmsms_data_ind)
605 {
606 UBYTE ti;
607 UBYTE pd;
608 CHAR *msg_type;
609 BOOL pass_to_rp = TRUE;
610
611
612 /* Enable the PCO to correctly decode the message */
613 PPASS (mmsms_data_ind, data_ind, MMSMS_DATA_IND);
614
615 if (for_get_pd_ti (&data_ind->sdu, &pd, &ti))
616 {
617 TRACE_FUNCTION_P1 ("for_mmsms_data_ind(TI=%u)", ti);
618
619 if (/*((! ti) OR (ti >= 8)) AND*/ (pd EQ PD_SMS))
620 {
621 register T_SMS_DATA *sms_data = GET_SMS_INSTANCE(ti);
622
623 if (sms_data)
624 {
625 CCD_START;
626
627 if(ccd_decodeMsg (CCDENT_SMS,
628 DOWNLINK,
629 (T_MSGBUF *) &data_ind->sdu,
630 (UBYTE *)_decodedMsg,
631 NOT_PRESENT_8BIT) EQ ccdError)
632 {
633 pass_to_rp = for_ccd_error_check(_decodedMsg,&data_ind->sdu,sms_data,ti);
634 }
635
636 if(pass_to_rp)
637 {
638 switch (_decodedMsg[0])
639 {
640 case D_CP_DATA:
641 cp_data_ind_cp_data ((T_D_CP_DATA *)_decodedMsg);
642 msg_type = "D_CP_DATA";
643 break ;
644
645 case B_CP_ERROR:
646 {
647 MCAST (error, B_CP_ERROR);
648
649 cp_data_ind_cp_error (error->cp_cause);
650 msg_type = "B_CP_ERROR";
651 break ;
652 }
653
654 case B_CP_ACK:
655 cp_data_ind_cp_ack ();
656 msg_type = "B_CP_ACK";
657 break ;
658 default:
659 cp_data_ind_cp_unknown ();
660 msg_type = "UNKNOWN MESSAGE";
661 break ;
662 }
663 TRACE_BINDUMP(sms_handle,
664 TC_USER4,
665 msg_type,
666 (&(data_ind->sdu.buf[0]) + ((data_ind->sdu.o_buf >> 3) -1)),
667 ((data_ind->sdu.l_buf >> 3) + 1));
668 }
669 CCD_END;
670 }
671 }
672 else
673 {
674 TRACE_EVENT_P1 ("PD wrong, PD=%d", pd);
675 }
676 }
677 else
678 {
679 TRACE_ERROR("for_mmsms_data_ind() error evaluating PD TI");
680 }
681 PFREE (data_ind) ;
682 }
683
684 #if defined (GPRS)
685 /*
686 +--------------------------------------------------------------------+
687 | PROJECT : GSM-PS (8410) MODULE : SMS_CP |
688 | STATE : code ROUTINE : cp_ll_unitdata_ind |
689 +--------------------------------------------------------------------+
690
691 PURPOSE : Processing the signal LL_UNITDATA_IND (GSMS only).
692
693 */
694 GLOBAL void for_ll_unitdata_ind (T_LL_UNITDATA_IND *ll_unitdata_ind)
695 {
696
697 UBYTE ti;
698 UBYTE pd;
699 CHAR *msg_type;
700
701 T_SMS_DATA *sms_global = GET_INSTANCE(0);
702
703 /* Enable the PCO to correctly decode the message */
704 PPASS (ll_unitdata_ind, unitdata_ind, LL_UNITDATA_IND);
705
706 TRACE_FUNCTION ("for_ll_unitdata_ind()");
707
708 if (!(unitdata_ind->sapi EQ LL_SAPI_7))
709 {
710 TRACE_EVENT ("SAPI not LL_SAPI_7");
711 PFREE (unitdata_ind);
712 return;
713 }
714
715 if (sms_global) /*lint !e774 (sms_global) always */
716 {
717 if (SMS_SMS_FLOW(sms_global) NEQ SMS_FLOW_AVAILABLE)
718 {
719 TRACE_ERROR ("unexpected primitive");
720 }
721
722 /*
723 * data has been received, mark flow status as busy
724 */
725 SMS_SMS_FLOW(sms_global) = SMS_FLOW_BUSY;
726 }
727
728 if (for_get_pd_ti (&unitdata_ind->sdu, &pd, &ti))
729 {
730 if (/*((! ti) OR (ti >= 8)) AND*/ (pd EQ PD_SMS))
731 {
732 register T_SMS_DATA *sms_data = GET_SMS_INSTANCE(ti);
733
734 if (sms_data)
735 {
736 CCD_START;
737
738 ccd_decodeMsg (CCDENT_SMS,
739 DOWNLINK,
740 (T_MSGBUF *) &unitdata_ind->sdu,
741 (UBYTE *) _decodedMsg,
742 NOT_PRESENT_8BIT);
743
744 switch (_decodedMsg[0])
745 {
746 case D_CP_DATA:
747 cp_data_ind_cp_data ((T_D_CP_DATA *)_decodedMsg);
748 msg_type = "D_CP_DATA";
749 break ;
750
751 case B_CP_ERROR:
752 {
753 MCAST (error, B_CP_ERROR);
754
755 cp_data_ind_cp_error (error->cp_cause);
756 msg_type = "B_CP_ERROR";
757 break ;
758 }
759
760 case B_CP_ACK:
761 cp_data_ind_cp_ack ();
762 msg_type = "B_CP_ACK";
763 break ;
764 default:
765 cp_data_ind_cp_unknown ();
766 msg_type = "UNKNOWN MESSAGE";
767 break ;
768 }
769 CCD_END;
770 TRACE_BINDUMP(sms_handle,
771 TC_USER4,
772 msg_type,
773 (&(unitdata_ind->sdu.buf[0]) + ((unitdata_ind->sdu.o_buf >> 3) -1)),
774 ((unitdata_ind->sdu.l_buf >> 3) + 1));
775 }
776 else
777 {
778 /*
779 * no SMS instance associated with pid, try to create new one
780 */
781 if (ti & 0x8)
782 {
783 register T_SMS_DATA *sms_data = for_get_new_mt_instance (ti);
784
785 if (sms_data)
786 {
787 CCD_START;
788
789 ccd_decodeMsg (CCDENT_SMS,
790 DOWNLINK,
791 (T_MSGBUF *) &unitdata_ind->sdu,
792 (UBYTE *) _decodedMsg,
793 NOT_PRESENT_8BIT);
794
795 SMS_INST_SET_STATE (STATE_CP, CP_GSMS_IDLE);
796 SMS_INST.downlink = SMS_DOWNLINK_LL;
797
798 switch (_decodedMsg[0])
799 {
800 case D_CP_DATA:
801 cp_data_ind_cp_data ((T_D_CP_DATA*) _decodedMsg);
802 msg_type = "D_CP_DATA";
803 break ;
804
805 case B_CP_ERROR:
806 {
807 MCAST (error, B_CP_ERROR);
808
809 cp_data_ind_cp_error (error->cp_cause);
810 msg_type = "B_CP_ERROR";
811 }
812 break ;
813
814 case B_CP_ACK:
815 cp_data_ind_cp_ack ();
816 msg_type = "B_CP_ACK";
817 break ;
818
819 default:
820 cp_data_ind_cp_unknown ();
821 msg_type = "UNKNOWN MESSAGE";
822 break ;
823 }
824 CCD_END;
825 TRACE_BINDUMP(sms_handle,
826 TC_USER4,
827 msg_type,
828 (&(unitdata_ind->sdu.buf[0]) + ((unitdata_ind->sdu.o_buf >> 3) -1)),
829 ((unitdata_ind->sdu.l_buf >> 3) + 1));
830 }
831 else
832 {
833 /*
834 * no further instance available, send rp error message
835 */
836 register T_SMS_DATA* sms_data_main = GET_INSTANCE(0);
837 CCD_START;
838
839 ccd_decodeMsg (CCDENT_SMS,
840 DOWNLINK,
841 (T_MSGBUF *) &unitdata_ind->sdu,
842 (UBYTE *) _decodedMsg,
843 NOT_PRESENT_8BIT);
844 if (sms_data_main) /*lint !e774 (sms_data_main) always */
845 {
846 if ((_decodedMsg[0] EQ D_CP_DATA) &&
847 (sms_data_main->llc_flow EQ SMS_LLC_AVAILABLE))
848 {
849 UBYTE msg_ref;
850
851 MCAST (d_cp_data, D_CP_DATA);
852 MCAST (cp_data, U_CP_DATA);
853 /*
854 * U_CP_DATA contains a maximum of 252 Bytes
855 */
856 PALLOC_SDU (unitdata_req, LL_UNITDATA_REQ, LEN_U_CP_DATA);
857
858 cp_init_ll_unitdata_req (unitdata_req);
859 msg_ref = d_cp_data->cp_user_data_dl.reference;
860
861 rl_build_rp_error_gprs (ti, unitdata_req, SMS_RP_CS_PROTOCOL_ERROR,
862 msg_ref, cp_data, NULL);
863 sms_data_main->llc_flow = SMS_LLC_BUSY;
864 TRACE_BINDUMP(sms_handle,
865 TC_USER4,
866 "U_CP_DATA",
867 (&(unitdata_req->sdu.buf[0]) + ((unitdata_req->sdu.o_buf >> 3) -1)),
868 ((unitdata_req->sdu.l_buf >> 3) + 1));
869 PSENDX (LLC, unitdata_req);
870 }
871 }
872 CCD_END;
873 }
874 }
875 else
876 {
877 TRACE_EVENT_P1 ("Unknown TI with response flag set, TI=%d", ti);
878 }
879 }
880 }
881 else
882 {
883 TRACE_EVENT_P1 ("PD wrong, PD=%d", pd);
884 }
885 }
886
887 PFREE (unitdata_ind);
888
889 /*
890 * Receive ready, if sending is not blocked
891 */
892 // if (SMS_LLC_FLOW(sms_global) NEQ SMS_LLC_BUSY_WAITING)
893 {
894 cp_send_getunitdata_req ();
895 }
896 }
897
898 /*
899 +--------------------------------------------------------------------+
900 | PROJECT : GSM-PS (8410) MODULE : SMS_CP |
901 | STATE : code ROUTINE : for_ll_unitready_ind |
902 +--------------------------------------------------------------------+
903
904 PURPOSE : Processing the signal LL_UNITREADY_IND (GSMS only).
905 */
906
907 GLOBAL void for_ll_unitready_ind (T_LL_UNITREADY_IND *unitready_ind)
908 {
909 GET_INSTANCE_DATA;
910
911 TRACE_FUNCTION ("ll_unitready_ind()");
912
913 if ((unitready_ind->sapi NEQ LL_SAPI_7) || !sms_data) /*lint !e774 (!sms_data) never */
914 {
915 TRACE_EVENT ("ll_unitready_ind(): SAPI not LL_SAPI_7 or no SMS instance");
916 PFREE (unitready_ind);
917 return;
918 }
919
920 if (SMS_LLC_FLOW(sms_data) EQ SMS_LLC_BUSY_WAITING)
921 {
922 /*
923 * find the message waiting for LLC
924 */
925 GET_MO_INSTANCE(sms_data);
926
927 if (SMS_INST_GET_STATE (STATE_CP) EQ CP_GSMS_IDLE)
928 {
929 switch (SMS_CP_ACK_TYPE(sms_data))
930 {
931 case SMS_CP_ACK:
932 cp_build_cp_ack ();
933 SMS_LLC_FLOW(sms_data) = SMS_LLC_BUSY;
934
935 if (SMS_CP_UDL(sms_data) NEQ NULL)
936 {
937 rl_data_ind (SMS_CP_UDL(sms_data));
938 MFREE(SMS_CP_UDL(sms_data));
939 SMS_CP_UDL(sms_data) = NULL;
940 }
941 if (SMS_INST.r_flag)
942 {
943 /*
944 * terminate SMS instance
945 */
946 SMS_INST_SET_STATE (STATE_CP, CP_IDLE);
947 SMS_INST.r_flag = FALSE;
948 FREE_SMS_INSTANCE (SMS_INST.ti);
949 }
950 break;
951
952 case SMS_CP_ERROR:
953 cp_build_cp_error (SMS_CP_CAUSE(sms_data));
954 SMS_LLC_FLOW(sms_data) = SMS_LLC_BUSY;
955 /*
956 * terminate SMS instance
957 */
958 SMS_INST_SET_STATE (STATE_CP, CP_IDLE);
959 SMS_INST.r_flag = FALSE;
960 FREE_SMS_INSTANCE (SMS_INST.ti);
961 break;
962
963 default:
964 SMS_LLC_FLOW(sms_data) = SMS_LLC_AVAILABLE;
965 break;
966 }
967 SMS_CP_ACK_TYPE(sms_data) = SMS_CP_NONE;
968 }
969 else
970 {
971 SMS_LLC_FLOW(sms_data) = SMS_LLC_AVAILABLE;
972 }
973 if (SMS_LLC_FLOW(sms_data) EQ SMS_LLC_AVAILABLE)
974 {
975 GET_MT_INSTANCE(sms_data);
976
977 switch (SMS_INST_GET_STATE (STATE_CP))
978 {
979 case CP_GSMS_IDLE:
980 case CP_GSMS_MT_WAIT_FOR_RP_ACK:
981 case CP_GSMS_MT_WAIT_FOR_CP_ACK:
982 switch (SMS_CP_ACK_TYPE(sms_data))
983 {
984 case SMS_CP_ACK:
985 cp_build_cp_ack ();
986 if (SMS_INST_GET_STATE (STATE_CP) EQ CP_GSMS_MT_WAIT_FOR_CP_ACK)
987 { /* stored CP-DATA will follow */
988 SMS_LLC_FLOW(sms_data) = SMS_LLC_BUSY_WAITING;
989 }
990 else
991 {
992 SMS_LLC_FLOW(sms_data) = SMS_LLC_BUSY;
993 }
994 break;
995
996 case SMS_CP_ERROR:
997 cp_build_cp_error (SMS_CP_CAUSE(sms_data));
998 SMS_LLC_FLOW(sms_data) = SMS_LLC_BUSY;
999 /*
1000 * terminate SMS instance
1001 */
1002 SMS_INST_SET_STATE (STATE_CP, CP_IDLE);
1003 SMS_INST.r_flag = FALSE;
1004 FREE_SMS_INSTANCE (SMS_INST.ti);
1005 break;
1006
1007 default:
1008 if (SMS_INST_GET_STATE (STATE_CP) EQ CP_GSMS_MT_WAIT_FOR_CP_ACK
1009 AND SMS_DATA_REQ(sms_data) NEQ 0)
1010 {
1011 cp_send_data_gsms ();
1012 SMS_LLC_FLOW(sms_data) = SMS_LLC_BUSY;
1013 }
1014 break;
1015
1016 }
1017 SMS_CP_ACK_TYPE(sms_data) = SMS_CP_NONE;
1018 break;
1019
1020 default:
1021 break;
1022 }
1023 }
1024 if (SMS_LLC_FLOW(sms_data) EQ SMS_LLC_AVAILABLE)
1025 {
1026 GET_MO_INSTANCE(sms_data);
1027
1028 switch (SMS_INST_GET_STATE (STATE_CP))
1029 {
1030 case CP_GSMS_MO_WAIT_FOR_CP_ACK:
1031 cp_send_data_gsms ();
1032
1033 SMS_LLC_FLOW(sms_data) = SMS_LLC_BUSY;
1034 break;
1035
1036 case CP_GSMS_IDLE:
1037 cp_send_data_gsms ();
1038 rl_proceed ();
1039
1040 SMS_INST.r_flag = TRUE;
1041 SMS_INST_SET_STATE (STATE_CP, CP_GSMS_MO_WAIT_FOR_CP_ACK);
1042 SMS_LLC_FLOW(sms_data) = SMS_LLC_BUSY;
1043 break;
1044
1045 default:
1046 break;
1047 }
1048 }
1049 }
1050 else
1051 {
1052 SMS_LLC_FLOW(sms_data) = SMS_LLC_AVAILABLE;
1053 }
1054 PFREE (unitready_ind);
1055
1056 // cp_send_getunitdata_req (sms_data);
1057 }
1058
1059 #endif /* GPRS */
1060
1061 #endif /* #ifndef SMS_FOR_C */