source: mainline/uspace/lib/usb/src/usbdrvreq.c@ 947d788

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 947d788 was f995350, checked in by Vojtech Horky <vojtechhorky@…>, 15 years ago

Add function for SET_ADDRESS request

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Copyright (c) 2010 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libusb usb
30 * @{
31 */
32/** @file
33 * @brief USB driver - standard USB requests (implementation).
34 */
35#include <usb/usbdrv.h>
36#include <usb/devreq.h>
37#include <errno.h>
38
39/** Change address of connected device.
40 *
41 * @see usb_drv_reserve_default_address
42 * @see usb_drv_release_default_address
43 * @see usb_drv_request_address
44 * @see usb_drv_release_address
45 * @see usb_drv_bind_address
46 *
47 * @param phone Open phone to HC driver.
48 * @param old_address Current address.
49 * @param address Address to be set.
50 * @return Error code.
51 */
52int usb_drv_req_set_address(int phone, usb_address_t old_address,
53 usb_address_t new_address)
54{
55 /* Prepare the target. */
56 usb_target_t target = {
57 .address = old_address,
58 .endpoint = 0
59 };
60
61 /* Prepare the setup packet. */
62 usb_device_request_setup_packet_t setup_packet = {
63 .request_type = 0,
64 .request = USB_DEVREQ_SET_ADDRESS,
65 .index = 0,
66 .length = 0,
67 };
68 setup_packet.value = new_address;
69
70 usb_handle_t handle;
71 int rc;
72
73 /* Start the control write transfer. */
74 rc = usb_drv_async_control_write_setup(phone, target,
75 &setup_packet, sizeof(setup_packet), &handle);
76 if (rc != EOK) {
77 return rc;
78 }
79 rc = usb_drv_async_wait_for(handle);
80 if (rc != EOK) {
81 return rc;
82 }
83
84 /* Finish the control write transfer. */
85 rc = usb_drv_async_control_write_status(phone, target, &handle);
86 if (rc != EOK) {
87 return rc;
88 }
89 rc = usb_drv_async_wait_for(handle);
90 if (rc != EOK) {
91 return rc;
92 }
93
94 return EOK;
95}
96
97/**
98 * @}
99 */
Note: See TracBrowser for help on using the repository browser.