comparison src/g23m-aci/aci/aci_aci.c @ 162:53929b40109c

src/g23m-aci: initial import from TCS3.2/LoCosto
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 11 Oct 2016 02:02:43 +0000
parents
children ab79cf3c29a5
comparison
equal deleted inserted replaced
161:4557e2a9c18e 162:53929b40109c
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-F&D (8411)
4 | Modul : ACI
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 Modul holds the main functions
18 | for the AT Command Interpreter
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef ACI_ACI_C
23 #define ACI_ACI_C
24
25 #include "aci_all.h"
26
27 #include "aci_cmh.h"
28 #ifdef _SIMULATION_
29 #include "dti.h"
30 #include "dti_conn_mng.h"
31
32 #ifdef UART
33 #include "psa_uart.h"
34 #endif
35
36 #ifdef FF_PSI
37 #include "psa_psi.h"
38 #endif /*FF_PSI*/
39 #include "ati_src_tst.h"
40 #endif
41
42 #ifdef FAX_AND_DATA
43 #include "aci_fd.h"
44 #endif /* of #ifdef FAX_AND_DATA */
45
46
47 #include "psa.h"
48 #include "psa_cc.h"
49 #include "cmh.h"
50 #include "cmh_cc.h"
51 #include "aci_lst.h"
52 #include "ati_cmd.h"
53 #include "ati_ext_mech.h"
54
55 #ifdef FF_ATI
56 #include "aci_io.h"
57 #endif
58
59 #ifdef FAX_AND_DATA
60 #include "psa_ra.h"
61 #include "cmh_ra.h"
62 #endif /* of #ifdef FAX_AND_DATA */
63
64 #ifdef BT_ADAPTER
65 #include "dti.h"
66
67 #include "bti.h"
68 #include "bti_int.h"
69 #include "bti_aci.h"
70 #include "ati_src_bt.h"
71 #endif
72
73
74 #ifdef FF_ATI_BAT
75 #include "p_bat.h"
76 #include "aci_bat.h"
77 #ifdef _SIMULATION_
78 #include "line_edit.h"
79 #include "ati_bat.h"
80 #endif
81 #endif
82
83
84 /*===== EXPORT =====================================================*/
85 /*===== PRIVATE ====================================================*/
86
87 /*===== VARIABLES ==================================================*/
88 T_ACI_CMD_MODE _mode=CMD_MODE_NONE;
89 UBYTE srcId_cb;
90 GLOBAL BOOL _g_ati_trc_enabled = FALSE;
91
92 /* 0 (CMD_SRC_LCL) are reserved */
93 GLOBAL USHORT used_sources = 1;
94
95 /*===== EXTERNALS ==================================================*/
96 #ifndef LOCOSTO_LITE_2_54_COMPILER_ERROR
97 EXTERN T_ACI_LIST *ati_src_list;
98 #endif
99
100 /*===== FUNCTIONS ==================================================*/
101
102 /*
103 +--------------------------------------------------------------------+
104 | PROJECT : GSM-F&D (8411) MODULE : ACI |
105 | STATE : code ROUTINE : aci_aci_cmd_req |
106 +--------------------------------------------------------------------+
107
108 PURPOSE : handle ACI command request primitive. It is only a
109 signal and must not be freed by PFREE.
110
111 */
112
113 GLOBAL void aci_aci_cmd_req (T_ACI_CMD_REQ *cmd)
114 {
115 TRACE_FUNCTION("aci_aci_cmd_req()");
116
117 #ifdef FF_ATI
118 if ( cmd->cmd_len < MAX_TRC_LEN )
119 {
120 cmd->cmd_seq[cmd->cmd_len] = '\0';
121 TRACE_EVENT_P1 ("%s", cmd->cmd_seq);
122 }
123 #ifdef DTI
124 #ifdef _SIMULATION_
125 if (cmd->cmd_src >= CMD_SRC_EXT AND cmd->cmd_src <= MAX_TST_SRC)
126 {
127 #ifdef FF_ATI_BAT
128 U8 src_id = tst_src_id[cmd->cmd_src - 1];
129 #endif
130 ati_src_tst_proc_cmd (cmd);
131 #ifdef FF_ATI_BAT
132 if (aci_cmd_src_mode_get(src_id) EQ CMD_MODE_BAT) /* simulation with BAT library */
133 {
134 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, src_id, search_ati_src_id);
135 T_ACI_DTI_PRC_PSI *src_infos_psi = find_element (psi_src_params, src_id, cmhPSItest_srcId);
136 while (ledit_ctrl(src_params->src_id,LEDIT_CTRL_MORE_CMDS, NULL) EQ LEDIT_CMPL)
137 {
138 ati_bat_response_simulation(&(src_infos_psi->res)); /* intermediate response */
139 }
140 if (src_params->cmd_state NEQ CMD_IDLE)
141 {
142 if (src_infos_psi->res.response AND (src_params->curAtCmd NEQ AT_CMD_CMGS))
143 {
144 ati_bat_response_simulation(&(src_infos_psi->res)); /* final response */
145 Perform_ati_bat_maint(src_id);
146 }
147 src_infos_psi->bat_client[src_infos_psi->active_client].curCmd = (T_BAT_ctrl_params)-1;
148 }
149 }
150 #endif /* FF_ATI_BAT */
151 }
152 else
153 {
154 TRACE_EVENT_P1 ("aci_aci_cmd_req(): [WRN] srcId=%d, but must be 0x01 or 0x02", cmd->cmd_src);
155 }
156 #endif /* _SIMULATION_ */
157 #endif /* DTI */
158 #endif
159
160 PFREE (cmd);
161
162 }
163
164 /*
165 +--------------------------------------------------------------------+
166 | PROJECT : GSM-F&D (8411) MODULE : ACI |
167 | STATE : code ROUTINE : aci_aci_cmd_req |
168 +--------------------------------------------------------------------+
169
170 PURPOSE : handle ACI command request primitive. It is only a
171 signal and must not be freed by PFREE.
172
173 */
174 #ifdef BT_ADAPTER
175 GLOBAL void aci_aci_cmd_req_bt (T_ACI_CMD_REQ_BT *cmd)
176 {
177 TRACE_FUNCTION("aci_aci_cmd_req_bt()");
178
179 #ifdef FF_ATI
180 if ( cmd->cmd_len <= 80 )
181 {
182 if( !strchr((char *)cmd->cmd_seq,'%'))
183 TRACE_EVENT ((char *)cmd->cmd_seq);
184 }
185
186 if (cmd->cmd_src EQ CMD_SRC_EXT)
187 {
188 ati_src_bt_proc_cmd(cmd);
189 }
190
191 #endif
192 PFREE(cmd);
193 }
194 #endif /* BT_ADAPTER */
195
196 /*
197 +--------------------------------------------------------------------+
198 | PROJECT : GSM-F&D (8411) MODULE : ACI |
199 | STATE : code ROUTINE : aci_aci_abort_req |
200 +--------------------------------------------------------------------+
201
202 PURPOSE : handle aci data mode abort request
203
204 */
205
206 GLOBAL void aci_aci_abort_req (T_ACI_ABORT_REQ *aci_abort_req)
207 {
208 #ifndef LOCOSTO_LITE_2_54_COMPILER_ERROR
209 EXTERN void aciAbort (UBYTE srcId);
210 #endif
211
212 UBYTE srcId;
213
214 TRACE_FUNCTION ("aci_aci_abort_req()");
215
216 srcId = aci_abort_req->cmd_src;
217
218 #ifdef DTI
219 #ifdef _SIMULATION_
220 if (srcId >= CMD_SRC_EXT AND srcId <= MAX_TST_SRC)
221 {
222 ati_src_tst_abort(srcId);
223 return;
224 }
225 #endif /* _SIMULATION_ */
226 #endif /* DTI */
227
228 #ifndef LOCOSTO_LITE_2_54_COMPILER_ERROR
229 if (aci_abort_req->cause EQ ABT_ABORT_CMD)
230 aciAbort (srcId);
231 #endif
232
233 #ifdef FAX_AND_DATA
234 if (aci_abort_req->cause EQ ABT_ABORT_DATA)
235 cmhRA_Escape ();
236 #endif
237
238 #ifdef BT_ADAPTER
239 btiaci_at_abort_res(srcId);
240 #endif /* BT_ADAPTER */
241
242 PFREE (aci_abort_req);
243
244 }
245
246
247 /*
248 +--------------------------------------------------------------------+
249 | PROJECT : GSM-F&D (8411) MODULE : ACI |
250 | STATE : code ROUTINE : aci_aci_abort_req |
251 +--------------------------------------------------------------------+
252
253 PURPOSE : handle aci (data mode) abort request for BT
254
255 */
256 #ifdef BT_ADAPTER
257 GLOBAL void aci_aci_abort_req_bt (T_ACI_ABORT_REQ_BT *aci_abort_req)
258 {
259 /* EXTERN void aciAbort (UBYTE srcId);*/
260
261 UBYTE srcId;
262
263 TRACE_FUNCTION ("aci_aci_abort_req_bt()");
264
265 srcId = aci_abort_req->src_id;
266
267 #ifndef LOCOSTO_LITE_2_54_COMPILER_ERROR
268 if (aci_abort_req->cause EQ ABT_ABORT_CMD)
269 aciAbort (srcId);
270 #endif
271
272 #ifdef FAX_AND_DATA
273 if (aci_abort_req->cause EQ ABT_ABORT_DATA)
274 cmhRA_Escape ();
275 #endif
276
277 btiaci_at_abort_res(get_port_by_srcID(srcId));
278
279
280 PFREE (aci_abort_req);
281
282 }
283 #endif /* BT_ADAPTER */
284
285 #ifdef FF_ATI
286
287 GLOBAL UBYTE aci_init (T_ATI_SRC_TYPE src_type)
288 {
289 int i;
290 UBYTE tst_src;
291
292 TRACE_FUNCTION ("aci_init ()");
293
294 #ifdef _SIMULATION_
295 if (src_type EQ ATI_SRC_TYPE_TST)
296 {
297 for (i = (CMD_SRC_MAX-1); i >= 0; i--)
298 {
299 tst_src = (0x01 << i) & used_sources;
300 if (!tst_src)
301 break;
302 }
303 if (tst_src)
304 {
305 return (0);
306 }
307
308 used_sources |= (0x01 << i);
309 return (UBYTE) (i);
310 }
311 #endif
312
313 for (i = 0; i < CMD_SRC_MAX; i++)
314 {
315 tst_src = (0x01 << i) & used_sources;
316 if (!tst_src)
317 break;
318 }
319 if (tst_src)
320 {
321 TRACE_EVENT_P1("No more sources available ! used_sources: %04X", used_sources);
322 return (0);
323 }
324 used_sources |= (0x01 << i);
325
326 if (src_type EQ ATI_SRC_TYPE_BLUETOOTH)
327 {
328 used_sources |= (0x01 << (i + 8));
329 }
330
331 TRACE_EVENT_P2("New source %d ! used_sources: %04X", i, used_sources);
332 return (i);
333 }
334
335 #endif /* FF_ATI */
336
337 GLOBAL void aci_finit (UBYTE src_id)
338 {
339 UBYTE tst_src;
340
341 TRACE_FUNCTION ("aci_finit ()");
342
343 tst_src = 0x01 << src_id;
344 if (!(used_sources & tst_src))
345 {
346 TRACE_EVENT ("[ERR] aci_finit(): invalid source");
347 return;
348 }
349 used_sources = used_sources & ~tst_src;
350
351 /* for BT */
352 tst_src = 0x01 << (src_id + 8);
353 used_sources = used_sources & ~tst_src;
354 }
355
356
357 #ifdef BT_ADAPTER
358 /*
359 +--------------------------------------------------------------------+
360 | PROJECT : GSM-F&D (8411) MODULE : ACI |
361 | STATE : code ROUTINE : aci_aci_cmd_res |
362 +--------------------------------------------------------------------+
363
364 PURPOSE : handle aci_cmd_res
365
366 */
367
368 GLOBAL void aci_aci_cmd_res (T_ACI_CMD_RES *aci_cmd_res)
369 {
370 TRACE_FUNCTION ("aci_aci_cmd_res()");
371
372 /*
373 This is currently just ignored !
374 Actually ACI_CMD_RES is an acknowledgement for ACI_CMD_IND. It should
375 be used to determine if an ACI_CMD_IND may be sent. After sending one
376 ACI_CMD_IND should wait for ACI_CMD_RES before another ACI_CMD_IND may
377 be sent. This behaviour shall be implemented later.
378 */
379 PFREE (aci_cmd_res);
380
381 }
382 /*
383 +--------------------------------------------------------------------+
384 | PROJECT : GSM-F&D (8411) MODULE : ACI |
385 | STATE : code ROUTINE : aci_aci_cmd_res |
386 +--------------------------------------------------------------------+
387
388 PURPOSE : handle aci_cmd_res_bt
389
390 */
391
392 GLOBAL void aci_aci_cmd_res_bt (T_ACI_CMD_RES_BT *aci_cmd_res)
393 {
394
395 ULONG port_nb;
396 T_ATI_BT_OUTPUT *cur_cmd;
397
398 TRACE_FUNCTION ("aci_aci_cmd_res()");
399
400 /*
401 This is currently just ignored !
402 Actually ACI_CMD_RES is an acknowledgement for ACI_CMD_IND. It should
403 be used to determine if an ACI_CMD_IND may be sent. After sending one
404 ACI_CMD_IND should wait for ACI_CMD_RES before another ACI_CMD_IND may
405 be sent. This behaviour shall be implemented later.
406 */
407
408 port_nb = get_port_by_srcID(aci_cmd_res->src_id);
409 PFREE (aci_cmd_res);
410
411 if (bti_port_table[port_nb].atqueue EQ NULL)
412 {
413 bti_port_table[port_nb].at_flow_on = TRUE;
414 TRACE_EVENT("BTA queue empty");
415 return;
416 }
417
418 cur_cmd = bti_port_table[port_nb].atqueue;
419
420 if (cur_cmd->output_type & ATI_BT_CONFIRM_COMMAND)
421 {
422 TRACE_EVENT("BTA confirm in queue");
423 bti_port_table[port_nb].atqueue = cur_cmd->next;
424
425 btiaci_at_cmd_res(port_nb, (char *)(cur_cmd->output));
426 MFREE(cur_cmd);
427
428 if (bti_port_table[port_nb].atqueue EQ NULL)
429 {
430 TRACE_EVENT("BTA queue empty");
431 bti_port_table[port_nb].at_flow_on = TRUE;
432 return;
433 }
434 else
435 {
436 cur_cmd = bti_port_table[port_nb].atqueue;
437 }
438 }
439
440 if ((cur_cmd->output_type & ATI_BT_NORMAL_COMMAND) ||
441 (cur_cmd->output_type & ATI_BT_INDICATION_COMMAND))
442 {
443 TRACE_EVENT("BTA command in queue");
444 bti_port_table[port_nb].at_flow_on = FALSE;
445
446 bti_port_table[port_nb].atqueue = cur_cmd->next;
447
448 TRACE_EVENT_P1("sending %s", cur_cmd->output);
449 btiaci_at_cmd_req(port_nb, (char *)(cur_cmd->output));
450 MFREE(cur_cmd);
451
452 #ifdef _SIMULATION_
453 cur_cmd = bti_port_table[port_nb].atqueue;
454 while (cur_cmd->next NEQ NULL) /* search end of queue */
455 {
456 TRACE_EVENT_P1("in queue: %s", cur_cmd->output); /* just for debugging */
457 cur_cmd = cur_cmd->next;
458 }
459 #endif
460
461 }
462 return;
463 }
464
465 /*
466 +--------------------------------------------------------------------+
467 | PROJECT : GSM-F&D (8411) MODULE : ACI |
468 | STATE : code ROUTINE : aci_aci_init_res |
469 +--------------------------------------------------------------------+
470
471 PURPOSE : handle aci_init_res
472
473 */
474
475 GLOBAL void aci_aci_init_res (T_ACI_INIT_RES *aci_init_res)
476 {
477 TRACE_FUNCTION ("aci_aci_init_res()");
478
479 PFREE (aci_init_res);
480 }
481
482 /*
483 +--------------------------------------------------------------------+
484 | PROJECT : GSM-F&D (8411) MODULE : ACI |
485 | STATE : code ROUTINE : aci_aci_deinit_req |
486 +--------------------------------------------------------------------+
487
488 PURPOSE : handle aci_deinit_req
489
490 */
491
492 GLOBAL void aci_aci_deinit_req (T_ACI_DEINIT_REQ *aci_deinit_req)
493 {
494 TRACE_FUNCTION ("aci_aci_deinit_req()");
495
496 io_closePort(0);
497
498 btiaci_at_deinit_res();
499
500 PFREE (aci_deinit_req);
501 }
502
503 /*
504 +--------------------------------------------------------------------+
505 | PROJECT : GSM-F&D (8411) MODULE : ACI |
506 | STATE : code ROUTINE : aci_aci_open_port_req|
507 +--------------------------------------------------------------------+
508
509 PURPOSE : handle aci_open_port_req
510
511 */
512
513 GLOBAL void aci_aci_open_port_req (T_ACI_OPEN_PORT_REQ *aci_open_port_req)
514 {
515 ULONG port;
516 T_BTI_ACK result;
517
518 TRACE_FUNCTION ("aci_aci_open_port_req()");
519
520 port = aci_open_port_req->port_nb;
521
522 result = io_openPort(port);
523
524 PFREE (aci_open_port_req);
525
526 btiaci_at_open_port_res(port, result);
527 }
528
529 /*
530 +--------------------------------------------------------------------+
531 | PROJECT : GSM-F&D (8411) MODULE : ACI |
532 | STATE : code ROUTINE : aci_aci_close_port_req|
533 +--------------------------------------------------------------------+
534
535 PURPOSE : handle aci_close_port_req
536
537 */
538
539 GLOBAL void aci_aci_close_port_req (T_ACI_CLOSE_PORT_REQ *aci_close_port_req)
540 {
541 ULONG port;
542
543 TRACE_FUNCTION ("aci_aci_close_port_req()");
544
545 port = aci_close_port_req->port_nb;
546
547 io_closePort(port);
548
549 PFREE (aci_close_port_req);
550
551 btiaci_at_close_port_res(port);
552 }
553
554 #endif /* BT_ADAPTER */
555
556 /*
557 +--------------------------------------------------------------------+
558 | PROJECT : GSM-F&D (8411) MODULE : ACI |
559 | STATE : code ROUTINE : aci_aci_trc_ind |
560 +--------------------------------------------------------------------+
561
562 PURPOSE : This function call is only relevant for the acia_adater. The acia_adapter
563 sends for every AT-cmd a psignal to aci (task switch).
564
565 */
566 #ifdef FF_MMI_RIV
567
568 EXTERN void acia_callback_for_ACI (void *AT_command_ptr);
569
570 GLOBAL void aci_aci_riv_cmd_req (T_ACI_RIV_CMD_REQ *cmd_ptr)
571 {
572 TRACE_FUNCTION ("aci_aci_riv_cmd_req()");
573
574 acia_callback_for_ACI ((void *)cmd_ptr);
575 }
576 #endif /* FF_MMI_RIV */
577
578 /*
579 +--------------------------------------------------------------------+
580 | PROJECT : GSM-F&D (8411) MODULE : ACI |
581 | STATE : code ROUTINE : aci_aci_trc_ind |
582 +--------------------------------------------------------------------+
583
584 PURPOSE : handle ACI trace indication primitive.
585
586 */
587
588 GLOBAL void aci_aci_trc_ind (T_ACI_TRC_IND *trc_ind)
589 {
590 T_ATI_SRC_PARAMS *src_params;
591
592 TRACE_FUNCTION("aci_aci_trc_ind()");
593
594 if (!_g_ati_trc_enabled)
595 {
596 PFREE (trc_ind);
597 return;
598 }
599
600 trc_ind->trc_buf[MAX_TRC_LEN-1] = '\0';
601
602 #ifdef FF_ATI
603 if ( trc_ind->trc_len >= MAX_TRC_LEN )
604 {
605 UBYTE c;
606 c = trc_ind->trc_buf[MAX_TRC_LEN-1];
607 trc_ind->trc_buf[MAX_TRC_LEN-1] = '\0';
608 TRACE_EVENT_P1 ("%s", trc_ind->trc_buf);
609 trc_ind->trc_buf[MAX_TRC_LEN-1] = c;
610 }
611 else
612 {
613 TRACE_EVENT_P1 ("%s", trc_ind->trc_buf);
614 }
615 #endif /* FF_ATI */
616 #ifndef LOCOSTO_LITE_2_54_COMPILER_ERROR
617 /* check if the src is valid */
618 src_params = find_element (ati_src_list, trc_ind->cmd_src, search_ati_src_id);
619 #ifdef FF_PSI
620 if ((src_params EQ NULL) OR ((src_params->src_type NEQ ATI_SRC_TYPE_UART) AND
621 (src_params->src_type NEQ ATI_SRC_TYPE_PSI)))
622 #else
623 if ((src_params EQ NULL) OR (src_params->src_type NEQ ATI_SRC_TYPE_UART))
624 #endif /*FF_PSI*/
625 {
626 src_params = get_next_element (ati_src_list, NULL);/* first element */
627 while (src_params NEQ NULL)
628 {
629 #ifdef FF_PSI
630 if (src_params->src_type EQ ATI_SRC_TYPE_UART OR src_params->src_type EQ ATI_SRC_TYPE_PSI)
631 #else
632 if (src_params->src_type EQ ATI_SRC_TYPE_UART)
633 #endif /*FF_PSI*/
634 {
635 break;
636 }
637 src_params = get_next_element (ati_src_list, src_params);
638 }
639 }
640
641 if (src_params NEQ NULL)
642 {
643 io_sendIndication(src_params->src_id, (CHAR *)trc_ind->trc_buf, ATI_FORCED_OUTPUT);
644 }
645 #endif /* LOCOSTO_LITE_2_54_COMPILER_ERROR */
646 PFREE (trc_ind);
647 }
648
649
650 /*
651 +--------------------------------------------------------------------+
652 | PROJECT : GSM-F&D (8411) MODULE : ACI |
653 | STATE : code ROUTINE : aci_aci_ext_ind |
654 +--------------------------------------------------------------------+
655
656 PURPOSE : handle ACI extension signal indication primitive.
657
658 */
659
660 GLOBAL void aci_aci_ext_ind (T_ACI_EXT_IND *aci_ext_ind)
661 {
662 TRACE_FUNCTION ("aci_aci_ext_ind()");
663 #ifndef LOCOSTO_LITE_2_54_COMPILER_ERROR
664 rEXT_Signal (aci_ext_ind);
665 #endif
666 PFREE (aci_ext_ind);
667 }
668
669
670
671 #endif /* ACI_ACI_C */