comparison gsm-fw/g23m-aci/aci/psa_uartp.c @ 775:eedbf248bac0

gsm-fw/g23m-aci subtree: initial import from LoCosto source
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 12 Oct 2014 01:45:14 +0000
parents
children d988f0f6aeb9
comparison
equal deleted inserted replaced
774:40a721fd9854 775:eedbf248bac0
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 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 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 void psa_uart_dti_cnf( T_UART_DTI_CNF *uart_dti_cnf )
165 {
166 T_ACI_DTI_PRC *src_infos = NULL;
167 T_DTI_CONN_LINK_ID link_id;
168
169 TRACE_FUNCTION("psa_uart_dti_cnf");
170
171 src_infos = cmhUART_find_dlci (uart_src_params,
172 uart_dti_cnf->device,
173 uart_dti_cnf->dlci);
174
175 /* for tracing of establishing of CMD channels for dual port version */
176 #ifdef RMV_15_04_03
177 sprintf(gob_tst_buf+strlen(gob_tst_buf), "utc:%d ", uart_dti_cnf->device);
178 #endif
179
180 if (src_infos == NULL)
181 {
182 TRACE_EVENT ("psa_uart_dti_cnf: src_infos EQ NULL");
183 PFREE(uart_dti_cnf);
184 return;
185 }
186 #ifdef DTI
187 link_id = dti_cntrl_get_link_id( DTI_ENTITY_UART, uart_dti_cnf->device, uart_dti_cnf->dlci );
188
189 if (uart_dti_cnf->dti_conn EQ UART_DISCONNECT_DTI)
190 {
191 /* tell DTI MNG that connection is closed */
192 dti_cntrl_entity_disconnected( link_id, DTI_ENTITY_UART );
193 }
194 else if (uart_dti_cnf->dti_conn EQ UART_CONNECT_DTI)
195 {
196 /* tell DTI MNG that connection is completed */
197 dti_cntrl_entity_connected( link_id, DTI_ENTITY_UART, DTI_OK );
198 }
199 #endif
200 PFREE(uart_dti_cnf);
201 }
202 /*
203 +---------------------------------------------------------------------+
204 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
205 | ROUTINE : psa_UART_error_IND |
206 +---------------------------------------------------------------------+
207
208 PURPOSE :
209
210 */
211 EXTERN void uart_erase_source( UBYTE srcId );
212
213 GLOBAL void psa_uart_error_ind( T_UART_ERROR_IND *uart_error_ind )
214 {
215 T_ACI_DTI_PRC *cmd;
216 T_DTI_CONN_LINK_ID link_id;
217 CHAR buf[40];
218
219 TRACE_FUNCTION("psa_uart_error_ind");
220
221 /* for tracing of establishing of CMD channels for dual port version */
222 #ifdef RMV_15_04_03
223 sprintf(gob_tst_buf+strlen(gob_tst_buf), "uei ");
224 #endif
225
226 cmd = cmhUART_find_dlci( uart_src_params,
227 uart_error_ind->device,
228 uart_error_ind->dlci);
229 #ifdef DTI
230 switch( uart_error_ind->error )
231 {
232 case( UART_ERROR_NO_CHANNEL ):
233 sprintf(buf, "Channel number %d cannot be created", cmd->srcId);
234 TRACE_EVENT(buf);
235 link_id = dti_cntrl_get_link_id( DTI_ENTITY_UART, uart_error_ind->device, uart_error_ind->dlci );
236
237 /* tell DTI manager that establishment has failed */
238 dti_cntrl_entity_connected( link_id, DTI_ENTITY_UART, DTI_ERROR);
239 break;
240
241 case( UART_ERROR_MUX_ESTABLISH_FAIL ):
242 case( UART_ERROR_MUX_NO_RESPONSE ):
243 default:
244 TRACE_EVENT("UART_ERROR_IND received with cause other than UART_ERROR_NO_CHANNEL");
245 break;
246 }
247 #endif
248 PFREE(uart_error_ind);
249 }
250
251 /*
252 +---------------------------------------------------------------------+
253 | PROJECT : GSM-PS (6147) MODULE :PSA_UART |
254 | ROUTINE : psa_uart_disable_cnf |
255 +---------------------------------------------------------------------+
256
257 PURPOSE :
258
259 */
260
261 GLOBAL void psa_uart_disable_cnf(T_UART_DISABLE_CNF *uart_disable_cnf)
262 {
263 TRACE_FUNCTION("psa_uart_disable_cnf");
264
265 PFREE(uart_disable_cnf);
266 }
267
268 /*
269 +---------------------------------------------------------------------+
270 | PROJECT : GSM-PS (6147) MODULE :PSA_UART |
271 | ROUTINE : psa_uart_ring_cnf |
272 +---------------------------------------------------------------------+
273
274 PURPOSE :
275
276 */
277
278 GLOBAL void psa_uart_ring_cnf(T_UART_RING_CNF *uart_ring_cnf)
279 {
280 T_ACI_DTI_PRC *src_infos = NULL;
281
282 TRACE_FUNCTION("psa_uart_ring_cnf");
283
284 src_infos = cmhUART_find_dlci (uart_src_params,
285 uart_ring_cnf->device,
286 uart_ring_cnf->dlci);
287
288 if (src_infos EQ NULL)
289 {
290 TRACE_EVENT_P2 ("[ERR] psa_uart_ring_cnf: not found: device=%d; dlci=%d",
291 uart_ring_cnf->device, uart_ring_cnf->dlci);
292 }
293 else
294 {
295 BITFIELD_CLEAR (src_infos->data_cntr, UART_RING_RUNNING);
296 }
297 PFREE(uart_ring_cnf);
298 }
299
300 /*
301 +---------------------------------------------------------------------+
302 | PROJECT : GSM-PS (6147) MODULE :PSA_UART |
303 | ROUTINE : psa_uart_dcd_cnf |
304 +---------------------------------------------------------------------+
305
306 PURPOSE :
307
308 */
309
310 GLOBAL void psa_uart_dcd_cnf(T_UART_DCD_CNF *uart_dcd_cnf )
311 {
312 TRACE_FUNCTION("psa_uart_dcd_cnf");
313
314 PFREE(uart_dcd_cnf);
315 }
316 /*
317 +---------------------------------------------------------------------+
318 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
319 | ROUTINE : psa_uart_escape_cnf |
320 +---------------------------------------------------------------------+
321
322 PURPOSE :
323
324 */
325
326 GLOBAL void psa_uart_escape_cnf(T_UART_ESCAPE_CNF *uart_escape_cnf )
327 {
328 TRACE_FUNCTION("psa_uart_escape_cnf");
329
330 PFREE(uart_escape_cnf);
331 }
332
333
334 /*
335 +---------------------------------------------------------------------+
336 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
337 | ROUTINE : psa_uart_dti_ind |
338 +---------------------------------------------------------------------+
339
340 PURPOSE :
341
342 this primitive is sent by UART to indicate that a dti-channel has been
343 closed (or opened, theoretically) without previous request from ACI.
344
345 */
346 GLOBAL void psa_uart_dti_ind( T_UART_DTI_IND
347 *uart_dti_ind )
348 {
349 T_DTI_CONN_LINK_ID link_id = DTI_LINK_ID_NOTPRESENT;
350 T_ACI_DTI_PRC *src_infos = NULL;
351
352 TRACE_FUNCTION("psa_uart_dti_ind");
353
354 src_infos = cmhUART_find_dlci (uart_src_params,
355 uart_dti_ind->device,
356 uart_dti_ind->dlci);
357 #ifdef DTI
358 if (src_infos EQ NULL)
359 {
360 TRACE_EVENT_P2 ("[ERR] psa_uart_dti_ind: not found: device=%d; dlci=%d",
361 uart_dti_ind->device, uart_dti_ind->dlci);
362 }
363 else
364 {
365 link_id = dti_cntrl_get_link_id( DTI_ENTITY_UART, uart_dti_ind->device, uart_dti_ind->dlci );
366
367 if (uart_dti_ind->dti_conn EQ UART_DISCONNECT_DTI)
368 {
369 /* tell DTI MNG that connection is closed */
370 dti_cntrl_entity_disconnected( link_id, DTI_ENTITY_UART );
371
372 }
373 else if (uart_dti_ind->dti_conn EQ UART_CONNECT_DTI)
374 {
375 dti_cntrl_entity_connected( link_id, DTI_ENTITY_UART, DTI_OK );
376 }
377 }
378 #endif
379 PFREE(uart_dti_ind);
380 }
381
382 /*
383 +---------------------------------------------------------------------+
384 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
385 | ROUTINE : psa_uart_detected_ind |
386 +---------------------------------------------------------------------+
387
388 PURPOSE :
389
390 TODO!!!
391
392 */
393
394 GLOBAL void psa_uart_detected_ind(T_UART_DETECTED_IND *uart_detected_ind )
395 {
396 TRACE_FUNCTION("psa_uart_detected_ind()");
397
398 cmhUART_DetectedESC_DTR ( uart_detected_ind->device,
399 uart_detected_ind->dlci,
400 uart_detected_ind->cause );
401
402 PFREE(uart_detected_ind);
403 }
404
405
406 /********* DTI related prims ****************************/
407
408
409
410
411 /*
412 +-------------------------------------------------------------------+
413 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
414 | ROUTINE : trace_buffer |
415 +-------------------------------------------------------------------+
416
417 PURPOSE :
418
419 */
420 /*
421 LOCAL void trace_buffer (UBYTE *buffer, int len)
422 {
423 char trcBuf[80];
424 char *writeP;
425 int i;
426
427 sprintf (trcBuf, "Buffer Len.: %d", len);
428 TRACE_EVENT (trcBuf);
429
430 writeP = trcBuf;
431 for (i = 0; i < len; i++)
432 {
433 writeP += sprintf (writeP, "%02X ", buffer[i]);
434 }
435 *writeP = '\0';
436 TRACE_EVENT ("===================================================");
437 TRACE_EVENT (trcBuf);
438 TRACE_EVENT ("===================================================");
439 }
440 */
441 /************ MUX related primitives ******************************/
442
443 /*
444 +---------------------------------------------------------------------+
445 | PROJECT : GSM-PS (6147) MODULE :PSA_UART |
446 | ROUTINE : psa_uart_mux_start_cnf |
447 +---------------------------------------------------------------------+
448
449 PURPOSE :
450
451 */
452
453 GLOBAL void psa_uart_mux_start_cnf(T_UART_MUX_START_CNF *uart_mux_start_cnf)
454 {
455 TRACE_FUNCTION("psa_uart_mux_start_cnf");
456
457 PFREE(uart_mux_start_cnf);
458 }
459
460 /*
461 +---------------------------------------------------------------------------------+
462 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
463 | ROUTINE : psa_uart_mux_dlc_establish_ind |
464 +---------------------------------------------------------------------------------+
465
466 PURPOSE : New dlci channel created... Device multiplexed.
467
468 */
469
470 GLOBAL void psa_uart_mux_dlc_establish_ind
471 ( T_UART_MUX_DLC_ESTABLISH_IND *uart_mux_dlc_establish_ind )
472 {
473 UBYTE srcId;
474 T_ACI_DTI_PRC *cmd;
475 BOOL Need_New_Source;
476
477 TRACE_FUNCTION("psa_uart_mux_dlc_establish_ind");
478
479 /* send response to UART */
480 psaUART_MuxRes(uart_mux_dlc_establish_ind->device,
481 uart_mux_dlc_establish_ind->dlci,
482 uart_mux_dlc_establish_ind->n1);
483
484 /* search if it is the first multiplexed channel to be established for this
485 particular device */
486 cmd = cmhUART_find_dlci (uart_src_params,
487 uart_mux_dlc_establish_ind->device,
488 UART_DLCI_NOT_MULTIPLEXED);
489
490 if (cmd EQ NULL)
491 /* means device has not been found: may (possibly ??) happen if some errors_ind
492 from UART have lead to erasing all previous sources of the device */
493 Need_New_Source = TRUE;
494 else if (cmd->dlci NEQ UART_DLCI_NOT_MULTIPLEXED)
495 /* then a new source is needed
496 (device aready has multiplexed channels) */
497 Need_New_Source = TRUE;
498 else
499 Need_New_Source = FALSE;
500
501 #ifdef DTI
502 /* create new source */
503 if( Need_New_Source )
504 {
505 srcId = uart_new_source( uart_mux_dlc_establish_ind->device,
506 uart_mux_dlc_establish_ind->dlci );
507
508 cmd = find_element (uart_src_params, srcId, cmhUARTtest_srcId);
509 if (cmd EQ NULL)
510 {
511 TRACE_EVENT_P1("[ERR] psa_uart_mux_dlc_establish_ind: "
512 "srcId=%d not found", srcId) ;
513 return ;
514 }
515 /* start new uart dti channel */
516 cmhUART_startConnection (srcId, DEVICE_TYPE_MUX);
517 }
518 else /* use previous one */
519 {
520 T_DTI_ENTITY_ID entity_list[] = {DTI_ENTITY_ACI};
521
522 /*lint -e613 (Warning --Possible use of null pointer) */
523 srcId = cmd->srcId;
524 uart_InitCmdStruct( cmd );
525 cmd->dlci = uart_mux_dlc_establish_ind->dlci;
526 cmd->LineState = LINE_CONNECTING;
527 /*lint +e613 (Warning --Possible use of null pointer) */
528
529 cmhUART_ChangeDeviceType (srcId, DEVICE_TYPE_MUX);
530
531 dti_cntrl_est_dpath_indirect ( srcId,
532 entity_list,
533 1,
534 SPLIT,
535 atiUART_dti_cb,
536 DTI_CPBLTY_CMD,
537 DTI_CID_NOTPRESENT);
538
539 dti_cntrl_change_sub_no(srcId, uart_mux_dlc_establish_ind->dlci);
540 }
541
542 #endif
543
544 PFREE(uart_mux_dlc_establish_ind);
545 }
546
547
548 /*
549 +---------------------------------------------------------------------------------+
550 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
551 | ROUTINE : psa_uart_mux_dlc_release_ind |
552 +---------------------------------------------------------------------------------+
553
554 PURPOSE :
555
556 */
557 GLOBAL void psa_uart_mux_dlc_release_ind( T_UART_MUX_DLC_RELEASE_IND *uart_mux_dlc_release_ind )
558 {
559 T_ACI_DTI_PRC *cmd;
560 CHAR buf[40];
561
562 TRACE_FUNCTION("psa_uart_mux_dlc_release_ind");
563
564 cmd = cmhUART_find_dlci (uart_src_params,
565 uart_mux_dlc_release_ind->device,
566 uart_mux_dlc_release_ind->dlci);
567
568 sprintf(buf,"Channel number %d cannot be created",cmd->srcId);
569 TRACE_EVENT(buf);
570
571 uart_erase_source (cmd->srcId);
572 cmhUART_erase_elem_received_cmd (cmd->srcId);
573 PFREE(uart_mux_dlc_release_ind);
574 }
575
576 /*
577 +---------------------------------------------------------------------------------+
578 | PROJECT : GSM-PS (6147) MODULE : PSA_UART |
579 | ROUTINE : psa_uart_mux_close_ind |
580 +---------------------------------------------------------------------------------+
581
582 PURPOSE :
583
584 */
585 GLOBAL void psa_uart_mux_close_ind( T_UART_MUX_CLOSE_IND *uart_mux_close_ind )
586 {
587 T_ACI_DTI_PRC *cmd;
588 UBYTE srcId;
589
590 TRACE_FUNCTION("psa_uart_mux_close_ind");
591
592 TRACE_EVENT_P1("MUX closed on device number: %d", uart_mux_close_ind->device);
593
594 do
595 {
596 cmd = cmhUART_find_dlci (uart_src_params,
597 uart_mux_close_ind->device,
598 UART_DLCI_NOT_MULTIPLEXED);
599
600 if( cmd EQ NULL )
601 break;
602
603 TRACE_EVENT_P1("Mux Channel with src id %d was released", cmd->srcId);
604
605 uart_erase_source( cmd->srcId );
606 cmhUART_erase_elem_received_cmd( cmd->srcId );
607
608 } while( TRUE );
609
610
611
612 /* reconnect device to uart in non-MUX mode */
613 srcId = uart_new_source( uart_mux_close_ind->device, UART_DLCI_NOT_MULTIPLEXED );
614
615 /* start uart dti channel */
616 cmhUART_startConnection (srcId, DEVICE_TYPE_URT);
617
618 PFREE(uart_mux_close_ind);
619 }
620
621 #endif /* UART */