2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __TIZEN_SYSTEM_USB_ACCESSORY_H__
18 #define __TIZEN_SYSTEM_USB_ACCESSORY_H__
24 * @addtogroup CAPI_SYSTEM_USB_ACCESSORY_MODULE
33 * @brief Enumerations of error code for usb accessory.
37 USB_ERROR_NONE = TIZEN_ERROR_NONE,
38 USB_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,
39 USB_ERROR_NOT_CONNECTED = TIZEN_ERROR_ENDPOINT_NOT_CONNECTED,
40 USB_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,
41 USB_ERROR_OPERATION_FAILED = TIZEN_ERROR_SYSTEM_CLASS | 0x62
45 * @brief The USB Accessory handle.
47 typedef struct usb_accessory_s* usb_accessory_h;
50 * @brief Called when the usb accessory is connected or disconnected.
53 * the handle of accessory will be free after end of usb_accessory_connection_cb()
55 * @param[in] accessory The handle of the attached usb accessory.
56 * @param[in] is_connected True when connected or False when connection is lost.
57 * @param[in] data The user data passed from the register function.
59 * @see usb_accessory_connection_set_cb()
61 typedef void (*usb_accessory_connection_changed_cb)(usb_accessory_h accessory, bool is_connected, void *data);
64 * @brief Called when the permission of usb accessory is granted.
67 * the handle of accessory will be free after end of usb_accessory_request_permission_cb()
69 * @param[in] accessory The handle of the attached usb accessory.
70 * @param[in] is_granted The permission of usb accessory.
72 * @see usb_accessory_request_permission()
74 typedef void (*usb_accessory_permission_response_cb)(usb_accessory_h accessory, bool is_granted);
77 * @brief Called to retrieve the handles of usb accessory.
80 * the handle of accessory will be free after end of usb_accessory_attached_cb()
82 * @param[in] handle The handle of the attached usb accessory.
83 * @param[in] data The user data passed from the foreach function.
85 * @return @c true to continue with the next iteration of the loop, \n
86 * @c false to break out of the loop.
88 * @see usb_accessory_foreach_attached()
90 typedef bool (*usb_accessory_attached_cb)(usb_accessory_h handle, void *data);
93 * @brief Clone the handle of usb accessory.
96 * the cloned handle must be destroyed by #usb_accessory_destroy()
98 * @param[in] handle The usb accessory handle that want to copy.
99 * @param[out] cloned_handle The cloned usb accessory handle.
101 * @return 0 on success, otherwise a negative error value
102 * @retval #USB_ERROR_NONE Successful
103 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
104 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
106 * @see usb_accessory_destroy()
108 int usb_accessory_clone(usb_accessory_h handle, usb_accessory_h* cloned_handle);
111 * @brief Destroy the handle of usb accessory.
113 * @param[in] handle The handle of the attached usb accessory.
115 * @return 0 on success, otherwise a negative error value
116 * @retval #USB_ERROR_NONE Successful
117 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
118 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
120 int usb_accessory_destroy(usb_accessory_h handle);
123 * @brief Retrieves every attached usb accessory handles.
125 * usb_accessory_attached_cb() will be called once for each handle of attached usb accessory.
126 * if usb_accessory_attached_cb() callback function returns false, then iteration will be finished.
129 * the handle of accessory will be free after end of usb_accessory_attached_cb().
131 * @param[in] callback The iteration callback function.
132 * @param[in] user_data The user data to be passed to the callback function.
134 * @return 0 on success, otherwise a negative error value
135 * @retval #USB_ERROR_NONE Successful
136 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
137 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
139 int usb_accessory_foreach_attached(usb_accessory_attached_cb callback, void *user_data);
142 * @brief Register callback function to be invoked when usb accessory connected or disconnected.
144 * The handle of attached usb accessory handle will be passed to usb_accessory_connection_cb().
145 * And status of connection will be also passed to callback function.
147 * @param[in] accessory The attached usb accessory handle.
148 * @param[in] callback The callback function to register.
149 * @param[in] user_data The user data to be passed to the callback function.
151 * @return 0 on success, otherwise a negative error value
152 * @retval #USB_ERROR_NONE Successful
153 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
154 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
156 * @see usb_accessory_connection_unset_cb()
159 int usb_accessory_set_connection_changed_cb(usb_accessory_connection_changed_cb callback, void* user_data);
162 * @brief Unregister the usb accessory connection callback function.
164 * @param[in] accessory The attached usb accessory handle.
166 * @return 0 on success, otherwise a negative error value
167 * @retval #USB_ERROR_NONE Successful
168 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
169 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
171 * @see usb_accessory_connection_set_cb()
173 int usb_accessory_connection_unset_cb(void);
176 * @brief Check whether or not the accessory has permission to access to the host.
178 * @param[in] accessory The attached usb accessory handle.
179 * @param[out] is_granted The permission to access to the host.
181 * @return 0 on success, otherwise a negative error value
182 * @retval #USB_ERROR_NONE Successful
183 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
184 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
186 int usb_accessory_has_permission(usb_accessory_h accessory, bool *is_granted);
189 * @brief opens a file descriptor for reading and writing data to the usb accessory.
191 * @param[in] accessory The attached usb accessory handle.
192 * @param[out] fd opened File descriptor for usb accessory.
194 * @return 0 on success, otherwise a negative error value
195 * @retval #USB_ERROR_NONE Successful
196 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
197 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
199 int usb_accessory_open(usb_accessory_h accessory, FILE **fd);
202 * @brief Get description of the accessory.
204 * @param[in] accessory The attached usb accessory handle.
205 * @param[out] description The description of the usbaccessory.
207 * @return 0 on success, otherwise a negative error value
208 * @retval #USB_ERROR_NONE Successful
209 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
210 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
212 int usb_accessory_get_description(usb_accessory_h accessory, char** description);
215 * @brief Get manufacturer name of the accessory.
217 * @param[in] accessory The attached usb accessory handle.
218 * @param[out] manufacturer The name of manufacturer.
220 * @return 0 on success, otherwise a negative error value
221 * @retval #USB_ERROR_NONE Successful
222 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
223 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
225 int usb_accessory_get_manufacturer(usb_accessory_h accessory, char** manufacturer);
228 * @brief Get model name of the accessory.
230 * @param[in] accessory The attached usb accessory handle.
231 * @param[out] model The model name of usb accessory.
233 * @return 0 on success, otherwise a negative error value
234 * @retval #USB_ERROR_NONE Successful
235 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
236 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
238 int usb_accessory_get_model(usb_accessory_h accessory, char** model);
241 * @brief Get unique serial number of the accessory.
243 * @param[in] accessory The attached usb accessory handle.
244 * @param[out] serial The serial of usb accessory.
246 * @return 0 on success, otherwise a negative error value
247 * @retval #USB_ERROR_NONE Successful
248 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
249 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
251 int usb_accessory_get_serial(usb_accessory_h accessory, char** serial);
254 * @brief Get version of the accessory.
256 * @param[in] accessory The attached usb accessory handle.
257 * @param[out] version The version of usb accessory.
259 * @return 0 on success, otherwise a negative error value
260 * @retval #USB_ERROR_NONE Successful
261 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
262 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
264 int usb_accessory_get_version(usb_accessory_h accessory, char** version);
267 * @brief Check whether or not the connection of the usb accessory.
269 * @param[in] accessory The usb accessory handle to check.
270 * @param[out] is_connected The connection status.
272 * @return 0 on success, otherwise a negative error value
273 * @retval #USB_ERROR_NONE Successful
274 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
275 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
277 int usb_accessory_is_connected(usb_accessory_h accessory, bool *is_connected);
280 * @brief Request permission to user for usb accessory.
282 * The usb accessory handle and boolean passed to callback function that indicating whether permission was granted by the user.
284 * @param[in] accessory The attached usb accessory handle.
285 * @param[in] callback The callback function to register.
286 * @param[in] user_data The user data to be passed to the callback function.
288 * @return 0 on success, otherwise a negative error value
289 * @retval #USB_ERROR_NONE Successful
290 * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
291 * @retval #USB_ERROR_OPERATION_FAILED Operation failed
294 int usb_accessory_request_permission(usb_accessory_h accessory, usb_accessory_permission_response_cb callback, void* user_data);
304 #endif // __TIZEN_SYSTEM_USB_ACCESSORY_H__