xref: /haiku/src/system/boot/platform/pxe_ia32/network.cpp (revision 9d6d3fcf5fe8308cd020cecf89dede440346f8c4)
1 /*
2  * Copyright 2006, Marcus Overhagen <marcus@overhagen.de. All rights reserved.
3  * Copyright 2005, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
4  * Distributed under the terms of the MIT License.
5  */
6 
7 #include <new>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 
12 #include <OS.h>
13 #include <KernelExport.h>
14 
15 #include <boot/net/Ethernet.h>
16 #include <boot/net/NetStack.h>
17 
18 #include "pxe_undi.h"
19 
20 #define TRACE_NETWORK
21 #ifdef TRACE_NETWORK
22 #	define TRACE(x...) dprintf(x)
23 #else
24 #	define TRACE(x...)
25 #endif
26 
27 #ifdef TRACE_NETWORK
28 
29 static void
30 hex_dump(const void *_data, int length)
31 {
32 	uint8 *data = (uint8*)_data;
33 	for (int i = 0; i < length; i++) {
34 		if (i % 4 == 0) {
35 			if (i % 32 == 0) {
36 				if (i != 0)
37 					TRACE("\n");
38 				TRACE("%03x: ", i);
39 			} else
40 				TRACE(" ");
41 		}
42 
43 		TRACE("%02x", data[i]);
44 	}
45 	TRACE("\n");
46 }
47 
48 #else	// !TRACE_NETWORK
49 
50 #define hex_dump(data, length)
51 
52 #endif	// !TRACE_NETWORK
53 
54 
55 class UNDI : public EthernetInterface
56 {
57 public:
58 						UNDI();
59 	virtual 			~UNDI();
60 
61 	status_t 			Init();
62 
63 	virtual mac_addr_t	MACAddress() const;
64 
65 	virtual	void *		AllocateSendReceiveBuffer(size_t size);
66 	virtual	void 		FreeSendReceiveBuffer(void *buffer);
67 
68 	virtual ssize_t		Send(const void *buffer, size_t size);
69 	virtual ssize_t		Receive(void *buffer, size_t size);
70 
71 private:
72 	mac_addr_t			fMACAddress;
73 };
74 
75 
76 UNDI::UNDI()
77 {
78 	TRACE("UNDI::UNDI\n");
79 }
80 
81 
82 UNDI::~UNDI()
83 {
84 	TRACE("UNDI::~UNDI\n");
85 }
86 
87 
88 status_t
89 UNDI::Init()
90 {
91 	TRACE("UNDI::Init\n");
92 	return B_OK;
93 }
94 
95 
96 mac_addr_t
97 UNDI::MACAddress() const
98 {
99 	return fMACAddress;
100 }
101 
102 void *
103 UNDI::AllocateSendReceiveBuffer(size_t size)
104 {
105 	TRACE("UNDI::AllocateSendReceiveBuffer, size %ld\n", size);
106 	return 0;
107 }
108 
109 
110 void
111 UNDI::FreeSendReceiveBuffer(void *buffer)
112 {
113 	TRACE("UNDI::FreeSendReceiveBuffer\n");
114 }
115 
116 
117 ssize_t
118 UNDI::Send(const void *buffer, size_t size)
119 {
120 	TRACE("UNDI::Send, size %ld\n", size);
121 	return 0;
122 }
123 
124 
125 ssize_t
126 UNDI::Receive(void *buffer, size_t size)
127 {
128 	TRACE("UNDI::Receive, size %ld\n", size);
129 	return 0;
130 }
131 
132 
133 status_t
134 platform_net_stack_init()
135 {
136 	TRACE("platform_net_stack_init\n");
137 
138 	pxe_undi_init();
139 
140 	UNDI *interface = new(nothrow) UNDI;
141 	if (!interface)
142 		return B_NO_MEMORY;
143 
144 	status_t error = interface->Init();
145 	if (error != B_OK) {
146 		delete interface;
147 		return error;
148 	}
149 
150 	error = NetStack::Default()->AddEthernetInterface(interface);
151 	if (error != B_OK) {
152 		delete interface;
153 		return error;
154 	}
155 
156 	return B_OK;
157 }
158