Changeset e56b8a3 in mainline for uspace/lib
- Timestamp:
- 2011-05-27T13:27:22Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0c904a3
- Parents:
- 8242dd86 (diff), 567a3e2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/lib
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/Makefile
r8242dd86 re56b8a3 40 40 generic/remote_usb.c \ 41 41 generic/remote_pci.c \ 42 generic/remote_usbhc.c 42 generic/remote_usbhc.c \ 43 generic/remote_usbhid.c 43 44 44 45 include $(USPACE_PREFIX)/Makefile.common -
uspace/lib/drv/generic/dev_iface.c
r8242dd86 re56b8a3 46 46 #include "remote_pci.h" 47 47 48 #include <stdio.h> 49 48 50 static iface_dipatch_table_t remote_ifaces = { 49 51 .ifaces = { … … 60 62 { 61 63 assert(is_valid_iface_idx(idx)); 64 62 65 return remote_ifaces.ifaces[idx]; 63 66 } -
uspace/lib/drv/generic/driver.c
r8242dd86 re56b8a3 405 405 /* The interface has not such method */ 406 406 printf("%s: driver_connection_gen error - " 407 "invalid interface method.", driver->name); 407 "invalid interface method (%d).\n", 408 driver->name, iface_method_idx); 408 409 async_answer_0(callid, ENOTSUP); 409 410 break; -
uspace/lib/drv/generic/remote_usbhid.c
r8242dd86 re56b8a3 36 36 #include <errno.h> 37 37 #include <assert.h> 38 #include <stdio.h> 38 39 39 40 #include "usbhid_iface.h" … … 42 43 static void remote_usbhid_get_event_length(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 43 44 static void remote_usbhid_get_event(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 45 static void remote_usbhid_get_report_descriptor_length(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 46 static void remote_usbhid_get_report_descriptor(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 44 47 // static void remote_usbhid_(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 45 48 … … 47 50 static remote_iface_func_ptr_t remote_usbhid_iface_ops [] = { 48 51 remote_usbhid_get_event_length, 49 remote_usbhid_get_event 52 remote_usbhid_get_event, 53 remote_usbhid_get_report_descriptor_length, 54 remote_usbhid_get_report_descriptor 50 55 }; 51 56 … … 58 63 }; 59 64 60 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;65 //usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 61 66 62 67 … … 64 69 ipc_callid_t callid, ipc_call_t *call) 65 70 { 71 printf("remote_usbhid_get_event_length()\n"); 72 66 73 usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface; 67 74 68 75 if (!hid_iface->get_event_length) { 69 async_answer_0(callid, ENOTSUP); 70 return; 71 } 72 73 int len = hid_iface->get_event_length(fun); 74 if (len == 0) { 75 len = EEMPTY; 76 } 77 if (len < 0) { 78 async_answer_0(callid, len); 79 } else { 80 async_answer_1(callid, EOK, len); 81 } 76 printf("Get event length not set!\n"); 77 async_answer_0(callid, ENOTSUP); 78 return; 79 } 80 81 size_t len = hid_iface->get_event_length(fun); 82 // if (len == 0) { 83 // len = EEMPTY; 84 // } 85 async_answer_1(callid, EOK, len); 86 87 // if (len < 0) { 88 // async_answer_0(callid, len); 89 // } else { 90 // async_answer_1(callid, EOK, len); 91 // } 82 92 } 83 93 … … 100 110 return; 101 111 } 102 /* Check that length is even number. Truncate otherwise. */103 if ((len % 2) == 1) {104 len--;105 }112 // /* Check that length is even number. Truncate otherwise. */ 113 // if ((len % 2) == 1) { 114 // len--; 115 // } 106 116 if (len == 0) { 107 117 async_answer_0(data_callid, EINVAL); 108 118 async_answer_0(callid, EINVAL); 119 return; 109 120 } 110 121 111 122 int rc; 112 123 113 size_t items = len / 2; 114 uint16_t *usage_pages_and_usages = malloc(sizeof(uint16_t) * len); 115 if (usage_pages_and_usages == NULL) { 124 uint8_t *data = malloc(len); 125 if (data == NULL) { 116 126 async_answer_0(data_callid, ENOMEM); 117 127 async_answer_0(callid, ENOMEM); 118 } 119 120 size_t act_items; 121 int rc = hid_iface->get_event(fun, usage_pages_and_usages, 122 usage_pages_and_usages + items, items, &act_items, flags); 128 return; 129 } 130 131 size_t act_length; 132 int event_nr; 133 rc = hid_iface->get_event(fun, data, len, &act_length, &event_nr, flags); 123 134 if (rc != EOK) { 124 free( usage_pages_and_usages);135 free(data); 125 136 async_answer_0(data_callid, rc); 126 137 async_answer_0(callid, rc); 127 } 128 if (act_items >= items) { 138 return; 139 } 140 if (act_length >= len) { 129 141 /* This shall not happen. */ 130 142 // FIXME: how about an assert here? 131 act_items = items; 132 } 133 134 async_data_read_finalize(data_callid, usage_pages_and_usages, 135 act_items * 2 * sizeof(uint16_t)); 136 137 free(usage_pages_and_usages); 138 143 act_length = len; 144 } 145 146 async_data_read_finalize(data_callid, data, act_length); 147 148 free(data); 149 150 async_answer_1(callid, EOK, event_nr); 151 } 152 153 void remote_usbhid_get_report_descriptor_length(ddf_fun_t *fun, void *iface, 154 ipc_callid_t callid, ipc_call_t *call) 155 { 156 usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface; 157 158 if (!hid_iface->get_report_descriptor_length) { 159 async_answer_0(callid, ENOTSUP); 160 return; 161 } 162 163 size_t len = hid_iface->get_report_descriptor_length(fun); 164 async_answer_1(callid, EOK, (sysarg_t) len); 165 } 166 167 void remote_usbhid_get_report_descriptor(ddf_fun_t *fun, void *iface, 168 ipc_callid_t callid, ipc_call_t *call) 169 { 170 usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface; 171 172 if (!hid_iface->get_report_descriptor) { 173 async_answer_0(callid, ENOTSUP); 174 return; 175 } 176 177 size_t len; 178 ipc_callid_t data_callid; 179 if (!async_data_read_receive(&data_callid, &len)) { 180 async_answer_0(callid, EINVAL); 181 return; 182 } 183 184 if (len == 0) { 185 async_answer_0(data_callid, EINVAL); 186 async_answer_0(callid, EINVAL); 187 return; 188 } 189 190 uint8_t *descriptor = malloc(len); 191 if (descriptor == NULL) { 192 async_answer_0(data_callid, ENOMEM); 193 async_answer_0(callid, ENOMEM); 194 return; 195 } 196 197 size_t act_len = 0; 198 int rc = hid_iface->get_report_descriptor(fun, descriptor, len, 199 &act_len); 200 if (act_len > len) { 201 rc = ELIMIT; 202 } 203 if (rc != EOK) { 204 free(descriptor); 205 async_answer_0(data_callid, rc); 206 async_answer_0(callid, rc); 207 return; 208 } 209 210 async_data_read_finalize(data_callid, descriptor, act_len); 139 211 async_answer_0(callid, EOK); 140 } 212 213 free(descriptor); 214 } 215 216 141 217 142 218 /** -
uspace/lib/drv/include/remote_pci.h
r8242dd86 re56b8a3 36 36 #define LIBDRV_REMOTE_PCI_H_ 37 37 38 remote_iface_t remote_pci_iface;38 extern remote_iface_t remote_pci_iface; 39 39 40 40 #endif -
uspace/lib/drv/include/remote_usb.h
r8242dd86 re56b8a3 36 36 #define LIBDRV_REMOTE_USB_H_ 37 37 38 remote_iface_t remote_usb_iface;38 extern remote_iface_t remote_usb_iface; 39 39 40 40 #endif -
uspace/lib/drv/include/remote_usbhc.h
r8242dd86 re56b8a3 36 36 #define LIBDRV_REMOTE_USBHC_H_ 37 37 38 remote_iface_t remote_usbhc_iface;38 extern remote_iface_t remote_usbhc_iface; 39 39 40 40 #endif -
uspace/lib/drv/include/remote_usbhid.h
r8242dd86 re56b8a3 36 36 #define LIBDRV_REMOTE_USBHID_H_ 37 37 38 remote_iface_t remote_usbhid_iface;38 extern remote_iface_t remote_usbhid_iface; 39 39 40 40 #endif -
uspace/lib/drv/include/usbhid_iface.h
r8242dd86 re56b8a3 45 45 * Parameters: none 46 46 * Answer: 47 * - EOK (expected always as long as device support USB HID interface) 48 * Parameters of the answer: 49 * - number of items 47 * - Size of one report in bytes. 50 48 */ 51 49 IPC_M_USBHID_GET_EVENT_LENGTH, … … 63 61 * It is okay if the client requests less data. Extra data must 64 62 * be truncated by the driver. 63 * 64 * @todo Change this comment. 65 65 */ 66 IPC_M_USBHID_GET_EVENT 66 IPC_M_USBHID_GET_EVENT, 67 68 /** Get the size of the report descriptor from the HID device. 69 * 70 * Parameters: 71 * - none 72 * Answer: 73 * - EOK - method is implemented (expected always) 74 * Parameters of the answer: 75 * - Size of the report in bytes. 76 */ 77 IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH, 78 79 /** Get the report descriptor from the HID device. 80 * 81 * Parameters: 82 * - none 83 * The call is followed by data read expecting the descriptor itself. 84 * Answer: 85 * - EOK - report descriptor returned. 86 */ 87 IPC_M_USBHID_GET_REPORT_DESCRIPTOR 67 88 } usbhid_iface_funcs_t; 68 89 … … 75 96 * 76 97 * @param[in] fun DDF function answering the request. 77 * @return Number of events or error code.98 * @return Size of the event in bytes. 78 99 */ 79 100 size_t (*get_event_length)(ddf_fun_t *fun); … … 87 108 * @return Error code. 88 109 */ 89 int (*get_event)(ddf_fun_t *fun, int32_t *buffer, size_t size, 90 size_t *act_size, unsigned int flags); 110 int (*get_event)(ddf_fun_t *fun, uint8_t *buffer, size_t size, 111 size_t *act_size, int *event_nr, unsigned int flags); 112 113 /** Get size of the report descriptor in bytes. 114 * 115 * @param[in] fun DDF function answering the request. 116 * @return Size of the report descriptor in bytes. 117 */ 118 size_t (*get_report_descriptor_length)(ddf_fun_t *fun); 119 120 /** Get the report descriptor from the HID device. 121 * 122 * @param[in] fun DDF function answering the request. 123 * @param[out] desc Buffer with the report descriptor. 124 * @param[in] size Size of the allocated @p desc buffer. 125 * @param[out] act_size Actual size of the report descriptor returned. 126 * @return Error code. 127 */ 128 int (*get_report_descriptor)(ddf_fun_t *fun, uint8_t *desc, 129 size_t size, size_t *act_size); 91 130 } usbhid_iface_t; 92 131 -
uspace/lib/usbhid/Makefile
r8242dd86 re56b8a3 41 41 src/hidpath.c \ 42 42 src/hidreport.c \ 43 src/consumer.c \ 43 44 src/hidreq.c 44 45 -
uspace/lib/usbhid/include/usb/hid/hidreport.h
r8242dd86 re56b8a3 44 44 * report parser. 45 45 * 46 * \param dev USB device representing a HID device. 47 * \param parser HID Report parser. 46 * \param[in] dev USB device representing a HID device. 47 * \param[in/out] parser HID Report parser. 48 * \param[out] report_desc Place to save report descriptor into. 49 * \param[out] report_size 48 50 * 49 51 * \retval EOK if successful. … … 57 59 */ 58 60 int usb_hid_process_report_descriptor(usb_device_t *dev, 59 usb_hid_report_t *report );61 usb_hid_report_t *report, uint8_t **report_desc, size_t *report_size); 60 62 61 63 #endif /* LIBUSB_HIDREPORT_H_ */ -
uspace/lib/usbhid/include/usb/hid/iface.h
r8242dd86 re56b8a3 38 38 #include <sys/types.h> 39 39 40 int usbhid_dev_get_event_length(int );41 int usbhid_dev_get_event(int, uint 16_t *, uint16_t *, size_t, size_t *,40 int usbhid_dev_get_event_length(int, size_t *); 41 int usbhid_dev_get_event(int, uint8_t *, size_t, size_t *, int *, 42 42 unsigned int); 43 int usbhid_dev_get_report_descriptor_length(int, size_t *); 44 int usbhid_dev_get_report_descriptor(int, uint8_t *, size_t, size_t *); 43 45 44 46 #endif -
uspace/lib/usbhid/src/hidiface.c
r8242dd86 re56b8a3 46 46 * @return Number of usages returned or negative error code. 47 47 */ 48 int usbhid_dev_get_event_length(int dev_phone )48 int usbhid_dev_get_event_length(int dev_phone, size_t *size) 49 49 { 50 50 if (dev_phone < 0) { … … 56 56 IPC_M_USBHID_GET_EVENT_LENGTH, &len); 57 57 if (rc == EOK) { 58 return (int) len; 59 } else { 60 return rc; 61 } 58 if (size != NULL) { 59 *size = (size_t) len; 60 } 61 } 62 63 return rc; 62 64 } 63 65 … … 74 76 * @return Error code. 75 77 */ 76 int usbhid_dev_get_event(int dev_phone, uint16_t *usage_pages, uint16_t *usages, 77 size_t usage_count, size_t *actual_usage_count, unsigned int flags) 78 { 79 if (dev_phone < 0) { 80 return EINVAL; 81 } 82 if ((usage_pages == NULL) || (usages == NULL)) { 83 return ENOMEM; 84 } 85 if (usage_count == 0) { 86 return EINVAL; 87 } 88 89 size_t buffer_size = sizeof(uint16_t) * usage_count * 2; 90 uint16_t *buffer = malloc(buffer_size); 78 int usbhid_dev_get_event(int dev_phone, uint8_t *buf, 79 size_t size, size_t *actual_size, int *event_nr, unsigned int flags) 80 { 81 if (dev_phone < 0) { 82 return EINVAL; 83 } 84 if ((buf == NULL)) { 85 return ENOMEM; 86 } 87 if (size == 0) { 88 return EINVAL; 89 } 90 91 // if (size == 0) { 92 // return EOK; 93 // } 94 95 size_t buffer_size = size; 96 uint8_t *buffer = malloc(buffer_size); 91 97 if (buffer == NULL) { 92 98 return ENOMEM; 93 99 } 94 100 101 ipc_call_t opening_request_call; 95 102 aid_t opening_request = async_send_2(dev_phone, 96 103 DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_EVENT, 97 flags, NULL);104 flags, &opening_request_call); 98 105 if (opening_request == 0) { 99 106 free(buffer); … … 128 135 } 129 136 130 size_t actual_size = IPC_GET_ARG2(data_request_call); 131 size_t items = actual_size / 2; 137 size_t act_size = IPC_GET_ARG2(data_request_call); 132 138 133 139 /* Copy the individual items. */ 134 memcpy(usage_pages, buffer, items * sizeof(uint16_t)); 135 memcpy(usages, buffer + items, items * sizeof(uint16_t)); 136 137 if (actual_usage_count != NULL) { 138 *actual_usage_count = items; 140 memcpy(buf, buffer, act_size); 141 // memcpy(usages, buffer + items, items * sizeof(int32_t)); 142 143 if (actual_size != NULL) { 144 *actual_size = act_size; 145 } 146 147 if (event_nr != NULL) { 148 *event_nr = IPC_GET_ARG1(opening_request_call); 149 } 150 151 return EOK; 152 } 153 154 155 int usbhid_dev_get_report_descriptor_length(int dev_phone, size_t *size) 156 { 157 if (dev_phone < 0) { 158 return EINVAL; 159 } 160 161 sysarg_t arg_size; 162 int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(USBHID_DEV_IFACE), 163 IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH, &arg_size); 164 if (rc == EOK) { 165 if (size != NULL) { 166 *size = (size_t) arg_size; 167 } 168 } 169 return rc; 170 } 171 172 int usbhid_dev_get_report_descriptor(int dev_phone, uint8_t *buf, size_t size, 173 size_t *actual_size) 174 { 175 if (dev_phone < 0) { 176 return EINVAL; 177 } 178 if ((buf == NULL)) { 179 return ENOMEM; 180 } 181 if (size == 0) { 182 return EINVAL; 183 } 184 185 aid_t opening_request = async_send_1(dev_phone, 186 DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_REPORT_DESCRIPTOR, 187 NULL); 188 if (opening_request == 0) { 189 return ENOMEM; 190 } 191 192 ipc_call_t data_request_call; 193 aid_t data_request = async_data_read(dev_phone, buf, size, 194 &data_request_call); 195 if (data_request == 0) { 196 async_wait_for(opening_request, NULL); 197 return ENOMEM; 198 } 199 200 sysarg_t data_request_rc; 201 sysarg_t opening_request_rc; 202 async_wait_for(data_request, &data_request_rc); 203 async_wait_for(opening_request, &opening_request_rc); 204 205 if (data_request_rc != EOK) { 206 /* Prefer return code of the opening request. */ 207 if (opening_request_rc != EOK) { 208 return (int) opening_request_rc; 209 } else { 210 return (int) data_request_rc; 211 } 212 } 213 214 if (opening_request_rc != EOK) { 215 return (int) opening_request_rc; 216 } 217 218 size_t act_size = IPC_GET_ARG2(data_request_call); 219 220 if (actual_size != NULL) { 221 *actual_size = act_size; 139 222 } 140 223 -
uspace/lib/usbhid/src/hidreport.c
r8242dd86 re56b8a3 164 164 165 165 int usb_hid_process_report_descriptor(usb_device_t *dev, 166 usb_hid_report_t *report )166 usb_hid_report_t *report, uint8_t **report_desc, size_t *report_size) 167 167 { 168 168 if (dev == NULL || report == NULL) { … … 172 172 } 173 173 174 uint8_t *report_desc = NULL; 175 size_t report_size; 176 177 int rc = usb_hid_get_report_descriptor(dev, &report_desc, 178 &report_size); 174 // uint8_t *report_desc = NULL; 175 // size_t report_size; 176 177 int rc = usb_hid_get_report_descriptor(dev, report_desc, report_size); 179 178 180 179 if (rc != EOK) { 181 180 usb_log_error("Problem with getting Report descriptor: %s.\n", 182 181 str_error(rc)); 183 if (report_desc != NULL) { 184 free(report_desc); 182 if (*report_desc != NULL) { 183 free(*report_desc); 184 *report_desc = NULL; 185 185 } 186 186 return rc; 187 187 } 188 188 189 assert( report_desc != NULL);190 191 rc = usb_hid_parse_report_descriptor(report, report_desc,report_size);189 assert(*report_desc != NULL); 190 191 rc = usb_hid_parse_report_descriptor(report, *report_desc, *report_size); 192 192 if (rc != EOK) { 193 193 usb_log_error("Problem parsing Report descriptor: %s.\n", 194 194 str_error(rc)); 195 free(report_desc); 195 free(*report_desc); 196 *report_desc = NULL; 196 197 return rc; 197 198 } 198 199 199 200 usb_hid_descriptor_print(report); 200 free(report_desc);201 201 202 202 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.