4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@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.
29 #include "user_request.h"
32 struct private_object_data {
33 struct tcore_sms_operations *ops;
34 gboolean b_readyStatus;
38 * This function is used to encode SMS Parameters to TPDU on EFsmsp
40 * @return length of string
41 * @param[in] incoming - telephony_sms_Params_t
42 * @param[in] data - TPDU data
43 * @Interface Synchronous.
47 int _tcore_util_sms_encode_smsParameters(const struct telephony_sms_Params *incoming, unsigned char *data, int SMSPRecordLen)
49 struct telephony_sms_Params *smsParams = (struct telephony_sms_Params *)incoming;
50 unsigned int nPIDIndex = 0;
51 unsigned char nOffset = 0;
53 if(incoming == NULL || data == NULL)
56 memset(data, 0xff, SMSPRecordLen);//pSmsParam->RecordLen);
58 dbg(" Record index = %d", (int) smsParams->recordIndex);
59 dbg(" Alpha ID Len = %d", (int) smsParams->alphaIdLen);
60 dbg(" Record Length : %d", SMSPRecordLen);//pSmsParam->RecordLen);
62 if (SMSPRecordLen/*pSmsParam->RecordLen*/>= nDefaultSMSPWithoutAlphaId) {
63 nPIDIndex = SMSPRecordLen
64 /*pSmsParam->RecordLen*/- nDefaultSMSPWithoutAlphaId;
67 //dongil01.park(2008/12/27) - Check Point
68 memcpy(data, smsParams->szAlphaId, (int) nPIDIndex/*pSmsParam->AlphaIdLen*/);
70 dbg(" Alpha ID : %s", smsParams->szAlphaId);
71 dbg(" nPIDIndex = %d", nPIDIndex);
73 data[nPIDIndex] = smsParams->paramIndicator;
75 dbg(" Param Indicator = %02x", smsParams->paramIndicator);
77 if ((smsParams->paramIndicator & SMSPValidDestAddr) == 0x00) {
78 nOffset = nDestAddrOffset;
80 data[nPIDIndex + (nOffset)] = smsParams->tpDestAddr.dialNumLen + 1;
81 data[nPIDIndex + (++nOffset)] = ((smsParams->tpDestAddr.typeOfNum << 4) | smsParams->tpDestAddr.numPlanId) | 0x80;
83 memcpy(&data[nPIDIndex + (++nOffset)], &smsParams->tpDestAddr.diallingNum, smsParams->tpDestAddr.dialNumLen);
85 dbg(" nextIndex = %d", nPIDIndex);
88 if( (smsParams->paramIndicator & SMSPValidSvcAddr) == 0x00 )
90 dbg("TON [%d] / NPI [%d]", smsParams->tpSvcCntrAddr.typeOfNum, smsParams->tpSvcCntrAddr.numPlanId);
92 nOffset = nSCAAddrOffset;
94 dbg("SCA Length : %d", smsParams->tpSvcCntrAddr.dialNumLen);
96 data[nPIDIndex + (nOffset)] = smsParams->tpSvcCntrAddr.dialNumLen + 1;
97 data[nPIDIndex + (++nOffset)] = ((smsParams->tpSvcCntrAddr.typeOfNum << 4) | smsParams->tpSvcCntrAddr.numPlanId) | 0x80;
99 memcpy(&data[nPIDIndex + (++nOffset)], &smsParams->tpSvcCntrAddr.diallingNum, smsParams->tpSvcCntrAddr.dialNumLen);
101 dbg(" nextIndex = %d", nPIDIndex);
104 if ((smsParams->paramIndicator & SMSPValidPID) == 0x00) {
105 nOffset = nPIDOffset;
107 data[nPIDIndex + nOffset] = smsParams->tpProtocolId;
108 dbg(" PID = %02x", smsParams->tpProtocolId);
109 dbg(" nextIndex = %d", nPIDIndex);
112 if ((smsParams->paramIndicator & SMSPValidDCS) == 0x00) {
113 nOffset = nDCSOffset;
115 data[nPIDIndex + nOffset] = smsParams->tpDataCodingScheme;
116 dbg(" DCS = %02x", smsParams->tpDataCodingScheme);
117 dbg(" nextIndex = %d", nPIDIndex);
120 if ((smsParams->paramIndicator & SMSPValidVP) == 0x00) {
123 data[nPIDIndex + nOffset] = smsParams->tpValidityPeriod;
124 dbg(" VP = %02x", smsParams->tpValidityPeriod);
125 dbg(" nextIndex = %d", nPIDIndex);
132 static void _clone_sms_operations(struct private_object_data *po,
133 struct tcore_sms_operations *sms_ops)
135 if (sms_ops->send_umts_msg)
136 po->ops->send_umts_msg = sms_ops->send_umts_msg;
138 if (sms_ops->read_msg)
139 po->ops->read_msg = sms_ops->read_msg;
141 if (sms_ops->save_msg)
142 po->ops->save_msg = sms_ops->save_msg;
144 if (sms_ops->delete_msg)
145 po->ops->delete_msg = sms_ops->delete_msg;
147 if (sms_ops->get_stored_msg_cnt)
148 po->ops->get_stored_msg_cnt = sms_ops->get_stored_msg_cnt;
150 if (sms_ops->get_sca)
151 po->ops->get_sca = sms_ops->get_sca;
153 if (sms_ops->set_sca)
154 po->ops->set_sca = sms_ops->set_sca;
156 if (sms_ops->get_cb_config)
157 po->ops->get_cb_config = sms_ops->get_cb_config;
159 if (sms_ops->set_cb_config)
160 po->ops->set_cb_config = sms_ops->set_cb_config;
162 if (sms_ops->set_mem_status)
163 po->ops->set_mem_status = sms_ops->set_mem_status;
165 if (sms_ops->get_pref_brearer)
166 po->ops->get_pref_brearer = sms_ops->get_pref_brearer;
168 if (sms_ops->set_pref_brearer)
169 po->ops->set_pref_brearer = sms_ops->set_pref_brearer;
171 if (sms_ops->set_delivery_report)
172 po->ops->set_delivery_report = sms_ops->set_delivery_report;
174 if (sms_ops->set_msg_status)
175 po->ops->set_msg_status = sms_ops->set_msg_status;
177 if (sms_ops->get_sms_params)
178 po->ops->get_sms_params = sms_ops->get_sms_params;
180 if (sms_ops->set_sms_params)
181 po->ops->set_sms_params = sms_ops->set_sms_params;
183 if (sms_ops->get_paramcnt)
184 po->ops->get_paramcnt = sms_ops->get_paramcnt;
186 if (sms_ops->send_cdma_msg)
187 po->ops->send_cdma_msg = sms_ops->send_cdma_msg;
192 static TReturn _dispatcher(CoreObject *o, UserRequest *ur)
194 enum tcore_request_command command;
195 struct private_object_data *po;
196 TReturn rtn = TCORE_RETURN_SUCCESS;
198 CORE_OBJECT_CHECK_RETURN(o, CORE_OBJECT_TYPE_SMS, TCORE_RETURN_EINVAL);
200 po = tcore_object_ref_object(o);
201 if (NULL == po || NULL == po->ops) {
202 dbg("[tcore_SMS] ERR: private_object is NULL or ops is NULL");
203 return TCORE_RETURN_ENOSYS;
206 if(po->b_readyStatus == FALSE) {
207 dbg("[tcore_SMS] DEVICE_NOT_READY");
208 return TCORE_RETURN_ENOSYS;
211 command = tcore_user_request_get_command(ur);
213 case TREQ_SMS_SEND_UMTS_MSG:
214 if (NULL == po->ops->send_umts_msg) {
215 dbg("[tcore_SMS] ERR: po->ops->send_umts_msg is NULL");
216 return TCORE_RETURN_ENOSYS;
219 rtn = po->ops->send_umts_msg(o, ur);
223 case TREQ_SMS_READ_MSG:
224 if (NULL == po->ops->read_msg) {
225 dbg("[tcore_SMS] ERR: po->ops->read_msg is NULL");
226 return TCORE_RETURN_ENOSYS;
229 rtn = po->ops->read_msg(o, ur);
233 case TREQ_SMS_SAVE_MSG:
234 if (NULL == po->ops->save_msg) {
235 dbg("[tcore_SMS] ERR: po->ops->save_msg is NULL");
236 return TCORE_RETURN_ENOSYS;
239 rtn = po->ops->save_msg(o, ur);
243 case TREQ_SMS_DELETE_MSG:
244 if (NULL == po->ops->delete_msg) {
245 dbg("[tcore_SMS] ERR: po->ops->delete_msg is NULL");
246 return TCORE_RETURN_ENOSYS;
249 rtn = po->ops->delete_msg(o, ur);
253 case TREQ_SMS_GET_COUNT:
254 if (NULL == po->ops->get_stored_msg_cnt) {
255 dbg("[tcore_SMS] ERR: po->ops->get_stored_msg_cnt is"
257 return TCORE_RETURN_ENOSYS;
260 rtn = po->ops->get_stored_msg_cnt(o, ur);
264 case TREQ_SMS_GET_SCA:
265 if (NULL == po->ops->get_sca) {
266 dbg("[tcore_SMS] ERR: po->ops->get_sca is NULL");
267 return TCORE_RETURN_ENOSYS;
270 rtn = po->ops->get_sca(o, ur);
274 case TREQ_SMS_SET_SCA:
275 if (NULL == po->ops->set_sca) {
276 dbg("[tcore_SMS] ERR: po->ops->set_sca is NULL");
277 return TCORE_RETURN_ENOSYS;
280 rtn = po->ops->set_sca(o, ur);
284 case TREQ_SMS_GET_CB_CONFIG:
285 if (NULL == po->ops->get_cb_config) {
286 dbg("[tcore_SMS] ERR: po->ops->get_cb_config is NULL");
287 return TCORE_RETURN_ENOSYS;
290 rtn = po->ops->get_cb_config(o, ur);
294 case TREQ_SMS_SET_CB_CONFIG:
295 if (NULL == po->ops->set_cb_config) {
296 dbg("[tcore_SMS] ERR: po->ops->set_cb_config is NULL");
297 return TCORE_RETURN_ENOSYS;
300 rtn = po->ops->set_cb_config(o, ur);
304 case TREQ_SMS_SET_MEM_STATUS:
305 if (NULL == po->ops->set_mem_status) {
306 dbg("[tcore_SMS] ERR: po->ops->set_mem_status is"
308 return TCORE_RETURN_ENOSYS;
311 rtn = po->ops->set_mem_status(o, ur);
315 case TREQ_SMS_GET_PREF_BEARER:
316 if (NULL == po->ops->get_pref_brearer) {
317 dbg("[tcore_SMS] ERR: po->ops->get_pref_brearer is"
319 return TCORE_RETURN_ENOSYS;
322 rtn = po->ops->get_pref_brearer(o, ur);
326 case TREQ_SMS_SET_PREF_BEARER:
327 if (NULL == po->ops->set_pref_brearer) {
328 dbg("[tcore_SMS] ERR: po->ops->get_pref_brearer is"
330 return TCORE_RETURN_ENOSYS;
333 rtn = po->ops->set_pref_brearer(o, ur);
337 case TREQ_SMS_SET_DELIVERY_REPORT:
338 if (!po->ops->set_delivery_report) {
339 dbg("[tcore_SMS] ERR: po->ops->set_delivery_report is"
341 return TCORE_RETURN_ENOSYS;
344 rtn = po->ops->set_delivery_report(o, ur);
348 case TREQ_SMS_SET_MSG_STATUS:
349 if (NULL == po->ops->set_msg_status) {
350 dbg("[tcore_SMS] ERR: po->ops->set_msg_status is"
352 return TCORE_RETURN_ENOSYS;
355 rtn = po->ops->set_msg_status(o, ur);
359 case TREQ_SMS_GET_PARAMS:
360 if (NULL == po->ops->get_sms_params) {
361 dbg("[tcore_SMS] ERR: po->ops->get_sms_params is"
363 return TCORE_RETURN_ENOSYS;
366 rtn = po->ops->get_sms_params(o, ur);
370 case TREQ_SMS_SET_PARAMS:
371 if (NULL == po->ops->set_sms_params) {
372 dbg("[tcore_SMS] ERR: po->ops->set_sms_params is"
374 return TCORE_RETURN_ENOSYS;
377 rtn = po->ops->set_sms_params(o, ur);
381 case TREQ_SMS_GET_PARAMCNT:
382 if (NULL == po->ops->get_paramcnt) {
383 dbg("[tcore_SMS] ERR: po->ops->get_paramcnt is NULL");
384 return TCORE_RETURN_ENOSYS;
387 rtn = po->ops->get_paramcnt(o, ur);
391 case TREQ_SMS_SEND_CDMA_MSG:
392 if (NULL == po->ops->send_cdma_msg) {
393 dbg("[tcore_SMS] ERR: po->ops->send_cdma_msg is NULL");
394 return TCORE_RETURN_ENOSYS;
397 rtn = po->ops->send_cdma_msg(o, ur);
405 dbg("[tcore_SMS] result = [0x%x], command = [0x%x]", rtn, command);
410 static void _free_hook(CoreObject *o)
412 struct private_object_data *po = NULL;
414 CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_SMS);
416 po = tcore_object_ref_object(o);
419 tcore_object_link_object(o, NULL);
423 static void _clone_hook(CoreObject *src, CoreObject *dest)
425 struct private_object_data *src_po = NULL;
426 struct private_object_data *dest_po = NULL;
431 dest_po = calloc(sizeof(struct private_object_data), 1);
433 tcore_object_link_object(dest, NULL);
437 src_po = tcore_object_ref_object(src);
438 dest_po->ops = src_po->ops;
440 tcore_object_link_object(dest, dest_po);
443 gboolean tcore_sms_get_ready_status(CoreObject *o)
445 struct private_object_data *po = NULL;
446 po = tcore_object_ref_object(o);
448 dbg("po access fail");
452 return po->b_readyStatus;
455 gboolean tcore_sms_set_ready_status(CoreObject *o, int status)
457 struct private_object_data *po = NULL;
458 po = tcore_object_ref_object(o);
460 dbg("po access fail");
464 po->b_readyStatus = status;
469 void tcore_sms_override_ops(CoreObject *o, struct tcore_sms_operations *sms_ops)
471 struct private_object_data *po = NULL;
473 CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_SMS);
475 po = (struct private_object_data *)tcore_object_ref_object(o);
481 _clone_sms_operations(po, sms_ops);
487 CoreObject *tcore_sms_new(TcorePlugin *p, const char *name,
488 struct tcore_sms_operations *ops, TcoreHal *hal)
490 CoreObject *o = NULL;
491 struct private_object_data *po = NULL;
496 o = tcore_object_new(p, name, hal);
500 po = calloc(sizeof(struct private_object_data), 1);
502 tcore_object_free(o);
508 tcore_object_set_type(o, CORE_OBJECT_TYPE_SMS);
509 tcore_object_link_object(o, po);
510 tcore_object_set_free_hook(o, _free_hook);
511 tcore_object_set_clone_hook(o, _clone_hook);
512 tcore_object_set_dispatcher(o, _dispatcher);
517 CoreObject *tcore_sms_clone(TcorePlugin *p, const char *name, TcoreHal *hal)
519 CoreObject *o = NULL;
524 o = tcore_object_clone_template_object(p, name, CORE_OBJECT_TYPE_SMS);
528 tcore_object_set_hal(o, hal);
533 void tcore_sms_free(CoreObject *o)
535 struct private_object_data *po = NULL;
537 CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_SMS);
539 po = tcore_object_ref_object(o);
544 tcore_object_free(o);