4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Chandan Swarup Patra <chandan.sp@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
27 #include <core_object.h>
32 #include <user_request.h>
37 #define ENVELOPE_CMD_LEN 256
39 static TReturn s_terminal_response(CoreObject *o, UserRequest *ur);
40 static void on_confirmation_sat_message_send(TcorePending *p, gboolean result, void *user_data); // from Kernel
42 static void on_confirmation_sat_message_send(TcorePending *p, gboolean result, void *user_data)
44 dbg("on_confirmation_modem_message_send - msg out from queue.\n");
46 if (result == FALSE) {
54 static gboolean on_response_terminal_response_confirm(CoreObject *o, const void *event_info, void *user_data)
56 dbg("Function Entry");
61 static gboolean on_event_sat_proactive_command(CoreObject *o, const void *event_info, void *user_data)
63 struct tcore_sat_proactive_command decoded_data;
64 struct tnoti_sat_proactive_ind proactive_noti;
65 int len_proactive_cmd = 0;
67 GSList *tokens = NULL;
71 char *recordData = NULL;
73 dbg("Function Entry");
75 memset(&proactive_noti, 0x00, sizeof(struct tnoti_sat_proactive_ind));
76 memset(&decoded_data, 0x00, sizeof(struct tcore_sat_proactive_command));
77 lines = (GSList *) event_info;
78 line = (char *) lines->data;
79 tokens = tcore_at_tok_new(line);
80 if (g_slist_length(tokens) != 1) {
81 dbg("invalid message");
82 tcore_at_tok_free(tokens);
85 hexData = (char *) g_slist_nth_data(tokens, 0);
87 dbg("hexdata %s ", hexData);
88 dbg("hexdata length %d", strlen(hexData));
90 tmp = util_removeQuotes(hexData);
91 recordData = util_hexStringToBytes(tmp);
92 dbg("recordData: %x", recordData);
94 util_hex_dump(" ", strlen(hexData) / 2, recordData);
95 len_proactive_cmd = strlen(recordData);
96 dbg("len_proactive_cmd = %d", len_proactive_cmd);
97 tcore_sat_decode_proactive_command((unsigned char *) recordData, (strlen(hexData) / 2) - 1, &decoded_data);
100 proactive_noti.cmd_number = decoded_data.cmd_num;
101 proactive_noti.cmd_type = decoded_data.cmd_type;
103 switch (decoded_data.cmd_type) {
104 case SAT_PROATV_CMD_DISPLAY_TEXT:
105 dbg("decoded command is display text!!");
106 memcpy(&proactive_noti.proactive_ind_data.display_text, &decoded_data.data.display_text, sizeof(struct tel_sat_display_text_tlv));
109 case SAT_PROATV_CMD_GET_INKEY:
110 dbg("decoded command is get inkey!!");
111 memcpy(&proactive_noti.proactive_ind_data.get_inkey, &decoded_data.data.get_inkey, sizeof(struct tel_sat_get_inkey_tlv));
114 case SAT_PROATV_CMD_GET_INPUT:
115 dbg("decoded command is get input!!");
116 memcpy(&proactive_noti.proactive_ind_data.get_input, &decoded_data.data.get_input, sizeof(struct tel_sat_get_input_tlv));
119 case SAT_PROATV_CMD_MORE_TIME:
120 dbg("decoded command is more time!!");
121 memcpy(&proactive_noti.proactive_ind_data.more_time, &decoded_data.data.more_time, sizeof(struct tel_sat_more_time_tlv));
124 case SAT_PROATV_CMD_PLAY_TONE:
125 dbg("decoded command is play tone!!");
126 memcpy(&proactive_noti.proactive_ind_data.play_tone, &decoded_data.data.play_tone, sizeof(struct tel_sat_play_tone_tlv));
129 case SAT_PROATV_CMD_SETUP_MENU:
130 dbg("decoded command is SETUP MENU!!");
131 memcpy(&proactive_noti.proactive_ind_data.setup_menu, &decoded_data.data.setup_menu, sizeof(struct tel_sat_setup_menu_tlv));
134 case SAT_PROATV_CMD_SELECT_ITEM:
135 dbg("decoded command is select item!!");
136 memcpy(&proactive_noti.proactive_ind_data.select_item, &decoded_data.data.select_item, sizeof(struct tel_sat_select_item_tlv));
139 case SAT_PROATV_CMD_SEND_SMS:
140 dbg("decoded command is send sms!!");
141 memcpy(&proactive_noti.proactive_ind_data.send_sms, &decoded_data.data.send_sms, sizeof(struct tel_sat_send_sms_tlv));
144 case SAT_PROATV_CMD_SEND_SS:
145 dbg("decoded command is send ss!!");
146 memcpy(&proactive_noti.proactive_ind_data.send_ss, &decoded_data.data.send_ss, sizeof(struct tel_sat_send_ss_tlv));
149 case SAT_PROATV_CMD_SEND_USSD:
150 dbg("decoded command is send ussd!!");
151 memcpy(&proactive_noti.proactive_ind_data.send_ussd, &decoded_data.data.send_ussd, sizeof(struct tel_sat_send_ussd_tlv));
154 case SAT_PROATV_CMD_SETUP_CALL:
155 dbg("decoded command is setup call!!");
156 memcpy(&proactive_noti.proactive_ind_data.setup_call, &decoded_data.data.setup_call, sizeof(struct tel_sat_setup_call_tlv));
159 case SAT_PROATV_CMD_REFRESH:
160 dbg("decoded command is refresh");
161 memcpy(&proactive_noti.proactive_ind_data.refresh, &decoded_data.data.refresh, sizeof(struct tel_sat_refresh_tlv));
164 case SAT_PROATV_CMD_PROVIDE_LOCAL_INFO:
165 dbg("decoded command is provide local info");
166 memcpy(&proactive_noti.proactive_ind_data.provide_local_info, &decoded_data.data.provide_local_info, sizeof(struct tel_sat_provide_local_info_tlv));
169 case SAT_PROATV_CMD_SETUP_EVENT_LIST:
170 dbg("decoded command is setup event list!!");
171 memcpy(&proactive_noti.proactive_ind_data.setup_event_list, &decoded_data.data.setup_event_list, sizeof(struct tel_sat_setup_event_list_tlv));
172 // setup_event_rsp_get(o, &decoded_data.data.setup_event_list);
175 case SAT_PROATV_CMD_SETUP_IDLE_MODE_TEXT:
176 dbg("decoded command is setup idle mode text");
177 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));
180 case SAT_PROATV_CMD_SEND_DTMF:
181 dbg("decoded command is send dtmf");
182 memcpy(&proactive_noti.proactive_ind_data.send_dtmf, &decoded_data.data.send_dtmf, sizeof(struct tel_sat_send_dtmf_tlv));
185 case SAT_PROATV_CMD_LANGUAGE_NOTIFICATION:
186 dbg("decoded command is language notification");
187 memcpy(&proactive_noti.proactive_ind_data.language_notification, &decoded_data.data.language_notification, sizeof(struct tel_sat_language_notification_tlv));
190 case SAT_PROATV_CMD_LAUNCH_BROWSER:
191 dbg("decoded command is launch browser");
192 memcpy(&proactive_noti.proactive_ind_data.launch_browser, &decoded_data.data.launch_browser, sizeof(struct tel_sat_launch_browser_tlv));
195 case SAT_PROATV_CMD_OPEN_CHANNEL:
196 dbg("decoded command is open channel!!");
197 memcpy(&proactive_noti.proactive_ind_data.open_channel, &decoded_data.data.open_channel, sizeof(struct tel_sat_open_channel_tlv));
200 case SAT_PROATV_CMD_CLOSE_CHANNEL:
201 dbg("decoded command is close channel!!");
202 memcpy(&proactive_noti.proactive_ind_data.close_channel, &decoded_data.data.close_channel, sizeof(struct tel_sat_close_channel_tlv));
205 case SAT_PROATV_CMD_RECEIVE_DATA:
206 dbg("decoded command is receive data!!");
207 memcpy(&proactive_noti.proactive_ind_data.receive_data, &decoded_data.data.receive_data, sizeof(struct tel_sat_receive_channel_tlv));
210 case SAT_PROATV_CMD_SEND_DATA:
211 dbg("decoded command is send data!!");
212 memcpy(&proactive_noti.proactive_ind_data.send_data, &decoded_data.data.send_data, sizeof(struct tel_sat_send_channel_tlv));
215 case SAT_PROATV_CMD_GET_CHANNEL_STATUS:
216 dbg("decoded command is get channel status!!");
217 memcpy(&proactive_noti.proactive_ind_data.get_channel_status, &decoded_data.data.get_channel_status, sizeof(struct tel_sat_get_channel_status_tlv));
224 if ((decoded_data.cmd_type == SAT_PROATV_CMD_REFRESH) || (decoded_data.cmd_type == SAT_PROATV_CMD_SETUP_EVENT_LIST)) {
226 dbg("Not suported Proactive command");
229 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SAT_PROACTIVE_CMD,
230 sizeof(struct tnoti_sat_proactive_ind), &proactive_noti);
231 tcore_at_tok_free(tokens);
232 dbg("Function Exit");
236 static void on_response_envelop_cmd(TcorePending *p, int data_len, const void *data, void *user_data)
238 const TcoreATResponse *resp = data;
239 UserRequest *ur = NULL;
240 CoreObject *o = NULL;
241 const struct treq_sat_envelop_cmd_data *req_data = NULL;
242 GSList *tokens = NULL;
243 struct tresp_sat_envelop_data res;
244 const char *line = NULL;
245 const char *env_res = NULL;
248 ur = tcore_pending_ref_user_request(p);
249 req_data = tcore_user_request_ref_data(ur, NULL);
250 o = tcore_pending_ref_core_object(p);
253 dbg("request data is NULL");
256 memset(&res, 0, sizeof(struct tresp_sat_envelop_data));
258 res.sub_cmd = req_data->sub_cmd;
260 if (resp->success > 0) {
263 line = (const char *) resp->lines->data;
264 tokens = tcore_at_tok_new(line);
265 if (g_slist_length(tokens) < 1) {
266 msg("invalid message");
267 tcore_at_tok_free(tokens);
271 env_res = g_slist_nth_data(tokens, 0);
273 res.envelop_resp = ENVELOPE_SUCCESS;
274 dbg("RESPONSE OK 3");
275 if (NULL != g_slist_nth_data(tokens, 1)) {
276 sw2 = atoi(g_slist_nth_data(tokens, 1));
277 dbg("RESPONSE OK 4");
279 dbg("RESPONSE OK 5");
280 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SAT_SESSION_END, 0, NULL);
286 res.envelop_resp = ENVELOPE_FAILED;
290 tcore_user_request_send_response(ur, TRESP_SAT_REQ_ENVELOPE, sizeof(struct tresp_sat_envelop_data), &res);
292 tcore_at_tok_free(tokens);
293 dbg(" Function exit");
297 static void on_response_terminal_response(TcorePending *p, int data_len, const void *data, void *user_data)
299 UserRequest *ur = NULL;
300 CoreObject *o = NULL;
301 const TcoreATResponse *resp = data;
304 dbg("Function Entry");
306 if (resp->success > 0) {
308 dbg(" resp->success = %d", resp->success);
309 ur = tcore_pending_ref_user_request(p);
310 tmp = (gpointer) tcore_user_request_ref_communicator(ur);
312 dbg("error - current ur is NULL");
316 o = tcore_pending_ref_core_object(p);
318 dbg("error - current sat core is NULL");
319 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SAT_SESSION_END, 0, NULL);
321 dbg("Function Exit");
324 static TReturn s_envelope(CoreObject *o, UserRequest *ur)
327 TcoreATRequest *req = NULL;
328 TcorePending *pending = NULL;
329 char *cmd_str = NULL;
330 const struct treq_sat_envelop_cmd_data *req_data = NULL;
331 int envelope_cmd_len = 0;
332 char envelope_cmd[ENVELOPE_CMD_LEN];
334 char envelope_cmdhex[ENVELOPE_CMD_LEN * 2];
335 char *pbuffer = NULL;
337 dbg("Function Entry");
338 memset(&envelope_cmdhex, 0x00, sizeof(envelope_cmdhex));
339 pbuffer = envelope_cmdhex;
341 hal = tcore_object_get_hal(o);
342 pending = tcore_pending_new(o, 0);
343 req_data = tcore_user_request_ref_data(ur, NULL);
344 dbg("new pending sub cmd(%d)", req_data->sub_cmd);
346 envelope_cmd_len = tcore_sat_encode_envelop_cmd(req_data, (char *) envelope_cmd);
348 dbg("envelope_cmd_len %d", envelope_cmd_len);
349 if (envelope_cmd_len == 0) {
350 return TCORE_RETURN_EINVAL;
352 for (count = 0; count < envelope_cmd_len; count++) {
353 dbg("envelope_cmd %02x", envelope_cmd[count]);
354 sprintf(pbuffer, "%02x", envelope_cmd[count]);
357 dbg("pbuffer %s", envelope_cmdhex);
358 cmd_str = g_strdup_printf("AT+SATE=\"%s\"", envelope_cmdhex);
359 req = tcore_at_request_new(cmd_str, "+SATE:", TCORE_AT_SINGLELINE);
360 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
362 tcore_pending_set_request_data(pending, 0, req);
363 tcore_pending_set_response_callback(pending, on_response_envelop_cmd, hal);
364 tcore_pending_link_user_request(pending, ur);
365 tcore_pending_set_send_callback(pending, on_confirmation_sat_message_send, NULL);
366 tcore_hal_send_request(hal, pending);
369 dbg("Function Exit");
370 return TCORE_RETURN_SUCCESS;
373 static TReturn s_terminal_response(CoreObject *o, UserRequest *ur)
375 TcoreHal *hal = NULL;
376 TcoreATRequest *req = NULL;
377 TcorePending *pending = NULL;
378 char *cmd_str = NULL;
379 const struct treq_sat_terminal_rsp_data *req_data = NULL;
380 int proactive_resp_len = 0;
381 char proactive_resp[ENVELOPE_CMD_LEN];
382 char proactive_resphex[ENVELOPE_CMD_LEN * 2];
383 char *pbuffer = NULL;
385 char *hexString = NULL;
387 dbg("Function Entry");
388 memset(&proactive_resphex, 0x00, sizeof(proactive_resphex));
389 pbuffer = proactive_resphex;
390 hal = tcore_object_get_hal(o);
391 pending = tcore_pending_new(o, 0);
392 req_data = tcore_user_request_ref_data(ur, NULL);
394 proactive_resp_len = tcore_sat_encode_terminal_response(req_data, (char *) proactive_resp);
395 dbg("proactive_resp %s", proactive_resp);
396 dbg("proactive_resp length %d", strlen(proactive_resp));
397 if (proactive_resp_len == 0) {
398 return TCORE_RETURN_EINVAL;
400 hexString = calloc((proactive_resp_len * 2) + 1, 1);
402 for (i = 0; i < proactive_resp_len * 2; i += 2) {
404 value = (proactive_resp[i / 2] & 0xf0) >> 4;
406 hexString[i] = ((proactive_resp[i / 2] & 0xf0) >> 4) + '0';
408 hexString[i] = ((proactive_resp[i / 2] & 0xf0) >> 4) + 'A' - 10;
410 value = proactive_resp[i / 2] & 0x0f;
412 hexString[i + 1] = (proactive_resp[i / 2] & 0x0f) + '0';
414 hexString[i + 1] = (proactive_resp[i / 2] & 0x0f) + 'A' - 10;
417 dbg("hexString %s", hexString);
418 cmd_str = g_strdup_printf("AT+SATR=\"%s\"", hexString);
420 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT);
421 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
423 tcore_pending_set_request_data(pending, 0, req);
424 tcore_pending_set_response_callback(pending, on_response_terminal_response, hal);
425 tcore_pending_link_user_request(pending, ur);
426 tcore_pending_set_send_callback(pending, on_confirmation_sat_message_send, NULL);
427 tcore_hal_send_request(hal, pending);
430 dbg("Function Exit");
431 return TCORE_RETURN_SUCCESS;
434 static struct tcore_sat_operations sat_ops = {
435 .envelope = s_envelope,
436 .terminal_response = s_terminal_response,
439 gboolean s_sat_init(TcorePlugin *p, TcoreHal *h)
441 CoreObject *o = NULL;
444 o = tcore_sat_new(p, "sat", &sat_ops, h);
446 dbg("CoreObject NULL !!");
450 tcore_object_add_callback(o, "+SATI", on_event_sat_proactive_command, NULL);
451 tcore_object_add_callback(o, "+SATN", on_event_sat_proactive_command, NULL);
452 tcore_object_add_callback(o, "+SATF", on_response_terminal_response_confirm, NULL);
458 void s_sat_exit(TcorePlugin *p)
460 CoreObject *o = NULL;
461 o = tcore_plugin_ref_core_object(p, "sat");