comparison src/g23m-aci/aci/aci_bat_ext.c @ 1:fa8dc04885d8

src/g23m-*: import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:25:50 +0000
parents
children
comparison
equal deleted inserted replaced
0:4e78acac3d88 1:fa8dc04885d8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-F&D (8411)
4 | Modul : ACI_BAT
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 file consists of the BAT Extension Mechanism
18 |
19 +-----------------------------------------------------------------------------
20 */
21 /*==== INCLUDES ===================================================*/
22 #include "aci_all.h"
23 #include "aci_mem.h"
24 #include "aci_cmh.h"
25 #include "ati_cmd.h"
26 #include "dti.h" /* functionality of the dti library */
27
28 #include "aci.h"
29 #include "aci_lst.h"
30
31 #include "psa_psi.h"
32 #include "cmh_psi.h"
33 #include "ati_src_psi.h"
34 #include "sap_dti.h"
35 #include "psa.h"
36 #include "cmh.h"
37
38 #include "aci_bat_cmh.h"
39 #include "aci_bat.h"
40 #include "aci_bat_err.h"
41 #include "aci_bat_cb.h" /* for rBAT_OK */
42
43 #include "ati_ext_mech.h"
44 #include "aci_bat_ext.h"
45
46
47 #include "l2p_types.h"
48 #include "l2p.h"
49 #include "bat_ctrl.h"
50 #include "aci_cmd.h"
51
52 #ifdef _SIMULATION_
53 #include "gdd_aci.h"
54 #endif
55
56 typedef struct
57 {
58 U8 ati_custom_src_id; /* ATI source, which handles the custom cmd/rsp */
59 U8 bat_custom_src_id; /* BAT source, which is the peer to ATI source */
60 } T_aci_bat_ext_globs;
61
62
63 T_aci_bat_ext_globs aci_bat_ext_globs = {0xFF, 0xFF};
64
65
66 /*
67 * The very first cutom AT command has no peer. So find it by broadcasting the command
68 * over all BAT sources. A BAT source is associated with a DTI connection between PSI
69 * and ACI. A DTI connection is associated with a certain BAT Lib instance. A BAT Lib
70 * instance can be created by a third party application suite, by Bluetooth, by TCP/IP
71 * its bearer manager BEAM and others in future.
72 * After sending the very first custom command over BAT via broadcast, we wait for the
73 * very first answer. Then we know our peer and will address it directly with all
74 * following custom commands.
75 * The following simplified MSC illustrates this.
76 * The BAT["XXX"] shall express that the string "XXX" is content of the BAT custom container.
77 * In the MSC at sequence 8 we got an answer to the custom command. Here we know our peer.
78 * Sequence 11 is neccessary to make the state machine of BAT LIB happy.
79
80 +---+ +---+ +---+ +---+ +---+ +---+
81 |PC | |ATI| |BAT| |BAT| |APP| |APP|
82 |APP| |EXT| |MOD| |LIB| | 1 | .. | N |
83 +---+ +---+ +---+ +---+ +---+ +---+
84 | | | | | |
85 | | | | | |
86 | "AT^SOMETHING=1" |aci_bat_send_custom_cmd | | |
87 1 |------------------>| "AT^SOMETHING=1" | | | |
88 2 | |------------------->| BAT["AT^SOMETH...] | | |
89 3 | | |-------------------->| uns_cb("AT^SOMETH...)| |
90 4 | | | with DTI over PSI |--------------------->| |
91 | | | | | |
92 | | | .. broadcast .. | | |
93 | | | | | |
94 | | | BAT["AT^SOMETH...] | | |
95 5 | | |-------------------->| uns_cb("AT^SOMETH...) |
96 6 | | | |------------------------------>|
97 | | | | | |
98 | | | | bat_send("OK") | |
99 7 | | | BAT["OK"] |<---------------------| |
100 8 | | rEXT_Response_BAT |<--------------------| | |
101 9 | "OK" |<-------------------| | | |
102 10|<------------------| | BAT_OK | | |
103 11| | |-------------------->| rsp_cb(BAT_OK) | |
104 12| | | |--------------------->| |
105 | | | | | |
106 */
107 LOCAL T_ACI_BAT_RSLT aci_bat_find_peer (T_BAT_cmd_send *cmd)
108 {
109 T_L2P_STATUS l2p_status = L2P_STAT_UNKNOWN_ERROR;
110 T_ACI_DTI_PRC_PSI *src_infos_psi = NULL;
111 int errVal = -1;
112 U8 client_id = 0xFC; /* custom channel */
113 int source, client;
114 BOOL custom_cmd_has_been_send;
115 BOOL has_it_been_send_at_all = FALSE;
116
117 TRACE_FUNCTION("aci_bat_find_peer()");
118
119 for (source = 0; source < CMD_SRC_MAX; source++)
120 {
121 custom_cmd_has_been_send = FALSE;
122 if (aci_cmd_src_mode_get((T_ACI_CMD_SRC)source) NEQ CMD_MODE_BAT)
123 {
124 continue; /* it is not a BAT source */
125 }
126
127 src_infos_psi = find_element(psi_src_params, source, cmhPSItest_srcId);
128
129 for (client=0; client < src_infos_psi->max_clients; client++)
130 {
131 if (custom_cmd_has_been_send EQ TRUE)
132 {
133 break;
134 }
135 if (src_infos_psi->bat_client[client].curCmd EQ (T_BAT_ctrl_params)-1)
136 {
137 l2p_status = L2P_Send(aci_bat_get_l2p_id(source),
138 client_id,
139 cmd->ctrl_params,
140 cmd->params.ptr_custom,
141 cmd->params.ptr_custom->c_buf + sizeof(U16), /* sizeof(c_buf) */
142 &errVal);
143 switch (l2p_status)
144 {
145 case (L2P_STAT_SUCCESS):
146 {
147 custom_cmd_has_been_send = TRUE;
148 has_it_been_send_at_all = TRUE;
149 #ifndef _SIMULATION_
150 /* make DTI happy with its flow control stuff */
151 psa_psi_DTI_getdata ((UBYTE)(src_infos_psi->srcId), DTI_ENTITY_PSI);
152 #endif
153 break;
154 }
155 default:
156 {
157 TRACE_EVENT_P1("aci_bat_find_peer(): l2p_status = %d", l2p_status);
158 TRACE_EVENT_P1("aci_bat_find_peer(): errVal = %d", errVal);
159 return (ACI_BAT_FAIL);
160 }
161 }
162 break;
163 }
164 }
165 if (custom_cmd_has_been_send EQ FALSE)
166 {
167 /* either all BAT channels associated to this source are busy or L2P did peg out */
168 TRACE_EVENT_P1("aci_bat_find_peer(): missed to send custom command for BAT source = %d", source);
169 }
170 } /* end of for (source = 0 ; source < CMD_SRC_MAX; source++) */
171 if (has_it_been_send_at_all EQ FALSE)
172 {
173 TRACE_ERROR("aci_bat_find_peer(): was not able to send custom command");
174 return (ACI_BAT_FAIL);
175 }
176 return (ACI_BAT_CMPL);
177 }
178
179 /*
180 +--------------------------------------------------------------------+
181 | PROJECT : GSM-F&D (8411) MODULE : ACI_BAT |
182 | STATE : code ROUTINE : aci_bat_send_custom_cmd |
183 +--------------------------------------------------------------------+
184
185 PURPOSE : called by rEXT_Execute(), see ati_ext_mech.c
186 */
187 GLOBAL T_ACI_BAT_RSLT aci_bat_send_custom_cmd (unsigned char src_id, T_BAT_cmd_send *cmd)
188 {
189 T_L2P_STATUS l2p_status = L2P_STAT_UNKNOWN_ERROR;
190 T_ACI_BAT_RSLT ret = ACI_BAT_FAIL;
191 int errVal = -1;
192 U8 client_id = 0xFC; /* custom channel */
193
194 TRACE_FUNCTION("aci_bat_send_custom_cmd()");
195
196 if (BITFIELD_CHECK(cmd->ctrl_params, BAT_BIT_13)) /* 0x2xxx = custom command */
197 {
198 TRACE_EVENT_P1("aci_bat_send_custom_cmd(): custom cmd 0x%04X over custom channel", cmd->ctrl_params);
199
200 if (aci_bat_ext_globs.ati_custom_src_id EQ 0xFF)
201 {
202 aci_bat_ext_globs.ati_custom_src_id = src_id; /* remember ATI src_id, from which custom cmd has been sent */
203 }
204 if (aci_bat_ext_globs.ati_custom_src_id NEQ src_id) /* currently allow only one ATI source to send custom cmds */
205 {
206 TRACE_EVENT_P2("aci_bat_send_custom_cmd(): ERROR ati_custom_src_id %d != src_id %d",
207 aci_bat_ext_globs.ati_custom_src_id, src_id);
208 return (ACI_BAT_FAIL);
209 }
210 if (aci_bat_ext_globs.bat_custom_src_id EQ 0xFF)
211 {
212 ret = aci_bat_find_peer(cmd);
213 switch (ret)
214 {
215 case (ACI_BAT_CMPL):
216 return (ACI_BAT_EXCT); /* because response comes asynchronously */
217 default:
218 break;
219 }
220 }
221 else
222 {
223 l2p_status = L2P_Send(aci_bat_get_l2p_id(aci_bat_ext_globs.bat_custom_src_id),
224 client_id,
225 cmd->ctrl_params,
226 cmd->params.ptr_custom,
227 cmd->params.ptr_custom->c_buf + sizeof(U16), /* sizeof(c_buf) */
228 &errVal);
229 switch (l2p_status)
230 {
231 case (L2P_STAT_SUCCESS):
232 {
233 #ifndef _SIMULATION_
234 /* make DTI happy with its flow control stuff */
235 psa_psi_DTI_getdata ((UBYTE)(aci_bat_ext_globs.bat_custom_src_id), DTI_ENTITY_PSI);
236 #endif
237 return (ACI_BAT_EXCT); /* because response comes asynchronously */
238 }
239 default:
240 {
241 TRACE_EVENT_P1("aci_bat_send_custom_cmd(): l2p_status = %d", l2p_status);
242 TRACE_EVENT_P1("aci_bat_send_custom_cmd(): errVal = %d", errVal);
243
244 }
245 }
246 }
247 }
248 else
249 {
250 TRACE_EVENT_P1("aci_bat_send_custom_cmd(): ERROR 0x%04X is not a valid custom cmd identifier",
251 cmd->ctrl_params);
252 }
253 return (ACI_BAT_FAIL);
254 }
255
256 /*
257 +--------------------------------------------------------------------+
258 | PROJECT : GSM-F&D (8411) MODULE : ACI_BAT |
259 | STATE : code ROUTINE : aci_bat_rcv_custom |
260 +--------------------------------------------------------------------+
261
262 PURPOSE : called by aci_bat_l2p_msg_rxd_cb(), see aci_bat.c
263 The dataPtr points to a content the customer is responsible for.
264 It can be a ASCII string or any binary data.
265 The dataSize information is already checked by BAT Lib that it
266 does not exceed BAT_MAX_CUSTOM_CMD_LEN.
267 */
268 GLOBAL T_ACI_BAT_RSLT aci_bat_rcv_custom (unsigned char src_id,
269 unsigned char client,
270 unsigned int dataTag,
271 void *dataPtr,
272 unsigned short dataSize)
273 {
274 T_L2P_STATUS l2p_status = L2P_STAT_UNKNOWN_ERROR;
275 int errVal = -1;
276 U8 client_id = client; /* send back on the same client channel */
277 T_ATI_EXT_RETURN ret = ATI_EXT_FAIL;
278 T_BAT_cmd_response rsp;
279 T_BAT_res_plus_ext_error ext_err;
280 T_BAT_no_parameter dummy;
281 T_BAT_custom custom;
282
283 TRACE_FUNCTION("aci_bat_rcv_custom()");
284
285 TRACE_EVENT_P3("aci_bat_rcv_custom(): tag = 0x%X, size = %d, data = %s", dataTag, dataSize, dataPtr);
286
287 rsp.ctrl_response = (T_BAT_ctrl_response)dataTag;
288 rsp.response.ptr_custom = &custom;
289 memcpy((U8 *)&custom, (U8 *)dataPtr, dataSize);
290
291 aci_bat_ext_globs.bat_custom_src_id = src_id;
292
293 ret = rEXT_Response_BAT (aci_bat_ext_globs.ati_custom_src_id, &rsp);
294
295 /*
296 * this response to BAT Lib is neccessary to satisfy it's internal state machine
297 */
298 switch (ret)
299 {
300 case (ATI_EXT_CMPL):
301 {
302 rsp.ctrl_response = BAT_RES_AT_OK;
303 rsp.response.ptr_at_ok = &dummy;
304 dummy.bat_dummy = 0xFF;
305
306 l2p_status = L2P_Send(aci_bat_get_l2p_id(aci_bat_ext_globs.bat_custom_src_id),
307 client_id,
308 rsp.ctrl_response,
309 rsp.response.ptr_at_ok,
310 sizeof(T_BAT_no_parameter),
311 &errVal);
312 break;
313 }
314 default:
315 {
316 TRACE_EVENT("aci_bat_rcv_custom(): rEXT_Response_BAT FAILED");
317
318 rsp.ctrl_response = BAT_RES_PLUS_EXT_ERROR;
319 rsp.response.ptr_plus_ext_error = &ext_err;
320 ext_err.err = BAT_EXT_ERROR_EXT_ERR_UNKNOWN;
321
322 l2p_status = L2P_Send(aci_bat_get_l2p_id(aci_bat_ext_globs.bat_custom_src_id),
323 client_id,
324 rsp.ctrl_response,
325 rsp.response.ptr_plus_ext_error,
326 sizeof(T_BAT_plus_ext_error_err),
327 &errVal);
328 break;
329 }
330 }
331
332 switch (l2p_status)
333 {
334 case (L2P_STAT_SUCCESS):
335 {
336 #ifndef _SIMULATION_
337 /* make DTI happy with its flow control stuff */
338 psa_psi_DTI_getdata ((UBYTE)(aci_bat_ext_globs.bat_custom_src_id), DTI_ENTITY_PSI);
339 #endif
340 break;
341 }
342 default:
343 {
344 TRACE_EVENT_P1("aci_bat_rcv_custom(): l2p_status = %d", l2p_status);
345 TRACE_EVENT_P1("aci_bat_rcv_custom(): errVal = %d", errVal);
346 return (ACI_BAT_FAIL);
347 }
348 }
349 return (ACI_BAT_CMPL);
350 }
351
352