2011-12-22 15:19:25 +00:00
|
|
|
/*
|
|
|
|
* \brief NIC session interface
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2009-11-13
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 20:44:47 +00:00
|
|
|
* Copyright (C) 2009-2013 Genode Labs GmbH
|
2011-12-22 15:19:25 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__NIC_SESSION__NIC_SESSION_H_
|
|
|
|
#define _INCLUDE__NIC_SESSION__NIC_SESSION_H_
|
|
|
|
|
|
|
|
#include <dataspace/capability.h>
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
#include <base/output.h>
|
2011-12-22 15:19:25 +00:00
|
|
|
#include <base/signal.h>
|
|
|
|
#include <base/rpc.h>
|
|
|
|
#include <session/session.h>
|
|
|
|
#include <packet_stream_tx/packet_stream_tx.h>
|
|
|
|
#include <packet_stream_rx/packet_stream_rx.h>
|
|
|
|
|
|
|
|
namespace Nic {
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
struct Mac_address;
|
|
|
|
struct Session;
|
2015-03-16 16:33:26 +00:00
|
|
|
|
|
|
|
using Genode::Packet_stream_sink;
|
|
|
|
using Genode::Packet_stream_source;
|
|
|
|
|
|
|
|
typedef Genode::Packet_descriptor Packet_descriptor;
|
2015-03-04 20:12:14 +00:00
|
|
|
}
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
struct Nic::Mac_address
|
|
|
|
{
|
|
|
|
enum { NUM_ELEM = 6 };
|
|
|
|
|
|
|
|
char addr[NUM_ELEM];
|
|
|
|
|
|
|
|
void print(Genode::Output &out) const
|
|
|
|
{
|
|
|
|
using Genode::Hex;
|
|
|
|
for (unsigned i = 0; i < NUM_ELEM; i++)
|
|
|
|
Genode::print(out, i > 0 ? ":" : "",
|
|
|
|
Hex(addr[i], Hex::OMIT_PREFIX, Hex::PAD));
|
|
|
|
}
|
|
|
|
};
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
|
2015-03-20 16:50:41 +00:00
|
|
|
/*
|
|
|
|
* NIC session interface
|
|
|
|
*
|
|
|
|
* A NIC session corresponds to a network adaptor, which can be used to
|
|
|
|
* transmit and receive network packets. Payload is communicated over the
|
|
|
|
* packet-stream interface set up between 'Session_client' and
|
|
|
|
* 'Session_server'.
|
|
|
|
*
|
|
|
|
* Even though the methods 'tx', 'tx_channel', 'rx', and 'rx_channel' are
|
|
|
|
* specific for the client side of the NIC session interface, they are part of
|
|
|
|
* the abstract 'Session' class to enable the client-side use of the NIC
|
|
|
|
* interface via a pointer to the abstract 'Session' class. This way, we can
|
|
|
|
* transparently co-locate the packet-stream server with the client in same
|
|
|
|
* program.
|
|
|
|
*/
|
2015-03-04 20:12:14 +00:00
|
|
|
struct Nic::Session : Genode::Session
|
|
|
|
{
|
|
|
|
enum { QUEUE_SIZE = 1024 };
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/*
|
|
|
|
* Types used by the client stub code and server implementation
|
|
|
|
*
|
|
|
|
* The acknowledgement queue has always the same size as the submit
|
|
|
|
* queue. We access the packet content as a char pointer.
|
|
|
|
*/
|
2015-03-16 16:33:26 +00:00
|
|
|
typedef Genode::Packet_stream_policy<Genode::Packet_descriptor,
|
|
|
|
QUEUE_SIZE, QUEUE_SIZE, char> Policy;
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
typedef Packet_stream_tx::Channel<Policy> Tx;
|
|
|
|
typedef Packet_stream_rx::Channel<Policy> Rx;
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
static const char *service_name() { return "Nic"; }
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
virtual ~Session() { }
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/**
|
|
|
|
* Request MAC address of network adapter
|
|
|
|
*/
|
|
|
|
virtual Mac_address mac_address() = 0;
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/**
|
|
|
|
* Request packet-transmission channel
|
|
|
|
*/
|
|
|
|
virtual Tx *tx_channel() { return 0; }
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/**
|
|
|
|
* Request packet-reception channel
|
|
|
|
*/
|
|
|
|
virtual Rx *rx_channel() { return 0; }
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/**
|
|
|
|
* Request client-side packet-stream interface of tx channel
|
|
|
|
*/
|
|
|
|
virtual Tx::Source *tx() { return 0; }
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/**
|
|
|
|
* Request client-side packet-stream interface of rx channel
|
|
|
|
*/
|
|
|
|
virtual Rx::Sink *rx() { return 0; }
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2015-03-11 10:33:03 +00:00
|
|
|
/**
|
|
|
|
* Request current link state of network adapter (true means link detected)
|
|
|
|
*/
|
|
|
|
virtual bool link_state() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register signal handler for link state changes
|
|
|
|
*/
|
|
|
|
virtual void link_state_sigh(Genode::Signal_context_capability sigh) = 0;
|
2015-03-04 20:12:14 +00:00
|
|
|
|
|
|
|
/*******************
|
|
|
|
** RPC interface **
|
|
|
|
*******************/
|
|
|
|
|
|
|
|
GENODE_RPC(Rpc_mac_address, Mac_address, mac_address);
|
|
|
|
GENODE_RPC(Rpc_tx_cap, Genode::Capability<Tx>, _tx_cap);
|
|
|
|
GENODE_RPC(Rpc_rx_cap, Genode::Capability<Rx>, _rx_cap);
|
2015-03-11 10:33:03 +00:00
|
|
|
GENODE_RPC(Rpc_link_state, bool, link_state);
|
|
|
|
GENODE_RPC(Rpc_link_state_sigh, void, link_state_sigh,
|
|
|
|
Genode::Signal_context_capability);
|
2015-03-04 20:12:14 +00:00
|
|
|
|
2015-03-11 10:33:03 +00:00
|
|
|
GENODE_RPC_INTERFACE(Rpc_mac_address, Rpc_link_state,
|
|
|
|
Rpc_link_state_sigh, Rpc_tx_cap, Rpc_rx_cap);
|
2015-03-04 20:12:14 +00:00
|
|
|
};
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
#endif /* _INCLUDE__NIC_SESSION__NIC_SESSION_H_ */
|