comparison src/gpf/tst/drv/tif2.c @ 6:8b2a9a374324

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