4 * Copyright (c) 2014 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.
27 * @addtogroup CAPI_TELEPHONY_SERVICE
31 #ifndef _TEL_UTILITY_H_
32 #define _TEL_UTILITY_H_
37 * @brief Definition for Invalid Request ID value.
39 #define INVALID_REQUEST_ID -1
40 #define DBUS_DEFAULT_PATH "/org/tizen/telephony"
43 * @brief Definition for negative error value
44 * @remarks If result is negative value in callback function, it comply below error.
46 #define TAPI_ERROR_OPERATION_FAILED -1
47 #define TAPI_ERROR_ACCESS_DENIED -2
48 #define TAPI_ERROR_OPERATION_NOT_SUPPORTED -3
51 * @brief Enumeration for TAPI return codes.
54 TAPI_API_SUCCESS = 0, /**< No Error occurred */
55 TAPI_API_INVALID_INPUT = -1, /**< Input values are not correct in the TAPI Library */
56 TAPI_API_INVALID_PTR = -2, /**< Invalid pointer */
57 TAPI_API_NOT_SUPPORTED = -3, /**< The feature corresponding to the requested API is not supported. This may be due to market/network/vendor reasons such as the feature is not available in the network */
58 TAPI_API_DEPRICATED = -4, /**< This API is deprecated and will be so in the future also */
59 TAPI_API_SYSTEM_OUT_OF_MEM = -5, /**< Out of memory */
60 TAPI_API_SYSTEM_RPC_LINK_DOWN = -6, /**< RPC link down */
61 TAPI_API_SERVICE_NOT_READY = -7, /**< Phone is powered on, but is still to receive the power up completed notification */
62 TAPI_API_SERVER_FAILURE = -8, /**< Error occurred in the Telephony server */
63 TAPI_API_OEM_PLUGIN_FAILURE = -9, /**< Plug-in layer failure */
64 TAPI_API_TRANSPORT_LAYER_FAILURE = -10, /**< Transport layer Failure */
65 TAPI_API_INVALID_DATA_LEN = -11, /**< Invalid data length */
66 TAPI_API_REQUEST_MAX_IN_PROGRESS = -12, /**< Maximum number of API Requests for the same service are already in progress */
67 TAPI_API_OFFLINE_MODE_ERROR = -13, /**< OEM Telephony Provider is in the Offline mode */
68 TAPI_EVENT_CLASS_UNKNOWN = -14, /**< Event class specified is not present in the Event Class list */
69 TAPI_EVENT_UNKNOWN = -15, /**< Event specified is not present in the TAPI Unsolicited Event list */
70 TAPI_REGISTRATION_OP_FAILED = -16, /**< Callback Registration/De-registration failed */
71 TAPI_API_OPERATION_FAILED = -17, /**< API operation failed */
72 TAPI_API_INVALID_OPERATION = -18, /**< API Invalid Operation */
73 TAPI_API_ACCESS_DENIED = -19, /**< Access Denied */
75 TAPI_API_SYSTEM_RPC_LINK_NOT_EST = -100, /**< RPC link down */
76 TAPI_API_API_NOT_SUPPORTED = -101, /**< API not supported */
77 TAPI_API_SERVER_LAYER_FAILURE = -102, /**< Server layer failure */
80 TAPI_API_INVALID_CALL_ID = -200, /**< Invalid call ID */
81 TAPI_API_CALL_CTXT_OVERFLOW = -201, /**< Call context overflow */
82 TAPI_API_COULD_NOT_GET_CALL_CTXT = -202, /**< Could not get the call context */
83 TAPI_API_CTXT_SEARCH_RET_NON_CALL_CTXT = -203, /**< Context search returned the non-call context */
84 TAPI_API_COULD_NOT_DESTROY_CTXT = -204, /**< Could not destroy the context */
85 TAPI_API_INVALID_LINE_ID = -205, /**< Invalid line ID */
86 TAPI_API_INVALID_CALL_HANDLE = -206, /**< Invalid call handle */
87 TAPI_API_INVALID_CALL_STATE = -207, /**< Invalid call state - Newly added. Need to raise a CR for this */
88 TAPI_API_CALL_PRE_COND_FAILED = -208, /**< Pre condition like MO call cannot be established now */
89 TAPI_API_CALL_SAME_REQ_PENDING = -209, /**< Cannot accept the same request multiple times */
92 TAPI_API_MODEM_POWERED_OFF = -300, /**< Modem is powered off */
93 TAPI_API_MODEM_ALREADY_ON = -301, /**< Modem is already on */
94 TAPI_API_MODEM_ALREADY_OFF = -302, /**< Modem is already off */
97 TAPI_API_NETTEXT_DEVICE_NOT_READY = -400, /**< Nettext device is not ready */
98 TAPI_API_NETTEXT_SCADDR_NOT_SET = -401, /**< Nettext SCA address is not set */
99 TAPI_API_NETTEXT_INVALID_DATA_LEN = -402, /**< Nettext Invalid data length */
100 TAPI_NETTEXT_SCADDRESS_NOT_SET = -403, /**< Nettext SCA address is not set */
103 TAPI_API_SIM_CARD_ERROR = -500, /**< SIM general error */
104 TAPI_API_SIM_NOT_FOUND = -501, /**< SIM is not present / removed */
105 TAPI_API_SIM_NOT_INITIALIZED = -502, /**< SIM has not initialized yet (waiting for PIN verification) */
106 TAPI_API_SIM_LOCKED = -503, /**< PIN/PUK/NCK/NSCK/SPCK/CCK required state */
107 TAPI_API_SIM_PERM_BLOCKED = -504, /**< SIM Permanently blocked state (no more allowing PUK input) */
108 TAPI_API_SIM_SERVICE_IS_DISABLED = -505, /**< Service is disabled in EF-SST due to a given operation */
111 TAPI_API_SAT_INVALID_COMMAND_ID = -600, /**< Command Number Invalid */
112 TAPI_API_SAT_COMMAND_TYPE_MISMATCH = -601, /**< Command Type Mismatch */
113 TAPI_API_SAT_EVENT_NOT_REQUIRED_BY_USIM = -602, /**< Event Not Requested by the USIM */
116 TAPI_API_NETWORK_INVALID_CTXT = -700, /**< Network invalid contex t*/
117 TAPI_API_NETWORK_PLMN_NOT_ALLOWED = -701, /** 3GPP Attache reject cause 11 */
118 TAPI_API_NETWORK_ROAMING_NOT_ALLOWED = -702, /** 3GPP Attache reject cause 13 */
121 TAPI_API_MISC_RETURN_NULL = -800, /**< MISC return NULL */
122 TAPI_API_MISC_VALIDITY_ERROR = -801, /**< MISC validity error */
123 TAPI_API_MISC_INPUTPARM_ERROR = -802, /**< MISC input parameter error */
124 TAPI_API_MISC_OUTPARAM_NULL = -803, /**< MISC output parameter NULL */
128 * @brief Checks the 'scalar_exp' for TRUE, if failed then it returns 'err_value' from the function.
130 #define TAPI_RET_ERR_NUM_IF_FAIL(scalar_exp, err_num) {\
133 err("TAPI_RET_ERR_NUM_IF_FAIL Failed. returning [%d]", err_num);\
139 * @brief Returns from the current function if the expression is not true.
140 * @details If the expression evaluates to FALSE, a critical message is logged and the function returns.
141 * This can only be used in functions which do not return a value.
143 * @param[in] scalar_exp The expression to check
145 #define TAPI_RETURN_IF_FAIL(scalar_exp) {\
148 err("TAPI_RETURN_IF_FAIL: Failed: Returning from here."); \
154 * @brief Returns from the current function, returning the value @a ret, if the expression is not true.
155 * @details If the expression evaluates to FALSE, a critical message is logged and @a ret is returned.
157 #define TAPI_RETURN_VAL_IF_FAIL(scalar_exp, ret) { \
160 err("TAPI_RETURN_VAL_IF_FAIL: Failed: Returning [%d]", ret); \
166 * @brief Returns from the current function, returning the value @a ret, if the expression is not true.
167 * @details If the expression evaluates to FALSE, a critical message is logged and @a ret is returned.
169 #define TAPI_RETURN_VAL_IF_SUCCESS(scalar_exp, ret) { \
172 err("TAPI_RETURN_VAL_IF_SUCCESS: Failed Returning [%d]", ret); \
178 * @brief Logs an error on stderr and abort, if assertion failed.
179 * @details Use this only if the telephpny sevrer needs to be exited, if asertion fails.
181 #define TAPI_ASSERT(scalar_exp) assert(scalar_exp);
184 * @brief Returns from the current function, returning the value @a ret, if @a exp1 and @a exp2 are of the same value.
185 * @details If the equal expression evaluates to TRUE, a critical message is logged and @a ret is returned.
187 #define TAPI_RETURN_VAL_IF_EQUAL(exp1, exp2, ret) { \
190 err("TAPI_RETURN_VAL_IF_EQUAL: FAILED, Returning [%d]", ret); \
196 * @brief Allocates a region of the memory, which is large enough to hold n elements of size bytes each.
197 * @details The allocated region is initialized to zero.
199 #define TAPI_CALLOC(ptr, no_elements, type) \
200 ptr = (type *) calloc (no_elements , sizeof (type)); \
202 perror("NULL is returned"); \
203 err("calloc error -NULL, errno is [%d]", errno); \
208 * @brief Deletes a pointer with double free check.
209 * @details If the same pointer is passed to free twice, known as a double free.
210 * To avoid this, set pointers to NULL after passing them to free: free(NULL) is safe (it does nothing).
212 #define TAPI_FREE(ptr) \
218 err("Double Free or NULL"); \
222 * @brief Checks for available destination buffer size before copying source buffer data to the destination buffer.
223 * @details It asserts if the destination buffer size is less than the source buffer size.
225 #define TAPI_MEMCPY(dest, src, dest_len, src_len) \
226 if (dest_len >= src_len) { \
227 memcpy(dest, src, src_len); \
230 err("TAPI_MEMCPY FAILURE - dest_len(%d) < src_len(%d)", dest_len, src_len); \
235 * @brief Encodes a sequence of binary data into its Base-64 stringified representation.
237 * @param[in] data The binary data to encode
238 * @param[in] len The length of data
239 * @param[out] encoded_data The encoded data
240 * @return A newly allocated, zero-terminated Base-64 encoded string representing data
242 #define TAPI_BASE64_ENCODE(data, len, encoded_data) \
243 encoded_data = g_base64_encode((const guchar *)data, (gsize) len);
246 * @brief Decodes a sequence of Base-64 encoded text into binary data.
248 * @param[in] text The zero-terminated string with base64 text to decode
249 * @param[out] decoded_data The decoded data
250 * @param[in] ptr_out_len The length of the decoded data
251 * @return A newly allocated buffer containing the binary data representing text
253 #define TAPI_BASE64_DECODE(text, decoded_data, ptr_out_len) \
254 decoded_data = g_base64_decode((const gchar *)text, (gsize *)ptr_out_len);
257 * @brief Calculates the length of SCA in BCD type.
259 #define TAPI_GET_LENGTH_FROM_BCD(nLength, rtn) { \
260 if (nLength <= 0) { \
263 else if ((nLength) % 2) { \
264 rtn = ((nLength) / 2) + 1; \
267 rtn = (nLength) / 2; \
272 #define TAPI_VALIDATE_EVENTTYPE(val_min ,val_max, type, ret) { \
273 if (type < val_min || type > val_max ) { \
280 #endif //_TEL_UTILITY_H_