Changes in uspace/lib/drv/generic/remote_usbhid.c [266fcd8:27b85d9] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/remote_usbhid.c
r266fcd8 r27b85d9 36 36 #include <errno.h> 37 37 #include <assert.h> 38 #include <stdio.h>39 38 40 39 #include "usbhid_iface.h" … … 43 42 static void remote_usbhid_get_event_length(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 44 43 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 *);47 44 // static void remote_usbhid_(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 48 45 … … 50 47 static remote_iface_func_ptr_t remote_usbhid_iface_ops [] = { 51 48 remote_usbhid_get_event_length, 52 remote_usbhid_get_event, 53 remote_usbhid_get_report_descriptor_length, 54 remote_usbhid_get_report_descriptor 49 remote_usbhid_get_event 55 50 }; 56 51 … … 63 58 }; 64 59 65 //usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;60 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 66 61 67 62 … … 69 64 ipc_callid_t callid, ipc_call_t *call) 70 65 { 71 printf("remote_usbhid_get_event_length()\n");72 73 66 usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface; 74 67 75 68 if (!hid_iface->get_event_length) { 76 printf("Get event length not set!\n");77 69 async_answer_0(callid, ENOTSUP); 78 70 return; 79 71 } 80 72 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 // } 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 } 92 82 } 93 83 … … 110 100 return; 111 101 } 112 ///* Check that length is even number. Truncate otherwise. */113 //if ((len % 2) == 1) {114 //len--;115 //}102 /* Check that length is even number. Truncate otherwise. */ 103 if ((len % 2) == 1) { 104 len--; 105 } 116 106 if (len == 0) { 117 107 async_answer_0(data_callid, EINVAL); 118 108 async_answer_0(callid, EINVAL); 119 return;120 109 } 121 110 122 111 int rc; 123 112 124 uint8_t *data = malloc(len); 125 if (data == NULL) { 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) { 126 116 async_answer_0(data_callid, ENOMEM); 127 117 async_answer_0(callid, ENOMEM); 128 return;129 118 } 130 119 131 size_t act_ length;132 int event_nr;133 rc = hid_iface->get_event(fun, data, len, &act_length, &event_nr, flags);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); 134 123 if (rc != EOK) { 135 free( data);124 free(usage_pages_and_usages); 136 125 async_answer_0(data_callid, rc); 137 126 async_answer_0(callid, rc); 138 return;139 127 } 140 if (act_ length >= len) {128 if (act_items >= items) { 141 129 /* This shall not happen. */ 142 130 // FIXME: how about an assert here? 143 act_ length = len;131 act_items = items; 144 132 } 145 133 146 async_data_read_finalize(data_callid, data, act_length); 134 async_data_read_finalize(data_callid, usage_pages_and_usages, 135 act_items * 2 * sizeof(uint16_t)); 147 136 148 free( data);137 free(usage_pages_and_usages); 149 138 150 async_answer_ 1(callid, EOK, event_nr);139 async_answer_0(callid, EOK); 151 140 } 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);211 async_answer_0(callid, EOK);212 213 free(descriptor);214 }215 216 217 141 218 142 /**
Note:
See TracChangeset
for help on using the changeset viewer.