The Pedigree Project  0.1
modules/drivers/x86/ne2k/main.cc
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include "Ne2k.h"
21 #include "modules/Module.h"
22 #include "pedigree/kernel/Log.h"
23 #include "pedigree/kernel/machine/Device.h"
24 #include "pedigree/kernel/utilities/new"
25 
26 class Network;
27 
28 static bool bFound = false;
29 
30 static void probeDevice(Device *pDev)
31 {
32  NOTICE("NE2K found");
33 
34  // Create a new NE2K node
35  Ne2k *pNe2k = new Ne2k(reinterpret_cast<Network *>(pDev));
36 
37  // Replace pDev with pNe2k.
38  pNe2k->setParent(pDev->getParent());
39  pDev->getParent()->replaceChild(pDev, pNe2k);
40 
41  bFound = true;
42 }
43 
44 static bool entry()
45 {
46  Device::searchByVendorIdAndDeviceId(
47  NE2K_VENDOR_ID, NE2K_DEVICE_ID, probeDevice);
48 
49  return bFound;
50 }
51 
52 static void exit()
53 {
54 }
55 
56 MODULE_NAME("ne2k");
57 MODULE_ENTRY(&entry);
58 MODULE_EXIT(&exit);
59 MODULE_DEPENDS("network-stack");
void replaceChild(Device *src, Device *dest)
Definition: Device.cc:168
Definition: Device.h:43
Definition: Ne2k.h:41
#define NOTICE(text)
Definition: Log.h:74
void setParent(Device *p)
Definition: Device.h:154
Device * getParent() const
Definition: Device.h:149