3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #ifndef __TIZEN_SYSTEM_USB_ACCESSORY_H__
19 #define __TIZEN_SYSTEM_USB_ACCESSORY_H__
25 * @addtogroup CAPI_SYSTEM_USB_ACCESSORY_MODULE
34 * @brief Enumerations of error code for usb accessory.
38 USB_ERROR_NONE = TIZEN_ERROR_NONE,
39 USB_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,
40 USB_ERROR_NOT_CONNECTED = TIZEN_ERROR_ENDPOINT_NOT_CONNECTED,
41 USB_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,
42 USB_ERROR_OPERATION_FAILED = TIZEN_ERROR_SYSTEM_CLASS | 0x62,
43 USB_ERROR_IPC_FAILED = TIZEN_ERROR_PROTOCOL_NOT_AVALIABLE,
44 USB_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORT_API
48 * @brief The USB Accessory handle.
50 typedef struct usb_accessory_s* usb_accessory_h;
53 * @brief Called when the usb accessory is connected or disconnected.
56 * the handle of accessory will be free after end of usb_accessory_connection_cb()
58 * @param[in] accessory The handle of the attached usb accessory.
59 * @param[in] is_connected True when connected or False when connection is lost.
60 * @param[in] data The user data passed from the register function.
62 * @see usb_accessory_connection_set_cb()
64 typedef void (*usb_accessory_connection_changed_cb)(usb_accessory_h accessory, bool is_connected, void *data);
67 * @brief Called when the permission of usb accessory is granted.
70 * the handle of accessory will be free after end of usb_accessory_request_permission_cb()
72 * @param[in] accessory The handle of the attached usb accessory.
73 * @param[in] is_granted The permission of usb accessory.
75 * @see usb_accessory_request_permission()
77 typedef void (*usb_accessory_permission_response_cb)(usb_accessory_h accessory, bool is_granted);
80 * @brief Called to retrieve the handles of usb accessory.
83 * the handle of accessory will be free after end of usb_accessory_attached_cb()
85 * @param[in] handle The handle of the attached usb accessory.
86 * @param[in] data The user data passed from the foreach function.
88 * @return @c true to continue with the next iteration of the loop, \n
89 * @c false to break out of the loop.
91 * @see usb_accessory_foreach_attached()
93 typedef bool (*usb_accessory_attached_cb)(usb_accessory_h handle, void *data);
96 * @brief Clone the handle of usb accessory.
99 * the cloned handle must be destroyed by #usb_accessory_destroy()
101 * @param[in] handle The usb accessory handle that want to copy.
102 * @param[out] cloned_handle The cloned usb accessory handle.
104 * @return 0 on success, otherwise a negative error value
105 * @retval #USB_ERROR_NONE Successful
106 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
107 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
109 * @see usb_accessory_destroy()
111 int usb_accessory_clone(usb_accessory_h handle, usb_accessory_h* cloned_handle);
114 * @brief Destroy the handle of usb accessory.
116 * @param[in] handle The handle of the attached usb accessory.
118 * @return 0 on success, otherwise a negative error value
119 * @retval #USB_ERROR_NONE Successful
120 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
121 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
123 int usb_accessory_destroy(usb_accessory_h handle);
126 * @brief Retrieves every attached usb accessory handles.
128 * usb_accessory_attached_cb() will be called once for each handle of attached usb accessory.
129 * if usb_accessory_attached_cb() callback function returns false, then iteration will be finished.
132 * the handle of accessory will be free after end of usb_accessory_attached_cb().
134 * @param[in] callback The iteration callback function.
135 * @param[in] user_data The user data to be passed to the callback function.
137 * @return 0 on success, otherwise a negative error value
138 * @retval #USB_ERROR_NONE Successful
139 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
140 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
142 int usb_accessory_foreach_attached(usb_accessory_attached_cb callback, void *user_data);
145 * @brief Register callback function to be invoked when usb accessory connected or disconnected.
147 * The handle of attached usb accessory handle will be passed to usb_accessory_connection_cb().
148 * And status of connection will be also passed to callback function.
150 * @param[in] accessory The attached usb accessory handle.
151 * @param[in] callback The callback function to register.
152 * @param[in] user_data The user data to be passed to the callback function.
154 * @return 0 on success, otherwise a negative error value
155 * @retval #USB_ERROR_NONE Successful
156 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
157 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
159 * @see usb_accessory_connection_unset_cb()
162 int usb_accessory_set_connection_changed_cb(usb_accessory_connection_changed_cb callback, void* user_data);
165 * @brief Unregister the usb accessory connection callback function.
167 * @param[in] accessory The attached usb accessory handle.
169 * @return 0 on success, otherwise a negative error value
170 * @retval #USB_ERROR_NONE Successful
171 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
172 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
174 * @see usb_accessory_connection_set_cb()
176 int usb_accessory_connection_unset_cb(void);
179 * @brief Check whether or not the accessory has permission to access to the host.
181 * @param[in] accessory The attached usb accessory handle.
182 * @param[out] is_granted The permission to access to the host.
184 * @return 0 on success, otherwise a negative error value
185 * @retval #USB_ERROR_NONE Successful
186 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
187 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
189 int usb_accessory_has_permission(usb_accessory_h accessory, bool *is_granted);
192 * @brief opens a file descriptor for reading and writing data to the usb accessory.
194 * @param[in] accessory The attached usb accessory handle.
195 * @param[out] fd opened File descriptor for usb accessory.
197 * @return 0 on success, otherwise a negative error value
198 * @retval #USB_ERROR_NONE Successful
199 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
200 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
202 int usb_accessory_open(usb_accessory_h accessory, FILE **fd);
205 * @brief Get description of the accessory.
207 * @param[in] accessory The attached usb accessory handle.
208 * @param[out] description The description of the usbaccessory.
210 * @return 0 on success, otherwise a negative error value
211 * @retval #USB_ERROR_NONE Successful
212 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
213 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
215 int usb_accessory_get_description(usb_accessory_h accessory, char** description);
218 * @brief Get manufacturer name of the accessory.
220 * @param[in] accessory The attached usb accessory handle.
221 * @param[out] manufacturer The name of manufacturer.
223 * @return 0 on success, otherwise a negative error value
224 * @retval #USB_ERROR_NONE Successful
225 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
226 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
228 int usb_accessory_get_manufacturer(usb_accessory_h accessory, char** manufacturer);
231 * @brief Get model name of the accessory.
233 * @param[in] accessory The attached usb accessory handle.
234 * @param[out] model The model name of usb accessory.
236 * @return 0 on success, otherwise a negative error value
237 * @retval #USB_ERROR_NONE Successful
238 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
239 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
241 int usb_accessory_get_model(usb_accessory_h accessory, char** model);
244 * @brief Get unique serial number of the accessory.
246 * @param[in] accessory The attached usb accessory handle.
247 * @param[out] serial The serial of usb accessory.
249 * @return 0 on success, otherwise a negative error value
250 * @retval #USB_ERROR_NONE Successful
251 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
252 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
254 int usb_accessory_get_serial(usb_accessory_h accessory, char** serial);
257 * @brief Get version of the accessory.
259 * @param[in] accessory The attached usb accessory handle.
260 * @param[out] version The version of usb accessory.
262 * @return 0 on success, otherwise a negative error value
263 * @retval #USB_ERROR_NONE Successful
264 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
265 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
267 int usb_accessory_get_version(usb_accessory_h accessory, char** version);
270 * @brief Check whether or not the connection of the usb accessory.
272 * @param[in] accessory The usb accessory handle to check.
273 * @param[out] is_connected The connection status.
275 * @return 0 on success, otherwise a negative error value
276 * @retval #USB_ERROR_NONE Successful
277 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
278 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
280 int usb_accessory_is_connected(usb_accessory_h accessory, bool *is_connected);
283 * @brief Request permission to user for usb accessory.
285 * The usb accessory handle and boolean passed to callback function that indicating whether permission was granted by the user.
287 * @param[in] accessory The attached usb accessory handle.
288 * @param[in] callback The callback function to register.
289 * @param[in] user_data The user data to be passed to the callback function.
291 * @return 0 on success, otherwise a negative error value
292 * @retval #USB_ERROR_NONE Successful
293 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
294 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
297 int usb_accessory_request_permission(usb_accessory_h accessory, usb_accessory_permission_response_cb callback, void* user_data);
307 #endif // __TIZEN_SYSTEM_USB_ACCESSORY_H__