]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/network/AppleBPF/AppleBPF.cpp
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * AppleBPF.cpp - BPF driver class implementation.
27 // Need to check with Simon on User/Client interface and how to do
28 // PostLoad, and check on IOBSD (IONeededResource)
31 #include <IOKit/IOLib.h>
37 #include <net/bpfdesc.h>
38 #include <sys/malloc.h>
41 //------------------------------------------------------------------------
43 #define super IOService
44 OSDefineMetaClassAndStructors(AppleBPF
, IOService
);
46 //------------------------------------------------------------------------
49 // -----------------------------------------------------------------------
51 // This is the first method to be called when an object of this class is
54 bool AppleBPF::init(OSDictionary
* properties
)
56 if (!super::init(properties
))
57 { IOLog("BPF: super init failed\n");
61 // Do class specific initialization here. Probably not necessary for
64 // IOLog("BPF: super init succeeded\n");
65 return true; // return 'true' for success, 'false' for failure.
68 // -----------------------------------------------------------------------
70 // The driver has been matched, start it up. Do most initialization and
71 // resource allocation here.
73 bool AppleBPF::start(IOService
* provider
)
76 extern struct bpf_d
*bpf_dtab
;
79 if (!super::start(provider
))
80 { IOLog("BPF: super start failed\n");
84 val
= OSDynamicCast(OSNumber
, getObject("IODevCount"));
86 nbpfilter
= DEFAULT_BPF_DEV_COUNT
;
88 nbpfilter
= val
->unsigned32BitValue();
90 // bpfops.bpf_tap = bpf_tap;
91 // bpfops.bpf_mtap = bpf_mtap;
93 bpf_dtab
= (struct bpf_d
*)IOMalloc(sizeof (struct bpf_d
) * nbpfilter
);
95 { IOLog("%s: couldn't get memory for descriptor table\n",
101 * Mark all the descriptors free
103 for (i
= 0; i
< nbpfilter
; ++i
)
104 D_MARKFREE(&bpf_dtab
[i
]);
106 // IOLog("AppleBPF::start() called\n");
108 return true; // return 'true' for success, 'false' for failure.
111 // -----------------------------------------------------------------------
113 // Release all resources before the driver goes away.
115 void AppleBPF::stop(IOService
* provider
)
116 { extern struct bpf_d
*bpf_dtab
;
117 extern int nbpfilter
;
119 IOFree((void *)bpf_dtab
, sizeof (struct bpf_d
) * nbpfilter
);