comparison g23m-aci/aci/aci_aci.c @ 0:75a11d740a02

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