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 TReturn _dispatcher(CoreObject *o, UserRequest *ur)
134 enum tcore_request_command command;
135 struct private_object_data *po = NULL;
136 TReturn rtn = TCORE_RETURN_SUCCESS;
138 CORE_OBJECT_CHECK_RETURN(o, CORE_OBJECT_TYPE_SMS, TCORE_RETURN_EINVAL);
140 po = tcore_object_ref_object(o);
141 if (!po || !po->ops) {
142 dbg("[tcore_SMS] ERR: private_object is NULL or ops is NULL");
143 return TCORE_RETURN_ENOSYS;
146 if(po->b_readyStatus == FALSE) {
147 dbg("[tcore_SMS] DEVICE_NOT_READY");
148 return TCORE_RETURN_ENOSYS; /* TAPI_API_NETTEXT_DEVICE_NOT_READY */
151 command = tcore_user_request_get_command(ur);
153 case TREQ_SMS_SEND_UMTS_MSG:
154 if (!po->ops->send_umts_msg)
156 dbg("[tcore_SMS] ERR: po->ops->send_umts_msg is NULL");
157 return TCORE_RETURN_ENOSYS;
160 rtn = po->ops->send_umts_msg(o, ur);
163 case TREQ_SMS_READ_MSG:
164 if (!po->ops->read_msg)
166 dbg("[tcore_SMS] ERR: po->ops->read_msg is NULL");
167 return TCORE_RETURN_ENOSYS;
170 rtn = po->ops->read_msg(o, ur);
173 case TREQ_SMS_SAVE_MSG:
174 if (!po->ops->save_msg)
176 dbg("[tcore_SMS] ERR: po->ops->save_msg is NULL");
177 return TCORE_RETURN_ENOSYS;
180 rtn = po->ops->save_msg(o, ur);
183 case TREQ_SMS_DELETE_MSG:
184 if (!po->ops->delete_msg)
186 dbg("[tcore_SMS] ERR: po->ops->delete_msg is NULL");
187 return TCORE_RETURN_ENOSYS;
190 rtn = po->ops->delete_msg(o, ur);
193 case TREQ_SMS_GET_COUNT:
194 if (!po->ops->get_storedMsgCnt)
196 dbg("[tcore_SMS] ERR: po->ops->get_storedMsgCnt is NULL");
197 return TCORE_RETURN_ENOSYS;
200 rtn = po->ops->get_storedMsgCnt(o, ur);
203 case TREQ_SMS_GET_SCA:
204 if (!po->ops->get_sca)
206 dbg("[tcore_SMS] ERR: po->ops->get_sca is NULL");
207 return TCORE_RETURN_ENOSYS;
210 rtn = po->ops->get_sca(o, ur);
213 case TREQ_SMS_SET_SCA:
214 if (!po->ops->set_sca)
216 dbg("[tcore_SMS] ERR: po->ops->set_sca is NULL");
217 return TCORE_RETURN_ENOSYS;
220 rtn = po->ops->set_sca(o, ur);
223 case TREQ_SMS_GET_CB_CONFIG:
224 if (!po->ops->get_cb_config)
226 dbg("[tcore_SMS] ERR: po->ops->get_cb_config is NULL");
227 return TCORE_RETURN_ENOSYS;
230 rtn = po->ops->get_cb_config(o, ur);
233 case TREQ_SMS_SET_CB_CONFIG:
234 if (!po->ops->set_cb_config)
236 dbg("[tcore_SMS] ERR: po->ops->set_cb_config is NULL");
237 return TCORE_RETURN_ENOSYS;
240 rtn = po->ops->set_cb_config(o, ur);
243 case TREQ_SMS_SET_MEM_STATUS:
244 if (!po->ops->set_mem_status)
246 dbg("[tcore_SMS] ERR: po->ops->set_mem_status is NULL");
247 return TCORE_RETURN_ENOSYS;
250 rtn = po->ops->set_mem_status(o, ur);
253 case TREQ_SMS_GET_PREF_BEARER:
254 if (!po->ops->get_pref_brearer)
256 dbg("[tcore_SMS] ERR: po->ops->get_pref_brearer is NULL");
257 return TCORE_RETURN_ENOSYS;
260 rtn = po->ops->get_pref_brearer(o, ur);
263 case TREQ_SMS_SET_PREF_BEARER:
264 if (!po->ops->set_pref_brearer)
266 dbg("[tcore_SMS] ERR: po->ops->get_pref_brearer is NULL");
267 return TCORE_RETURN_ENOSYS;
270 rtn = po->ops->set_pref_brearer(o, ur);
273 case TREQ_SMS_SET_DELIVERY_REPORT:
274 if (!po->ops->set_delivery_report)
276 dbg("[tcore_SMS] ERR: po->ops->set_delivery_report is NULL");
277 return TCORE_RETURN_ENOSYS;
280 rtn = po->ops->set_delivery_report(o, ur);
283 case TREQ_SMS_SET_MSG_STATUS:
284 if (!po->ops->set_msg_status)
286 dbg("[tcore_SMS] ERR: po->ops->set_msg_status is NULL");
287 return TCORE_RETURN_ENOSYS;
290 rtn = po->ops->set_msg_status(o, ur);
293 case TREQ_SMS_GET_PARAMS:
294 if (!po->ops->get_sms_params)
296 dbg("[tcore_SMS] ERR: po->ops->get_sms_params is NULL");
297 return TCORE_RETURN_ENOSYS;
300 rtn = po->ops->get_sms_params(o, ur);
303 case TREQ_SMS_SET_PARAMS:
304 if (!po->ops->set_sms_params)
306 dbg("[tcore_SMS] ERR: po->ops->set_sms_params is NULL");
307 return TCORE_RETURN_ENOSYS;
310 rtn = po->ops->set_sms_params(o, ur);
313 case TREQ_SMS_GET_PARAMCNT:
314 if (!po->ops->get_paramcnt)
316 dbg("[tcore_SMS] ERR: po->ops->get_paramcnt is NULL");
317 return TCORE_RETURN_ENOSYS;
320 rtn = po->ops->get_paramcnt(o, ur);
323 case TREQ_SMS_SEND_CDMA_MSG:
324 if (!po->ops->send_cdma_msg)
326 dbg("[tcore_SMS] ERR: po->ops->send_cdma_msg is NULL");
327 return TCORE_RETURN_ENOSYS;
330 rtn = po->ops->send_cdma_msg(o, ur);
337 dbg("[tcore_SMS] result = [0x%x], command = [0x%x]", rtn, command);
342 static void _free_hook(CoreObject *o)
344 struct private_object_data *po = NULL;
346 CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_SMS);
348 po = tcore_object_ref_object(o);
351 tcore_object_link_object(o, NULL);
355 static void _clone_hook(CoreObject *src, CoreObject *dest)
357 struct private_object_data *src_po = NULL;
358 struct private_object_data *dest_po = NULL;
363 dest_po = calloc(sizeof(struct private_object_data), 1);
365 tcore_object_link_object(dest, NULL);
369 src_po = tcore_object_ref_object(src);
370 dest_po->ops = src_po->ops;
372 tcore_object_link_object(dest, dest_po);
375 gboolean tcore_sms_get_ready_status(CoreObject *o)
377 struct private_object_data *po = NULL;
378 po = tcore_object_ref_object(o);
380 dbg("po access fail");
384 return po->b_readyStatus;
387 gboolean tcore_sms_set_ready_status(CoreObject *o, int status)
389 struct private_object_data *po = NULL;
390 po = tcore_object_ref_object(o);
392 dbg("po access fail");
396 po->b_readyStatus = status;
401 CoreObject *tcore_sms_new(TcorePlugin *p, const char *name,
402 struct tcore_sms_operations *ops, TcoreHal *hal)
404 CoreObject *o = NULL;
405 struct private_object_data *po = NULL;
410 o = tcore_object_new(p, name, hal);
414 po = calloc(sizeof(struct private_object_data), 1);
416 tcore_object_free(o);
422 tcore_object_set_type(o, CORE_OBJECT_TYPE_SMS);
423 tcore_object_link_object(o, po);
424 tcore_object_set_free_hook(o, _free_hook);
425 tcore_object_set_clone_hook(o, _clone_hook);
426 tcore_object_set_dispatcher(o, _dispatcher);
431 void tcore_sms_free(CoreObject *o)
433 struct private_object_data *po = NULL;
435 CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_SMS);
437 po = tcore_object_ref_object(o);
442 tcore_object_free(o);