comparison src/g23m-aci/dti/dti_int.c @ 1:fa8dc04885d8

src/g23m-*: import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:25:50 +0000
parents
children
comparison
equal deleted inserted replaced
0:4e78acac3d88 1:fa8dc04885d8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : DTILIB
4 | Modul : DTI
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 : Definitions for the Protocol Stack Library
18 | DTI
19 +-----------------------------------------------------------------------------
20
21 MODULE : DTI
22
23 PURPOSE : Internal functions of the Protocol Stack Library DTI
24 */
25
26 #ifndef DTI_INT_C
27 #define DTI_INT_C
28 #endif
29
30 /*==== CONST =======================================================*/
31
32 #include <string.h>
33 #include "typedefs.h"
34 #include "pconst.cdg"
35 #include "vsi.h"
36 #include "custom.h"
37 #include "gsm.h"
38 #include "prim.h"
39 #include "dti.h"
40 #include "dti_int_def.h"
41 #include "dti_int_prot.h"
42
43
44 #ifdef FF_TCP_IP
45 #include "atp/atp_api.h"
46 #endif /* FF_TCP_IP */
47
48 /*
49 +---------------------------------------------------------------------+
50 | PROJECT : DTILIB MODULE : DTI_KERF |
51 | STATE : code ROUTINE : set_default_para_data_base|
52 +---------------------------------------------------------------------+
53
54 *
55 * Set the default parameter for the DTI data base
56 *
57 */
58
59 GLOBAL void set_default_para_data_base(DTI_HANDLE hDTI)
60 {
61 hDTI->first_link = D_LINK;
62 hDTI->handle = D_LINK_HANDLE;
63 hDTI->max_links = D_MAX_LINKS;
64
65 #ifdef FF_TCP_IP
66 hDTI->entity_id_p = D_ATP_SW_ENTITY_ID;
67 #endif /* FF_TCP_IP */
68 }
69
70 /*
71 +--------------------------------------------------------------------+
72 | PROJECT : DTILIB MODULE : DTI_KERF |
73 | STATE : code ROUTINE : free_dti_packets_queue |
74 +--------------------------------------------------------------------+
75
76 *
77 * Free dti packets in the queue
78 *
79 */
80
81 LOCAL void free_dti_data_ind_packets_queue(DTI_HANDLE hDTI, T_DTI2_DATA_IND * p_data_ind)
82 {
83 T_DTI2_DATA_IND *p_ind;
84
85 BOOL go = TRUE;
86
87 trace_function( hDTI->handle,
88 "free_dti_data_ind_packets_queue()",
89 hDTI->entity_options);
90
91 /*
92 * Are there any packets in the queue ?
93 */
94
95 if (p_data_ind EQ NO_DATA_PACKET )
96 return;
97
98 p_ind = p_data_ind;
99
100 /*
101 * Check if DTILIB is supported
102 */
103
104 /*
105 * Free the packets
106 */
107
108 do {
109 T_DTI2_DATA_IND *p_last_ind;
110 p_last_ind = p_ind;
111
112 if(p_ind->link_id NEQ 0)
113 p_ind = (T_DTI2_DATA_IND *) p_ind->link_id;
114 else
115 go = FALSE;
116
117 /*
118 * Free the descs at first
119 */
120 mfree_desc(hDTI, &p_last_ind->desc_list2);
121
122 /*
123 * Free the primitive
124 */
125 PFREE (p_last_ind);
126
127 } while( go );
128 } /* free_dti_data_ind_packets_queue() */
129
130
131
132 /*
133 +-----------------------------------------------------------------------+
134 | PROJECT : DTILIB MODULE : DTI_KERF |
135 | STATE : code ROUTINE : set_default_para_link_table |
136 +-----------------------------------------------------------------------+
137 *
138 * Set the default parameter for DTI_LINK
139 *
140 */
141
142 GLOBAL void set_default_para_link_table (DTI_HANDLE hDTI,
143 DTI_LINK *link,
144 U32 link_id,
145 U8 direction)
146 {
147 /*
148 * Free primitives and descs if there are any in the queue
149 */
150 free_dti_data_ind_packets_queue(hDTI, link->dti_data_ind);
151 link->dti_data_ind = NULL;
152 /*
153 * Set the other parameter to default
154 */
155 link->link_id = link_id;
156 link->direction = direction;
157 link->version = D_VERSION;
158 link->link_options = D_LINK_OPTIONS;
159 link->instance = D_INSTANCE;
160 link->interfac = D_INTERFACE;
161 link->channel = D_CHANNEL;
162 link->link_handle = D_LINK_HANDLE;
163 link->queue_size = D_QUEUE_SIZE;
164 link->queue_len = 0;
165 link->connect_state = D_CONNECT_STATE;
166 link->rx_state = DTI_RX_IDLE;
167 link->tx_state = DTI_TX_IDLE;
168 } /* set_default_para_link_table() */
169
170
171
172 /*
173 +-----------------------------------------------------------------------+
174 | PROJECT : DTILIB MODULE : DTI_int |
175 | STATE : code ROUTINE : init_link_table |
176 +-----------------------------------------------------------------------+
177 *
178 * Set the init parameter for DTI_LINK
179 *
180 */
181
182 GLOBAL void init_link_table (DTI_LINK *link)
183 {
184 link->link_id = D_FREE_LINK_ID;
185 link->direction = D_DIRECTION;
186 link->version = D_VERSION;
187 link->link_options = D_LINK_OPTIONS;
188 link->instance = D_INSTANCE;
189 link->interfac = D_INTERFACE;
190 link->link_handle = D_LINK_HANDLE;
191 link->queue_size = D_QUEUE_SIZE;
192 link->queue_len = 0;
193 link->channel = D_CHANNEL;
194 link->dti_data_ind = NULL;
195 link->connect_state = D_CONNECT_STATE;
196 link->rx_state = DTI_RX_IDLE;
197 link->tx_state = DTI_TX_IDLE;
198 link->next_link = D_LINK;
199 #ifdef FF_TCP_IP
200 link->ul_next_atp_data = 0;
201 link->atp_tx_state = ATP_TX_FLOW_ON;
202 link->dti_id = 0;
203 link->entity_db = (U32) NULL;
204 link->port_nb = 0;
205 #endif /* FF_TCP_IP */
206 } /* init_link_table() */
207
208
209
210 /*
211 +--------------------------------------------------------------------+
212 | PROJECT : DTILIB MODULE : DTI_KERF |
213 | STATE : code ROUTINE : free_dti_link_structure |
214 +--------------------------------------------------------------------+
215
216 *
217 * Free DTI link structures, DTI_LINK.
218 *
219 */
220
221 GLOBAL void free_dti_link_structure(DTI_HANDLE hDTI)
222 {
223 DTI_LINK *link_last, *link;
224 BOOL go = TRUE;
225
226 trace_function(hDTI->handle,
227 "free_dti_link_structure()", /*lint !e605 Increase in pointer capability */
228 hDTI->entity_options);
229
230 /*
231 * Check if there are any packets to free
232 */
233 if(hDTI->first_link EQ D_LINK)
234 return;
235
236 link = (DTI_LINK *) hDTI->first_link;
237
238 do {
239 link_last = link;
240
241 if(link->next_link NEQ D_LINK)
242 link = (DTI_LINK *) link->next_link;
243 else
244 go = FALSE;
245
246 /*
247 * Free the dti_queue
248 */
249 free_dti_data_ind_packets_queue(hDTI, link_last->dti_data_ind);
250
251 /*
252 * Free a link structure
253 */
254 MFREE (link_last);
255
256 } while( go );
257
258 } /* free_dti_link_structure() */
259
260 /*
261 +--------------------------------------------------------------------+
262 | PROJECT : DTILIB MODULE : DTI_KERF |
263 | STATE : code ROUTINE : trace_message |
264 +--------------------------------------------------------------------+
265
266 *
267 * Create a string
268 *
269 */
270
271 GLOBAL void trace_message (T_HANDLE handle,
272 char *str,
273 U32 entity_options)
274 {
275 if(! (entity_options & DTI_NO_TRACE) )
276 {
277 TRACE_EVENT(str);
278 }
279 } /*lint !e715 handle not referenced trace_message() */
280
281
282
283 /*
284 +--------------------------------------------------------------------+
285 | PROJECT : DTILIB MODULE : DTI_KERF |
286 | STATE : code ROUTINE : trace_message_link_id |
287 +--------------------------------------------------------------------+
288
289 *
290 * Create a string and a number
291 *
292 */
293
294 GLOBAL void trace_message_link_id (T_HANDLE handle,
295 char *str,
296 U32 link_id,
297 U32 entity_options)
298 {
299 if(! (entity_options & DTI_NO_TRACE) )
300 {
301 TRACE_EVENT_P2("%s - link_id=%d", str, link_id);
302 }
303 } /*lint !e715 handle not referenced trace_message_link_id() */
304
305
306
307 /*
308 +--------------------------------------------------------------------+
309 | PROJECT : DTILIB MODULE : DTI_KERF |
310 | STATE : code ROUTINE : trace_message_l_dl |
311 +--------------------------------------------------------------------+
312
313 *
314 * Create a string with link_id and data length
315 *
316 */
317
318 GLOBAL void trace_message_l_dl (T_HANDLE handle,
319 char *str,
320 U32 link_id,
321 U16 length,
322 U32 entity_options)
323 {
324 if(! (entity_options & DTI_NO_TRACE) )
325 {
326 TRACE_EVENT_P3("%s - link_id=%d length=%d", str, link_id, length);
327 }
328 } /* trace_message_l_dl() */
329
330
331
332 /*
333 +--------------------------------------------------------------------+
334 | PROJECT : DTILIB MODULE : DTI_KERF |
335 | STATE : code ROUTINE : trace_message_iic |
336 +--------------------------------------------------------------------+
337
338 *
339 * Create a string and a number
340 *
341 */
342
343 GLOBAL void trace_message_iic (T_HANDLE handle,
344 char *str,
345 U8 instance,
346 U8 interfac,
347 U8 channel,
348 U32 entity_options)
349 {
350 if(!(entity_options & DTI_NO_TRACE))
351 {
352 TRACE_EVENT_P4("%s - instance=%d interface=%d channel=%d",
353 str,
354 instance,
355 interfac,
356 channel);
357 }
358 } /*lint !e715 handle not referenced trace_message_iic() */
359
360
361
362 /*
363 +--------------------------------------------------------------------+
364 | PROJECT : DTILIB MODULE : DTI_KERF |
365 | STATE : code ROUTINE : trace_message_l_e |
366 +--------------------------------------------------------------------+
367
368 *
369 * Create a string and a number
370 *
371 */
372
373 GLOBAL void trace_message_l_e (T_HANDLE handle,
374 char *str,
375 U32 link_id,
376 char* entity,
377 U32 entity_options)
378 {
379 if(!(entity_options & DTI_NO_TRACE))
380 {
381 TRACE_EVENT_P3("%s - link_id=%d neighbor_entity=%s",
382 str,
383 link_id,
384 entity);
385 }
386 } /*lint !e715 handle not referenced trace_message_l_e() */
387
388 /*
389 +--------------------------------------------------------------------+
390 | PROJECT : DTILIB MODULE : DTI_KERF |
391 | STATE : code ROUTINE : trace_function |
392 +--------------------------------------------------------------------+
393
394 *
395 * Call macro TRACE_FUNKTION if traces are enabled
396 *
397 */
398
399 GLOBAL void trace_function( T_HANDLE handle, char *str, U32 entity_options)
400 {
401 if(! (entity_options & DTI_NO_TRACE) )
402 {
403 TRACE_FUNCTION (str);
404 }
405 } /*lint !e715 handle not referenced trace_function() */
406
407
408
409 /*
410 +--------------------------------------------------------------------+
411 | PROJECT : DTILIB MODULE : DTI_KERF |
412 | STATE : code ROUTINE : get_pointer_link_table_channel |
413 +--------------------------------------------------------------------+
414
415 *
416 * The function searchs an instance and a channel in the database link list
417 * and returns a pointer to the link list. If there is no link with the same channel and
418 * the same interface it returns NULL.
419 */
420
421 GLOBAL DTI_LINK * get_pointer_link_table_channel (DTI_HANDLE hDTI,
422 U8 instance,
423 U8 interfac,
424 U8 channel)
425 {
426 DTI_LINK *link_last, *link;
427 BOOL go = TRUE;
428
429 trace_function(hDTI->handle,
430 "get_pointer_link_table_channel()", /*lint !e605 Increase in pointer capability */
431 hDTI->entity_options);
432
433 link = (DTI_LINK *) hDTI->first_link;
434
435 /*
436 * Check if the link is not set
437 */
438
439 if(link EQ NULL)
440 return NULL;
441
442 do {
443 link_last = link;
444
445 /*
446 * Search on instance, interface and channal
447 */
448
449 if((link_last->instance EQ instance) AND (link_last->channel EQ channel) AND
450 (link_last->interfac EQ interfac) AND
451 (link_last->link_id NEQ D_FREE_LINK_ID))
452
453 return link_last;
454
455 if(link->next_link NEQ D_LINK)
456 link = (DTI_LINK *) link->next_link;
457 else
458 go = FALSE;
459
460 } while( go );
461
462 return NULL;
463 }
464
465
466 /*
467 +--------------------------------------------------------------------+
468 | PROJECT : DTILIB MODULE : DTI_KERF |
469 | STATE : code ROUTINE : get_pointer_link_table |
470 +--------------------------------------------------------------------+
471
472 *
473 * The function searchs a link id in the databank link list and returns a
474 * pointer to the link list. If there is no link_id with the selected direction it
475 * returns NULL. Note: the direction is used to select between to equal
476 * links in a link list because it could be 2 channels are connected on one
477 * instance.
478 */
479
480 GLOBAL DTI_LINK * get_pointer_link_table (DTI_HANDLE hDTI,
481 U32 select_link_id,
482 U8 select_direction)
483 {
484 DTI_LINK* link;
485
486 trace_function(hDTI->handle,
487 "get_pointer_link_table()",
488 hDTI->entity_options);
489
490 link = (DTI_LINK *) hDTI->first_link;
491
492 /*
493 * Find the link and return it
494 */
495 while(link NEQ NULL)
496 {
497 if(link->link_id EQ select_link_id)
498 return link;
499
500 link = (DTI_LINK *) link->next_link;
501 }
502
503 return NULL;
504 } /* get_pointer_link_table() */
505
506
507
508 /*
509 +--------------------------------------------------------------------+
510 | PROJECT : DTILIB MODULE : DTI_KERF |
511 | STATE : code ROUTINE : get_pointer_free_link |
512 +--------------------------------------------------------------------+
513
514 PURPOSE : The function searches a free link in the database link list
515 and returns a pointer to the link structure. If there is no
516 linkin the database then it returns NULL.
517 */
518
519 GLOBAL DTI_LINK * get_pointer_free_link (DTI_HANDLE hDTI)
520 {
521 DTI_LINK* link;
522
523 trace_function( hDTI->handle,
524 "get_pointer_free_link()",
525 hDTI->entity_options);
526
527 /*
528 * Search for unused link
529 */
530 link = (DTI_LINK *) hDTI->first_link;
531 while(link)
532 {
533 if(link->connect_state EQ DTI_CLOSED)
534 return link;
535 link = (DTI_LINK*)link->next_link;
536 }
537
538 /*
539 * Search for a link where only DTI_CONNECT_REQ has been received.
540 * This solves the situation when dti_open() is called for a new link
541 * and all links are used by existing links
542 * which are going to be closed and reopened with an other link_id
543 */
544 link = (DTI_LINK *) hDTI->first_link;
545 while(link)
546 {
547 if(link->connect_state EQ DTI_CONNECTING)
548 return link;
549 link = (DTI_LINK*)link->next_link;
550 }
551
552 return NULL;
553 } /* get_pointer_free_link() */
554
555
556
557 /*
558 +--------------------------------------------------------------------+
559 | PROJECT : DTILIB MODULE : DTI_KERF |
560 | STATE : code ROUTINE : open_comm_channel |
561 +--------------------------------------------------------------------+
562
563 *
564 * This function opens a VSI communication channel. If it's open it will be closed
565 * and opened new again. The opened handle is returned in the parameter com_handle.
566 */
567
568 GLOBAL void open_comm_channel(T_HANDLE entity_handle,
569 T_HANDLE *com_handle,
570 char *name,
571 U32 entity_options)
572 {
573
574 trace_function( entity_handle,
575 "open_comm_channel()",
576 entity_options);
577
578 /* Be sure the channel is closed if it was opened before */
579 vsi_c_close (entity_handle, *com_handle);
580
581 /* Open */
582 *com_handle = vsi_c_open(entity_handle, name);
583 }
584
585 /*
586 +--------------------------------------------------------------------+
587 | PROJECT : DTILIB MODULE : DTI_KERF |
588 | STATE : code ROUTINE : check_dti_version |
589 +--------------------------------------------------------------------+
590
591 *
592 * This function checks the version in a link table.
593 * and returns TRUE if the same version is found as in the request_version.
594 */
595
596 GLOBAL BOOL check_dti_version (DTI_HANDLE hDTI, U32 request_version)
597 {
598 trace_function(hDTI->handle,
599 "check_dti_version()", /*lint !e605 Increase in pointer capability */
600 hDTI->entity_options);
601
602 /*
603 * DTILIB has to be able to use older versions too.
604 * NOTE: this has been D_VERSION <= request_version until Aug-2002
605 * just an error or some sort of intricate reasoning??
606 */
607 if(D_VERSION >= request_version)
608 return TRUE;
609 else
610 return FALSE;
611 }
612
613 /*
614 +--------------------------------------------------------------------+
615 | PROJECT : DTILIB MODULE : DTI_KERF |
616 | STATE : code ROUTINE : validate_open_parameters |
617 +--------------------------------------------------------------------+
618
619 *
620 * This function validates the open-parameters
621 */
622 GLOBAL DTI_RESULT validate_open_parameters(DTI_HANDLE hDTI,
623 U32 link_id,
624 U8 *queue_size,
625 U8 *direction,
626 U32 *link_options,
627 U32 version,
628 U8 *neighbor_entity)
629 {
630 trace_function(hDTI->handle,
631 "validate_open_parameters()", /*lint !e605 Increase in pointer capability */
632 hDTI->entity_options);
633
634 /*
635 * Check version of peer dtilib
636 */
637 if (
638 check_dti_version
639 (
640 hDTI,
641 version
642 ) EQ FALSE
643 )
644 {
645 trace_message_link_id(hDTI->handle,
646 "DTI ERROR: Wrong DTI version", /*lint !e605 Increase in pointer capability */
647 link_id,
648 hDTI->entity_options);
649 return DTI_E_FAIL;
650 }
651
652 /*
653 * Legacy
654 */
655
656 /*
657 * Check if open with the NULL device.
658 */
659 if (strcmp ((CHAR*)neighbor_entity, NULL_NAME) EQ 0)
660 {
661 *direction = DTI_NULL_LINK;
662 }
663 if (*link_options EQ FLOW_CNTRL_ENABLED)
664 {
665 if (*queue_size EQ DTI_QUEUE_DISABLED)
666 {
667 *link_options = DTI_QUEUE_UNUSED;
668 }
669 else if (*queue_size EQ DTI_QUEUE_UNLIMITED)
670 {
671 *link_options = DTI_QUEUE_UNBOUNDED;
672 }
673 else
674 {
675 /*
676 * Set default behaviour
677 */
678 *link_options = DTI_QUEUE_RM_LIFO;
679 }
680 }
681
682 /*
683 * Ensure consistency
684 */
685 if((*link_options EQ DTI_QUEUE_UNUSED) OR
686 (*link_options EQ DTI_FLOW_CNTRL_DISABLED) OR
687 (*link_options EQ DTI_QUEUE_UNBOUNDED))
688 {
689 *queue_size = 0;
690 }
691 else if(*queue_size EQ 0)
692 {
693 *link_options = DTI_QUEUE_UNUSED;
694 }
695
696 return DTI_S_OK;
697 }
698
699
700 /*
701 +-----------------------------------------------------------------------+
702 | PROJECT : DTILIB MODULE : DTI_KERF |
703 | STATE : code ROUTINE : set_link_parameter |
704 +-----------------------------------------------------------------------+
705
706 *
707 * Set parameter in a link desc.
708 */
709
710 GLOBAL void set_open_para_link_table (DTI_HANDLE hDTI,
711 DTI_LINK *link,
712 U32 version,
713 U32 link_options,
714 U8 instance,
715 U8 interfac,
716 U8 channel,
717 U8 queue_size,
718 U8 connect_state)
719 {
720 trace_function(hDTI->handle,
721 "set_open_para_link_table()",
722 hDTI->entity_options);
723
724 /*
725 * Free primitives and descs if there are any in the queue.
726 */
727 free_dti_data_ind_packets_queue(hDTI, link->dti_data_ind);
728 link->dti_data_ind = NULL;
729 /*
730 * set parameters as requested
731 */
732 link->version = version;
733 link->instance = instance;
734 link->interfac = interfac;
735 link->channel = channel;
736 link->link_handle = D_LINK_HANDLE;
737 link->queue_len = 0;
738 link->rx_state = DTI_RX_IDLE;
739 link->tx_state = DTI_TX_BUFFER_FULL;
740 link->connect_state = connect_state;
741 link->queue_size = queue_size;
742 link->link_options = link_options;
743 /*
744 * the following structure is needed for ATP links
745 */
746 #ifdef FF_TCP_IP
747 link->entity_db = D_HANDLE;
748 link->port_nb = 0;
749 #endif /* FF_TCP_IP */
750 } /* set_open_para_link_table() */
751
752
753
754 /*
755 +--------------------------------------------------------------------+
756 | PROJECT : DTILIB MODULE : DTI_KERF |
757 | STATE : code ROUTINE : dti_resolve_link_id |
758 +--------------------------------------------------------------------+
759
760 *
761 * This function returns the link_id for the given
762 * instance/interface/channel.
763 *
764 * This is to be used to identify primitives sent from the entity to ACI
765 *
766 * return value: TRUE if associated link_id is found
767 * FALSE, otherwise
768 */
769
770 GLOBAL BOOL dti_resolve_link_id (DTI_HANDLE hDTI,
771 U8 instance,
772 U8 interfac,
773 U8 channel,
774 U32 *link_id)
775 {
776 DTI_LINK *link;
777
778 trace_function(hDTI->handle,
779 "dti_resolve_link_id()", /*lint !e605 Increase in pointer capability */
780 hDTI->entity_options);
781
782 if((link = get_pointer_link_table_channel(hDTI,
783 instance,
784 interfac,
785 channel)) EQ NULL)
786 {
787 return FALSE;
788 }
789
790 *link_id = link->link_id;
791 return TRUE;
792 } /* dti_resolve_link_id() */
793
794 /*
795 +--------------------------------------------------------------------+
796 | PROJECT : DTILIB MODULE : DTI_KERF |
797 | STATE : code ROUTINE : put_dti_data_ind_in_queue|
798 +--------------------------------------------------------------------+
799
800 *
801 * This function puts a dti_data_req primitive in queue.
802 */
803
804 GLOBAL void put_dti_data_ind_in_queue( DTI_HANDLE hDTI, DTI_LINK *link,
805 T_DTI2_DATA_IND *dti_data_ind)
806 {
807
808 if (hDTI->handle NEQ 0)
809 {
810 trace_function( hDTI->handle,
811 "put_dti_data_ind_in_queue()",
812 hDTI->entity_options);
813 }
814
815 dti_data_ind->link_id = 0;
816
817 /*
818 * Put in the first data packet.
819 * When using the old SAP the link->queue len can be 0 or 1
820 */
821 {
822 T_DTI2_DATA_IND *p_ind;
823 U8 chk = 1;
824
825 if(link->queue_len EQ 0)
826 {
827 link->dti_data_ind = dti_data_ind;
828 link->queue_len++;
829 return;
830 }
831
832
833 /* Now put more packets in the queue and put the new one on the last position */
834 p_ind = link->dti_data_ind;
835
836 /*
837 * Search the last packet in queue.
838 */
839 while(p_ind->link_id NEQ 0)
840 {
841 p_ind = (T_DTI2_DATA_IND *) p_ind->link_id;
842 chk++;
843 }
844
845 p_ind->link_id = (U32) dti_data_ind;
846
847 /*
848 * Check the queue length.
849 */
850 if(chk != link->queue_len)
851 {
852 trace_message_link_id(hDTI->handle,
853 "DTI ERROR: Write to queue error", /*lint !e605 Increase in pointer capability */
854 link->link_id,
855 hDTI->entity_options);
856 return;
857 }
858 link->queue_len++;
859 }
860 }
861
862
863
864 /*
865 +--------------------------------------------------------------------+
866 | PROJECT : DTILIB MODULE : DTI_KERF |
867 | STATE : code ROUTINE : get_dti_data_ind_from_queue |
868 +--------------------------------------------------------------------+
869
870 *
871 * This function gets a dti_data_ind primitive from queue. If there is
872 * no packet in the queue it returns NULL.
873 */
874
875 GLOBAL T_DTI2_DATA_IND * get_dti_data_ind_from_queue(DTI_HANDLE hDTI,
876 DTI_LINK *link)
877 {
878 T_DTI2_DATA_IND *ret_dti_data_ind;
879
880 trace_function( hDTI->handle,
881 "get_dti_data_ind_from_queue()",
882 hDTI->entity_options);
883
884 /*
885 * Is there any packet in the queue ?
886 */
887 if(link->queue_len EQ 0)
888 {
889 return NULL;
890 }
891 /*
892 * Set the second data packet on the first position.
893 */
894 ret_dti_data_ind = link->dti_data_ind;
895 /*
896 * Set the queue length
897 */
898 link->queue_len--;
899 /*
900 * Put the next data packet in position.
901 */
902 link->dti_data_ind = (T_DTI2_DATA_IND *)link->dti_data_ind->link_id;
903
904 return (ret_dti_data_ind);
905 } /* get_dti_data_ind_from_queue() */
906
907
908
909 /*
910 +--------------------------------------------------------------------+
911 | PROJECT : DTILIB MODULE : DTI_KERF |
912 | STATE : code ROUTINE : get_last_dti_data_ind_from_queue |
913 +--------------------------------------------------------------------+
914
915 *
916 * This function gets a dti_data_ind primitive from queue. If there is
917 * no packet in the queue it returns NULL.
918 */
919
920 LOCAL T_DTI2_DATA_IND * get_last_dti_data_ind_from_queue(DTI_HANDLE hDTI,
921 DTI_LINK *link)
922 {
923 T_DTI2_DATA_IND **last_dti_data_ind;
924 T_DTI2_DATA_IND *ret_dti_data_ind;
925
926 trace_function(hDTI->handle,
927 "get_last_dti_data_ind_from_queue()",
928 hDTI->entity_options);
929
930 /*
931 * Is there any packet in the queue?
932 */
933 if(link->queue_len EQ 0)
934 {
935 return NULL;
936 }
937 /*
938 * Get the last data packet
939 */
940 last_dti_data_ind = &(link->dti_data_ind);
941 while((*last_dti_data_ind)->link_id NEQ 0)
942 {
943 last_dti_data_ind = (T_DTI2_DATA_IND **) &((*last_dti_data_ind)->link_id);
944 }
945 ret_dti_data_ind = *last_dti_data_ind;
946 /*
947 * Set the queue length
948 */
949 link->queue_len--;
950 /*
951 * remove the data packet from queue.
952 */
953 *last_dti_data_ind = 0;
954
955 return (ret_dti_data_ind);
956 } /* get_last_dti_data_ind_from_queue() */
957
958
959
960 /*
961 +--------------------------------------------------------------------+
962 | PROJECT : DTILIB MODULE : DTI_KERF |
963 | STATE : code ROUTINE : put_dti_data_ind_in_queue_managed|
964 +--------------------------------------------------------------------+
965
966 *
967 * This function puts a dti_data_req primitive in queue.
968 * If the queue is full, it acts accordingly
969 */
970
971 GLOBAL void put_dti_data_ind_in_queue_managed (DTI_HANDLE hDTI,
972 DTI_LINK *link,
973 T_DTI2_DATA_IND *dti_data_ind)
974 {
975 trace_function(hDTI->handle,
976 "put_dti_data_ind_in_queue_managed()", /*lint !e605 Increase in pointer capability */
977 hDTI->entity_options);
978
979 /*
980 * Put new data packet into the queue.
981 */
982 if(link->link_options NEQ DTI_QUEUE_UNUSED)
983 {
984 put_dti_data_ind_in_queue(hDTI, link, dti_data_ind);
985 }
986
987 /*
988 * If queue full - send signal to entity.
989 */
990 switch (link->link_options)
991 {
992 case DTI_QUEUE_UNBOUNDED:
993 case DTI_QUEUE_WATERMARK:
994 break;
995
996 case DTI_QUEUE_UNUSED:
997 /* free data primitive since we cannot handle it */
998
999 trace_message_link_id(hDTI->handle,
1000 "DTI ERROR: No send queue available, discarding data packet", /*lint !e605 Increase in pointer capability */
1001 link->link_id,
1002 hDTI->entity_options);
1003
1004 mfree_desc (hDTI, &dti_data_ind->desc_list2);
1005 PFREE (dti_data_ind);
1006 break;
1007
1008 case DTI_QUEUE_RM_FIFO:
1009 if (link->queue_len > link->queue_size)
1010 {
1011 T_DTI2_DATA_IND *free_dti_data_ind
1012 = get_dti_data_ind_from_queue(hDTI, link);
1013
1014 trace_message_link_id(hDTI->handle,
1015 "Send queue full, discarding oldest data packet", /*lint !e605 Increase in pointer capability */
1016 link->link_id,
1017 hDTI->entity_options);
1018
1019 mfree_desc (hDTI, &free_dti_data_ind->desc_list2);
1020 PFREE (free_dti_data_ind);
1021 }
1022 break;
1023
1024 case DTI_QUEUE_RM_LIFO:
1025 if (link->queue_len > link->queue_size)
1026 {
1027 T_DTI2_DATA_IND *free_dti_data_ind
1028 = get_last_dti_data_ind_from_queue(hDTI, link);
1029
1030 trace_message_link_id(hDTI->handle,
1031 "Send queue full, discarding newest data packet", /*lint !e605 Increase in pointer capability */
1032 link->link_id,
1033 hDTI->entity_options);
1034
1035 mfree_desc (hDTI, &free_dti_data_ind->desc_list2);
1036 PFREE (free_dti_data_ind);
1037 }
1038 break;
1039
1040 default:
1041 trace_message_link_id(hDTI->handle,
1042 "DTI ERROR: Unknown state for link_options", /*lint !e605 Increase in pointer capability */
1043 link->link_id,
1044 hDTI->entity_options);
1045 break;
1046 }
1047 } /* put_dti_data_ind_in_queue_managed() */
1048
1049
1050
1051 /*
1052 +--------------------------------------------------------------------+
1053 | PROJECT : DTILIB MODULE : DTI_KERF |
1054 | STATE : code ROUTINE : dti_make_new_desc |
1055 +--------------------------------------------------------------------+
1056
1057 *
1058 * Malloc a knew desc. Init a buffer 0 if buff_init_0 is TRUE.
1059 *
1060 */
1061
1062 BOOL dti_make_new_desc( DTI_HANDLE hDTI, T_desc2 **p_desc_new,
1063 U16 malloc_len, BOOL buff_init_0)
1064 {
1065 #define VSI_CALLER hDTI->handle,
1066
1067 trace_function( hDTI->handle,
1068 "dti_make_new_desc()",
1069 hDTI->entity_options);
1070
1071 MALLOC ((*p_desc_new), ((U16)(sizeof(T_desc2)-1 + malloc_len)));
1072
1073 if(*p_desc_new EQ 0)
1074 return(FALSE);
1075
1076 if(buff_init_0)
1077 {
1078 U16 i;
1079 for(i=0; i<malloc_len; i++)
1080 (*p_desc_new)->buffer[i] = 0;
1081 }
1082 (*p_desc_new)->len = malloc_len;
1083 (*p_desc_new)->next = 0;
1084 (*p_desc_new)->offset = 0;
1085 (*p_desc_new)->size = (*p_desc_new)->len + (*p_desc_new)->offset;
1086 return(TRUE);
1087
1088 #undef VSI_CALLER
1089 }
1090
1091
1092 /*
1093 +--------------------------------------------------------------------+
1094 | PROJECT : DTILIB MODULE : DTI_KERF |
1095 | STATE : code ROUTINE : mfree_desc |
1096 +--------------------------------------------------------------------+
1097
1098 *
1099 * Free the descs in a desc list.
1100 *
1101 */
1102
1103
1104 GLOBAL void mfree_desc(DTI_HANDLE hDTI, T_desc_list2 * desc_list2)
1105 {
1106 BOOL go = TRUE;
1107 T_desc2 *p_desc_last, *p_desc;
1108
1109 trace_function( hDTI->handle,
1110 "mfree_desc()",
1111 hDTI->entity_options);
1112
1113 if (desc_list2 EQ NULL)
1114 return;
1115
1116 if (desc_list2->first EQ 0)
1117 return;
1118
1119 p_desc = (T_desc2 *) desc_list2->first;
1120
1121 do {
1122 p_desc_last = p_desc;
1123
1124 if(p_desc->next >0)
1125 p_desc = (T_desc2 *) p_desc->next;
1126 else
1127 go = FALSE;
1128
1129 MFREE (p_desc_last);
1130
1131 } while( go );
1132 }
1133
1134
1135 /*
1136 +-----------------------------------------------------------------------+
1137 | PROJECT : DTILIB MODULE : DTI_KERF |
1138 | STATE : code ROUTINE : close_link_with_signal |
1139 +-----------------------------------------------------------------------+
1140
1141 *
1142 * Close a link.
1143 */
1144
1145 GLOBAL void close_link_with_signal(DTI_HANDLE hDTI, DTI_LINK *link)
1146 {
1147 U8 hlp_instance, hlp_interface;
1148 U8 hlp_channel;
1149
1150 trace_function( hDTI->handle,
1151 "close_link_with_signal()",
1152 hDTI->entity_options);
1153
1154 /*
1155 * Close communication channel
1156 */
1157 vsi_c_close (hDTI->handle, link->link_handle);
1158
1159 hlp_instance = link->instance;
1160 hlp_interface = link->interfac;
1161 hlp_channel = link->channel;
1162
1163 /*
1164 * Set the default parameter and call the callback function.
1165 */
1166
1167 set_default_para_link_table(hDTI,link, D_FREE_LINK_ID, D_DIRECTION);
1168
1169 /*
1170 * Call the callback function.
1171 */
1172
1173 hDTI->sig_callback(hlp_instance, hlp_interface, hlp_channel,
1174 DTI_REASON_CONNECTION_CLOSED, NULL);
1175
1176 /*
1177 * Note: Any flow control and any data primitive are now silently discarded.
1178 */
1179 }
1180
1181
1182
1183 /*
1184 +-------------------------------------------------------------------------+
1185 | PROJECT : DTILIB MODULE : DTI_KERF |
1186 | STATE : code ROUTINE : set_reset_req_para_link_table |
1187 +-------------------------------------------------------------------------+
1188 *
1189 * Set parameter by reset.
1190 *
1191 */
1192
1193 GLOBAL void set_reset_req_para_link_table(DTI_HANDLE hDTI, DTI_LINK *link)
1194 {
1195 /*
1196 * Free primitives and descs if there are any in the queue.
1197 */
1198 free_dti_data_ind_packets_queue(hDTI, link->dti_data_ind);
1199 link->dti_data_ind = NULL;
1200 /*
1201 * Set the other parameters
1202 */
1203 link->queue_len = 0;
1204 link->connect_state = DTI_IDLE;
1205 } /* set_reset_req_para_link_table() */