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