openfirmware: another way to find the MAC address
Of course Sun and Apple didn't put it at the same place... Change-Id: I974caff7335bb25a0e8dd4f7da8bdb9a737d011e Reviewed-on: https://review.haiku-os.org/c/haiku/+/2357 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2005, Ingo Weinhold <[email protected]>.
|
* Copyright 2005, Ingo Weinhold <[email protected]>.
|
||||||
* Copyright 2010, Andreas Faerber <[email protected]>
|
* Copyright 2010, Andreas Faerber <[email protected]>
|
||||||
|
* Copyright 2002, Adrien Destugues <[email protected]>
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -30,22 +31,25 @@
|
|||||||
|
|
||||||
class OFEthernetInterface : public EthernetInterface {
|
class OFEthernetInterface : public EthernetInterface {
|
||||||
public:
|
public:
|
||||||
OFEthernetInterface();
|
OFEthernetInterface();
|
||||||
virtual ~OFEthernetInterface();
|
virtual ~OFEthernetInterface();
|
||||||
|
|
||||||
status_t Init(const char *device, const char *parameters);
|
status_t Init(const char *device, const char *parameters);
|
||||||
|
|
||||||
virtual mac_addr_t MACAddress() const;
|
virtual mac_addr_t MACAddress() const;
|
||||||
|
|
||||||
virtual void *AllocateSendReceiveBuffer(size_t size);
|
virtual void * AllocateSendReceiveBuffer(size_t size);
|
||||||
virtual void FreeSendReceiveBuffer(void *buffer);
|
virtual void FreeSendReceiveBuffer(void *buffer);
|
||||||
|
|
||||||
virtual ssize_t Send(const void *buffer, size_t size);
|
virtual ssize_t Send(const void *buffer, size_t size);
|
||||||
virtual ssize_t Receive(void *buffer, size_t size);
|
virtual ssize_t Receive(void *buffer, size_t size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
intptr_t fHandle;
|
status_t FindMACAddress();
|
||||||
mac_addr_t fMACAddress;
|
|
||||||
|
private:
|
||||||
|
intptr_t fHandle;
|
||||||
|
mac_addr_t fMACAddress;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -96,6 +100,40 @@ OFEthernetInterface::~OFEthernetInterface()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
OFEthernetInterface::FindMACAddress()
|
||||||
|
{
|
||||||
|
intptr_t package = of_instance_to_package(fHandle);
|
||||||
|
|
||||||
|
// get MAC address
|
||||||
|
int bytesRead = of_getprop(package, "local-mac-address", &fMACAddress,
|
||||||
|
sizeof(fMACAddress));
|
||||||
|
if (bytesRead == (int)sizeof(fMACAddress))
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
// Failed to get the MAC address of the network device. The system may
|
||||||
|
// have a global standard MAC address.
|
||||||
|
bytesRead = of_getprop(gChosen, "mac-address", &fMACAddress,
|
||||||
|
sizeof(fMACAddress));
|
||||||
|
if (bytesRead == (int)sizeof(fMACAddress)) {
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// On Sun machines, there is a global word 'mac-address' which returns
|
||||||
|
// the size and a pointer to the MAC address
|
||||||
|
size_t size;
|
||||||
|
void* ptr;
|
||||||
|
if (of_interpret("mac-address", 0, 2, &size, &ptr) != OF_FAILED) {
|
||||||
|
if (size == sizeof(fMACAddress)) {
|
||||||
|
memcpy(&fMACAddress, ptr, size);
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
OFEthernetInterface::Init(const char *device, const char *parameters)
|
OFEthernetInterface::Init(const char *device, const char *parameters)
|
||||||
{
|
{
|
||||||
@@ -109,20 +147,9 @@ OFEthernetInterface::Init(const char *device, const char *parameters)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
intptr_t package = of_instance_to_package(fHandle);
|
if (FindMACAddress() != B_OK) {
|
||||||
|
printf("Failed to get MAC address\n");
|
||||||
// get MAC address
|
return B_ERROR;
|
||||||
int bytesRead = of_getprop(package, "local-mac-address", &fMACAddress,
|
|
||||||
sizeof(fMACAddress));
|
|
||||||
if (bytesRead == OF_FAILED || bytesRead < (int)sizeof(fMACAddress)) {
|
|
||||||
// Failed to get the MAC address of the network device. The system may
|
|
||||||
// have a global standard MAC address.
|
|
||||||
bytesRead = of_getprop(gChosen, "mac-address", &fMACAddress,
|
|
||||||
sizeof(fMACAddress));
|
|
||||||
if (bytesRead == OF_FAILED || bytesRead < (int)sizeof(fMACAddress)) {
|
|
||||||
printf("Failed to get MAC address\n");
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get IP address
|
// get IP address
|
||||||
|
|||||||
Reference in New Issue
Block a user