5 * Copyright (C) 2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "manes/manec.h"
28 using namespace resources
;
30 void get_mac_addr(u8
*mac
);
31 void ne2k_pci_init(pci_did pciaddr
);
32 void ne2k_pci_send_packet(pci_did pciaddr
, u8
*buff
, u16 len
);
36 bool ne2k::init_device(p
<did
> id
) {
39 ne2k_pci_init(*id
.cast
<pci_did
>());
43 bool ne2k::check_device(p
<did
> id
) {
44 p
<pci_did
> pid
= id
.cast
<pci_did
>();
49 /* It must be an ethernet card */
50 unsigned int devclass
= pid
->get_bus().cast
<pci
>()->get_devclass(id
) >> 8;
51 if (devclass
!= 0x0200)
54 unsigned int devid
= pid
->get_bus().cast
<pci
>()->get_devid(id
);
55 /* It must be a *compatible* ethernet card (for example Realtek 8029) */
56 if (devid
!= 0x802910ec)
62 void ne2k::send_data(const buffer
&x
) {
63 ne2k_pci_send_packet(*device_id
.cast
<pci_did
>(), (u8
*)x
.get_address(), x
.get_size());
67 net::mac_addr
ne2k::get_haddr() const {
70 return net::mac_addr::from_be(*(u32
*)addr
, ((u16
*)addr
)[2]);
73 void ne2k::register_type() {
74 delegate
<bool, p
<did
> > chk
;
75 chk
.function(&ne2k::check_device
);
76 manes::manec::get()->register_driver
<ne2k
>("ne2k", "nic", chk
);