]> git.ozlabs.org Git - ppp.git/blob - solaris/ppp_mod.c
pppd man page: Update header to refer to pppd 2.5.x
[ppp.git] / solaris / ppp_mod.c
1 /*
2  * ppp_mod.c - modload support for PPP pseudo-device driver.
3  *
4  * Copyright (c) 1994 Paul Mackerras. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *
18  * 3. The name(s) of the authors of this software must not be used to
19  *    endorse or promote products derived from this software without
20  *    prior written permission.
21  *
22  * 4. Redistributions of any form whatsoever must retain the following
23  *    acknowledgment:
24  *    "This product includes software developed by Paul Mackerras
25  *     <paulus@samba.org>".
26  *
27  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
28  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
29  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
30  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
31  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
32  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
33  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
34  *
35  * $Id: ppp_mod.c,v 1.3 2004/01/17 05:47:55 carlsonj Exp $
36  */
37
38 /*
39  * This file is used under Solaris 2.
40  */
41
42 #include <sys/types.h>
43 #include <sys/param.h>
44 #include <sys/stat.h>
45 #include <sys/conf.h>
46 #include <sys/modctl.h>
47 #include <sys/sunddi.h>
48 #include <sys/ksynch.h>
49
50 static int ppp_identify(dev_info_t *);
51 static int ppp_attach(dev_info_t *, ddi_attach_cmd_t);
52 static int ppp_detach(dev_info_t *, ddi_detach_cmd_t);
53 static int ppp_devinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
54
55 extern struct streamtab pppinfo;
56 extern krwlock_t ppp_lower_lock;
57
58 static dev_info_t *ppp_dip;
59
60 static struct cb_ops cb_ppp_ops = {
61     nulldev, nulldev, nodev, nodev,     /* cb_open, ... */
62     nodev, nodev, nodev, nodev,         /* cb_dump, ... */
63     nodev, nodev, nodev, nochpoll,      /* cb_devmap, ... */
64     ddi_prop_op,                        /* cb_prop_op */
65     &pppinfo,                           /* cb_stream */
66     D_NEW|D_MP|D_MTQPAIR|D_MTOUTPERIM|D_MTOCEXCL        /* cb_flag */
67 };
68
69 static struct dev_ops ppp_ops = {
70     DEVO_REV,                           /* devo_rev */
71     0,                                  /* devo_refcnt */
72     ppp_devinfo,                        /* devo_getinfo */
73     ppp_identify,                       /* devo_identify */
74     nulldev,                            /* devo_probe */
75     ppp_attach,                         /* devo_attach */
76     ppp_detach,                         /* devo_detach */
77     nodev,                              /* devo_reset */
78     &cb_ppp_ops,                        /* devo_cb_ops */
79     NULL                                /* devo_bus_ops */
80 };
81
82 /*
83  * Module linkage information
84  */
85
86 static struct modldrv modldrv = {
87     &mod_driverops,                     /* says this is a pseudo driver */
88     "PPP-2.4.7 multiplexing driver",
89     &ppp_ops                            /* driver ops */
90 };
91
92 static struct modlinkage modlinkage = {
93     MODREV_1,
94     (void *) &modldrv,
95     NULL
96 };
97
98 int
99 _init(void)
100 {
101     return mod_install(&modlinkage);
102 }
103
104 int
105 _fini(void)
106 {
107     return mod_remove(&modlinkage);
108 }
109
110 int
111 _info(mip)
112     struct modinfo *mip;
113 {
114     return mod_info(&modlinkage, mip);
115 }
116
117 static int
118 ppp_identify(dip)
119     dev_info_t *dip;
120 {
121     /* This entry point is not used as of Solaris 10 */
122 #ifdef DDI_IDENTIFIED
123     return strcmp(ddi_get_name(dip), "ppp") == 0? DDI_IDENTIFIED:
124         DDI_NOT_IDENTIFIED;
125 #else
126     return 0;
127 #endif
128 }
129
130 static int
131 ppp_attach(dip, cmd)
132     dev_info_t *dip;
133     ddi_attach_cmd_t cmd;
134 {
135
136     if (cmd != DDI_ATTACH)
137         return DDI_FAILURE;
138     if (ddi_create_minor_node(dip, "ppp", S_IFCHR, 0, DDI_PSEUDO, CLONE_DEV)
139         == DDI_FAILURE) {
140         ddi_remove_minor_node(dip, NULL);
141         return DDI_FAILURE;
142     }
143     rw_init(&ppp_lower_lock, NULL, RW_DRIVER, NULL);
144     return DDI_SUCCESS;
145 }
146
147 static int
148 ppp_detach(dip, cmd)
149     dev_info_t *dip;
150     ddi_detach_cmd_t cmd;
151 {
152     rw_destroy(&ppp_lower_lock);
153     ddi_remove_minor_node(dip, NULL);
154     return DDI_SUCCESS;
155 }
156
157 static int
158 ppp_devinfo(dip, cmd, arg, result)
159     dev_info_t *dip;
160     ddi_info_cmd_t cmd;
161     void *arg;
162     void **result;
163 {
164     int error;
165
166     error = DDI_SUCCESS;
167     switch (cmd) {
168     case DDI_INFO_DEVT2DEVINFO:
169         if (ppp_dip == NULL)
170             error = DDI_FAILURE;
171         else
172             *result = (void *) ppp_dip;
173         break;
174     case DDI_INFO_DEVT2INSTANCE:
175         *result = NULL;
176         break;
177     default:
178         error = DDI_FAILURE;
179     }
180     return error;
181 }