FreeCalypso > hg > freecalypso-citrine
comparison g23m-aci/dti/dti_kerf.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 | |
22 /* | |
23 * Version 1.6 | |
24 */ | |
25 | |
26 #ifndef DTI_KERF_C | |
27 #define DTI_KERF_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 #ifdef FF_TCP_IP | |
48 #include "atp/atp_api.h" | |
49 #include "atp/atp_messages.h" | |
50 #include "aaa.h" | |
51 #include "dti_atp.h" | |
52 #include "gprs.h" | |
53 #include "dti_conn_mng.h" /* for getting EXTRACT_DTI_ID */ | |
54 #endif | |
55 | |
56 /*==== LOCALS ================================================================*/ | |
57 | |
58 #ifdef _SIMULATION_ | |
59 LOCAL void send_data_test_req_or_ind | |
60 ( | |
61 DTI_HANDLE hDTI, | |
62 DTI_LINK *link, | |
63 T_DTI2_DATA_IND *dti_data_ind | |
64 ); | |
65 #endif /* _SIMULATION_ */ | |
66 | |
67 | |
68 #ifdef FF_TCP_IP | |
69 static BOOL ATP_used_flag; | |
70 #endif | |
71 | |
72 /*==== GLOBALS ===============================================================*/ | |
73 | |
74 /* | |
75 +--------------------------------------------------------------------+ | |
76 | PROJECT : DTILIB MODULE : DTI_KERF | | |
77 | STATE : code ROUTINE : dti_init | | |
78 +--------------------------------------------------------------------+ | |
79 * | |
80 * Malloc and set default parameters and specified entity_options for the database | |
81 * | |
82 */ | |
83 | |
84 GLOBAL DTI_HANDLE dti_init( | |
85 U8 maximum_links, | |
86 T_HANDLE handle, | |
87 U32 entity_options, | |
88 void (sig_callback( | |
89 U8 instance, | |
90 U8 interfac, | |
91 U8 channel, | |
92 U8 reason, | |
93 T_DTI2_DATA_IND *dti_data_ind) | |
94 ) | |
95 ) | |
96 { | |
97 U16 i; | |
98 DTI_HANDLE hDTI; | |
99 DTI_LINK *link, *last_link; | |
100 | |
101 trace_function(handle, "dti_init()", entity_options); | |
102 | |
103 #if defined ALLOCATE_DATABASE_BLOCK | |
104 | |
105 /* | |
106 * Allocate all needed memory for the DTI Database in one block. | |
107 */ | |
108 MALLOC( hDTI, (U16) | |
109 /* Database */ | |
110 (sizeof(temp_mem_1) - sizeof(DTI_LINK) + | |
111 /* Every links */ | |
112 ((sizeof(temp_mem_2) - sizeof(temp_mem_1))* maximum_links))); | |
113 | |
114 /* | |
115 * Set defaults to the Database. | |
116 */ | |
117 set_default_para_data_base(hDTI); | |
118 | |
119 /* | |
120 * Number of links in the Data Base (DTI_DATA_BASE). | |
121 */ | |
122 hDTI->max_links = maximum_links; | |
123 hDTI->handle = handle; | |
124 hDTI->entity_options = entity_options; | |
125 | |
126 /* | |
127 * Cast the links and init them. | |
128 */ | |
129 { | |
130 U32 link_addr_offset = 0; | |
131 for(i = 0; i < maximum_links; i++) | |
132 { | |
133 if(i == 0) | |
134 { | |
135 hDTI->first_link = ((U32) &((temp_mem_1*) hDTI)->tmp_link[i]); | |
136 link = (DTI_LINK*)hDTI->first_link; | |
137 init_link_table(link); | |
138 link_addr_offset = ((U32) &((temp_mem_2*) hDTI)->tmp_link[1]) - ((U32) link); | |
139 } | |
140 else | |
141 { | |
142 link = link + link_addr_offset; | |
143 init_link_table(link); | |
144 } | |
145 } | |
146 } | |
147 #else | |
148 | |
149 /* | |
150 * Allocate the memory over separate blocks. | |
151 */ | |
152 MALLOC (hDTI, (U16)(sizeof(DTI_DATA_BASE) - 1)); | |
153 | |
154 /* | |
155 * Set defaults | |
156 */ | |
157 set_default_para_data_base(hDTI); | |
158 | |
159 /* | |
160 * Number of links in the Data Base (DTI_DATA_BASE). | |
161 */ | |
162 hDTI->max_links = maximum_links; | |
163 hDTI->handle = handle; | |
164 hDTI->entity_options = entity_options; | |
165 | |
166 /* | |
167 * Allocate LINK_TABLE for maximum_links and set default parameters | |
168 */ | |
169 if(maximum_links > 0) | |
170 { | |
171 MALLOC (link, (U16) sizeof(DTI_LINK)); | |
172 init_link_table(link); | |
173 hDTI->first_link = (U32) link; | |
174 for(i = 1; i < maximum_links; i++) | |
175 { | |
176 last_link = link; | |
177 MALLOC (link, (U16) sizeof(DTI_LINK)); | |
178 init_link_table(link); | |
179 last_link->next_link = (U32) link; | |
180 } | |
181 } | |
182 #endif | |
183 | |
184 #ifdef FF_TCP_IP | |
185 if (!ATP_used_flag) /* initialise array of references to ATP links */ | |
186 { | |
187 for ( i=0; i<MAX_ATP_LINKS; i++) | |
188 { | |
189 atp_links[i]= D_LINK; | |
190 } | |
191 } | |
192 #endif | |
193 | |
194 /* | |
195 * Set the callback function for the entity / instance | |
196 */ | |
197 hDTI->sig_callback = sig_callback; | |
198 return hDTI; | |
199 } /* dti_init() */ | |
200 /* | |
201 +--------------------------------------------------------------------+ | |
202 | PROJECT : DTILIB MODULE : DTI_KERF | | |
203 | STATE : code ROUTINE : dti_deinit | | |
204 +--------------------------------------------------------------------+ | |
205 | |
206 * | |
207 * Malloc and set default parameter for the Data Base | |
208 * | |
209 */ | |
210 | |
211 GLOBAL void dti_deinit( DTI_HANDLE hDTI) | |
212 { | |
213 trace_function(hDTI->handle, "dti_deinit()", hDTI->entity_options); | |
214 | |
215 if(hDTI EQ D_NO_DATA_BASE) | |
216 return; | |
217 | |
218 #if defined ALLOCATE_DATABASE_BLOCK | |
219 | |
220 /* | |
221 * Free the datablock as a block. | |
222 */ | |
223 | |
224 MFREE (hDTI); | |
225 | |
226 #else | |
227 | |
228 /* | |
229 * Free the links of the link table with DTI queue | |
230 */ | |
231 | |
232 free_dti_link_structure(hDTI); | |
233 | |
234 /* | |
235 * Free the DTI_DATA_BASE | |
236 */ | |
237 | |
238 MFREE (hDTI); | |
239 | |
240 #endif | |
241 } /* dti_deinit() */ | |
242 | |
243 /* | |
244 +--------------------------------------------------------------------+ | |
245 | PROJECT : DTILIB MODULE : DTI_KERF | | |
246 | STATE : code ROUTINE : acquire_link | | |
247 +--------------------------------------------------------------------+ | |
248 | |
249 * | |
250 * This function acquires a link | |
251 */ | |
252 LOCAL DTI_RESULT acquire_link(DTI_HANDLE hDTI, | |
253 U32 link_id, | |
254 U8 direction, | |
255 DTI_LINK **link) | |
256 { | |
257 trace_function(hDTI->handle, | |
258 "acquire_link()", | |
259 hDTI->entity_options); | |
260 | |
261 if((*link = get_pointer_link_table(hDTI, link_id, direction)) NEQ NULL) | |
262 return DTI_S_FOUND; | |
263 | |
264 if((*link=get_pointer_free_link(hDTI)) NEQ NULL) | |
265 { | |
266 set_default_para_link_table (hDTI, *link, link_id, direction); | |
267 return DTI_S_CREATED_NEW; | |
268 } | |
269 | |
270 /* | |
271 * No free link and so no connection possible. | |
272 */ | |
273 trace_message_link_id(hDTI->handle, | |
274 "DTI ERROR: No link free in dtilib", | |
275 link_id, | |
276 hDTI->entity_options); | |
277 return DTI_E_FAIL; | |
278 } | |
279 | |
280 | |
281 /* | |
282 +--------------------------------------------------------------------+ | |
283 | PROJECT : DTILIB MODULE : dti_kerf.c | | |
284 | STATE : code ROUTINE : send_connect_req_or_ind | | |
285 +--------------------------------------------------------------------+ | |
286 | |
287 * PURPOSE: Send a Connect primitive depending on the direction. | |
288 */ | |
289 | |
290 LOCAL void send_connect_req_or_ind (DTI_HANDLE hDTI, DTI_LINK *link) | |
291 { | |
292 #define VSI_CALLER hDTI->handle, | |
293 /* | |
294 * Check if the link is upwards or downwards | |
295 * and send the according connect primitive. | |
296 */ | |
297 switch(link->direction) | |
298 { | |
299 case DTI_CHANNEL_TO_HIGHER_LAYER: | |
300 { | |
301 PALLOC (dti_connect_ind, DTI2_CONNECT_IND); | |
302 dti_connect_ind->link_id = link->link_id; | |
303 dti_connect_ind->version = link->version; | |
304 if(hDTI->entity_options & DTI_NO_TRACE) | |
305 { | |
306 PSEND_NTRACE(link->link_handle, dti_connect_ind); | |
307 } | |
308 else | |
309 { | |
310 PSEND(link->link_handle, dti_connect_ind); | |
311 trace_message_link_id(hDTI->handle, | |
312 "OUT: DTI2_CONNECT_IND", | |
313 link->link_id, | |
314 hDTI->entity_options); | |
315 } | |
316 } | |
317 break; | |
318 | |
319 case DTI_CHANNEL_TO_LOWER_LAYER: | |
320 { | |
321 PALLOC (dti_connect_req, DTI2_CONNECT_REQ); | |
322 dti_connect_req->link_id = link->link_id; | |
323 dti_connect_req->version = link->version; | |
324 if(hDTI->entity_options & DTI_NO_TRACE) | |
325 { | |
326 PSEND_NTRACE(link->link_handle, dti_connect_req); | |
327 } | |
328 else | |
329 { | |
330 PSEND(link->link_handle, dti_connect_req); | |
331 trace_message_link_id(hDTI->handle, | |
332 "OUT: DTI2_CONNECT_REQ", | |
333 link->link_id, | |
334 hDTI->entity_options); | |
335 } | |
336 } | |
337 break; | |
338 | |
339 default: | |
340 /* | |
341 * no known channel type open so do not send anything | |
342 */ | |
343 break; | |
344 } | |
345 #undef VSI_CALLER | |
346 } /* send_connect_req_or_ind() */ | |
347 | |
348 | |
349 | |
350 /* | |
351 +--------------------------------------------------------------------+ | |
352 | PROJECT : DTILIB MODULE : dti_kerf.c | | |
353 | STATE : code ROUTINE : send_connect_res_or_cnf | | |
354 +--------------------------------------------------------------------+ | |
355 | |
356 * PURPOSE: Send a Connect Confirm primitive depending on the direction. | |
357 */ | |
358 | |
359 LOCAL void send_connect_res_or_cnf (DTI_HANDLE hDTI, DTI_LINK *link) | |
360 { | |
361 #define VSI_CALLER hDTI->handle, | |
362 /* | |
363 * Check if the link is upwards or downwards | |
364 * and send the according connect primitive. | |
365 */ | |
366 switch(link->direction) | |
367 { | |
368 case DTI_CHANNEL_TO_HIGHER_LAYER: | |
369 { | |
370 PALLOC (dti_connect_cnf, DTI2_CONNECT_CNF); | |
371 dti_connect_cnf->link_id = link->link_id; | |
372 dti_connect_cnf->version = link->version; | |
373 if(hDTI->entity_options & DTI_NO_TRACE) | |
374 { | |
375 PSEND_NTRACE(link->link_handle, dti_connect_cnf); | |
376 } | |
377 else | |
378 { | |
379 PSEND(link->link_handle, dti_connect_cnf); | |
380 trace_message_link_id(hDTI->handle, | |
381 "OUT: DTI2_CONNECT_CNF", | |
382 link->link_id, | |
383 hDTI->entity_options); | |
384 } | |
385 } | |
386 break; | |
387 | |
388 case DTI_CHANNEL_TO_LOWER_LAYER: | |
389 { | |
390 PALLOC (dti_connect_res, DTI2_CONNECT_RES); | |
391 dti_connect_res->link_id = link->link_id; | |
392 dti_connect_res->version = link->version; | |
393 if(hDTI->entity_options & DTI_NO_TRACE) | |
394 { | |
395 PSEND_NTRACE(link->link_handle, dti_connect_res); | |
396 } | |
397 else | |
398 { | |
399 PSEND(link->link_handle, dti_connect_res); | |
400 trace_message_link_id(hDTI->handle, | |
401 "OUT: DTI2_CONNECT_RES", | |
402 link->link_id, | |
403 hDTI->entity_options); | |
404 } | |
405 } | |
406 break; | |
407 | |
408 default: | |
409 /* | |
410 * no known channel type open so do not send anything | |
411 */ | |
412 break; | |
413 } | |
414 #undef VSI_CALLER | |
415 } /* send_connect_res_or_cnf() */ | |
416 | |
417 | |
418 | |
419 /* | |
420 +-------------------------------------------------------------------------+ | |
421 | PROJECT : DTILIB MODULE : DTI_KERF | | |
422 | STATE : code ROUTINE : send_open_ready_callback | | |
423 +-------------------------------------------------------------------------+ | |
424 | |
425 * | |
426 * Activate connection_opened and tx_buffer_ready callback funktions. | |
427 */ | |
428 | |
429 LOCAL void send_open_ready_callback(DTI_HANDLE hDTI, DTI_LINK *link) | |
430 { | |
431 #ifdef FF_TCP_IP | |
432 /* | |
433 * trigger DTI Primitive transmission separatly, because it can not be done by ATP | |
434 */ | |
435 if(link->link_type EQ RIVIERA_ATP_LINK) | |
436 { | |
437 PALLOC(dti_ready_ind, DTI2_READY_IND); | |
438 dti_ready_ind->link_id = link->link_id; | |
439 #define VSI_CALLER 0, | |
440 PSEND_NTRACE(link->link_handle, dti_ready_ind); | |
441 #undef VSI_CALLER | |
442 /* | |
443 * stop ATP reception Flow Control | |
444 */ | |
445 TRACE_EVENT("initial: ATP_RX_FLOW_OFF"); | |
446 atp_set_signal(hDTI->entity_id_p, | |
447 link->port_nb, | |
448 ATP_RX_FLOW_OFF, | |
449 ATP_RX_FLOW_UNMASK); | |
450 } | |
451 #endif /* FF_TCP_IP */ | |
452 /* | |
453 * send indication for the open connection | |
454 */ | |
455 hDTI->sig_callback( | |
456 link->instance, | |
457 link->interfac, | |
458 link->channel, | |
459 DTI_REASON_CONNECTION_OPENED, | |
460 NULL); | |
461 | |
462 /* | |
463 * Call the callback function with the signal tx_buffer_ready | |
464 * if the queue is used and not full | |
465 */ | |
466 if((link->direction EQ DTI_NULL_LINK) OR | |
467 ((link->queue_len < link->queue_size) OR | |
468 (link->link_options EQ DTI_QUEUE_UNBOUNDED))) | |
469 { | |
470 link->tx_state = DTI_TX_IDLE; | |
471 hDTI->sig_callback( | |
472 link->instance, | |
473 link->interfac, | |
474 link->channel, | |
475 DTI_REASON_TX_BUFFER_READY, | |
476 NULL | |
477 ); | |
478 } | |
479 } /* send_open_ready_callback() */ | |
480 | |
481 | |
482 | |
483 /* | |
484 +--------------------------------------------------------------------+ | |
485 | PROJECT : DTILIB MODULE : DTI_KERF | | |
486 | STATE : code ROUTINE : dti_open | | |
487 +--------------------------------------------------------------------+ | |
488 | |
489 * | |
490 * This function opens or resets a DTI connection. | |
491 * | |
492 */ | |
493 | |
494 GLOBAL BOOL dti_open (DTI_HANDLE hDTI, | |
495 U8 instance, | |
496 U8 interfac, | |
497 U8 channel, | |
498 U8 queue_size, | |
499 U8 direction, | |
500 U32 link_options, | |
501 U32 version, | |
502 U8 *neighbor_entity, | |
503 U32 link_id) | |
504 { | |
505 DTI_LINK *link; | |
506 BOOL send_req_or_ind = FALSE; | |
507 BOOL send_res_or_cnf = FALSE; | |
508 BOOL open_vsi_channel = FALSE; | |
509 BOOL riviera_atp_channel = FALSE; /* came by DAA hack */ | |
510 #ifdef BT_ADAPTER | |
511 BOOL riviera_bt_channel = FALSE; /* came by dirty BT interface hack */ | |
512 #endif /* riviera_bt_channel */ | |
513 U8 signal = DTI_NO_SIGNAL; | |
514 | |
515 trace_function(hDTI->handle, | |
516 "dti_open()", | |
517 hDTI->entity_options); | |
518 | |
519 trace_message_l_e(hDTI->handle, | |
520 "open connection", | |
521 link_id, | |
522 (char*)neighbor_entity, | |
523 hDTI->entity_options); | |
524 | |
525 #ifdef BT_ADAPTER | |
526 /* | |
527 * Check if open with a riviera entity. | |
528 */ | |
529 if (strcmp ((CHAR*)neighbor_entity, BTI_NAME) EQ 0) | |
530 { | |
531 riviera_bt_channel = TRUE; | |
532 } | |
533 #endif /* BT_ADAPTER */ | |
534 | |
535 #ifdef FF_TCP_IP | |
536 TRACE_EVENT_P5 ("dti_open: QS:%d DIR:%d LOPT:%d NE:%s LID:%d V:4", queue_size, direction, link_options, neighbor_entity, link_id); | |
537 if (strcmp ((CHAR*)neighbor_entity, RIV_NAME) EQ 0) | |
538 { | |
539 riviera_atp_channel = TRUE; | |
540 TRACE_EVENT("Riviera link to be opened!"); | |
541 } | |
542 #endif /* FF_TCP_IP */ | |
543 | |
544 /* | |
545 * Validate and correct passed parameters | |
546 */ | |
547 if(validate_open_parameters(hDTI, | |
548 link_id, | |
549 &queue_size, | |
550 &direction, | |
551 &link_options, | |
552 version, | |
553 neighbor_entity) EQ DTI_E_FAIL) | |
554 { | |
555 return FALSE; | |
556 } | |
557 | |
558 /* | |
559 * Find a link with the given link_id and direction | |
560 */ | |
561 switch (acquire_link (hDTI, link_id, direction, &link) ) | |
562 { | |
563 case DTI_S_FOUND: | |
564 /* | |
565 * Found already existing link | |
566 */ | |
567 switch (link->connect_state) | |
568 { | |
569 case DTI_CLOSING: | |
570 link->connect_state = DTI_IDLE; | |
571 /* fall through */ | |
572 | |
573 case DTI_IDLE: | |
574 /* | |
575 * Reset the link and set the parameter. | |
576 */ | |
577 trace_message(hDTI->handle, | |
578 "existing DTI connection is being reset!", | |
579 hDTI->entity_options); | |
580 | |
581 set_open_para_link_table(hDTI, | |
582 link, | |
583 version, | |
584 link_options, | |
585 instance, | |
586 interfac, | |
587 channel, | |
588 queue_size, | |
589 DTI_IDLE); | |
590 /* | |
591 * Send a confirm primitive if we use SAP DTI2.DOC. Then also set the parameter. | |
592 */ | |
593 send_req_or_ind = TRUE; | |
594 signal = DTI_REASON_CONNECTION_OPENED; | |
595 if (link->direction NEQ DTI_NULL_LINK) | |
596 { | |
597 /* | |
598 * Close the old channel. | |
599 */ | |
600 vsi_c_close (hDTI->handle, link->link_handle); | |
601 } | |
602 | |
603 /* | |
604 * Set the flag to open a new channel. | |
605 */ | |
606 open_vsi_channel = TRUE; | |
607 | |
608 break; | |
609 | |
610 case DTI_SETUP: | |
611 /* | |
612 * Collision of DTI2_CONNECT_REQ and DTI2_CONNECT_IND. The parameters | |
613 * have been set in dti_open before. They stay in this state. | |
614 */ | |
615 break; | |
616 | |
617 case DTI_CLOSED: | |
618 /* | |
619 * Start with connecting | |
620 */ | |
621 | |
622 set_open_para_link_table | |
623 ( | |
624 hDTI, link, version, link_options, | |
625 instance, interfac, channel, queue_size, DTI_SETUP | |
626 ); | |
627 | |
628 link->connect_state = DTI_SETUP; | |
629 send_req_or_ind = TRUE; | |
630 open_vsi_channel = TRUE; | |
631 break; | |
632 | |
633 case DTI_CONNECTING: | |
634 /* | |
635 * Got a connecting primitive, send a confirm primitive and set the parameter. | |
636 */ | |
637 set_open_para_link_table | |
638 ( | |
639 hDTI, link, version, link_options, | |
640 instance, interfac, channel, queue_size, DTI_IDLE | |
641 ); | |
642 | |
643 send_res_or_cnf = TRUE; | |
644 signal = DTI_REASON_CONNECTION_OPENED; | |
645 open_vsi_channel = TRUE; | |
646 break; | |
647 | |
648 default: | |
649 /* | |
650 * Wrong state | |
651 */ | |
652 trace_message_link_id(hDTI->handle, | |
653 "DTI ERROR: Wrong state of dtilib", | |
654 link_id, | |
655 hDTI->entity_options); | |
656 break; | |
657 } | |
658 break; | |
659 | |
660 /* | |
661 * Created new link | |
662 */ | |
663 case DTI_S_CREATED_NEW: | |
664 /* | |
665 * Open the requested channel and send a req/ind primitive. | |
666 */ | |
667 open_vsi_channel = TRUE; | |
668 | |
669 /* | |
670 * DTILIB can handle DTI SAP DTI.DOC and DTI2.DOC. By using DTI.DOC (the old | |
671 * SAP) the parameter are set but the connect primitives are not supported. | |
672 * | |
673 * SAP DTI.DOC does also not support a queue. So the queue len is set to | |
674 * 0 in the function set_link_parameter(). | |
675 */ | |
676 set_open_para_link_table | |
677 ( | |
678 hDTI, link, version, link_options, | |
679 instance, interfac, channel, queue_size, DTI_SETUP | |
680 ); | |
681 send_req_or_ind = TRUE; | |
682 break; | |
683 | |
684 default: | |
685 /* | |
686 * No free link - no connection possible. | |
687 */ | |
688 return FALSE; | |
689 } /*lint !e788 enum constant not used */ | |
690 | |
691 /* in case of RIV link, get parameters from AAA */ | |
692 #ifdef FF_TCP_IP | |
693 if( riviera_atp_channel) | |
694 { | |
695 link->link_type = RIVIERA_ATP_LINK; | |
696 link->entity_db = hDTI; /* remember the entity the link belongs to */ | |
697 link->dti_id = EXTRACT_DTI_ID(link_id); | |
698 /* link->link_options = FLOW_CNTRL_DISABLED; */ /* to avoid the full DTI state machine */ | |
699 | |
700 /* get the parameters valid within RIV environment from AAA */ | |
701 if(!aaa_get_connection_data( link->dti_id, &(link->port_nb), &(hDTI->entity_id_p), &(hDTI->own_name))) | |
702 { | |
703 TRACE_ERROR("aaa_get_connection_data() failed!"); | |
704 } | |
705 else | |
706 { | |
707 TRACE_EVENT_P2("got connection_data: name: %s, link_id: %d", (char*) (hDTI->own_name), link->link_id); | |
708 } | |
709 | |
710 if(hDTI->handle EQ PEI_ERROR) | |
711 { | |
712 TRACE_ERROR("error getting my own entity handle!"); | |
713 } | |
714 } | |
715 #endif | |
716 | |
717 /* mark links connection type */ | |
718 if( !riviera_atp_channel | |
719 #ifdef BT_ADAPTER | |
720 AND !riviera_bt_channel | |
721 #endif | |
722 ) /*lint !e774 (Info -- Boolean within 'if' always evaluates to True), only used for FF_TCP_IP/BT */ | |
723 { | |
724 link->link_type = ENTITY_LINK; | |
725 } | |
726 | |
727 /* | |
728 * link to BlueTooth | |
729 */ | |
730 #ifdef BT_ADAPTER | |
731 if(riviera_bt_channel) | |
732 { | |
733 link->link_type = RIVIERA_BT_LINK; | |
734 } | |
735 #endif | |
736 | |
737 /* | |
738 * Open a channel to VSI. If it is not possible to open, return FALSE to the entity | |
739 * so that the entity can try again. | |
740 */ | |
741 if(open_vsi_channel) | |
742 { | |
743 /* | |
744 * If NULL device then disable flow control | |
745 */ | |
746 if(direction EQ DTI_NULL_LINK) | |
747 { | |
748 trace_message(hDTI->handle, | |
749 "DTI connection is to be opened for NULL device", | |
750 hDTI->entity_options); | |
751 /* | |
752 * it is not exactly necessary to set this here, | |
753 * but only a logical consequence | |
754 */ | |
755 link->link_options = DTI_FLOW_CNTRL_DISABLED; | |
756 link->link_type = NULL_LINK; | |
757 link->connect_state = DTI_IDLE; | |
758 /* | |
759 * Activate callback function with reason_connection_opened | |
760 * and, additionally, signal tx_buffer_ready if the queue is used. | |
761 */ | |
762 send_open_ready_callback(hDTI, link); | |
763 return TRUE; | |
764 } | |
765 | |
766 if (link->link_type EQ ENTITY_LINK) /* check for connection within GPF */ | |
767 { | |
768 open_comm_channel(hDTI->handle, | |
769 &link->link_handle, | |
770 (char *) neighbor_entity, | |
771 hDTI->entity_options); | |
772 } | |
773 | |
774 #ifdef FF_TCP_IP | |
775 else if (link->link_type EQ RIVIERA_ATP_LINK) /* check for connection towards Riv */ | |
776 { | |
777 link->dti_data_ind = NULL; | |
778 link->connect_state = DTI_IDLE; /* we don't use connect prims here, */ | |
779 /* so set it by hand */ | |
780 signal = DTI_REASON_CONNECTION_OPENED; | |
781 send_res_or_cnf = FALSE; | |
782 send_req_or_ind = FALSE; | |
783 | |
784 open_comm_channel( hDTI->handle, /* open com handle to hDTI-entity */ | |
785 &link->link_handle, | |
786 (char *) hDTI->own_name, | |
787 hDTI->entity_options); | |
788 | |
789 /* the port has already been opened by AAA, so only remember link as leading to ATP, | |
790 * for sending data or events 'backwards' to that entity | |
791 */ | |
792 if(link->link_handle >= VSI_OK) | |
793 { | |
794 if(atp_links[link->port_nb] EQ D_LINK) | |
795 { | |
796 atp_links[link->port_nb] = link; | |
797 ATP_used_flag = TRUE; | |
798 } | |
799 else | |
800 { | |
801 TRACE_ERROR("link reference could not be saved for DAA"); | |
802 } | |
803 } | |
804 } | |
805 #endif | |
806 | |
807 if(link->link_handle < VSI_OK) | |
808 { | |
809 trace_message_link_id(hDTI->handle, | |
810 "DTI ERROR: open a comm channel not possible", | |
811 link_id, | |
812 hDTI->entity_options); | |
813 | |
814 set_default_para_link_table(hDTI, link, D_FREE_LINK_ID, D_DIRECTION); | |
815 return FALSE; | |
816 } | |
817 | |
818 #ifdef BT_ADAPTER | |
819 if(link->link_type EQ RIVIERA_BT_LINK) /* connection links into RIV environment */ | |
820 { | |
821 /* | |
822 xxxx: handle new BT link | |
823 */ | |
824 } | |
825 #endif | |
826 } /* if(open_channel) */ | |
827 | |
828 if(send_res_or_cnf) /* shouldn't happen for ATP links! */ | |
829 { | |
830 /* Send DTI2_CONNECT_RES or DTI2_CONNECT_CNF | |
831 */ | |
832 send_connect_res_or_cnf (hDTI, link); | |
833 } | |
834 else if(send_req_or_ind) /* is supposed to happen for ATP links??? */ | |
835 { | |
836 /* Send DTI2_CONNECT_REQ or DTI_CONNECT_IND. | |
837 */ | |
838 if(link->link_type EQ ENTITY_LINK) | |
839 { | |
840 send_connect_req_or_ind (hDTI, link); | |
841 } | |
842 } | |
843 /* | |
844 * Activate the callback function to the entity. | |
845 */ | |
846 if(signal EQ DTI_REASON_CONNECTION_OPENED) | |
847 { | |
848 if (!(hDTI->entity_options & DTI_NO_TRACE) ) | |
849 { | |
850 trace_message_l_e(hDTI->handle, | |
851 "DTI connection opened", /*lint !e605 Increase in pointer capability */ | |
852 link_id, | |
853 (char*)neighbor_entity, | |
854 hDTI->entity_options); | |
855 } | |
856 | |
857 /* | |
858 * Activate callback function with reason_connection_opened | |
859 * and, additionally, signal tx_buffer_ready if the queue is used. | |
860 */ | |
861 send_open_ready_callback (hDTI, link); | |
862 } | |
863 return TRUE; | |
864 } | |
865 | |
866 /* | |
867 +--------------------------------------------------------------------+ | |
868 | PROJECT : DTILIB MODULE : dti_kerf.c | | |
869 | STATE : code ROUTINE : send_disconnect_req_or_ind | | |
870 +--------------------------------------------------------------------+ | |
871 | |
872 * PURPOSE: Send a Disconnect primitive depending on the direction. | |
873 */ | |
874 | |
875 LOCAL void send_disconnect_req_or_ind (DTI_HANDLE hDTI, | |
876 DTI_LINK* link, | |
877 U8 cause) | |
878 { | |
879 #define VSI_CALLER hDTI->handle, | |
880 /* | |
881 * Check if the link is upwards or downwards | |
882 * and send the according disconnect primitive. | |
883 */ | |
884 switch (link->direction) | |
885 { | |
886 case DTI_CHANNEL_TO_HIGHER_LAYER: | |
887 { | |
888 PALLOC (dti_disconnect_ind, DTI2_DISCONNECT_IND); | |
889 dti_disconnect_ind->link_id = link->link_id; | |
890 dti_disconnect_ind->cause = cause; | |
891 if(hDTI->entity_options & DTI_NO_TRACE) | |
892 { | |
893 PSEND_NTRACE(link->link_handle, dti_disconnect_ind); | |
894 } | |
895 else | |
896 { | |
897 PSEND(link->link_handle, dti_disconnect_ind); | |
898 trace_message_link_id(hDTI->handle, | |
899 "OUT: DTI2_DISCONNECT_IND", | |
900 link->link_id, | |
901 hDTI->entity_options); | |
902 } | |
903 } | |
904 break; | |
905 | |
906 case DTI_CHANNEL_TO_LOWER_LAYER: | |
907 { | |
908 PALLOC (dti_disconnect_req, DTI2_DISCONNECT_REQ); | |
909 dti_disconnect_req->link_id = link->link_id; | |
910 dti_disconnect_req->cause = cause; | |
911 if(hDTI->entity_options & DTI_NO_TRACE) | |
912 { | |
913 PSEND_NTRACE(link->link_handle, dti_disconnect_req); | |
914 } | |
915 else | |
916 { | |
917 PSEND(link->link_handle, dti_disconnect_req); | |
918 trace_message_link_id(hDTI->handle, | |
919 "OUT: DTI2_DISCONNECT_REQ", | |
920 link->link_id, | |
921 hDTI->entity_options); | |
922 } | |
923 } | |
924 break; | |
925 | |
926 default: | |
927 /* | |
928 * no known channel type open so do not send anything | |
929 */ | |
930 break; | |
931 } | |
932 #undef VSI_CALLER | |
933 } /* send_disconnect_req_or_ind() */ | |
934 | |
935 | |
936 | |
937 /* | |
938 +--------------------------------------------------------------------+ | |
939 | PROJECT : DTILIB MODULE : dti_kerf.c | | |
940 | STATE : code ROUTINE : send_ready_req_or_ind | | |
941 +--------------------------------------------------------------------+ | |
942 | |
943 * PURPOSE: Send a Flow Control primitive depending on the direction. | |
944 */ | |
945 | |
946 LOCAL void send_ready_req_or_ind (DTI_HANDLE hDTI, DTI_LINK *link) | |
947 { | |
948 #define VSI_CALLER hDTI->handle, | |
949 | |
950 #ifdef FF_TCP_IP | |
951 /* | |
952 * do not send flow control primitives in case of riviera link | |
953 * but send a Data primitive to trigger next data reception | |
954 * this is needed because ATP may has sent data | |
955 * where DTILIB was not initialized yet | |
956 */ | |
957 if(link->link_type EQ RIVIERA_ATP_LINK) | |
958 { | |
959 PALLOC(dti_data_ind, DTI2_DATA_IND); | |
960 dti_data_ind->link_id = link->link_id; | |
961 dti_data_ind->desc_list2.list_len = 0; | |
962 dti_data_ind->desc_list2.first = (U32)NULL; | |
963 PSEND(link->link_handle, dti_data_ind); | |
964 return; | |
965 } | |
966 #endif /* FF_TCP_IP */ | |
967 /* | |
968 * Check if the link is upwards or downwards | |
969 * and send the according connect primitive. | |
970 */ | |
971 switch (link->direction) | |
972 { | |
973 case DTI_CHANNEL_TO_HIGHER_LAYER: | |
974 #ifdef BT_ADAPTER | |
975 if(link->link_type EQ RIVIERA_BT_LINK) | |
976 { | |
977 btidti_getdata_req(link_id); | |
978 } | |
979 else | |
980 #endif /* BT_ADAPTER */ | |
981 { | |
982 if(link->link_type EQ ENTITY_LINK) | |
983 { | |
984 PALLOC (dti_ready_ind, DTI2_READY_IND); | |
985 dti_ready_ind->link_id = link->link_id; | |
986 if(hDTI->entity_options & DTI_NO_TRACE) | |
987 { | |
988 PSEND_NTRACE(link->link_handle, dti_ready_ind); | |
989 } | |
990 else | |
991 { | |
992 PSEND(link->link_handle, dti_ready_ind); | |
993 trace_message_link_id(hDTI->handle, | |
994 "OUT: DTI2_READY_IND", | |
995 link->link_id, | |
996 hDTI->entity_options); | |
997 } | |
998 } | |
999 } | |
1000 break; | |
1001 | |
1002 case DTI_CHANNEL_TO_LOWER_LAYER: | |
1003 #ifdef BT_ADAPTER | |
1004 if(link->link_type EQ RIVIERA_BT_LINK) | |
1005 { | |
1006 btidti_getdata_req(link_id); | |
1007 } | |
1008 else | |
1009 #endif /* BT_ADAPTER */ | |
1010 { | |
1011 if(link->link_type EQ ENTITY_LINK) | |
1012 { | |
1013 PALLOC (dti_getdata_req, DTI2_GETDATA_REQ); | |
1014 dti_getdata_req->link_id = link->link_id; | |
1015 if(hDTI->entity_options & DTI_NO_TRACE) | |
1016 { | |
1017 PSEND_NTRACE(link->link_handle, dti_getdata_req); | |
1018 } | |
1019 else | |
1020 { | |
1021 PSEND(link->link_handle, dti_getdata_req); | |
1022 trace_message_link_id(hDTI->handle, | |
1023 "OUT: DTI2_GETDATA_REQ", | |
1024 link->link_id, | |
1025 hDTI->entity_options); | |
1026 } | |
1027 } | |
1028 } | |
1029 break; | |
1030 | |
1031 default: | |
1032 /* | |
1033 * no known channel type open so do not send anything | |
1034 */ | |
1035 break; | |
1036 } | |
1037 #undef VSI_CALLER | |
1038 } /* send_ready_req_or_ind() */ | |
1039 | |
1040 | |
1041 | |
1042 /* | |
1043 +--------------------------------------------------------------------+ | |
1044 | PROJECT : DTILIB MODULE : DTI_KERF | | |
1045 | STATE : code ROUTINE : dti_close | | |
1046 +--------------------------------------------------------------------+ | |
1047 | |
1048 * | |
1049 * The function searchs a link in the databank link list and closes it. | |
1050 * Then it calls the callback function with the signal DTI_REASON_CONNECTION_CLOSED. | |
1051 */ | |
1052 | |
1053 GLOBAL void dti_close (DTI_HANDLE hDTI, | |
1054 U8 instance, | |
1055 U8 interfac, | |
1056 U8 channel, | |
1057 BOOL flush) | |
1058 { | |
1059 DTI_LINK *link; | |
1060 | |
1061 trace_function( hDTI->handle, | |
1062 "dti_close()", | |
1063 hDTI->entity_options); | |
1064 | |
1065 /* | |
1066 * Find the link in the database | |
1067 */ | |
1068 | |
1069 if((link = get_pointer_link_table_channel(hDTI, | |
1070 instance, | |
1071 interfac, | |
1072 channel)) NEQ NULL) | |
1073 { | |
1074 | |
1075 trace_message_link_id(hDTI->handle, | |
1076 "closing DTI connection", /*lint !e605 Increase in pointer capability */ | |
1077 link->link_id, | |
1078 hDTI->entity_options); | |
1079 | |
1080 if (link->direction EQ DTI_NULL_LINK) | |
1081 { | |
1082 set_default_para_link_table(hDTI, link, D_FREE_LINK_ID, D_DIRECTION); | |
1083 return; | |
1084 } | |
1085 | |
1086 switch (link->connect_state) | |
1087 { | |
1088 /* | |
1089 * The link is already closed | |
1090 */ | |
1091 | |
1092 case DTI_CLOSED: | |
1093 trace_message_link_id(hDTI->handle, | |
1094 "Link is already closed for this entity", | |
1095 link->link_id, | |
1096 hDTI->entity_options); | |
1097 return; | |
1098 | |
1099 /* | |
1100 * In all other states the entity sends a disconnect primitive | |
1101 */ | |
1102 default: | |
1103 /* | |
1104 * exit only after send queue has been emptied? | |
1105 */ | |
1106 if(flush EQ TRUE) | |
1107 { | |
1108 /* | |
1109 * if it is not empty, wait for data flow primitives | |
1110 * from the peer entity | |
1111 */ | |
1112 if(link->queue_len NEQ 0) | |
1113 { | |
1114 link->connect_state = DTI_CLOSING; | |
1115 return; | |
1116 } | |
1117 else | |
1118 { | |
1119 /* | |
1120 * call the callback function right now. | |
1121 */ | |
1122 hDTI->sig_callback( | |
1123 link->instance, | |
1124 link->interfac, | |
1125 link->channel, | |
1126 DTI_REASON_CONNECTION_CLOSED, | |
1127 NULL | |
1128 ); | |
1129 } | |
1130 } | |
1131 | |
1132 if (link->link_type NEQ RIVIERA_ATP_LINK) | |
1133 /* check for connection towards ATP. The NULL_LINK case is handled | |
1134 * above, already. | |
1135 */ | |
1136 { | |
1137 send_disconnect_req_or_ind (hDTI, link, DTI_CAUSE_NORMAL_CLOSE); | |
1138 } | |
1139 #ifdef FF_TCP_IP | |
1140 else /* the links goes towards Riviera */ | |
1141 { | |
1142 U8 i; | |
1143 atp_links[link->port_nb] = D_LINK; | |
1144 ATP_used_flag = FALSE; | |
1145 for (i=0; i<MAX_ATP_LINKS; i++) | |
1146 { | |
1147 if(atp_links[i] NEQ D_LINK) | |
1148 { | |
1149 ATP_used_flag = TRUE; | |
1150 TRACE_EVENT("there are still open ATP links!"); | |
1151 break; | |
1152 } | |
1153 } | |
1154 } | |
1155 #endif /* FF_TCP_IP */ | |
1156 | |
1157 /* | |
1158 * close the communication channel | |
1159 */ | |
1160 vsi_c_close (hDTI->handle, link->link_handle); | |
1161 /* | |
1162 * Set the default parameter. The channel is closed in the neighbour entity. | |
1163 */ | |
1164 set_default_para_link_table(hDTI,link, D_FREE_LINK_ID, D_DIRECTION); | |
1165 | |
1166 /* | |
1167 * Note: Flow control and data primitives are silently discarded. | |
1168 */ | |
1169 | |
1170 break; | |
1171 } | |
1172 } | |
1173 else | |
1174 { | |
1175 /* | |
1176 * there is no link to be found in the table | |
1177 */ | |
1178 trace_message_iic(hDTI->handle, | |
1179 "DTI link is alredy closed", | |
1180 instance, | |
1181 interfac, | |
1182 channel, | |
1183 hDTI->entity_options); | |
1184 } | |
1185 } | |
1186 | |
1187 | |
1188 | |
1189 /* | |
1190 +--------------------------------------------------------------------+ | |
1191 | PROJECT : DTILIB MODULE : DTI_KERF | | |
1192 | STATE : code ROUTINE : dti_start | | |
1193 +--------------------------------------------------------------------+ | |
1194 | |
1195 * | |
1196 * If the entity wants to receive data primitives, this function must be | |
1197 * called. | |
1198 */ | |
1199 | |
1200 GLOBAL void dti_start( DTI_HANDLE hDTI, U8 instance, U8 interfac, U8 channel) | |
1201 { | |
1202 DTI_LINK *link; | |
1203 | |
1204 trace_function( hDTI->handle, | |
1205 "dti_start()", | |
1206 hDTI->entity_options); | |
1207 | |
1208 /* | |
1209 * Find the link in the database. | |
1210 */ | |
1211 link = get_pointer_link_table_channel(hDTI, instance, interfac, channel); | |
1212 if(link EQ NULL) | |
1213 { | |
1214 /* | |
1215 * Link id is not in the table. | |
1216 */ | |
1217 trace_message_iic(hDTI->handle, | |
1218 "DTI ERROR: dti_start() - No link id in the database", | |
1219 instance, | |
1220 interfac, | |
1221 channel, | |
1222 hDTI->entity_options); | |
1223 return; | |
1224 } | |
1225 /* | |
1226 * Is the entity connected ? | |
1227 */ | |
1228 if(link->connect_state NEQ DTI_IDLE) | |
1229 { | |
1230 trace_message_link_id(hDTI->handle, | |
1231 "DTI ERROR: link is not connected", | |
1232 link->link_id, | |
1233 hDTI->entity_options); | |
1234 return; | |
1235 } | |
1236 /* | |
1237 * Check if the flow control is not used but do nothing. | |
1238 */ | |
1239 if(link->link_options EQ DTI_FLOW_CNTRL_DISABLED) | |
1240 return; | |
1241 /* | |
1242 * Handle the states | |
1243 */ | |
1244 switch(link->rx_state) | |
1245 { | |
1246 case DTI_RX_IDLE: | |
1247 /* | |
1248 * Change the state to indicate ready to receive data. | |
1249 */ | |
1250 link->rx_state = DTI_RX_READY; | |
1251 /* | |
1252 * No flow control primitive was sent. So send one now. | |
1253 * NOTE: The parameter link->direction gives information about the | |
1254 * direction for sending the data. | |
1255 */ | |
1256 send_ready_req_or_ind (hDTI, link); | |
1257 break; | |
1258 | |
1259 case DTI_RX_STOPPED: | |
1260 /* | |
1261 * The entity has stopped the flow control. | |
1262 * The flow control was sent already. | |
1263 * So change state to DTI_RX_READY. | |
1264 */ | |
1265 link->rx_state = DTI_RX_READY; | |
1266 break; | |
1267 | |
1268 case DTI_RX_READY: | |
1269 /* | |
1270 * dti_start() was already called. | |
1271 */ | |
1272 break; | |
1273 | |
1274 default: | |
1275 /* | |
1276 * Unexpected state - set ERROR. | |
1277 */ | |
1278 trace_message_link_id(hDTI->handle, | |
1279 "DTI ERROR: wrong state", | |
1280 link->link_id, | |
1281 hDTI->entity_options); | |
1282 break; | |
1283 } | |
1284 } /* dti_start() */ | |
1285 | |
1286 | |
1287 | |
1288 /* | |
1289 +--------------------------------------------------------------------+ | |
1290 | PROJECT : DTILIB MODULE : DTI_KERF | | |
1291 | STATE : code ROUTINE : dti_stop | | |
1292 +--------------------------------------------------------------------+ | |
1293 | |
1294 * | |
1295 * This function is called if the entity wants to stop receiving of data | |
1296 * primitives. | |
1297 */ | |
1298 | |
1299 GLOBAL void dti_stop( DTI_HANDLE hDTI, U8 instance, U8 interfac, U8 channel) | |
1300 { | |
1301 DTI_LINK *link; | |
1302 | |
1303 trace_function( hDTI->handle, | |
1304 "dti_stop()", | |
1305 hDTI->entity_options); | |
1306 | |
1307 /* | |
1308 * Find the link in the databank. | |
1309 */ | |
1310 link = get_pointer_link_table_channel(hDTI, instance, interfac, channel); | |
1311 /* | |
1312 * It is link id in the table ? | |
1313 */ | |
1314 if(link EQ NULL) | |
1315 { | |
1316 trace_message_iic(hDTI->handle, | |
1317 "DTI ERROR: dti_stop() - No link id in the database", | |
1318 instance, | |
1319 interfac, | |
1320 channel, | |
1321 hDTI->entity_options); | |
1322 return; | |
1323 } | |
1324 /* | |
1325 * Is the entity connected ? | |
1326 */ | |
1327 if(link->connect_state NEQ DTI_IDLE) | |
1328 { | |
1329 trace_message_link_id(hDTI->handle, | |
1330 "DTI ERROR: dti_stop() - link is not connected", | |
1331 link->link_id, | |
1332 hDTI->entity_options); | |
1333 return; | |
1334 } | |
1335 /* | |
1336 * Check if the flow control is not used - then do nothing | |
1337 */ | |
1338 if(link->link_options EQ DTI_FLOW_CNTRL_DISABLED) | |
1339 return; | |
1340 /* | |
1341 * Handle the states | |
1342 */ | |
1343 switch(link->rx_state) | |
1344 { | |
1345 case DTI_RX_READY: | |
1346 /* | |
1347 * The flow control was already sent therefor change to stop state. | |
1348 */ | |
1349 link->rx_state = DTI_RX_STOPPED; | |
1350 break; | |
1351 | |
1352 case DTI_RX_STOPPED: | |
1353 case DTI_RX_IDLE: | |
1354 /* | |
1355 * dti_stop() was already called. | |
1356 * So there is no need to change state. | |
1357 */ | |
1358 break; | |
1359 | |
1360 default: | |
1361 /* | |
1362 * Other state - ERROR | |
1363 */ | |
1364 trace_message_link_id(hDTI->handle, | |
1365 "DTI ERROR: dti_stop() - wrong state", | |
1366 link->link_id, | |
1367 hDTI->entity_options); | |
1368 break; | |
1369 } | |
1370 } /* dti_stop() */ | |
1371 | |
1372 | |
1373 | |
1374 #ifdef _SIMULATION_ | |
1375 /* | |
1376 +--------------------------------------------------------------------+ | |
1377 | PROJECT : DTILIB MODULE : dti_kerf.c | | |
1378 | STATE : code ROUTINE : send_data_test_req_or_ind | | |
1379 +--------------------------------------------------------------------+ | |
1380 | |
1381 * PURPOSE: Get a DTI_DATA_IND and translate it to DTI_DATA_TEST_IND | |
1382 * and send it. | |
1383 */ | |
1384 | |
1385 LOCAL void send_data_test_req_or_ind (DTI_HANDLE hDTI, | |
1386 DTI_LINK* link, | |
1387 T_DTI2_DATA_IND* dti_data_ind) | |
1388 { | |
1389 #define VSI_CALLER hDTI->handle, | |
1390 U16 len_buf_bits; | |
1391 U16 i; | |
1392 U16 len; | |
1393 U16 j; | |
1394 T_desc2 *p_desc; | |
1395 | |
1396 trace_function(hDTI->handle, | |
1397 "send_data_test_req_or_ind()", | |
1398 hDTI->entity_options); | |
1399 | |
1400 len_buf_bits = dti_data_ind->desc_list2.list_len * 8; | |
1401 | |
1402 /* | |
1403 * Build the SDU primitive and send it | |
1404 */ | |
1405 { | |
1406 PALLOC_SDU (dti_data_test_ind, DTI2_DATA_TEST_IND, len_buf_bits); | |
1407 memset (dti_data_test_ind, 0, sizeof (T_DTI2_DATA_TEST_IND)); | |
1408 | |
1409 dti_data_test_ind->link_id = dti_data_ind->link_id; | |
1410 dti_data_test_ind->parameters = dti_data_ind->parameters; | |
1411 | |
1412 dti_data_test_ind->sdu.l_buf = len_buf_bits; | |
1413 dti_data_test_ind->sdu.o_buf = 0; | |
1414 | |
1415 /* | |
1416 * Copy the descs into sdu structure. | |
1417 */ | |
1418 if(len_buf_bits > 0) | |
1419 { | |
1420 j = 0; | |
1421 p_desc = (T_desc2*)(dti_data_ind->desc_list2.first); | |
1422 while(p_desc NEQ NULL) | |
1423 { | |
1424 len = p_desc->len; | |
1425 for(i=0; i < len; i++) | |
1426 { | |
1427 dti_data_test_ind->sdu.buf[j] = p_desc->buffer[i]; | |
1428 j++; | |
1429 } | |
1430 p_desc = (T_desc2*)(p_desc->next); | |
1431 } | |
1432 } | |
1433 | |
1434 /* | |
1435 * Check if the link is upwards or downwards | |
1436 * and send the according disconnect primitive. | |
1437 */ | |
1438 switch (link->direction) | |
1439 { | |
1440 case DTI_CHANNEL_TO_HIGHER_LAYER: | |
1441 if(hDTI->entity_options & DTI_NO_TRACE) | |
1442 { | |
1443 PSEND_NTRACE(link->link_handle, dti_data_test_ind); | |
1444 } | |
1445 else | |
1446 { | |
1447 PSEND(link->link_handle, dti_data_test_ind); | |
1448 trace_message_l_dl(hDTI->handle, | |
1449 "OUT: DTI2_DATA_TEST_IND", | |
1450 dti_data_ind->link_id, | |
1451 dti_data_ind->desc_list2.list_len, | |
1452 hDTI->entity_options); | |
1453 } | |
1454 break; | |
1455 | |
1456 case DTI_CHANNEL_TO_LOWER_LAYER: | |
1457 if(hDTI->entity_options & DTI_NO_TRACE) | |
1458 { | |
1459 PPASS_NTRACE(dti_data_test_ind, | |
1460 dti_data_test_req, | |
1461 DTI2_DATA_TEST_REQ); | |
1462 PSEND_NTRACE(link->link_handle, dti_data_test_req); | |
1463 } | |
1464 else | |
1465 { | |
1466 PPASS(dti_data_test_ind, dti_data_test_req, DTI2_DATA_TEST_REQ); | |
1467 PSEND(link->link_handle, dti_data_test_req); | |
1468 trace_message_l_dl(hDTI->handle, | |
1469 "OUT: DTI2_DATA_TEST_REQ", | |
1470 dti_data_ind->link_id, | |
1471 dti_data_ind->desc_list2.list_len, | |
1472 hDTI->entity_options); | |
1473 } | |
1474 break; | |
1475 | |
1476 default: | |
1477 /* | |
1478 * no known channel type open so do not send anything | |
1479 */ | |
1480 break; | |
1481 } | |
1482 } | |
1483 /* | |
1484 * Free the dti_data_ind primitive and the descs in the linked list. | |
1485 */ | |
1486 mfree_desc(hDTI, &dti_data_ind->desc_list2); | |
1487 PFREE (dti_data_ind); | |
1488 #undef VSI_CALLER | |
1489 } /* send_data_test_req_or_ind() */ | |
1490 #endif /* _SIMULATION_ */ | |
1491 | |
1492 | |
1493 | |
1494 /* | |
1495 +--------------------------------------------------------------------+ | |
1496 | PROJECT : DTILIB MODULE : dti_kerf.c | | |
1497 | STATE : code ROUTINE : send_data_req_or_ind | | |
1498 +--------------------------------------------------------------------+ | |
1499 | |
1500 * PURPOSE: Send a Data primitive depending on the direction. | |
1501 */ | |
1502 | |
1503 LOCAL void send_data_req_or_ind (DTI_HANDLE hDTI, | |
1504 DTI_LINK* link, | |
1505 T_DTI2_DATA_IND* dti_data_ind) | |
1506 { | |
1507 #ifndef _SIMULATION_ | |
1508 U32 link_id; | |
1509 U16 list_len; | |
1510 #endif /* !_SIMULATION_ */ | |
1511 #ifdef BT_ADAPTER | |
1512 if(link->link_type EQ RIVIERA_BT_LINK) | |
1513 { | |
1514 btidti_data_req(dti_data_ind); | |
1515 } | |
1516 else | |
1517 #endif /* BT_ADAPTER */ | |
1518 /* | |
1519 * Check if the primitive is directed to a GPF or ATP entity, and send it. | |
1520 */ | |
1521 #ifdef FF_TCP_IP | |
1522 if(link->link_type EQ RIVIERA_ATP_LINK) | |
1523 { | |
1524 dti_send_data_to_atp(hDTI, link, dti_data_ind); | |
1525 return; | |
1526 } | |
1527 #endif /* FF_TCP_IP */ | |
1528 | |
1529 #ifdef _SIMULATION_ | |
1530 send_data_test_req_or_ind(hDTI, link, dti_data_ind); | |
1531 #else /* _SIMULATION_ */ | |
1532 #define VSI_CALLER hDTI->handle, | |
1533 /* | |
1534 * Check if the link is upwards or downwards | |
1535 * and send the according disconnect primitive. | |
1536 */ | |
1537 switch (link->direction) | |
1538 { | |
1539 case DTI_CHANNEL_TO_HIGHER_LAYER: | |
1540 #ifdef BT_ADAPTER | |
1541 if(link->link_type EQ RIVIERA_LINK) | |
1542 { | |
1543 btidti_data_req(dti_data_ind); | |
1544 } | |
1545 else | |
1546 #endif /* BT_ADAPTER */ | |
1547 { | |
1548 if(hDTI->entity_options & DTI_NO_TRACE) | |
1549 { | |
1550 PSEND_NTRACE(link->link_handle, dti_data_ind); | |
1551 } | |
1552 else | |
1553 { | |
1554 link_id = dti_data_ind->link_id; | |
1555 list_len = dti_data_ind->desc_list2.list_len; | |
1556 PSEND(link->link_handle, dti_data_ind); | |
1557 trace_message_l_dl(hDTI->handle, | |
1558 "OUT: DTI2_DATA_IND", | |
1559 link_id, | |
1560 list_len, | |
1561 hDTI->entity_options); | |
1562 } | |
1563 } | |
1564 break; | |
1565 | |
1566 case DTI_CHANNEL_TO_LOWER_LAYER: | |
1567 if(hDTI->entity_options & DTI_NO_TRACE) | |
1568 { | |
1569 PPASS_NTRACE(dti_data_ind, dti_data_req, DTI2_DATA_REQ); | |
1570 PSEND_NTRACE(link->link_handle, dti_data_req); | |
1571 } | |
1572 else | |
1573 { | |
1574 PPASS(dti_data_ind, dti_data_req, DTI2_DATA_REQ); | |
1575 link_id = dti_data_req->link_id; | |
1576 list_len = dti_data_req->desc_list2.list_len; | |
1577 PSEND(link->link_handle, dti_data_req); | |
1578 trace_message_l_dl(hDTI->handle, | |
1579 "OUT: DTI2_DATA_REQ", | |
1580 link_id, | |
1581 list_len, | |
1582 hDTI->entity_options); | |
1583 } | |
1584 break; | |
1585 | |
1586 default: | |
1587 /* | |
1588 * no known channel type open so do not send anything | |
1589 */ | |
1590 break; | |
1591 } | |
1592 #undef VSI_CALLER | |
1593 #endif /* else _SIMULATION_ */ | |
1594 } /* send_data_req_or_ind() */ | |
1595 | |
1596 | |
1597 | |
1598 /* | |
1599 +--------------------------------------------------------------------+ | |
1600 | PROJECT : DTILIB MODULE : DTI_KERF | | |
1601 | STATE : code ROUTINE : dti_send_data | | |
1602 +--------------------------------------------------------------------+ | |
1603 | |
1604 * | |
1605 * This function sends data. If the database direction is set to | |
1606 * DTI_UPLINK then it sends a dti_data_req primitive otherwise a DTI_DATA_IND | |
1607 * primitive. | |
1608 */ | |
1609 | |
1610 GLOBAL void dti_send_data (DTI_HANDLE hDTI, | |
1611 U8 instance, | |
1612 U8 interfac, | |
1613 U8 channel, | |
1614 T_DTI2_DATA_IND *dti_data_ind) | |
1615 { | |
1616 DTI_LINK *link; | |
1617 T_DTI2_DATA_IND *hlp_data_ind; | |
1618 | |
1619 trace_function(hDTI->handle, | |
1620 "dti_send_data()", | |
1621 hDTI->entity_options); | |
1622 | |
1623 /* | |
1624 * Find the link in the database. | |
1625 */ | |
1626 link = get_pointer_link_table_channel(hDTI, instance, interfac, channel); | |
1627 if(link EQ NULL) | |
1628 { | |
1629 /* | |
1630 * link_id is not in the table. | |
1631 */ | |
1632 trace_message_iic(hDTI->handle, | |
1633 "DTI ERROR: dti_send_data() - No link id in the database", | |
1634 instance, | |
1635 interfac, | |
1636 channel, | |
1637 hDTI->entity_options); | |
1638 mfree_desc(hDTI, &dti_data_ind->desc_list2); | |
1639 PFREE (dti_data_ind); | |
1640 return; | |
1641 } | |
1642 | |
1643 /* | |
1644 * Is the entity connected ? | |
1645 */ | |
1646 if(link->connect_state NEQ DTI_IDLE) | |
1647 { | |
1648 trace_message_link_id(hDTI->handle, | |
1649 "DTI ERROR: dti_send_data() - link is not connected", | |
1650 link->link_id, | |
1651 hDTI->entity_options); | |
1652 mfree_desc(hDTI, &dti_data_ind->desc_list2); | |
1653 PFREE (dti_data_ind); | |
1654 return; | |
1655 } | |
1656 | |
1657 /* | |
1658 * If link is a NULL device then just free the message | |
1659 */ | |
1660 if (link->direction EQ DTI_NULL_LINK) | |
1661 { | |
1662 mfree_desc (hDTI, &dti_data_ind->desc_list2); | |
1663 PFREE (dti_data_ind); | |
1664 return; | |
1665 } | |
1666 | |
1667 /* | |
1668 * There is no flow control, so the primitive doesn't get into the queue | |
1669 * and has to get sent at once. | |
1670 */ | |
1671 if(link->link_options EQ DTI_FLOW_CNTRL_DISABLED) | |
1672 { | |
1673 send_data_req_or_ind(hDTI, link, dti_data_ind); | |
1674 return; | |
1675 } | |
1676 | |
1677 switch (link->tx_state) | |
1678 { | |
1679 case DTI_TX_IDLE: | |
1680 case DTI_TX_BUFFER_FULL: | |
1681 /* | |
1682 * While waiting for a flow control primitive no sending is possible. | |
1683 * Put the primitive dti_data_ind in the queue. | |
1684 */ | |
1685 put_dti_data_ind_in_queue_managed (hDTI, link, dti_data_ind); | |
1686 break; | |
1687 | |
1688 case DTI_TX_FLOW: | |
1689 /* | |
1690 * The flow control primitive is already received. | |
1691 * So just send Data primitive and change state. | |
1692 * Because of ATP links there might be still a prim in the queue | |
1693 * therefore we have to use the queue for this | |
1694 */ | |
1695 put_dti_data_ind_in_queue(hDTI, link, dti_data_ind); | |
1696 /* | |
1697 * Read the last packet from the queue and send it. | |
1698 */ | |
1699 { | |
1700 hlp_data_ind = get_dti_data_ind_from_queue(hDTI, link); | |
1701 hlp_data_ind->link_id = link->link_id; | |
1702 /* | |
1703 * The packet will be sent. Now change the state to DTI_TX_IDLE. | |
1704 */ | |
1705 link->tx_state = DTI_TX_IDLE; | |
1706 /* | |
1707 * Send the primitive depending on its direction. | |
1708 */ | |
1709 send_data_req_or_ind(hDTI, link, hlp_data_ind); | |
1710 } | |
1711 break; | |
1712 | |
1713 default: | |
1714 /* | |
1715 * Unknown state.. | |
1716 */ | |
1717 trace_message_link_id(hDTI->handle, | |
1718 "DTI ERROR: dti_send_data() - wrong state", | |
1719 link->link_id, | |
1720 hDTI->entity_options); | |
1721 mfree_desc(hDTI, &dti_data_ind->desc_list2); | |
1722 PFREE (dti_data_ind); | |
1723 break; | |
1724 } | |
1725 /* | |
1726 * if queue is full now, send a warning callback | |
1727 */ | |
1728 if((link->queue_len >= link->queue_size) AND | |
1729 (link->link_options NEQ DTI_QUEUE_UNBOUNDED)) | |
1730 { | |
1731 link->tx_state = DTI_TX_BUFFER_FULL; | |
1732 hDTI->sig_callback(link->instance, | |
1733 link->interfac, | |
1734 link->channel, | |
1735 DTI_REASON_TX_BUFFER_FULL, | |
1736 NULL); | |
1737 } | |
1738 } /* dti_send_data() */ | |
1739 | |
1740 | |
1741 | |
1742 /* | |
1743 +--------------------------------------------------------------------------+ | |
1744 | PROJECT : DTILIB MODULE : DTI_KERF | | |
1745 | STATE : code ROUTINE : flow_control_prim_received | | |
1746 +--------------------------------------------------------------------------+ | |
1747 | |
1748 PURPOSE : Process primitives DTI_GETDATA_REQ and DTI_READY_IND | |
1749 received from neighbour DTI | |
1750 */ | |
1751 | |
1752 GLOBAL void flow_control_prim_received (DTI_HANDLE hDTI, | |
1753 U32 link_id, | |
1754 U8 direction) | |
1755 { | |
1756 DTI_LINK* link; | |
1757 T_DTI2_DATA_IND* dti_data_ind; | |
1758 | |
1759 trace_function(hDTI->handle, | |
1760 "flow_control_prim_received()", | |
1761 hDTI->entity_options); | |
1762 | |
1763 /* | |
1764 * get link pointer | |
1765 */ | |
1766 link = get_pointer_link_table(hDTI, link_id, direction); | |
1767 if(link EQ NULL) | |
1768 { | |
1769 /* | |
1770 * There is no link_id which requested to the link_id in the link_table. | |
1771 */ | |
1772 trace_message_link_id(hDTI->handle, | |
1773 "DTI ERROR: fc_prim - No link in data base", | |
1774 link_id, | |
1775 hDTI->entity_options); | |
1776 return; | |
1777 } | |
1778 | |
1779 /* | |
1780 * check for valid link | |
1781 * the link is valid if it is in IDLE or CLOSING state | |
1782 * Flow Control primitives are unexpected if Flow Control is disabled | |
1783 */ | |
1784 if(((link->connect_state NEQ DTI_IDLE) AND | |
1785 (link->connect_state NEQ DTI_CLOSING)) OR | |
1786 (link->link_options EQ DTI_FLOW_CNTRL_DISABLED)) | |
1787 { | |
1788 TRACE_EVENT_P4("HORST=7, weil: connect_state %d, link_options %d, link_id %u, direction %d", | |
1789 link->connect_state, link->link_options, link_id, direction); | |
1790 return; | |
1791 } | |
1792 /* | |
1793 * get next prim from queue | |
1794 */ | |
1795 dti_data_ind = get_dti_data_ind_from_queue(hDTI, link); | |
1796 /* | |
1797 * Select the state. | |
1798 */ | |
1799 switch (link->tx_state) | |
1800 { | |
1801 case DTI_TX_IDLE: | |
1802 case DTI_TX_FLOW: | |
1803 /* | |
1804 * A flow control primitive is received. Send a data packet | |
1805 * if there is any in the queue or change the state. | |
1806 * In case of an RIVIERA_ATP_LINK it is necessary to check the send queue | |
1807 * also in DTI_TX_FLOW state | |
1808 */ | |
1809 if(dti_data_ind NEQ NULL) | |
1810 { | |
1811 /* | |
1812 * Select link_id and send data. | |
1813 */ | |
1814 dti_data_ind->link_id = link->link_id; | |
1815 send_data_req_or_ind(hDTI, link, dti_data_ind); | |
1816 | |
1817 /* | |
1818 * Stay in this state. | |
1819 */ | |
1820 } | |
1821 else | |
1822 { | |
1823 /* | |
1824 * Change the state because there is a flow control primitive | |
1825 * and no packet has been sent. | |
1826 */ | |
1827 link->tx_state = DTI_TX_FLOW; | |
1828 } | |
1829 break; | |
1830 | |
1831 case DTI_TX_BUFFER_FULL: | |
1832 /* | |
1833 * The buffer had been full. Send packets from queue and signal ready | |
1834 */ | |
1835 if(dti_data_ind NEQ NULL) | |
1836 { | |
1837 /* | |
1838 * Select link_id and send data. | |
1839 */ | |
1840 dti_data_ind->link_id = link->link_id; | |
1841 send_data_req_or_ind(hDTI, link, dti_data_ind); | |
1842 /* | |
1843 * Change the state if the queue is ready | |
1844 * to get the next data from the entity | |
1845 */ | |
1846 if(link->queue_len < link->queue_size) | |
1847 { | |
1848 link->tx_state = DTI_TX_IDLE; | |
1849 } | |
1850 } | |
1851 else | |
1852 { | |
1853 /* | |
1854 * Change the state because there is a flow control primitive | |
1855 * and no packet has been sent. | |
1856 */ | |
1857 link->tx_state = DTI_TX_FLOW; | |
1858 } | |
1859 /* | |
1860 * Signal to the callback function that the buffer is ready. | |
1861 */ | |
1862 if((link->connect_state NEQ DTI_CLOSING) AND | |
1863 (link->tx_state NEQ DTI_TX_BUFFER_FULL)) | |
1864 { | |
1865 hDTI->sig_callback(link->instance, | |
1866 link->interfac, | |
1867 link->channel, | |
1868 DTI_REASON_TX_BUFFER_READY, | |
1869 NULL); | |
1870 } | |
1871 break; | |
1872 | |
1873 default: | |
1874 trace_message_link_id(hDTI->handle, | |
1875 "DTI ERROR: Wrong state for flow control primitive", | |
1876 link->link_id, | |
1877 hDTI->entity_options); | |
1878 /* | |
1879 * free whole prim, incl. descs | |
1880 */ | |
1881 if(dti_data_ind NEQ NULL) | |
1882 { | |
1883 mfree_desc(hDTI, (T_desc_list2*) &(dti_data_ind->desc_list2)); | |
1884 PFREE(dti_data_ind); | |
1885 } | |
1886 break; | |
1887 } | |
1888 | |
1889 /* | |
1890 * if the connection is to be closed and the send queue is empty | |
1891 * then close the connection now | |
1892 */ | |
1893 if((link->queue_len EQ 0) AND | |
1894 (link->connect_state EQ DTI_CLOSING)) | |
1895 { | |
1896 send_disconnect_req_or_ind(hDTI, link, DTI_CAUSE_NORMAL_CLOSE); | |
1897 close_link_with_signal(hDTI, link); | |
1898 } | |
1899 } /* flow_control_prim_received() */ | |
1900 | |
1901 | |
1902 | |
1903 /* | |
1904 +--------------------------------------------------------------------------+ | |
1905 | PROJECT : DTILIB MODULE : DTI_KERF | | |
1906 | STATE : code ROUTINE : connect_init_prim_received | | |
1907 +--------------------------------------------------------------------------+ | |
1908 | |
1909 PURPOSE : Process primitives DTI_CONNECT_REQ and DTI_CONNECT_IND | |
1910 received from neighbour DTI | |
1911 */ | |
1912 | |
1913 GLOBAL void connect_init_prim_received (DTI_HANDLE hDTI, | |
1914 U32 link_id, | |
1915 U32 version, | |
1916 U8 direction) | |
1917 { | |
1918 DTI_LINK* link; | |
1919 BOOL send_cnf = FALSE; | |
1920 BOOL send_disc = FALSE; | |
1921 U8 signal = DTI_NO_SIGNAL; | |
1922 | |
1923 trace_function( hDTI->handle, | |
1924 "connect_init_prim_received()", | |
1925 hDTI->entity_options); | |
1926 | |
1927 /* | |
1928 * Check version of peer dtilib | |
1929 */ | |
1930 if(check_dti_version(hDTI, version) EQ FALSE) | |
1931 { | |
1932 trace_message_link_id(hDTI->handle, | |
1933 "DTI ERROR: init_prim - Wrong DTI version", | |
1934 link_id, | |
1935 hDTI->entity_options); | |
1936 /* | |
1937 * Inform peer dtilib that connection failed | |
1938 */ | |
1939 link = get_pointer_link_table(hDTI, link_id, direction); | |
1940 if(link NEQ NULL) | |
1941 { | |
1942 send_disconnect_req_or_ind (hDTI, link, DTI_CAUSE_UNSUPPORTED_VERSION); | |
1943 close_link_with_signal(hDTI, link); | |
1944 } | |
1945 return; | |
1946 } | |
1947 | |
1948 switch (acquire_link (hDTI, link_id, direction, &link) ) | |
1949 { | |
1950 case DTI_S_FOUND: | |
1951 /* | |
1952 * Entry for link_id found, continue connecting procedure | |
1953 */ | |
1954 break; | |
1955 | |
1956 case DTI_S_CREATED_NEW: | |
1957 /* | |
1958 * There is no entry with the requested link_id in the link_table yet. | |
1959 * Wait for call of dti_open(). | |
1960 * The remaining parameters are set in dti_open(). Then the response | |
1961 * primitive will be sent. | |
1962 */ | |
1963 link->connect_state = DTI_CONNECTING; | |
1964 return; | |
1965 | |
1966 default: | |
1967 /* | |
1968 * No free link | |
1969 */ | |
1970 return; | |
1971 } | |
1972 | |
1973 /* | |
1974 * Start up connecting. | |
1975 */ | |
1976 switch (link->connect_state) | |
1977 { | |
1978 case DTI_IDLE: | |
1979 /* | |
1980 * Reset the link and send a response primitive, free the data packets, | |
1981 * and call the callback funktion. | |
1982 */ | |
1983 set_reset_req_para_link_table(hDTI, link); | |
1984 send_cnf = TRUE; | |
1985 signal = DTI_REASON_CONNECTION_OPENED; | |
1986 trace_message_link_id(hDTI->handle, | |
1987 "DTI connection opened", | |
1988 link->link_id, | |
1989 hDTI->entity_options); | |
1990 break; | |
1991 | |
1992 case DTI_SETUP: | |
1993 /* | |
1994 * Collision ! The neighbour entity has sent a dti_connect_ind | |
1995 * primitive as well which means the neighbor enitiy is willing to connect as well. | |
1996 * So we send a response and open the connection. | |
1997 */ | |
1998 link->connect_state = DTI_IDLE; | |
1999 send_cnf = TRUE; | |
2000 signal = DTI_REASON_CONNECTION_OPENED; | |
2001 link->rx_state = DTI_RX_IDLE; | |
2002 trace_message_link_id(hDTI->handle, | |
2003 "DTI connection opened", | |
2004 link->link_id, | |
2005 hDTI->entity_options); | |
2006 break; | |
2007 | |
2008 case DTI_CLOSING: | |
2009 /* | |
2010 * because of the connect request, internal buffers | |
2011 * are being reset. Thus, the send queue is empty now | |
2012 * and the connection can be closed down. | |
2013 * there has to be a confirmation for the connect | |
2014 * primitive anyway | |
2015 */ | |
2016 send_disc = TRUE; | |
2017 send_cnf = TRUE; | |
2018 break; | |
2019 | |
2020 case DTI_CLOSED: | |
2021 /* | |
2022 * dti_open() is not called yet. The confirm primitive will | |
2023 * be sent then and the parameter will be set. | |
2024 */ | |
2025 link->connect_state = DTI_CONNECTING; | |
2026 break; | |
2027 | |
2028 default: | |
2029 trace_message_link_id(hDTI->handle, | |
2030 "DTI ERROR: init_prim - Wrong state dtilib", | |
2031 link_id, | |
2032 hDTI->entity_options); | |
2033 break; | |
2034 } | |
2035 | |
2036 /* | |
2037 * Send the confirm primitive. | |
2038 */ | |
2039 if (send_cnf) | |
2040 { | |
2041 send_connect_res_or_cnf (hDTI, link); | |
2042 } | |
2043 | |
2044 /* | |
2045 * Send the disconnect primitive. | |
2046 */ | |
2047 if (send_disc) | |
2048 { | |
2049 send_disconnect_req_or_ind (hDTI, link, DTI_CAUSE_NORMAL_CLOSE); | |
2050 close_link_with_signal(hDTI, link); | |
2051 /* | |
2052 * No more signals to be sent in this case.. | |
2053 */ | |
2054 return; | |
2055 } | |
2056 | |
2057 /* | |
2058 * Activate callback function with reason_connection_opened | |
2059 * and, additionally, signal tx_buffer_ready if the queue is used. | |
2060 */ | |
2061 if(signal EQ DTI_REASON_CONNECTION_OPENED) | |
2062 { | |
2063 send_open_ready_callback (hDTI, link); | |
2064 } | |
2065 } /* connect_init_prim_received() */ | |
2066 | |
2067 | |
2068 | |
2069 /* | |
2070 +--------------------------------------------------------------------------+ | |
2071 | PROJECT : DTILIB MODULE : DTI_KERF | | |
2072 | STATE : code ROUTINE : connect_confirm_prim_received | | |
2073 +--------------------------------------------------------------------------+ | |
2074 | |
2075 PURPOSE : Process primitives DTI_CONNECT_RES and DTI_CONNECT_CNF | |
2076 received from neighbour DTI | |
2077 */ | |
2078 | |
2079 GLOBAL void connect_confirm_prim_received (DTI_HANDLE hDTI, | |
2080 U32 link_id, | |
2081 U32 version, | |
2082 U8 direction) | |
2083 { | |
2084 DTI_LINK* link; | |
2085 U8 signal = DTI_NO_SIGNAL; | |
2086 | |
2087 trace_function(hDTI->handle, | |
2088 "connect_confirm_prim_received()", | |
2089 hDTI->entity_options); | |
2090 | |
2091 /* | |
2092 * Note: No need to check the version because this has already been done | |
2093 * by the primitives dti_connect_req and dti_connect_ind. | |
2094 */ | |
2095 if((link = get_pointer_link_table(hDTI, link_id, direction)) EQ NULL) | |
2096 { | |
2097 trace_message_link_id(hDTI->handle, | |
2098 "DTI ERROR: cnf_prim - No link in dtilib", | |
2099 link_id, | |
2100 hDTI->entity_options); | |
2101 return; | |
2102 } | |
2103 | |
2104 /* | |
2105 * The link is in the list so check the state. | |
2106 */ | |
2107 switch (link->connect_state) | |
2108 { | |
2109 case DTI_SETUP: | |
2110 /* | |
2111 * The entity can now enter the final state. The entity connection | |
2112 * is established. | |
2113 */ | |
2114 link->connect_state = DTI_IDLE; | |
2115 signal = DTI_REASON_CONNECTION_OPENED; | |
2116 link->rx_state = DTI_RX_IDLE; | |
2117 trace_message_link_id(hDTI->handle, | |
2118 "DTI connection opened", | |
2119 link->link_id, | |
2120 hDTI->entity_options); | |
2121 break; | |
2122 | |
2123 case DTI_CLOSED: | |
2124 case DTI_IDLE: | |
2125 /* | |
2126 * We are already in the final state. So there is nothing to do here. | |
2127 */ | |
2128 break; | |
2129 | |
2130 default: | |
2131 trace_message_link_id(hDTI->handle, | |
2132 "DTI ERROR: cnf_prim - Wrong state dtilib", | |
2133 link_id, | |
2134 hDTI->entity_options); | |
2135 break; | |
2136 } | |
2137 | |
2138 /* | |
2139 * Activate callback function with reason_connection_opened | |
2140 * and, additionally, signal tx_buffer_ready if the queue is used. | |
2141 */ | |
2142 if(signal EQ DTI_REASON_CONNECTION_OPENED) | |
2143 { | |
2144 send_open_ready_callback (hDTI, link); | |
2145 } | |
2146 } /* connect_confirm_prim_received() */ | |
2147 | |
2148 | |
2149 | |
2150 /* | |
2151 +--------------------------------------------------------------------------+ | |
2152 | PROJECT : DTILIB MODULE : DTI_KERF | | |
2153 | STATE : code ROUTINE : disconnect_prim_received | | |
2154 +--------------------------------------------------------------------------+ | |
2155 | |
2156 PURPOSE : Process primitives DTI_DISCONNECT_IND and DTI_DISCONNECT_REQ | |
2157 received from neighbour DTI | |
2158 */ | |
2159 | |
2160 GLOBAL void disconnect_prim_received (DTI_HANDLE hDTI, | |
2161 U32 link_id, | |
2162 U8 direction) | |
2163 { | |
2164 | |
2165 DTI_LINK *link; | |
2166 | |
2167 trace_function(hDTI->handle, | |
2168 "disconnect_prim_received()", | |
2169 hDTI->entity_options); | |
2170 | |
2171 /* | |
2172 * Is the link in the link list ? | |
2173 */ | |
2174 if((link = get_pointer_link_table( | |
2175 hDTI, | |
2176 link_id, | |
2177 direction) | |
2178 ) NEQ NULL) | |
2179 { | |
2180 switch (link->connect_state) | |
2181 { | |
2182 /* | |
2183 * Link is already closed. | |
2184 */ | |
2185 case DTI_CLOSED: | |
2186 trace_message_link_id(hDTI->handle, | |
2187 "DTI link alredy closed", | |
2188 link->link_id, | |
2189 hDTI->entity_options); | |
2190 break; | |
2191 | |
2192 /* | |
2193 * Close the link. | |
2194 */ | |
2195 default: | |
2196 close_link_with_signal(hDTI, link); | |
2197 | |
2198 break; | |
2199 } | |
2200 } | |
2201 | |
2202 } | |
2203 | |
2204 | |
2205 | |
2206 /* | |
2207 +--------------------------------------------------------------------+ | |
2208 | PROJECT : DTILIB MODULE : DTI_KERP | | |
2209 | STATE : code ROUTINE : data_prim_received | | |
2210 +--------------------------------------------------------------------+ | |
2211 | |
2212 * | |
2213 * Process primitives DTI_DATA_REQ and DTI_DATA_IND received from DTI peer | |
2214 */ | |
2215 | |
2216 GLOBAL void data_prim_received(DTI_HANDLE hDTI, | |
2217 T_DTI2_DATA_IND *dti_data_ind, | |
2218 U8 direction) | |
2219 { | |
2220 DTI_LINK *link; | |
2221 U32 link_id; | |
2222 | |
2223 trace_function(hDTI->handle, | |
2224 "data_prim_received()", | |
2225 hDTI->entity_options); | |
2226 | |
2227 /* | |
2228 * Check if old or new SAP is supported. | |
2229 */ | |
2230 link_id = dti_data_ind->link_id; | |
2231 | |
2232 /* | |
2233 * Is the link in the link list ? | |
2234 */ | |
2235 link = get_pointer_link_table(hDTI, link_id, direction); | |
2236 if(link EQ NULL) | |
2237 { | |
2238 /* | |
2239 * The link_id is not in the list of ids. | |
2240 */ | |
2241 trace_message_link_id(hDTI->handle, | |
2242 "DTI ERROR: data_prim - No link in data base", | |
2243 link_id, | |
2244 hDTI->entity_options); | |
2245 /* | |
2246 * Just ignore the received data primitive. | |
2247 */ | |
2248 mfree_desc(hDTI, &dti_data_ind->desc_list2); | |
2249 PFREE(dti_data_ind); | |
2250 return; | |
2251 } | |
2252 /* | |
2253 * If there is no connection silently discard primitive. | |
2254 */ | |
2255 if(link->connect_state NEQ DTI_IDLE) | |
2256 { | |
2257 trace_message_link_id(hDTI->handle, | |
2258 "DTI ERROR: data_prim_received() - link is not connected", | |
2259 link->link_id, | |
2260 hDTI->entity_options); | |
2261 /* | |
2262 * Just ignore the received data primitive. | |
2263 */ | |
2264 mfree_desc(hDTI, &dti_data_ind->desc_list2); | |
2265 PFREE(dti_data_ind); | |
2266 return; | |
2267 } | |
2268 /* | |
2269 * Check if no flow control should be supported. Pass the primitive at once | |
2270 * to the entity over the callback function. | |
2271 */ | |
2272 if(link->link_options EQ DTI_FLOW_CNTRL_DISABLED) | |
2273 { | |
2274 hDTI->sig_callback(link->instance, | |
2275 link->interfac, | |
2276 link->channel, | |
2277 DTI_REASON_DATA_RECEIVED, | |
2278 dti_data_ind); | |
2279 return; | |
2280 } | |
2281 | |
2282 #ifdef FF_TCP_IP | |
2283 /* | |
2284 * Get primitive content in case it is a RIVIERA_ATP_LINK | |
2285 */ | |
2286 if(link->link_type EQ RIVIERA_ATP_LINK) | |
2287 { | |
2288 if((link->rx_state EQ DTI_RX_READY) OR | |
2289 (link->rx_state EQ DTI_RX_STOPPED)) | |
2290 { | |
2291 /* | |
2292 * DTI does not really know if there is data available | |
2293 * In case there is no ATP data the list_len value is set to 0 | |
2294 */ | |
2295 get_data_from_atp(hDTI, link, dti_data_ind); | |
2296 | |
2297 if(dti_data_ind->desc_list2.list_len EQ 0) | |
2298 { | |
2299 /* | |
2300 * there is no data in the ATP buffer any more | |
2301 * so release the primitive and start ATP flow control again | |
2302 */ | |
2303 mfree_desc(hDTI, &dti_data_ind->desc_list2); | |
2304 PFREE (dti_data_ind); | |
2305 TRACE_EVENT("atp_set_signal: ATP_RX_FLOW_ON"); | |
2306 atp_set_signal(hDTI->entity_id_p, | |
2307 link->port_nb, | |
2308 ATP_RX_FLOW_ON, | |
2309 ATP_RX_FLOW_UNMASK); | |
2310 return; | |
2311 } | |
2312 } | |
2313 else | |
2314 { | |
2315 /* | |
2316 * the entity has stopped data flow | |
2317 * currently it is not allowed to receive data | |
2318 */ | |
2319 mfree_desc(hDTI, &dti_data_ind->desc_list2); | |
2320 PFREE (dti_data_ind); | |
2321 return; | |
2322 } | |
2323 } | |
2324 #endif /* FF_TCP_IP */ | |
2325 | |
2326 /* | |
2327 * Handle the states. | |
2328 */ | |
2329 switch(link->rx_state) | |
2330 { | |
2331 case DTI_RX_READY: | |
2332 /* | |
2333 * Receive dti_data_ind, give a signal and send flow control primitive. | |
2334 */ | |
2335 hDTI->sig_callback(link->instance, | |
2336 link->interfac, | |
2337 link->channel, | |
2338 DTI_REASON_DATA_RECEIVED, | |
2339 dti_data_ind); | |
2340 /* | |
2341 * Check if the entity has stoped during the callback. | |
2342 * If yes do not send a flow control. | |
2343 */ | |
2344 if(link->rx_state EQ DTI_RX_READY) | |
2345 { | |
2346 send_ready_req_or_ind(hDTI, link); | |
2347 } | |
2348 else | |
2349 { | |
2350 link->rx_state = DTI_RX_IDLE; | |
2351 } | |
2352 break; | |
2353 | |
2354 case DTI_RX_STOPPED: | |
2355 /* | |
2356 * The entity has stoped the communication but the flow control primitive to | |
2357 * the neighbour entity was sent. The last dti_data_ind signal must be sended | |
2358 * to the entity. DTILIB change to DTI_RX_IDLE. | |
2359 */ | |
2360 link->rx_state = DTI_RX_IDLE; | |
2361 hDTI->sig_callback(link->instance, | |
2362 link->interfac, | |
2363 link->channel, | |
2364 DTI_REASON_DATA_RECEIVED, | |
2365 dti_data_ind); | |
2366 break; | |
2367 | |
2368 default: | |
2369 trace_message_link_id(hDTI->handle, | |
2370 "DTI ERROR: Wrong state for dti_data_ind primitive", | |
2371 link_id, | |
2372 hDTI->entity_options); | |
2373 mfree_desc(hDTI, &dti_data_ind->desc_list2); | |
2374 PFREE (dti_data_ind); | |
2375 break; | |
2376 } | |
2377 } /* data_prim_received() */ | |
2378 | |
2379 | |
2380 | |
2381 #ifdef _SIMULATION_ | |
2382 /* | |
2383 +--------------------------------------------------------------------+ | |
2384 | PROJECT : DTILIB MODULE : DTI_KERP | | |
2385 | STATE : code ROUTINE : data_test_prim_received | | |
2386 +--------------------------------------------------------------------+ | |
2387 | |
2388 PURPOSE : Process primitives DTI_DATA_TEST_REQ and DTI_DATA_TEST_IND | |
2389 received from neighbour DTI | |
2390 */ | |
2391 | |
2392 GLOBAL void data_test_prim_received (DTI_HANDLE hDTI, | |
2393 T_DTI2_DATA_TEST_IND *dti_data_test_ind, | |
2394 U8 direction) | |
2395 { | |
2396 USHORT len_buff, offset, i; | |
2397 T_desc2 *test_desc; | |
2398 | |
2399 trace_function(hDTI->handle, | |
2400 "data_test_prim_received()", | |
2401 hDTI->entity_options); | |
2402 | |
2403 /* | |
2404 * Fill in dti_data_ind the structure. | |
2405 */ | |
2406 { | |
2407 PALLOC (dti_data_ind, DTI2_DATA_IND); | |
2408 | |
2409 dti_data_ind->link_id = dti_data_test_ind->link_id; | |
2410 dti_data_ind->parameters = dti_data_test_ind->parameters; | |
2411 | |
2412 len_buff = dti_data_test_ind->sdu.l_buf>>3; | |
2413 offset = dti_data_test_ind->sdu.o_buf>>3; | |
2414 | |
2415 /* | |
2416 * Build a new desc and fill in the parameter. | |
2417 */ | |
2418 dti_make_new_desc(hDTI, &test_desc, len_buff, TRUE); | |
2419 | |
2420 for(i=0; i < len_buff; i++) | |
2421 test_desc->buffer[i] = dti_data_test_ind->sdu.buf[i+offset]; | |
2422 | |
2423 dti_data_ind->desc_list2.list_len = len_buff; | |
2424 dti_data_ind->desc_list2.first = (ULONG) test_desc; | |
2425 | |
2426 /* | |
2427 * Handle the primitive. | |
2428 */ | |
2429 PFREE (dti_data_test_ind); | |
2430 | |
2431 data_prim_received (hDTI, dti_data_ind, direction); | |
2432 } | |
2433 } | |
2434 | |
2435 #endif /* _SIMULATION_ */ | |
2436 | |
2437 | |
2438 /* | |
2439 +-------------------------------------------------------------------------+ | |
2440 | PROJECT : DTILIB MODULE : DTI_KERF | | |
2441 | STATE : code ROUTINE : vsi_c_psend_ntrace | | |
2442 +-------------------------------------------------------------------------+ | |
2443 | |
2444 * | |
2445 * vsi_c_psend without traces | |
2446 */ | |
2447 | |
2448 #ifdef MEMORY_SUPERVISION | |
2449 GLOBAL SHORT vsi_c_psend_ntrace ( T_HANDLE Caller, T_HANDLE ComHandle, | |
2450 T_VOID_STRUCT *ptr, ULONG MsgLen, const char *file, int line ) | |
2451 #else /* MEMORY_SUPERVISION */ | |
2452 GLOBAL SHORT vsi_c_psend_ntrace ( T_HANDLE Caller, T_HANDLE ComHandle, | |
2453 T_VOID_STRUCT *ptr, ULONG MsgLen ) | |
2454 #endif /* MEMORY_SUPERVISION */ | |
2455 { | |
2456 T_QMSG QMsg; | |
2457 | |
2458 QMsg.Msg.Primitive.Prim = (T_VOID_STRUCT*)(D2P(ptr)); | |
2459 QMsg.Msg.Primitive.PrimLen = MsgLen; | |
2460 QMsg.MsgType = MSG_PRIMITIVE; | |
2461 | |
2462 #ifdef MEMORY_SUPERVISION | |
2463 return ( vsi_c_send ( Caller, ComHandle, &QMsg, file, line) ); | |
2464 #else | |
2465 return ( vsi_c_send ( Caller, ComHandle, &QMsg) ); | |
2466 #endif /* MEMORY_SUPERVISION */ | |
2467 } |