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