comparison src/g23m-aci/aci/aci_aci.c @ 1:d393cd9bb723

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