comparison g23m/condat/ms/src/aci/aci_aci.c @ 0:509db1a7b7b8

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