comparison g23m/condat/ms/src/aci/ati_src_bt.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
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : BLUETOOTH
4 | Modul : ATI_SRC_BT_C
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 : .
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifndef ATI_SRC_BT_C
22 #define ATI_SRC_BT_C
23 #endif
24
25 #include "aci_all.h"
26
27 /*==== INCLUDES ===================================================*/
28 #include "aci_cmh.h"
29 #include "ati_cmd.h"
30 #include "aci_cmd.h"
31
32 #include "aci_lst.h"
33 #include "dti.h"
34 #include "dti_conn_mng.h"
35 #include "psa_uart.h"
36 #include "ati_io.h"
37 #include "cmh_uart.h"
38 #include "aci_io.h"
39 #include "aci_mem.h"
40
41 #if defined (BT_ADAPTER)
42 #include "bti_aci.h"
43 #include "bti_int.h"
44 #endif
45
46
47 #include "ati_src_bt.h"
48
49 /*==== CONSTANTS ==================================================*/
50 /*#ifdef GPRS
51 #define MAX_LARGE_BUFFER_LEN (600)
52 #define MAX_BUFFER_COUNT (15)
53 #else
54 #define MAX_LARGE_BUFFER_LEN (400)
55 #ifdef FAX_AND_DATA
56 #define MAX_BUFFER_COUNT (27)
57 #else
58 #define MAX_BUFFER_COUNT (7)
59 #endif
60 #endif
61 */
62 /*==== TYPES ======================================================*/
63
64 /*==== EXPORT =====================================================*/
65
66 /*==== VARIABLES ==================================================*/
67
68 /*==== FUNCTIONS ==================================================*/
69
70 T_BTI_AT_RING_TYPE get_bti_ring_type(T_ACI_CRING_TYP t);
71 T_BTI_AT_DCE_SIGNAL get_bti_ring_state(T_IO_DCD_STAT s);
72 T_BTI_AT_DCE_SIGNAL get_bti_dcd_state(T_IO_DCD_STAT s);
73
74 /*
75 +--------------------------------------------------------------------+
76 | PROJECT : BLUETOOTH 8445 MODULE : ACI_URT |
77 | STATE : code ROUTINE : io_openPort |
78 +--------------------------------------------------------------------+
79
80 PURPOSE: opens an external port
81
82 */
83 GLOBAL T_BTI_ACK io_openPort (T_BTI_PORT_NB port)
84 {
85 TRACE_EVENT("io_openPort()");
86
87 if ((port >= MAX_PORTS) || (port < 0)) /* if requested port number is higher than available ports (including 0) -> fail*/
88 return BTI_NAK;
89
90 if (bti_port_table[port].aci_src_id != 0) /* port already used */
91 return BTI_NAK;
92
93 bti_port_table[port].aci_src_id = ati_init(ATI_SRC_TYPE_BLUETOOTH, bt_src_result_cb, bt_src_line_state_cb);
94
95 TRACE_EVENT_P2("port %d aci_src_id %d", port, bti_port_table[port].aci_src_id);
96
97 if (bti_port_table[port].aci_src_id == 0) /* failed to get aci src id */
98 return BTI_NAK;
99
100 dti_mng_new (bti_port_table[port].aci_src_id, bti_port_table[port].aci_src_id,
101 bt_src_dti_cb, TRUE, DTI_MNG_DEVICE_TYPE_BT, DTI_MNG_DATA_TYPE_CMD);
102
103 bti_port_table[port].dti_data_ind_BTI = NULL;
104 bti_port_table[port].data_offset = 0;
105 bti_port_table[port].data_left = 0;
106 bti_port_table[port].bti_gsm_port_info.optimal_gsm_max_packet_size = 0;
107 bti_port_table[port].bti_bt_port_info.optimal_bt_max_packet_size = 0;
108 bti_port_table[port].atqueue = NULL;
109 bti_port_table[port].large_at_output = FALSE;
110 bti_port_table[port].at_flow_on = TRUE;
111
112 return BTI_ACK;
113 }
114
115 /*
116 +--------------------------------------------------------------------+
117 | PROJECT : BLUETOOTH 8445 MODULE : ACI_URT |
118 | STATE : code ROUTINE : io_closePort |
119 +--------------------------------------------------------------------+
120
121 PURPOSE: closes an external port
122
123 */
124 GLOBAL void io_closePort (T_BTI_PORT_NB port)
125 {
126 TRACE_EVENT("io_closePort()");
127 ati_finit(bti_port_table[port].aci_src_id);
128
129 bti_port_table[port].aci_src_id = 0;
130 bti_port_table[port].dti_data_ind_BTI = NULL;
131 bti_port_table[port].data_offset = 0;
132 bti_port_table[port].data_left = 0;
133 bti_port_table[port].bti_gsm_port_info.optimal_gsm_max_packet_size = 0;
134 bti_port_table[port].bti_bt_port_info.optimal_bt_max_packet_size = 0;
135 bti_port_table[port].atqueue = NULL;
136 bti_port_table[port].large_at_output = FALSE;
137 bti_port_table[port].at_flow_on = TRUE;
138 }
139
140
141
142 /*
143 +--------------------------------------------------------------------+
144 | PROJECT : BLUETOOTH 8445 MODULE : ACI_URT |
145 | STATE : code ROUTINE : get_bti_ring_type |
146 +--------------------------------------------------------------------+
147
148 PURPOSE: converting ACI type to BTI type
149 */
150 T_BTI_AT_RING_TYPE get_bti_ring_type(T_ACI_CRING_TYP t)
151 {
152 switch (t)
153 {
154 case CRING_TYP_NotPresent:
155 return BTI_AT_RING_NotPresent;
156 case CRING_TYP_Async:
157 return BTI_AT_RING_Async;
158 case CRING_TYP_Sync:
159 return BTI_AT_RING_Sync;
160 case CRING_TYP_RelAsync:
161 return BTI_AT_RING_RelAsync;
162 case CRING_TYP_RelSync:
163 return BTI_AT_RING_RelSync;
164 case CRING_TYP_Fax:
165 return BTI_AT_RING_Fax;
166 case CRING_TYP_Voice:
167 return BTI_AT_RING_Voice;
168 case CRING_TYP_AuxVoice:
169 return BTI_AT_RING_AuxVoice;
170 #ifdef GPRS
171 case CRING_TYP_GPRS:
172 return BTI_AT_RING_GPRS;
173 #endif /* GPRS */
174
175 }
176 return BTI_AT_RING_NotPresent;
177 }
178
179 /*
180 +--------------------------------------------------------------------+
181 | PROJECT : BLUETOOTH 8445 MODULE : ACI_URT |
182 | STATE : code ROUTINE : get_bti_ring_state |
183 +--------------------------------------------------------------------+
184
185 PURPOSE: converting ACI type to BTI type
186 */
187 T_BTI_AT_DCE_SIGNAL get_bti_ring_state(T_IO_RING_STAT s)
188 {
189 switch (s)
190 {
191 case IO_RING_OFF:
192 TRACE_EVENT ("V.24 RING OFF");
193 return BTI_AT_RING_OFF;
194
195 case IO_RING_ON:
196 TRACE_EVENT ("V.24 RING ON");
197 return BTI_AT_RING_ON;
198 }
199 }
200
201 /*
202 +--------------------------------------------------------------------+
203 | PROJECT : BLUETOOTH 8445 MODULE : ACI_URT |
204 | STATE : code ROUTINE : get_bti_dcd_state |
205 +--------------------------------------------------------------------+
206
207 PURPOSE: converting ACI type to BTI type
208 */
209 T_BTI_AT_DCE_SIGNAL get_bti_dcd_state(T_IO_DCD_STAT s)
210 {
211 switch (s)
212 {
213 case IO_DCD_OFF:
214 TRACE_EVENT ("V.24 DCD OFF");
215 return BTI_AT_DCD_OFF;
216
217 case IO_DCD_ON:
218 TRACE_EVENT ("V.24 DCD ON");
219 return BTI_AT_DCD_ON;
220 }
221 }
222
223 /*
224 +--------------------------------------------------------------------+
225 | PROJECT : BLUETOOTH 8445 MODULE : ACI_URT |
226 | STATE : code ROUTINE : ati_src_bt_proc_cmd|
227 +--------------------------------------------------------------------+
228
229 PURPOSE:
230
231 */
232
233 GLOBAL BOOL ati_src_bt_proc_cmd (T_ACI_CMD_REQ_BT *cmd)
234 {
235 TRACE_FUNCTION ("ati_src_bt_proc_cmd ()");
236 return (ati_execute (cmd->src_id, cmd->cmd_seq, cmd->cmd_len));
237 }
238
239 /*
240 +-------------------------------------------------------------------+
241 | PROJECT : BLUETOOTH 8445 MODULE : PSA_UART |
242 | ROUTINE : bt_src_connect |
243 +-------------------------------------------------------------------+
244
245 PURPOSE :
246
247 */
248 GLOBAL T_ACI_RETURN bt_src_connect (UBYTE srcId, T_DTI_ENTITY_ID unit)
249 {
250 T_BTI_PORT_NB port_nb;
251
252 TRACE_EVENT("bt_src_connect()");
253
254 port_nb = get_port_by_srcID(srcId);
255
256 TRACE_EVENT_P3("port %d src_id %d unit %d", port_nb, bti_port_table[port_nb].aci_src_id, unit);
257
258 dti_entity_connected(srcId, CONNECTED, UNIT_BLUETOOTH);
259
260 return AT_CMPL;
261 }
262
263 /*
264 +-------------------------------------------------------------------+
265 | PROJECT : BLUETOOTH 8445 MODULE : PSA_UART |
266 | ROUTINE : bt_src_disconnect |
267 +-------------------------------------------------------------------+
268
269 PURPOSE :
270
271 */
272 GLOBAL T_ACI_RETURN bt_src_disconnect (UBYTE srcId)
273 {
274 T_BTI_PORT_NB port_nb;
275
276 port_nb = get_port_by_srcID(srcId);
277
278 return AT_CMPL;
279 }
280
281 /*
282 +-------------------------------------------------------------------+
283 | PROJECT : BLUETOOTH 8445 MODULE : PSA_UART |
284 | ROUTINE : bt_enqueue_command |
285 +-------------------------------------------------------------------+
286
287 PURPOSE :
288
289 */
290 GLOBAL void bt_enqueue_command(T_BTI_PORT_NB port_nb, UBYTE *output, USHORT output_len, UBYTE type)
291 {
292 T_ATI_BT_OUTPUT *cur_cmd;
293 T_ATI_BT_OUTPUT *queue_end;
294 int len;
295
296 TRACE_EVENT_P2("bt_enqueue_command() %d %s",type, output);
297
298 len = output_len + sizeof(T_ATI_BT_OUTPUT);
299 ACI_MALLOC(cur_cmd, len);
300
301 cur_cmd->output_len = output_len;
302 cur_cmd->output_type = type;
303 cur_cmd->next = NULL;
304 memcpy (cur_cmd->output, output, output_len);
305 cur_cmd->output[output_len] = 0;
306
307 if (bti_port_table[port_nb].atqueue == NULL) /* Queue is empty */
308 {
309 bti_port_table[port_nb].atqueue = cur_cmd;
310 }
311 else /* There are already pending commands */
312 {
313 queue_end = bti_port_table[port_nb].atqueue;
314 len = 1; /* just for debugging */
315
316 #ifdef _SIMULATION_
317 // TRACE_EVENT_P1("content: %s", queue_end->output); /* just for debugging */
318 #endif
319
320 while (queue_end->next != NULL) /* search end of queue */
321 {
322 queue_end = queue_end->next;
323 len++; /* just for debugging */
324 #ifdef _SIMULATION_
325 // TRACE_EVENT_P1("content: %s", queue_end->output); /* just for debugging */
326 #endif
327 }
328 TRACE_EVENT_P1("elements in queue: %d", len); /* just for debugging */
329 queue_end->next = cur_cmd;
330 }
331 return;
332 }
333
334
335 /*
336 +-------------------------------------------------------------------+
337 | PROJECT : BLUETOOTH 8445 MODULE : PSA_UART |
338 | ROUTINE : bt_set_output_type |
339 +-------------------------------------------------------------------+
340
341 PURPOSE :
342
343 */
344 GLOBAL UBYTE bt_set_output_type(T_ATI_OUTPUT_TYPE t)
345 {
346 if (IS_CONFIRM_OUTPUT(t))
347 return ATI_BT_CONFIRM_COMMAND;
348 if (IS_NORMAL_OUTPUT(t))
349 return ATI_BT_NORMAL_COMMAND;
350 if (IS_INDICATION_OUTPUT(t))
351 return ATI_BT_INDICATION_COMMAND;
352
353 TRACE_EVENT("ATI_BT unexpected output type");
354 }
355
356 /*==== CALLBACKS ==================================================*/
357
358 /*
359 +--------------------------------------------------------------------+
360 | PROJECT : BLUETOOTH 8445 MODULE : ACI_URT |
361 | STATE : code ROUTINE : bt_src_result_cb |
362 +--------------------------------------------------------------------+
363
364 PURPOSE:
365
366 */
367 GLOBAL void bt_src_result_cb (UBYTE src_id,
368 T_ATI_OUTPUT_TYPE output_type,
369 UBYTE *output,
370 USHORT output_len)
371 {
372 ULONG port_nb;
373
374 port_nb = get_port_by_srcID(src_id);
375
376 TRACE_EVENT_P1("bt_src_result_cb() pt: %d", port_nb);
377
378 /* just for test purposes */
379 TRACE_EVENT((char*)output);
380
381 /* first check, if we are allowed to send */
382 if (bti_port_table[port_nb].at_flow_on == FALSE)
383 {
384 TRACE_EVENT("bt_src_result_cb() commands pending");
385 bt_enqueue_command(port_nb, output, output_len, bt_set_output_type(output_type));
386 return;
387 }
388
389 /* kk 010808
390 * according to RIE NORMAL_OUTPUT and CONFIRM_OUTPUT is mutual exclusive
391 * but this is not the case in the current implementation
392 * addionally INDICATION_OUTPUT is never set
393 * temporary solution is to check for CONFIRM first then exit if applicable
394 * else check for NORMAL_OUTPUT and assume that this is also INDICATION
395 * NEEDS FIX from RIE
396 */
397 if (IS_CONFIRM_OUTPUT(output_type))
398 {
399 TRACE_EVENT("bt_src_result_cb() confirm sent");
400 btiaci_at_cmd_res(port_nb, (char *)output);
401 return;
402 }
403
404 /* kk 010808
405 * according to RIE NORMAL_OUTPUT and CONFIRM_OUTPUT is mutual exclusive
406 * but this is not the case in the current implementation
407 * addionally INDICATION_OUTPUT is never set
408 * temporary solution is to check for CONFIRM first then exit if applicable
409 * else check for NORMAL_OUTPUT and assume that this is also INDICATION
410 * NEEDS FIX from RIE
411 */
412 if (IS_NORMAL_OUTPUT(output_type) OR IS_INDICATION_OUTPUT(output_type) OR IS_ECHO_OUTPUT(output_type))
413 {
414 TRACE_EVENT("bt_src_result_cb() indication/normal sent");
415 bti_port_table[port_nb].at_flow_on = FALSE;
416 btiaci_at_cmd_req(port_nb, (char *)output);
417 return;
418 }
419
420 TRACE_EVENT("bt_src_result_cb() SOMETHING IS WRONG HERE");
421 }
422
423 /*
424 +--------------------------------------------------------------------+
425 | PROJECT : BLUETOOTH 8445 MODULE : ACI_URT |
426 | STATE : code ROUTINE : bt_src_line_state_cb
427 +--------------------------------------------------------------------+
428
429 PURPOSE:
430
431 */
432 GLOBAL void bt_src_line_state_cb (UBYTE src_id,
433 T_ATI_LINE_STATE_TYPE line_state_type,
434 ULONG line_state_param)
435 {
436
437 T_BTI_AT_RING_TYPE bt1, bt2;
438 T_BTI_AT_DCE_SIGNAL signal;
439 T_BTI_PORT_NB port_nb;
440
441 T_IO_RING_PARAMS *ring;
442 T_IO_DCD_STAT *dcd;
443
444 port_nb = get_port_by_srcID(src_id);
445
446 TRACE_EVENT_P1("bt_src_line_state_cb() pt: %d", port_nb);
447
448 switch (line_state_type)
449 {
450 case ATI_LINE_STATE_RNG:
451 TRACE_EVENT("line state RING");
452
453 ring = (T_IO_RING_PARAMS *)line_state_param;
454
455 bt1 = get_bti_ring_type(ring->b_cap_1);
456 bt2 = get_bti_ring_type(ring->b_cap_2);
457 signal = get_bti_ring_state(ring->ring_stat);
458
459 btiaci_at_signal_change_req(port_nb, signal, bt1, bt2);
460 break;
461
462 case ATI_LINE_STATE_DCD:
463 TRACE_EVENT("line state DCD");
464
465 dcd = (T_IO_DCD_STAT *)line_state_param;
466 signal = get_bti_dcd_state(*dcd);
467 btiaci_at_signal_change_req(port_nb, signal, BTI_AT_RING_NotPresent, BTI_AT_RING_NotPresent);
468 break;
469
470 case ATI_LINE_STATE_OUTPUT_TYPE:
471 /*src_infos->run_cmd = TRUE;*/
472 /*src_infos->first_output = TRUE;*/
473
474 if( line_state_param EQ ATI_OUTPUT_TYPE_LARGE )
475 {
476 TRACE_EVENT("large output following");
477 bti_port_table[port_nb].large_at_output = TRUE;
478 }
479 else
480 {
481 TRACE_EVENT("normal output following");
482 bti_port_table[port_nb].large_at_output = FALSE;
483 }
484 break;
485
486 default:
487 TRACE_EVENT("line state NO TYPE");
488 break;
489 }
490 }
491
492
493
494 /*
495 +-------------------------------------------------------------------+
496 | PROJECT : BLUETOOTH 8445 MODULE : PSA_UART |
497 | ROUTINE : bt_src_dti_cb |
498 +-------------------------------------------------------------------+
499
500 PURPOSE : callback for dti manager.
501
502 */
503
504 GLOBAL BOOL bt_src_dti_cb( UBYTE srcId, T_DTI_MNG_CB_TYPE result_type )
505 {
506 TRACE_FUNCTION("bt_src_dti_cb()");
507
508 switch(result_type)
509 {
510 case(CB_TYPE_CONNECTED):
511 TRACE_EVENT_P1("srcID %d connected", srcId);
512 break;
513
514 case(CB_TYPE_TMP_RECONNECTED):
515 TRACE_EVENT_P1("srcID %d reconnected", srcId);
516 break;
517
518 case(CB_TYPE_NEW_CONNECTED):
519 TRACE_EVENT_P1("srcID %d new connected", srcId);
520 break;
521
522 case(CB_TYPE_TMP_DISCONNECTING):
523 TRACE_EVENT_P1("srcID %d disconnecting", srcId);
524 break;
525
526 case(CB_TYPE_TMP_DISCONNECTED):
527 TRACE_EVENT_P1("srcID %d disconnected", srcId);
528 break;
529
530 case(CB_TYPE_ERROR):
531 TRACE_EVENT_P1("srcID %d ERROR", srcId);
532
533 /* connection failed */
534 //kk srcInfos->LineState = LINE_TMP_DISCONNECTED;
535 //k dti_mng_owner_connect(srcId, UNIT_UART);
536 break;
537
538 default:
539 break;
540 }
541
542 return TRUE;
543 }
544