2014-11-13 14:44:15 +00:00
|
|
|
/**
|
|
|
|
* \brief USB session for raw device connection
|
|
|
|
* \author Sebastian Sumpf
|
|
|
|
* \date 2014-12-08
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2014-2017 Genode Labs GmbH
|
2014-11-13 14:44:15 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2014-11-13 14:44:15 +00:00
|
|
|
*/
|
|
|
|
#ifndef _INCLUDE__USB_SESSION__USB_SESSION_H_
|
|
|
|
#define _INCLUDE__USB_SESSION__USB_SESSION_H_
|
|
|
|
|
|
|
|
#include <os/packet_stream.h>
|
|
|
|
#include <packet_stream_tx/packet_stream_tx.h>
|
|
|
|
#include <session/session.h>
|
|
|
|
#include <usb/types.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Usb {
|
2015-03-16 16:33:26 +00:00
|
|
|
|
2014-11-13 14:44:15 +00:00
|
|
|
using namespace Genode;
|
|
|
|
class Session;
|
|
|
|
struct Packet_descriptor;
|
2023-03-23 15:45:12 +00:00
|
|
|
struct Isoc_transfer;
|
2014-11-13 14:44:15 +00:00
|
|
|
struct Completion;
|
|
|
|
}
|
|
|
|
|
2015-03-16 16:33:26 +00:00
|
|
|
|
2014-11-13 14:44:15 +00:00
|
|
|
/**
|
|
|
|
* USB packet type
|
|
|
|
*/
|
2015-03-16 16:33:26 +00:00
|
|
|
struct Usb::Packet_descriptor : Genode::Packet_descriptor
|
2014-11-13 14:44:15 +00:00
|
|
|
{
|
2021-06-08 16:34:53 +00:00
|
|
|
enum Type { STRING, CTRL, BULK, IRQ, ISOC, ALT_SETTING, CONFIG, RELEASE_IF, FLUSH_TRANSFERS };
|
2014-11-13 14:44:15 +00:00
|
|
|
|
2016-10-17 12:13:51 +00:00
|
|
|
/* use the polling interval stated in the endpoint descriptor */
|
|
|
|
enum { DEFAULT_POLLING_INTERVAL = -1 };
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
Type type { STRING };
|
|
|
|
bool succeded { false };
|
|
|
|
Completion *completion { nullptr };
|
2014-11-13 14:44:15 +00:00
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2015-03-16 16:33:26 +00:00
|
|
|
uint8_t index;
|
|
|
|
unsigned length;
|
2014-11-13 14:44:15 +00:00
|
|
|
} string;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
2015-03-16 16:33:26 +00:00
|
|
|
uint8_t request;
|
|
|
|
uint8_t request_type;
|
|
|
|
uint16_t value;
|
|
|
|
uint16_t index;
|
2015-04-27 11:00:27 +00:00
|
|
|
int actual_size; /* returned */
|
2015-03-16 16:33:26 +00:00
|
|
|
int timeout;
|
2014-11-13 14:44:15 +00:00
|
|
|
} control;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint8_t ep;
|
|
|
|
int actual_size; /* returned */
|
2016-10-17 12:13:51 +00:00
|
|
|
int polling_interval; /* for interrupt transfers */
|
2014-11-13 14:44:15 +00:00
|
|
|
} transfer;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
2015-03-16 16:33:26 +00:00
|
|
|
uint8_t number;
|
|
|
|
uint8_t alt_setting;
|
2014-11-13 14:44:15 +00:00
|
|
|
} interface;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint8_t number;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-02-01 10:18:00 +00:00
|
|
|
enum Error {
|
|
|
|
NO_ERROR,
|
|
|
|
INTERFACE_OR_ENDPOINT_ERROR,
|
|
|
|
MEMORY_ERROR,
|
|
|
|
NO_DEVICE_ERROR,
|
|
|
|
PACKET_INVALID_ERROR,
|
|
|
|
PROTOCOL_ERROR,
|
|
|
|
STALL_ERROR,
|
|
|
|
TIMEOUT_ERROR,
|
|
|
|
UNKNOWN_ERROR
|
|
|
|
};
|
2016-04-21 12:06:38 +00:00
|
|
|
|
|
|
|
Error error = NO_ERROR;
|
|
|
|
|
2016-05-11 16:21:47 +00:00
|
|
|
/**
|
|
|
|
* Return true if packet is a read transfer
|
|
|
|
*/
|
|
|
|
bool read_transfer() { return transfer.ep & ENDPOINT_IN; }
|
|
|
|
|
2014-11-13 14:44:15 +00:00
|
|
|
Packet_descriptor(off_t offset = 0, size_t size = 0)
|
2015-03-16 16:33:26 +00:00
|
|
|
: Genode::Packet_descriptor(offset, size) { }
|
2014-11-13 14:44:15 +00:00
|
|
|
|
2015-03-16 16:33:26 +00:00
|
|
|
Packet_descriptor(Genode::Packet_descriptor p, Type type, Completion *completion = nullptr)
|
|
|
|
: Genode::Packet_descriptor(p.offset(), p.size()), type(type), completion(completion) { }
|
2014-11-13 14:44:15 +00:00
|
|
|
};
|
|
|
|
|
2015-03-16 16:33:26 +00:00
|
|
|
|
2023-03-23 15:45:12 +00:00
|
|
|
/**
|
|
|
|
* Isochronous transfer metadata (located at start of stream packet)
|
|
|
|
*/
|
|
|
|
struct Usb::Isoc_transfer
|
|
|
|
{
|
|
|
|
enum { MAX_PACKETS = 32 };
|
|
|
|
|
|
|
|
unsigned number_of_packets;
|
|
|
|
unsigned packet_size[MAX_PACKETS];
|
|
|
|
unsigned actual_packet_size[MAX_PACKETS];
|
|
|
|
|
|
|
|
char *data() { return (char *)(this + 1); }
|
|
|
|
|
|
|
|
static size_t size(unsigned data_size)
|
|
|
|
{
|
|
|
|
return sizeof(Isoc_transfer) + data_size;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-11-13 14:44:15 +00:00
|
|
|
/**
|
|
|
|
* Completion for asynchronous communication
|
|
|
|
*/
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
struct Usb::Completion : Genode::Interface
|
2014-11-13 14:44:15 +00:00
|
|
|
{
|
|
|
|
virtual void complete(Usb::Packet_descriptor &p) = 0;
|
|
|
|
};
|
|
|
|
|
2015-03-16 16:33:26 +00:00
|
|
|
|
2014-11-13 14:44:15 +00:00
|
|
|
struct Usb::Session : public Genode::Session
|
|
|
|
{
|
|
|
|
/****************
|
|
|
|
** Exceptions **
|
|
|
|
****************/
|
|
|
|
|
|
|
|
class Device_not_found : public Exception { };
|
|
|
|
class Interface_not_found : public Exception { };
|
|
|
|
class Interface_already_claimed : public Exception { };
|
|
|
|
class Interface_not_claimed : public Exception { };
|
|
|
|
class Invalid_endpoint : public Exception { };
|
|
|
|
|
|
|
|
|
|
|
|
/*******************
|
|
|
|
** Packet stream **
|
|
|
|
*******************/
|
|
|
|
|
|
|
|
enum { TX_QUEUE_SIZE = 64 };
|
|
|
|
|
|
|
|
typedef Packet_stream_policy<Usb::Packet_descriptor,
|
|
|
|
TX_QUEUE_SIZE, TX_QUEUE_SIZE,
|
|
|
|
char> Tx_policy;
|
|
|
|
|
|
|
|
typedef Packet_stream_tx::Channel<Tx_policy> Tx;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request packet-transmission channel
|
|
|
|
*/
|
|
|
|
virtual Tx *tx_channel() { return 0; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request client-side packet-stream interface of tx channel
|
|
|
|
*/
|
|
|
|
virtual Tx::Source *source() { return 0; }
|
|
|
|
|
|
|
|
|
|
|
|
/***********************
|
|
|
|
** Session interface **
|
|
|
|
***********************/
|
|
|
|
|
2017-05-24 12:41:19 +00:00
|
|
|
/**
|
|
|
|
* \noapi
|
|
|
|
*/
|
2014-11-13 14:44:15 +00:00
|
|
|
static const char *service_name() { return "Usb"; }
|
|
|
|
|
2017-05-07 20:03:25 +00:00
|
|
|
enum { CAP_QUOTA = 5 };
|
|
|
|
|
2014-11-13 14:44:15 +00:00
|
|
|
/**
|
|
|
|
* Send from the server to the client upon device state change
|
|
|
|
*/
|
|
|
|
virtual void sigh_state_change(Signal_context_capability sigh) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is the device present
|
|
|
|
*/
|
|
|
|
virtual bool plugged() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve device and current configurations despcriptors
|
|
|
|
*/
|
|
|
|
virtual void config_descriptor(Device_descriptor *device_descr,
|
|
|
|
Config_descriptor *config_descr) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return number of alt settings for iterface
|
|
|
|
*/
|
|
|
|
virtual unsigned alt_settings(unsigned index) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return interface descriptor for interface index/alternate setting tuple
|
|
|
|
*/
|
|
|
|
virtual void interface_descriptor(unsigned index, unsigned alt_setting,
|
|
|
|
Interface_descriptor *interface_descr) = 0;
|
|
|
|
|
2020-12-02 08:28:20 +00:00
|
|
|
virtual bool interface_extra(unsigned index, unsigned alt_setting,
|
|
|
|
Interface_extra *interface_data) = 0;
|
|
|
|
|
2014-11-13 14:44:15 +00:00
|
|
|
/**
|
|
|
|
* Return endpoint for interface index/alternate setting tuple
|
|
|
|
*/
|
|
|
|
virtual void endpoint_descriptor(unsigned interface_num,
|
|
|
|
unsigned alt_setting,
|
|
|
|
unsigned endpoint_num,
|
|
|
|
Endpoint_descriptor *endpoint_descr) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Claim an interface number
|
|
|
|
*/
|
2016-01-06 13:43:21 +00:00
|
|
|
virtual void claim_interface(unsigned interface_num) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release an interface number
|
|
|
|
*/
|
|
|
|
virtual void release_interface(unsigned interface_num) = 0;
|
2014-11-13 14:44:15 +00:00
|
|
|
|
|
|
|
GENODE_RPC(Rpc_plugged, bool, plugged);
|
|
|
|
GENODE_RPC(Rpc_sigh_state_change, void, sigh_state_change, Signal_context_capability);
|
|
|
|
GENODE_RPC(Rpc_tx_cap, Capability<Tx>, _tx_cap);
|
|
|
|
GENODE_RPC_THROW(Rpc_config_descr, void, config_descriptor, GENODE_TYPE_LIST(Device_not_found),
|
|
|
|
Device_descriptor *, Config_descriptor *);
|
2022-08-23 14:10:20 +00:00
|
|
|
GENODE_RPC_THROW(Rpc_alt_settings, unsigned, alt_settings, GENODE_TYPE_LIST(Device_not_found,
|
|
|
|
Interface_not_found), unsigned);
|
2014-11-13 14:44:15 +00:00
|
|
|
GENODE_RPC_THROW(Rpc_iface_descr, void, interface_descriptor, GENODE_TYPE_LIST(Device_not_found,
|
|
|
|
Interface_not_found), unsigned, unsigned, Interface_descriptor *);
|
2020-12-02 08:28:20 +00:00
|
|
|
GENODE_RPC_THROW(Rpc_iface_extra, bool, interface_extra, GENODE_TYPE_LIST(Device_not_found,
|
|
|
|
Interface_not_found), unsigned, unsigned, Interface_extra *);
|
2014-11-13 14:44:15 +00:00
|
|
|
GENODE_RPC_THROW(Rpc_ep_descr, void, endpoint_descriptor, GENODE_TYPE_LIST(Device_not_found,
|
|
|
|
Interface_not_found), unsigned, unsigned, unsigned, Endpoint_descriptor *);
|
2022-08-23 14:10:20 +00:00
|
|
|
GENODE_RPC_THROW(Rpc_claim_interface, void, claim_interface, GENODE_TYPE_LIST(Device_not_found,
|
|
|
|
Interface_not_found, Interface_already_claimed), unsigned);
|
|
|
|
GENODE_RPC_THROW(Rpc_release_interface, void, release_interface, GENODE_TYPE_LIST(Device_not_found,
|
|
|
|
Interface_not_found), unsigned);
|
2014-11-13 14:44:15 +00:00
|
|
|
GENODE_RPC_INTERFACE(Rpc_plugged, Rpc_sigh_state_change, Rpc_tx_cap, Rpc_config_descr,
|
2020-12-02 08:28:20 +00:00
|
|
|
Rpc_iface_descr, Rpc_iface_extra, Rpc_ep_descr, Rpc_alt_settings,
|
|
|
|
Rpc_claim_interface, Rpc_release_interface);
|
2014-11-13 14:44:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__USB_SESSION__USB_SESSION_H_ */
|