FreeCalypso > hg > fc-magnetite
comparison src/g23m-gsm/sim/sim_stk.c @ 104:27a4235405c6
src/g23m-gsm: import from LoCosto source
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 04 Oct 2016 18:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
103:76d139c7a25e | 104:27a4235405c6 |
---|---|
1 /* | |
2 +----------------------------------------------------------------------------- | |
3 | Project : GSM-F&D (8411) | |
4 | Modul : SIM_STK | |
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 defines the SIM Toolkit Upgrade. | |
18 +----------------------------------------------------------------------------- | |
19 */ | |
20 | |
21 #ifndef SIM_STK_C | |
22 #define SIM_STK_C | |
23 | |
24 #define ENTITY_SIM | |
25 | |
26 /*==== INCLUDES ===================================================*/ | |
27 | |
28 #include <string.h> | |
29 #include "typedefs.h" | |
30 #include "pcm.h" | |
31 #include "pconst.cdg" | |
32 #include "message.h" | |
33 #include "ccdapi.h" | |
34 #include "vsi.h" | |
35 #include "custom.h" | |
36 #include "gsm.h" | |
37 #include "cnf_sim.h" | |
38 #include "mon_sim.h" | |
39 #include "prim.h" | |
40 #include "pei.h" | |
41 #include "tok.h" | |
42 #include "sim.h" | |
43 #include "sim_em.h" | |
44 #include "cl_imei.h" /* IMEI common library */ | |
45 #include "cl_shrd.h" | |
46 | |
47 #ifdef TI_PS_UICC_CHIPSET_15 | |
48 #include "8010_136_SIMDRV_SAP_inline.h" | |
49 #endif | |
50 | |
51 EXTERN USHORT stk_l_cmd; | |
52 /*==== EXPORT =====================================================*/ | |
53 | |
54 /* | |
55 * These Functions are only temporary valid and should be replaced as soon as possible | |
56 */ | |
57 EXTERN UBYTE get_network_meas (UBYTE * chan_list); | |
58 EXTERN UBYTE get_bcch_chan_list (stk_data_type * out_stk_data); | |
59 | |
60 | |
61 /*==== PRIVAT =====================================================*/ | |
62 | |
63 #ifdef FF_SAT_E | |
64 LOCAL void stk_handle_ccd_error(UBYTE notOK, | |
65 UBYTE* status, | |
66 UBYTE* general_result, | |
67 UBYTE* add_info_result); | |
68 LOCAL void stk_bip_decode_stk_command(T_sdu* message, | |
69 T_cmd_details* cmd_details, | |
70 UBYTE* status, | |
71 UBYTE* general_result, | |
72 UBYTE* add_info_result); | |
73 LOCAL void stk_close_dti_connection(UBYTE open); | |
74 LOCAL void stk_close_bip_channel(UBYTE general_result, | |
75 UBYTE add_info_result); | |
76 /* LOCAL void stk_dti_inform_mmi_old (UBYTE dti_conn_req); */ | |
77 LOCAL void stk_dti_inform_mmi(UBYTE dti_conn_req, UBYTE bip_conn_req ); | |
78 | |
79 LOCAL void stk_dti_send_data(); | |
80 LOCAL void stk_bip_send_data_terminal_response(UBYTE general_result, | |
81 UBYTE add_info_result); | |
82 #endif /* FF_SAT_E */ | |
83 | |
84 /*==== TYPES ======================================================*/ | |
85 | |
86 typedef struct | |
87 { | |
88 UBYTE tag; | |
89 UBYTE min_len; | |
90 UBYTE mand; | |
91 UBYTE min_req; | |
92 } T_SAT_TAG_DESC; | |
93 | |
94 typedef struct | |
95 { | |
96 UBYTE cmd_type; | |
97 UBYTE tp_i; | |
98 UBYTE tp_flag; | |
99 UBYTE max_tag; | |
100 const T_SAT_TAG_DESC *tag_desc; | |
101 } T_SAT_CMD_DESC; | |
102 | |
103 /*==== CONSTANTS ==================================================*/ | |
104 | |
105 const T_SAT_TAG_DESC sat_def_cmd[2] = { | |
106 { STK_COMMAND_DETAILS_TAG, | |
107 STK_COMMAND_DETAILS_LEN, | |
108 TRUE, TRUE }, | |
109 { STK_DEVICE_IDENTITY_TAG, | |
110 STK_DEVICE_IDENTITY_LEN, | |
111 TRUE, TRUE } | |
112 }; // valid tags for any command | |
113 | |
114 const T_SAT_TAG_DESC sat_cmd_poll_itv[3] = { | |
115 { STK_COMMAND_DETAILS_TAG, | |
116 STK_COMMAND_DETAILS_LEN, | |
117 TRUE, TRUE }, | |
118 { STK_DEVICE_IDENTITY_TAG, | |
119 STK_DEVICE_IDENTITY_LEN, | |
120 TRUE, TRUE }, | |
121 { STK_DURATION_TAG, | |
122 STK_DURATION_LEN, | |
123 TRUE, TRUE } | |
124 }; // valid tags for POLL INTERVALL | |
125 | |
126 const T_SAT_TAG_DESC sat_cmd_refresh[3] = { | |
127 { STK_COMMAND_DETAILS_TAG, | |
128 STK_COMMAND_DETAILS_LEN, | |
129 TRUE, TRUE }, | |
130 { STK_DEVICE_IDENTITY_TAG, | |
131 STK_DEVICE_IDENTITY_LEN, | |
132 TRUE, TRUE }, | |
133 { STK_FILE_LIST_TAG, | |
134 STK_FILE_LIST_LEN, | |
135 FALSE, TRUE } | |
136 }; // valid tags for REFRESH | |
137 | |
138 const T_SAT_TAG_DESC sat_cmd_event_list[3] = { | |
139 { STK_COMMAND_DETAILS_TAG, | |
140 STK_COMMAND_DETAILS_LEN, | |
141 TRUE, TRUE }, | |
142 { STK_DEVICE_IDENTITY_TAG, | |
143 STK_DEVICE_IDENTITY_LEN, | |
144 TRUE, TRUE }, | |
145 { STK_EVENT_LIST_TAG, | |
146 STK_EVENT_LIST_LEN, | |
147 TRUE, TRUE } | |
148 }; // valid tags for SETUP EVENT LIST | |
149 | |
150 const T_SAT_TAG_DESC sat_cmd_timer[4] = { | |
151 { STK_COMMAND_DETAILS_TAG, | |
152 STK_COMMAND_DETAILS_LEN, | |
153 TRUE, TRUE }, | |
154 { STK_DEVICE_IDENTITY_TAG, | |
155 STK_DEVICE_IDENTITY_LEN, | |
156 TRUE, TRUE }, | |
157 { STK_TIMER_ID_TAG, | |
158 STK_TIMER_ID_LEN, | |
159 TRUE, TRUE }, | |
160 { STK_TIMER_VALUE_TAG, | |
161 STK_TIMER_VALUE_LEN, | |
162 FALSE, FALSE } | |
163 }; // valid tags for TIMER MANAGEMENT | |
164 | |
165 const T_SAT_TAG_DESC sat_cmd_receive_data[5] = { | |
166 { STK_COMMAND_DETAILS_TAG, | |
167 STK_COMMAND_DETAILS_LEN, | |
168 TRUE, TRUE }, | |
169 { STK_DEVICE_IDENTITY_TAG, | |
170 STK_DEVICE_IDENTITY_LEN, | |
171 TRUE, TRUE }, | |
172 { STK_ALPHA_IDENTITY_TAG, | |
173 STK_ALPHA_IDENTITY_LEN, | |
174 FALSE, FALSE }, | |
175 { STK_ICON_IDENTITY_TAG, | |
176 STK_ICON_IDENTITY_LEN, | |
177 FALSE, FALSE }, | |
178 { STK_CHANNEL_DATA_LGTH_TAG, | |
179 STK_CHANNEL_DATA_LGTH_LEN, | |
180 TRUE, TRUE } | |
181 }; // valid tags for RECEIVE DATA | |
182 | |
183 const T_SAT_TAG_DESC sat_cmd_send_data[5] = { | |
184 { STK_COMMAND_DETAILS_TAG, | |
185 STK_COMMAND_DETAILS_LEN, | |
186 TRUE, TRUE }, | |
187 { STK_DEVICE_IDENTITY_TAG, | |
188 STK_DEVICE_IDENTITY_LEN, | |
189 TRUE, TRUE }, | |
190 { STK_ALPHA_IDENTITY_TAG, | |
191 STK_ALPHA_IDENTITY_LEN, | |
192 FALSE, FALSE }, | |
193 { STK_ICON_IDENTITY_TAG, | |
194 STK_ICON_IDENTITY_LEN, | |
195 FALSE, FALSE }, | |
196 { STK_CHANNEL_DATA_TAG, | |
197 STK_CHANNEL_DATA_LEN, | |
198 TRUE, TRUE } | |
199 }; // valid tags for SEND DATA | |
200 | |
201 const T_SAT_CMD_DESC sat_cmd_list[] = { | |
202 { 0, 0, 0xFF, | |
203 item_of(sat_def_cmd), sat_def_cmd }, // command not yet known | |
204 { STK_REFRESH, 2, SAT_TP3_REFRESH, | |
205 item_of(sat_cmd_refresh), sat_cmd_refresh }, | |
206 { STK_MORE_TIME, 2, SAT_TP3_MORE_TIME, | |
207 item_of(sat_def_cmd), sat_def_cmd }, | |
208 { STK_POLL_INTERVALL, 2, SAT_TP3_POLL_ITV, | |
209 item_of(sat_cmd_poll_itv), sat_cmd_poll_itv }, | |
210 { STK_POLLING_OFF, 2, SAT_TP3_POLL_OFF, | |
211 item_of(sat_def_cmd), sat_def_cmd }, | |
212 { STK_SET_UP_CALL, 3, SAT_TP4_SETUP_CALL, | |
213 item_of(sat_def_cmd), sat_def_cmd }, | |
214 { STK_SEND_SS, 3, SAT_TP4_SEND_SS, | |
215 item_of(sat_def_cmd), sat_def_cmd }, | |
216 { STK_SEND_SMS, 3, SAT_TP4_SEND_SMS, | |
217 item_of(sat_def_cmd), sat_def_cmd }, | |
218 { STK_PLAY_TONE, 2, SAT_TP3_PLAY_TONE, | |
219 item_of(sat_def_cmd), sat_def_cmd }, | |
220 { STK_DISPLAY_TEXT, 2, SAT_TP3_DSPL_TXT, | |
221 item_of(sat_def_cmd), sat_def_cmd }, | |
222 { STK_GET_INKEY, 2, SAT_TP3_GET_INKEY, | |
223 item_of(sat_def_cmd), sat_def_cmd }, | |
224 { STK_GET_INPUT, 2, SAT_TP3_GET_INPUT, | |
225 item_of(sat_def_cmd), sat_def_cmd }, | |
226 { STK_SELECT_ITEM, 3, SAT_TP4_SEL_ITEM, | |
227 item_of(sat_def_cmd), sat_def_cmd }, | |
228 { STK_SET_UP_MENU, 3, SAT_TP4_SETUP_MENU, | |
229 item_of(sat_def_cmd), sat_def_cmd }, | |
230 { STK_PROVIDE_LOCAL_INFO, 3, SAT_TP4_PLI_PLMN_IMEI, | |
231 item_of(sat_def_cmd), sat_def_cmd }, | |
232 { STK_TIMER_MANAGEMENT, 7, SAT_TP8_TMNG_ST, | |
233 item_of(sat_cmd_timer), sat_cmd_timer }, | |
234 { STK_SETUP_EVENT_LIST, 4, SAT_TP5_EVENT_LIST, | |
235 item_of(sat_def_cmd), sat_def_cmd }, | |
236 { STK_SEND_USSD, 3, SAT_TP4_SEND_USSD, | |
237 item_of(sat_def_cmd), sat_def_cmd }, | |
238 { STK_SEND_DTMF, 8, SAT_TP9_DTMF_CMD, | |
239 item_of(sat_def_cmd), sat_def_cmd }, | |
240 { STK_SETUP_IDLE_TEXT, 7, SAT_TP8_IDLE_TXT, | |
241 item_of(sat_def_cmd), sat_def_cmd }, | |
242 { STK_RUN_AT_CMD, 7, SAT_TP8_AT_CMD, | |
243 item_of(sat_def_cmd), sat_def_cmd }, | |
244 { STK_LANGUAGE_NOTIFICATION, 8, SAT_TP9_LANG_NOTIFY, | |
245 item_of(sat_def_cmd), sat_def_cmd } | |
246 #ifdef FF_SAT_C | |
247 , | |
248 { STK_LAUNCH_BROWSER, 8, SAT_TP9_LAUNCH_BROWSER, | |
249 item_of(sat_def_cmd), sat_def_cmd } | |
250 #endif /* FF_SAT_C */ | |
251 #ifdef FF_SAT_E | |
252 , | |
253 { STK_OPEN_CHANNEL, 11, SAT_TP12_OPEN_CHANNEL, | |
254 item_of(sat_def_cmd), sat_def_cmd }, | |
255 { STK_CLOSE_CHANNEL, 11, SAT_TP12_CLOSE_CHANNEL, | |
256 item_of(sat_def_cmd), sat_def_cmd }, | |
257 { STK_RECEIVE_DATA, 11, SAT_TP12_RECEIVE_DATA, | |
258 item_of(sat_cmd_receive_data), sat_cmd_receive_data }, | |
259 { STK_SEND_DATA, 11, SAT_TP12_SEND_DATA, | |
260 item_of(sat_cmd_send_data), sat_cmd_send_data }, | |
261 { STK_GET_CHANNEL_STAT, 11, SAT_TP12_GET_CHANNEL_STAT, | |
262 item_of(sat_def_cmd), sat_def_cmd } | |
263 #endif /* FF_SAT_E */ | |
264 }; | |
265 | |
266 /* Terminal Profile bits for which SIM is exclusively responsible. | |
267 They are discarded from the profile provided by MMI */ | |
268 | |
269 static const UBYTE sat_tp_sim_exclusive[MAX_STK_PRF] = { | |
270 /* SAT_TP1_PRF_DNL |*/ SAT_TP1_TIMER_EXP | SAT_TP1_CC_ON_REDIAL, | |
271 0x0, | |
272 SAT_TP3_MORE_TIME | SAT_TP3_POLL_ITV | SAT_TP3_POLL_OFF, | |
273 SAT_TP4_PLI_PLMN_IMEI | SAT_TP4_PLI_NMR, | |
274 0x0 /*SAT_TP5_LOC_STATUS*/, | |
275 0x0, 0xFF, | |
276 SAT_TP8_TMNG_ST | SAT_TP8_TMNG_VAL, | |
277 SAT_TP9_BCCH_COD | SAT_TP9_PLI_TIMING_ADV, /* Timing Advance is to be supported */ | |
278 0x0, 0x0, | |
279 SAT_TP12_RECEIVE_DATA | SAT_TP12_SEND_DATA, | |
280 0x0, 0x0, 0x0, 0x0, 0x0, 0xFF, 0x0, 0xFF}; | |
281 | |
282 /* Terminal Profile bits which have to be supported by SIM to be | |
283 valid with the profile provided by MMI */ | |
284 | |
285 static const UBYTE sat_tp_sim_ability[MAX_STK_PRF] = { | |
286 SAT_TP1_PRF_DNL, | |
287 SAT_TP2_CMD_RES, | |
288 SAT_TP3_DSPL_TXT | SAT_TP3_GET_INKEY | SAT_TP3_GET_INPUT | |
289 | SAT_TP3_PLAY_TONE | SAT_TP3_REFRESH, | |
290 SAT_TP4_SEL_ITEM | SAT_TP4_SEND_SMS | SAT_TP4_SEND_SS | |
291 | SAT_TP4_SEND_USSD | SAT_TP4_SETUP_CALL | SAT_TP4_SETUP_MENU, | |
292 SAT_TP5_EVENT_LIST, 0x0, 0x0, | |
293 SAT_TP8_IDLE_TXT | SAT_TP8_AT_CMD | SAT_TP8_PLI_DTT, | |
294 SAT_TP9_DTMF_CMD | SAT_TP9_LANG_NOTIFY | SAT_TP9_LAUNCH_BROWSER, | |
295 0x0, 0x0, | |
296 SAT_TP12_OPEN_CHANNEL | SAT_TP12_CLOSE_CHANNEL | SAT_TP12_GET_CHANNEL_STAT, | |
297 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; | |
298 | |
299 /* Currently supported Terminal Profile bits by SIM */ | |
300 | |
301 static const UBYTE sat_tp_sim_enabled[MAX_STK_PRF] = { | |
302 SAT_TP1_PRF_DNL | SAT_TP1_SMS_DNL | SAT_TP1_9E_XX | SAT_TP1_TIMER_EXP, | |
303 SAT_TP2_CMD_RES, | |
304 SAT_TP3_MORE_TIME | SAT_TP3_POLL_ITV | SAT_TP3_POLL_OFF | SAT_TP3_REFRESH, | |
305 SAT_TP4_PLI_PLMN_IMEI | SAT_TP4_PLI_NMR, | |
306 0x0, 0x0, 0x0, | |
307 SAT_TP8_TMNG_ST | SAT_TP8_TMNG_VAL | SAT_TP8_PLI_DTT | |
308 | SAT_TP8_IDLE_TXT | SAT_TP8_AT_CMD, | |
309 SAT_TP9_BCCH_COD | SAT_TP9_PLI_TIMING_ADV, /* Timing Advance is to be supported */ | |
310 0x0, 0x0, | |
311 #ifdef FF_SAT_E | |
312 SAT_TP12_OPEN_CHANNEL | SAT_TP12_CLOSE_CHANNEL | SAT_TP12_GET_CHANNEL_STAT | |
313 | SAT_TP12_RECEIVE_DATA | SAT_TP12_SEND_DATA, | |
314 #else | |
315 0x0, | |
316 #endif | |
317 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; | |
318 | |
319 static const UBYTE tbl_device_src_id[] = | |
320 { | |
321 DEV_SRC_KBD, | |
322 DEV_SRC_DSP, | |
323 DEV_SRC_EAR, | |
324 DEV_SRC_CDR0, | |
325 DEV_SRC_CDR1, | |
326 DEV_SRC_CDR2, | |
327 DEV_SRC_CDR3, | |
328 DEV_SRC_CDR4, | |
329 DEV_SRC_CDR5, | |
330 DEV_SRC_CDR6, | |
331 DEV_SRC_CDR7, | |
332 DEV_SRC_CH1, | |
333 DEV_SRC_CH2, | |
334 DEV_SRC_CH3, | |
335 DEV_SRC_CH4, | |
336 DEV_SRC_CH5, | |
337 DEV_SRC_CH6, | |
338 DEV_SRC_CH7, | |
339 DEV_SRC_SIM, | |
340 DEV_SRC_ME, | |
341 DEV_SRC_NTW, | |
342 0 | |
343 }; | |
344 | |
345 /*==== VARIABLES ==================================================*/ | |
346 BOOL startTimerPollOff = FALSE; | |
347 | |
348 USHORT cusSatMinPollItv = 50; // 5 seconds | |
349 | |
350 /*==== FUNCTIONS ==================================================*/ | |
351 | |
352 LOCAL UBYTE stk_dti_bip_receive_data (T_sdu* message, UBYTE result_code); | |
353 | |
354 /* | |
355 +--------------------------------------------------------------------+ | |
356 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
357 | STATE : code ROUTINE : stk_init_sim_data | | |
358 +--------------------------------------------------------------------+ | |
359 | |
360 PURPOSE : Initialize the SIM data for the module SIM TOOLKIT. | |
361 | |
362 */ | |
363 | |
364 GLOBAL void stk_init_sim_data (void) | |
365 { | |
366 TRACE_FUNCTION ("stk_init_sim_data()"); | |
367 | |
368 /* | |
369 * initialize SAT variables | |
370 */ | |
371 sim_data.sat_session = FALSE; | |
372 sim_data.ext_sat_cmd = FALSE; | |
373 sim_data.term_resp_sent = FALSE; | |
374 sim_data.chk_sat_avail = FALSE; | |
375 sim_data.context_switch_ptr = NULL; | |
376 sim_data.cust_mode = FALSE; | |
377 sim_data.user_confirmation_expected = FALSE; | |
378 | |
379 #ifdef FF_SAT_E | |
380 /* | |
381 * initialize DTI variables | |
382 */ | |
383 sim_data.dti_connection_state = SIM_DTI_CONNECTION_CLOSED; | |
384 sim_data.dti_rx_state = SIM_DTI_RX_IDLE; | |
385 sim_data.dti_tx_state = SIM_DTI_TX_IDLE; | |
386 sim_data.event_data_avail = SIM_EVENT_DISABLE; | |
387 sim_data.bip_state = SIM_BIP_CLOSED; | |
388 sim_data.bip_suspend = FALSE; | |
389 #ifdef _SIMULATION_ | |
390 TRACE_EVENT("bip_rx_state = IDLE"); | |
391 #endif | |
392 sim_data.bip_rx_state = SIM_BIP_RX_IDLE; | |
393 #ifdef _SIMULATION_ | |
394 TRACE_EVENT("bip_tx_state = IDLE"); | |
395 #endif | |
396 sim_data.bip_tx_state = SIM_BIP_TX_IDLE; | |
397 sim_data.bip_timer_state = SIM_BIP_TIMER_DISCONNECTED; | |
398 sim_data.bip_release_time = SIM_NO_AUTO_RELEASE; | |
399 sim_data.bip_general_result = RSLT_PERF_SUCCESS; | |
400 sim_data.bip_add_info_result = ADD_NO_CAUSE; | |
401 sim_data.con_type = SIM_CON_TYPE_UDP; | |
402 sim_data.data_to_send.first = (ULONG)NULL; | |
403 sim_data.data_to_send.list_len = 0; | |
404 sim_data.prev_data_to_send.first = (ULONG)NULL; | |
405 sim_data.prev_data_to_send.list_len = 0; | |
406 sim_data.received_data.first = (ULONG)NULL; | |
407 sim_data.received_data.list_len = 0; | |
408 sim_data.received_data_pos = 0; | |
409 sim_data.sim_dti_req = NULL; | |
410 sim_data.sim_bip_req = NULL; | |
411 sim_data.sim_bip_config_req = NULL; | |
412 memset(&sim_data.udp_parameters, 0, sizeof(T_SRC_DES)); | |
413 #endif /* FF_SAT_E */ | |
414 } /* stk_init_sim_data() */ | |
415 | |
416 /* | |
417 +--------------------------------------------------------------------+ | |
418 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
419 | STATE : code ROUTINE : stk_check_tp | | |
420 +--------------------------------------------------------------------+ | |
421 | |
422 PURPOSE : Evaluates the received Terminal Profile against the | |
423 capability of the SIM Entity. | |
424 | |
425 */ | |
426 | |
427 GLOBAL void stk_check_tp (UBYTE *out_prf, UBYTE *in_prf, USHORT len) | |
428 { | |
429 int i; | |
430 UBYTE tp_tmp; | |
431 | |
432 /* TRACE_FUNCTION ("stk_check_tp()"); */ | |
433 | |
434 len = MINIMUM(len, MAX_STK_PRF); | |
435 for (i = 0; i < len; i++) // check TP from MMI | |
436 { | |
437 #ifndef __OLD | |
438 tp_tmp = sat_tp_sim_enabled[i] & ~sat_tp_sim_ability[i]; | |
439 out_prf[i] = ((in_prf[i] & ~sat_tp_sim_exclusive[i]) & | |
440 ~tp_tmp) | tp_tmp; | |
441 #else | |
442 out_prf[i] = ((in_prf[i] & ~sat_tp_sim_exclusive[i]) & | |
443 (sat_tp_sim_enabled[i] | ~sat_tp_sim_ability[i])) | |
444 | sat_tp_sim_enabled[i]; | |
445 #endif | |
446 } | |
447 if (!(out_prf[0] & SAT_TP1_SMS_DNL)) // check SMS download | |
448 out_prf[0] &= ~SAT_TP1_9E_XX; // only valid with SMS download | |
449 | |
450 if (len >= 6 AND | |
451 !(out_prf[4] & SAT_TP5_EVENT_LIST)) // check event list consistency | |
452 out_prf[5] = out_prf[4] = 0; // discard event list | |
453 | |
454 if (len >= 12 AND | |
455 (out_prf[11] & STK_TP12_CLASS_E) NEQ STK_TP12_CLASS_E) | |
456 { | |
457 out_prf[11] &= ~STK_TP12_CLASS_E; | |
458 | |
459 if (len >= 13) | |
460 out_prf[12] &= ~(SAT_TP13_CSD_SUPP_BY_ME | SAT_TP13_GPRS_SUPP_BY_ME); | |
461 | |
462 if (len >= 17) | |
463 out_prf[16] &= ~(SAT_TP17_BEARER_IND_SUPP_TCP | SAT_TP17_BEARER_IND_SUPP_UDP); | |
464 } | |
465 TRACE_EVENT_P5("TP: %02X %02X %02X %02X ... (%d bytes)", | |
466 out_prf[0], out_prf[1], out_prf[2], out_prf[3], len); | |
467 } | |
468 | |
469 /* | |
470 +--------------------------------------------------------------------+ | |
471 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
472 | STATE : code ROUTINE : stk_perform_profile_download | | |
473 +--------------------------------------------------------------------+ | |
474 | |
475 PURPOSE : Initialize the SIM data for the module application. | |
476 | |
477 */ | |
478 | |
479 GLOBAL void stk_perform_profile_download (void) | |
480 { | |
481 USHORT result; | |
482 USHORT used_tp = (USHORT)sizeof (sim_data.stk_profile); | |
483 | |
484 TRACE_FUNCTION ("stk_perform_profile_download()"); | |
485 | |
486 do | |
487 { | |
488 if (sim_data.stk_profile[--used_tp] NEQ 0) | |
489 break; | |
490 } while (used_tp >= 3); | |
491 used_tp++; | |
492 | |
493 if ((result = FKT_TerminalProfile (sim_data.stk_profile, | |
494 used_tp)) NEQ SIM_NO_ERROR) | |
495 { | |
496 TRACE_EVENT_P1("TP dnl error: %04X", result); | |
497 } | |
498 } | |
499 | |
500 /* | |
501 +--------------------------------------------------------------------+ | |
502 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
503 | STATE : code ROUTINE : stk_proactive_polling | | |
504 +--------------------------------------------------------------------+ | |
505 | |
506 PURPOSE : Polling of an proactive SIM card. | |
507 | |
508 */ | |
509 | |
510 static const UBYTE tag_dur [] = | |
511 { | |
512 STK_DURATION_TAG | | |
513 STK_COMPREHENSION_REQUIRED, /* duration tag */ | |
514 STK_DURATION_LEN, /* duration length */ | |
515 0, /* unit */ | |
516 0 /* number of units */ | |
517 }; | |
518 | |
519 static const UBYTE terminal_response_loci [21] = | |
520 { | |
521 STK_COMMAND_DETAILS_TAG | | |
522 STK_COMPREHENSION_REQUIRED, /* command details tag */ | |
523 STK_COMMAND_DETAILS_LEN, /* command details length */ | |
524 0, /* command number */ | |
525 STK_PROVIDE_LOCAL_INFO, /* command PROVIDE LOCATION INFO*/ | |
526 0, /* location information */ | |
527 STK_DEVICE_IDENTITY_TAG | | |
528 STK_COMPREHENSION_REQUIRED, /* device details tag */ | |
529 STK_DEVICE_IDENTITY_LEN, /* device details length */ | |
530 0x82, /* source ME */ | |
531 0x81, /* destination SIM */ | |
532 STK_RESULT_TAG | | |
533 STK_COMPREHENSION_REQUIRED, /* result tag */ | |
534 1, /* result length */ | |
535 0, /* result OK */ | |
536 0x13, /* location information tag */ | |
537 7, /* location information length */ | |
538 0,0,0, /* MCC & MNC */ | |
539 0,0, /* Location area code */ | |
540 0,0 /* cell identity */ | |
541 }; | |
542 | |
543 static const UBYTE terminal_response_imei [22] = | |
544 { | |
545 STK_COMMAND_DETAILS_TAG | | |
546 STK_COMPREHENSION_REQUIRED, /* command details tag */ | |
547 STK_COMMAND_DETAILS_LEN, /* command details length */ | |
548 0, /* command number */ | |
549 STK_PROVIDE_LOCAL_INFO, /* command PROVIDE LOCATION INFO*/ | |
550 1, /* imei */ | |
551 STK_DEVICE_IDENTITY_TAG | | |
552 STK_COMPREHENSION_REQUIRED, /* device details tag */ | |
553 STK_DEVICE_IDENTITY_LEN, /* device details length */ | |
554 0x82, /* source ME */ | |
555 0x81, /* destination SIM */ | |
556 STK_RESULT_TAG | | |
557 STK_COMPREHENSION_REQUIRED, /* result tag */ | |
558 1, /* result length */ | |
559 0, /* result OK */ | |
560 0x14, /* imei tag */ | |
561 8, /* imei length */ | |
562 0,0,0,0,0,0,0,0 /* imei digits */ | |
563 }; | |
564 | |
565 static const UBYTE terminal_response_nmr [14] = | |
566 { | |
567 STK_COMMAND_DETAILS_TAG | | |
568 STK_COMPREHENSION_REQUIRED, /* command details tag */ | |
569 STK_COMMAND_DETAILS_LEN, /* command details length */ | |
570 0, /* command number */ | |
571 STK_PROVIDE_LOCAL_INFO, /* command PROVIDE LOCATION INFO*/ | |
572 2, /* network measurement results */ | |
573 STK_DEVICE_IDENTITY_TAG | | |
574 STK_COMPREHENSION_REQUIRED, /* device details tag */ | |
575 STK_DEVICE_IDENTITY_LEN, /* device details length */ | |
576 0x82, /* source ME */ | |
577 0x81, /* destination SIM */ | |
578 STK_RESULT_TAG | | |
579 STK_COMPREHENSION_REQUIRED, /* result tag */ | |
580 1, /* result length */ | |
581 0, /* result OK */ | |
582 0x16, /* nmr tag */ | |
583 16 /* nmr length */ | |
584 }; | |
585 | |
586 /* | |
587 * Terminal-Response for timing advance | |
588 */ | |
589 static const UBYTE terminal_response_timingadv [16] = | |
590 { | |
591 /* ---- cmd details ----- */ | |
592 STK_COMMAND_DETAILS_TAG | | |
593 STK_COMPREHENSION_REQUIRED, /* command details tag */ | |
594 STK_COMMAND_DETAILS_LEN, /* command details length */ | |
595 0, /* command number */ | |
596 STK_PROVIDE_LOCAL_INFO, /* command PROVIDE LOCAL INFO */ | |
597 5, /* timing advance */ | |
598 | |
599 /* ---- device ids ------ */ | |
600 STK_DEVICE_IDENTITY_TAG | | |
601 STK_COMPREHENSION_REQUIRED, /* device details tag */ | |
602 STK_DEVICE_IDENTITY_LEN, /* device details length */ | |
603 0x82, /* source ME */ | |
604 0x81, /* destination SIM */ | |
605 | |
606 /* ------result --------- */ | |
607 STK_RESULT_TAG | | |
608 STK_COMPREHENSION_REQUIRED, /* result tag */ | |
609 1, /* result length */ | |
610 0, /* result OK */ | |
611 | |
612 /* --- timing advance --- */ | |
613 0x2E, /* timing advance tag */ | |
614 2, /* timing advance len */ | |
615 0, /* ME Status */ | |
616 0 /* Timing Advance */ | |
617 }; | |
618 | |
619 static const T_SIM_TRSP_SIMPLE terminal_response_def = | |
620 { | |
621 STK_COMMAND_DETAILS_TAG | | |
622 STK_COMPREHENSION_REQUIRED, /* command details tag */ | |
623 STK_COMMAND_DETAILS_LEN, /* command details length */ | |
624 0, /* command number */ | |
625 0, /* command type place holder */ | |
626 0, /* command qualifier */ | |
627 STK_DEVICE_IDENTITY_TAG | | |
628 STK_COMPREHENSION_REQUIRED, /* device details tag */ | |
629 STK_DEVICE_IDENTITY_LEN, /* device details length */ | |
630 0x82, /* source ME */ | |
631 0x81, /* destination SIM */ | |
632 STK_RESULT_TAG | | |
633 STK_COMPREHENSION_REQUIRED, /* result tag */ | |
634 1, /* result length place holder */ | |
635 0xFF, /* result place holder */ | |
636 0, /* result additional info */ | |
637 }; | |
638 | |
639 #ifdef __INVALID | |
640 static const UBYTE terminal_response_ok [12] = | |
641 { | |
642 STK_COMMAND_DETAILS_TAG | | |
643 STK_COMPREHENSION_REQUIRED, /* command details tag */ | |
644 STK_COMMAND_DETAILS_LEN, /* command details length */ | |
645 0, /* command number */ | |
646 2, /* command MORE TIME */ | |
647 0, /* not used */ | |
648 STK_DEVICE_IDENTITY_TAG | | |
649 STK_COMPREHENSION_REQUIRED, /* device details tag */ | |
650 STK_DEVICE_IDENTITY_LEN, /* device details length */ | |
651 0x82, /* source ME */ | |
652 0x81, /* destination SIM */ | |
653 STK_RESULT_TAG | | |
654 STK_COMPREHENSION_REQUIRED, /* result tag */ | |
655 1, /* result length */ | |
656 0 /* result OK */ | |
657 }; | |
658 | |
659 static const UBYTE terminal_response_loci_neg [13] = | |
660 { | |
661 STK_COMMAND_DETAILS_TAG | | |
662 STK_COMPREHENSION_REQUIRED, /* command details tag */ | |
663 STK_COMMAND_DETAILS_LEN, /* command details length */ | |
664 0, /* command number */ | |
665 STK_PROVIDE_LOCAL_INFO, /* command PROVIDE LOCATION INFO*/ | |
666 0, /* location information */ | |
667 STK_DEVICE_IDENTITY_TAG | | |
668 STK_COMPREHENSION_REQUIRED, /* device details tag */ | |
669 STK_DEVICE_IDENTITY_LEN, /* device details length */ | |
670 0x82, /* source ME */ | |
671 0x81, /* destination SIM */ | |
672 STK_RESULT_TAG | | |
673 STK_COMPREHENSION_REQUIRED, /* result tag */ | |
674 2, /* result length */ | |
675 0x20, /* result ME unable to process */ | |
676 4 /* result add. info no service */ | |
677 }; | |
678 | |
679 static const UBYTE terminal_response_no_cap [12] = | |
680 { | |
681 STK_COMMAND_DETAILS_TAG | | |
682 STK_COMPREHENSION_REQUIRED, /* command details tag */ | |
683 STK_COMMAND_DETAILS_LEN, /* command details length */ | |
684 0, /* command number */ | |
685 0x26, /* command PROVIDE LOCATION INFO*/ | |
686 0, /* location information */ | |
687 2, /* device details tag */ | |
688 2, /* device details length */ | |
689 0x82, /* source ME */ | |
690 0x81, /* destination SIM */ | |
691 3, /* result tag */ | |
692 1, /* result length */ | |
693 0x30 /* result beyond ME capability */ | |
694 }; | |
695 #endif | |
696 | |
697 LOCAL UBYTE stk_process_tl (UBYTE **pp_stk, | |
698 SHORT *p_ber_len, | |
699 SHORT *p_tlv_len) | |
700 { | |
701 /* get tag and length and adjust pointer to get parameter values */ | |
702 | |
703 UBYTE tag = STK_COMPREHENSION_REQUIRED; | |
704 SHORT tlv_len; | |
705 | |
706 if (*p_ber_len >= 2) | |
707 { | |
708 tag = *((*pp_stk)++); // get tag and adjust pointer | |
709 if ((tlv_len = (SHORT)*((*pp_stk)++)) <= 0x7F) | |
710 { // one byte length | |
711 *p_tlv_len = tlv_len; // get length | |
712 *p_ber_len -= 2; | |
713 } | |
714 else if (tlv_len EQ 0x81 AND *p_ber_len >= 3) | |
715 { // two bytes length | |
716 *p_tlv_len = (SHORT)*((*pp_stk)++); | |
717 *p_ber_len -= 3; // get length and adjust pointer | |
718 } | |
719 else | |
720 { // erroneous length coding | |
721 *p_tlv_len = 0; | |
722 *p_ber_len = 0; | |
723 return STK_COMPREHENSION_REQUIRED; | |
724 } | |
725 } | |
726 return tag; | |
727 } | |
728 | |
729 LOCAL SHORT stk_build_response (UBYTE *p_response, | |
730 UBYTE *p_cmd, int cmd_len, | |
731 UBYTE *p_res, int res_len, | |
732 UBYTE *p_prm, int prm_len) | |
733 { | |
734 /* | |
735 * builds a TERMINAL RESPONSE | |
736 */ | |
737 static const UBYTE dev_resp[5] = | |
738 { | |
739 STK_DEVICE_IDENTITY_TAG | | |
740 STK_COMPREHENSION_REQUIRED, /* device details tag */ | |
741 STK_DEVICE_IDENTITY_LEN, /* device details length */ | |
742 0x82, /* source ME */ | |
743 0x81, /* destination SIM */ | |
744 STK_RESULT_TAG | | |
745 STK_COMPREHENSION_REQUIRED /* result tag */ | |
746 }; | |
747 int tr_len = 6; | |
748 | |
749 #ifdef _SIMULATION_ | |
750 TRACE_FUNCTION ("stk_build_response()"); | |
751 #endif | |
752 TRACE_FUNCTION_P1 ("TERMINAL_RESPONSE: result=0x%02X", (int)*p_res); | |
753 | |
754 memcpy (p_response, p_cmd, cmd_len); | |
755 memcpy (p_response + cmd_len, dev_resp, 5); | |
756 p_response[cmd_len + 5] = (UBYTE)res_len; | |
757 memcpy (p_response + cmd_len + 6, p_res, res_len); | |
758 tr_len += cmd_len + res_len; | |
759 | |
760 if (p_prm NEQ NULL AND prm_len > 0) | |
761 { | |
762 memcpy (p_response + tr_len, p_prm, prm_len); | |
763 tr_len += prm_len; | |
764 } | |
765 return (SHORT)tr_len; | |
766 } | |
767 | |
768 | |
769 GLOBAL int process_sim_refresh( T_CONTEXT_SWITCH *cmd_ptr ) | |
770 { | |
771 int i; | |
772 SHORT resp_len = 0; | |
773 #ifdef TI_PS_UICC_CHIPSET_15 | |
774 U8 readerId = SIMDRV_VAL_READER_ID__RANGE_MIN; | |
775 U8 voltageSelect = SIMDRV_REQ_VOLTAGE_SEL; | |
776 #endif | |
777 | |
778 T_STK_POLL_DATA *p; | |
779 MALLOC (p, sizeof (T_STK_POLL_DATA)); | |
780 memset (p, 0, sizeof (T_STK_POLL_DATA)); | |
781 | |
782 | |
783 TRACE_FUNCTION ("process_sim_refresh()"); | |
784 | |
785 | |
786 /* process as before */ | |
787 switch (cmd_ptr->p_cmd[4]) | |
788 { | |
789 case 1: | |
790 /*check file list is empty */ | |
791 if( ( 0 == cmd_ptr->fl_len ) OR ( 1 == cmd_ptr->fl_len ) ) | |
792 { | |
793 cmd_ptr->res_code[0] = STK_RES_ERR_MISS_VALUE; | |
794 resp_len = stk_build_response (p->response, | |
795 cmd_ptr->p_cmd, (int)cmd_ptr->cmd_len, | |
796 cmd_ptr->res_code, 1, NULL, 0); | |
797 #ifdef _SIMULATION_ | |
798 TRACE_EVENT("FCN: File List is empty"); | |
799 #endif | |
800 FKT_TerminalResponse (p->response, (USHORT)resp_len); | |
801 break; | |
802 } | |
803 if (cmd_ptr->tag2 NEQ NULL AND cmd_ptr->fl_len >= 5) | |
804 { | |
805 BOOL sim_init = FALSE; | |
806 PALLOC (file_update_sms, SIM_FILE_UPDATE_IND); | |
807 memset (file_update_sms, 0, sizeof(T_SIM_FILE_UPDATE_IND)); | |
808 | |
809 file_update_sms->val_nr = *(cmd_ptr->tag2++); | |
810 cmd_ptr->fl_len -= 3; /* align file id count */ | |
811 for (i = 0; cmd_ptr->fl_len > 0 AND i < (int)file_update_sms->val_nr; i++) | |
812 { | |
813 do | |
814 { | |
815 cmd_ptr->tag2 += 2; | |
816 /* Check if entry is a first level directory */ | |
817 if(cmd_ptr->tag2[0] EQ 0x7F) | |
818 { | |
819 if(file_update_sms->file_info[i].v_path_info EQ FALSE) | |
820 { | |
821 file_update_sms->file_info[i].v_path_info = TRUE; | |
822 file_update_sms->file_info[i].path_info.df_level1 = | |
823 ((USHORT)cmd_ptr->tag2[0] << 8) | (USHORT)cmd_ptr->tag2[1]; | |
824 } | |
825 else | |
826 { | |
827 /* This has already been filled. There cannot be another | |
828 first level directory. Since i is reduced, i will not | |
829 equal to file_update_sms->val_nr and error will be sent to SIM */ | |
830 i--; | |
831 break; | |
832 } | |
833 } | |
834 /* Check if entry is a second level directory and first level | |
835 * directory is also filled*/ | |
836 else if(cmd_ptr->tag2[0] EQ 0x5F) | |
837 { | |
838 if(file_update_sms->file_info[i].v_path_info EQ TRUE AND | |
839 file_update_sms->file_info[i].path_info.v_df_level2 EQ FALSE) | |
840 { | |
841 file_update_sms->file_info[i].path_info.v_df_level2 = TRUE; | |
842 file_update_sms->file_info[i].path_info.df_level2 = | |
843 ((USHORT)cmd_ptr->tag2[0] << 8) | (USHORT)cmd_ptr->tag2[1]; | |
844 } | |
845 else | |
846 { | |
847 /* This has already been filled. There cannot be another | |
848 second level directory */ | |
849 i--; | |
850 break; | |
851 } | |
852 } | |
853 cmd_ptr->fl_len -= 2; | |
854 } | |
855 while (cmd_ptr->fl_len > 0 AND cmd_ptr->tag2[2] NEQ 0x3F); | |
856 | |
857 if (cmd_ptr->tag2[0] NEQ 0x2F AND cmd_ptr->tag2[0] NEQ 0x6F | |
858 AND cmd_ptr->tag2[0] NEQ 0x4F) | |
859 break; /* no EF code -> loop exit leads to error response */ | |
860 | |
861 file_update_sms->file_info[i].datafield = ((USHORT)cmd_ptr->tag2[0] << 8) | |
862 | (USHORT)cmd_ptr->tag2[1]; | |
863 if ((file_update_sms->file_info[i].datafield EQ SIM_PHASE) OR | |
864 (file_update_sms->file_info[i].datafield EQ SIM_SST)) | |
865 | |
866 { /* SIM initialisation is needed! */ | |
867 sim_init = TRUE; | |
868 TRACE_FUNCTION ("FCN converted to INIT"); | |
869 /* break; exit for loop */ | |
870 } | |
871 } | |
872 if (cmd_ptr->fl_len > 0 OR i NEQ (int)file_update_sms->val_nr) | |
873 { /* inconsistent TLV content */ | |
874 PFREE(file_update_sms); | |
875 cmd_ptr->res_code[0] = STK_RES_ERR_CMD_DATA; | |
876 resp_len = stk_build_response (p->response, | |
877 cmd_ptr->p_cmd, (int)cmd_ptr->cmd_len, | |
878 cmd_ptr->res_code, 1, NULL, 0); | |
879 #ifdef _SIMULATION_ | |
880 TRACE_EVENT("FCN: inconsistent TLV content"); | |
881 #endif | |
882 FKT_TerminalResponse (p->response, (USHORT)resp_len); | |
883 break; /* exit switch 'cmd_qual' */ | |
884 } | |
885 if (!sim_init) | |
886 { | |
887 { | |
888 PALLOC (file_update_mmi, SIM_FILE_UPDATE_IND); | |
889 memcpy (file_update_mmi, file_update_sms, | |
890 sizeof(T_SIM_FILE_UPDATE_IND)); | |
891 PSENDX (MMI, file_update_mmi); | |
892 } | |
893 { | |
894 PALLOC (file_update_mm, SIM_FILE_UPDATE_IND); | |
895 memcpy (file_update_mm, file_update_sms, | |
896 sizeof(T_SIM_FILE_UPDATE_IND)); | |
897 PSENDX (MM, file_update_mm); | |
898 } | |
899 PSENDX (SMS, file_update_sms); | |
900 | |
901 sim_data.file_change_resp = 0x7; /* check response */ | |
902 /* Force file selection */ | |
903 sim_data.act_directory = NOT_PRESENT_16BIT; | |
904 sim_data.act_field = NOT_PRESENT_16BIT; | |
905 | |
906 if ((USHORT)(cmd_ptr->cmd_len + 7) <= sizeof (sim_data.stk_response)) | |
907 { | |
908 sim_data.stk_resp_len = stk_build_response (sim_data.stk_response, | |
909 cmd_ptr->p_cmd, (int)cmd_ptr->cmd_len, | |
910 cmd_ptr->res_code, 1, NULL, 0); | |
911 #ifdef _SIMULATION_ | |
912 TRACE_EVENT("FCN: prepare TR"); | |
913 #endif | |
914 } | |
915 else | |
916 sim_data.stk_resp_len = 0; | |
917 break; | |
918 } | |
919 else | |
920 { | |
921 PFREE (file_update_sms); | |
922 } | |
923 } | |
924 else | |
925 { | |
926 cmd_ptr->res_code[0] = STK_RES_ERR_MISS_VALUE; | |
927 resp_len = stk_build_response (p->response, | |
928 cmd_ptr->p_cmd, (int)cmd_ptr->cmd_len, | |
929 cmd_ptr->res_code, 1, NULL, 0); | |
930 #ifdef _SIMULATION_ | |
931 TRACE_EVENT("FCN: cmd incomplete"); | |
932 #endif | |
933 FKT_TerminalResponse (p->response, (USHORT)resp_len); | |
934 break; | |
935 } // no break for sim_init EQ TRUE ! | |
936 | |
937 case 3: | |
938 case 2: | |
939 if (cmd_ptr->res_code[0] EQ STK_RES_SUCCESS) | |
940 // do not overwrite special result codes | |
941 // these commands read more EFs than indicated | |
942 cmd_ptr->res_code[0] = STK_RES_SUCC_ADD_EF_READ; | |
943 case 0: | |
944 if ( (SIM_IS_FLAG_SET (CALL_ACTIVE)) AND (sim_data.cust_mode EQ 0) ) | |
945 { | |
946 cmd_ptr->res_code[0] = STK_RES_BUSY_ME; | |
947 cmd_ptr->res_code[1] = STK_RES_EXT_BUSY_CALL; | |
948 resp_len = stk_build_response (p->response, | |
949 cmd_ptr->p_cmd, (int)cmd_ptr->cmd_len, | |
950 cmd_ptr->res_code, 2, NULL, 0); | |
951 #ifdef _SIMULATION_ | |
952 TRACE_EVENT("INIT: call active"); | |
953 #endif | |
954 FKT_TerminalResponse (p->response, (USHORT)resp_len); | |
955 } | |
956 else | |
957 { | |
958 /* Force file selection */ | |
959 sim_data.act_directory = NOT_PRESENT_16BIT; | |
960 sim_data.act_field = NOT_PRESENT_16BIT; | |
961 sim_data.status_time = THIRTY_SECONDS; | |
962 app_sim_read_parameters (); | |
963 /* The terminal response to be sent is created and stored in context. | |
964 Once ACI and MM indicates the completion of the reading of the EFs | |
965 through SIM_SYNC_REQ, the response will be sent. */ | |
966 sim_data.stk_resp_len = stk_build_response (sim_data.stk_response, | |
967 cmd_ptr->p_cmd, (int)cmd_ptr->cmd_len, | |
968 cmd_ptr->res_code, 1, NULL, 0); | |
969 sim_data.sync_awaited = SIM_SYNC_AWAIT_MM_READ | SIM_SYNC_AWAIT_MMI_READ; | |
970 | |
971 #ifdef _SIMULATION_ | |
972 TRACE_EVENT("INIT: success"); | |
973 #endif | |
974 } | |
975 break; | |
976 case 4: | |
977 if ( (SIM_IS_FLAG_SET (CALL_ACTIVE)) AND (sim_data.cust_mode EQ 0) ) | |
978 { | |
979 cmd_ptr->res_code[0] = STK_RES_BUSY_ME; | |
980 cmd_ptr->res_code[1] = STK_RES_EXT_BUSY_CALL; | |
981 resp_len = stk_build_response (p->response, | |
982 cmd_ptr->p_cmd, (int)cmd_ptr->cmd_len, | |
983 cmd_ptr->res_code, 2, NULL, 0); | |
984 #ifdef _SIMULATION_ | |
985 TRACE_EVENT("RESET: call active"); | |
986 #endif | |
987 FKT_TerminalResponse (p->response, (USHORT)resp_len); | |
988 } | |
989 else | |
990 { | |
991 #ifndef TI_PS_UICC_CHIPSET_15 | |
992 T_SIM_CARD sim_info; | |
993 #endif /* TI_PS_UICC_CHIPSET_15 */ | |
994 USHORT retcode; | |
995 | |
996 TRACE_ASSERT (cmd_ptr->sig_ptr); | |
997 PFREE (cmd_ptr->sig_ptr); | |
998 TRACE_ASSERT (p); | |
999 MFREE (p); | |
1000 sim_data.remove_error = SIM_NO_ERROR; | |
1001 app_sim_remove (); | |
1002 sim_data.remove_error = SIM_CAUSE_CARD_REMOVED; | |
1003 | |
1004 #ifndef TI_PS_UICC_CHIPSET_15 | |
1005 SIM_PowerOff (); | |
1006 #else | |
1007 simdrv_poweroff(readerId); | |
1008 #endif | |
1009 /* Force file selection */ | |
1010 sim_data.act_directory = NOT_PRESENT_16BIT; | |
1011 sim_data.act_field = NOT_PRESENT_16BIT; | |
1012 | |
1013 /*retcode = SIM_Restart (&sim_info); Driver does not call 'insert()'! */ | |
1014 #ifndef TI_PS_UICC_CHIPSET_15 | |
1015 retcode = SIM_Reset (&sim_info); | |
1016 #else | |
1017 retcode = simdrv_reset (readerId,voltageSelect); | |
1018 #endif | |
1019 TRACE_EVENT_P1 ("Result SIM Restart = %d", (int)retcode); | |
1020 TRACE_FUNCTION ("process_sim_refresh() exited(1)"); | |
1021 return(1); //return and exit stk_proactive_polling(), if that is where called from | |
1022 } | |
1023 break; | |
1024 | |
1025 default: | |
1026 /* | |
1027 * not supported information request | |
1028 */ | |
1029 TRACE_FUNCTION ("process_sim_refresh() default:"); | |
1030 cmd_ptr->res_code[0] = STK_RES_ERR_CMD_TYPE; | |
1031 resp_len = stk_build_response (p->response, cmd_ptr->p_cmd, cmd_ptr->cmd_len, | |
1032 cmd_ptr->res_code, 1, NULL, 0); | |
1033 #ifdef _SIMULATION_ | |
1034 TRACE_EVENT("RFR: unknown qualifier"); | |
1035 #endif | |
1036 FKT_TerminalResponse (p->response, (USHORT)resp_len); | |
1037 break; | |
1038 } | |
1039 | |
1040 TRACE_ASSERT (cmd_ptr->sig_ptr); | |
1041 PFREE (cmd_ptr->sig_ptr); | |
1042 TRACE_ASSERT (p); | |
1043 MFREE (p); | |
1044 TRACE_FUNCTION ("process_sim_refresh() exited(0)"); | |
1045 return(0); | |
1046 | |
1047 } | |
1048 | |
1049 | |
1050 | |
1051 | |
1052 GLOBAL void stk_proactive_polling (void) | |
1053 { | |
1054 UBYTE *stk, *p_tag, *p_cmd = NULL; | |
1055 UBYTE *found_tag[STK_MAX_EXP_TAG]; | |
1056 UBYTE compreh = 0, cmd_nr = 0, cmd_type, cmd_qual = 0; | |
1057 SHORT ber_len, tag_len, cmd_len, fl_len = 0, resp_len = 0; | |
1058 SHORT i, tag_i, cmd_i, tlv_len; | |
1059 const T_SAT_TAG_DESC *p_tag_desc; | |
1060 int offset; | |
1061 T_LOC_INFO loc_info; | |
1062 T_TIM_ADV tim_adv; | |
1063 | |
1064 TRACE_FUNCTION ("stk_proactive_polling()"); | |
1065 | |
1066 if (SIM_IS_FLAG_SET (PRO_ACTIVE_SIM)) | |
1067 { | |
1068 while (sim_data.proactive_sim_data_len > 0) | |
1069 { | |
1070 UINT in_queue, out_queue; | |
1071 UBYTE result = FALSE; | |
1072 UBYTE res_code[2] = {STK_RES_SUCCESS, 0}; | |
1073 T_TIME tm_val; | |
1074 T_STK_POLL_DATA *p; | |
1075 | |
1076 PALLOC (sim_toolkit_ind, SIM_TOOLKIT_IND); | |
1077 MALLOC (p, sizeof (T_STK_POLL_DATA)); | |
1078 /* | |
1079 * clear indication primitive | |
1080 */ | |
1081 memset (sim_toolkit_ind, 0, sizeof (T_SIM_TOOLKIT_IND)); | |
1082 sim_toolkit_ind->stk_cmd.l_cmd = ((USHORT)sim_data.proactive_sim_data_len) << 3; | |
1083 ber_len = (SHORT)sim_data.proactive_sim_data_len; | |
1084 sim_data.proactive_sim_data_len = 0; | |
1085 sim_data.term_resp_sent = FALSE; | |
1086 | |
1087 if (FKT_Fetch(sim_toolkit_ind->stk_cmd.cmd, ber_len) EQ SIM_NO_ERROR) | |
1088 { | |
1089 UBYTE tag; | |
1090 BOOL tag_not_found = TRUE; | |
1091 | |
1092 #ifdef _SIMULATION_ | |
1093 TRACE_EVENT("FKT_Fetch_EQ_SIM_NO_ERROR"); /* for debug purpose only */ | |
1094 #endif | |
1095 sim_data.ext_sat_cmd = FALSE; /* internal command by default */ | |
1096 | |
1097 stk = sim_toolkit_ind->stk_cmd.cmd; | |
1098 memset (found_tag, 0, sizeof(found_tag)); | |
1099 tag_i = cmd_i = 0; | |
1100 cmd_len = 0; | |
1101 cmd_type = 0; | |
1102 | |
1103 tag = stk_process_tl(&stk, &ber_len, &tlv_len); /* BER tag */ | |
1104 if (tag NEQ STK_PROACTIVE_SIM_COMMAND_TAG) | |
1105 { | |
1106 res_code[0] = STK_RES_ERR_MISS_VALUE; | |
1107 } | |
1108 else if (ber_len >= tlv_len) | |
1109 { | |
1110 ber_len = tlv_len; // omit data after BER-TLV | |
1111 result = TRUE; | |
1112 } | |
1113 else /* ber_len < tlv_len */ | |
1114 { | |
1115 if (tlv_len > 2) | |
1116 { | |
1117 res_code[0] = STK_RES_ERR_MISS_VALUE; | |
1118 result = TRUE; | |
1119 } | |
1120 else | |
1121 { | |
1122 res_code[0] = STK_RES_ERR_CMD_DATA; | |
1123 } | |
1124 } | |
1125 | |
1126 while (result AND ber_len > 0) // tag and length needed | |
1127 { | |
1128 UBYTE tag_simple; | |
1129 | |
1130 p_tag = stk; // begin of TLV | |
1131 tag_len = ber_len; | |
1132 tag_simple = stk_process_tl(&stk, &ber_len, &tlv_len); | |
1133 | |
1134 if (ber_len < tlv_len) // inconsistent length | |
1135 { | |
1136 if (res_code[0] NEQ STK_RES_ERR_MISS_VALUE) | |
1137 { | |
1138 TRACE_EVENT("ber_len < tlv_len -> STK_RES_ERR_CMD_DATA"); | |
1139 res_code[0] = STK_RES_ERR_CMD_DATA; | |
1140 } | |
1141 result = FALSE; | |
1142 break; | |
1143 } | |
1144 else | |
1145 ber_len -= tlv_len; // remaining BER-TLV | |
1146 | |
1147 tag_len -= ber_len; // length of TLV | |
1148 | |
1149 if (tag EQ (tag_simple & ~STK_COMPREHENSION_REQUIRED)) | |
1150 { | |
1151 #ifdef _SIMULATION_ | |
1152 TRACE_EVENT("TC_505A, TC_505B, TC_505C"); | |
1153 #endif | |
1154 stk += tlv_len; | |
1155 continue; | |
1156 } | |
1157 else | |
1158 { | |
1159 tag = tag_simple; | |
1160 tag_not_found = FALSE; | |
1161 } | |
1162 | |
1163 compreh = tag & STK_COMPREHENSION_REQUIRED; | |
1164 tag &= ~STK_COMPREHENSION_REQUIRED; | |
1165 | |
1166 do | |
1167 { | |
1168 p_tag_desc = &sat_cmd_list[cmd_i].tag_desc[tag_i]; | |
1169 if (tag EQ p_tag_desc->tag) | |
1170 { | |
1171 break; /* tag found !!! */ | |
1172 } | |
1173 else if (!p_tag_desc->mand) | |
1174 { | |
1175 tag_i++; /* skip non-mandatory tags */ | |
1176 } | |
1177 else /* mandatory tag missed */ | |
1178 { | |
1179 i = tag_i; | |
1180 res_code[0] = STK_RES_ERR_MISS_VALUE; | |
1181 while (i < (int)sat_cmd_list[cmd_i].max_tag) | |
1182 { | |
1183 p_tag_desc = &sat_cmd_list[cmd_i].tag_desc[i++]; | |
1184 if (tag EQ p_tag_desc->tag AND !p_tag_desc->mand) | |
1185 { | |
1186 #ifdef _SIMULATION_ | |
1187 TRACE_EVENT("TC_506"); | |
1188 #endif | |
1189 res_code[0] = STK_RES_ERR_CMD_DATA; | |
1190 break; | |
1191 } | |
1192 } | |
1193 if (!compreh AND i EQ (int)sat_cmd_list[cmd_i].max_tag) | |
1194 { | |
1195 #ifdef _SIMULATION_ | |
1196 TRACE_EVENT("TC_507"); | |
1197 #endif | |
1198 res_code[0] = STK_RES_SUCC_PART_COMPR; | |
1199 tag_not_found = TRUE; | |
1200 } | |
1201 break; | |
1202 } | |
1203 } while (tag_i < (int)sat_cmd_list[cmd_i].max_tag OR res_code[0]); | |
1204 | |
1205 if (tag_i >= (int)sat_cmd_list[cmd_i].max_tag) | |
1206 { | |
1207 i = (int)sat_cmd_list[cmd_i].tp_i; | |
1208 | |
1209 if ((~sat_tp_sim_ability[i] & sat_cmd_list[cmd_i].tp_flag) EQ 0) | |
1210 { | |
1211 break; /* the commmand is being handled outside the SIM */ | |
1212 } | |
1213 | |
1214 if (compreh) | |
1215 { | |
1216 #ifdef _SIMULATION_ | |
1217 TRACE_EVENT("TC_502C, TC_504"); | |
1218 #endif | |
1219 res_code[0] = STK_RES_ERR_CMD_DATA; | |
1220 result = FALSE; | |
1221 break; | |
1222 } | |
1223 } | |
1224 else | |
1225 { | |
1226 p_tag_desc = &sat_cmd_list[cmd_i].tag_desc[tag_i]; | |
1227 if (tag NEQ p_tag_desc->tag OR tlv_len < p_tag_desc->min_len) | |
1228 { | |
1229 if (compreh) | |
1230 { | |
1231 #ifdef _SIMULATION_ | |
1232 TRACE_EVENT("TC_503, TC_506"); | |
1233 #endif | |
1234 result = FALSE; | |
1235 break; | |
1236 } | |
1237 } | |
1238 else | |
1239 found_tag[tag_i] = stk; // points to parameters of tag | |
1240 } | |
1241 | |
1242 if (tag_not_found) | |
1243 { | |
1244 stk += tlv_len; | |
1245 continue; | |
1246 } | |
1247 | |
1248 switch (tag) | |
1249 { | |
1250 case STK_COMMAND_DETAILS_TAG: | |
1251 p_cmd = p_tag; // for TERMINAL RESPONSE | |
1252 cmd_len = tag_len; | |
1253 cmd_nr = stk[0]; | |
1254 cmd_type = stk[1]; | |
1255 cmd_qual = stk[2]; | |
1256 | |
1257 TRACE_FUNCTION_P2("COMMAND_DETAILS: type=0x%02X, qlf=0x%02X", | |
1258 (int)cmd_type, (int) cmd_qual); | |
1259 | |
1260 SIM_EM_PROACTIVE_COMMAND; | |
1261 | |
1262 for (i = 1; i < (SHORT)item_of(sat_cmd_list); i++) /* find out if known command */ | |
1263 { | |
1264 if (cmd_type EQ sat_cmd_list[i].cmd_type) | |
1265 { | |
1266 cmd_i = i; | |
1267 break; | |
1268 } | |
1269 } | |
1270 if (i EQ item_of(sat_cmd_list)) | |
1271 { | |
1272 TRACE_EVENT_P1("UNKNOWN COMMAND TYPE:0x%02X", cmd_type); | |
1273 } | |
1274 break; | |
1275 | |
1276 case STK_DEVICE_IDENTITY_TAG: | |
1277 #ifdef _SIMULATION_ | |
1278 TRACE_EVENT("found SIMPLE_TAG: STK_DEVICE_IDENTITY_TAG"); | |
1279 #endif | |
1280 break; | |
1281 | |
1282 case STK_CHANNEL_DATA_TAG: | |
1283 #ifdef _SIMULATION_ | |
1284 TRACE_EVENT("found SIMPLE_TAG: STK_CHANNEL_DATA_TAG"); | |
1285 #endif | |
1286 break; | |
1287 | |
1288 case STK_CHANNEL_DATA_LGTH_TAG: | |
1289 #ifdef _SIMULATION_ | |
1290 TRACE_EVENT("found SIMPLE_TAG: STK_CHANNEL_DATA_LGTH_TAG"); | |
1291 #endif | |
1292 break; | |
1293 | |
1294 case STK_FILE_LIST_TAG: | |
1295 fl_len = tlv_len; | |
1296 break; | |
1297 | |
1298 default: | |
1299 #ifdef _SIMULATION_ | |
1300 TRACE_EVENT_P1("other tag=0x%02X", tag); | |
1301 #endif | |
1302 break; | |
1303 } | |
1304 if (++tag_i >= STK_MAX_EXP_TAG) /* incremented index points to next tag_desc entry */ | |
1305 break; | |
1306 | |
1307 stk += tlv_len; | |
1308 } | |
1309 | |
1310 if (!result) | |
1311 { | |
1312 if (found_tag[0] EQ 0) | |
1313 { | |
1314 switch (res_code[0]) | |
1315 { | |
1316 case STK_RES_ERR_MISS_VALUE: | |
1317 #ifdef _SIMULATION_ | |
1318 TRACE_EVENT("TC_501, TC_508"); | |
1319 #endif | |
1320 memcpy (p->response, &terminal_response_def, SAT_TRSP_MIN_RES); | |
1321 ((T_SIM_TRSP_SIMPLE *)p->response)->cmd_nr = cmd_nr; | |
1322 ((T_SIM_TRSP_SIMPLE *)p->response)->cmd_type = cmd_type; | |
1323 ((T_SIM_TRSP_SIMPLE *)p->response)->res_gnrl = res_code[0]; | |
1324 FKT_TerminalResponse (p->response, SAT_TRSP_MIN_RES); | |
1325 break; | |
1326 | |
1327 default: | |
1328 break; | |
1329 } | |
1330 } | |
1331 else if (found_tag[0] AND cmd_i NEQ 0) | |
1332 { | |
1333 switch (res_code[0]) | |
1334 { | |
1335 case STK_RES_ERR_CMD_DATA: | |
1336 #ifdef _SIMULATION_ | |
1337 TRACE_EVENT("TC_502A, TC_502B, TC_502C, TC_506"); | |
1338 #endif | |
1339 memcpy (p->response, &terminal_response_def, SAT_TRSP_MIN_RES); | |
1340 ((T_SIM_TRSP_SIMPLE *)p->response)->cmd_nr = cmd_nr; | |
1341 ((T_SIM_TRSP_SIMPLE *)p->response)->cmd_type = cmd_type; | |
1342 ((T_SIM_TRSP_SIMPLE *)p->response)->res_gnrl = res_code[0]; | |
1343 FKT_TerminalResponse (p->response, SAT_TRSP_MIN_RES); | |
1344 break; | |
1345 | |
1346 case STK_RES_ERR_MISS_VALUE: | |
1347 #ifdef _SIMULATION_ | |
1348 TRACE_EVENT("TC_503, TC_509A"); | |
1349 #endif | |
1350 memcpy (p->response, &terminal_response_def, SAT_TRSP_MIN_RES); | |
1351 ((T_SIM_TRSP_SIMPLE *)p->response)->cmd_nr = cmd_nr; | |
1352 ((T_SIM_TRSP_SIMPLE *)p->response)->cmd_type = cmd_type; | |
1353 ((T_SIM_TRSP_SIMPLE *)p->response)->res_gnrl = res_code[0]; | |
1354 FKT_TerminalResponse (p->response, SAT_TRSP_MIN_RES); | |
1355 break; | |
1356 | |
1357 default: | |
1358 break; | |
1359 } | |
1360 } | |
1361 else if (cmd_i EQ 0) | |
1362 { | |
1363 #ifdef _SIMULATION_ | |
1364 TRACE_EVENT("TC_504"); | |
1365 #endif | |
1366 res_code[0] = STK_RES_ERR_CMD_TYPE; | |
1367 memcpy (p->response, &terminal_response_def, SAT_TRSP_MIN_RES); | |
1368 ((T_SIM_TRSP_SIMPLE *)p->response)->cmd_nr = cmd_nr; | |
1369 ((T_SIM_TRSP_SIMPLE *)p->response)->cmd_type = cmd_type; | |
1370 ((T_SIM_TRSP_SIMPLE *)p->response)->res_gnrl = res_code[0]; | |
1371 FKT_TerminalResponse (p->response, SAT_TRSP_MIN_RES); | |
1372 } | |
1373 else | |
1374 { | |
1375 resp_len = stk_build_response (p->response, p_cmd, cmd_len, res_code, 1, NULL, 0); | |
1376 #ifdef _SIMULATION_ | |
1377 TRACE_EVENT("SAT: other error"); | |
1378 #endif | |
1379 FKT_TerminalResponse (p->response, (USHORT)resp_len); | |
1380 } | |
1381 PFREE (sim_toolkit_ind); | |
1382 } | |
1383 else switch (cmd_type) | |
1384 { | |
1385 case STK_DISPLAY_TEXT: | |
1386 case STK_GET_INKEY: | |
1387 case STK_GET_INPUT: | |
1388 case STK_PLAY_TONE: | |
1389 case STK_SET_UP_MENU: | |
1390 case STK_SELECT_ITEM: | |
1391 case STK_SEND_SMS: | |
1392 case STK_SEND_SS: | |
1393 case STK_SET_UP_CALL: | |
1394 | |
1395 case STK_SETUP_EVENT_LIST: | |
1396 case STK_SEND_USSD: | |
1397 case STK_SEND_DTMF: | |
1398 case STK_SETUP_IDLE_TEXT: | |
1399 case STK_LAUNCH_BROWSER: | |
1400 case STK_RUN_AT_CMD: | |
1401 case STK_LANGUAGE_NOTIFICATION: | |
1402 #ifdef FF_SAT_E | |
1403 case STK_OPEN_CHANNEL: | |
1404 case STK_CLOSE_CHANNEL: | |
1405 case STK_GET_CHANNEL_STAT: | |
1406 #endif /* FF_SAT_E */ | |
1407 /* | |
1408 * Operations processed by MMI / MFW | |
1409 */ | |
1410 sim_data.sat_session = TRUE; | |
1411 sim_data.ext_sat_cmd = TRUE; | |
1412 PSENDX (MMI, sim_toolkit_ind); | |
1413 break; | |
1414 | |
1415 case STK_POLL_INTERVALL: | |
1416 /* | |
1417 * SIM toolkit defines an idle poll interval. The timer in | |
1418 * SIM application is stopped and started with the | |
1419 * new value. A terminal response with the used time | |
1420 * is sent to SIM toolkit. | |
1421 */ | |
1422 if (found_tag[2] NEQ NULL) | |
1423 { | |
1424 BOOL org_val; | |
1425 TRACE_EVENT("Idle Polling switched on"); | |
1426 | |
1427 if (found_tag[2][1] NEQ 0) /* value not "reserved" */ | |
1428 { | |
1429 switch (found_tag[2][0]) | |
1430 { | |
1431 case 0: /* minutes */ | |
1432 if ((ULONG)found_tag[2][1] * 600L >= (ULONG)cusSatMinPollItv) | |
1433 { | |
1434 sim_data.status_time = ((T_TIME)found_tag[2][1]) * 60L * 1000 | |
1435 - TIMER_LATENCY; | |
1436 org_val = TRUE; | |
1437 } | |
1438 else | |
1439 org_val = FALSE; | |
1440 break; | |
1441 case 1: /* seconds */ | |
1442 if ((USHORT)found_tag[2][1] * 10 >= cusSatMinPollItv) | |
1443 { | |
1444 sim_data.status_time = ((T_TIME)found_tag[2][1]) * 1000L | |
1445 - TIMER_LATENCY; | |
1446 org_val = TRUE; | |
1447 } | |
1448 else | |
1449 org_val = FALSE; | |
1450 break; | |
1451 case 2: /* tenth seconds */ | |
1452 if ((USHORT)found_tag[2][1] >= cusSatMinPollItv) | |
1453 { | |
1454 sim_data.status_time = ((T_TIME)found_tag[2][1]) * 100L | |
1455 - TIMER_LATENCY; | |
1456 org_val = TRUE; | |
1457 } | |
1458 else | |
1459 org_val = FALSE; | |
1460 break; | |
1461 default: /* command data not understood */ | |
1462 res_code[0] = STK_RES_ERR_CMD_DATA; | |
1463 org_val = TRUE; | |
1464 break; /* return original values */ | |
1465 } | |
1466 } | |
1467 else /* return original values */ | |
1468 { | |
1469 res_code[0] = STK_RES_ERR_CMD_DATA; | |
1470 org_val = TRUE; | |
1471 } | |
1472 | |
1473 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
1474 res_code, 1, (UBYTE *)tag_dur, sizeof(tag_dur)); | |
1475 #ifdef _SIMULATION_ | |
1476 TRACE_EVENT("POLL_ITV data not understood"); | |
1477 #endif | |
1478 if (org_val) | |
1479 { | |
1480 p->response[cmd_len+ 9] = found_tag[2][0]; /* copy unit */ | |
1481 /* copy number of units (1 to 255) or 0 !!! */ | |
1482 p->response[cmd_len+10] = found_tag[2][1]; | |
1483 } | |
1484 else | |
1485 { | |
1486 sim_data.status_time = ((T_TIME)cusSatMinPollItv) * 100L | |
1487 - TIMER_LATENCY; | |
1488 if (cusSatMinPollItv < 0x100) | |
1489 { | |
1490 p->response[cmd_len+ 9] = 2; // fits to tenth of seconds | |
1491 p->response[cmd_len+10] = (UBYTE)cusSatMinPollItv; | |
1492 } | |
1493 else if (cusSatMinPollItv < (0x100*10)) | |
1494 { | |
1495 p->response[cmd_len+ 9] = 1; // fits to seconds | |
1496 p->response[cmd_len+10] = (UBYTE)((cusSatMinPollItv / 5 + 1) / 2); | |
1497 } | |
1498 else | |
1499 { | |
1500 p->response[cmd_len+ 9] = 0; // fits to minutes | |
1501 p->response[cmd_len+10] = (UBYTE)((cusSatMinPollItv / 300 + 1) / 2); | |
1502 } | |
1503 } | |
1504 sim_data.idle_polling = TRUE; | |
1505 } | |
1506 else | |
1507 { | |
1508 res_code[0] = STK_RES_ERR_MISS_VALUE; | |
1509 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
1510 res_code, 1, NULL, 0); | |
1511 #ifdef _SIMULATION_ | |
1512 TRACE_EVENT("POLL_ITV missing value"); | |
1513 #endif | |
1514 } | |
1515 FKT_TerminalResponse (p->response, (USHORT)resp_len); | |
1516 PFREE (sim_toolkit_ind); | |
1517 | |
1518 if (SIM_IS_FLAG_CLEARED (CALL_ACTIVE) OR | |
1519 sim_data.status_time < THIRTY_SECONDS) | |
1520 TIMER_PSTART( sim_handle, | |
1521 SIM_TIMER, | |
1522 sim_data.status_time, | |
1523 sim_data.status_time); | |
1524 break; | |
1525 | |
1526 case STK_PROVIDE_LOCAL_INFO: | |
1527 /* | |
1528 * SIM toolkit request local information from the | |
1529 * SIM application. These informations are: | |
1530 * MCC, MNC, LAC, Cell Identity or IMEI. | |
1531 * SIM application sends this information with | |
1532 * a terminal response to the SIM toolkit. | |
1533 */ | |
1534 if(p_cmd EQ NULL) | |
1535 { | |
1536 TRACE_EVENT("p_cmd is NULL"); | |
1537 return; | |
1538 } | |
1539 switch (cmd_qual) | |
1540 { | |
1541 case QLF_PLOI_LOC_INFO: | |
1542 /* | |
1543 * request location information | |
1544 */ | |
1545 #ifdef _SIMULATION_ | |
1546 if (sim_data.location_info.c_loc NEQ 0) | |
1547 { | |
1548 memcpy (p->response, p_cmd, cmd_len); | |
1549 /* location information available */ | |
1550 memcpy (&p->response[cmd_len], &terminal_response_loci[5], 9); | |
1551 /* copy MCC, MNC & LAC */ | |
1552 memcpy (&p->response[cmd_len+ 9], &sim_data.location_info.loc[4], 5); | |
1553 /* copy cell identity */ | |
1554 p->response[cmd_len+14] = sim_data.cell_identity >> 8; | |
1555 p->response[cmd_len+15] = sim_data.cell_identity & 0xFF; | |
1556 p->response[cmd_len+ 6] = res_code[0]; | |
1557 resp_len = cmd_len + 16; | |
1558 #else | |
1559 if((cl_shrd_get_loc (&loc_info) EQ TRUE) AND | |
1560 (loc_info.service_mode NEQ NO_SERVICE)) | |
1561 { | |
1562 memcpy (p->response, p_cmd, cmd_len); | |
1563 /* location information available */ | |
1564 memcpy (&p->response[cmd_len], &terminal_response_loci[5], 9); | |
1565 /* copy from loc_info to response */ | |
1566 p->response[cmd_len+9] = loc_info.mcc[1] << 4; | |
1567 p->response[cmd_len+9] += loc_info.mcc[0]; | |
1568 p->response[cmd_len+10] = loc_info.mnc[2] << 4; | |
1569 p->response[cmd_len+10] += loc_info.mcc[2]; | |
1570 p->response[cmd_len+11] = loc_info.mnc[1] << 4; | |
1571 p->response[cmd_len+11] += loc_info.mnc[0]; | |
1572 p->response[cmd_len+12] = loc_info.lac >> 8; | |
1573 p->response[cmd_len+13] = loc_info.lac & 0xff; | |
1574 p->response[cmd_len+14] = loc_info.cell_id >> 8; | |
1575 p->response[cmd_len+15] = loc_info.cell_id & 0xFF; | |
1576 | |
1577 if ( loc_info.service_mode EQ LIMITED_SERVICE ) | |
1578 { | |
1579 p->response[cmd_len+ 6] = STK_RES_SUCC_LIMITED_SERVICE; | |
1580 } | |
1581 else | |
1582 { | |
1583 p->response[cmd_len+ 6] = res_code[0]; | |
1584 } | |
1585 resp_len = cmd_len + 16; | |
1586 #endif /* _SIMULATION_ */ | |
1587 } | |
1588 else | |
1589 { | |
1590 /* location information not available */ | |
1591 res_code[0] = STK_RES_BUSY_ME; | |
1592 res_code[1] = STK_RES_EXT_NO_SERVICE; | |
1593 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
1594 res_code, 2, NULL, 0); | |
1595 #ifdef _SIMULATION_ | |
1596 TRACE_EVENT("PLI: local info not available"); | |
1597 #endif | |
1598 } | |
1599 sim_data.ext_sat_cmd = FALSE; | |
1600 break; | |
1601 case QLF_PLOI_IMEI: | |
1602 /* | |
1603 * request IMEI | |
1604 */ | |
1605 memcpy (p->response, p_cmd, cmd_len); | |
1606 memcpy (&p->response[cmd_len], &terminal_response_imei[5], 17); | |
1607 | |
1608 cl_get_imeisv(CL_IMEI_SIZE, | |
1609 &p->response[cmd_len + 9], | |
1610 CL_IMEI_GET_STORED_IMEI); | |
1611 for (i = (int)cmd_len + 8 + CL_IMEI_SIZE; | |
1612 i > (int)cmd_len + 9; i--) | |
1613 { /* place nibbles according to 4.08 */ | |
1614 p->response[i] = (p->response[i] & 0xf0) | | |
1615 (p->response[i - 1] & 0x0f); | |
1616 } | |
1617 /* i points to first IMEI octet, set 'type of identity' */ | |
1618 p->response[i] = (p->response[i] & 0xf0) | 0xA; | |
1619 p->response[cmd_len+8+CL_IMEI_SIZE] &= 0xF; | |
1620 p->response[cmd_len+ 6] = res_code[0]; | |
1621 resp_len = cmd_len + 17; | |
1622 sim_data.ext_sat_cmd = FALSE; | |
1623 break; | |
1624 case QLF_PLOI_NTW_MSR: | |
1625 /* | |
1626 * request network measurement results and BCCH list | |
1627 */ | |
1628 if ((sat_tp_sim_enabled[3] & SAT_TP4_PLI_NMR) EQ 0) | |
1629 { | |
1630 /* if not effective */ | |
1631 res_code[0] = STK_RES_ERR_NO_SUPPORT; | |
1632 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
1633 res_code, 1, NULL, 0); | |
1634 #ifdef _SIMULATION_ | |
1635 TRACE_EVENT("PLI: NMR not supported"); | |
1636 #endif | |
1637 break; | |
1638 } | |
1639 memcpy (p->response, p_cmd, cmd_len); | |
1640 /* location information available */ | |
1641 memcpy (&p->response[cmd_len], &terminal_response_nmr[5], 9); | |
1642 if (get_network_meas (&p->response[cmd_len+9])) | |
1643 { | |
1644 /* | |
1645 * set result code | |
1646 */ | |
1647 #ifdef _SIMULATION_ | |
1648 p->response[cmd_len+ 6] = res_code[0]; | |
1649 resp_len = cmd_len + 25; | |
1650 #else | |
1651 if ((cl_shrd_get_loc (&loc_info) EQ TRUE) AND | |
1652 (loc_info.service_mode NEQ NO_SERVICE)) | |
1653 { | |
1654 if ( loc_info.service_mode EQ LIMITED_SERVICE ) | |
1655 { | |
1656 p->response[cmd_len+ 6] = STK_RES_SUCC_LIMITED_SERVICE; | |
1657 } | |
1658 else | |
1659 { | |
1660 p->response[cmd_len+ 6] = res_code[0]; | |
1661 } | |
1662 resp_len = cmd_len + 25; | |
1663 } | |
1664 else | |
1665 { | |
1666 res_code[0] = STK_RES_BUSY_ME; | |
1667 res_code[1] = STK_RES_EXT_NO_SERVICE; | |
1668 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
1669 res_code, 2, NULL, 0); | |
1670 #ifdef _SIMULATION_ | |
1671 TRACE_EVENT("PLI: service mode not available"); | |
1672 #endif /* _SIMULATION_ */ | |
1673 } | |
1674 #endif /* _SIMULATION_ */ | |
1675 /* | |
1676 * Add BCCH list | |
1677 */ | |
1678 if (get_bcch_chan_list (&p->stk_data)) | |
1679 { | |
1680 /* | |
1681 * copy BCCH data list for answer | |
1682 */ | |
1683 p->response[resp_len] = 0x1D; /* BCCH channel flag */ | |
1684 p->response[resp_len + 1] = p->stk_data.stk_length; | |
1685 memcpy (&p->response[resp_len + 2], p->stk_data.stk_parameter, | |
1686 p->stk_data.stk_length); | |
1687 resp_len += (2+p->stk_data.stk_length); | |
1688 } | |
1689 else | |
1690 { | |
1691 /* location information not available */ | |
1692 res_code[0] = STK_RES_BUSY_ME; | |
1693 res_code[1] = STK_RES_EXT_NO_SERVICE; | |
1694 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
1695 res_code, 2, NULL, 0); | |
1696 #ifdef _SIMULATION_ | |
1697 TRACE_EVENT("PLI: BCCH list not available"); | |
1698 #endif | |
1699 } | |
1700 } | |
1701 else | |
1702 { | |
1703 /* location information not available */ | |
1704 res_code[0] = STK_RES_BUSY_ME; | |
1705 res_code[1] = STK_RES_EXT_NO_SERVICE; | |
1706 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
1707 res_code, 2, NULL, 0); | |
1708 #ifdef _SIMULATION_ | |
1709 TRACE_EVENT("PLI: measurement not available"); | |
1710 #endif | |
1711 } | |
1712 sim_data.ext_sat_cmd = FALSE; | |
1713 break; | |
1714 case QLF_PLOI_DTT: | |
1715 /* | |
1716 * Date, Time and Timezone | |
1717 */ | |
1718 if ((sim_data.stk_profile[7] & SAT_TP8_PLI_DTT) EQ 0) | |
1719 { | |
1720 /* if not effective */ | |
1721 res_code[0] = STK_RES_ERR_NO_SUPPORT; | |
1722 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
1723 res_code, 1, NULL, 0); | |
1724 #ifdef _SIMULATION_ | |
1725 TRACE_EVENT("PLI: not supported in TP"); | |
1726 #endif | |
1727 break; | |
1728 } | |
1729 /* | |
1730 * Operations processed by MMI / MFW | |
1731 */ | |
1732 sim_data.ext_sat_cmd = TRUE; | |
1733 PSENDX (MMI, sim_toolkit_ind); | |
1734 break; | |
1735 case QLF_PLOI_LANG_SET: | |
1736 /* | |
1737 * Language Setting to be supported (to be processed by ACI) | |
1738 */ | |
1739 if ((sim_data.stk_profile[8] & SAT_TP9_PLI_LANG) EQ 0) | |
1740 { | |
1741 /* if not effective */ | |
1742 res_code[0] = STK_RES_ERR_NO_SUPPORT; | |
1743 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
1744 res_code, 1, NULL, 0); | |
1745 #ifdef _SIMULATION_ | |
1746 TRACE_EVENT("language setting not supported"); | |
1747 #endif | |
1748 break; | |
1749 } | |
1750 /* | |
1751 * To be processed by ACI | |
1752 */ | |
1753 sim_data.sat_session = TRUE; | |
1754 sim_data.ext_sat_cmd = TRUE; | |
1755 PSENDX (MMI, sim_toolkit_ind); | |
1756 break; | |
1757 | |
1758 case QLF_PLOI_TIM_ADV: | |
1759 | |
1760 if ((sat_tp_sim_enabled[8] & SAT_TP9_PLI_TIMING_ADV) EQ 0) | |
1761 { | |
1762 res_code[0] = STK_RES_ERR_NO_SUPPORT; | |
1763 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
1764 res_code, 1, NULL, 0); | |
1765 #ifdef _SIMULATION_ | |
1766 TRACE_EVENT("PLI: timing advance not supported"); | |
1767 #endif | |
1768 } | |
1769 else | |
1770 { | |
1771 memset (&tim_adv, 0, sizeof(T_TIM_ADV)); | |
1772 memcpy (p->response, p_cmd, cmd_len); | |
1773 memcpy (&p->response[cmd_len], &terminal_response_timingadv[5], 11); | |
1774 #ifdef _SIMULATION_ | |
1775 p->response[cmd_len+ 6] = res_code[0]; | |
1776 resp_len = cmd_len + 11; | |
1777 #else | |
1778 if(cl_shrd_get_tim_adv (&tim_adv) EQ TRUE) | |
1779 { | |
1780 | |
1781 | |
1782 p->response[cmd_len+9] = tim_adv.me_status; | |
1783 p->response[cmd_len+10] = tim_adv.tm_adv; | |
1784 /* | |
1785 * Set result code. | |
1786 */ | |
1787 p->response[cmd_len+ 6] = res_code[0]; | |
1788 resp_len = cmd_len + 11; | |
1789 } | |
1790 else | |
1791 { | |
1792 res_code[0] = STK_RES_BUSY_ME; | |
1793 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
1794 res_code, 1, NULL, 0); | |
1795 #ifdef _SIMULATION_ | |
1796 TRACE_EVENT("PLI: Timing Advance not available"); | |
1797 #endif | |
1798 } | |
1799 #endif /* _SIMULATION_ */ | |
1800 } | |
1801 | |
1802 sim_data.ext_sat_cmd = FALSE; | |
1803 break; | |
1804 default: | |
1805 /* | |
1806 * no valid command qualifier | |
1807 */ | |
1808 res_code[0] = STK_RES_ERR_CMD_TYPE; | |
1809 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
1810 res_code, 1, NULL, 0); | |
1811 #ifdef _SIMULATION_ | |
1812 TRACE_EVENT("PLI: type not understood"); | |
1813 #endif | |
1814 sim_data.ext_sat_cmd = FALSE; | |
1815 break; | |
1816 } | |
1817 if (!sim_data.ext_sat_cmd) /* may depend on Command Qualifier */ | |
1818 { | |
1819 FKT_TerminalResponse (p->response, (USHORT)resp_len); | |
1820 PFREE (sim_toolkit_ind); | |
1821 } | |
1822 break; | |
1823 | |
1824 case STK_REFRESH: | |
1825 /* | |
1826 * process SIM REFRESH according to command qualifier | |
1827 */ | |
1828 TRACE_EVENT("process SIM REFRESH according to command qualifier"); | |
1829 | |
1830 /* MALLOC area for CONTEXT SWITCH */ | |
1831 if ( sim_data.context_switch_ptr != NULL ) | |
1832 { | |
1833 TRACE_EVENT("ERROR!! context_switch_ptr should be NULL - freeing"); | |
1834 MFREE ( sim_data.context_switch_ptr ); | |
1835 sim_data.context_switch_ptr = NULL; | |
1836 } | |
1837 MALLOC (sim_data.context_switch_ptr, sizeof (T_CONTEXT_SWITCH)); | |
1838 memset ( sim_data.context_switch_ptr,0, sizeof (T_CONTEXT_SWITCH)); | |
1839 | |
1840 /* Set sig_ptr to handle required signal */ | |
1841 #ifdef TI_PS_FF_AT_P_CMD_CUST | |
1842 if (sim_data.cust_mode EQ 1) | |
1843 { | |
1844 /* Cust_Mode 1 operation setup*/ | |
1845 PALLOC(copy_sim_toolkit_ind,SIM_TOOLKIT_IND); | |
1846 memcpy(copy_sim_toolkit_ind,sim_toolkit_ind,sizeof(T_SIM_TOOLKIT_IND)); | |
1847 sim_data.context_switch_ptr->sig_ptr = copy_sim_toolkit_ind; | |
1848 } | |
1849 else | |
1850 { | |
1851 /*default operation setup*/ | |
1852 sim_data.context_switch_ptr->sig_ptr = sim_toolkit_ind; | |
1853 } | |
1854 #else | |
1855 /*default operation setup*/ | |
1856 sim_data.context_switch_ptr->sig_ptr = sim_toolkit_ind; | |
1857 #endif /* TI_PS_FF_AT_P_CMD_CUST */ | |
1858 | |
1859 /* Save decoding of original sim_toolkit_ind signal processed by stk_proactive_polling */ | |
1860 offset = (long)found_tag[2] - (long)sim_toolkit_ind; | |
1861 sim_data.context_switch_ptr->tag2 = (UBYTE *)(sim_data.context_switch_ptr->sig_ptr) + offset; | |
1862 sim_data.context_switch_ptr->fl_len = fl_len; | |
1863 offset = (long)p_cmd - (long)sim_toolkit_ind; | |
1864 sim_data.context_switch_ptr->p_cmd = (UBYTE *)(sim_data.context_switch_ptr->sig_ptr) + offset; | |
1865 sim_data.context_switch_ptr->cmd_len = cmd_len; | |
1866 sim_data.context_switch_ptr->res_code[0]=res_code[0]; | |
1867 sim_data.context_switch_ptr->res_code[1]=res_code[1]; | |
1868 | |
1869 #ifdef TI_PS_FF_AT_P_CMD_CUST | |
1870 /* functionality is depended on cust_mode */ | |
1871 if (sim_data.cust_mode EQ 1) | |
1872 { | |
1873 /* Cust_Mode 1 operation */ | |
1874 sim_data.user_confirmation_expected = TRUE; | |
1875 | |
1876 /*send Refresh command to MMI*/ | |
1877 PSENDX (MMI, sim_toolkit_ind); | |
1878 | |
1879 /*REFRESH COMMAND NOW PROCESSED IN stk_sim_refresh_user_res() */ | |
1880 /*note: stk_sim_refresh_user_res() will call process_sim_refresh() */ | |
1881 /* This routine will free sig_ptr, user must free the */ | |
1882 /* context_switch. */ | |
1883 | |
1884 /*Terminate Command */ | |
1885 break; | |
1886 } | |
1887 | |
1888 else | |
1889 { | |
1890 /* sim_data.cust_mode EQ 0 */ | |
1891 /* process default operation */ | |
1892 if ( process_sim_refresh(sim_data.context_switch_ptr) ) | |
1893 { | |
1894 /* processed a SIM_RESET. Special case - exit stk_proactive_polling()*/ | |
1895 MFREE(p); | |
1896 /* this thread has finished with the context switch so free it. */ | |
1897 MFREE (sim_data.context_switch_ptr); | |
1898 sim_data.context_switch_ptr = NULL; | |
1899 return; /* exit from stk_proactive_polling() */ | |
1900 } | |
1901 else | |
1902 { | |
1903 /* process_sim_refresh() frees signal sim_data.context_switch_ptr->sig_ptr */ | |
1904 /* this thread has finished with the context switch so free it. */ | |
1905 MFREE (sim_data.context_switch_ptr); | |
1906 sim_data.context_switch_ptr = NULL; | |
1907 } | |
1908 } | |
1909 #else | |
1910 /* sim_data.cust_mode EQ 0 */ | |
1911 /* process default operation */ | |
1912 if ( process_sim_refresh(sim_data.context_switch_ptr) ) | |
1913 { | |
1914 /* processed a SIM_RESET. Special case - exit stk_proactive_polling()*/ | |
1915 MFREE(p); | |
1916 /* this thread has finished with the context switch so free it. */ | |
1917 MFREE (sim_data.context_switch_ptr); | |
1918 sim_data.context_switch_ptr = NULL; | |
1919 return; /* exit from stk_proactive_polling() */ | |
1920 } | |
1921 else | |
1922 { | |
1923 /* process_sim_refresh() frees signal sim_data.context_switch_ptr->sig_ptr */ | |
1924 /* this thread has finished with the context switch so free it. */ | |
1925 MFREE (sim_data.context_switch_ptr); | |
1926 sim_data.context_switch_ptr = NULL; | |
1927 } | |
1928 #endif /* TI_PS_FF_AT_P_CMD_CUST */ | |
1929 break; //end of case STK_REFRESH | |
1930 | |
1931 #ifdef FF_SAT_E | |
1932 case STK_RECEIVE_DATA: | |
1933 if (stk_dti_bip_receive_data((T_sdu*)&sim_toolkit_ind->stk_cmd, res_code[0])) | |
1934 { | |
1935 /* | |
1936 * message contains TLV elements to display | |
1937 * so forward it to MMI | |
1938 */ | |
1939 sim_data.sat_session = TRUE; | |
1940 | |
1941 TRACE_EVENT("SEND receive data indication to MMI"); | |
1942 PSENDX (MMI, sim_toolkit_ind); | |
1943 TRACE_EVENT("receive data indication to MMI sent"); | |
1944 } | |
1945 else | |
1946 { | |
1947 PFREE (sim_toolkit_ind); | |
1948 } | |
1949 break; | |
1950 | |
1951 case STK_SEND_DATA: | |
1952 if (stk_dti_bip_send_data((T_sdu*)&sim_toolkit_ind->stk_cmd)) | |
1953 { | |
1954 /* | |
1955 * message contains TLV elements to display | |
1956 * so forward it to MMI | |
1957 */ | |
1958 sim_data.sat_session = TRUE; | |
1959 PSENDX (MMI, sim_toolkit_ind); | |
1960 } | |
1961 else | |
1962 { | |
1963 PFREE (sim_toolkit_ind); | |
1964 } | |
1965 break; | |
1966 #endif /* FF_SAT_E */ | |
1967 | |
1968 case STK_TIMER_MANAGEMENT: | |
1969 { | |
1970 UBYTE tag_tv[8] = {STK_TIMER_ID_TAG|STK_COMPREHENSION_REQUIRED, STK_TIMER_ID_LEN, 0, | |
1971 STK_TIMER_VALUE_TAG, STK_TIMER_VALUE_LEN, | |
1972 0, 0 ,0}; | |
1973 tag_tv[2] = found_tag[2][0]; | |
1974 | |
1975 if ((unsigned)(i = (int)found_tag[2][0] - 1) >= MAX_SAT_TIMER) | |
1976 { /* invalid Timer identifier */ | |
1977 res_code[0] = STK_RES_ERR_CMD_DATA; | |
1978 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
1979 res_code, 1, NULL, 0); | |
1980 #ifdef _SIMULATION_ | |
1981 TRACE_EVENT("stk_build_response No 17"); | |
1982 #endif | |
1983 } | |
1984 /* | |
1985 * Process TIMER MANAGEMENT according to command qualifier | |
1986 */ | |
1987 else switch (cmd_qual) | |
1988 { | |
1989 case 0: | |
1990 if (found_tag[3] EQ NULL) | |
1991 { | |
1992 res_code[0] = STK_RES_ERR_MISS_VALUE; | |
1993 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
1994 res_code, 1, NULL, 0); | |
1995 #ifdef _SIMULATION_ | |
1996 TRACE_EVENT("TM: missing parameters"); | |
1997 #endif | |
1998 break; | |
1999 } | |
2000 /* translate timer value into unit of seconds */ | |
2001 tm_val = ((T_TIME)BCD2INT(found_tag[3][0]) * 60 + // hours | |
2002 (T_TIME)BCD2INT(found_tag[3][1])) * 60 + // minutes | |
2003 (T_TIME)BCD2INT(found_tag[3][2]); // seconds | |
2004 //TISH, patch for OMAPS00115011, 2007-02-12 | |
2005 //start | |
2006 if (tm_val==0) | |
2007 { | |
2008 res_code[0] = STK_RES_ERR_CMD_DATA; | |
2009 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
2010 res_code, 1, NULL, 0); | |
2011 TRACE_ERROR("TR wrong tm value"); | |
2012 break; | |
2013 } | |
2014 //end | |
2015 sim_data.timer[i].hour = found_tag[3][0]; | |
2016 sim_data.timer[i].minute = found_tag[3][1]; | |
2017 sim_data.timer[i].second = found_tag[3][2]; | |
2018 | |
2019 TIMER_START (sim_handle, (USHORT)(i+1), (tm_val * 1000 - TIMER_LATENCY)); | |
2020 sim_data.timer[i].active = TRUE; | |
2021 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
2022 res_code, 1, tag_tv, 3); | |
2023 #ifdef _SIMULATION_ | |
2024 TRACE_EVENT("TM: set timer"); | |
2025 #endif | |
2026 break; | |
2027 case 1: | |
2028 case 2: | |
2029 if (sim_data.timer[i].active) | |
2030 { | |
2031 TIMER_STATUS (sim_handle, (USHORT)(i + 1), &tm_val); | |
2032 tm_val /= 1000; | |
2033 tag_tv[7] = INT2BCD((UBYTE)(tm_val % 60)); | |
2034 tm_val /= 60; | |
2035 tag_tv[6] = INT2BCD((UBYTE)(tm_val % 60)); | |
2036 tm_val /= 60; | |
2037 if (tm_val < 24) | |
2038 tag_tv[5] = INT2BCD((UBYTE)tm_val); | |
2039 else | |
2040 { // set maximum value | |
2041 tag_tv[7] = tag_tv[6] = 0x59; | |
2042 tag_tv[5] = 0x23; | |
2043 } | |
2044 if (cmd_qual EQ 1) /* timer to be stopped */ | |
2045 { | |
2046 TIMER_STOP (sim_handle, (USHORT)(i + 1)); | |
2047 sim_data.timer[i].active = FALSE; | |
2048 } | |
2049 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
2050 res_code, 1, tag_tv, 8); | |
2051 #ifdef _SIMULATION_ | |
2052 TRACE_EVENT("TM: stop/query timer"); | |
2053 #endif | |
2054 } | |
2055 else | |
2056 { | |
2057 res_code[0] = STK_RES_BUSY_TIMER_STATE; | |
2058 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
2059 res_code, 1, NULL, 0); | |
2060 #ifdef _SIMULATION_ | |
2061 TRACE_EVENT("TM: timer not running"); | |
2062 #endif | |
2063 } | |
2064 break; | |
2065 default: | |
2066 /* | |
2067 * not supported information request | |
2068 */ | |
2069 res_code[0] = STK_RES_ERR_CMD_TYPE; | |
2070 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
2071 res_code, 1, NULL, 0); | |
2072 #ifdef _SIMULATION_ | |
2073 TRACE_EVENT("TM: unknown qualifier"); | |
2074 #endif | |
2075 break; | |
2076 } | |
2077 FKT_TerminalResponse (p->response, (USHORT)resp_len); | |
2078 PFREE (sim_toolkit_ind); | |
2079 break; | |
2080 } | |
2081 default: | |
2082 result = FALSE; | |
2083 res_code[0] = STK_RES_ERR_CMD_TYPE; /* command type not understood */ | |
2084 /* | |
2085 * fall through | |
2086 */ | |
2087 case STK_POLLING_OFF: | |
2088 /* | |
2089 * SIM toolkit cancels the effect of a previous | |
2090 * POLL INTERVAL command. Polling of the SIM | |
2091 * toolkit is done now all thirty seconds with the | |
2092 * STATUS command, when in a call. | |
2093 */ | |
2094 if (result AND SIM_IS_FLAG_SET (PRO_ACTIVE_SIM)) | |
2095 { | |
2096 TRACE_EVENT("Idle Polling switched off"); | |
2097 sim_data.idle_polling = FALSE; | |
2098 /* there will not be a status command after this .so just force one status command to enable sleep */ | |
2099 startTimerPollOff = TRUE; | |
2100 if(SIM_IS_FLAG_SET(CALL_ACTIVE)) | |
2101 { | |
2102 /* SIM_TIMER will be restarted, during a call, for | |
2103 * presence detection | |
2104 */ | |
2105 sim_data.status_time = THIRTY_SECONDS; | |
2106 } | |
2107 else | |
2108 { | |
2109 /* timer value set to max, for with a '0', the timer would | |
2110 run for about one tick | |
2111 */ | |
2112 sim_data.status_time = 0xFFFFFFFF; | |
2113 TIMER_STOP (sim_handle, SIM_TIMER); | |
2114 } | |
2115 | |
2116 } | |
2117 case STK_MORE_TIME: | |
2118 /* | |
2119 * SIM toolkit needs more time. | |
2120 * SIM application sends terminal response with OK. | |
2121 */ | |
2122 resp_len = stk_build_response (p->response, p_cmd, cmd_len, | |
2123 res_code, 1, NULL, 0); | |
2124 #ifdef _SIMULATION_ | |
2125 TRACE_EVENT("MORE_TIME"); | |
2126 #endif | |
2127 FKT_TerminalResponse (p->response, (USHORT)resp_len); | |
2128 PFREE (sim_toolkit_ind); | |
2129 break; | |
2130 } | |
2131 } | |
2132 else | |
2133 { | |
2134 #ifdef _SIMULATION_ | |
2135 TRACE_EVENT("FKT_Fetch_NEQ_SIM_NO_ERROR"); | |
2136 #endif | |
2137 PFREE (sim_toolkit_ind); | |
2138 } | |
2139 MFREE (p); | |
2140 | |
2141 if (vsi_c_status (VSI_CALLER &in_queue, &out_queue) EQ VSI_OK) | |
2142 { | |
2143 if (in_queue > 0) break; /* break while */ | |
2144 } | |
2145 } /* END while */ | |
2146 /* | |
2147 * send end of SAT session indicator | |
2148 */ | |
2149 TRACE_FUNCTION ("stk_proactive_polling() send end of SAT session indicator"); | |
2150 if ((sim_data.term_resp_sent) AND (sim_data.sat_session)) | |
2151 { | |
2152 PALLOC (sim_toolkit_ind, SIM_TOOLKIT_IND); | |
2153 memset (sim_toolkit_ind, 0, sizeof (T_SIM_TOOLKIT_IND)); | |
2154 #ifdef _SIMULATION_ | |
2155 TRACE_EVENT("SAT session ended"); | |
2156 #endif | |
2157 sim_data.sat_session = FALSE; | |
2158 sim_data.term_resp_sent = FALSE; | |
2159 PSENDX (MMI, sim_toolkit_ind); | |
2160 } | |
2161 } | |
2162 TRACE_FUNCTION ("stk_proactive_polling() exited"); | |
2163 } | |
2164 | |
2165 | |
2166 | |
2167 | |
2168 /* | |
2169 +--------------------------------------------------------------------+ | |
2170 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
2171 | STATE : code ROUTINE : stk_stop_all_sat_timers | | |
2172 +--------------------------------------------------------------------+ | |
2173 | |
2174 PURPOSE : Stop all timers started by TIMER MANAGEMENT, if running. | |
2175 Required when card is deactivated or reset. | |
2176 | |
2177 */ | |
2178 | |
2179 GLOBAL void stk_stop_all_sat_timers (void) | |
2180 { | |
2181 int i; | |
2182 | |
2183 for (i = 0; i < MAX_SAT_TIMER; i++) | |
2184 { | |
2185 if (sim_data.timer[i].active) | |
2186 { | |
2187 TIMER_STOP (sim_handle, (USHORT)(i + 1)); | |
2188 sim_data.timer[i].active = FALSE; | |
2189 } | |
2190 } | |
2191 } | |
2192 | |
2193 /* | |
2194 +--------------------------------------------------------------------+ | |
2195 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
2196 | STATE : code ROUTINE : stk_start_timer_and_poll | | |
2197 +--------------------------------------------------------------------+ | |
2198 | |
2199 PURPOSE : Start STATUS timer and control SIM Toolkit Polling | |
2200 | |
2201 */ | |
2202 | |
2203 LOCAL void stk_start_timer_and_poll (void) | |
2204 { | |
2205 T_TIME t_val; | |
2206 /* | |
2207 * start status timer if SIM is inserted | |
2208 * for periodic status polling of SIM Toolkit | |
2209 */ | |
2210 if ((SIM_IS_FLAG_SET (PRO_ACTIVE_SIM) AND | |
2211 sim_data.idle_polling AND | |
2212 SIM_IS_FLAG_CLEARED (TEST_MODE_POLLING)) OR | |
2213 SIM_IS_FLAG_SET (CALL_ACTIVE)) | |
2214 { | |
2215 /* | |
2216 * Start Status Polling | |
2217 */ | |
2218 t_val = (SIM_IS_FLAG_SET (CALL_ACTIVE) AND | |
2219 sim_data.status_time > THIRTY_SECONDS)? | |
2220 THIRTY_SECONDS: sim_data.status_time; | |
2221 | |
2222 TIMER_PSTART (sim_handle, SIM_TIMER, t_val, t_val); | |
2223 } | |
2224 sim_data.chk_sat_avail = TRUE; | |
2225 // stk_proactive_polling(); | |
2226 } | |
2227 | |
2228 #ifdef FF_SAT_E | |
2229 /* | |
2230 +--------------------------------------------------------------------+ | |
2231 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
2232 | STATE : code ROUTINE : stk_handle_ccd_error | | |
2233 +--------------------------------------------------------------------+ | |
2234 | |
2235 PURPOSE : Handle CCD error causes. | |
2236 | |
2237 */ | |
2238 | |
2239 LOCAL void stk_handle_ccd_error(UBYTE notOK, | |
2240 UBYTE* status, | |
2241 UBYTE* general_result, | |
2242 UBYTE* add_info_result) | |
2243 { | |
2244 UBYTE ccd_error; | |
2245 USHORT parameter_list[MAX_ERR_PAR]; | |
2246 TRACE_EVENT_P1("stk_handle_ccd_error(): %d", notOK); | |
2247 /* | |
2248 * handle errors in list | |
2249 */ | |
2250 memset (parameter_list, 0, sizeof(parameter_list)); | |
2251 ccd_error = ccd_getFirstError(CCDENT_SAT, parameter_list); | |
2252 | |
2253 if (notOK EQ ccdWarning) | |
2254 { | |
2255 while (ccd_error NEQ ERR_NO_MORE_ERROR) | |
2256 { | |
2257 switch (ccd_error) | |
2258 { | |
2259 case ERR_COMPREH_REQUIRED: | |
2260 /* | |
2261 * comprehension required | |
2262 */ | |
2263 TRACE_ERROR("CCD_WARNING=ERR_COMPREH_REQUIRED"); | |
2264 if (*status EQ SIM_CCD_OK) | |
2265 { | |
2266 *general_result = RSLT_UNKN_DATA; | |
2267 *add_info_result = ADD_NO_CAUSE; | |
2268 *status = SIM_CCD_RETURN; | |
2269 } | |
2270 break; | |
2271 | |
2272 case ERR_IE_NOT_EXPECTED: | |
2273 /* | |
2274 * unexpected element | |
2275 */ | |
2276 TRACE_ERROR("CCD_WARNING=ERR_IE_NOT_EXPECTED"); | |
2277 if (*status EQ SIM_CCD_OK) | |
2278 { | |
2279 *general_result = RSLT_PERF_PART_CMPR; | |
2280 *add_info_result = ADD_NO_CAUSE; | |
2281 } | |
2282 break; | |
2283 | |
2284 case ERR_MAND_ELEM_MISS: | |
2285 /* | |
2286 * mandatory elements missing | |
2287 */ | |
2288 TRACE_ERROR("CCD_WARNING=ERR_MAND_ELEM_MISS"); | |
2289 *general_result = RSLT_ERR_REQ_VAL; | |
2290 *add_info_result = ADD_NO_CAUSE; | |
2291 *status = SIM_CCD_RETURN; | |
2292 break; | |
2293 | |
2294 case ERR_MSG_LEN: | |
2295 TRACE_ERROR("CCD_WARNING=ERR_MSG_LEN (TC_509B)"); | |
2296 *general_result = RSLT_PERF_SUCCESS; | |
2297 *add_info_result = ADD_NO_CAUSE; | |
2298 *status = SIM_CCD_OK; | |
2299 break; | |
2300 | |
2301 default: | |
2302 TRACE_ERROR("CCD_WARNING ignored"); | |
2303 TRACE_EVENT_P1("ccd_error=0x%02X", ccd_error); | |
2304 break; | |
2305 } | |
2306 memset (parameter_list,0, sizeof(parameter_list)); | |
2307 ccd_error = ccd_getNextError (CCDENT_SAT, parameter_list); | |
2308 } | |
2309 } | |
2310 else /* ccdError */ | |
2311 { | |
2312 while (ccd_error NEQ ERR_NO_MORE_ERROR) | |
2313 { | |
2314 switch (ccd_error) | |
2315 { | |
2316 case ERR_COMPREH_REQUIRED: | |
2317 /* | |
2318 * comprehension required | |
2319 */ | |
2320 TRACE_ERROR("CCD_ERROR=ERR_COMPREH_REQUIRED"); | |
2321 if (*status EQ SIM_CCD_OK) | |
2322 { | |
2323 *general_result = RSLT_UNKN_DATA; | |
2324 *add_info_result = ADD_NO_CAUSE; | |
2325 *status = SIM_CCD_RETURN; | |
2326 } | |
2327 break; | |
2328 | |
2329 case ERR_IE_NOT_EXPECTED: | |
2330 /* | |
2331 * unexpected element | |
2332 */ | |
2333 TRACE_ERROR("CCD_ERROR=ERR_IE_NOT_EXPECTED"); | |
2334 if (*status EQ SIM_CCD_OK) | |
2335 { | |
2336 *general_result = RSLT_PERF_PART_CMPR; | |
2337 *add_info_result = ADD_NO_CAUSE; | |
2338 } | |
2339 break; | |
2340 | |
2341 case ERR_MAND_ELEM_MISS: | |
2342 /* | |
2343 * mandatory elements missing | |
2344 */ | |
2345 TRACE_ERROR("CCD_ERROR=ERR_MAND_ELEM_MISS"); | |
2346 *general_result = RSLT_ERR_REQ_VAL; | |
2347 *add_info_result = ADD_NO_CAUSE; | |
2348 *status = SIM_CCD_RETURN; | |
2349 break; | |
2350 | |
2351 case ERR_MSG_LEN: | |
2352 TRACE_ERROR("CCD_ERROR=ERR_MSG_LEN"); | |
2353 *general_result = RSLT_UNKN_DATA; | |
2354 *add_info_result = ADD_NO_CAUSE; | |
2355 *status = SIM_CCD_DISCARD; | |
2356 break; | |
2357 | |
2358 default: | |
2359 TRACE_ERROR("CCD_ERROR ignored"); | |
2360 TRACE_EVENT_P1("ccd_error=0x%02X", ccd_error); | |
2361 break; | |
2362 } | |
2363 memset (parameter_list,0, sizeof(parameter_list)); | |
2364 ccd_error = ccd_getNextError (CCDENT_SAT, parameter_list); | |
2365 } | |
2366 } | |
2367 } | |
2368 /* | |
2369 +--------------------------------------------------------------------+ | |
2370 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
2371 | STATE : code ROUTINE : stk_bip_decode_stk_command | | |
2372 +--------------------------------------------------------------------+ | |
2373 | |
2374 PURPOSE : First step of decoding SEND DATA and RECEIVE DATA message. | |
2375 | |
2376 */ | |
2377 | |
2378 LOCAL void stk_bip_decode_stk_command(T_sdu* message, | |
2379 T_cmd_details* cmd_details, | |
2380 UBYTE* status, | |
2381 UBYTE* general_result, | |
2382 UBYTE* add_info_result) | |
2383 { | |
2384 UBYTE ccdRet; | |
2385 MCAST(stk_cmd, STK_CMD); | |
2386 memset(stk_cmd, 0, sizeof(T_STK_CMD)); | |
2387 /* | |
2388 * decode toolkit command | |
2389 */ | |
2390 ccdRet = ccd_decodeMsg (CCDENT_SAT, | |
2391 DOWNLINK, | |
2392 (T_MSGBUF *) message, | |
2393 (UBYTE *) _decodedMsg, | |
2394 STK_CMD); | |
2395 | |
2396 #ifdef _SIMULATION_ | |
2397 TRACE_EVENT_P1("ccdRet@bip_decode_stk_command: %d", ccdRet); | |
2398 #endif | |
2399 | |
2400 if ((stk_cmd->v_pas_cmd) AND (stk_cmd->pas_cmd.v_cmd_details)) | |
2401 { | |
2402 /* | |
2403 * store command details | |
2404 */ | |
2405 *cmd_details = stk_cmd->pas_cmd.cmd_details; | |
2406 | |
2407 if (ccdRet NEQ ccdOK) | |
2408 { | |
2409 /* | |
2410 * handle errors in list | |
2411 */ | |
2412 stk_handle_ccd_error(ccdRet, status, general_result, add_info_result); | |
2413 } | |
2414 if ((stk_cmd->pas_cmd.v_cmd_prms EQ FALSE) OR | |
2415 (stk_cmd->pas_cmd.v_dev_ids EQ FALSE)) | |
2416 { | |
2417 /* | |
2418 * no Channel Data (Length) element present or | |
2419 * no Device Identities element present | |
2420 * Error, required values are missing | |
2421 */ | |
2422 *general_result = RSLT_ERR_REQ_VAL; | |
2423 *add_info_result = ADD_NO_CAUSE; | |
2424 *status = SIM_CCD_RETURN; | |
2425 } | |
2426 if (*status EQ SIM_CCD_OK) | |
2427 { | |
2428 int i = 0; | |
2429 while (tbl_device_src_id[i]) | |
2430 { | |
2431 if (stk_cmd->pas_cmd.dev_ids.dest_dev EQ tbl_device_src_id[i]) | |
2432 break; | |
2433 | |
2434 i++; | |
2435 } | |
2436 if (tbl_device_src_id[i] EQ 0) | |
2437 { | |
2438 /* | |
2439 * device id not valid | |
2440 */ | |
2441 *general_result = RSLT_UNKN_DATA; | |
2442 *add_info_result = ADD_NO_CAUSE; | |
2443 *status = SIM_CCD_RETURN; | |
2444 } | |
2445 else if /* norm sim_data.bip_ch_id for 11.14/12.7 conform */ | |
2446 ((sim_data.bip_state EQ SIM_BIP_CLOSED) OR | |
2447 (stk_cmd->pas_cmd.dev_ids.dest_dev NEQ (sim_data.bip_ch_id | 0x020))) | |
2448 { | |
2449 /* | |
2450 * BIP error, Channel identifier not valid | |
2451 */ | |
2452 *general_result = RSLT_BEARIND_PERR; | |
2453 *add_info_result = ADD_BIP_CHANID_NT_VLD; | |
2454 *status = SIM_CCD_RETURN; | |
2455 } | |
2456 else | |
2457 { | |
2458 /* | |
2459 * store command parameters | |
2460 */ | |
2461 sim_data.bip_cmd_prms = stk_cmd->pas_cmd.cmd_prms; | |
2462 } | |
2463 } | |
2464 } | |
2465 else | |
2466 { | |
2467 /* | |
2468 * incomplete message | |
2469 */ | |
2470 *general_result = RSLT_ERR_REQ_VAL; | |
2471 *add_info_result = ADD_NO_CAUSE; | |
2472 *status = SIM_CCD_RETURN; | |
2473 /* | |
2474 * set Command Details object values to 0x00 | |
2475 */ | |
2476 cmd_details->cmd_nr = 0; | |
2477 cmd_details->cmd_typ = 0; | |
2478 cmd_details->cmd_qlf = 0; | |
2479 } | |
2480 } /* stk_bip_decode_stk_command */ | |
2481 | |
2482 /* | |
2483 +-----------------------------------------------------------------------------+ | |
2484 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
2485 | STATE : code ROUTINE : stk_dti_send_data | | |
2486 +-----------------------------------------------------------------------------+ | |
2487 | |
2488 PURPOSE : Create and send a DTI Data primitive. | |
2489 | |
2490 */ | |
2491 | |
2492 LOCAL void stk_dti_send_data() | |
2493 { | |
2494 T_desc2* temp_desc1; | |
2495 /* | |
2496 * send DTI data primitive | |
2497 */ | |
2498 PALLOC_DESC2 (dti_data_ind, DTI2_DATA_IND); | |
2499 | |
2500 #ifdef _SIMULATION_ | |
2501 dti_data_ind->parameters.p_id = DTI_PID_UOS; | |
2502 dti_data_ind->parameters.st_lines.st_flow = DTI_FLOW_ON; | |
2503 dti_data_ind->parameters.st_lines.st_line_sa = DTI_SA_ON; | |
2504 dti_data_ind->parameters.st_lines.st_line_sb = DTI_SB_ON; | |
2505 dti_data_ind->parameters.st_lines.st_break_len = DTI_BREAK_OFF; | |
2506 #endif /* _SIMULATION_ */ | |
2507 switch(sim_data.con_type) | |
2508 { | |
2509 | |
2510 case SIM_CON_TYPE_UDP: | |
2511 MALLOC(temp_desc1, (USHORT)(sizeof(T_desc2) - 1 + | |
2512 sizeof(T_SRC_DES))); | |
2513 memcpy(temp_desc1->buffer, | |
2514 &sim_data.udp_parameters, | |
2515 sizeof(T_SRC_DES));/*lint !e419 Apparent data overrun for function*/ | |
2516 temp_desc1->len = sizeof(T_SRC_DES); | |
2517 temp_desc1->next = sim_data.data_to_send.first; | |
2518 sim_data.data_to_send.first = (ULONG)temp_desc1; | |
2519 sim_data.data_to_send.list_len+= temp_desc1->len; | |
2520 break; | |
2521 | |
2522 case SIM_CON_TYPE_IP: | |
2523 dti_data_ind->parameters.p_id = DTI_PID_IP; | |
2524 break; | |
2525 | |
2526 case SIM_CON_TYPE_SERIAL: | |
2527 dti_data_ind->parameters.st_lines.st_flow = DTI_FLOW_ON; | |
2528 dti_data_ind->parameters.st_lines.st_line_sa = DTI_SA_ON; | |
2529 dti_data_ind->parameters.st_lines.st_line_sb = DTI_SB_ON; | |
2530 dti_data_ind->parameters.st_lines.st_break_len = DTI_BREAK_OFF; | |
2531 break; | |
2532 } | |
2533 dti_data_ind->desc_list2 = sim_data.data_to_send; | |
2534 sim_data.data_to_send.first = (ULONG)NULL; | |
2535 sim_data.data_to_send.list_len = 0; | |
2536 dti_send_data(sim_data.hDTI, 0, 0, 0, dti_data_ind); | |
2537 } /* stk_dti_send_data() */ | |
2538 | |
2539 /* | |
2540 +-----------------------------------------------------------------------------+ | |
2541 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
2542 | STATE : code ROUTINE : stk_bip_send_data_terminal_response | | |
2543 +-----------------------------------------------------------------------------+ | |
2544 | |
2545 PURPOSE : Send a Terminal Response message for a SEND DATA message. | |
2546 | |
2547 */ | |
2548 | |
2549 LOCAL void stk_bip_send_data_terminal_response(UBYTE general_result, | |
2550 UBYTE add_info_result) | |
2551 { | |
2552 T_sdu* temp_sdu; | |
2553 UBYTE ccdRet; | |
2554 | |
2555 /* | |
2556 * memory for encoded message | |
2557 */ | |
2558 MALLOC(temp_sdu, (USHORT)(sizeof(T_sdu) - 1 + MAX_STK_CMD)); | |
2559 temp_sdu->l_buf = MAX_STK_CMD << 3; | |
2560 temp_sdu->o_buf = 0; | |
2561 | |
2562 CCD_START; | |
2563 { | |
2564 MCAST(term_resp, TERM_RESP); | |
2565 memset(term_resp, 0, sizeof(T_TERM_RESP)); | |
2566 | |
2567 /* | |
2568 * set Command details | |
2569 */ | |
2570 term_resp->v_cmd_details = TRUE; | |
2571 term_resp->cmd_details = sim_data.bip_tx_cmd_details; | |
2572 /* | |
2573 * set set Device identities | |
2574 */ | |
2575 term_resp->v_dev_ids = TRUE; | |
2576 term_resp->dev_ids.src_dev = DEV_SRC_ME; | |
2577 term_resp->dev_ids.dest_dev = DEV_DST_SIM; | |
2578 /* | |
2579 * set Result | |
2580 */ | |
2581 term_resp->v_res = TRUE; | |
2582 term_resp->res.gen = general_result; | |
2583 switch(general_result) | |
2584 { | |
2585 case RSLT_ME_UNAB_PROC: | |
2586 case RSLT_NTW_UNAB_PROC: | |
2587 case RSLT_LABRWS_GENERIC: | |
2588 case RSLT_SS_ERR: | |
2589 case RSLT_SMS_ERR: | |
2590 case RSLT_USSD_ERR: | |
2591 case RSLT_CC_SIM_PRM: | |
2592 case RSLT_BEARIND_PERR: | |
2593 /* | |
2594 * one byte for additional information | |
2595 */ | |
2596 term_resp->res.v_add = TRUE; | |
2597 term_resp->res.add.l_add = 1 << 3; | |
2598 term_resp->res.add.o_add = 0; | |
2599 term_resp->res.add.b_add[0] = add_info_result; | |
2600 break; | |
2601 } | |
2602 /* | |
2603 * set Channel Data Length | |
2604 */ | |
2605 term_resp->v_chan_dat_lth = TRUE; | |
2606 if ((SIM_CLASS_E_BUFFER_SIZE - sim_data.data_to_send.list_len) > 255) | |
2607 { | |
2608 /* | |
2609 * more than 255 bytes are available in TX buffer | |
2610 */ | |
2611 term_resp->chan_dat_lth = 0xff; | |
2612 } | |
2613 else | |
2614 { | |
2615 term_resp->chan_dat_lth = SIM_CLASS_E_BUFFER_SIZE - | |
2616 sim_data.data_to_send.list_len; | |
2617 } | |
2618 /* | |
2619 * encode message | |
2620 */ | |
2621 ccdRet = ccd_codeMsg (CCDENT_SAT, | |
2622 UPLINK, | |
2623 (T_MSGBUF *) temp_sdu, | |
2624 (UBYTE *) _decodedMsg, | |
2625 TERM_RESP); | |
2626 } | |
2627 CCD_END; | |
2628 /* | |
2629 * send Terminal Response | |
2630 */ | |
2631 if (ccdRet NEQ ccdOK) | |
2632 { | |
2633 TRACE_EVENT_P1("SEND DATA: CCD Coding Error: %d",ccdRet ); | |
2634 } | |
2635 else | |
2636 { | |
2637 FKT_TerminalResponse (temp_sdu->buf, (USHORT)(temp_sdu->l_buf >> 3)); | |
2638 } | |
2639 MFREE(temp_sdu); | |
2640 } /* stk_bip_send_data_terminal_response() */ | |
2641 | |
2642 /* | |
2643 +--------------------------------------------------------------------+ | |
2644 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
2645 | STATE : code ROUTINE : stk_close_dti_connection | | |
2646 +--------------------------------------------------------------------+ | |
2647 | |
2648 PURPOSE : Close DTI connection. | |
2649 | |
2650 PARAMETER: The open parameter indicates if the DTI connection is | |
2651 still open or already closed. | |
2652 | |
2653 */ | |
2654 | |
2655 LOCAL void stk_close_dti_connection(UBYTE close) | |
2656 { | |
2657 #ifdef _SIMULATION_ | |
2658 TRACE_FUNCTION ("stk_close_dti_connection()"); | |
2659 #endif | |
2660 #ifdef _SIMULATION_ | |
2661 TRACE_EVENT_P1(" |___-->: sim_data.dti_connection_state=0x%02X", sim_data.dti_connection_state); | |
2662 #endif | |
2663 if (sim_data.dti_connection_state NEQ SIM_DTI_CONNECTION_CLOSED) | |
2664 { | |
2665 /* | |
2666 * close UDP connection | |
2667 */ | |
2668 if (sim_data.con_type EQ SIM_CON_TYPE_UDP) | |
2669 { | |
2670 /* | |
2671 * close currently used port | |
2672 */ | |
2673 if ((sim_data.dti_connection_state NEQ SIM_DTI_CONNECTION_BIND) AND | |
2674 (hCommUDP >= VSI_OK)) | |
2675 { | |
2676 PALLOC(udp_closeport_req, UDP_CLOSEPORT_REQ); | |
2677 udp_closeport_req->port = sim_data.udp_parameters.src_port[0]; | |
2678 udp_closeport_req->port = (udp_closeport_req->port << 8); | |
2679 udp_closeport_req->port+= sim_data.udp_parameters.src_port[1]; | |
2680 PSEND(hCommUDP, udp_closeport_req); | |
2681 } | |
2682 /* | |
2683 * release VSI channel | |
2684 */ | |
2685 if (hCommUDP >= VSI_OK) | |
2686 { | |
2687 vsi_c_close (VSI_CALLER hCommUDP); | |
2688 } | |
2689 hCommUDP = VSI_ERROR; | |
2690 } | |
2691 /* | |
2692 * disconnect BIP channel | |
2693 */ | |
2694 if (sim_data.bip_state EQ SIM_BIP_CONNECTED) | |
2695 { | |
2696 sim_data.bip_state = SIM_BIP_OPEN; | |
2697 /* | |
2698 * stop release timer | |
2699 */ | |
2700 if (sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) | |
2701 { | |
2702 if (sim_data.bip_timer_state EQ SIM_BIP_TIMER_START) | |
2703 { | |
2704 #ifdef _SIMULATION_ | |
2705 TRACE_EVENT("SIM_BIP_TIMER: stopped"); | |
2706 #endif | |
2707 TIMER_STOP (sim_handle, SIM_BIP_TIMER); | |
2708 } | |
2709 sim_data.bip_timer_state = SIM_BIP_TIMER_DISCONNECTED; | |
2710 } | |
2711 } | |
2712 /* | |
2713 * close DTI connection | |
2714 */ | |
2715 sim_data.dti_connection_state = SIM_DTI_CONNECTION_CLOSED; | |
2716 if (close) | |
2717 { | |
2718 dti_close(sim_data.hDTI, 0, 0, 0, FALSE); | |
2719 } | |
2720 #ifdef _SIMULATION_ | |
2721 TRACE_EVENT_P1("stk_close_dti_connection: sim_data.dti_connection_state=0x%02X", sim_data.dti_connection_state); | |
2722 #endif | |
2723 } | |
2724 } /* stk_close_dti_connection() */ | |
2725 | |
2726 /* | |
2727 +--------------------------------------------------------------------+ | |
2728 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
2729 | STATE : code ROUTINE : stk_close_bip_channel | | |
2730 +--------------------------------------------------------------------+ | |
2731 | |
2732 PURPOSE : Close Bearer Independent Protocol Channel. | |
2733 | |
2734 */ | |
2735 | |
2736 LOCAL void stk_close_bip_channel(UBYTE general_result, | |
2737 UBYTE add_info_result) | |
2738 { | |
2739 T_desc2* temp_desc1; | |
2740 T_desc2* temp_desc2; | |
2741 | |
2742 if (sim_data.bip_state NEQ SIM_BIP_CLOSED) | |
2743 { | |
2744 /* | |
2745 * set BIP to close | |
2746 */ | |
2747 sim_data.bip_state = SIM_BIP_CLOSED; | |
2748 /* | |
2749 * stop release timer if used | |
2750 */ | |
2751 if (sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) | |
2752 { | |
2753 if (sim_data.bip_timer_state EQ SIM_BIP_TIMER_START) | |
2754 { | |
2755 #ifdef _SIMULATION_ | |
2756 TRACE_EVENT("SIM_BIP_TIMER: stopped"); | |
2757 #endif | |
2758 TIMER_STOP (sim_handle, SIM_BIP_TIMER); | |
2759 } | |
2760 sim_data.bip_timer_state = SIM_BIP_TIMER_DISCONNECTED; | |
2761 } | |
2762 /* | |
2763 * send Terminal Response | |
2764 */ | |
2765 if (sim_data.bip_tx_state EQ SIM_BIP_TX_SEND) | |
2766 { | |
2767 stk_bip_send_data_terminal_response(general_result, add_info_result); | |
2768 /* | |
2769 * close channel is not triggered from a proactive_polling function call | |
2770 * so adjust timer and start polling | |
2771 */ | |
2772 stk_start_timer_and_poll(); | |
2773 } | |
2774 /* | |
2775 * release suspension | |
2776 */ | |
2777 sim_data.bip_suspend = FALSE; | |
2778 /* | |
2779 * release RX and TX buffer | |
2780 */ | |
2781 temp_desc1 = (T_desc2*)sim_data.data_to_send.first; | |
2782 while(temp_desc1) | |
2783 { | |
2784 temp_desc2 = temp_desc1; | |
2785 temp_desc1 = (T_desc2*)temp_desc1->next; | |
2786 MFREE(temp_desc2); | |
2787 } | |
2788 sim_data.data_to_send.first = (ULONG)NULL; | |
2789 sim_data.data_to_send.list_len = 0; | |
2790 sim_data.prev_data_to_send.first = (ULONG)NULL; | |
2791 sim_data.prev_data_to_send.list_len = 0; | |
2792 #ifdef _SIMULATION_ | |
2793 TRACE_EVENT("bip_tx_state = IDLE"); | |
2794 #endif | |
2795 sim_data.bip_tx_state = SIM_BIP_TX_IDLE; | |
2796 temp_desc1 = (T_desc2*)sim_data.received_data.first; | |
2797 while(temp_desc1) | |
2798 { | |
2799 temp_desc2 = temp_desc1; | |
2800 temp_desc1 = (T_desc2*)temp_desc1->next; | |
2801 MFREE(temp_desc2); | |
2802 } | |
2803 sim_data.received_data.first = (ULONG)NULL; | |
2804 sim_data.received_data.list_len = 0; | |
2805 sim_data.received_data_pos = 0; | |
2806 #ifdef _SIMULATION_ | |
2807 TRACE_EVENT("bip_rx_state = IDLE"); | |
2808 #endif | |
2809 sim_data.bip_rx_state = SIM_BIP_RX_IDLE; | |
2810 } | |
2811 } /* stk_close_bip_channel() */ | |
2812 | |
2813 /* | |
2814 +--------------------------------------------------------------------+ | |
2815 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
2816 | STATE : code ROUTINE : stk_dti_inform_mmi | | |
2817 +--------------------------------------------------------------------+ | |
2818 | |
2819 PURPOSE : Informs MMI if the requested actions have been done. | |
2820 | |
2821 */ | |
2822 | |
2823 LOCAL void stk_dti_inform_mmi (UBYTE dti_conn_req, UBYTE bip_conn_req ) | |
2824 { | |
2825 UBYTE dti_conn_done; | |
2826 UBYTE bip_conn_done; | |
2827 #if _SIMULATION_ | |
2828 TRACE_FUNCTION ("stk_dti_inform_mmi()"); | |
2829 #endif | |
2830 /* | |
2831 * set stutus | |
2832 */ | |
2833 dti_conn_done = 0; | |
2834 bip_conn_done = 0; | |
2835 | |
2836 if (sim_data.bip_state EQ SIM_BIP_CLOSED) | |
2837 { | |
2838 bip_conn_done |= SIM_BIP_CLOSE_CHANNEL; | |
2839 } | |
2840 else | |
2841 { | |
2842 bip_conn_done |= SIM_BIP_OPEN_CHANNEL; | |
2843 /* | |
2844 * Only if BIP channel not closed, deal with its suspension state | |
2845 */ | |
2846 if (sim_data.bip_suspend) | |
2847 { | |
2848 bip_conn_done |= SIM_BIP_CHANNEL_SUSPENDED; | |
2849 } | |
2850 else | |
2851 { | |
2852 bip_conn_done |= SIM_BIP_CHANNEL_RESUMED; | |
2853 } | |
2854 } | |
2855 | |
2856 if (sim_data.dti_connection_state EQ SIM_DTI_CONNECTION_OPEN) | |
2857 { | |
2858 dti_conn_done = SIM_DTI_CONNECT; | |
2859 } | |
2860 | |
2861 if (sim_data.dti_connection_state EQ SIM_DTI_CONNECTION_CLOSED) | |
2862 { | |
2863 dti_conn_done = SIM_DTI_DISCONNECT; | |
2864 } | |
2865 | |
2866 /* | |
2867 * inform MMI | |
2868 */ | |
2869 if ( /* reguirements REALLY fullfilled in code, then confirm or indicate */ | |
2870 /* else no reaction at all !! */ | |
2871 (((bip_conn_req & bip_conn_done) EQ bip_conn_req) OR (bip_conn_req EQ SIM_BIP_UNKNOWN)) AND | |
2872 ((dti_conn_req EQ dti_conn_done)OR (dti_conn_req EQ SIM_DTI_UNKNOWN)) AND | |
2873 (~(UCHAR)((dti_conn_req EQ SIM_DTI_UNKNOWN) AND (bip_conn_req EQ SIM_BIP_UNKNOWN))) | |
2874 ) | |
2875 { | |
2876 if (sim_data.sim_dti_req) | |
2877 { | |
2878 /* | |
2879 * send DTI confirm primitive | |
2880 */ | |
2881 PALLOC(sim_dti_cnf, SIM_DTI_CNF); | |
2882 sim_dti_cnf->link_id = sim_data.sim_dti_req->link_id; | |
2883 sim_dti_cnf->dti_conn = dti_conn_done; | |
2884 PSEND(hCommMMI, sim_dti_cnf); | |
2885 /* | |
2886 * free request primitive | |
2887 */ | |
2888 PFREE(sim_data.sim_dti_req); | |
2889 sim_data.sim_dti_req = NULL; | |
2890 } | |
2891 else if (sim_data.sim_bip_req) | |
2892 { | |
2893 /* | |
2894 * send BIP confirm primitive | |
2895 */ | |
2896 PALLOC(sim_bip_cnf, SIM_BIP_CNF); | |
2897 sim_bip_cnf->bip_ch_id = sim_data.sim_bip_req->bip_ch_id; | |
2898 sim_bip_cnf->bip_conn = bip_conn_done; | |
2899 PSEND(hCommMMI, sim_bip_cnf); | |
2900 /* | |
2901 * free request primitive | |
2902 */ | |
2903 PFREE(sim_data.sim_bip_req); | |
2904 sim_data.sim_bip_req = NULL; | |
2905 } | |
2906 else | |
2907 { | |
2908 /* | |
2909 * send indication primitive | |
2910 */ | |
2911 PALLOC(sim_dti_bip_ind, SIM_DTI_BIP_IND); | |
2912 sim_dti_bip_ind->link_id = sim_data.link_id; | |
2913 sim_dti_bip_ind->dti_conn = dti_conn_done; | |
2914 sim_dti_bip_ind->bip_ch_id = sim_data.bip_ch_id; | |
2915 sim_dti_bip_ind->bip_conn = bip_conn_done; | |
2916 PSEND(hCommMMI, sim_dti_bip_ind); | |
2917 } | |
2918 } /* and if (requirements fullfilled) */ | |
2919 } /* stk_dti_inform_mmi() */ | |
2920 | |
2921 /* | |
2922 +--------------------------------------------------------------------+ | |
2923 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
2924 | STATE : code ROUTINE : stk_dti_connection_opened | | |
2925 +--------------------------------------------------------------------+ | |
2926 | |
2927 PURPOSE : Handle CONNECTION OPENED signal from DTILIB. | |
2928 | |
2929 */ | |
2930 | |
2931 GLOBAL void stk_dti_connection_opened (void) | |
2932 { | |
2933 TRACE_FUNCTION ("stk_dti_connection_opened()"); | |
2934 | |
2935 switch(sim_data.dti_connection_state) | |
2936 { | |
2937 case SIM_DTI_CONNECTION_SETUP: | |
2938 sim_data.dti_connection_state = SIM_DTI_CONNECTION_OPEN; | |
2939 /* | |
2940 * send confirm primitive | |
2941 */ | |
2942 stk_dti_inform_mmi(sim_data.sim_dti_req->dti_conn, (UBYTE) SIM_BIP_UNKNOWN); | |
2943 /* fall through */ | |
2944 case SIM_DTI_CONNECTION_OPEN: | |
2945 /* | |
2946 * connect BIP with DTI | |
2947 */ | |
2948 if (sim_data.bip_state EQ SIM_BIP_OPEN) | |
2949 { | |
2950 sim_data.bip_state = SIM_BIP_CONNECTED; | |
2951 if (sim_data.bip_release_time EQ SIM_NO_AUTO_RELEASE) | |
2952 { | |
2953 sim_data.bip_timer_state = SIM_BIP_TIMER_NOT_USED; | |
2954 } | |
2955 else if (sim_data.bip_suspend) | |
2956 { | |
2957 sim_data.bip_timer_state = SIM_BIP_TIMER_SUSPENDED; | |
2958 } | |
2959 else | |
2960 { | |
2961 sim_data.bip_timer_state = SIM_BIP_TIMER_STOPPED; | |
2962 } | |
2963 } | |
2964 break; | |
2965 | |
2966 default: | |
2967 /* | |
2968 * wrong state | |
2969 * so close DTI connection | |
2970 * and inform MMI | |
2971 */ | |
2972 TRACE_ERROR("DTI_CONNECTION_OPENED in wrong state"); | |
2973 stk_close_dti_connection(TRUE); | |
2974 stk_dti_inform_mmi(SIM_DTI_DISCONNECT, (UBYTE) SIM_BIP_UNKNOWN); | |
2975 break; | |
2976 } | |
2977 /* | |
2978 * reset RX, TX and timer | |
2979 */ | |
2980 sim_data.dti_rx_state = SIM_DTI_RX_IDLE; | |
2981 sim_data.dti_tx_state = SIM_DTI_TX_IDLE; | |
2982 #if 0 /*###jk:OK?*/ | |
2983 if (sim_data.bip_timer_state EQ SIM_BIP_TIMER_START) | |
2984 { | |
2985 sim_data.bip_timer_state = SIM_BIP_TIMER_STOPPED; | |
2986 #ifdef _SIMULATION_ | |
2987 TRACE_EVENT("SIM_BIP_TIMER: stopped"); | |
2988 #endif | |
2989 TIMER_STOP (sim_handle, SIM_BIP_TIMER); | |
2990 } | |
2991 /* | |
2992 * update timer and DTI states | |
2993 */ | |
2994 if ((sim_data.bip_state EQ SIM_BIP_CONNECTED) AND | |
2995 (sim_data.bip_rx_state EQ SIM_BIP_RX_IDLE)) | |
2996 { | |
2997 /* | |
2998 * start reception | |
2999 */ | |
3000 sim_data.dti_rx_state = SIM_DTI_RX_READY; | |
3001 dti_start(sim_data.hDTI, 0, 0, 0); | |
3002 /* | |
3003 * start timer | |
3004 */ | |
3005 if ((sim_data.bip_timer_state EQ SIM_BIP_TIMER_STOPPED) AND | |
3006 (sim_data.bip_tx_state EQ SIM_BIP_TX_IDLE) | |
3007 ) | |
3008 { | |
3009 /* | |
3010 * no data trafic on the BIP channel, | |
3011 * so use the timer | |
3012 */ | |
3013 sim_data.bip_timer_state = SIM_BIP_TIMER_START; | |
3014 #ifdef _SIMULATION_ | |
3015 TRACE_EVENT("SIM_BIP_TIMER: start in stk_dti_connection_opened()"); | |
3016 #endif | |
3017 TIMER_START (sim_handle, SIM_BIP_TIMER, sim_data.bip_release_time); | |
3018 } | |
3019 } | |
3020 #endif /*###jk:OK?*/ | |
3021 } /* stk_dti_connection_opened() */ | |
3022 | |
3023 /* | |
3024 +--------------------------------------------------------------------+ | |
3025 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
3026 | STATE : code ROUTINE : stk_dti_connection_closed | | |
3027 +--------------------------------------------------------------------+ | |
3028 | |
3029 PURPOSE : Handle CONNECTION CLOSED signal from DTILIB. | |
3030 | |
3031 */ | |
3032 | |
3033 GLOBAL void stk_dti_connection_closed (void) | |
3034 { | |
3035 TRACE_FUNCTION ("stk_dti_connection_closed()"); | |
3036 | |
3037 /* | |
3038 * close DTI connection | |
3039 */ | |
3040 stk_close_dti_connection(FALSE); | |
3041 /* | |
3042 * inform MMI about disconnection | |
3043 */ | |
3044 stk_dti_inform_mmi(SIM_DTI_DISCONNECT, (UBYTE) SIM_BIP_UNKNOWN); | |
3045 } /* stk_dti_connection_closed() */ | |
3046 | |
3047 /* | |
3048 +--------------------------------------------------------------------+ | |
3049 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
3050 | STATE : code ROUTINE : stk_dti_data_received | | |
3051 +--------------------------------------------------------------------+ | |
3052 | |
3053 PURPOSE : Deal with incomming DTI data primitives. | |
3054 | |
3055 */ | |
3056 | |
3057 GLOBAL void stk_dti_data_received (T_DTI2_DATA_IND* dti_data_ind) | |
3058 { | |
3059 UBYTE ccdRet; | |
3060 UBYTE dummy[4]; | |
3061 T_sdu* temp_sdu; | |
3062 T_desc2* temp_desc1; | |
3063 T_desc2* temp_desc2; | |
3064 | |
3065 TRACE_FUNCTION ("stk_dti_data_received()"); | |
3066 | |
3067 #ifdef _SIMULATION_ | |
3068 /* | |
3069 * copy bytes of T_SRC_DES struct in extra descriptor | |
3070 * this is a requirement of the DTI communication with UDP, but it should | |
3071 * not have any side affects in case of communication with other entities | |
3072 */ | |
3073 if ((dti_data_ind->desc_list2.first NEQ (ULONG)NULL) AND | |
3074 (dti_data_ind->desc_list2.list_len >= sizeof(T_SRC_DES))) | |
3075 { | |
3076 T_desc2 *old_desc, *addr_desc, *test_desc, *next_desc; | |
3077 USHORT i, j; | |
3078 | |
3079 old_desc = (T_desc2 *)dti_data_ind->desc_list2.first; | |
3080 | |
3081 /* | |
3082 * build the T_SRC_DES for IP-addresses and ports | |
3083 */ | |
3084 MALLOC(addr_desc, (USHORT)(sizeof(T_desc2) - 1 + sizeof(T_SRC_DES))); | |
3085 addr_desc->len = sizeof(T_SRC_DES); | |
3086 j = 0; | |
3087 for(i=0; i < addr_desc->len; i++) | |
3088 { | |
3089 while(j >= old_desc->len) | |
3090 { | |
3091 next_desc = (T_desc2*)old_desc->next; | |
3092 MFREE(old_desc); | |
3093 old_desc = next_desc; | |
3094 j = 0; | |
3095 } | |
3096 addr_desc->buffer[i] = old_desc->buffer[j]; | |
3097 j++; | |
3098 } | |
3099 | |
3100 /* | |
3101 * Build the desc for the data | |
3102 */ | |
3103 if (j < old_desc->len) | |
3104 { | |
3105 MALLOC(test_desc, (USHORT)(sizeof(T_desc2) - 1 + old_desc->len - j)); | |
3106 test_desc->len = old_desc->len - j; | |
3107 test_desc->next = old_desc->next; | |
3108 for(i=0; i < test_desc->len; i++) | |
3109 { | |
3110 test_desc->buffer[i] = old_desc->buffer[j]; | |
3111 j++; | |
3112 } | |
3113 } | |
3114 else | |
3115 { | |
3116 test_desc = (T_desc2*)old_desc->next; | |
3117 } | |
3118 MFREE(old_desc); | |
3119 | |
3120 dti_data_ind->desc_list2.first = (ULONG)addr_desc; | |
3121 addr_desc->next = (ULONG)test_desc; | |
3122 | |
3123 } | |
3124 #endif /* _SIMULATION_ */ | |
3125 /* | |
3126 * take data | |
3127 */ | |
3128 temp_desc1 = (T_desc2*)dti_data_ind->desc_list2.first; | |
3129 /* | |
3130 * free primitive | |
3131 */ | |
3132 PFREE(dti_data_ind); | |
3133 /* | |
3134 * | |
3135 */ | |
3136 switch(sim_data.con_type) | |
3137 { | |
3138 /* --67 asd; ###jk test error for image*/ | |
3139 case SIM_CON_TYPE_UDP: | |
3140 /* | |
3141 * free first descriptor | |
3142 */ | |
3143 temp_desc2 = temp_desc1; | |
3144 if (temp_desc1) | |
3145 { | |
3146 temp_desc1 = (T_desc2*)temp_desc1->next; | |
3147 } | |
3148 MFREE(temp_desc2); | |
3149 /* fall through */ | |
3150 case SIM_CON_TYPE_IP: | |
3151 /* | |
3152 * store data | |
3153 */ | |
3154 if (sim_data.received_data.first EQ (ULONG)NULL) | |
3155 { | |
3156 sim_data.received_data.first = (ULONG)temp_desc1; | |
3157 } | |
3158 else | |
3159 { | |
3160 /* | |
3161 * error | |
3162 * free received data | |
3163 */ | |
3164 TRACE_ERROR("DTI data received, but still data in RX buffer"); | |
3165 while(temp_desc1) | |
3166 { | |
3167 temp_desc2 = temp_desc1; | |
3168 temp_desc1 = (T_desc2*)temp_desc1->next; | |
3169 MFREE(temp_desc2); | |
3170 } | |
3171 temp_desc1 = NULL; | |
3172 } | |
3173 break; | |
3174 | |
3175 case SIM_CON_TYPE_SERIAL: | |
3176 /* | |
3177 * store data | |
3178 */ | |
3179 if (sim_data.received_data.first EQ (ULONG)NULL) | |
3180 { | |
3181 sim_data.received_data.first = (ULONG)temp_desc1; | |
3182 } | |
3183 else | |
3184 { | |
3185 /* | |
3186 * error, but concatinate data | |
3187 */ | |
3188 TRACE_ERROR("DTI data received, but still data in RX buffer"); | |
3189 /* | |
3190 * find last descriptor | |
3191 */ | |
3192 temp_desc2 = (T_desc2*)sim_data.received_data.first; | |
3193 while(temp_desc2->next NEQ (ULONG)NULL) | |
3194 { | |
3195 temp_desc2 = (T_desc2*)temp_desc2->next; | |
3196 } | |
3197 temp_desc2->next = (ULONG)temp_desc1; | |
3198 } | |
3199 break; | |
3200 } | |
3201 /* | |
3202 * update list length | |
3203 */ | |
3204 while(temp_desc1) | |
3205 { | |
3206 sim_data.received_data.list_len+= temp_desc1->len; | |
3207 temp_desc1 = (T_desc2*)temp_desc1->next; | |
3208 } | |
3209 | |
3210 if (sim_data.received_data.list_len) | |
3211 { | |
3212 /* | |
3213 * change state of BIP RX and stop timer | |
3214 */ | |
3215 #ifdef _SIMULATION_ | |
3216 TRACE_EVENT("bip_rx_state = DATA"); | |
3217 #endif | |
3218 sim_data.bip_rx_state = SIM_BIP_RX_DATA; | |
3219 if ((sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) AND | |
3220 (sim_data.bip_timer_state EQ SIM_BIP_TIMER_START) | |
3221 ) | |
3222 { | |
3223 sim_data.bip_timer_state = SIM_BIP_TIMER_STOPPED; | |
3224 #ifdef _SIMULATION_ | |
3225 TRACE_EVENT("SIM_BIP_TIMER: stopped"); | |
3226 #endif | |
3227 TIMER_STOP (sim_handle, SIM_BIP_TIMER); | |
3228 } | |
3229 /* | |
3230 * stop reception | |
3231 */ | |
3232 sim_data.dti_rx_state = SIM_DTI_RX_IDLE; | |
3233 dti_stop(sim_data.hDTI, 0, 0, 0); | |
3234 /* | |
3235 * inform SIM card | |
3236 */ | |
3237 if (sim_data.event_data_avail EQ SIM_EVENT_ENABLE) | |
3238 { | |
3239 CCD_START; | |
3240 { | |
3241 MCAST(env_cmd, ENV_CMD); | |
3242 memset(env_cmd, 0, sizeof(T_ENV_CMD)); | |
3243 | |
3244 /* | |
3245 * Event Download Command | |
3246 */ | |
3247 env_cmd->v_evd_cmd = TRUE; | |
3248 /* | |
3249 * Event List | |
3250 */ | |
3251 env_cmd->evd_cmd.v_ev_list = TRUE; | |
3252 env_cmd->evd_cmd.ev_list.c_event = 1; | |
3253 env_cmd->evd_cmd.ev_list.event[0] = EVENT_DATA_AVAIL; | |
3254 /* | |
3255 * Device Identities | |
3256 */ | |
3257 env_cmd->evd_cmd.v_dev_ids = TRUE; | |
3258 env_cmd->evd_cmd.dev_ids.src_dev = DEV_SRC_ME; | |
3259 env_cmd->evd_cmd.dev_ids.dest_dev = DEV_DST_SIM; | |
3260 /* | |
3261 * Channel Satus | |
3262 */ | |
3263 env_cmd->evd_cmd.v_chan_stat = TRUE; | |
3264 env_cmd->evd_cmd.chan_stat.chan_id = sim_data.bip_ch_id & 0x07; | |
3265 env_cmd->evd_cmd.chan_stat.chan_stat_inf1 = 0; | |
3266 env_cmd->evd_cmd.chan_stat.chan_stat_link = LINK_ESTABL; | |
3267 env_cmd->evd_cmd.chan_stat.chan_stat_inf2 = NO_FURTH_INFO; | |
3268 /* | |
3269 * Channel Data Length | |
3270 */ | |
3271 env_cmd->evd_cmd.v_chan_dat_lth = TRUE; | |
3272 if (sim_data.received_data.list_len > 255) | |
3273 { | |
3274 /* | |
3275 * more than 255 bytes are available in RX buffer | |
3276 */ | |
3277 env_cmd->evd_cmd.chan_dat_lth = 0xff; | |
3278 } | |
3279 else | |
3280 { | |
3281 env_cmd->evd_cmd.chan_dat_lth = (UBYTE)sim_data.received_data.list_len; | |
3282 } | |
3283 /* | |
3284 * encode message | |
3285 */ | |
3286 MALLOC(temp_sdu, (USHORT)(sizeof(T_sdu) - 1 + MAX_STK_CMD)); | |
3287 temp_sdu->l_buf = MAX_STK_CMD << 3; | |
3288 temp_sdu->o_buf = 0; | |
3289 | |
3290 ccdRet = ccd_codeMsg (CCDENT_SAT, | |
3291 UPLINK, | |
3292 (T_MSGBUF *) temp_sdu, | |
3293 (UBYTE *) _decodedMsg, | |
3294 ENV_CMD); | |
3295 } | |
3296 CCD_END; | |
3297 | |
3298 if ( ccdRet NEQ ccdOK ) | |
3299 { | |
3300 TRACE_EVENT_P1("Data Available: CCD Coding Error: %d",ccdRet ); | |
3301 } | |
3302 else | |
3303 { | |
3304 FKT_Envelope (dummy, temp_sdu->buf, (USHORT)(temp_sdu->l_buf >> 3), 0); | |
3305 /* | |
3306 * data received is not triggered from a proactive_polling | |
3307 * function call, so adjust timer and start polling | |
3308 */ | |
3309 stk_start_timer_and_poll(); | |
3310 } | |
3311 MFREE(temp_sdu); | |
3312 } | |
3313 } | |
3314 } /* stk_dti_data_received() */ | |
3315 | |
3316 /* | |
3317 +--------------------------------------------------------------------+ | |
3318 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
3319 | STATE : code ROUTINE : stk_dti_tx_buffer_full | | |
3320 +--------------------------------------------------------------------+ | |
3321 | |
3322 PURPOSE : Handle TX BUFFER FULL signal from DTILIB. | |
3323 | |
3324 */ | |
3325 | |
3326 GLOBAL void stk_dti_tx_buffer_full (void) | |
3327 { | |
3328 TRACE_FUNCTION ("stk_dti_tx_buffer_full()"); | |
3329 | |
3330 /* | |
3331 * set new DTI state | |
3332 */ | |
3333 sim_data.dti_tx_state = SIM_DTI_TX_IDLE; | |
3334 } /* stk_dti_tx_buffer_full() */ | |
3335 | |
3336 /* | |
3337 +--------------------------------------------------------------------+ | |
3338 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
3339 | STATE : code ROUTINE : stk_dti_tx_buffer_ready | | |
3340 +--------------------------------------------------------------------+ | |
3341 | |
3342 PURPOSE : Handle TX BUFFER READY signal from DTILIB. | |
3343 | |
3344 */ | |
3345 | |
3346 GLOBAL void stk_dti_tx_buffer_ready (void) | |
3347 { | |
3348 TRACE_FUNCTION ("stk_dti_tx_buffer_ready()"); | |
3349 | |
3350 /* | |
3351 * set new DTI state | |
3352 */ | |
3353 sim_data.dti_tx_state = SIM_DTI_TX_READY; | |
3354 | |
3355 /* | |
3356 * send confirm primitive to MMI: out of here; actually as the response for | |
3357 * SIM_BIP_CONFIG_REQ | |
3358 */ | |
3359 if ((sim_data.sim_bip_config_req) AND (sim_data.dti_connection_state EQ SIM_DTI_CONNECTION_SETUP)) | |
3360 { | |
3361 PALLOC(sim_bip_config_cnf, SIM_BIP_CONFIG_CNF); | |
3362 PSEND(hCommMMI, sim_bip_config_cnf); | |
3363 /* primitive no longer needed.. */ | |
3364 /* and so avoid the second confirm in stk_udp_bind_cnf() */ | |
3365 PFREE(sim_data.sim_bip_config_req); | |
3366 sim_data.sim_bip_config_req = NULL; | |
3367 /* | |
3368 * set the open state: the connection is now truly opened | |
3369 */ | |
3370 sim_data.dti_connection_state = SIM_DTI_CONNECTION_OPEN; | |
3371 } | |
3372 /* | |
3373 * send data | |
3374 */ | |
3375 if (sim_data.bip_tx_state EQ SIM_BIP_TX_SEND) | |
3376 { | |
3377 /* | |
3378 * set new BIP state | |
3379 */ | |
3380 #ifdef _SIMULATION_ | |
3381 TRACE_EVENT("bip_tx_state = IDLE"); | |
3382 #endif | |
3383 sim_data.bip_tx_state = SIM_BIP_TX_IDLE; | |
3384 /* | |
3385 * send DTI data primitive | |
3386 */ | |
3387 stk_dti_send_data(); | |
3388 /* | |
3389 * send Terminal Response | |
3390 */ | |
3391 stk_bip_send_data_terminal_response(sim_data.bip_general_result, | |
3392 sim_data.bip_add_info_result); | |
3393 /* | |
3394 * buffer ready is not triggered from a proactive_polling function call | |
3395 * so adjust timer and start polling | |
3396 */ | |
3397 stk_start_timer_and_poll(); | |
3398 /* | |
3399 * (re)start release timer | |
3400 */ | |
3401 if ((sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) AND | |
3402 (sim_data.bip_rx_state EQ SIM_BIP_RX_IDLE) AND | |
3403 ((sim_data.bip_timer_state EQ SIM_BIP_TIMER_STOPPED) OR | |
3404 (sim_data.bip_timer_state EQ SIM_BIP_TIMER_START))) | |
3405 { | |
3406 sim_data.bip_timer_state = SIM_BIP_TIMER_START; | |
3407 #ifdef _SIMULATION_ | |
3408 TRACE_EVENT("SIM_BIP_TIMER: start in stk_dti_tx_buffer_ready()"); | |
3409 #endif | |
3410 TIMER_START (sim_handle, SIM_BIP_TIMER, sim_data.bip_release_time); | |
3411 } | |
3412 } | |
3413 } /* stk_dti_tx_buffer_ready() */ | |
3414 | |
3415 /* | |
3416 +--------------------------------------------------------------------+ | |
3417 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
3418 | STATE : code ROUTINE : stk_dti_bip_send_data | | |
3419 +--------------------------------------------------------------------+ | |
3420 | |
3421 PURPOSE : Handle SEND DATA message from SIM card. | |
3422 | |
3423 */ | |
3424 | |
3425 GLOBAL UBYTE stk_dti_bip_send_data (T_sdu* message) | |
3426 { | |
3427 UBYTE ccdRet; | |
3428 UBYTE func_ret; | |
3429 UBYTE general_result; | |
3430 UBYTE add_info_result; | |
3431 UBYTE status; | |
3432 T_desc2* temp_desc1; | |
3433 T_desc2* temp_desc2; | |
3434 USHORT temp_pos; | |
3435 USHORT temp_len; | |
3436 | |
3437 TRACE_FUNCTION ("stk_dti_bip_send_data()"); | |
3438 | |
3439 /* | |
3440 * initialize value; | |
3441 */ | |
3442 ccdRet = ccdOK; | |
3443 func_ret = FALSE; | |
3444 general_result = RSLT_PERF_SUCCESS; | |
3445 add_info_result = ADD_NO_CAUSE; | |
3446 status = SIM_CCD_OK; | |
3447 | |
3448 CCD_START; | |
3449 /* | |
3450 * decode SIM Toolkit Command | |
3451 */ | |
3452 stk_bip_decode_stk_command(message, | |
3453 &sim_data.bip_tx_cmd_details, | |
3454 &status, | |
3455 &general_result, | |
3456 &add_info_result); | |
3457 /* | |
3458 * decode SEND DATA message | |
3459 */ | |
3460 if (status EQ SIM_CCD_OK) | |
3461 { | |
3462 MCAST(send_data, SEND_DATA); | |
3463 memset(send_data, 0, sizeof(T_SEND_DATA)); | |
3464 /* | |
3465 * decode SEND DATA message | |
3466 */ | |
3467 ccdRet = ccd_decodeMsg (CCDENT_SAT, | |
3468 DOWNLINK, | |
3469 (T_MSGBUF *) &sim_data.bip_cmd_prms, | |
3470 (UBYTE *) _decodedMsg, | |
3471 SEND_DATA); | |
3472 | |
3473 if (ccdRet NEQ ccdOK) | |
3474 { | |
3475 /* | |
3476 * handle errors in list | |
3477 */ | |
3478 stk_handle_ccd_error(ccdRet, &status, &general_result, &add_info_result); | |
3479 } | |
3480 if (send_data->v_chan_data EQ FALSE) | |
3481 { | |
3482 /* | |
3483 * no Channel Data element present | |
3484 * Error, required values are missing | |
3485 */ | |
3486 general_result = RSLT_ERR_REQ_VAL; | |
3487 add_info_result = ADD_NO_CAUSE; | |
3488 status = SIM_CCD_RETURN; | |
3489 } | |
3490 if (status EQ SIM_CCD_OK) | |
3491 { | |
3492 if (sim_data.bip_suspend) | |
3493 { | |
3494 /* | |
3495 * channel suspended | |
3496 * ME currently unable to process command | |
3497 */ | |
3498 general_result = sim_data.bip_general_result; | |
3499 add_info_result = sim_data.bip_add_info_result; | |
3500 status = SIM_CCD_RETURN; | |
3501 } | |
3502 else if ((SIM_CLASS_E_BUFFER_SIZE - sim_data.data_to_send.list_len) < | |
3503 send_data->chan_data.c_ch_dat_str) | |
3504 { | |
3505 /* | |
3506 * not enough space in tx buffer | |
3507 * BIP error | |
3508 */ | |
3509 general_result = RSLT_BEARIND_PERR; | |
3510 add_info_result = ADD_BIP_BUF_SIZ_NAVAIL; | |
3511 status = SIM_CCD_RETURN; | |
3512 } | |
3513 else | |
3514 { | |
3515 /* | |
3516 * concatenate Channel data | |
3517 */ | |
3518 sim_data.prev_data_to_send = sim_data.data_to_send; | |
3519 if (sim_data.data_to_send.first NEQ (ULONG)NULL) | |
3520 { | |
3521 /* | |
3522 * find last descriptor | |
3523 */ | |
3524 temp_desc1 = (T_desc2*)sim_data.data_to_send.first; | |
3525 while(temp_desc1->next NEQ (ULONG)NULL) | |
3526 { | |
3527 temp_desc1 = (T_desc2*)temp_desc1->next; | |
3528 } | |
3529 } | |
3530 else if (send_data->chan_data.c_ch_dat_str) | |
3531 { | |
3532 /* | |
3533 * allocate a new descriptor | |
3534 */ | |
3535 MALLOC(temp_desc1, (USHORT)(sizeof(T_desc2) - 1 + | |
3536 SIM_BIP_TX_DESC_SIZE)); | |
3537 temp_desc1->next = (ULONG)NULL; | |
3538 temp_desc1->offset= 0; /*###jk:OK*/ | |
3539 temp_desc1->len = 0; | |
3540 temp_desc1->size= 0; /*###jk:OK*/ | |
3541 sim_data.data_to_send.first = (ULONG)temp_desc1; | |
3542 sim_data.data_to_send.list_len = 0; | |
3543 } | |
3544 temp_pos = 0; | |
3545 while(temp_pos < send_data->chan_data.c_ch_dat_str) | |
3546 { | |
3547 if (temp_desc1->len >= SIM_BIP_TX_DESC_SIZE) /*lint !e644 temp_desc1 may not have been initialized*/ | |
3548 { | |
3549 /* | |
3550 * allocate new desriptor | |
3551 */ | |
3552 temp_desc2 = temp_desc1; | |
3553 MALLOC(temp_desc1, (USHORT)(sizeof(T_desc2) - 1 + | |
3554 SIM_BIP_TX_DESC_SIZE)); | |
3555 temp_desc1->next = (ULONG)NULL; | |
3556 temp_desc1->offset = 0; /*###jk:OK*/ | |
3557 temp_desc1->len = 0; | |
3558 temp_desc1->size = 0; /*###jk:OK*/ | |
3559 temp_desc2->next = (ULONG)temp_desc1; | |
3560 } | |
3561 /* | |
3562 * calculate length | |
3563 */ | |
3564 temp_len = send_data->chan_data.c_ch_dat_str - temp_pos; | |
3565 if (temp_len > (SIM_BIP_TX_DESC_SIZE - temp_desc1->len)) | |
3566 { | |
3567 temp_len = SIM_BIP_TX_DESC_SIZE - temp_desc1->len; | |
3568 TRACE_EVENT("sdbsd_5: if (temp_desc1->len >= SIM_BIP_TX_DESC_SIZE)"); /*###jk:tbd*/ | |
3569 TRACE_EVENT_P1("sdbsd_5: temp_len = %d", temp_len); /*###jk:tbd*/ | |
3570 } | |
3571 /* | |
3572 * copy data | |
3573 */ | |
3574 memcpy(&temp_desc1->buffer[temp_desc1->len], | |
3575 &send_data->chan_data.ch_dat_str[temp_pos], | |
3576 temp_len); | |
3577 temp_pos += temp_len; | |
3578 temp_desc1->len += temp_len; | |
3579 temp_desc1->size += temp_len; /*###jk:OK?*/ | |
3580 sim_data.data_to_send.list_len+= temp_len; | |
3581 } | |
3582 } | |
3583 /* | |
3584 * process SEND DATA message | |
3585 */ | |
3586 if (status EQ SIM_CCD_OK) | |
3587 { | |
3588 /* | |
3589 * if alpha identifier or icon identifier is present then | |
3590 * forward message to MMI | |
3591 */ | |
3592 if ((send_data->v_alpha_id) OR | |
3593 (send_data->v_icon)) | |
3594 { | |
3595 func_ret = TRUE; | |
3596 } | |
3597 /* | |
3598 * check for immediate/store bit | |
3599 */ | |
3600 if (sim_data.bip_tx_cmd_details.cmd_qlf & SIM_QLF_SEND_DATA_1) | |
3601 { | |
3602 /* | |
3603 * send data immediately | |
3604 */ | |
3605 if (sim_data.bip_state EQ SIM_BIP_CONNECTED) | |
3606 { | |
3607 /* | |
3608 * DTI connected | |
3609 */ | |
3610 if (sim_data.dti_tx_state EQ SIM_DTI_TX_READY) | |
3611 { | |
3612 /* | |
3613 * send DTI data primitive | |
3614 */ | |
3615 #ifdef _SIMULATION_ | |
3616 TRACE_EVENT("bip_tx_state = IDLE"); | |
3617 #endif | |
3618 sim_data.bip_tx_state = SIM_BIP_TX_IDLE; | |
3619 status = SIM_CCD_RETURN; | |
3620 stk_dti_send_data(); | |
3621 } | |
3622 else | |
3623 { | |
3624 TRACE_EVENT("stbsd_8: else (sim_data.dti_tx_state EQ SIM_DTI_TX_READY)"); /*###jk:tbd*/ | |
3625 /* | |
3626 * start release timer | |
3627 */ | |
3628 #ifdef _SIMULATION_ | |
3629 TRACE_EVENT("bip_tx_state = SEND"); | |
3630 #endif | |
3631 sim_data.bip_tx_state = SIM_BIP_TX_SEND; | |
3632 status = SIM_CCD_DISCARD; | |
3633 if ((sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) AND | |
3634 (sim_data.bip_timer_state EQ SIM_BIP_TIMER_START) | |
3635 ) | |
3636 { | |
3637 sim_data.bip_timer_state = SIM_BIP_TIMER_STOPPED; | |
3638 #ifdef _SIMULATION_ | |
3639 TRACE_EVENT("SIM_BIP_TIMER: stopped"); | |
3640 #endif | |
3641 TIMER_STOP (sim_handle, SIM_BIP_TIMER); | |
3642 } | |
3643 } | |
3644 /* | |
3645 * (re)start release timer | |
3646 */ | |
3647 if ((sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) AND | |
3648 (sim_data.bip_rx_state EQ SIM_BIP_RX_IDLE) AND | |
3649 (sim_data.bip_tx_state EQ SIM_BIP_TX_IDLE) AND | |
3650 ((sim_data.bip_timer_state EQ SIM_BIP_TIMER_STOPPED) OR | |
3651 (sim_data.bip_timer_state EQ SIM_BIP_TIMER_START))) | |
3652 { | |
3653 sim_data.bip_timer_state = SIM_BIP_TIMER_START; | |
3654 #ifdef _SIMULATION_ | |
3655 TRACE_EVENT("SIM_BIP_TIMER: start in stk_dti_bip_send_data(..)"); | |
3656 #endif | |
3657 TIMER_START (sim_handle, SIM_BIP_TIMER, sim_data.bip_release_time); | |
3658 } | |
3659 } | |
3660 else | |
3661 { | |
3662 TRACE_EVENT("stbsd_7: else (sim_data.bip_state EQ SIM_BIP_CONNECTED)"); /*###jk:tbd*/ | |
3663 /* | |
3664 * wait for DTI connection | |
3665 */ | |
3666 #ifdef _SIMULATION_ | |
3667 TRACE_EVENT("bip_tx_state = SEND"); | |
3668 #endif | |
3669 sim_data.bip_tx_state = SIM_BIP_TX_SEND; | |
3670 status = SIM_CCD_DISCARD; | |
3671 if ((sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) AND | |
3672 (sim_data.bip_timer_state EQ SIM_BIP_TIMER_START) | |
3673 ) | |
3674 { | |
3675 sim_data.bip_timer_state = SIM_BIP_TIMER_STOPPED; | |
3676 #ifdef _SIMULATION_ | |
3677 TRACE_EVENT("SIM_BIP_TIMER: stopped"); | |
3678 #endif | |
3679 TIMER_STOP (sim_handle, SIM_BIP_TIMER); | |
3680 } | |
3681 if (sim_data.dti_connection_state EQ SIM_DTI_CONNECTION_CLOSED) | |
3682 { | |
3683 /* | |
3684 * on demand link establishment | |
3685 * so forward message to MMI | |
3686 */ | |
3687 func_ret = TRUE; | |
3688 } | |
3689 } | |
3690 } | |
3691 else | |
3692 { | |
3693 /* | |
3694 * store data | |
3695 */ | |
3696 TRACE_EVENT("bip_tx_state = STORE"); | |
3697 sim_data.bip_tx_state = SIM_BIP_TX_STORE; | |
3698 status = SIM_CCD_RETURN; | |
3699 /* | |
3700 * stop release timer if used | |
3701 */ | |
3702 if ((sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) AND | |
3703 (sim_data.bip_timer_state EQ SIM_BIP_TIMER_START) | |
3704 ) | |
3705 { | |
3706 sim_data.bip_timer_state = SIM_BIP_TIMER_STOPPED; | |
3707 TRACE_EVENT("SIM_BIP_TIMER: stopped"); | |
3708 TIMER_STOP (sim_handle, SIM_BIP_TIMER); | |
3709 } | |
3710 } | |
3711 } | |
3712 } | |
3713 } /* if (status EQ SIM_CCD_OK) */ | |
3714 | |
3715 CCD_END; | |
3716 | |
3717 /* | |
3718 * send TERMINAL RESPONSE message | |
3719 */ | |
3720 if (status EQ SIM_CCD_RETURN) | |
3721 { | |
3722 stk_bip_send_data_terminal_response(general_result, add_info_result); | |
3723 } | |
3724 else | |
3725 { | |
3726 /* | |
3727 * store result codes | |
3728 */ | |
3729 sim_data.bip_general_result = general_result; | |
3730 sim_data.bip_add_info_result = add_info_result; | |
3731 } | |
3732 /* | |
3733 * send return value | |
3734 */ | |
3735 return func_ret; | |
3736 } /* stk_dti_bip_send_data() */ | |
3737 | |
3738 /* | |
3739 +--------------------------------------------------------------------+ | |
3740 | PROJECT : GSM-PS (6302) MODULE : SIM_STK | | |
3741 | STATE : code ROUTINE : stk_dti_bip_receive_data | | |
3742 +--------------------------------------------------------------------+ | |
3743 | |
3744 PURPOSE : Handle RECEIVE DATA message from SIM card. | |
3745 | |
3746 */ | |
3747 | |
3748 LOCAL UBYTE stk_dti_bip_receive_data (T_sdu* message, UBYTE result_code) | |
3749 { | |
3750 UBYTE ccdRet; | |
3751 UBYTE func_ret; | |
3752 UBYTE general_result; | |
3753 UBYTE add_info_result; | |
3754 UBYTE status; | |
3755 UBYTE chan_dat_lth; | |
3756 T_desc2* temp_desc1; | |
3757 T_desc2* temp_desc2; | |
3758 T_sdu* temp_sdu; | |
3759 USHORT temp_pos; | |
3760 USHORT temp_len; | |
3761 | |
3762 /* | |
3763 * initialize value; | |
3764 */ | |
3765 ccdRet = ccdOK; | |
3766 func_ret = FALSE; | |
3767 general_result = RSLT_PERF_SUCCESS; | |
3768 add_info_result = ADD_NO_CAUSE; | |
3769 status = SIM_CCD_OK; | |
3770 chan_dat_lth = 0; /* jk: initialized because of LINT error */ | |
3771 | |
3772 CCD_START; | |
3773 /* | |
3774 * decode SIM Toolkit Command | |
3775 */ | |
3776 stk_bip_decode_stk_command(message, | |
3777 &sim_data.bip_rx_cmd_details, | |
3778 &status, | |
3779 &general_result, | |
3780 &add_info_result); | |
3781 | |
3782 /* | |
3783 * decode RECEIVE DATA message | |
3784 */ | |
3785 if (status EQ SIM_CCD_OK) | |
3786 { | |
3787 MCAST(receive_data, RECEIVE_DATA); | |
3788 memset(receive_data, 0, sizeof(T_RECEIVE_DATA)); | |
3789 | |
3790 ccdRet = ccd_decodeMsg (CCDENT_SAT, | |
3791 DOWNLINK, | |
3792 (T_MSGBUF *) &sim_data.bip_cmd_prms, | |
3793 (UBYTE *) _decodedMsg, | |
3794 RECEIVE_DATA); | |
3795 | |
3796 #ifdef _SIMULATION_ | |
3797 TRACE_EVENT_P1("ccdRet@dti_bip_receive_data: %d", ccdRet); | |
3798 #endif | |
3799 | |
3800 if (ccdRet NEQ ccdOK) | |
3801 { | |
3802 /* | |
3803 * handle errors in list | |
3804 */ | |
3805 stk_handle_ccd_error(ccdRet, &status, &general_result, &add_info_result); | |
3806 } | |
3807 if (receive_data->v_chan_dat_lth EQ FALSE) | |
3808 { | |
3809 /* | |
3810 * no Channel Data Length element present | |
3811 * Error, required values are missing | |
3812 */ | |
3813 general_result = RSLT_ERR_REQ_VAL; | |
3814 add_info_result = ADD_NO_CAUSE; | |
3815 status = SIM_CCD_RETURN; | |
3816 } | |
3817 /* | |
3818 * process RECEIVE DATA message | |
3819 */ | |
3820 if (status EQ SIM_CCD_OK) | |
3821 { | |
3822 /* | |
3823 * if alpha identifier or icon identifier is present then | |
3824 * forward message to MMI | |
3825 */ | |
3826 if ((receive_data->v_alpha_id) OR | |
3827 (receive_data->v_icon)) | |
3828 { | |
3829 func_ret = TRUE; | |
3830 } | |
3831 if (sim_data.received_data.list_len < receive_data->chan_dat_lth) | |
3832 { | |
3833 /* | |
3834 * can not fill the complete buffer | |
3835 */ | |
3836 general_result = RSLT_PERF_MISS_INFO; | |
3837 add_info_result = ADD_NO_CAUSE; | |
3838 } | |
3839 status = SIM_CCD_RETURN; | |
3840 /* | |
3841 * store Channel Data Length | |
3842 */ | |
3843 chan_dat_lth = receive_data->chan_dat_lth; | |
3844 } | |
3845 } | |
3846 CCD_END; | |
3847 /* | |
3848 * send TERMINAL RESPONSE message | |
3849 */ | |
3850 if (status EQ SIM_CCD_RETURN) | |
3851 { | |
3852 CCD_START; | |
3853 { | |
3854 MCAST(term_resp, TERM_RESP); | |
3855 memset(term_resp, 0, sizeof(T_TERM_RESP)); | |
3856 | |
3857 /* | |
3858 * set Command details | |
3859 */ | |
3860 term_resp->v_cmd_details = TRUE; | |
3861 term_resp->cmd_details = sim_data.bip_rx_cmd_details; | |
3862 /* | |
3863 * set set Device identities | |
3864 */ | |
3865 term_resp->v_dev_ids = TRUE; | |
3866 term_resp->dev_ids.src_dev = DEV_SRC_ME; | |
3867 term_resp->dev_ids.dest_dev = DEV_DST_SIM; | |
3868 /* | |
3869 * set Result | |
3870 */ | |
3871 term_resp->v_res = TRUE; | |
3872 term_resp->res.gen = general_result; | |
3873 switch (general_result) | |
3874 { | |
3875 case RSLT_ME_UNAB_PROC: | |
3876 case RSLT_NTW_UNAB_PROC: | |
3877 case RSLT_LABRWS_GENERIC: | |
3878 case RSLT_SS_ERR: | |
3879 case RSLT_SMS_ERR: | |
3880 case RSLT_USSD_ERR: | |
3881 case RSLT_CC_SIM_PRM: | |
3882 /* | |
3883 * one byte for additional information | |
3884 */ | |
3885 term_resp->res.v_add = TRUE; | |
3886 term_resp->res.add.l_add = 1 << 3; | |
3887 term_resp->res.add.o_add = 0; | |
3888 term_resp->res.add.b_add[0] = add_info_result; | |
3889 break; | |
3890 | |
3891 case RSLT_BEARIND_PERR: | |
3892 /* | |
3893 * one byte for additional information | |
3894 */ | |
3895 term_resp->res.v_add = TRUE; | |
3896 term_resp->res.add.l_add = 1 << 3; | |
3897 term_resp->res.add.o_add = 0; | |
3898 term_resp->res.add.b_add[0] = add_info_result-1; | |
3899 break; | |
3900 | |
3901 default: | |
3902 if (result_code) | |
3903 term_resp->res.gen = RSLT_PERF_PART_CMPR; | |
3904 break; | |
3905 } | |
3906 /* | |
3907 * set Channel Data | |
3908 */ | |
3909 term_resp->v_chan_data = TRUE; | |
3910 switch (general_result) | |
3911 { | |
3912 case RSLT_PERF_SUCCESS: | |
3913 case RSLT_PERF_PART_CMPR: | |
3914 case RSLT_PERF_MISS_INFO: | |
3915 case RSLT_PERF_MDFY_SIM: | |
3916 case RSLT_PERF_MDFIED: | |
3917 /* | |
3918 * calculate Channel Data String length | |
3919 */ | |
3920 term_resp->chan_data.c_ch_dat_str = SIM_TERM_RESP_MAX_CHANNEL_DATA; | |
3921 if (sim_data.received_data.list_len < term_resp->chan_data.c_ch_dat_str) | |
3922 { | |
3923 term_resp->chan_data.c_ch_dat_str = (UBYTE)sim_data.received_data.list_len; | |
3924 } | |
3925 if (chan_dat_lth < term_resp->chan_data.c_ch_dat_str) | |
3926 { | |
3927 term_resp->chan_data.c_ch_dat_str = chan_dat_lth; | |
3928 } | |
3929 /* | |
3930 * copy data | |
3931 */ | |
3932 temp_desc1 = (T_desc2*)sim_data.received_data.first; | |
3933 temp_pos = 0; | |
3934 while (temp_pos < term_resp->chan_data.c_ch_dat_str) | |
3935 { | |
3936 /* | |
3937 * calculate length | |
3938 */ | |
3939 temp_len = term_resp->chan_data.c_ch_dat_str - temp_pos; | |
3940 if (temp_len > (temp_desc1->len - sim_data.received_data_pos)) | |
3941 { | |
3942 temp_len = temp_desc1->len - sim_data.received_data_pos; | |
3943 } | |
3944 /* | |
3945 * copy data | |
3946 */ | |
3947 memcpy(&term_resp->chan_data.ch_dat_str[temp_pos], | |
3948 &temp_desc1->buffer[sim_data.received_data_pos], | |
3949 temp_len); | |
3950 /* | |
3951 * updata length and position values and descriptors | |
3952 */ | |
3953 temp_pos += temp_len; | |
3954 sim_data.received_data_pos += temp_len; | |
3955 sim_data.received_data.list_len-= temp_len; | |
3956 if (sim_data.received_data_pos >= temp_desc1->len) | |
3957 { | |
3958 temp_desc2 = temp_desc1; | |
3959 temp_desc1 = (T_desc2*)temp_desc1->next; | |
3960 sim_data.received_data_pos = 0; | |
3961 sim_data.received_data.first = (ULONG)temp_desc1; | |
3962 MFREE(temp_desc2); | |
3963 } | |
3964 } | |
3965 break; | |
3966 | |
3967 case RSLT_BEARIND_PERR: | |
3968 case RSLT_UNKN_DATA: | |
3969 term_resp->v_chan_data = FALSE; | |
3970 term_resp->chan_data.c_ch_dat_str = 0; | |
3971 break; | |
3972 | |
3973 default: | |
3974 /* | |
3975 * if an error is occured then do not provide data | |
3976 */ | |
3977 term_resp->chan_data.c_ch_dat_str = 0; | |
3978 break; | |
3979 } | |
3980 | |
3981 switch (general_result) | |
3982 { | |
3983 case RSLT_BEARIND_PERR: | |
3984 case RSLT_UNKN_DATA: | |
3985 break; | |
3986 | |
3987 default: | |
3988 /* | |
3989 * set Channel Data Length | |
3990 */ | |
3991 term_resp->v_chan_dat_lth = TRUE; | |
3992 if (sim_data.received_data.list_len > 255) | |
3993 { | |
3994 /* | |
3995 * more than 255 bytes are available in RX buffer | |
3996 */ | |
3997 term_resp->chan_dat_lth = 0xff; | |
3998 } | |
3999 else | |
4000 { | |
4001 term_resp->chan_dat_lth = (UBYTE)sim_data.received_data.list_len; | |
4002 } | |
4003 break; | |
4004 } | |
4005 /* | |
4006 * send Terminal Response | |
4007 */ | |
4008 MALLOC(temp_sdu, (USHORT)(sizeof(T_sdu) - 1 + MAX_STK_CMD)); | |
4009 temp_sdu->l_buf = MAX_STK_CMD << 3; | |
4010 temp_sdu->o_buf = 0; | |
4011 | |
4012 ccdRet = ccd_codeMsg (CCDENT_SAT, | |
4013 UPLINK, | |
4014 (T_MSGBUF *) temp_sdu, | |
4015 (UBYTE *) _decodedMsg, | |
4016 TERM_RESP); | |
4017 } | |
4018 CCD_END; | |
4019 | |
4020 if ( ccdRet NEQ ccdOK ) | |
4021 { | |
4022 TRACE_EVENT_P1("CCD Coding Error: %d",ccdRet ); | |
4023 } | |
4024 else | |
4025 { | |
4026 FKT_TerminalResponse (temp_sdu->buf, (USHORT)(temp_sdu->l_buf >> 3)); | |
4027 } | |
4028 MFREE(temp_sdu); | |
4029 } | |
4030 | |
4031 if ((sim_data.bip_rx_state EQ SIM_BIP_RX_DATA) AND | |
4032 (sim_data.received_data.list_len EQ 0)) | |
4033 { | |
4034 /* | |
4035 * set new BIP state | |
4036 */ | |
4037 #ifdef _SIMULATION_ | |
4038 TRACE_EVENT("bip_rx_state = IDLE"); | |
4039 #endif | |
4040 sim_data.bip_rx_state = SIM_BIP_RX_IDLE; | |
4041 /* | |
4042 * start DTI reception | |
4043 */ | |
4044 if ((sim_data.bip_state EQ SIM_BIP_CONNECTED) AND | |
4045 (sim_data.dti_rx_state EQ SIM_DTI_RX_IDLE)) | |
4046 { | |
4047 sim_data.dti_rx_state = SIM_DTI_RX_READY; | |
4048 dti_start(sim_data.hDTI, 0, 0, 0); | |
4049 } | |
4050 /* | |
4051 * start release timer | |
4052 */ | |
4053 if ((sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) AND | |
4054 (sim_data.bip_timer_state EQ SIM_BIP_TIMER_STOPPED) AND | |
4055 (sim_data.bip_tx_state EQ SIM_BIP_TX_IDLE) | |
4056 ) | |
4057 { | |
4058 /* | |
4059 * no data trafic on the BIP channel, | |
4060 * so use the timer | |
4061 */ | |
4062 sim_data.bip_timer_state = SIM_BIP_TIMER_START; | |
4063 #ifdef _SIMULATION_ | |
4064 TRACE_EVENT("SIM_BIP_TIMER: start in stk_dti_bip_receive_data(..)"); | |
4065 #endif | |
4066 TIMER_START (sim_handle, SIM_BIP_TIMER, sim_data.bip_release_time); | |
4067 } | |
4068 } | |
4069 /* | |
4070 * send return value | |
4071 */ | |
4072 return func_ret; | |
4073 } /* stk_dti_bip_receive_data() */ | |
4074 | |
4075 #ifdef FF_SAT_E | |
4076 /* | |
4077 +--------------------------------------------------------------------+ | |
4078 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
4079 | STATE : code ROUTINE : stk_udp_bind_cnf | | |
4080 +--------------------------------------------------------------------+ | |
4081 | |
4082 PURPOSE : Process the primitive UDP_BIND_CNF. | |
4083 | |
4084 */ | |
4085 | |
4086 GLOBAL void stk_udp_bind_cnf (T_UDP_BIND_CNF* udp_bind_cnf) | |
4087 { | |
4088 TRACE_FUNCTION ("stk_udp_bind_cnf()"); | |
4089 | |
4090 if (sim_data.dti_connection_state EQ SIM_DTI_CONNECTION_BIND) | |
4091 { | |
4092 if (udp_bind_cnf->err EQ UDP_BIND_NOERROR) | |
4093 { | |
4094 /* | |
4095 * store source port | |
4096 */ | |
4097 sim_data.udp_parameters.src_port[0] = | |
4098 ((udp_bind_cnf->port >> 8) & 0x00ff); | |
4099 sim_data.udp_parameters.src_port[1] = | |
4100 ((udp_bind_cnf->port) & 0x00ff); | |
4101 /* | |
4102 * make sending of the confirmation primitive (SIM_BIP_CONFIG_CNF) | |
4103 * out of "stk_dti_buffer_ready()" possible | |
4104 */ | |
4105 sim_data.dti_connection_state = SIM_DTI_CONNECTION_SETUP; | |
4106 | |
4107 /*###jk:OK? moved & changed from "stk_dti_connection_open()" */ | |
4108 if ((sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) AND | |
4109 (sim_data.bip_timer_state EQ SIM_BIP_TIMER_START) | |
4110 ) | |
4111 { | |
4112 sim_data.bip_timer_state = SIM_BIP_TIMER_STOPPED; | |
4113 #ifdef _SIMULATION_ | |
4114 TRACE_EVENT("stk_udp_bind_cnf(): SIM_BIP_TIMER: stopped"); | |
4115 #endif | |
4116 TIMER_STOP (sim_handle, SIM_BIP_TIMER); | |
4117 } | |
4118 /* | |
4119 * update timer (if used) and DTI states | |
4120 */ | |
4121 if ((sim_data.bip_state EQ SIM_BIP_CONNECTED) AND | |
4122 (sim_data.bip_rx_state EQ SIM_BIP_RX_IDLE)) | |
4123 { | |
4124 /* | |
4125 * start reception | |
4126 */ | |
4127 sim_data.dti_rx_state = SIM_DTI_RX_READY; | |
4128 dti_start(sim_data.hDTI, 0, 0, 0); | |
4129 /* | |
4130 * start timer if used | |
4131 */ | |
4132 if ((sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) AND | |
4133 (sim_data.bip_tx_state EQ SIM_BIP_TX_IDLE) AND | |
4134 (sim_data.bip_timer_state EQ SIM_BIP_TIMER_STOPPED) | |
4135 ) | |
4136 { | |
4137 /* | |
4138 * no data trafic on the BIP channel, | |
4139 * so use the timer | |
4140 */ | |
4141 sim_data.bip_timer_state = SIM_BIP_TIMER_START; | |
4142 #ifdef _SIMULATION_ | |
4143 TRACE_EVENT("SIM_BIP_TIMER: start in stk_dti_connection_opened()"); | |
4144 #endif | |
4145 TIMER_START (sim_handle, SIM_BIP_TIMER, sim_data.bip_release_time); | |
4146 } | |
4147 } /*###jk:OK?*/ | |
4148 } | |
4149 else | |
4150 { | |
4151 /* | |
4152 * can not open UDP port | |
4153 * so disconnect BIP channel from DTI | |
4154 */ | |
4155 stk_close_dti_connection(TRUE); | |
4156 /* | |
4157 * send confirm primitive | |
4158 */ | |
4159 stk_dti_inform_mmi(SIM_DTI_DISCONNECT, (UBYTE) SIM_BIP_UNKNOWN); | |
4160 } | |
4161 } | |
4162 /* | |
4163 * free primitive | |
4164 */ | |
4165 PFREE(udp_bind_cnf); | |
4166 } /* stk_udp_bind_cnf() */ | |
4167 | |
4168 /* | |
4169 +--------------------------------------------------------------------+ | |
4170 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
4171 | STATE : code ROUTINE : stk_udp_closeport_cnf | | |
4172 +--------------------------------------------------------------------+ | |
4173 | |
4174 PURPOSE : Process the primitive UDP_CLOSEPORT_CNF. | |
4175 | |
4176 */ | |
4177 | |
4178 GLOBAL void stk_udp_closeport_cnf ( | |
4179 T_UDP_CLOSEPORT_CNF* udp_closeport_cnf) | |
4180 { | |
4181 TRACE_FUNCTION ("stk_udp_closeport_cnf()"); | |
4182 | |
4183 /* | |
4184 * free primitive | |
4185 */ | |
4186 PFREE(udp_closeport_cnf); | |
4187 } /* stk_udp_closeport_cnf() */ | |
4188 | |
4189 /* | |
4190 +--------------------------------------------------------------------+ | |
4191 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
4192 | STATE : code ROUTINE : stk_udp_error_ind | | |
4193 +--------------------------------------------------------------------+ | |
4194 | |
4195 PURPOSE : Process the primitive UDP_ERROR_IND. | |
4196 | |
4197 */ | |
4198 | |
4199 GLOBAL void stk_udp_error_ind (T_UDP_ERROR_IND* udp_error_ind) | |
4200 { | |
4201 TRACE_FUNCTION ("stk_udp_error_ind()"); | |
4202 | |
4203 /* | |
4204 * free primitive | |
4205 */ | |
4206 PFREE(udp_error_ind); | |
4207 /* | |
4208 * generate error response | |
4209 */ | |
4210 { | |
4211 PALLOC(udp_error_res, UDP_ERROR_RES); | |
4212 PSEND(hCommUDP, udp_error_res); | |
4213 } | |
4214 } /* stk_udp_error_ind() */ | |
4215 | |
4216 /* | |
4217 +--------------------------------------------------------------------+ | |
4218 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
4219 | STATE : code ROUTINE : stk_udp_shutdown_ind | | |
4220 +--------------------------------------------------------------------+ | |
4221 | |
4222 PURPOSE : Process the primitive UDP_SHUTDOWN_IND. | |
4223 | |
4224 */ | |
4225 | |
4226 GLOBAL void stk_udp_shutdown_ind (T_UDP_SHUTDOWN_IND* udp_shutdown_ind) | |
4227 { | |
4228 TRACE_FUNCTION ("stk_udp_shutdown_ind()"); | |
4229 | |
4230 /* | |
4231 * send confirm primitive | |
4232 */ | |
4233 if (hCommUDP < VSI_OK) | |
4234 { | |
4235 hCommUDP = vsi_c_open (VSI_CALLER UDP_NAME); | |
4236 } | |
4237 if (hCommUDP >= VSI_OK) | |
4238 { | |
4239 PALLOC(udp_shutdown_res, UDP_SHUTDOWN_RES); | |
4240 PSEND(hCommUDP, udp_shutdown_res); | |
4241 /* | |
4242 * release VSI channel | |
4243 */ | |
4244 vsi_c_close (VSI_CALLER hCommUDP); | |
4245 hCommUDP = VSI_ERROR; | |
4246 } | |
4247 /* | |
4248 * close DTI connection | |
4249 */ | |
4250 if (sim_data.con_type EQ SIM_CON_TYPE_UDP) | |
4251 { | |
4252 switch(sim_data.dti_connection_state) | |
4253 { | |
4254 case SIM_DTI_CONNECTION_OPEN: | |
4255 case SIM_DTI_CONNECTION_SETUP: | |
4256 stk_close_dti_connection(TRUE); | |
4257 break; | |
4258 | |
4259 default: | |
4260 stk_close_dti_connection(FALSE); | |
4261 break; | |
4262 } | |
4263 /* | |
4264 * inform ACI about disconnection | |
4265 */ | |
4266 stk_dti_inform_mmi(SIM_DTI_DISCONNECT, (UBYTE) SIM_BIP_UNKNOWN); | |
4267 } | |
4268 } /* stk_udp_shutdown_ind() */ | |
4269 #endif /* FF_SAT_E */ | |
4270 | |
4271 /* | |
4272 +--------------------------------------------------------------------+ | |
4273 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
4274 | STATE : code ROUTINE : stk_sim_dti_req | | |
4275 +--------------------------------------------------------------------+ | |
4276 | |
4277 PURPOSE : Process the primitive SIM_DTI_REQ. | |
4278 | |
4279 */ | |
4280 | |
4281 GLOBAL void stk_sim_dti_req (T_SIM_DTI_REQ* sim_dti_req) | |
4282 { | |
4283 UBYTE dti_conn; | |
4284 | |
4285 TRACE_FUNCTION ("stk_sim_dti_req()"); | |
4286 | |
4287 #ifdef _SIMULATION_ | |
4288 /* | |
4289 * set entity_name parameter | |
4290 */ | |
4291 switch(sim_dti_req->entity_name) | |
4292 { | |
4293 case 1: | |
4294 sim_dti_req->entity_name = (ULONG)("UDP"); | |
4295 break; | |
4296 | |
4297 case 2: | |
4298 sim_dti_req->entity_name = (ULONG)("SND"); | |
4299 break; | |
4300 | |
4301 case 3: | |
4302 sim_dti_req->entity_name = (ULONG)("L2R"); | |
4303 break; | |
4304 | |
4305 default: | |
4306 sim_dti_req->entity_name = (ULONG)(NULL); | |
4307 break; | |
4308 } | |
4309 #endif /* _SIMULATION_ */ | |
4310 /* | |
4311 * store the received primitive | |
4312 */ | |
4313 if (sim_data.sim_dti_req) | |
4314 { | |
4315 /* | |
4316 * free previous primitive before store the new one | |
4317 */ | |
4318 PFREE(sim_data.sim_dti_req); | |
4319 } | |
4320 sim_data.sim_dti_req = sim_dti_req; | |
4321 | |
4322 /* | |
4323 * store requested operations | |
4324 */ | |
4325 dti_conn = sim_dti_req->dti_conn; | |
4326 | |
4327 switch (dti_conn) | |
4328 { | |
4329 case SIM_DTI_DISCONNECT: /* close DTI connection */ | |
4330 { | |
4331 switch(sim_data.dti_connection_state) | |
4332 { | |
4333 case SIM_DTI_CONNECTION_OPEN: | |
4334 case SIM_DTI_CONNECTION_SETUP: | |
4335 stk_close_dti_connection(TRUE); | |
4336 break; | |
4337 default: | |
4338 stk_close_dti_connection(FALSE); | |
4339 break; | |
4340 } | |
4341 break; | |
4342 } | |
4343 case SIM_DTI_CONNECT: /* open DTI connection */ | |
4344 { | |
4345 /* | |
4346 * if a new DTI connection is requested close the old one before | |
4347 */ | |
4348 switch(sim_data.dti_connection_state) | |
4349 { | |
4350 case SIM_DTI_CONNECTION_OPEN: | |
4351 case SIM_DTI_CONNECTION_SETUP: | |
4352 stk_close_dti_connection(TRUE); | |
4353 break; | |
4354 default: | |
4355 stk_close_dti_connection(FALSE); | |
4356 } | |
4357 /* | |
4358 * store relevant data | |
4359 */ | |
4360 sim_data.link_id = sim_dti_req->link_id; | |
4361 sim_data.dti_connection_state = SIM_DTI_CONNECTION_SETUP; | |
4362 dti_open(sim_data.hDTI, /* DTI handle */ | |
4363 0, /* instance */ | |
4364 0, /* interface */ | |
4365 0, /* channel */ | |
4366 0, /* queue size */ | |
4367 sim_dti_req->dti_direction, /* direction */ | |
4368 FLOW_CNTRL_ENABLED, /* comm_type */ | |
4369 DTI_VERSION_10, /* version */ | |
4370 (UBYTE*)sim_dti_req->entity_name, /* entity name */ | |
4371 sim_dti_req->link_id); /* link identifier */ | |
4372 } | |
4373 } | |
4374 /* | |
4375 * send confirm primitive | |
4376 */ | |
4377 if (sim_data.sim_dti_req) | |
4378 { | |
4379 TRACE_EVENT_P1("if(sim_data.sim_dti_req): ~ ->dti_conn=0x%02X", sim_dti_req->dti_conn); | |
4380 | |
4381 stk_dti_inform_mmi(sim_dti_req->dti_conn, (UBYTE)SIM_BIP_UNKNOWN); | |
4382 } | |
4383 } /* stk_sim_dti_req() */ | |
4384 | |
4385 | |
4386 /* | |
4387 +--------------------------------------------------------------------+ | |
4388 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
4389 | STATE : code ROUTINE : stk_sim_bip_req | | |
4390 +--------------------------------------------------------------------+ | |
4391 | |
4392 PURPOSE : Process the primitive SIM_BIP_REQ. | |
4393 | |
4394 */ | |
4395 | |
4396 GLOBAL void stk_sim_bip_req (T_SIM_BIP_REQ* sim_bip_req) | |
4397 { | |
4398 UBYTE bip_conn; | |
4399 USHORT temp_len; | |
4400 T_desc2* temp_desc1; | |
4401 T_desc2* temp_desc2; | |
4402 | |
4403 TRACE_FUNCTION ("stk_sim_bip_req()"); | |
4404 | |
4405 /* | |
4406 * store the received primitive | |
4407 */ | |
4408 if (sim_data.sim_bip_req) | |
4409 { | |
4410 /* | |
4411 * free previous primitive before store the new one | |
4412 */ | |
4413 PFREE(sim_data.sim_bip_req); | |
4414 } | |
4415 sim_data.sim_bip_req = sim_bip_req; | |
4416 /* | |
4417 * store requested operations | |
4418 */ | |
4419 bip_conn = sim_bip_req->bip_conn; | |
4420 | |
4421 /* | |
4422 * resume BIP channel | |
4423 */ | |
4424 if (bip_conn & SIM_BIP_CHANNEL_RESUMED) | |
4425 { | |
4426 /* | |
4427 * set new suspension state | |
4428 */ | |
4429 sim_data.bip_suspend = FALSE; | |
4430 /* | |
4431 * restart timer if used | |
4432 */ | |
4433 if ((sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) AND | |
4434 (sim_data.bip_timer_state EQ SIM_BIP_TIMER_SUSPENDED) | |
4435 ) | |
4436 { | |
4437 sim_data.bip_timer_state = SIM_BIP_TIMER_STOPPED; | |
4438 if ((sim_data.bip_rx_state EQ SIM_BIP_RX_IDLE) AND | |
4439 (sim_data.bip_tx_state EQ SIM_BIP_TX_IDLE) | |
4440 ) | |
4441 { | |
4442 /* | |
4443 * no data trafic on the BIP channel, | |
4444 * so use the timer | |
4445 */ | |
4446 sim_data.bip_timer_state = SIM_BIP_TIMER_START; | |
4447 #ifdef _SIMULATION_ | |
4448 TRACE_EVENT("SIM_BIP_TIMER: start in stk_sim_bip_req(..)"); | |
4449 #endif | |
4450 TIMER_START (sim_handle, SIM_BIP_TIMER, sim_data.bip_release_time); | |
4451 } | |
4452 } | |
4453 } | |
4454 /* | |
4455 * close BIP channel | |
4456 */ | |
4457 if (bip_conn & SIM_BIP_CLOSE_CHANNEL) | |
4458 { | |
4459 stk_close_bip_channel(sim_bip_req->general_result, | |
4460 sim_bip_req->add_info_result); | |
4461 } | |
4462 /* | |
4463 * open BIP channel | |
4464 */ | |
4465 if ((bip_conn & SIM_BIP_OPEN_CHANNEL) AND | |
4466 (sim_data.bip_state EQ SIM_BIP_CLOSED)) | |
4467 { | |
4468 /* | |
4469 * set new BIP state and | |
4470 * store BIP channel identifier | |
4471 */ | |
4472 sim_data.bip_state = SIM_BIP_OPEN; | |
4473 sim_data.bip_ch_id = sim_bip_req->bip_ch_id; | |
4474 /* | |
4475 * store relevant data | |
4476 */ | |
4477 sim_data.bip_release_time = | |
4478 (T_TIME)sim_bip_req->release_time * 100; /* convert to msec. */ | |
4479 if (sim_bip_req->general_result NEQ RSLT_PERF_SUCCESS) | |
4480 { | |
4481 sim_data.bip_general_result = sim_bip_req->general_result; | |
4482 sim_data.bip_add_info_result = sim_bip_req->add_info_result; | |
4483 } | |
4484 } | |
4485 /* | |
4486 * suspend BIP channel | |
4487 */ | |
4488 if (bip_conn & SIM_BIP_CHANNEL_SUSPENDED) | |
4489 { | |
4490 /* | |
4491 * set new suspension state | |
4492 */ | |
4493 sim_data.bip_suspend = TRUE; | |
4494 /* | |
4495 * stop timer if timer is used | |
4496 */ | |
4497 if (sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) | |
4498 { | |
4499 if (sim_data.bip_timer_state EQ SIM_BIP_TIMER_START) | |
4500 { | |
4501 sim_data.bip_timer_state = SIM_BIP_TIMER_SUSPENDED; | |
4502 #ifdef _SIMULATION_ | |
4503 TRACE_EVENT("SIM_BIP_TIMER: stopped"); | |
4504 #endif | |
4505 TIMER_STOP (sim_handle, SIM_BIP_TIMER); | |
4506 } | |
4507 else if (sim_data.bip_timer_state EQ SIM_BIP_TIMER_STOPPED) | |
4508 { | |
4509 sim_data.bip_timer_state = SIM_BIP_TIMER_SUSPENDED; | |
4510 } | |
4511 } | |
4512 /* | |
4513 * store result codes | |
4514 */ | |
4515 sim_data.bip_general_result = sim_bip_req->general_result; | |
4516 sim_data.bip_add_info_result = sim_bip_req->add_info_result; | |
4517 /* | |
4518 * inform SIM card | |
4519 */ | |
4520 if (sim_data.bip_tx_state EQ SIM_BIP_TX_SEND) | |
4521 { | |
4522 /* | |
4523 * free data of last SEND DATA message | |
4524 */ | |
4525 temp_desc1 = (T_desc2*)sim_data.data_to_send.first; | |
4526 sim_data.data_to_send = sim_data.prev_data_to_send; | |
4527 if (sim_data.data_to_send.first EQ (ULONG)NULL) | |
4528 { | |
4529 while(temp_desc1) | |
4530 { | |
4531 temp_desc2 = temp_desc1; | |
4532 temp_desc1 = (T_desc2*)temp_desc1->next; | |
4533 MFREE(temp_desc2); | |
4534 } | |
4535 } | |
4536 else | |
4537 { | |
4538 temp_len = 0; | |
4539 while((temp_desc1) AND | |
4540 (temp_len + temp_desc1->len) < sim_data.data_to_send.list_len) | |
4541 { | |
4542 temp_len += temp_desc1->len; | |
4543 temp_desc1 = (T_desc2*)temp_desc1->next; | |
4544 } | |
4545 if (temp_desc1) | |
4546 { | |
4547 temp_desc1->len = sim_data.data_to_send.list_len - temp_len; | |
4548 temp_desc2 = (T_desc2*)temp_desc1->next; | |
4549 temp_desc1->next = (ULONG)NULL; | |
4550 temp_desc1 = temp_desc2; | |
4551 while(temp_desc1) | |
4552 { | |
4553 temp_desc2 = temp_desc1; | |
4554 temp_desc1 = (T_desc2*)temp_desc1->next; | |
4555 MFREE(temp_desc2); | |
4556 } | |
4557 } | |
4558 } | |
4559 /* | |
4560 * set new BIP TX state | |
4561 */ | |
4562 if (sim_data.data_to_send.first EQ (ULONG)NULL) | |
4563 { | |
4564 #ifdef _SIMULATION_ | |
4565 TRACE_EVENT("bip_tx_state = IDLE"); | |
4566 #endif | |
4567 sim_data.bip_tx_state = SIM_BIP_TX_IDLE; | |
4568 } | |
4569 else | |
4570 { | |
4571 #ifdef _SIMULATION_ | |
4572 TRACE_EVENT("bip_tx_state = STORE"); | |
4573 #endif | |
4574 sim_data.bip_tx_state = SIM_BIP_TX_STORE; | |
4575 if ((sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) AND | |
4576 (sim_data.bip_timer_state EQ SIM_BIP_TIMER_START) | |
4577 ) | |
4578 { | |
4579 sim_data.bip_timer_state = SIM_BIP_TIMER_STOPPED; | |
4580 #ifdef _SIMULATION_ | |
4581 TRACE_EVENT("SIM_BIP_TIMER: stopped"); | |
4582 #endif | |
4583 TIMER_STOP (sim_handle, SIM_BIP_TIMER); | |
4584 } | |
4585 } | |
4586 /* | |
4587 * send Terminal Response | |
4588 */ | |
4589 stk_bip_send_data_terminal_response(sim_bip_req->general_result, | |
4590 sim_bip_req->add_info_result); | |
4591 /* | |
4592 * suspension is not triggered from a proactive_polling function call | |
4593 * so adjust timer and start polling | |
4594 */ | |
4595 stk_start_timer_and_poll(); | |
4596 } | |
4597 } | |
4598 /* | |
4599 * send confirm primitive | |
4600 */ | |
4601 if (sim_data.sim_bip_req) | |
4602 { | |
4603 stk_dti_inform_mmi((UBYTE) SIM_DTI_UNKNOWN, sim_bip_req->bip_conn); | |
4604 } | |
4605 } /* stk_sim_bip_req() */ | |
4606 | |
4607 | |
4608 /* | |
4609 +--------------------------------------------------------------------+ | |
4610 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
4611 | STATE : code ROUTINE : stk_sim_bip_config_req | | |
4612 +--------------------------------------------------------------------+ | |
4613 | |
4614 PURPOSE : Process the primitive SIM_BIP_CONFIG_REQ. | |
4615 | |
4616 */ | |
4617 | |
4618 GLOBAL void stk_sim_bip_config_req(T_SIM_BIP_CONFIG_REQ * sim_bip_config_req) | |
4619 { | |
4620 TRACE_FUNCTION ("stk_sim_bip_config_req()"); | |
4621 /* | |
4622 * store the received primitive | |
4623 */ | |
4624 if (sim_data.sim_bip_config_req) | |
4625 { | |
4626 /* | |
4627 * free previous primitive before store the new one | |
4628 */ | |
4629 PFREE(sim_data.sim_bip_config_req); | |
4630 } | |
4631 sim_data.sim_bip_config_req = sim_bip_config_req; | |
4632 /* | |
4633 * store relevant data | |
4634 */ | |
4635 sim_data.con_type = sim_bip_config_req->con_type; | |
4636 | |
4637 #if 0 | |
4638 sim_data.udp_parameters.src_ip[0] = | |
4639 (UBYTE)((sim_bip_config_req->local_ip >> 24) & 0x000000ff); | |
4640 sim_data.udp_parameters.src_ip[1] = | |
4641 (UBYTE)((sim_bip_config_req->local_ip >> 16) & 0x000000ff); | |
4642 sim_data.udp_parameters.src_ip[2] = | |
4643 (UBYTE)((sim_bip_config_req->local_ip >> 8) & 0x000000ff); | |
4644 sim_data.udp_parameters.src_ip[3] = | |
4645 (UBYTE)((sim_bip_config_req->local_ip) & 0x000000ff); | |
4646 #else | |
4647 sim_data.udp_parameters.src_ip[3] = | |
4648 (UBYTE)((sim_bip_config_req->local_ip >> 24) & 0x000000ff); | |
4649 sim_data.udp_parameters.src_ip[2] = | |
4650 (UBYTE)((sim_bip_config_req->local_ip >> 16) & 0x000000ff); | |
4651 sim_data.udp_parameters.src_ip[1] = | |
4652 (UBYTE)((sim_bip_config_req->local_ip >> 8) & 0x000000ff); | |
4653 sim_data.udp_parameters.src_ip[0] = | |
4654 (UBYTE)((sim_bip_config_req->local_ip) & 0x000000ff); | |
4655 #endif | |
4656 | |
4657 sim_data.udp_parameters.des_ip[0] = | |
4658 (UBYTE)((sim_bip_config_req->destination_ip >> 24) & 0x000000ff); | |
4659 sim_data.udp_parameters.des_ip[1] = | |
4660 (UBYTE)((sim_bip_config_req->destination_ip >> 16) & 0x000000ff); | |
4661 sim_data.udp_parameters.des_ip[2] = | |
4662 (UBYTE)((sim_bip_config_req->destination_ip >> 8) & 0x000000ff); | |
4663 sim_data.udp_parameters.des_ip[3] = | |
4664 (UBYTE)((sim_bip_config_req->destination_ip) & 0x000000ff); | |
4665 | |
4666 #if 0 | |
4667 sim_data.udp_parameters.des_port[0] = | |
4668 (UBYTE)((sim_bip_config_req->destination_port >> 8) & 0x00ff); | |
4669 sim_data.udp_parameters.des_port[1] = | |
4670 (UBYTE)((sim_bip_config_req->destination_port) & 0x00ff); | |
4671 #else | |
4672 sim_data.udp_parameters.des_port[1] = | |
4673 (UBYTE)((sim_bip_config_req->destination_port >> 8) & 0x00ff); | |
4674 sim_data.udp_parameters.des_port[0] = | |
4675 (UBYTE)((sim_bip_config_req->destination_port) & 0x00ff); | |
4676 #endif | |
4677 | |
4678 /* | |
4679 * UDP connection | |
4680 */ | |
4681 if (sim_data.con_type EQ SIM_CON_TYPE_UDP) | |
4682 { | |
4683 /* | |
4684 * open VSI channel to UDP | |
4685 */ | |
4686 if (hCommUDP < VSI_OK) | |
4687 { | |
4688 TRACE_EVENT("if(hCommUDP < VSI_OK)"); | |
4689 if ((hCommUDP = vsi_c_open (VSI_CALLER UDP_NAME)) < VSI_OK) | |
4690 { | |
4691 TRACE_EVENT("if ((hCommUDP = vsi_c_open (VSI_CALLER UDP_NAME)) < VSI_OK)"); | |
4692 /* | |
4693 * can not open VSI channel | |
4694 * so act as if DTI close was requested | |
4695 */ | |
4696 sim_data.sim_dti_req->dti_conn = SIM_DTI_DISCONNECT; | |
4697 TRACE_EVENT_P1(": sim_data.sim_dti_req->dti_conn=0x%02X", sim_data.sim_dti_req->dti_conn); | |
4698 } | |
4699 } | |
4700 /* | |
4701 * send UDP_BIND_REQ | |
4702 */ | |
4703 if (hCommUDP >= VSI_OK) | |
4704 { | |
4705 PALLOC(udp_bind_req, UDP_BIND_REQ); | |
4706 sim_data.dti_connection_state = SIM_DTI_CONNECTION_BIND; | |
4707 udp_bind_req->port = UDP_AUTOASSIGN_PORT; | |
4708 PSEND(hCommUDP, udp_bind_req); | |
4709 /* | |
4710 * send confirm primitive: | |
4711 * will be sent out of "stk_dti_buffer_ready()" function in case of success, | |
4712 * in case of udp_bind_cnf failure only indication primitive will be sent | |
4713 * out of "stk_udp_bind_cnf" to MMI instead. | |
4714 */ | |
4715 } | |
4716 } | |
4717 /* | |
4718 * bearer level connection | |
4719 */ | |
4720 else | |
4721 { | |
4722 /*###jk:OK? moved & changed from "stk_dti_connection_open()" */ | |
4723 if ((sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) AND | |
4724 (sim_data.bip_timer_state EQ SIM_BIP_TIMER_START) | |
4725 ) | |
4726 { | |
4727 sim_data.bip_timer_state = SIM_BIP_TIMER_STOPPED; | |
4728 #ifdef _SIMULATION_ | |
4729 TRACE_EVENT("stk_udp_bind_cnf(): SIM_BIP_TIMER: stopped"); | |
4730 #endif | |
4731 TIMER_STOP (sim_handle, SIM_BIP_TIMER); | |
4732 } | |
4733 /* | |
4734 * update timer (if used) and DTI states | |
4735 */ | |
4736 if ((sim_data.bip_state EQ SIM_BIP_CONNECTED) AND | |
4737 (sim_data.bip_rx_state EQ SIM_BIP_RX_IDLE)) | |
4738 { | |
4739 /* | |
4740 * start reception | |
4741 */ | |
4742 sim_data.dti_rx_state = SIM_DTI_RX_READY; | |
4743 dti_start(sim_data.hDTI, 0, 0, 0); | |
4744 /* | |
4745 * start timer if used | |
4746 */ | |
4747 if ((sim_data.bip_timer_state NEQ SIM_BIP_TIMER_NOT_USED) AND | |
4748 (sim_data.bip_tx_state EQ SIM_BIP_TX_IDLE) AND | |
4749 (sim_data.bip_timer_state EQ SIM_BIP_TIMER_STOPPED) | |
4750 ) | |
4751 { | |
4752 /* | |
4753 * no data trafic on the BIP channel, | |
4754 * so use the timer | |
4755 */ | |
4756 sim_data.bip_timer_state = SIM_BIP_TIMER_START; | |
4757 #ifdef _SIMULATION_ | |
4758 TRACE_EVENT("SIM_BIP_TIMER: start in stk_dti_connection_opened()"); | |
4759 #endif | |
4760 TIMER_START (sim_handle, SIM_BIP_TIMER, sim_data.bip_release_time); | |
4761 } | |
4762 } /*###jk:OK?*/ | |
4763 | |
4764 /* | |
4765 * make sending of the confirmation primitive (SIM_BIP_CONFIG_CNF) | |
4766 * out of "stk_dti_buffer_ready()" possible | |
4767 */ | |
4768 sim_data.dti_connection_state = SIM_DTI_CONNECTION_SETUP; | |
4769 | |
4770 /* | |
4771 * send confirm primitive: | |
4772 * will be sent out of "stk_dti_buffer_ready()" function in order to | |
4773 * prevent sending of the data to connected neighbour DTI-entity before | |
4774 * this entity is ready to receive data. | |
4775 */ | |
4776 #if 0 /*###jk:OK? -> */ | |
4777 /* | |
4778 * send confirm primitive | |
4779 */ | |
4780 if (sim_data.sim_bip_config_req) | |
4781 { | |
4782 PALLOC(sim_bip_config_cnf, SIM_BIP_CONFIG_CNF); | |
4783 PSEND(hCommMMI, sim_bip_config_cnf); | |
4784 } | |
4785 #endif | |
4786 } | |
4787 } /* stk_bip_config_req() */ | |
4788 | |
4789 /* | |
4790 +--------------------------------------------------------------------+ | |
4791 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
4792 | STATE : code ROUTINE : stk_sim_eventlist_req | | |
4793 +--------------------------------------------------------------------+ | |
4794 | |
4795 PURPOSE : Process the primitive SIM_EVENTLIST_REQ. | |
4796 | |
4797 */ | |
4798 | |
4799 GLOBAL void stk_sim_eventlist_req ( | |
4800 T_SIM_EVENTLIST_REQ* sim_eventlist_req) | |
4801 { | |
4802 TRACE_FUNCTION ("stk_sim_eventlist_req()"); | |
4803 | |
4804 /* | |
4805 * store new state of Data available event | |
4806 */ | |
4807 sim_data.event_data_avail = sim_eventlist_req->event_data_avail; | |
4808 /* | |
4809 * free primitive | |
4810 */ | |
4811 PFREE(sim_eventlist_req); | |
4812 /* | |
4813 * send confirm primitive | |
4814 */ | |
4815 { | |
4816 PALLOC(sim_eventlist_cnf, SIM_EVENTLIST_CNF); | |
4817 sim_eventlist_cnf->event_data_avail = sim_data.event_data_avail; | |
4818 PSEND(hCommMMI, sim_eventlist_cnf); | |
4819 } | |
4820 } /* stk_sim_eventlist_req() */ | |
4821 #endif /* FF_SAT_E */ | |
4822 | |
4823 /* | |
4824 +--------------------------------------------------------------------+ | |
4825 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
4826 | STATE : code ROUTINE : stk_sim_toolkit_res | | |
4827 +--------------------------------------------------------------------+ | |
4828 | |
4829 PURPOSE : Process the primitive SIM_TOOLKIT_RES. MMI sends a | |
4830 Terminal Response Message to SIM toolkit. | |
4831 | |
4832 */ | |
4833 | |
4834 GLOBAL void stk_sim_toolkit_res (T_SIM_TOOLKIT_RES * sim_toolkit_res) | |
4835 { | |
4836 TRACE_FUNCTION ("stk_sim_toolkit_res()"); | |
4837 | |
4838 if (sim_data.ext_sat_cmd) | |
4839 { | |
4840 FKT_TerminalResponse (sim_toolkit_res->stk_cmd.cmd, | |
4841 (USHORT)(sim_toolkit_res->stk_cmd.l_cmd>>3)); | |
4842 PFREE (sim_toolkit_res); | |
4843 | |
4844 sim_data.ext_sat_cmd = FALSE; | |
4845 stk_start_timer_and_poll(); | |
4846 } | |
4847 else | |
4848 { | |
4849 TRACE_EVENT("no outstanding TR"); | |
4850 } | |
4851 } | |
4852 | |
4853 /* | |
4854 +--------------------------------------------------------------------+ | |
4855 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
4856 | STATE : code ROUTINE : stk_sim_toolkit_req | | |
4857 +--------------------------------------------------------------------+ | |
4858 | |
4859 PURPOSE : Process the primitive SIM_TOOLKIT_REQ. MMI sends an | |
4860 Envelope Message to SIM toolkit. | |
4861 | |
4862 */ | |
4863 | |
4864 GLOBAL void stk_sim_toolkit_req (T_SIM_TOOLKIT_REQ * sim_toolkit_req) | |
4865 { | |
4866 PALLOC (sim_toolkit_cnf, SIM_TOOLKIT_CNF); | |
4867 | |
4868 sim_toolkit_cnf->stk_cmd.o_cmd = 0; | |
4869 sim_toolkit_cnf->req_id = sim_toolkit_req->req_id; | |
4870 | |
4871 TRACE_FUNCTION ("stk_sim_toolkit_req()"); | |
4872 | |
4873 switch (sim_toolkit_req->source) // check valid source | |
4874 { | |
4875 case SRC_MMI: | |
4876 case SRC_SMS: | |
4877 break; | |
4878 default: | |
4879 TRACE_EVENT ("SIM_TOOLKIT_REQ: invalid source"); | |
4880 PFREE (sim_toolkit_cnf); | |
4881 PFREE (sim_toolkit_req); | |
4882 return; | |
4883 } | |
4884 /* | |
4885 * Forward envelope command to SIM toolkit | |
4886 */ | |
4887 sim_toolkit_cnf->cause = FKT_Envelope (sim_toolkit_cnf->stk_cmd.cmd, | |
4888 sim_toolkit_req->stk_cmd.cmd, | |
4889 (USHORT)(sim_toolkit_req->stk_cmd.l_cmd >> 3), | |
4890 NOT_PRESENT_16BIT); | |
4891 | |
4892 /* | |
4893 * Special treatment of SW1 is required for Call Control/MO-SM Control by SIM | |
4894 */ | |
4895 if (sim_toolkit_cnf->cause NEQ SIM_NO_ERROR) | |
4896 { | |
4897 switch (sim_toolkit_req->stk_cmd.cmd[0]) /* ENVELOPE tag */ | |
4898 { | |
4899 case 0xD4: /* Call Control */ | |
4900 case 0xD5: /* MO-SM Control */ | |
4901 if (sim_data.sw1 EQ 0x6F OR sim_data.sw1 EQ 0x92) /* Card problem */ | |
4902 sim_toolkit_cnf->cause = SIM_NO_ERROR; | |
4903 break; | |
4904 default: | |
4905 break; | |
4906 } | |
4907 } | |
4908 | |
4909 if (sim_data.sim_data_len > 0) | |
4910 { | |
4911 sim_toolkit_cnf->stk_cmd.l_cmd = stk_l_cmd; | |
4912 stk_l_cmd = 0; | |
4913 } | |
4914 else | |
4915 sim_toolkit_cnf->stk_cmd.l_cmd = 0; | |
4916 | |
4917 /* | |
4918 * send confirmation to requesting entity | |
4919 */ | |
4920 if (sim_toolkit_req->source EQ SRC_MMI) | |
4921 { | |
4922 PSENDX (MMI, sim_toolkit_cnf); | |
4923 } | |
4924 else | |
4925 { | |
4926 PSENDX (SMS, sim_toolkit_cnf); | |
4927 } | |
4928 PFREE (sim_toolkit_req); | |
4929 stk_start_timer_and_poll(); | |
4930 } | |
4931 | |
4932 /* | |
4933 +--------------------------------------------------------------------+ | |
4934 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
4935 | STATE : code ROUTINE : stk_file_update_res | | |
4936 +--------------------------------------------------------------------+ | |
4937 | |
4938 PURPOSE : Process the primitive SIM_FILE_UPDATE_RES. A File Change | |
4939 Notification is responded. | |
4940 | |
4941 */ | |
4942 | |
4943 GLOBAL void stk_file_update_res (T_SIM_FILE_UPDATE_RES * file_update_res) | |
4944 { | |
4945 UBYTE *p_res; // access to result code | |
4946 | |
4947 TRACE_FUNCTION ("stk_file_update_res()"); | |
4948 | |
4949 if (file_update_res->source EQ SRC_MMI) | |
4950 sim_data.file_change_resp &= ~1; | |
4951 else if (file_update_res->source EQ SRC_SMS) | |
4952 sim_data.file_change_resp &= ~2; | |
4953 else if (file_update_res->source EQ SRC_MM) | |
4954 sim_data.file_change_resp &= ~4; | |
4955 else | |
4956 { | |
4957 PFREE (file_update_res); | |
4958 return; | |
4959 } | |
4960 p_res = &sim_data.stk_response[sim_data.stk_response[1] + 8]; | |
4961 if (file_update_res->fu_rsc EQ SIM_FU_SUCC_ADD) | |
4962 *p_res = STK_RES_SUCC_ADD_EF_READ; | |
4963 | |
4964 if (sim_data.file_change_resp EQ 0) | |
4965 { | |
4966 FKT_TerminalResponse (sim_data.stk_response, (USHORT)sim_data.stk_resp_len); | |
4967 stk_start_timer_and_poll(); | |
4968 } | |
4969 PFREE (file_update_res); | |
4970 } | |
4971 | |
4972 /* | |
4973 +--------------------------------------------------------------------+ | |
4974 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
4975 | STATE : code ROUTINE : stk_timeout | | |
4976 +--------------------------------------------------------------------+ | |
4977 | |
4978 PURPOSE : Process the timeout of a timer established by the SAT | |
4979 command TIMER MANAGEMENT. | |
4980 | |
4981 */ | |
4982 | |
4983 static const UBYTE timer_env[] = { | |
4984 STK_TIMER_EXPIRATION_TAG, | |
4985 STK_DEVICE_IDENTITY_LEN+STK_TIMER_ID_LEN+STK_TIMER_VALUE_LEN+6, | |
4986 STK_DEVICE_IDENTITY_TAG|STK_COMPREHENSION_REQUIRED, STK_DEVICE_IDENTITY_LEN, 0x82, 0x81, | |
4987 STK_TIMER_ID_TAG|STK_COMPREHENSION_REQUIRED, STK_TIMER_ID_LEN, 0, | |
4988 STK_TIMER_VALUE_TAG|STK_COMPREHENSION_REQUIRED, STK_TIMER_VALUE_LEN, 0, 0, 0 | |
4989 }; | |
4990 | |
4991 extern UBYTE pending_timers[]; | |
4992 extern UBYTE next_pos_to_fill; | |
4993 extern UBYTE next_pos_to_send; | |
4994 | |
4995 | |
4996 GLOBAL void stk_timeout (USHORT index) | |
4997 { | |
4998 UBYTE env[sizeof(timer_env)]; | |
4999 UBYTE dummy[4]; | |
5000 USHORT error; | |
5001 | |
5002 TRACE_FUNCTION("stk_timeout"); | |
5003 #ifdef FF_SAT_E | |
5004 /* | |
5005 * handle BIP timeout | |
5006 */ | |
5007 if (index EQ SIM_BIP_TIMER) | |
5008 { | |
5009 /* | |
5010 * close DTI connection | |
5011 */ | |
5012 switch(sim_data.dti_connection_state) | |
5013 { | |
5014 case SIM_DTI_CONNECTION_OPEN: | |
5015 case SIM_DTI_CONNECTION_SETUP: | |
5016 stk_close_dti_connection(TRUE); | |
5017 break; | |
5018 | |
5019 default: | |
5020 stk_close_dti_connection(FALSE); | |
5021 break; | |
5022 } | |
5023 /* | |
5024 * close BIP channel and inform MMI | |
5025 */ | |
5026 stk_close_bip_channel(RSLT_BEARIND_PERR, ADD_BIP_CHAN_CLOSD); | |
5027 stk_dti_inform_mmi(SIM_DTI_DISCONNECT, SIM_BIP_CLOSE_CHANNEL); | |
5028 return; | |
5029 } | |
5030 #endif /* FF_SAT_E */ | |
5031 | |
5032 if ((unsigned)(--index) >= MAX_SAT_TIMER) /* index range 0..7 */ | |
5033 return; | |
5034 | |
5035 if (sim_data.timer[index].active) | |
5036 { | |
5037 memcpy (env, timer_env, sizeof(timer_env)); | |
5038 env[8] = (UBYTE)(index + 1); /* Timer number range is 1..8 */ | |
5039 env[11] = sim_data.timer[index].hour; | |
5040 env[12] = sim_data.timer[index].minute; | |
5041 env[13] = sim_data.timer[index].second; | |
5042 | |
5043 error = FKT_Envelope (dummy, env, sizeof(timer_env), 0); | |
5044 //TISH, test patch for OMAPS00179771: SATK: Timer Expiration, modified by Jinshu Wang, 2008-09-01 | |
5045 //start | |
5046 #if 0 | |
5047 if (error EQ SIM_NO_ERROR) | |
5048 stk_start_timer_and_poll(); | |
5049 #else | |
5050 if (error EQ SIM_NO_ERROR) | |
5051 { | |
5052 stk_start_timer_and_poll(); | |
5053 sim_data.timer[index].active = FALSE; //modified by Jinshu Wang, 2008-09-04 | |
5054 if(sim_data.chk_sat_avail) | |
5055 { | |
5056 sim_data.chk_sat_avail = FALSE; | |
5057 stk_proactive_polling(); | |
5058 } | |
5059 return; //modified by Jinshu Wang, 2008-09-04 | |
5060 } | |
5061 #endif | |
5062 //end | |
5063 /* | |
5064 * If SIM response is busy(9300), we have to once retry sending | |
5065 * timer-expiry envelope after SIM becomes OK on getting a TR | |
5066 */ | |
5067 if (error EQ SIM_CAUSE_SAT_BUSY) | |
5068 { | |
5069 pending_timers[next_pos_to_fill] = (UBYTE) index; | |
5070 if (8 == next_pos_to_fill) | |
5071 { | |
5072 next_pos_to_fill = 0; | |
5073 } | |
5074 else | |
5075 { | |
5076 next_pos_to_fill++; | |
5077 } | |
5078 } | |
5079 sim_data.timer[index].active = FALSE; | |
5080 } | |
5081 } | |
5082 | |
5083 #ifdef TI_PS_FF_AT_P_CMD_CUST | |
5084 /* | |
5085 +--------------------------------------------------------------------+ | |
5086 | PROJECT : GSM-PS (8419) MODULE : SIM_STK | | |
5087 | STATE : code ROUTINE : stk_sim_refresh_user_res | | |
5088 +--------------------------------------------------------------------+ | |
5089 | |
5090 PURPOSE : Process the primitive SIM_REFRESH_USER_RES. MMI sends a | |
5091 Response Message to SIM_TOOLKIT_IND. | |
5092 This Primitive should not occur when cust_mode is 0 | |
5093 | |
5094 */ | |
5095 | |
5096 GLOBAL void stk_sim_refresh_user_res (T_SIM_REFRESH_USER_RES * sim_refresh_user_res) | |
5097 { | |
5098 TRACE_FUNCTION ("stk_sim_refresh_user_res()"); | |
5099 | |
5100 /* primitive should not occur for cust_mode 0 */ | |
5101 if (sim_data.cust_mode EQ 0) | |
5102 { | |
5103 //Handle error condition | |
5104 TRACE_FUNCTION_P1 ("!!!!Incorrect operation: Unexpected mode: cust_mode = %d !!!!",sim_data.cust_mode); | |
5105 TRACE_FUNCTION ("Primitive should not occur if cust_mode = 0"); | |
5106 //MFREE (sim_data.context_switch_ptr); Don't free context as it should be freed by other thread. i.e. stk_proactive_polling() | |
5107 PFREE (sim_refresh_user_res); | |
5108 return; | |
5109 } | |
5110 | |
5111 /* check that we are expecting primitive */ | |
5112 if ( sim_data.user_confirmation_expected EQ FALSE ) | |
5113 { | |
5114 //Handle error condition | |
5115 TRACE_FUNCTION ("!!!!Incorrect operation: user_confirmation_expected is FALSE !!!!"); | |
5116 TRACE_FUNCTION ("Primitive should only occur if user_confirmation_expected is TRUE"); | |
5117 //MFREE (sim_data.context_switch_ptr); Don't free context switch as setup can not be guaranteed to be correct. | |
5118 PFREE (sim_refresh_user_res); | |
5119 return; | |
5120 } | |
5121 else | |
5122 { | |
5123 //Reset user_confirmation_expected | |
5124 sim_data.user_confirmation_expected = FALSE; | |
5125 } | |
5126 | |
5127 | |
5128 if ((sim_refresh_user_res->user_accepts) EQ FALSE) | |
5129 { | |
5130 TRACE_FUNCTION ("User REJECTS Refresh Request"); | |
5131 | |
5132 FKT_TerminalResponse (sim_refresh_user_res->stk_cmd.cmd, | |
5133 (USHORT)(sim_refresh_user_res->stk_cmd.l_cmd>>3)); | |
5134 sim_data.ext_sat_cmd = FALSE; | |
5135 stk_start_timer_and_poll(); | |
5136 | |
5137 //process_sim_refresh() automatically frees the signal. | |
5138 //As we are not calling process_sim_refresh() we need to handle the freeing | |
5139 TRACE_ASSERT(sim_data.context_switch_ptr->sig_ptr); | |
5140 PFREE (sim_data.context_switch_ptr->sig_ptr); | |
5141 } | |
5142 else | |
5143 { | |
5144 TRACE_FUNCTION ("User ACCEPTS Refresh Request"); | |
5145 process_sim_refresh(sim_data.context_switch_ptr); | |
5146 TRACE_FUNCTION ("stk_sim_refresh_user_res() send end of SAT session indicator"); | |
5147 if ((sim_data.term_resp_sent) AND (sim_data.sat_session)) | |
5148 { | |
5149 PALLOC (sim_toolkit_ind, SIM_TOOLKIT_IND); | |
5150 memset (sim_toolkit_ind, 0, sizeof (T_SIM_TOOLKIT_IND)); | |
5151 #ifdef _SIMULATION_ | |
5152 TRACE_EVENT("SAT session ended"); | |
5153 #endif | |
5154 sim_data.sat_session = FALSE; | |
5155 sim_data.term_resp_sent = FALSE; | |
5156 PSENDX (MMI, sim_toolkit_ind); | |
5157 } | |
5158 | |
5159 } | |
5160 TRACE_ASSERT(sim_data.context_switch_ptr); | |
5161 MFREE (sim_data.context_switch_ptr); | |
5162 sim_data.context_switch_ptr = NULL; | |
5163 | |
5164 PFREE (sim_refresh_user_res); | |
5165 TRACE_FUNCTION ("stk_sim_refresh_user_res() exited"); | |
5166 } | |
5167 #endif /* TI_PS_FF_AT_P_CMD_CUST */ | |
5168 | |
5169 #endif |