comparison gpf/tst_drv/tif2.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 | File: tif.c
4 +------------------------------------------------------------------------------
5 | Copyright 2002 Texas Instruments Berlin, AG
6 | All rights reserved.
7 |
8 | This file is confidential and a trade secret of Texas
9 | Instruments Berlin, AG
10 | The receipt of or possession of this file does not convey
11 | any rights to reproduce or disclose its contents or to
12 | manufacture, use, or sell anything it may describe, in
13 | whole, or in part, without the specific written consent of
14 | Texas Instruments Berlin, AG.
15 +-----------------------------------------------------------------------------
16 | Purpose : This Modul contains the TIF driver
17 +-----------------------------------------------------------------------------
18 */
19
20 #ifndef __TIF_C__
21 #define __TIF_C__
22 #endif
23
24 #include <string.h>
25 #include "gpfconf.h"
26 #include "typedefs.h"
27 #include "gdi.h"
28 #include "vsi.h"
29 #include "tools.h"
30 #include "glob_defs.h"
31 #if 0 // FreeCalypso
32 #include "ccdtable.h"
33 #include "ccddata.h"
34 #endif
35 #include "pcon.h"
36 #include "p_mem.h"
37 #include "drvconf.h"
38 #include "tstheader.h"
39
40 #ifdef _TOOLS_
41 #include "frame_const.h"
42 #include <stdio.h>
43 #endif /* _TOOLS_ */
44 #include "printtofile.h"
45
46 #ifndef _TOOLS_
47 #if !defined (_SOLARIS_) && !defined (_LINUX_)
48 #pragma pack(4)
49 #endif
50 #endif
51
52 /*lint -e545 */
53 /*==== TYPES ======================================================*/
54
55 typedef struct
56 {
57 USHORT Handle;
58 USHORT EnabledSignalType;
59 T_DRV_CB_FUNC Callback;
60 USHORT Config;
61 } T_TIF_DATA;
62
63 #ifdef _TOOLS_
64 typedef struct
65 {
66 unsigned int use_id;
67 char *name;
68 } T_RIV_USEID_TO_NAME;
69 #endif
70
71 /*==== CONSTANTS ==================================================*/
72
73 #define ALLOWED_TIF_SIGNALS (DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT|DRV_SIGTYPE_DISCONNECT)
74
75 #define NAME_LENGTH 4
76
77 #define TIF_RCV_CMD_SIZE 32
78 #define TIF_MAX_CMD (TIF_RCV_CMD_SIZE-1)
79
80 #define STX 0x02
81 #define LF 0x0a
82
83 #define PCON_ENABLED 0x0001
84 #define SYNC_MODE 0x0002
85
86 #undef VSI_CALLER
87 #define VSI_CALLER TST_Handle,
88
89 #ifdef _TOOLS_
90 const T_RIV_USEID_TO_NAME riv_use_id_to_name[] =
91 {
92 { 0x00010001, "RVM" },
93 { 0x00010002, "RVT" },
94 { 0x000A0001, "R2D" },
95 { 0x000A0002, "RTC" },
96 { 0x000A0004, "FFS" },
97 { 0x000A0008, "KPD" },
98 { 0x000A0010, "SPI" },
99 { 0x000A0020, "PWR" },
100 { 0x000A0040, "RGUI" },
101 { 0x00140001, "HCI" },
102 { 0x00140002, "L2CA" },
103 { 0x00140004, "BTCT" },
104 { 0x00140008, "RFC" },
105 { 0x00140010, "SPP" },
106 { 0x00140020, "HS" },
107 { 0x00140040, "HSG" },
108 { 0x00140080, "SDP" },
109 { 0x00140100, "DUN" },
110 { 0x00140200, "FAX" },
111 { 0x00140400, "OBX" },
112 { 0x00140800, "OPP" },
113 { 0x00141000, "FTP" },
114 { 0x00142000, "SYN" },
115 { 0x001E0001, "EXPL" },
116 { 0x001E0010, "AUDIO" },
117 { 0x001E0020, "ETM" },
118 { 0x001E0040, "DAR" },
119 { 0x001E0080, "MKS" },
120 { 0x001E0100, "MPM" },
121 { 0x001E0200, "LLS" },
122 { 0x001E0400, "ATP" },
123 { 0x001E0800, "ATPUART" },
124 { 0x001E2000, "MDC" },
125 { 0x001E4000, "TTY" },
126 { 0x001E8000, "DCM" },
127 { 0x00280001, "TEST" },
128 { 0x00280002, "TUT" },
129 { 0x00320001, "KIL" },
130 { 0x00320002, "KGC" },
131 { 0x00320004, "KCL" },
132 { 0x00320008, "KMM" },
133 { 0x00320010, "KNM" },
134 { 0x00320020, "UVM" },
135 { 0x00320040, "KZP" },
136 { 0x00320080, "KPG" },
137 { 0x00320100, "JTM" },
138 { 0x003C0001, "DEV1" },
139 { 0x003C0002, "DEV2" },
140 { 0x003C0003, "DEV3" },
141 { 0x00460001, "RNET" },
142 { 0x00460002, "RNET_WS" },
143 { 0x00460004, "RNET_RT" },
144 { 0x00460008, "RNET_BR" },
145 { 0x00640001, "MSME" },
146 { 0x00640002, "MSFE" },
147 { 0x00640004, "STKE" },
148 { 0x00640008, "BRSE" },
149 { 0x00640010, "BRAE" },
150 { 0x00640020, "PHSE" },
151 { 0x00640040, "IBSE" },
152 { 0x00640080, "MMSE" },
153 { 0x00640100, "SLSE" },
154 { 0x00640200, "SMAE" },
155 { 0x00640400, "MEAE" },
156 { 0x00640800, "SECE" },
157 { 0x00641000, "SELE" },
158 { 0x00642000, "PRSE" },
159 { 0x00644000, "JAAE" },
160 { 0x00648000, "JASE" },
161 { 0x006E0001, "IT1E" },
162 { 0x006E0002, "IT2E" },
163 { 0x006E0004, "IT0E" },
164 { 0x0, NULL}
165 };
166 #endif
167
168 /*==== EXTERNALS ==================================================*/
169
170 extern T_HANDLE TST_Handle;
171
172 #ifndef _TOOLS_
173 extern const T_PCON_PROPERTIES *pcon;
174 extern ULONG MaxPrimPartSize;
175 extern const T_MEM_PROPERTIES *mem;
176 #endif
177
178 #ifdef CTB
179 extern BOOL ctb_sent_to_tap;
180 extern BOOL ctb_tick_enabled;
181 #endif
182
183 /*==== VARIABLES ==================================================*/
184
185 #ifndef RUN_INT_RAM
186 char corruptWarning[] = "corrupt prim received: ";
187 char wrongTSTWarning[] = "wrong (old) TST header used on toolside! ";
188 T_TIF_DATA TIF_Data;
189 static ULONG TIF_WrInd = 0;
190 BOOL socket_flush = TRUE;
191 #else
192 extern T_TIF_DATA TIF_Data;
193 extern BOOL socket_flush;
194 #endif /* RUN_INT_RAM */
195
196 #ifdef _TOOLS_
197 char buffer[80];
198
199 const T_PCON_PROPERTIES pcon_export =
200 {
201 pcon_init_prim_coding,
202 pcon_decodePrim,
203 pcon_codePrim,
204 pcon_make_filter,
205 PCON_STACK_OFFSET
206 };
207
208 T_PCON_PROPERTIES const *pcon = &pcon_export;
209 #endif
210
211 /*==== FUNCTIONS ==================================================*/
212
213 #ifndef RUN_INT_RAM
214 USHORT TIF_Write ( void *Buffer, ULONG *BytesToWrite );
215 #endif
216
217 #ifndef RUN_INT_RAM
218 /*
219 +--------------------------------------------------------------------+
220 | PROJECT : GSM-Frame (8415) MODULE : TIF |
221 | STATE : code ROUTINE : TIF_Exit |
222 +--------------------------------------------------------------------+
223
224 PURPOSE : exit a driver
225
226 */
227 LOCAL void TIF_Exit ( void )
228 {
229 #ifdef _TOOLS_
230 ccddata_exit();
231 #endif /* _TOOLS_ */
232 }
233 #endif
234
235 #ifndef RUN_FLASH
236 /*
237 +--------------------------------------------------------------------+
238 | PROJECT : GSM-Frame (8415) MODULE : TIF |
239 | STATE : code ROUTINE : TIF_Write |
240 +--------------------------------------------------------------------+
241
242 PURPOSE : write data to driver
243
244 */
245 /* Lint is not able to analyze the program flow through if...else constructions
246 and therefor bring a bunch of warnings.*/
247 /*lint -e645 suppress warning -- Symbol '...' may not have been initialized */
248 /*lint -e644 suppress warning -- Symbol '...' may not have been initialized */
249 /*lint -e613 suppress warning -- possibly use of NULL pointer '...' */
250 USHORT TIF_Write ( void *Buffer, ULONG *BytesToWrite )
251 {
252 T_PRIM_HEADER *prim = (T_PRIM_HEADER*)Buffer;
253 T_PRIM_HEADER *prim_ptr = NULL;
254 TST_SMALL_HEADER *tst_header_ptr;
255 T_S_HEADER *s_hdr;
256 unsigned int bytes_to_write;
257 unsigned int size;
258 unsigned int name_len;
259 unsigned int length;
260 unsigned int org_rcv_len = 0;
261 unsigned int opc_len = 0;
262 unsigned int bytes_written = 0;
263 unsigned int write_flag = 0;
264 char *write_ptr;
265 char *tst_data_ptr;
266 char trace_opc=0;
267 char Sender[RESOURCE_NAMELEN] = {0};
268 void *coded_prim;
269 void *decoded_prim;
270 int pcon_called = 0;
271 int is_primitive = TRUE;
272 int ret = DRV_OK;
273 int sts;
274 #ifdef _TOOLS_
275 int is_generated_primitive = FALSE;
276 #endif /* _TOOLS_ */
277
278
279 s_hdr = (T_S_HEADER*)((ULONG*)prim + prim->sh_offset);
280 if ( prim->opc & SYS_MASK )
281 {
282 size = prim->len - sizeof(T_PRIM_HEADER);
283 tst_data_ptr = (char*)P2D(prim);
284 tst_header_ptr = (TST_SMALL_HEADER*) tst_data_ptr - 1;
285 tst_header_ptr->combined[INFO_BYTE] = (~HDR_IDENT_MASK | IDENT_SYS_PRIM);
286 InsertString(s_hdr->rcv, (char*)&tst_header_ptr->receiver, 4);
287 is_primitive = FALSE;
288 #ifdef _TOOLS_
289 if ( (length = GetNextToken (tst_data_ptr, buffer, " #")) > 0)
290 {
291 if ( !strcmp (buffer, FILTER) )
292 {
293 void *filter_prim;
294 if ( (pcon != NULL) && pcon->make_filter(tst_data_ptr+length+1, &filter_prim) == PCON_OK )
295 {
296 prim = D2P(filter_prim);
297 s_hdr = (T_S_HEADER*)((ULONG*)prim + prim->sh_offset);
298 is_primitive = TRUE;
299 is_generated_primitive = TRUE;
300 }
301 }
302 }
303 #endif
304 }
305 else if ( (SAP_NR(prim->opc)==TRACE_SAP) || (prim->opc==TRACE_OPC) )
306 {
307 is_primitive = FALSE;
308 size = prim->len - sizeof(T_PRIM_HEADER);
309 tst_data_ptr = (char*)P2D(prim);
310 if (prim->opc!=TRACE_OPC)
311 {
312 /* we have a traceclass id */
313 trace_opc=(char)PRIM_NR(prim->opc);
314 }
315 tst_header_ptr = (TST_SMALL_HEADER*) tst_data_ptr - 1;
316 tst_header_ptr->combined[INFO_BYTE] = (~HDR_IDENT_MASK | IDENT_TRACE);
317 InsertString(FRM_PCO_NAME, (char*)&tst_header_ptr->receiver, 4);
318 }
319 if ( is_primitive == TRUE )
320 {
321 TST_BIG_HEADER tst_big_header;
322 TST_BIG_HEADER *tst_big_header_ptr;
323 #ifdef _TOOLS_
324 /* on the tool side the primitive to be duplicated is copied when sent to TST */
325 prim_ptr = prim;
326 #else
327 /* in the target a pointer to the primitive to be duplicated is transported in a carrier of type T_PRIM_X */
328 prim_ptr = (T_PRIM_HEADER*)((T_PRIM_X*)(prim))->prim_ptr;
329 #endif
330
331 size = prim_ptr->len - sizeof(T_PRIM_HEADER);
332 tst_data_ptr = (char*)P2D(prim_ptr);
333 tst_big_header_ptr = &tst_big_header;
334 opc_len = 4;
335 org_rcv_len = 4;
336 if ( (pcon != NULL) && (TIF_Data.Config & PCON_ENABLED) && !(prim_ptr->opc & VIRTUAL_OPC) )
337 {
338 decoded_prim = P2D(prim_ptr);
339 if ( (sts = (int)(pcon->code_prim( prim_ptr->opc, decoded_prim, &coded_prim, (ULONG*)&size, 0, s_hdr->rcv ))) != PCON_OK )
340 {
341 vsi_o_ttrace (NO_TASK, TC_SYSTEM,"PCON Code Error %d, TIF_Write() aborted", sts );
342 return DRV_INTERNAL_ERROR;
343 }
344 else
345 {
346 prim_ptr = D2P(coded_prim);
347 tst_data_ptr = coded_prim;
348 pcon_called = 1;
349 }
350 }
351
352 EXCHANGE_4BYTES_ENDIANESS(&prim_ptr->opc);
353
354 tst_big_header_ptr->opc = prim_ptr->opc;
355 tst_big_header_ptr->combined[INFO_BYTE] = (~HDR_IDENT_MASK | IDENT_PS_PRIM);
356 InsertString(s_hdr->rcv, (char*) &tst_big_header_ptr->receiver, 4);
357 InsertString(s_hdr->org_rcv, (char*) &tst_big_header_ptr->orgreceiver, 4);
358 socket_flush = TRUE;
359 tst_header_ptr = (TST_SMALL_HEADER*) tst_big_header_ptr;
360 }
361
362 tst_header_ptr->combined[INFO_BYTE] = ((tst_header_ptr->combined[INFO_BYTE] & (~HDR_VERSION_MASK)) | HDR_VALID_VERSION_1);
363 tst_header_ptr->combined[INFO_BYTE] = ((tst_header_ptr->combined[INFO_BYTE] & (~HDR_TIME_MASK)) | HDR_TIME_MS);
364 tst_header_ptr->time = s_hdr->time;
365 EXCHANGE_4BYTES_ENDIANESS(&tst_header_ptr->time);
366 tst_header_ptr->sender[0] = 0;
367
368 if ( s_hdr->snd[0] == 0 )
369 {
370 if ( *tst_data_ptr == '~')
371 {
372 name_len = GetNextToken ((char*)(tst_data_ptr), Sender, "~");
373 InsertString(Sender, (char*) &tst_header_ptr->sender, 4);
374 size -= 2+name_len;
375 /* rub out a leading ~NAM~ in data field: */
376 memcpy ( tst_data_ptr, tst_data_ptr + 2 + name_len, size );
377 }
378 else
379 {
380 InsertString(FRM_SYST_NAME, (char*)&tst_header_ptr->sender, 4);
381 }
382 }
383 else
384 {
385 T_HANDLE TaskHandle;
386 if ( s_hdr->snd[0] & ~HANDLE_MASK )
387 {
388 TaskHandle = (T_HANDLE)(s_hdr->snd[0]&HANDLE_MASK);
389 vsi_e_name ( TST_Handle, TaskHandle, Sender );
390 InsertString(Sender, (char*)&tst_header_ptr->sender, 4);
391 }
392 else
393 {
394 InsertString(s_hdr->snd, (char*)&tst_header_ptr->sender, 4);
395 }
396 }
397
398 length = size + TST_HEADER_TRAILING_FIELDS + org_rcv_len + opc_len + (trace_opc ? 1 : 0);
399 tst_header_ptr->combined[FIRST_BYTE] = (UBYTE) (LOW_MASK & length);
400 tst_header_ptr->combined[SECOND_BYTE] = (UBYTE) (LOW_MASK & (length >> 8));
401 bytes_to_write = length + TST_HEADER_LEADING_FIELDS;
402 write_ptr = (char*)&tst_header_ptr->combined[INFO_BYTE];
403 if (trace_opc)
404 {
405 /* move small header 1 byte to the left and insert trace class id */
406 char *trace_opc_ptr=tst_data_ptr-1;
407 write_ptr = (char*)tst_header_ptr;
408 memcpy(write_ptr,(char*)tst_header_ptr+1,sizeof(TST_SMALL_HEADER)-1);
409 *trace_opc_ptr=trace_opc;
410 length++;
411 }
412 else if ( prim_ptr != NULL )
413 {
414 bytes_written = TST_BIG_HEADER_SIZE;
415 if ( vsi_d_write ( TIF_Data.Handle, 0, write_ptr, bytes_written | PRIM_HEADER_FLAG ) != VSI_OK )
416 {
417 ret = DRV_INTERNAL_ERROR;
418 *BytesToWrite = 0;
419 }
420 write_ptr = tst_data_ptr;
421 write_flag = PRIM_DATA_FLAG;
422 }
423
424 if (ret==DRV_OK)
425 {
426 #if defined (_TOOLS_) || defined (_LINUX_) || defined (_SOLARIS_)
427 socket_flush = TRUE; /* flush socket always on tool side */
428 #endif
429
430 if ( vsi_d_write ( TIF_Data.Handle, 0, write_ptr, (bytes_to_write - bytes_written) | write_flag ) != VSI_OK )
431 {
432 ret = DRV_INTERNAL_ERROR;
433 *BytesToWrite = 0;
434 }
435 }
436 if ( pcon_called )
437 {
438 PFREE(P2D((T_VOID_STRUCT*)prim_ptr));
439 }
440 #ifdef _TOOLS_
441 if ( is_generated_primitive == TRUE )
442 {
443 vsi_c_free ( TST_Handle, (T_VOID_STRUCT**)&prim );
444 }
445 #else /* _TOOLS_ */
446 if (prim->opc & MEMHANDLE_OPC)
447 {
448 M_FREE(P_MEMHANDLE_SDU(((T_PRIM_X*)(prim))->prim_ptr));
449 }
450 #endif /* _TOOLS_ */
451 #if defined _NUCLEUS_ && !defined _TARGET_
452 #ifdef CTB
453 if(ctb_tick_enabled && !ctb_sent_to_tap && !strncmp(tst_header_ptr->receiver,"TAP",3))
454 {
455 ctb_sent_to_tap = TRUE;
456 }
457 #endif
458 #endif
459
460 return ( (USHORT)ret );
461 }
462 /*lint +e645 */
463 /*lint +e613 */
464 #endif
465
466 #ifndef RUN_INT_RAM
467 /*
468 +--------------------------------------------------------------------+
469 | PROJECT : GSM-Frame (8415) MODULE : TIF |
470 | STATE : code ROUTINE : TIF_SetSignal |
471 +--------------------------------------------------------------------+
472
473 PURPOSE : enable signal for the driver
474
475 */
476 LOCAL USHORT TIF_SetSignal ( USHORT SignalType )
477 {
478 if ( !(SignalType & ALLOWED_TIF_SIGNALS) )
479 return DRV_INVALID_PARAMS;
480 else
481 TIF_Data.EnabledSignalType |= SignalType;
482
483 return DRV_OK;
484 }
485 #endif
486
487 #ifndef RUN_INT_RAM
488 /*
489 +--------------------------------------------------------------------+
490 | PROJECT : GSM-Frame (8415) MODULE : TIF |
491 | STATE : code ROUTINE : TIF_ResetSignal |
492 +--------------------------------------------------------------------+
493
494 PURPOSE : disable signal for the driver
495
496 */
497 LOCAL USHORT TIF_ResetSignal ( USHORT SignalType )
498 {
499 if ( !(SignalType & ALLOWED_TIF_SIGNALS) )
500 return DRV_INVALID_PARAMS;
501 else
502 TIF_Data.EnabledSignalType &= ~SignalType;
503
504 return DRV_OK;
505 }
506 #endif
507
508 #ifndef RUN_INT_RAM
509 /*
510 +--------------------------------------------------------------------+
511 | PROJECT : GSM-Frame (8415) MODULE : TIF |
512 | STATE : code ROUTINE : TIF_SetConfig |
513 +--------------------------------------------------------------------+
514
515 PURPOSE : set configuration for the driver
516
517 */
518 /*lint -esym(715,Buffer), suppress Info -- Symbol 'Buffer' not referenced) */
519 LOCAL USHORT TIF_SetConfig ( char *Buffer )
520 {
521 if ( !strcmp ( TIF_PCON_ENABLE, Buffer ) )
522 {
523 if ( TIF_Data.Config & PCON_ENABLED)
524 {
525 /* already in PCON mode */
526 return DRV_OK;
527 }
528
529 #ifdef _TOOLS_
530 switch (ccddata_init(NULL,0,NULL,NULL))
531 {
532 case CCDDATA_DLL_OK:
533 case CCDDATA_DLL_ALREADY:
534 break;
535 default:
536 return DRV_INTERNAL_ERROR;
537 }
538 #endif
539 TIF_Data.Config |= PCON_ENABLED;
540
541 #ifdef _TOOLS_
542 printf("TIF: PCON mode selected\n");
543 #endif
544 return DRV_OK;
545 }
546 else if ( !strcmp ( DRV_DEFAULT, Buffer ) )
547 {
548 if ( !(TIF_Data.Config & PCON_ENABLED))
549 {
550 /* already in default mode */
551 return DRV_OK;
552 }
553
554 #ifdef _TOOLS_
555 ccddata_exit();
556 #endif
557 TIF_Data.Config &= ~PCON_ENABLED;
558
559 #ifdef _TOOLS_
560 printf("TIF: default mode selected\n");
561 #endif
562 return DRV_OK;
563 }
564 #ifdef _TOOLS_
565 else if ( !strcmp ( ENABLE_SYNC_MODE, Buffer ) )
566 {
567 TIF_Data.Config |= SYNC_MODE;
568 PrintToFile("TIF: sync mode enabled\n");
569 return DRV_OK;
570 }
571 else if ( !strcmp ( DISABLE_SYNC_MODE, Buffer ) )
572 {
573 TIF_Data.Config &= ~SYNC_MODE;
574 PrintToFile("TIF: sync mode disabled\n");
575 return DRV_OK;
576 }
577 return DRV_INVALID_PARAMS;
578 #else
579 return DRV_OK;
580 #endif
581 }
582 #endif
583
584 #ifndef RUN_INT_RAM
585 /*
586 +--------------------------------------------------------------------+
587 | PROJECT : GSM-Frame (8415) MODULE : TIF |
588 | STATE : code ROUTINE : Callback |
589 +--------------------------------------------------------------------+
590
591 PURPOSE : callback function of the driver
592
593 */
594 /* Lint is not able to analyze the program flow through if...else constructions
595 and therefor bring a bunch of warnings.*/
596 /*lint -esym(645,opc_str) suppress warning -- Symbol 'opc_str' may not have been initialized */
597 LOCAL void TIF_Callback ( T_DRV_SIGNAL *Signal )
598 {
599 T_PRIM_HEADER *prim;
600 T_S_HEADER *s_hdr;
601 T_PRIM_X *sys_prim;
602 T_DRV_SIGNAL TIF_Signal;
603 TST_BIG_HEADER tst_header;
604 unsigned int CorruptByteOffset = 0;
605 unsigned int length;
606 unsigned int BytesToRead = 0;
607 unsigned int BytesRead;
608 unsigned int Bytes = 0;
609 unsigned int i;
610 unsigned int opc_len = 0;
611 unsigned int org_rcv_len = 0;
612 unsigned int alloc_size;
613 int sts;
614 int WrongTSTHeader = FALSE;
615 char *target;
616 void *decoded_prim;
617 char opc_str[4];
618 #ifdef _TOOLS_
619 int l1_sigtype = 0;
620 #endif
621
622 switch ( Signal->SignalType )
623 {
624 #ifdef _TOOLS_
625 case DRV_SIGTYPE_READ_L1:
626 l1_sigtype = 1;
627 /*lint -fallthrough*/
628 case DRV_SIGTYPE_READ_RIV:
629
630 if ( vsi_d_read ( TIF_Data.Handle, 0, NULL, &BytesToRead ) != DRV_OK )
631 return;
632
633 alloc_size = S_ALLOC_SIZE(BytesToRead + 1);
634 if ( ( prim = (T_PRIM_HEADER*)vsi_c_new ( TST_Handle, alloc_size, 0 FILE_LINE_MACRO )) != NULL )
635 {
636 TIF_WrInd = 0;
637 Bytes = 0;
638 BytesRead = BytesToRead;
639 do
640 {
641 vsi_d_read ( TIF_Data.Handle, 0, (void*)((char*)P2D(prim)+TIF_WrInd), &BytesRead );
642 Bytes += BytesRead;
643 if ( Bytes < BytesToRead )
644 {
645 TIF_WrInd += BytesRead;
646 BytesRead = BytesToRead - BytesRead;
647 }
648 } while ( Bytes < BytesToRead );
649 prim->sh_offset = S_HDR_OFFSET(alloc_size - sizeof(T_S_HEADER));
650 s_hdr = (T_S_HEADER*)((ULONG*)prim + prim->sh_offset);
651 s_hdr->time = 0;
652 s_hdr->org_rcv[0] = 0;
653 if ( l1_sigtype == 1 )
654 {
655 strcpy ( s_hdr->snd, "L1" );
656 }
657 else
658 {
659 int i = 0;
660 unsigned int use_id = 0;
661 unsigned char *p = (unsigned char*)P2D(prim);
662 use_id = use_id | *p++ << 24;
663 use_id = use_id | *p++ << 16;
664 use_id = use_id | *p++ << 8;
665 use_id = use_id | *p;
666 do
667 {
668 if ( riv_use_id_to_name[i].use_id == use_id )
669 {
670 strcpy ( s_hdr->snd, riv_use_id_to_name[i].name );
671 break;
672 }
673 if ( riv_use_id_to_name[i+1].use_id == 0 )
674 strcpy ( s_hdr->snd, "RIV" );
675 } while ( riv_use_id_to_name[++i].use_id != 0 );
676 memcpy ( (char*)P2D(prim), (char*)P2D(prim)+5, BytesToRead);
677 }
678 strcpy ( s_hdr->rcv, FRM_PCO_NAME );
679
680 sys_prim = (T_PRIM_X*) vsi_c_new ( TST_Handle, alloc_size, 0 FILE_LINE_MACRO );
681 sys_prim->prim_ptr = prim;
682 prim->opc = 0;
683 prim->len = BytesToRead + sizeof(T_PRIM_HEADER);
684
685 if ( TIF_Data.EnabledSignalType & DRV_SIGTYPE_READ )
686 {
687 VSI_PPM_SEND ( (T_PRIM_HEADER*)sys_prim, TST_Handle );
688 VSI_PPM_SEND ( (T_PRIM_HEADER*)sys_prim->prim_ptr, TST_Handle );
689 TIF_Signal.SignalType = DRV_SIGTYPE_READ;
690 TIF_Signal.DrvHandle = TIF_Data.Handle;
691 TIF_Signal.UserData = (T_VOID_STRUCT*)sys_prim;
692 (TIF_Data.Callback)( &TIF_Signal );
693 }
694 }
695 break;
696 #endif
697 case DRV_SIGTYPE_READ:
698 /*
699 * Get the size of the needed buffer to store the data
700 */
701
702 if ( vsi_d_read ( TIF_Data.Handle, 0, NULL, (ULONG*)&BytesToRead ) != DRV_OK )
703 return;
704
705 if ( BytesToRead )
706 {
707 if ( BytesToRead >= TST_SMALL_HEADER_SIZE )
708 BytesToRead -= TST_SMALL_HEADER_SIZE;
709 Bytes = 0;
710 TIF_WrInd = 0;
711 BytesRead = TST_SMALL_HEADER_SIZE;
712 do
713 {
714 vsi_d_read ( TIF_Data.Handle, 0, (void*)((char*)&tst_header.combined[INFO_BYTE]+TIF_WrInd), (ULONG*)&BytesRead );
715 Bytes += BytesRead;
716 if ( Bytes < TST_SMALL_HEADER_SIZE )
717 {
718 TIF_WrInd += BytesRead;
719 BytesRead = TST_SMALL_HEADER_SIZE - BytesRead;
720 }
721 } while ( Bytes < TST_SMALL_HEADER_SIZE );
722
723 alloc_size = ALIGN(sizeof(T_PRIM_X));
724 sys_prim = (T_PRIM_X*) vsi_c_new ( TST_Handle, alloc_size, 0 FILE_LINE_MACRO );
725
726 switch (tst_header.combined[INFO_BYTE] & HDR_IDENT_MASK)
727 {
728 case IDENT_ABORT:
729 tst_header.combined[INFO_BYTE] = ((tst_header.combined[INFO_BYTE] & ~HDR_IDENT_MASK) | IDENT_TRACE);
730 #ifdef _TOOLS_
731 /* TR did loose byte(s)! Primitive is corrupt, no header val can be
732 guaranteed to be valid.
733 Create a HUGE trace prim with zero time, sender tst, receiver pco,
734 org_receiver tst
735 TRACE DATA will contain: a "corrupt prim received: " string,
736 the already received part of the prim and all the rest */
737 CorruptByteOffset = TST_SMALL_HEADER_SIZE + strlen(corruptWarning) + 1;
738 #else
739 /* TR did receive a prim from tool side old TST header format and swiched to new.
740 Now we have to TRACE the wrong tool side format, because the prim is lost. */
741 WrongTSTHeader = TRUE;
742 BytesToRead = 0;
743 CorruptByteOffset = strlen(wrongTSTWarning) + 1;
744 #endif
745 break;
746 case IDENT_PS_PRIM:
747 opc_len = 4;
748 org_rcv_len = 4;
749 break;
750 default:
751 break;
752 }
753
754 if ( (BytesRead = org_rcv_len) > 0 )
755 {
756 if ( BytesToRead >= org_rcv_len )
757 BytesToRead -= org_rcv_len;
758 Bytes = 0;
759 TIF_WrInd = 0;
760 do
761 {
762 vsi_d_read ( TIF_Data.Handle, 0, (void*)((char*)&tst_header.orgreceiver+TIF_WrInd), (ULONG*)&BytesRead );
763 Bytes += BytesRead;
764 if ( Bytes < org_rcv_len )
765 {
766 TIF_WrInd += BytesRead;
767 BytesRead = org_rcv_len - BytesRead;
768 }
769 } while ( Bytes < org_rcv_len );
770 }
771
772 if ( (BytesRead = opc_len) > 0 )
773 {
774 if ( BytesToRead >= opc_len )
775 BytesToRead -= opc_len;
776 Bytes = 0;
777 TIF_WrInd = 0;
778 do
779 {
780 vsi_d_read ( TIF_Data.Handle, 0, (void*)(opc_str+TIF_WrInd), (ULONG*)&BytesRead );
781 Bytes += BytesRead;
782 if ( Bytes < opc_len )
783 {
784 TIF_WrInd += BytesRead;
785 BytesRead = opc_len - BytesRead;
786 }
787 } while ( Bytes < opc_len );
788 }
789
790 alloc_size = S_ALLOC_SIZE(CorruptByteOffset + BytesToRead + 1);
791 #ifdef _TOOLS_
792 if ( alloc_size > MAX_PRIM_PARTITION_SIZE - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER))
793 alloc_size = MAX_PRIM_PARTITION_SIZE - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER);
794 #else
795 if ( alloc_size > MaxPrimPartSize - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER) )
796 alloc_size = MaxPrimPartSize - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER);
797 #endif
798 if ( ( prim = (T_PRIM_HEADER*)vsi_c_new ( TST_Handle, alloc_size, 0 FILE_LINE_MACRO )) != NULL )
799 {
800 TIF_WrInd = 0;
801 Bytes = 0;
802 if ((BytesToRead + CorruptByteOffset) > alloc_size)
803 {
804 #ifdef _TOOLS_
805 PrintToFile("TIF: Reduced a new Prim's size\n");
806 #endif
807 BytesToRead = alloc_size - CorruptByteOffset;
808 }
809 BytesRead = BytesToRead;
810
811 target = (char*) P2D(prim);
812
813 if (WrongTSTHeader)
814 {
815 memcpy(target, wrongTSTWarning, strlen(wrongTSTWarning));
816 target += strlen(wrongTSTWarning);
817 }
818 else if (CorruptByteOffset)
819 {
820 #ifdef _TOOLS_
821 PrintToFile("TIF: Byte(s) lost\n");
822 #endif
823 memcpy(target, corruptWarning, strlen(corruptWarning));
824 target += strlen(corruptWarning);
825 /*lint -e420, suppress Warning -- Apparent access beyond array for function 'memcpy(...*/
826 memcpy(target,&tst_header.combined[INFO_BYTE], TST_SMALL_HEADER_SIZE-1);
827 /*lint +e420 */
828 target += TST_SMALL_HEADER_SIZE - 1;
829 }
830
831
832 if (WrongTSTHeader == FALSE && BytesToRead)
833 {
834 if ( (tst_header.combined[INFO_BYTE] & HDR_IDENT_MASK)==IDENT_TRACE )
835 {
836 /* we read the first bytes in advance in case the trace class is carried */
837 ULONG bread=1;
838 vsi_d_read ( TIF_Data.Handle, 0, (void*)((char*)target+TIF_WrInd), &bread );
839
840 if (bread==1 && *((char*)target)<0x20) /* no character -> assume traceclass id */
841 {
842 opc_str[0]=*((char*)target);
843 opc_len=1;
844
845 BytesToRead -= bread;
846 }
847 else
848 {
849 /* ok, we have no traceclass info :-( */
850 TIF_WrInd += bread;
851 Bytes += bread;
852 }
853 BytesRead = BytesToRead - Bytes;
854 }
855
856 do
857 {
858 vsi_d_read ( TIF_Data.Handle, 0, (void*)((char*)target+TIF_WrInd), (ULONG*)&BytesRead );
859 Bytes += BytesRead;
860 if ( Bytes < BytesToRead )
861 {
862 TIF_WrInd += BytesRead;
863 BytesRead = BytesToRead - Bytes;
864 }
865 } while ( Bytes < BytesToRead );
866 }
867
868 *((char*)target + Bytes) = 0;
869 prim->sh_offset = S_HDR_OFFSET(alloc_size - sizeof(T_S_HEADER));
870 s_hdr = (T_S_HEADER*)((ULONG*)prim + prim->sh_offset);
871 switch (tst_header.combined[INFO_BYTE] & HDR_IDENT_MASK)
872 {
873 case IDENT_PS_PRIM:
874
875 EXCHANGE_4BYTES_ENDIANESS(opc_str);
876
877 memcpy((char*)&prim->opc, opc_str, 4);
878 if ( (pcon != NULL) && (TIF_Data.Config & PCON_ENABLED) )
879 {
880 if ( (sts = (int)pcon->decode_prim ( prim->opc, &decoded_prim, (void*)((char*)prim+sizeof(T_PRIM_HEADER)), (ULONG*)&length, 0 )) != PCON_OK )
881 {
882 if ( sts != PCON_CONFIG_PRIM )
883 {
884 vsi_o_ttrace (NO_TASK, TC_SYSTEM,"PCON Deode Error %d, TIF_Callback() aborted", sts );
885 }
886 PFREE(P2D(sys_prim));
887 PFREE(P2D(prim));
888 return;
889 }
890 PFREE(P2D((T_VOID_STRUCT*)prim));
891 sys_prim->prim_ptr = D2P(decoded_prim);
892 }
893 else
894 {
895 sys_prim->prim_ptr = prim;
896 length = BytesToRead;
897 }
898 sys_prim->prim_ptr->sh_offset = S_HDR_OFFSET(length+sizeof(T_PRIM_HEADER));
899 sys_prim->prim_ptr->len = length + sizeof(T_PRIM_HEADER);
900 s_hdr = (T_S_HEADER*)((ULONG*)sys_prim->prim_ptr + sys_prim->prim_ptr->sh_offset);
901 #ifndef _TOOLS_
902 /* evtl. convert aux sdu to mem handle */
903 if (sys_prim->prim_ptr->opc & MEMHANDLE_OPC && mem!=NULL)
904 {
905 if (P_MEMHANDLE_SDU(sys_prim->prim_ptr))
906 {
907 U32 mem_handle;
908 U8 buffer_handle;
909 U8 user_handle;
910 U8 *user_data;
911 T_sdu *sdu;
912 U16 len;
913
914 sdu=(T_sdu *)P_MEMHANDLE_SDU(sys_prim->prim_ptr);
915 len=(sdu->l_buf + 7)/8;
916
917 buffer_handle=mem->create_buffer(MEM_UNORDERED_BUFFER, len);
918 user_handle = mem->create_user(buffer_handle, 23, "TST");
919
920 user_data=mem->alloc(user_handle,len,&mem_handle);
921 memcpy(user_data,sdu->buf+(sdu->o_buf+7)/8,len);
922 P_MEMHANDLE(sys_prim->prim_ptr)=mem_handle;
923
924 mem->delete_user(user_handle);
925 mem->delete_buffer(buffer_handle);
926 }
927 }
928 #endif
929 break;
930
931 case IDENT_SYS_PRIM:
932 sys_prim->prim_ptr = prim;
933 prim->opc = SYS_MASK;
934 prim->len = BytesToRead + sizeof(T_PRIM_HEADER);
935 break;
936
937 case IDENT_TRACE:
938 sys_prim->prim_ptr = prim;
939 if (opc_len)
940 {
941 /* nice, we found a traceclass info */
942 prim->opc = opc_str[0];
943 prim->opc = prim->opc << 16;
944 prim->opc |= EXTENDED_OPC | VIRTUAL_OPC | TRACE_SAP;
945 }
946 else
947 {
948 prim->opc = TRACE_OPC;
949 }
950 prim->len = CorruptByteOffset + BytesToRead + sizeof(T_PRIM_HEADER);
951 break;
952
953 default:
954 break;
955 }
956
957 /*
958 * Extract Sender and Receiverfrom header
959 */
960 if (CorruptByteOffset)
961 {
962 s_hdr->time = 0; /* FreeCalypso: changed from NULL */
963 #ifndef _TOOLS_
964 memcpy ( s_hdr->snd, "~TST", 4 );
965 memcpy ( s_hdr->rcv, FRM_TST_NAME, 4 );
966 #else
967 memcpy ( s_hdr->snd, FRM_TST_NAME, 4 );
968 memcpy ( s_hdr->rcv, FRM_PCO_NAME, 4 );
969 #endif
970 memcpy ( s_hdr->org_rcv, "TST", 4 );
971 }
972 else
973 {
974 s_hdr->time = tst_header.time;
975
976 i = 0;
977 do
978 {
979 s_hdr->snd[i] = tst_header.sender[i];
980 i++;
981 } while ( tst_header.sender[i] != 0x20 && i < 4 );
982 s_hdr->snd[i] = 0;
983
984 i = 0;
985 do
986 {
987 s_hdr->rcv[i] = tst_header.receiver[i];
988 i++;
989 } while ( tst_header.receiver[i] != 0x20 && i < 4 );
990 s_hdr->rcv[i] = 0;
991
992 if (org_rcv_len)
993 {
994 i = 0;
995 do
996 {
997 s_hdr->org_rcv[i] = tst_header.orgreceiver[i];
998 i++;
999 } while ( tst_header.orgreceiver[i] != 0x20 && i < 4 );
1000 s_hdr->org_rcv[i] = 0;
1001 }
1002 }
1003
1004 if ( TIF_Data.EnabledSignalType & DRV_SIGTYPE_READ )
1005 {
1006 VSI_PPM_SEND ( (T_PRIM_HEADER*)sys_prim, TST_Handle );
1007 VSI_PPM_SEND ( (T_PRIM_HEADER*)sys_prim->prim_ptr, TST_Handle );
1008 TIF_Signal.SignalType = DRV_SIGTYPE_READ;
1009 TIF_Signal.DrvHandle = TIF_Data.Handle;
1010 TIF_Signal.UserData = (T_VOID_STRUCT*)sys_prim;
1011 (TIF_Data.Callback)( &TIF_Signal );
1012 }
1013 }
1014 } /* if ( BytesToRead ) */
1015 break;
1016 case DRV_SIGTYPE_CONNECT:
1017 case DRV_SIGTYPE_DISCONNECT:
1018 if ( TIF_Data.EnabledSignalType & Signal->SignalType )
1019 {
1020 TIF_Signal.SignalType = Signal->SignalType;
1021 TIF_Signal.DrvHandle = TIF_Data.Handle;
1022 TIF_Signal.UserData = NULL;
1023 (TIF_Data.Callback)( &TIF_Signal );
1024 }
1025 break;
1026 default:
1027 break;
1028 }
1029 }
1030 #endif
1031
1032 #ifndef RUN_INT_RAM
1033 /*
1034 +--------------------------------------------------------------------+
1035 | PROJECT : GSM-Frame (8415) MODULE : TIF |
1036 | STATE : code ROUTINE : TIF_Init |
1037 +--------------------------------------------------------------------+
1038
1039 PURPOSE : initialize driver
1040
1041 */
1042 GLOBAL USHORT TIF_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo )
1043 {
1044 static const T_DRV_EXPORT TIF_Info =
1045 {
1046 TIF_NAME,
1047 0,
1048 {
1049 #ifdef _TOOLS_
1050 TIF_Init,
1051 #endif
1052 TIF_Exit,
1053 NULL,
1054 TIF_Write,
1055 NULL,
1056 NULL,
1057 NULL,
1058 TIF_SetSignal,
1059 TIF_ResetSignal,
1060 TIF_SetConfig,
1061 NULL,
1062 TIF_Callback,
1063 }
1064 };
1065
1066 #ifndef _TOOLS_
1067 union
1068 {
1069 USHORT s;
1070 UBYTE b[2];
1071 } test;
1072 #endif /* !_TOOLS_ */
1073
1074 TIF_Data.Handle = DrvHandle;
1075 TIF_Data.EnabledSignalType = 0;
1076 TIF_Data.Config = 0;
1077 TIF_Data.Callback = CallbackFunc;
1078
1079 #ifdef _TOOLS_
1080 switch (ccddata_init(NULL,0,NULL,NULL))
1081 {
1082 case CCDDATA_DLL_OK:
1083 case CCDDATA_DLL_ALREADY:
1084 break;
1085 default:
1086 return DRV_INITFAILURE;
1087 }
1088 #else /* _TOOLS_ */
1089 test.s = 1;
1090 if ( pcon != NULL )
1091 {
1092 ULONG sts = pcon->init_prim_coding ( TST_Handle,(UBYTE)((test.b[0]==1) ? PCON_LITTLE : PCON_BIG));
1093 #ifndef _TARGET_
1094 vsi_pcheck_register (pcon->pcheck, PCON_OK);
1095 #endif /* !_TARGET_ */
1096 }
1097 #endif /* !_TOOLS_ */
1098
1099 *DrvInfo = &TIF_Info;
1100
1101 return DRV_OK;
1102 }
1103 #endif
1104
1105