Changeset b4292e7 in mainline
- Timestamp:
- 2011-11-26T13:17:48Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8969f46
- Parents:
- 272f46f8
- Location:
- uspace/lib/usbdev
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/include/usb/dev/pipes.h
r272f46f8 rb4292e7 179 179 180 180 int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *); 181 int usb_pipe_write(usb_pipe_t *, void *, size_t);181 int usb_pipe_write(usb_pipe_t *, const void *, size_t); 182 182 183 183 int usb_pipe_control_read(usb_pipe_t *, const void *, size_t, -
uspace/lib/usbdev/src/pipesio.c
r272f46f8 rb4292e7 62 62 * @return Error code. 63 63 */ 64 static int usb_pipe_read_no_check s(usb_pipe_t *pipe,64 static int usb_pipe_read_no_check(usb_pipe_t *pipe, uint64_t setup, 65 65 void *buffer, size_t size, size_t *size_transfered) 66 66 { 67 67 /* Only interrupt and bulk transfers are supported */ 68 68 if (pipe->transfer_type != USB_TRANSFER_INTERRUPT && 69 pipe->transfer_type != USB_TRANSFER_BULK) 69 pipe->transfer_type != USB_TRANSFER_BULK && 70 pipe->transfer_type != USB_TRANSFER_CONTROL) 70 71 return ENOTSUP; 71 72 … … 79 80 80 81 const int ret = usbhc_read(exch, pipe->wire->address, pipe->endpoint_no, 81 0, buffer, size, size_transfered);82 setup, buffer, size, size_transfered); 82 83 async_exchange_end(exch); 83 84 pipe_end_transaction(pipe); … … 85 86 } 86 87 87 88 88 /** Request a read (in) transfer on an endpoint pipe. 89 89 * … … 124 124 size_t act_size = 0; 125 125 126 rc = usb_pipe_read_no_check s(pipe, buffer, size, &act_size);126 rc = usb_pipe_read_no_check(pipe, 0, buffer, size, &act_size); 127 127 128 128 pipe_drop_ref(pipe); … … 139 139 } 140 140 141 142 143 144 141 /** Request an out transfer, no checking of input parameters. 145 142 * … … 149 146 * @return Error code. 150 147 */ 151 static int usb_pipe_write_no_check(usb_pipe_t *pipe, 152 void *buffer, size_t size)148 static int usb_pipe_write_no_check(usb_pipe_t *pipe, uint64_t setup, 149 const void *buffer, size_t size) 153 150 { 154 151 /* Only interrupt and bulk transfers are supported */ 155 152 if (pipe->transfer_type != USB_TRANSFER_INTERRUPT && 156 pipe->transfer_type != USB_TRANSFER_BULK) 153 pipe->transfer_type != USB_TRANSFER_BULK && 154 pipe->transfer_type != USB_TRANSFER_CONTROL) 157 155 return ENOTSUP; 158 156 … … 166 164 const int ret = 167 165 usbhc_write(exch, pipe->wire->address, pipe->endpoint_no, 168 0, buffer, size);166 setup, buffer, size); 169 167 async_exchange_end(exch); 170 168 pipe_end_transaction(pipe); … … 179 177 * @return Error code. 180 178 */ 181 int usb_pipe_write(usb_pipe_t *pipe, 182 void *buffer, size_t size) 179 int usb_pipe_write(usb_pipe_t *pipe, const void *buffer, size_t size) 183 180 { 184 181 assert(pipe); 185 182 186 if (buffer == NULL) { 187 return EINVAL; 188 } 189 190 if (size == 0) { 183 if (buffer == NULL || size == 0) { 191 184 return EINVAL; 192 185 } … … 201 194 202 195 int rc; 203 204 196 rc = pipe_add_ref(pipe, false); 205 197 if (rc != EOK) { … … 207 199 } 208 200 209 rc = usb_pipe_write_no_check(pipe, buffer, size);201 rc = usb_pipe_write_no_check(pipe, 0, buffer, size); 210 202 211 203 pipe_drop_ref(pipe); … … 227 219 228 220 229 /* Prevent in definite recursion. */221 /* Prevent infinite recursion. */ 230 222 pipe->auto_reset_halt = false; 231 223 usb_request_clear_endpoint_halt(pipe, 0); … … 233 225 } 234 226 235 236 /** Request a control read transfer, no checking of input parameters. 227 /** Request a control read transfer on an endpoint pipe. 228 * 229 * This function encapsulates all three stages of a control transfer. 237 230 * 238 231 * @param[in] pipe Pipe used for the transfer. … … 245 238 * @return Error code. 246 239 */ 247 static int usb_pipe_control_read_no_check(usb_pipe_t *pipe,248 const void *setup_buffer, size_t setup_buffer_size,249 void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)250 {251 /* Ensure serialization over the phone. */252 pipe_start_transaction(pipe);253 254 assert(setup_buffer_size == 8);255 uint64_t setup_packet;256 memcpy(&setup_packet, setup_buffer, 8);257 258 async_exch_t *exch = async_exchange_begin(pipe->hc_sess);259 if (!exch) {260 pipe_end_transaction(pipe);261 return ENOMEM;262 }263 264 const int ret = usbhc_read(exch, pipe->wire->address, pipe->endpoint_no,265 setup_packet, data_buffer, data_buffer_size, data_transfered_size);266 async_exchange_end(exch);267 pipe_end_transaction(pipe);268 return ret;269 }270 271 /** Request a control read transfer on an endpoint pipe.272 *273 * This function encapsulates all three stages of a control transfer.274 *275 * @param[in] pipe Pipe used for the transfer.276 * @param[in] setup_buffer Buffer with the setup packet.277 * @param[in] setup_buffer_size Size of the setup packet (in bytes).278 * @param[out] data_buffer Buffer for incoming data.279 * @param[in] data_buffer_size Size of the buffer for incoming data (in bytes).280 * @param[out] data_transfered_size Number of bytes that were actually281 * transfered during the DATA stage.282 * @return Error code.283 */284 240 int usb_pipe_control_read(usb_pipe_t *pipe, 285 241 const void *setup_buffer, size_t setup_buffer_size, … … 288 244 assert(pipe); 289 245 290 if ((setup_buffer == NULL) || (setup_buffer_size == 0)) {246 if ((setup_buffer == NULL) || (setup_buffer_size != 8)) { 291 247 return EINVAL; 292 248 } … … 301 257 } 302 258 259 uint64_t setup_packet; 260 memcpy(&setup_packet, setup_buffer, 8); 261 303 262 int rc; 304 263 … … 309 268 310 269 size_t act_size = 0; 311 rc = usb_pipe_control_read_no_check(pipe, 312 setup_buffer, setup_buffer_size, 270 rc = usb_pipe_read_no_check(pipe, setup_packet, 313 271 data_buffer, data_buffer_size, &act_size); 314 272 … … 330 288 } 331 289 332 333 /** Request a control write transfer, no checking of input parameters. 290 /** Request a control write transfer on an endpoint pipe. 291 * 292 * This function encapsulates all three stages of a control transfer. 334 293 * 335 294 * @param[in] pipe Pipe used for the transfer. … … 340 299 * @return Error code. 341 300 */ 342 static int usb_pipe_control_write_no_check(usb_pipe_t *pipe,343 const void *setup_buffer, size_t setup_buffer_size,344 const void *data_buffer, size_t data_buffer_size)345 {346 /* Ensure serialization over the phone. */347 pipe_start_transaction(pipe);348 349 assert(setup_buffer_size == 8);350 uint64_t setup_packet;351 memcpy(&setup_packet, setup_buffer, 8);352 353 /* Make call identifying target USB device and control transfer type. */354 async_exch_t *exch = async_exchange_begin(pipe->hc_sess);355 if (!exch) {356 pipe_end_transaction(pipe);357 return ENOMEM;358 }359 const int ret =360 usbhc_write(exch, pipe->wire->address, pipe->endpoint_no,361 setup_packet, data_buffer, data_buffer_size);362 async_exchange_end(exch);363 pipe_end_transaction(pipe);364 return ret;365 }366 367 /** Request a control write transfer on an endpoint pipe.368 *369 * This function encapsulates all three stages of a control transfer.370 *371 * @param[in] pipe Pipe used for the transfer.372 * @param[in] setup_buffer Buffer with the setup packet.373 * @param[in] setup_buffer_size Size of the setup packet (in bytes).374 * @param[in] data_buffer Buffer with data to be sent.375 * @param[in] data_buffer_size Size of the buffer with outgoing data (in bytes).376 * @return Error code.377 */378 301 int usb_pipe_control_write(usb_pipe_t *pipe, 379 302 const void *setup_buffer, size_t setup_buffer_size, … … 382 305 assert(pipe); 383 306 384 if ((setup_buffer == NULL) || (setup_buffer_size == 0)) {307 if ((setup_buffer == NULL) || (setup_buffer_size != 8)) { 385 308 return EINVAL; 386 309 } … … 399 322 } 400 323 324 uint64_t setup_packet; 325 memcpy(&setup_packet, setup_buffer, 8); 326 401 327 int rc; 402 403 328 rc = pipe_add_ref(pipe, false); 404 329 if (rc != EOK) { … … 406 331 } 407 332 408 rc = usb_pipe_ control_write_no_check(pipe,409 setup_buffer, setup_buffer_size,data_buffer, data_buffer_size);333 rc = usb_pipe_write_no_check(pipe, setup_packet, 334 data_buffer, data_buffer_size); 410 335 411 336 if (rc == ESTALL) {
Note:
See TracChangeset
for help on using the changeset viewer.