4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
\r
6 * Contact: chandan swarup patra <chandan.sp@samsung.com>
\r
8 * PROPRIETARY/CONFIDENTIAL
\r
10 * This software is the confidential and proprietary information of SAMSUNG ELECTRONICS ("Confidential Information").
\r
11 * You shall not disclose such Confidential Information and shall
\r
12 * use it only in accordance with the terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
\r
13 * SAMSUNG make no representations or warranties about the suitability
\r
14 * of the software, either express or implied, including but not
\r
15 * limited to the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.
\r
16 * SAMSUNG shall not be liable for any damages suffered by licensee as
\r
17 * a result of using, modifying or distributing this software or its derivatives.
\r
26 #include <core_object.h>
\r
31 #include <user_request.h>
\r
34 #include "s_common.h"
\r
36 #define ENVELOPE_CMD_LEN 256
\r
38 static TReturn s_terminal_response(CoreObject *o, UserRequest *ur);
\r
39 static void on_confirmation_sat_message_send(TcorePending *p, gboolean result, void *user_data ); // from Kernel
\r
41 static void on_confirmation_sat_message_send( TcorePending *p, gboolean result, void *user_data )
\r
43 dbg("on_confirmation_modem_message_send - msg out from queue.\n");
\r
45 if (result == FALSE)
\r
56 static gboolean on_response_terminal_response_confirm(CoreObject *o, const void *event_info, void *user_data)
\r
58 dbg("Function Entry");
\r
60 dbg("Function Exit");
\r
63 static gboolean on_event_sat_proactive_command(CoreObject *o, const void *event_info, void *user_data)
\r
65 struct tcore_sat_proactive_command decoded_data;
\r
66 struct tnoti_sat_proactive_ind proactive_noti;
\r
67 int len_proactive_cmd = 0;
\r
68 GSList *lines= NULL;
\r
69 GSList *tokens= NULL;
\r
71 char *hexData= NULL;
\r
73 char *recordData= NULL;
\r
75 dbg("Function Entry");
\r
77 memset(&proactive_noti, 0x00, sizeof(struct tnoti_sat_proactive_ind));
\r
78 memset(&decoded_data, 0x00, sizeof(struct tcore_sat_proactive_command));
\r
79 lines = (GSList*)event_info;
\r
80 line = (char*)lines->data;
\r
81 tokens = tcore_at_tok_new(line);
\r
82 if (g_slist_length(tokens) != 1)
\r
84 dbg("invalid message");
\r
85 tcore_at_tok_free(tokens);
\r
88 hexData = (char*)g_slist_nth_data(tokens, 0);
\r
90 dbg("hexdata %s ", hexData);
\r
91 dbg("hexdata length %d", strlen(hexData));
\r
93 tmp = calloc(1, strlen(hexData)-1);
\r
98 memcpy(tmp, hexData+1, strlen(hexData)-2);
\r
100 recordData = util_hexStringToBytes(tmp);
\r
101 dbg("recordData: %x", recordData);
\r
103 util_hex_dump(" ", strlen(hexData)/2, recordData);
\r
104 len_proactive_cmd = strlen(recordData);
\r
105 dbg("len_proactive_cmd = %d", len_proactive_cmd);
\r
106 tcore_sat_decode_proactive_command((unsigned char*)recordData, (strlen(hexData)/2) - 1, &decoded_data);
\r
109 proactive_noti.cmd_number = decoded_data.cmd_num;
\r
110 proactive_noti.cmd_type = decoded_data.cmd_type;
\r
112 switch(decoded_data.cmd_type)
\r
114 case SAT_PROATV_CMD_DISPLAY_TEXT:
\r
115 dbg("decoded command is display text!!");
\r
116 memcpy(&proactive_noti.proactive_ind_data.display_text, &decoded_data.data.display_text, sizeof(struct tel_sat_display_text_tlv));
\r
118 case SAT_PROATV_CMD_GET_INKEY:
\r
119 dbg("decoded command is get inkey!!");
\r
120 memcpy(&proactive_noti.proactive_ind_data.get_inkey, &decoded_data.data.get_inkey, sizeof(struct tel_sat_get_inkey_tlv));
\r
122 case SAT_PROATV_CMD_GET_INPUT:
\r
123 dbg("decoded command is get input!!");
\r
124 memcpy(&proactive_noti.proactive_ind_data.get_input, &decoded_data.data.get_input, sizeof(struct tel_sat_get_input_tlv));
\r
126 case SAT_PROATV_CMD_MORE_TIME:
\r
127 dbg("decoded command is more time!!");
\r
128 memcpy(&proactive_noti.proactive_ind_data.more_time, &decoded_data.data.more_time, sizeof(struct tel_sat_more_time_tlv));
\r
130 case SAT_PROATV_CMD_PLAY_TONE:
\r
131 dbg("decoded command is play tone!!");
\r
132 memcpy(&proactive_noti.proactive_ind_data.play_tone, &decoded_data.data.play_tone, sizeof(struct tel_sat_play_tone_tlv));
\r
134 case SAT_PROATV_CMD_SETUP_MENU:
\r
135 dbg("decoded command is SETUP MENU!!");
\r
136 memcpy(&proactive_noti.proactive_ind_data.setup_menu, &decoded_data.data.setup_menu, sizeof(struct tel_sat_setup_menu_tlv));
\r
138 case SAT_PROATV_CMD_SELECT_ITEM:
\r
139 dbg("decoded command is select item!!");
\r
140 memcpy(&proactive_noti.proactive_ind_data.select_item, &decoded_data.data.select_item, sizeof(struct tel_sat_select_item_tlv));
\r
142 case SAT_PROATV_CMD_SEND_SMS:
\r
143 dbg("decoded command is send sms!!");
\r
144 memcpy(&proactive_noti.proactive_ind_data.send_sms, &decoded_data.data.send_sms, sizeof(struct tel_sat_send_sms_tlv));
\r
146 case SAT_PROATV_CMD_SEND_SS:
\r
147 dbg("decoded command is send ss!!");
\r
148 memcpy(&proactive_noti.proactive_ind_data.send_ss, &decoded_data.data.send_ss, sizeof(struct tel_sat_send_ss_tlv));
\r
150 case SAT_PROATV_CMD_SEND_USSD:
\r
151 dbg("decoded command is send ussd!!");
\r
152 memcpy(&proactive_noti.proactive_ind_data.send_ussd, &decoded_data.data.send_ussd, sizeof(struct tel_sat_send_ussd_tlv));
\r
154 case SAT_PROATV_CMD_SETUP_CALL:
\r
155 dbg("decoded command is setup call!!");
\r
156 memcpy(&proactive_noti.proactive_ind_data.setup_call, &decoded_data.data.setup_call, sizeof(struct tel_sat_setup_call_tlv));
\r
158 case SAT_PROATV_CMD_REFRESH:
\r
159 dbg("decoded command is refresh");
\r
160 memcpy(&proactive_noti.proactive_ind_data.refresh, &decoded_data.data.refresh, sizeof(struct tel_sat_refresh_tlv));
\r
162 case SAT_PROATV_CMD_PROVIDE_LOCAL_INFO:
\r
163 dbg("decoded command is provide local info");
\r
164 memcpy(&proactive_noti.proactive_ind_data.provide_local_info, &decoded_data.data.provide_local_info, sizeof(struct tel_sat_provide_local_info_tlv));
\r
166 case SAT_PROATV_CMD_SETUP_EVENT_LIST:
\r
167 dbg("decoded command is setup event list!!");
\r
168 memcpy(&proactive_noti.proactive_ind_data.setup_event_list, &decoded_data.data.setup_event_list, sizeof(struct tel_sat_setup_event_list_tlv));
\r
169 //setup_event_rsp_get(o, &decoded_data.data.setup_event_list);
\r
171 case SAT_PROATV_CMD_SETUP_IDLE_MODE_TEXT:
\r
172 dbg("decoded command is setup idle mode text");
\r
173 memcpy(&proactive_noti.proactive_ind_data.setup_idle_mode_text, &decoded_data.data.setup_idle_mode_text, sizeof(struct tel_sat_setup_idle_mode_text_tlv));
\r
175 case SAT_PROATV_CMD_SEND_DTMF:
\r
176 dbg("decoded command is send dtmf");
\r
177 memcpy(&proactive_noti.proactive_ind_data.send_dtmf, &decoded_data.data.send_dtmf, sizeof(struct tel_sat_send_dtmf_tlv));
\r
179 case SAT_PROATV_CMD_LANGUAGE_NOTIFICATION:
\r
180 dbg("decoded command is language notification");
\r
181 memcpy(&proactive_noti.proactive_ind_data.language_notification, &decoded_data.data.language_notification, sizeof(struct tel_sat_language_notification_tlv));
\r
183 case SAT_PROATV_CMD_LAUNCH_BROWSER:
\r
184 dbg("decoded command is launch browser");
\r
185 memcpy(&proactive_noti.proactive_ind_data.launch_browser, &decoded_data.data.launch_browser, sizeof(struct tel_sat_launch_browser_tlv));
\r
187 case SAT_PROATV_CMD_OPEN_CHANNEL:
\r
188 dbg("decoded command is open channel!!");
\r
189 memcpy(&proactive_noti.proactive_ind_data.open_channel, &decoded_data.data.open_channel, sizeof(struct tel_sat_open_channel_tlv));
\r
191 case SAT_PROATV_CMD_CLOSE_CHANNEL:
\r
192 dbg("decoded command is close channel!!");
\r
193 memcpy(&proactive_noti.proactive_ind_data.close_channel, &decoded_data.data.close_channel, sizeof(struct tel_sat_close_channel_tlv));
\r
195 case SAT_PROATV_CMD_RECEIVE_DATA:
\r
196 dbg("decoded command is receive data!!");
\r
197 memcpy(&proactive_noti.proactive_ind_data.receive_data, &decoded_data.data.receive_data, sizeof(struct tel_sat_receive_channel_tlv));
\r
199 case SAT_PROATV_CMD_SEND_DATA:
\r
200 dbg("decoded command is send data!!");
\r
201 memcpy(&proactive_noti.proactive_ind_data.send_data, &decoded_data.data.send_data, sizeof(struct tel_sat_send_channel_tlv));
\r
203 case SAT_PROATV_CMD_GET_CHANNEL_STATUS:
\r
204 dbg("decoded command is get channel status!!");
\r
205 memcpy(&proactive_noti.proactive_ind_data.get_channel_status, &decoded_data.data.get_channel_status, sizeof(struct tel_sat_get_channel_status_tlv));
\r
208 dbg("wrong input");
\r
211 if((decoded_data.cmd_type == SAT_PROATV_CMD_REFRESH) || (decoded_data.cmd_type == SAT_PROATV_CMD_SETUP_EVENT_LIST))
\r
214 dbg("Not suported Proactive command");
\r
217 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SAT_PROACTIVE_CMD,
\r
218 sizeof(struct tnoti_sat_proactive_ind), &proactive_noti);
\r
219 tcore_at_tok_free(tokens);
\r
220 dbg("Function Exit");
\r
224 static void on_response_envelop_cmd(TcorePending *p, int data_len, const void *data, void *user_data)
\r
226 const TcoreATResponse *resp = data;
\r
227 UserRequest *ur = NULL;
\r
228 CoreObject *o = NULL;
\r
229 const struct treq_sat_envelop_cmd_data *req_data = NULL;
\r
230 GSList *tokens=NULL;
\r
231 struct tresp_sat_envelop_data res;
\r
232 const char *line = NULL;
\r
233 const char *env_res = NULL;
\r
236 ur = tcore_pending_ref_user_request(p);
\r
237 req_data = tcore_user_request_ref_data(ur, NULL);
\r
238 o = tcore_pending_ref_core_object(p);
\r
241 dbg("request data is NULL");
\r
244 memset(&res, 0, sizeof(struct tresp_sat_envelop_data));
\r
246 res.sub_cmd = req_data->sub_cmd;
\r
248 if(resp->success > 0)
\r
250 dbg("RESPONSE OK");
\r
253 line = (const char*)resp->lines->data;
\r
254 tokens = tcore_at_tok_new(line);
\r
255 if (g_slist_length(tokens) < 1)
\r
257 msg("invalid message");
\r
258 tcore_at_tok_free(tokens);
\r
262 env_res = g_slist_nth_data(tokens, 0);
\r
263 res.result = 0x8000;
\r
264 res.envelop_resp = ENVELOPE_SUCCESS;
\r
265 dbg("RESPONSE OK 3");
\r
266 if(NULL != g_slist_nth_data(tokens, 1))
\r
268 sw2 = atoi(g_slist_nth_data(tokens, 1));
\r
269 dbg("RESPONSE OK 4");
\r
272 dbg("RESPONSE OK 5");
\r
273 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SAT_SESSION_END, 0, NULL);
\r
279 dbg("RESPONSE NOK");
\r
281 res.envelop_resp = ENVELOPE_FAILED;
\r
286 tcore_user_request_send_response(ur, TRESP_SAT_REQ_ENVELOPE, sizeof(struct tresp_sat_envelop_data), &res);
\r
288 tcore_at_tok_free(tokens);
\r
289 dbg(" Function exit");
\r
292 static void on_timeout_terminal_response(TcorePending *p, void *user_data)
\r
294 UserRequest *ur = NULL;
\r
295 CoreObject *o = NULL;
\r
296 gpointer tmp = NULL;
\r
298 dbg("Function Entry");
\r
299 dbg("SAT - TIMEOUT !!!!! pending=%p", p);
\r
301 ur = tcore_pending_ref_user_request(p);
\r
302 tmp = (gpointer)tcore_user_request_ref_communicator(ur);
\r
305 dbg("error - current ur is NULL");
\r
309 o = tcore_pending_ref_core_object(p);
\r
311 dbg("error - current sat core is NULL");
\r
313 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SAT_SESSION_END, 0, NULL);
\r
314 dbg("Function Exit");
\r
318 static void on_response_terminal_response(TcorePending *p, int data_len, const void *data, void *user_data)
\r
320 UserRequest *ur = NULL;
\r
321 CoreObject *o = NULL;
\r
322 const TcoreATResponse *resp = data;
\r
323 gpointer tmp = NULL;
\r
325 dbg("Function Entry");
\r
327 if(resp->success > 0)
\r
329 dbg("RESPONSE OK");
\r
330 dbg(" resp->success = %d", resp->success);
\r
331 ur = tcore_pending_ref_user_request(p);
\r
332 tmp = (gpointer)tcore_user_request_ref_communicator(ur);
\r
335 dbg("error - current ur is NULL");
\r
339 o = tcore_pending_ref_core_object(p);
\r
341 dbg("error - current sat core is NULL");
\r
342 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SAT_SESSION_END, 0, NULL);
\r
344 dbg("Function Exit");
\r
347 static TReturn s_envelope(CoreObject *o, UserRequest *ur)
\r
350 TcoreATRequest *req = NULL;
\r
351 TcorePending *pending = NULL;
\r
352 char *cmd_str = NULL;
\r
353 const struct treq_sat_envelop_cmd_data *req_data = NULL;
\r
354 int envelope_cmd_len = 0;
\r
355 char envelope_cmd[ENVELOPE_CMD_LEN];
\r
357 char envelope_cmdhex[ENVELOPE_CMD_LEN*2];
\r
358 char *pbuffer = NULL;
\r
360 dbg("Function Entry");
\r
361 memset(&envelope_cmdhex, 0x00, sizeof(envelope_cmdhex));
\r
362 pbuffer = envelope_cmdhex;
\r
364 hal = tcore_object_get_hal(o);
\r
365 pending = tcore_pending_new(o, 0);
\r
366 req_data = tcore_user_request_ref_data(ur, NULL);
\r
367 dbg("new pending sub cmd(%d)", req_data->sub_cmd);
\r
369 envelope_cmd_len = tcore_sat_encode_envelop_cmd(req_data, (char *)envelope_cmd);
\r
371 dbg("envelope_cmd_len %d", envelope_cmd_len);
\r
372 if(envelope_cmd_len == 0)
\r
374 return TCORE_RETURN_EINVAL;
\r
376 for(count = 0; count < envelope_cmd_len ;count++ )
\r
378 dbg("envelope_cmd %02x", envelope_cmd[count]);
\r
379 sprintf(pbuffer, "%02x", envelope_cmd[count]);
\r
382 dbg("pbuffer %s", envelope_cmdhex);
\r
383 cmd_str = g_strdup_printf("AT+SATE=\"%s\"%s", envelope_cmdhex,"\r");
\r
384 req = tcore_at_request_new(cmd_str, "+SATE:", TCORE_AT_SINGLELINE);
\r
385 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
\r
387 tcore_pending_set_request_data(pending, 0, req);
\r
388 tcore_pending_set_response_callback(pending, on_response_envelop_cmd, hal);
\r
389 tcore_pending_link_user_request(pending, ur);
\r
390 tcore_pending_set_send_callback(pending, on_confirmation_sat_message_send, NULL);
\r
391 tcore_hal_send_request(hal, pending);
\r
393 dbg("Function Exit");
\r
394 return TCORE_RETURN_SUCCESS;
\r
397 static TReturn s_terminal_response(CoreObject *o, UserRequest *ur)
\r
399 TcoreHal *hal = NULL;
\r
400 TcoreATRequest *req = NULL;
\r
401 TcorePending *pending = NULL;
\r
402 char *cmd_str = NULL;
\r
403 const struct treq_sat_terminal_rsp_data *req_data = NULL;
\r
404 int proactive_resp_len = 0;
\r
405 char proactive_resp[ENVELOPE_CMD_LEN];
\r
406 char proactive_resphex[ENVELOPE_CMD_LEN*2];
\r
407 char *pbuffer = NULL;
\r
409 char *hexString = NULL;
\r
411 dbg("Function Entry");
\r
412 memset(&proactive_resphex, 0x00, sizeof(proactive_resphex));
\r
413 pbuffer = proactive_resphex;
\r
414 hal = tcore_object_get_hal(o);
\r
415 pending = tcore_pending_new(o, 0);
\r
416 req_data = tcore_user_request_ref_data(ur, NULL);
\r
418 proactive_resp_len = tcore_sat_encode_terminal_response(req_data, (char *)proactive_resp);
\r
419 dbg("proactive_resp %s", proactive_resp);
\r
420 dbg("proactive_resp length %d", strlen(proactive_resp));
\r
421 if(proactive_resp_len == 0)
\r
423 return TCORE_RETURN_EINVAL;
\r
425 hexString = calloc((proactive_resp_len*2)+1, 1);
\r
427 for(i=0; i<proactive_resp_len*2; i+=2)
\r
430 value = (proactive_resp[i/2] & 0xf0) >> 4;
\r
432 hexString[i] = ((proactive_resp[i/2] & 0xf0) >> 4) + '0';
\r
434 hexString[i] = ((proactive_resp[i/2] & 0xf0) >> 4) + 'A' -10;
\r
436 value = proactive_resp[i/2] & 0x0f;
\r
438 hexString[i+1] = (proactive_resp[i/2] & 0x0f) + '0';
\r
440 hexString[i+1] = (proactive_resp[i/2] & 0x0f) + 'A' -10;
\r
443 dbg("hexString %s", hexString);
\r
444 cmd_str = g_strdup_printf("AT+SATR=\"%s\"%s", hexString,"\r");
\r
446 req = tcore_at_request_new(cmd_str, NULL , TCORE_AT_NO_RESULT);
\r
447 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
\r
449 tcore_pending_set_request_data(pending, 0, req);
\r
450 tcore_pending_set_timeout(pending, 10);
\r
451 tcore_pending_set_response_callback(pending, on_response_terminal_response, hal);
\r
452 tcore_pending_set_timeout_callback(pending, on_timeout_terminal_response, NULL);
\r
453 tcore_pending_link_user_request(pending, ur);
\r
454 tcore_pending_set_send_callback(pending, on_confirmation_sat_message_send, NULL);
\r
455 tcore_hal_send_request(hal, pending);
\r
457 dbg("Function Exit");
\r
458 return TCORE_RETURN_SUCCESS;
\r
461 static struct tcore_sat_operations sat_ops =
\r
463 .envelope = s_envelope,
\r
464 .terminal_response = s_terminal_response,
\r
467 gboolean s_sat_init(TcorePlugin *p, TcoreHal *h)
\r
469 CoreObject *o = NULL;
\r
472 o = tcore_sat_new(p, "sat", &sat_ops,h);
\r
475 dbg("CoreObject NULL !!");
\r
479 tcore_object_add_callback(o, "+SATI", on_event_sat_proactive_command, NULL);
\r
480 tcore_object_add_callback(o, "+SATN", on_event_sat_proactive_command, NULL);
\r
481 tcore_object_add_callback(o, "+SATF", on_response_terminal_response_confirm, NULL);
\r
487 void s_sat_exit(TcorePlugin *p)
\r
489 CoreObject *o = NULL;
\r
490 o = tcore_plugin_ref_core_object(p, "sat");
\r