1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2004, Niels S. Reedijk 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 22 #include "usb_p.h" 23 24 Pipe::Pipe( Device *dev , Direction &dir , uint8 &endpointaddress ) 25 { 26 m_direction = dir; 27 m_device = dev; 28 m_endpoint = endpointaddress; 29 if ( m_device != NULL ) 30 m_bus = m_device->GetBusManager(); 31 } 32 33 Pipe::~Pipe() 34 { 35 } 36 37 int8 Pipe::GetDeviceAddress() 38 { 39 if ( m_device == NULL ) 40 return -1; 41 else 42 return m_device->GetAddress(); 43 } 44 45 ControlPipe::ControlPipe( Device *dev , Direction dir , uint8 endpointaddress ) 46 : Pipe( dev , dir , endpointaddress ) 47 { 48 49 } 50 51 ControlPipe::ControlPipe( BusManager *bus , int8 dev_address , Direction dir , Speed speed , uint8 endpointaddress ) 52 : Pipe( NULL , dir , endpointaddress ) 53 { 54 m_bus = bus; 55 m_deviceaddress = dev_address; 56 m_speed = speed; 57 } 58 59 int8 ControlPipe::GetDeviceAddress() 60 { 61 if ( m_device == NULL ) 62 return m_deviceaddress; 63 else 64 return m_device->GetAddress(); 65 } 66 67 status_t ControlPipe::SendRequest( uint8 request_type , uint8 request , uint16 value , 68 uint16 index , uint16 length , void *data , 69 size_t data_len , size_t *actual_len ) 70 { 71 usb_request_data req; 72 73 req.RequestType = request_type; 74 req.Request = request; 75 req.Value = value; 76 req.Index = index; 77 req.Length = length; 78 79 return SendControlMessage( &req , data , data_len , actual_len , 3 * 1000 * 1000 ); 80 } 81 82 status_t ControlPipe::SendControlMessage( usb_request_data *command , void *data , 83 size_t data_length , size_t *actual_length , 84 bigtime_t timeout ) 85 { 86 // this method should build an usb packet (new class) with the needed data 87 Transfer *transfer = new Transfer( this , true ); 88 89 transfer->SetRequestData( command ); 90 transfer->SetBuffer( (uint8 *)data ); 91 transfer->SetBufferLength( data_length ); 92 transfer->SetActualLength( actual_length ); 93 94 status_t retval = m_bus->SubmitTransfer( transfer ); 95 return retval; 96 } 97