00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #include <dev_iface.h>
00036 #include <usbhid_iface.h>
00037 #include <usb/hid/iface.h>
00038 #include <errno.h>
00039 #include <str_error.h>
00040 #include <async.h>
00041 #include <assert.h>
00042
00048 int usbhid_dev_get_event_length(int dev_phone, size_t *size)
00049 {
00050 if (dev_phone < 0) {
00051 return EINVAL;
00052 }
00053
00054 sysarg_t len;
00055 int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(USBHID_DEV_IFACE),
00056 IPC_M_USBHID_GET_EVENT_LENGTH, &len);
00057 if (rc == EOK) {
00058 if (size != NULL) {
00059 *size = (size_t) len;
00060 }
00061 }
00062
00063 return rc;
00064 }
00065
00078 int usbhid_dev_get_event(int dev_phone, uint8_t *buf,
00079 size_t size, size_t *actual_size, int *event_nr, unsigned int flags)
00080 {
00081 if (dev_phone < 0) {
00082 return EINVAL;
00083 }
00084 if ((buf == NULL)) {
00085 return ENOMEM;
00086 }
00087 if (size == 0) {
00088 return EINVAL;
00089 }
00090
00091
00092
00093
00094
00095 size_t buffer_size = size;
00096 uint8_t *buffer = malloc(buffer_size);
00097 if (buffer == NULL) {
00098 return ENOMEM;
00099 }
00100
00101 ipc_call_t opening_request_call;
00102 aid_t opening_request = async_send_2(dev_phone,
00103 DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_EVENT,
00104 flags, &opening_request_call);
00105 if (opening_request == 0) {
00106 free(buffer);
00107 return ENOMEM;
00108 }
00109
00110 ipc_call_t data_request_call;
00111 aid_t data_request = async_data_read(dev_phone, buffer, buffer_size,
00112 &data_request_call);
00113 if (data_request == 0) {
00114 async_wait_for(opening_request, NULL);
00115 free(buffer);
00116 return ENOMEM;
00117 }
00118
00119 sysarg_t data_request_rc;
00120 sysarg_t opening_request_rc;
00121 async_wait_for(data_request, &data_request_rc);
00122 async_wait_for(opening_request, &opening_request_rc);
00123
00124 if (data_request_rc != EOK) {
00125
00126 if (opening_request_rc != EOK) {
00127 return (int) opening_request_rc;
00128 } else {
00129 return (int) data_request_rc;
00130 }
00131 }
00132
00133 if (opening_request_rc != EOK) {
00134 return (int) opening_request_rc;
00135 }
00136
00137 size_t act_size = IPC_GET_ARG2(data_request_call);
00138
00139
00140 memcpy(buf, buffer, act_size);
00141
00142
00143 if (actual_size != NULL) {
00144 *actual_size = act_size;
00145 }
00146
00147 if (event_nr != NULL) {
00148 *event_nr = IPC_GET_ARG1(opening_request_call);
00149 }
00150
00151 return EOK;
00152 }
00153
00154
00155 int usbhid_dev_get_report_descriptor_length(int dev_phone, size_t *size)
00156 {
00157 if (dev_phone < 0) {
00158 return EINVAL;
00159 }
00160
00161 sysarg_t arg_size;
00162 int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(USBHID_DEV_IFACE),
00163 IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH, &arg_size);
00164 if (rc == EOK) {
00165 if (size != NULL) {
00166 *size = (size_t) arg_size;
00167 }
00168 }
00169 return rc;
00170 }
00171
00172 int usbhid_dev_get_report_descriptor(int dev_phone, uint8_t *buf, size_t size,
00173 size_t *actual_size)
00174 {
00175 if (dev_phone < 0) {
00176 return EINVAL;
00177 }
00178 if ((buf == NULL)) {
00179 return ENOMEM;
00180 }
00181 if (size == 0) {
00182 return EINVAL;
00183 }
00184
00185 aid_t opening_request = async_send_1(dev_phone,
00186 DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_REPORT_DESCRIPTOR,
00187 NULL);
00188 if (opening_request == 0) {
00189 return ENOMEM;
00190 }
00191
00192 ipc_call_t data_request_call;
00193 aid_t data_request = async_data_read(dev_phone, buf, size,
00194 &data_request_call);
00195 if (data_request == 0) {
00196 async_wait_for(opening_request, NULL);
00197 return ENOMEM;
00198 }
00199
00200 sysarg_t data_request_rc;
00201 sysarg_t opening_request_rc;
00202 async_wait_for(data_request, &data_request_rc);
00203 async_wait_for(opening_request, &opening_request_rc);
00204
00205 if (data_request_rc != EOK) {
00206
00207 if (opening_request_rc != EOK) {
00208 return (int) opening_request_rc;
00209 } else {
00210 return (int) data_request_rc;
00211 }
00212 }
00213
00214 if (opening_request_rc != EOK) {
00215 return (int) opening_request_rc;
00216 }
00217
00218 size_t act_size = IPC_GET_ARG2(data_request_call);
00219
00220 if (actual_size != NULL) {
00221 *actual_size = act_size;
00222 }
00223
00224 return EOK;
00225 }
00226