Changes in uspace/lib/drv/generic/remote_usbhid.c [27b85d9:9dddb3d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/remote_usbhid.c
r27b85d9 r9dddb3d 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 rc = hid_iface->get_event(fun, data, len, &act_length, flags); 123 133 if (rc != EOK) { 124 free( usage_pages_and_usages);134 free(data); 125 135 async_answer_0(data_callid, rc); 126 136 async_answer_0(callid, rc); 127 } 128 if (act_items >= items) { 137 return; 138 } 139 if (act_length >= len) { 129 140 /* This shall not happen. */ 130 141 // 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); 142 act_length = len; 143 } 144 145 async_data_read_finalize(data_callid, data, act_length); 146 147 free(data); 138 148 139 149 async_answer_0(callid, EOK); 140 150 } 151 152 void remote_usbhid_get_report_descriptor_length(ddf_fun_t *fun, void *iface, 153 ipc_callid_t callid, ipc_call_t *call) 154 { 155 usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface; 156 157 if (!hid_iface->get_report_descriptor_length) { 158 async_answer_0(callid, ENOTSUP); 159 return; 160 } 161 162 size_t len = hid_iface->get_report_descriptor_length(fun); 163 async_answer_1(callid, EOK, (sysarg_t) len); 164 } 165 166 void remote_usbhid_get_report_descriptor(ddf_fun_t *fun, void *iface, 167 ipc_callid_t callid, ipc_call_t *call) 168 { 169 usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface; 170 171 if (!hid_iface->get_report_descriptor) { 172 async_answer_0(callid, ENOTSUP); 173 return; 174 } 175 176 size_t len; 177 ipc_callid_t data_callid; 178 if (!async_data_read_receive(&data_callid, &len)) { 179 async_answer_0(callid, EINVAL); 180 return; 181 } 182 183 if (len == 0) { 184 async_answer_0(data_callid, EINVAL); 185 async_answer_0(callid, EINVAL); 186 return; 187 } 188 189 uint8_t *descriptor = malloc(len); 190 if (descriptor == NULL) { 191 async_answer_0(data_callid, ENOMEM); 192 async_answer_0(callid, ENOMEM); 193 return; 194 } 195 196 size_t act_len = 0; 197 int rc = hid_iface->get_report_descriptor(fun, descriptor, len, 198 &act_len); 199 if (act_len > len) { 200 rc = ELIMIT; 201 } 202 if (rc != EOK) { 203 free(descriptor); 204 async_answer_0(data_callid, rc); 205 async_answer_0(callid, rc); 206 return; 207 } 208 209 async_data_read_finalize(data_callid, descriptor, act_len); 210 async_answer_0(callid, EOK); 211 212 free(descriptor); 213 } 214 215 141 216 142 217 /**
Note:
See TracChangeset
for help on using the changeset viewer.