xref: /haiku/headers/private/kernel/boot/net/Ethernet.h (revision d561d0ad6889135e08b83c18dede8872a75c6d75)
1*d561d0adSIngo Weinhold /*
2*d561d0adSIngo Weinhold  * Copyright 2005, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3*d561d0adSIngo Weinhold  * All rights reserved. Distributed under the terms of the MIT License.
4*d561d0adSIngo Weinhold  */
5*d561d0adSIngo Weinhold 
6*d561d0adSIngo Weinhold #ifndef _BOOT_ETHERNET_H
7*d561d0adSIngo Weinhold #define _BOOT_ETHERNET_H
8*d561d0adSIngo Weinhold 
9*d561d0adSIngo Weinhold #include <boot/net/NetDefs.h>
10*d561d0adSIngo Weinhold #include <util/Vector.h>
11*d561d0adSIngo Weinhold 
12*d561d0adSIngo Weinhold class ChainBuffer;
13*d561d0adSIngo Weinhold class EthernetService;
14*d561d0adSIngo Weinhold 
15*d561d0adSIngo Weinhold // EthernetInterface
16*d561d0adSIngo Weinhold class EthernetInterface {
17*d561d0adSIngo Weinhold public:
18*d561d0adSIngo Weinhold 	EthernetInterface();
19*d561d0adSIngo Weinhold 	virtual ~EthernetInterface();
20*d561d0adSIngo Weinhold 
21*d561d0adSIngo Weinhold 	ip_addr_t IPAddress() const;
22*d561d0adSIngo Weinhold 	void SetIPAddress(ip_addr_t ipAddress);
23*d561d0adSIngo Weinhold 
24*d561d0adSIngo Weinhold 	virtual mac_addr_t MACAddress() const = 0;
25*d561d0adSIngo Weinhold 
26*d561d0adSIngo Weinhold 	virtual	void *AllocateSendReceiveBuffer(size_t size) = 0;
27*d561d0adSIngo Weinhold 	virtual	void FreeSendReceiveBuffer(void *buffer) = 0;
28*d561d0adSIngo Weinhold 
29*d561d0adSIngo Weinhold 	virtual ssize_t Send(const void *buffer, size_t size) = 0;
30*d561d0adSIngo Weinhold 	virtual ssize_t Receive(void *buffer, size_t size) = 0;
31*d561d0adSIngo Weinhold 
32*d561d0adSIngo Weinhold protected:
33*d561d0adSIngo Weinhold 	ip_addr_t					fIPAddress;
34*d561d0adSIngo Weinhold };
35*d561d0adSIngo Weinhold 
36*d561d0adSIngo Weinhold // EthernetSubService
37*d561d0adSIngo Weinhold class EthernetSubService : public NetService {
38*d561d0adSIngo Weinhold public:
39*d561d0adSIngo Weinhold 	EthernetSubService(const char *serviceName);
40*d561d0adSIngo Weinhold 	virtual ~EthernetSubService();
41*d561d0adSIngo Weinhold 
42*d561d0adSIngo Weinhold 	virtual uint16 EthernetProtocol() const = 0;
43*d561d0adSIngo Weinhold 
44*d561d0adSIngo Weinhold 	virtual void HandleEthernetPacket(EthernetService *ethernet,
45*d561d0adSIngo Weinhold 		const mac_addr_t &targetAddress, const void *data, size_t size) = 0;
46*d561d0adSIngo Weinhold };
47*d561d0adSIngo Weinhold 
48*d561d0adSIngo Weinhold 
49*d561d0adSIngo Weinhold // EthernetService
50*d561d0adSIngo Weinhold class EthernetService : public NetService {
51*d561d0adSIngo Weinhold public:
52*d561d0adSIngo Weinhold 	EthernetService();
53*d561d0adSIngo Weinhold 	virtual ~EthernetService();
54*d561d0adSIngo Weinhold 
55*d561d0adSIngo Weinhold 	status_t Init(EthernetInterface *interface);
56*d561d0adSIngo Weinhold 
57*d561d0adSIngo Weinhold 	mac_addr_t MACAddress() const;
58*d561d0adSIngo Weinhold 	ip_addr_t IPAddress() const;
59*d561d0adSIngo Weinhold 	void SetIPAddress(ip_addr_t ipAddress);
60*d561d0adSIngo Weinhold 
61*d561d0adSIngo Weinhold 	status_t Send(const mac_addr_t &destination, uint16 protocol,
62*d561d0adSIngo Weinhold 		ChainBuffer *buffer);
63*d561d0adSIngo Weinhold 	void ProcessIncomingPackets();
64*d561d0adSIngo Weinhold 
65*d561d0adSIngo Weinhold 	bool RegisterEthernetSubService(EthernetSubService *service);
66*d561d0adSIngo Weinhold 	bool UnregisterEthernetSubService(EthernetSubService *service);
67*d561d0adSIngo Weinhold 
68*d561d0adSIngo Weinhold 	virtual int CountSubNetServices() const;
69*d561d0adSIngo Weinhold 	virtual NetService *SubNetServiceAt(int index) const;
70*d561d0adSIngo Weinhold 
71*d561d0adSIngo Weinhold private:
72*d561d0adSIngo Weinhold 	enum {
73*d561d0adSIngo Weinhold 		SEND_BUFFER_SIZE	= 2048,
74*d561d0adSIngo Weinhold 		RECEIVE_BUFFER_SIZE	= SEND_BUFFER_SIZE,
75*d561d0adSIngo Weinhold 	};
76*d561d0adSIngo Weinhold 
77*d561d0adSIngo Weinhold 	EthernetInterface			*fInterface;
78*d561d0adSIngo Weinhold 	void						*fSendBuffer;
79*d561d0adSIngo Weinhold 	void						*fReceiveBuffer;
80*d561d0adSIngo Weinhold 	Vector<EthernetSubService*>	fServices;
81*d561d0adSIngo Weinhold };
82*d561d0adSIngo Weinhold 
83*d561d0adSIngo Weinhold 
84*d561d0adSIngo Weinhold #endif	// _BOOT_ETHERNET_H
85