RDK Documentation (Open Sourced RDK Components)
usbctrl.h
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 /**
21  * @defgroup USB_CNTRL RDK Usb Device Control
22  * - Supports USB detection and control functionality to enable USB detection and control from application.
23  * - This ensures that the USB port works as expected before using peripherals and capabilities that use the USB port.
24  *
25  * @defgroup USB_CNTRL_TYPES USB Control Types
26  * @ingroup USB_CNTRL
27  *
28  * @defgroup USB_CNTRL_APIS USB Control APIs
29  * @ingroup USB_CNTRL
30  *
31  **/
32 
33 /*
34  * The following table is are published properties by this library
35  */
36  typedef enum {
37 //Device Level //sysfs attr
38 RUSBCTRL_PROPNAME_MANUFACTURER = 0, //"manufacturer"
39 RUSBCTRL_PROPNAME_PRODUCT, // "product"
40 RUSBCTRL_PROPNAME_MODEL, // "idProduct"
41 RUSBCTRL_PROPNAME_VENDOR, // "idVendor"
42 RUSBCTRL_PROPNAME_SERIAL, //"serial"
43 // Interface Level
44 RUSBCTRL_PROPNAME_DEVTYPE, //"bInterfaceClass"
45 RUSBCTRL_PROPNAME_DEVSUBTYPE, // "bInterfaceSubClass"
46 } rusbCtrl_propname_t;
47 
48 
49 typedef enum {
50  RUSBCTRL_SUCCESS = 0,
51  RUSBCTRL_FAILURE = -1
52 } rusbCtrl_result_t;
53 
54 /**
55  * @addtogroup USB_CNTRL_TYPES
56  * @{
57  */
58 
59 /**
60  * @brief The callback will be invoked when a device of monitored type is inserted or removed.
61  *
62  * @param[in] devId Device ID is a unique Id generated by libusbctrl. Device ID should be a Id that can identify
63  * a USB interface. A USB device can have multiple interfaces.
64  * @param[in] inserted This indicates of the device is inserted or removed.
65  * @param[in] cbData Callback data.
66  */
67 typedef void (*rusbCtrl_devCallback_t)(int devId, int inserted, void *cbData);
68 
69 /** @} */ //END OF GROUP USB_CNTRL_TYPES
70 
71 /**
72  * @addtogroup USB_CNTRL_APIS
73  * @{
74  */
75 
76 /**
77  * @brief This API Initiate the library to a state that it is ready to detect device events and invoke callbacks.
78  *
79  * Library can be initialized multple times. But init and term must match.
80  *
81  * @return Returns status of the operation.
82  */
83 int rusbCtrl_init(void);
84 
85 /**
86  * @brief This API Release all allocated resources.
87  *
88  * @return Returns status of the operation.
89  */
90 int rusbCtrl_term();
91 
92 /**
93  * @brief This callback Allow application to listen for USB insert/remove events.
94  * An appliction can only register 1 callback.
95  * (This constraint may be lifted in the future if needed)
96  *
97  * @param[in] cb Callback Function.
98  * @param[in] cbData Callback Data.
99  * @param[in] devList Device list is a pointer to an array containing list of connected devices.
100  * @param[in] devListNumEntries Number of entries in the array.
101  *
102  * @return Returns status of the operation.
103  *
104  * @note
105  * devList is a pointer to an array allocated on the heap and must be freed by the user.
106  */
107 int rusbCtrl_registerCallback(rusbCtrl_devCallback_t cb, void *cbData, int **devList, int *devListNumEntries);
108 
109 /**
110  * @brief This API compares unique identifier against its internal data structures and validates to provides property value.
111  * @param[in] devId Device ID.
112  * @param[in] propertyName Set of properties published by libusbCtrl.
113  *
114  * @return On success returns property data. On failure returns NULL.
115  *
116  * @note
117  * User is responsible to free() the value returned.
118  */
119 char *rusbCtrl_getProperty(int devId, const char *propertyName);
120 
121 /** @} */ //END OF GROUP USB_CNTRL_APIS
rusbCtrl_init
int rusbCtrl_init(void)
This API Initiate the library to a state that it is ready to detect device events and invoke callback...
Definition: usbctrl.cpp:540
rusbCtrl_devCallback_t
void(* rusbCtrl_devCallback_t)(int devId, int inserted, void *cbData)
The callback will be invoked when a device of monitored type is inserted or removed.
Definition: usbctrl.h:67
rusbCtrl_getProperty
char * rusbCtrl_getProperty(int devId, const char *propertyName)
This API compares unique identifier against its internal data structures and validates to provides pr...
Definition: usbctrl.cpp:555
rusbCtrl_term
int rusbCtrl_term()
This API Release all allocated resources.
Definition: usbctrl.cpp:546
rusbCtrl_registerCallback
int rusbCtrl_registerCallback(rusbCtrl_devCallback_t cb, void *cbData, int **devList, int *devListNumEntries)
This callback Allow application to listen for USB insert/remove events. An appliction can only regist...
Definition: usbctrl.cpp:551