1/*
2 * Copyright (c) 1998-2011 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23#ifndef _IONETWORKSTACK_H
24#define _IONETWORKSTACK_H
25
26// User-client keys
27//
28#define kIONetworkStackUserCommandKey   "IONetworkStackUserCommand"
29#define kIONetworkStackUserCommand      "IONetworkStackUserCommand"
30
31enum {
32    kIONetworkStackRegisterInterfaceWithUnit        = 0,
33    kIONetworkStackRegisterInterfaceWithLowestUnit  = 1,
34    kIONetworkStackRegisterInterfaceAll             = 2
35};
36
37#ifdef KERNEL
38
39class IONetworkInterface;
40
41class IONetworkStack : public IOService
42{
43    OSDeclareFinalStructors( IONetworkStack )
44
45protected:
46    OSSet *             _ifListNaming;
47    OSArray *           _ifListDetach;
48    OSArray *           _ifListAttach;
49    OSDictionary *      _ifPrefixDict;
50    IONotifier *        _ifNotifier;
51    IOLock *            _stateLock;
52    thread_call_t       _asyncThread;
53    const OSSymbol *    _noBSDAttachSymbol;
54
55    static SInt32       orderNetworkInterfaces(
56                            const OSMetaClassBase * obj1,
57                            const OSMetaClassBase * obj2,
58                            void *                  ref );
59
60    virtual void        free( void );
61
62    bool                interfacePublished(
63                            void *          refCon,
64                            IOService *     service,
65                            IONotifier *    notifier );
66
67    void                asyncWork( void );
68
69    bool                insertNetworkInterface(
70                            IONetworkInterface * netif );
71
72    void                removeNetworkInterface(
73                            IONetworkInterface * netif );
74
75    uint32_t            getNextAvailableUnitNumber(
76                            const char *         name,
77                            uint32_t             startingUnit );
78
79    bool                reserveInterfaceUnitNumber(
80                            IONetworkInterface * netif,
81                            uint32_t             unit,
82                            bool                 isUnitFixed,
83                            bool *               attachToBSD );
84
85    IOReturn            attachNetworkInterfaceToBSD(
86                            IONetworkInterface * netif );
87
88    IOReturn            registerAllNetworkInterfaces( void );
89
90    IOReturn            registerNetworkInterface(
91                            IONetworkInterface * netif,
92                            uint32_t             unit,
93                            bool                 isUnitFixed );
94
95public:
96    virtual bool        start( IOService * provider );
97    virtual bool        didTerminate( IOService *, IOOptionBits, bool * );
98    virtual IOReturn    setProperties( OSObject * properties );
99};
100
101#endif /* KERNEL */
102#endif /* !_IONETWORKSTACK_H */
103