comparison src/aci2/aci/psa_uartp.c @ 3:93999a60b835

src/aci2, src/condat2: import of g23m/condat source pieces from TCS211
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Sep 2016 00:29:36 +0000
parents
children
comparison
equal deleted inserted replaced
2:c41a534f33c6 3:93999a60b835
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-PS (6147)
4 | Modul : PSA_UARTP
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 : This module defines the processing functions for the
18 | primitives sent to the protocol stack adapter by the DTI
19 | interface.
20 +-----------------------------------------------------------------------------
21 */
22
23 #ifdef UART
24
25 #ifndef PSA_UARTP_C
26 #define PSA_UARTP_C
27 #endif
28
29 #include "aci_all.h"
30
31 /*==== INCLUDES ===================================================*/
32 #include "aci_cmh.h"
33 #include "ati_cmd.h"
34 #include "aci_cmd.h"
35 #include "dti.h" /* functionality of the dti library */
36
37 #include "aci.h"
38 #include "aci_lst.h"
39
40 #include "dti_conn_mng.h"
41 #include "dti_cntrl_mng.h"
42 #include "psa_uart.h"
43 #include "ati_io.h"
44 #include "cmh_uart.h"
45
46 #include "aci_mem.h"
47
48 #include "ati_src_uart.h"
49
50 #include "sap_dti.h"
51
52 /*==== CONSTANTS ==================================================*/
53
54
55 /*==== TYPES ======================================================*/
56
57
58 /*==== EXPORT =====================================================*/
59
60 EXTERN void cmhUART_erase_elem_received_cmd (UBYTE srcId);
61
62 /*==== VARIABLES ==================================================*/
63
64 /*==== FUNCTIONS ==================================================*/
65
66 /* for tracing of establishing of CMD channels for dual port version */
67 #ifdef RMV_15_04_03
68 CHAR gob_tst_buf[80];
69 #endif
70
71 /********** UART related primitives *************************/
72
73 /*
74 +-------------------------------------------------------------------+
75 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
76 | ROUTINE : psa_uart_parameters_cnf |
77 +-------------------------------------------------------------------+
78
79 PURPOSE : .
80
81 */
82
83 GLOBAL const void psa_uart_parameters_cnf( T_UART_PARAMETERS_CNF *uart_parameters_cnf )
84 {
85 TRACE_FUNCTION("psa_uart_parameters_cnf");
86
87 cmhUART_ParmsUpdated( uart_parameters_cnf->device );
88
89 PFREE(uart_parameters_cnf);
90 }
91
92
93 /*
94 +-------------------------------------------------------------------+
95 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
96 | ROUTINE : psa_uart_parameters_ind |
97 +-------------------------------------------------------------------+
98
99 PURPOSE : .
100
101 TODO: set uart_instances parameter for aci here..
102
103 */
104
105 GLOBAL const void psa_uart_parameters_ind( T_UART_PARAMETERS_IND *uart_parameters_ind )
106 {
107 UBYTE i;
108 UBYTE srcId;
109
110 TRACE_FUNCTION("psa_uart_parameters_ind");
111
112 /* for tracing of establishing of CMD channels for dual port version */
113 #ifdef RMV_15_04_03
114 memset (gob_tst_buf, 0, 80);
115 sprintf(gob_tst_buf+strlen(gob_tst_buf), "pi:%d ", uart_parameters_ind->uart_instances);
116 #endif
117
118 /*FF_ATI*/
119 for (i=0;i<uart_parameters_ind->uart_instances;i++)
120 {
121 srcId = uart_new_source (i, UART_DLCI_NOT_MULTIPLEXED);
122 cmhUART_startConnection (srcId, DEVICE_TYPE_URT);
123 }
124
125 PFREE(uart_parameters_ind);
126
127 #if defined (RMV_01_04_03) AND defined (DTI)
128 {
129 /* this is the same as AT%DATA=2,"UART",1,,"SER","UART",0, which is issued by RIL */
130 BOOL rv = dti_cntrl_set_redirect_from_device ((UBYTE)DTI_MODE_PERM,
131 DTI_ENTITY_UART,
132 1,
133 0,
134 DTI_ENTITY_UART,
135 0,
136 0,
137 DTI_CPBLTY_SER,
138 0);
139
140 if (rv EQ TRUE)
141 {
142 TRACE_EVENT("dti_cntrl_set_redirect_from_device returned TRUE");
143 }
144 else
145 {
146 TRACE_EVENT("dti_cntrl_set_redirect_from_device returned FALSE");
147 }
148 }
149 #endif
150 }
151
152
153
154
155 /*
156 +-------------------------------------------------------------------+
157 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
158 | ROUTINE : psa_uart_dti_cnf |
159 +-------------------------------------------------------------------+
160
161 PURPOSE : .
162
163 */
164 GLOBAL const void psa_uart_dti_cnf( T_UART_DTI_CNF *uart_dti_cnf )
165 {
166 T_ACI_LIST *elem = NULL;
167 T_ACI_DTI_PRC *src_infos = NULL;
168 T_DTI_CONN_LINK_ID link_id;
169
170 TRACE_FUNCTION("psa_uart_dti_cnf");
171
172 src_infos = cmhUART_find_dlci (uart_src_params,
173 uart_dti_cnf->device,
174 uart_dti_cnf->dlci);
175
176 /* for tracing of establishing of CMD channels for dual port version */
177 #ifdef RMV_15_04_03
178 sprintf(gob_tst_buf+strlen(gob_tst_buf), "utc:%d ", uart_dti_cnf->device);
179 #endif
180
181 if (src_infos == NULL)
182 {
183 TRACE_EVENT ("psa_uart_dti_cnf: src_infos EQ NULL");
184 PFREE(uart_dti_cnf);
185 return;
186 }
187 #ifdef DTI
188 link_id = dti_cntrl_get_link_id( DTI_ENTITY_UART, uart_dti_cnf->device, uart_dti_cnf->dlci );
189
190 if (uart_dti_cnf->dti_conn EQ UART_DISCONNECT_DTI)
191 {
192 /* tell DTI MNG that connection is closed */
193 dti_cntrl_entity_disconnected( link_id, DTI_ENTITY_UART );
194 }
195 else if (uart_dti_cnf->dti_conn EQ UART_CONNECT_DTI)
196 {
197 /* tell DTI MNG that connection is completed */
198 dti_cntrl_entity_connected( link_id, DTI_ENTITY_UART, DTI_OK );
199 }
200 #endif
201 PFREE(uart_dti_cnf);
202 }
203 /*
204 +---------------------------------------------------------------------+
205 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
206 | ROUTINE : psa_UART_error_IND |
207 +---------------------------------------------------------------------+
208
209 PURPOSE :
210
211 */
212 EXTERN void uart_erase_source( UBYTE srcId );
213
214 GLOBAL const void psa_uart_error_ind( T_UART_ERROR_IND *uart_error_ind )
215 {
216 T_ACI_DTI_PRC *cmd;
217 T_DTI_CONN_LINK_ID link_id;
218 CHAR buf[40];
219
220 TRACE_FUNCTION("psa_uart_error_ind");
221
222 /* for tracing of establishing of CMD channels for dual port version */
223 #ifdef RMV_15_04_03
224 sprintf(gob_tst_buf+strlen(gob_tst_buf), "uei ");
225 #endif
226
227 cmd = cmhUART_find_dlci( uart_src_params,
228 uart_error_ind->device,
229 uart_error_ind->dlci);
230 #ifdef DTI
231 switch( uart_error_ind->error )
232 {
233 case( UART_ERROR_NO_CHANNEL ):
234 sprintf(buf, "Channel number %d cannot be created", cmd->srcId);
235 TRACE_EVENT(buf);
236 link_id = dti_cntrl_get_link_id( DTI_ENTITY_UART, uart_error_ind->device, uart_error_ind->dlci );
237
238 /* tell DTI manager that establishment has failed */
239 dti_cntrl_entity_connected( link_id, DTI_ENTITY_UART, DTI_ERROR);
240 break;
241
242 case( UART_ERROR_MUX_ESTABLISH_FAIL ):
243 case( UART_ERROR_MUX_NO_RESPONSE ):
244 default:
245 TRACE_EVENT("UART_ERROR_IND received with cause other than UART_ERROR_NO_CHANNEL");
246 break;
247 }
248 #endif
249 PFREE(uart_error_ind);
250 }
251
252 /*
253 +---------------------------------------------------------------------+
254 | PROJECT : GSM-PS (6147) MODULE :PSA_UART |
255 | ROUTINE : psa_uart_disable_cnf |
256 +---------------------------------------------------------------------+
257
258 PURPOSE :
259
260 */
261
262 GLOBAL const void psa_uart_disable_cnf(T_UART_DISABLE_CNF *uart_disable_cnf)
263 {
264 TRACE_FUNCTION("psa_uart_disable_cnf");
265
266 PFREE(uart_disable_cnf);
267 }
268
269 /*
270 +---------------------------------------------------------------------+
271 | PROJECT : GSM-PS (6147) MODULE :PSA_UART |
272 | ROUTINE : psa_uart_ring_cnf |
273 +---------------------------------------------------------------------+
274
275 PURPOSE :
276
277 */
278
279 GLOBAL const void psa_uart_ring_cnf(T_UART_RING_CNF *uart_ring_cnf)
280 {
281 T_ACI_DTI_PRC *src_infos = NULL;
282
283 TRACE_FUNCTION("psa_uart_ring_cnf");
284
285 src_infos = cmhUART_find_dlci (uart_src_params,
286 uart_ring_cnf->device,
287 uart_ring_cnf->dlci);
288
289 if (src_infos EQ NULL)
290 {
291 TRACE_EVENT_P2 ("[ERR] psa_uart_ring_cnf: not found: device=%d; dlci=%d",
292 uart_ring_cnf->device, uart_ring_cnf->dlci);
293 }
294 else
295 {
296 BITFIELD_CLEAR (src_infos->data_cntr, UART_RING_RUNNING);
297 }
298 PFREE(uart_ring_cnf);
299 }
300
301 /*
302 +---------------------------------------------------------------------+
303 | PROJECT : GSM-PS (6147) MODULE :PSA_UART |
304 | ROUTINE : psa_uart_dcd_cnf |
305 +---------------------------------------------------------------------+
306
307 PURPOSE :
308
309 */
310
311 GLOBAL const void psa_uart_dcd_cnf(T_UART_DCD_CNF *uart_dcd_cnf )
312 {
313 TRACE_FUNCTION("psa_uart_dcd_cnf");
314
315 PFREE(uart_dcd_cnf);
316 }
317 /*
318 +---------------------------------------------------------------------+
319 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
320 | ROUTINE : psa_uart_escape_cnf |
321 +---------------------------------------------------------------------+
322
323 PURPOSE :
324
325 */
326
327 GLOBAL const void psa_uart_escape_cnf(T_UART_ESCAPE_CNF *uart_escape_cnf )
328 {
329 TRACE_FUNCTION("psa_uart_escape_cnf");
330
331 PFREE(uart_escape_cnf);
332 }
333
334
335 /*
336 +---------------------------------------------------------------------+
337 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
338 | ROUTINE : psa_uart_dti_ind |
339 +---------------------------------------------------------------------+
340
341 PURPOSE :
342
343 this primitive is sent by UART to indicate that a dti-channel has been
344 closed (or opened, theoretically) without previous request from ACI.
345
346 */
347 GLOBAL const void psa_uart_dti_ind( T_UART_DTI_IND
348 *uart_dti_ind )
349 {
350 T_DTI_CONN_LINK_ID link_id = DTI_LINK_ID_NOTPRESENT;
351 T_ACI_DTI_PRC *src_infos = NULL;
352
353 TRACE_FUNCTION("psa_uart_dti_ind");
354
355 src_infos = cmhUART_find_dlci (uart_src_params,
356 uart_dti_ind->device,
357 uart_dti_ind->dlci);
358 #ifdef DTI
359 if (src_infos EQ NULL)
360 {
361 TRACE_EVENT_P2 ("[ERR] psa_uart_dti_ind: not found: device=%d; dlci=%d",
362 uart_dti_ind->device, uart_dti_ind->dlci);
363 }
364 else
365 {
366 link_id = dti_cntrl_get_link_id( DTI_ENTITY_UART, uart_dti_ind->device, uart_dti_ind->dlci );
367
368 if (uart_dti_ind->dti_conn EQ UART_DISCONNECT_DTI)
369 {
370 /* tell DTI MNG that connection is closed */
371 dti_cntrl_entity_disconnected( link_id, DTI_ENTITY_UART );
372
373 }
374 else if (uart_dti_ind->dti_conn EQ UART_CONNECT_DTI)
375 {
376 dti_cntrl_entity_connected( link_id, DTI_ENTITY_UART, DTI_OK );
377 }
378 }
379 #endif
380 PFREE(uart_dti_ind);
381 }
382
383 /*
384 +---------------------------------------------------------------------+
385 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
386 | ROUTINE : psa_uart_detected_ind |
387 +---------------------------------------------------------------------+
388
389 PURPOSE :
390
391 TODO!!!
392
393 */
394
395 GLOBAL const void psa_uart_detected_ind(T_UART_DETECTED_IND *uart_detected_ind )
396 {
397 TRACE_FUNCTION("psa_uart_detected_ind()");
398
399 cmhUART_DetectedESC_DTR ( uart_detected_ind->device,
400 uart_detected_ind->dlci,
401 uart_detected_ind->cause );
402
403 PFREE(uart_detected_ind);
404 }
405
406
407 /********* DTI related prims ****************************/
408
409
410
411
412 /*
413 +-------------------------------------------------------------------+
414 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
415 | ROUTINE : trace_buffer |
416 +-------------------------------------------------------------------+
417
418 PURPOSE :
419
420 */
421 /*
422 LOCAL void trace_buffer (UBYTE *buffer, int len)
423 {
424 char trcBuf[80];
425 char *writeP;
426 int i;
427
428 sprintf (trcBuf, "Buffer Len.: %d", len);
429 TRACE_EVENT (trcBuf);
430
431 writeP = trcBuf;
432 for (i = 0; i < len; i++)
433 {
434 writeP += sprintf (writeP, "%02X ", buffer[i]);
435 }
436 *writeP = '\0';
437 TRACE_EVENT ("===================================================");
438 TRACE_EVENT (trcBuf);
439 TRACE_EVENT ("===================================================");
440 }
441 */
442 /************ MUX related primitives ******************************/
443
444 /*
445 +---------------------------------------------------------------------+
446 | PROJECT : GSM-PS (6147) MODULE :PSA_UART |
447 | ROUTINE : psa_uart_mux_start_cnf |
448 +---------------------------------------------------------------------+
449
450 PURPOSE :
451
452 */
453
454 GLOBAL const void psa_uart_mux_start_cnf(T_UART_MUX_START_CNF *uart_mux_start_cnf)
455 {
456 TRACE_FUNCTION("psa_uart_mux_start_cnf");
457
458 PFREE(uart_mux_start_cnf);
459 }
460
461 /*
462 +---------------------------------------------------------------------------------+
463 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
464 | ROUTINE : psa_uart_mux_dlc_establish_ind |
465 +---------------------------------------------------------------------------------+
466
467 PURPOSE : New dlci channel created... Device multiplexed.
468
469 */
470
471 GLOBAL const void psa_uart_mux_dlc_establish_ind
472 ( T_UART_MUX_DLC_ESTABLISH_IND *uart_mux_dlc_establish_ind )
473 {
474 UBYTE srcId;
475 T_ACI_DTI_PRC *cmd;
476 BOOL Need_New_Source;
477
478 TRACE_FUNCTION("psa_uart_mux_dlc_establish_ind");
479
480 /* send response to UART */
481 psaUART_MuxRes(uart_mux_dlc_establish_ind->device,
482 uart_mux_dlc_establish_ind->dlci,
483 uart_mux_dlc_establish_ind->n1);
484
485 /* search if it is the first multiplexed channel to be established for this
486 particular device */
487 cmd = cmhUART_find_dlci (uart_src_params,
488 uart_mux_dlc_establish_ind->device,
489 UART_DLCI_NOT_MULTIPLEXED);
490
491 if (cmd EQ NULL)
492 /* means device has not been found: may (possibly ??) happen if some errors_ind
493 from UART have lead to erasing all previous sources of the device */
494 Need_New_Source = TRUE;
495 else if (cmd->dlci NEQ UART_DLCI_NOT_MULTIPLEXED)
496 /* then a new source is needed
497 (device aready has multiplexed channels) */
498 Need_New_Source = TRUE;
499 else
500 Need_New_Source = FALSE;
501
502 #ifdef DTI
503 /* create new source */
504 if( Need_New_Source )
505 {
506 srcId = uart_new_source( uart_mux_dlc_establish_ind->device,
507 uart_mux_dlc_establish_ind->dlci );
508
509 cmd = find_element (uart_src_params, srcId, cmhUARTtest_srcId);
510 if (cmd EQ NULL)
511 {
512 TRACE_EVENT_P1("[ERR] psa_uart_mux_dlc_establish_ind: "
513 "srcId=%d not found", srcId) ;
514 return ;
515 }
516 /* start new uart dti channel */
517 cmhUART_startConnection (srcId, DEVICE_TYPE_MUX);
518 }
519 else /* use previous one */
520 {
521 T_DTI_ENTITY_ID entity_list[] = {DTI_ENTITY_ACI};
522
523 srcId = cmd->srcId;
524 uart_InitCmdStruct( cmd );
525 cmd->dlci = uart_mux_dlc_establish_ind->dlci;
526 cmd->LineState = LINE_CONNECTING;
527 cmhUART_ChangeDeviceType (srcId, DEVICE_TYPE_MUX);
528
529 dti_cntrl_est_dpath_indirect ( srcId,
530 entity_list,
531 1,
532 SPLIT,
533 atiUART_dti_cb,
534 DTI_CPBLTY_CMD,
535 DTI_CID_NOTPRESENT);
536
537 dti_cntrl_change_sub_no(srcId, uart_mux_dlc_establish_ind->dlci);
538 }
539 #endif
540
541 PFREE(uart_mux_dlc_establish_ind);
542 }
543
544
545 /*
546 +---------------------------------------------------------------------------------+
547 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
548 | ROUTINE : psa_uart_mux_dlc_release_ind |
549 +---------------------------------------------------------------------------------+
550
551 PURPOSE :
552
553 */
554 GLOBAL const void psa_uart_mux_dlc_release_ind( T_UART_MUX_DLC_RELEASE_IND *uart_mux_dlc_release_ind )
555 {
556 T_ACI_DTI_PRC *cmd;
557 CHAR buf[40];
558
559 TRACE_FUNCTION("psa_uart_mux_dlc_release_ind");
560
561 cmd = cmhUART_find_dlci (uart_src_params,
562 uart_mux_dlc_release_ind->device,
563 uart_mux_dlc_release_ind->dlci);
564
565 sprintf(buf,"Channel number %d cannot be created",cmd->srcId);
566 TRACE_EVENT(buf);
567
568 uart_erase_source (cmd->srcId);
569 cmhUART_erase_elem_received_cmd (cmd->srcId);
570 PFREE(uart_mux_dlc_release_ind);
571 }
572
573 /*
574 +---------------------------------------------------------------------------------+
575 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
576 | ROUTINE : psa_uart_mux_close_ind |
577 +---------------------------------------------------------------------------------+
578
579 PURPOSE :
580
581 */
582 GLOBAL const void psa_uart_mux_close_ind( T_UART_MUX_CLOSE_IND *uart_mux_close_ind )
583 {
584 T_ACI_DTI_PRC *cmd;
585 UBYTE srcId;
586
587 TRACE_FUNCTION("psa_uart_mux_close_ind");
588
589 TRACE_EVENT_P1("MUX closed on device number: %d", uart_mux_close_ind->device);
590
591 do
592 {
593 cmd = cmhUART_find_dlci (uart_src_params,
594 uart_mux_close_ind->device,
595 UART_DLCI_NOT_MULTIPLEXED);
596
597 if( cmd EQ NULL )
598 break;
599
600 TRACE_EVENT_P1("Mux Channel with src id %d was released", cmd->srcId);
601
602 uart_erase_source( cmd->srcId );
603 cmhUART_erase_elem_received_cmd( cmd->srcId );
604
605 } while( TRUE );
606
607
608
609 /* reconnect device to uart in non-MUX mode */
610 srcId = uart_new_source( uart_mux_close_ind->device, UART_DLCI_NOT_MULTIPLEXED );
611
612 /* start uart dti channel */
613 cmhUART_startConnection (srcId, DEVICE_TYPE_URT);
614
615 PFREE(uart_mux_close_ind);
616 }
617
618 #endif /* UART */