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