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 err("Invalid message");
82 tcore_at_tok_free(tokens);
86 hexData = (char *)g_slist_nth_data(tokens, 0);
87 dbg("SAT data: [%s] SAT data length: [%d]", hexData, strlen(hexData));
89 tmp = util_removeQuotes(hexData);
90 recordData = util_hexStringToBytes(tmp);
91 dbg("recordData: %x", recordData);
93 util_hex_dump(" ", strlen(hexData) / 2, recordData);
94 len_proactive_cmd = strlen(recordData);
95 dbg("len_proactive_cmd = %d", len_proactive_cmd);
96 tcore_sat_decode_proactive_command((unsigned char *) recordData, (strlen(hexData) / 2) - 1, &decoded_data);
99 proactive_noti.cmd_number = decoded_data.cmd_num;
100 proactive_noti.cmd_type = decoded_data.cmd_type;
102 switch (decoded_data.cmd_type) {
103 case SAT_PROATV_CMD_DISPLAY_TEXT:
104 dbg("decoded command is display text!!");
105 memcpy(&proactive_noti.proactive_ind_data.display_text, &decoded_data.data.display_text, sizeof(struct tel_sat_display_text_tlv));
108 case SAT_PROATV_CMD_GET_INKEY:
109 dbg("decoded command is get inkey!!");
110 memcpy(&proactive_noti.proactive_ind_data.get_inkey, &decoded_data.data.get_inkey, sizeof(struct tel_sat_get_inkey_tlv));
113 case SAT_PROATV_CMD_GET_INPUT:
114 dbg("decoded command is get input!!");
115 memcpy(&proactive_noti.proactive_ind_data.get_input, &decoded_data.data.get_input, sizeof(struct tel_sat_get_input_tlv));
118 case SAT_PROATV_CMD_MORE_TIME:
119 dbg("decoded command is more time!!");
120 memcpy(&proactive_noti.proactive_ind_data.more_time, &decoded_data.data.more_time, sizeof(struct tel_sat_more_time_tlv));
123 case SAT_PROATV_CMD_PLAY_TONE:
124 dbg("decoded command is play tone!!");
125 memcpy(&proactive_noti.proactive_ind_data.play_tone, &decoded_data.data.play_tone, sizeof(struct tel_sat_play_tone_tlv));
128 case SAT_PROATV_CMD_SETUP_MENU:
129 dbg("decoded command is SETUP MENU!!");
130 memcpy(&proactive_noti.proactive_ind_data.setup_menu, &decoded_data.data.setup_menu, sizeof(struct tel_sat_setup_menu_tlv));
133 case SAT_PROATV_CMD_SELECT_ITEM:
134 dbg("decoded command is select item!!");
135 memcpy(&proactive_noti.proactive_ind_data.select_item, &decoded_data.data.select_item, sizeof(struct tel_sat_select_item_tlv));
138 case SAT_PROATV_CMD_SEND_SMS:
139 dbg("decoded command is send sms!!");
140 memcpy(&proactive_noti.proactive_ind_data.send_sms, &decoded_data.data.send_sms, sizeof(struct tel_sat_send_sms_tlv));
143 case SAT_PROATV_CMD_SEND_SS:
144 dbg("decoded command is send ss!!");
145 memcpy(&proactive_noti.proactive_ind_data.send_ss, &decoded_data.data.send_ss, sizeof(struct tel_sat_send_ss_tlv));
148 case SAT_PROATV_CMD_SEND_USSD:
149 dbg("decoded command is send ussd!!");
150 memcpy(&proactive_noti.proactive_ind_data.send_ussd, &decoded_data.data.send_ussd, sizeof(struct tel_sat_send_ussd_tlv));
153 case SAT_PROATV_CMD_SETUP_CALL:
154 dbg("decoded command is setup call!!");
155 memcpy(&proactive_noti.proactive_ind_data.setup_call, &decoded_data.data.setup_call, sizeof(struct tel_sat_setup_call_tlv));
158 case SAT_PROATV_CMD_REFRESH:
159 dbg("decoded command is refresh");
160 memcpy(&proactive_noti.proactive_ind_data.refresh, &decoded_data.data.refresh, sizeof(struct tel_sat_refresh_tlv));
163 case SAT_PROATV_CMD_PROVIDE_LOCAL_INFO:
164 dbg("decoded command is provide local info");
165 memcpy(&proactive_noti.proactive_ind_data.provide_local_info, &decoded_data.data.provide_local_info, sizeof(struct tel_sat_provide_local_info_tlv));
168 case SAT_PROATV_CMD_SETUP_EVENT_LIST:
169 dbg("decoded command is setup event list!!");
170 memcpy(&proactive_noti.proactive_ind_data.setup_event_list, &decoded_data.data.setup_event_list, sizeof(struct tel_sat_setup_event_list_tlv));
171 // setup_event_rsp_get(o, &decoded_data.data.setup_event_list);
174 case SAT_PROATV_CMD_SETUP_IDLE_MODE_TEXT:
175 dbg("decoded command is setup idle mode text");
176 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));
179 case SAT_PROATV_CMD_SEND_DTMF:
180 dbg("decoded command is send dtmf");
181 memcpy(&proactive_noti.proactive_ind_data.send_dtmf, &decoded_data.data.send_dtmf, sizeof(struct tel_sat_send_dtmf_tlv));
184 case SAT_PROATV_CMD_LANGUAGE_NOTIFICATION:
185 dbg("decoded command is language notification");
186 memcpy(&proactive_noti.proactive_ind_data.language_notification, &decoded_data.data.language_notification, sizeof(struct tel_sat_language_notification_tlv));
189 case SAT_PROATV_CMD_LAUNCH_BROWSER:
190 dbg("decoded command is launch browser");
191 memcpy(&proactive_noti.proactive_ind_data.launch_browser, &decoded_data.data.launch_browser, sizeof(struct tel_sat_launch_browser_tlv));
194 case SAT_PROATV_CMD_OPEN_CHANNEL:
195 dbg("decoded command is open channel!!");
196 memcpy(&proactive_noti.proactive_ind_data.open_channel, &decoded_data.data.open_channel, sizeof(struct tel_sat_open_channel_tlv));
199 case SAT_PROATV_CMD_CLOSE_CHANNEL:
200 dbg("decoded command is close channel!!");
201 memcpy(&proactive_noti.proactive_ind_data.close_channel, &decoded_data.data.close_channel, sizeof(struct tel_sat_close_channel_tlv));
204 case SAT_PROATV_CMD_RECEIVE_DATA:
205 dbg("decoded command is receive data!!");
206 memcpy(&proactive_noti.proactive_ind_data.receive_data, &decoded_data.data.receive_data, sizeof(struct tel_sat_receive_channel_tlv));
209 case SAT_PROATV_CMD_SEND_DATA:
210 dbg("decoded command is send data!!");
211 memcpy(&proactive_noti.proactive_ind_data.send_data, &decoded_data.data.send_data, sizeof(struct tel_sat_send_channel_tlv));
214 case SAT_PROATV_CMD_GET_CHANNEL_STATUS:
215 dbg("decoded command is get channel status!!");
216 memcpy(&proactive_noti.proactive_ind_data.get_channel_status, &decoded_data.data.get_channel_status, sizeof(struct tel_sat_get_channel_status_tlv));
223 if (decoded_data.cmd_type == SAT_PROATV_CMD_REFRESH) {
225 dbg("Not suported Proactive command");
228 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SAT_PROACTIVE_CMD,
229 sizeof(struct tnoti_sat_proactive_ind), &proactive_noti);
230 tcore_at_tok_free(tokens);
231 dbg("Function Exit");
235 static void on_response_envelop_cmd(TcorePending *p, int data_len, const void *data, void *user_data)
237 const TcoreATResponse *resp = data;
238 UserRequest *ur = NULL;
239 CoreObject *o = NULL;
240 const struct treq_sat_envelop_cmd_data *req_data = NULL;
241 GSList *tokens = NULL;
242 struct tresp_sat_envelop_data res;
243 const char *line = NULL;
244 const char *env_res = NULL;
247 ur = tcore_pending_ref_user_request(p);
248 req_data = tcore_user_request_ref_data(ur, NULL);
249 o = tcore_pending_ref_core_object(p);
252 dbg("request data is NULL");
255 memset(&res, 0, sizeof(struct tresp_sat_envelop_data));
257 res.sub_cmd = req_data->sub_cmd;
259 if (resp->success > 0) {
262 line = (const char *) resp->lines->data;
263 tokens = tcore_at_tok_new(line);
264 if (g_slist_length(tokens) < 1) {
265 msg("invalid message");
266 tcore_at_tok_free(tokens);
270 env_res = g_slist_nth_data(tokens, 0);
272 res.envelop_resp = ENVELOPE_SUCCESS;
273 dbg("RESPONSE OK 3");
274 if (NULL != g_slist_nth_data(tokens, 1)) {
275 sw2 = atoi(g_slist_nth_data(tokens, 1));
276 dbg("RESPONSE OK 4");
278 dbg("RESPONSE OK 5");
279 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SAT_SESSION_END, 0, NULL);
285 res.envelop_resp = ENVELOPE_FAILED;
289 tcore_user_request_send_response(ur, TRESP_SAT_REQ_ENVELOPE, sizeof(struct tresp_sat_envelop_data), &res);
291 tcore_at_tok_free(tokens);
292 dbg(" Function exit");
296 static void on_response_terminal_response(TcorePending *p, int data_len, const void *data, void *user_data)
298 UserRequest *ur = NULL;
299 CoreObject *o = NULL;
300 const TcoreATResponse *resp = data;
303 dbg("Function Entry");
305 if (resp->success > 0) {
307 dbg(" resp->success = %d", resp->success);
308 ur = tcore_pending_ref_user_request(p);
309 tmp = (gpointer) tcore_user_request_ref_communicator(ur);
311 dbg("error - current ur is NULL");
315 o = tcore_pending_ref_core_object(p);
317 dbg("error - current sat core is NULL");
318 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SAT_SESSION_END, 0, NULL);
320 dbg("Function Exit");
323 static TReturn s_envelope(CoreObject *o, UserRequest *ur)
326 TcoreATRequest *req = NULL;
327 TcorePending *pending = NULL;
328 char *cmd_str = NULL;
329 const struct treq_sat_envelop_cmd_data *req_data = NULL;
330 int envelope_cmd_len = 0;
331 char envelope_cmd[ENVELOPE_CMD_LEN];
333 char envelope_cmdhex[ENVELOPE_CMD_LEN * 2];
334 char *pbuffer = NULL;
336 dbg("Function Entry");
337 memset(&envelope_cmdhex, 0x00, sizeof(envelope_cmdhex));
338 pbuffer = envelope_cmdhex;
340 hal = tcore_object_get_hal(o);
341 if(FALSE == tcore_hal_get_power_state(hal)){
342 dbg("cp not ready/n");
343 return TCORE_RETURN_ENOSYS;
346 pending = tcore_pending_new(o, 0);
347 req_data = tcore_user_request_ref_data(ur, NULL);
348 dbg("new pending sub cmd(%d)", req_data->sub_cmd);
350 envelope_cmd_len = tcore_sat_encode_envelop_cmd(req_data, (char *) envelope_cmd);
352 dbg("envelope_cmd_len %d", envelope_cmd_len);
353 if (envelope_cmd_len == 0) {
354 return TCORE_RETURN_EINVAL;
356 for (count = 0; count < envelope_cmd_len; count++) {
357 dbg("envelope_cmd %02x", (unsigned char)envelope_cmd[count]);
358 sprintf(pbuffer, "%02x", (unsigned char)envelope_cmd[count]);
361 dbg("pbuffer %s", envelope_cmdhex);
362 cmd_str = g_strdup_printf("AT+SATE=\"%s\"", envelope_cmdhex);
363 req = tcore_at_request_new(cmd_str, "+SATE:", TCORE_AT_SINGLELINE);
364 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
366 tcore_pending_set_request_data(pending, 0, req);
367 tcore_pending_set_response_callback(pending, on_response_envelop_cmd, hal);
368 tcore_pending_link_user_request(pending, ur);
369 tcore_pending_set_send_callback(pending, on_confirmation_sat_message_send, NULL);
370 tcore_hal_send_request(hal, pending);
373 dbg("Function Exit");
374 return TCORE_RETURN_SUCCESS;
377 static TReturn s_terminal_response(CoreObject *o, UserRequest *ur)
379 TcoreHal *hal = NULL;
380 TcoreATRequest *req = NULL;
381 TcorePending *pending = NULL;
382 char *cmd_str = NULL;
383 const struct treq_sat_terminal_rsp_data *req_data = NULL;
384 int proactive_resp_len = 0;
385 char proactive_resp[ENVELOPE_CMD_LEN];
386 char proactive_resphex[ENVELOPE_CMD_LEN * 2];
387 char *pbuffer = NULL;
389 char *hexString = NULL;
391 dbg("Function Entry");
392 memset(&proactive_resphex, 0x00, sizeof(proactive_resphex));
393 pbuffer = proactive_resphex;
394 hal = tcore_object_get_hal(o);
395 if(FALSE == tcore_hal_get_power_state(hal)){
396 dbg("cp not ready/n");
397 return TCORE_RETURN_ENOSYS;
400 pending = tcore_pending_new(o, 0);
401 req_data = tcore_user_request_ref_data(ur, NULL);
403 proactive_resp_len = tcore_sat_encode_terminal_response(req_data, (char *) proactive_resp);
404 dbg("proactive_resp %s", proactive_resp);
405 dbg("proactive_resp length %d", strlen(proactive_resp));
406 if (proactive_resp_len == 0) {
407 return TCORE_RETURN_EINVAL;
409 hexString = calloc((proactive_resp_len * 2) + 1, 1);
411 for (i = 0; i < proactive_resp_len * 2; i += 2) {
413 value = (proactive_resp[i / 2] & 0xf0) >> 4;
415 hexString[i] = ((proactive_resp[i / 2] & 0xf0) >> 4) + '0';
417 hexString[i] = ((proactive_resp[i / 2] & 0xf0) >> 4) + 'A' - 10;
419 value = proactive_resp[i / 2] & 0x0f;
421 hexString[i + 1] = (proactive_resp[i / 2] & 0x0f) + '0';
423 hexString[i + 1] = (proactive_resp[i / 2] & 0x0f) + 'A' - 10;
426 dbg("hexString %s", hexString);
427 cmd_str = g_strdup_printf("AT+SATR=\"%s\"", hexString);
429 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT);
430 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
432 tcore_pending_set_request_data(pending, 0, req);
433 tcore_pending_set_response_callback(pending, on_response_terminal_response, hal);
434 tcore_pending_link_user_request(pending, ur);
435 tcore_pending_set_send_callback(pending, on_confirmation_sat_message_send, NULL);
436 tcore_hal_send_request(hal, pending);
439 dbg("Function Exit");
440 return TCORE_RETURN_SUCCESS;
443 static struct tcore_sat_operations sat_ops = {
444 .envelope = s_envelope,
445 .terminal_response = s_terminal_response,
448 gboolean s_sat_init(TcorePlugin *cp, CoreObject *co_sat)
452 tcore_sat_override_ops(co_sat, &sat_ops);
454 tcore_object_override_callback(co_sat, "+SATI", on_event_sat_proactive_command, NULL);
455 tcore_object_override_callback(co_sat, "+SATN", on_event_sat_proactive_command, NULL);
456 tcore_object_override_callback(co_sat, "+SATF", on_response_terminal_response_confirm, NULL);
463 void s_sat_exit(TcorePlugin *cp, CoreObject *co_sat)