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 if ( speed == LowSpeed ) 57 m_lowspeed = true; 58 else 59 m_lowspeed = false; 60 } 61 62 int8 ControlPipe::GetDeviceAddress() 63 { 64 if ( m_device == NULL ) 65 return m_deviceaddress; 66 else 67 return m_device->GetAddress(); 68 } 69 70 status_t ControlPipe::SendRequest( uint8 request_type , uint8 request , uint16 value , 71 uint16 index , uint16 length , void *data , 72 size_t data_len , size_t *actual_len ) 73 { 74 //todo: het moet speciaal soort geheugen worden 75 usb_request_data *req = (usb_request_data *)malloc( sizeof( usb_request_data) ); 76 77 req->RequestType = request_type; 78 req->Request = request; 79 req->Value = value; 80 req->Index = index; 81 req->Length = length; 82 83 //Nicen up the second argument: the default pipe 84 //1) set up the pipe stuff a little nicer 85 //2) don't assume it's a low speed device :-( 86 return SendControlMessage( req , data , data_len , actual_len , 3 * 1000 * 1000 ); 87 } 88 89 status_t ControlPipe::SendControlMessage( usb_request_data *command , void *data , 90 size_t data_length , size_t *actual_length , 91 bigtime_t timeout ) 92 { 93 // this method should build an usb packet (new class) with the needed data 94 Transfer transfer( this ); 95 96 transfer.SetRequestData( command ); 97 transfer.SetBuffer( (uint8 *)data ); 98 transfer.SetBufferLength( data_length ); 99 transfer.SetActualLength( actual_length ); 100 101 status_t retval = m_bus->SubmitTransfer( transfer ); 102 return retval; 103 } 104