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, struct tcore_sms_operations *sms_ops)
134 if(sms_ops->send_umts_msg) {
135 po->ops->send_umts_msg = sms_ops->send_umts_msg;
137 if(sms_ops->read_msg) {
138 po->ops->read_msg = sms_ops->read_msg;
140 if(sms_ops->save_msg) {
141 po->ops->save_msg = sms_ops->save_msg;
143 if(sms_ops->delete_msg) {
144 po->ops->delete_msg = sms_ops->delete_msg;
146 if(sms_ops->get_storedMsgCnt) {
147 po->ops->get_storedMsgCnt = sms_ops->get_storedMsgCnt;
149 if(sms_ops->get_sca) {
150 po->ops->get_sca = sms_ops->get_sca;
152 if(sms_ops->set_sca) {
153 po->ops->set_sca = sms_ops->set_sca;
155 if(sms_ops->get_cb_config) {
156 po->ops->get_cb_config = sms_ops->get_cb_config;
158 if(sms_ops->set_cb_config) {
159 po->ops->set_cb_config = sms_ops->set_cb_config;
161 if(sms_ops->set_mem_status) {
162 po->ops->set_mem_status = sms_ops->set_mem_status;
164 if(sms_ops->get_pref_brearer) {
165 po->ops->get_pref_brearer = sms_ops->get_pref_brearer;
167 if(sms_ops->set_pref_brearer) {
168 po->ops->set_pref_brearer = sms_ops->set_pref_brearer;
170 if(sms_ops->set_delivery_report) {
171 po->ops->set_delivery_report = sms_ops->set_delivery_report;
173 if(sms_ops->set_msg_status) {
174 po->ops->set_msg_status = sms_ops->set_msg_status;
176 if(sms_ops->get_sms_params) {
177 po->ops->get_sms_params = sms_ops->get_sms_params;
179 if(sms_ops->set_sms_params) {
180 po->ops->set_sms_params = sms_ops->set_sms_params;
182 if(sms_ops->get_paramcnt) {
183 po->ops->get_paramcnt = sms_ops->get_paramcnt;
185 if(sms_ops->send_cdma_msg) {
186 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 = NULL;
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 (!po || !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; /* TAPI_API_NETTEXT_DEVICE_NOT_READY */
211 command = tcore_user_request_get_command(ur);
213 case TREQ_SMS_SEND_UMTS_MSG:
214 if (!po->ops->send_umts_msg)
216 dbg("[tcore_SMS] ERR: po->ops->send_umts_msg is NULL");
217 return TCORE_RETURN_ENOSYS;
220 rtn = po->ops->send_umts_msg(o, ur);
223 case TREQ_SMS_READ_MSG:
224 if (!po->ops->read_msg)
226 dbg("[tcore_SMS] ERR: po->ops->read_msg is NULL");
227 return TCORE_RETURN_ENOSYS;
230 rtn = po->ops->read_msg(o, ur);
233 case TREQ_SMS_SAVE_MSG:
234 if (!po->ops->save_msg)
236 dbg("[tcore_SMS] ERR: po->ops->save_msg is NULL");
237 return TCORE_RETURN_ENOSYS;
240 rtn = po->ops->save_msg(o, ur);
243 case TREQ_SMS_DELETE_MSG:
244 if (!po->ops->delete_msg)
246 dbg("[tcore_SMS] ERR: po->ops->delete_msg is NULL");
247 return TCORE_RETURN_ENOSYS;
250 rtn = po->ops->delete_msg(o, ur);
253 case TREQ_SMS_GET_COUNT:
254 if (!po->ops->get_storedMsgCnt)
256 dbg("[tcore_SMS] ERR: po->ops->get_storedMsgCnt is NULL");
257 return TCORE_RETURN_ENOSYS;
260 rtn = po->ops->get_storedMsgCnt(o, ur);
263 case TREQ_SMS_GET_SCA:
264 if (!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);
273 case TREQ_SMS_SET_SCA:
274 if (!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);
283 case TREQ_SMS_GET_CB_CONFIG:
284 if (!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);
293 case TREQ_SMS_SET_CB_CONFIG:
294 if (!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);
303 case TREQ_SMS_SET_MEM_STATUS:
304 if (!po->ops->set_mem_status)
306 dbg("[tcore_SMS] ERR: po->ops->set_mem_status is NULL");
307 return TCORE_RETURN_ENOSYS;
310 rtn = po->ops->set_mem_status(o, ur);
313 case TREQ_SMS_GET_PREF_BEARER:
314 if (!po->ops->get_pref_brearer)
316 dbg("[tcore_SMS] ERR: po->ops->get_pref_brearer is NULL");
317 return TCORE_RETURN_ENOSYS;
320 rtn = po->ops->get_pref_brearer(o, ur);
323 case TREQ_SMS_SET_PREF_BEARER:
324 if (!po->ops->set_pref_brearer)
326 dbg("[tcore_SMS] ERR: po->ops->get_pref_brearer is NULL");
327 return TCORE_RETURN_ENOSYS;
330 rtn = po->ops->set_pref_brearer(o, ur);
333 case TREQ_SMS_SET_DELIVERY_REPORT:
334 if (!po->ops->set_delivery_report)
336 dbg("[tcore_SMS] ERR: po->ops->set_delivery_report is NULL");
337 return TCORE_RETURN_ENOSYS;
340 rtn = po->ops->set_delivery_report(o, ur);
343 case TREQ_SMS_SET_MSG_STATUS:
344 if (!po->ops->set_msg_status)
346 dbg("[tcore_SMS] ERR: po->ops->set_msg_status is NULL");
347 return TCORE_RETURN_ENOSYS;
350 rtn = po->ops->set_msg_status(o, ur);
353 case TREQ_SMS_GET_PARAMS:
354 if (!po->ops->get_sms_params)
356 dbg("[tcore_SMS] ERR: po->ops->get_sms_params is NULL");
357 return TCORE_RETURN_ENOSYS;
360 rtn = po->ops->get_sms_params(o, ur);
363 case TREQ_SMS_SET_PARAMS:
364 if (!po->ops->set_sms_params)
366 dbg("[tcore_SMS] ERR: po->ops->set_sms_params is NULL");
367 return TCORE_RETURN_ENOSYS;
370 rtn = po->ops->set_sms_params(o, ur);
373 case TREQ_SMS_GET_PARAMCNT:
374 if (!po->ops->get_paramcnt)
376 dbg("[tcore_SMS] ERR: po->ops->get_paramcnt is NULL");
377 return TCORE_RETURN_ENOSYS;
380 rtn = po->ops->get_paramcnt(o, ur);
383 case TREQ_SMS_SEND_CDMA_MSG:
384 if (!po->ops->send_cdma_msg)
386 dbg("[tcore_SMS] ERR: po->ops->send_cdma_msg is NULL");
387 return TCORE_RETURN_ENOSYS;
390 rtn = po->ops->send_cdma_msg(o, ur);
397 dbg("[tcore_SMS] result = [0x%x], command = [0x%x]", rtn, command);
402 static void _free_hook(CoreObject *o)
404 struct private_object_data *po = NULL;
406 CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_SMS);
408 po = tcore_object_ref_object(o);
411 tcore_object_link_object(o, NULL);
415 static void _clone_hook(CoreObject *src, CoreObject *dest)
417 struct private_object_data *src_po = NULL;
418 struct private_object_data *dest_po = NULL;
423 dest_po = calloc(sizeof(struct private_object_data), 1);
425 tcore_object_link_object(dest, NULL);
429 src_po = tcore_object_ref_object(src);
430 dest_po->ops = src_po->ops;
432 tcore_object_link_object(dest, dest_po);
435 gboolean tcore_sms_get_ready_status(CoreObject *o)
437 struct private_object_data *po = NULL;
438 po = tcore_object_ref_object(o);
440 dbg("po access fail");
444 return po->b_readyStatus;
447 gboolean tcore_sms_set_ready_status(CoreObject *o, int status)
449 struct private_object_data *po = NULL;
450 po = tcore_object_ref_object(o);
452 dbg("po access fail");
456 po->b_readyStatus = status;
461 void tcore_sms_override_ops(CoreObject *o, struct tcore_sms_operations *sms_ops)
463 struct private_object_data *po = NULL;
465 CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_SMS);
467 po = (struct private_object_data *)tcore_object_ref_object(o);
473 _clone_sms_operations(po, sms_ops);
479 CoreObject *tcore_sms_new(TcorePlugin *p, const char *name,
480 struct tcore_sms_operations *ops, TcoreHal *hal)
482 CoreObject *o = NULL;
483 struct private_object_data *po = NULL;
488 o = tcore_object_new(p, name, hal);
492 po = calloc(sizeof(struct private_object_data), 1);
494 tcore_object_free(o);
500 tcore_object_set_type(o, CORE_OBJECT_TYPE_SMS);
501 tcore_object_link_object(o, po);
502 tcore_object_set_free_hook(o, _free_hook);
503 tcore_object_set_clone_hook(o, _clone_hook);
504 tcore_object_set_dispatcher(o, _dispatcher);
509 CoreObject *tcore_sms_clone(TcorePlugin *p, const char *name, TcoreHal *hal)
511 CoreObject *o = NULL;
516 o = tcore_object_clone_template_object(p, name, CORE_OBJECT_TYPE_SMS);
520 tcore_object_set_hal(o, hal);
525 void tcore_sms_free(CoreObject *o)
527 struct private_object_data *po = NULL;
529 CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_SMS);
531 po = tcore_object_ref_object(o);
536 tcore_object_free(o);