ppp_mod.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. * This file is used under Solaris 2.
  39. */
  40. #include <sys/types.h>
  41. #include <sys/param.h>
  42. #include <sys/stat.h>
  43. #include <sys/conf.h>
  44. #include <sys/modctl.h>
  45. #include <sys/sunddi.h>
  46. #include <sys/ksynch.h>
  47. #ifdef __STDC__
  48. #define __P(x) x
  49. #else
  50. #define __P(x) ()
  51. #endif
  52. static int ppp_identify __P((dev_info_t *));
  53. static int ppp_attach __P((dev_info_t *, ddi_attach_cmd_t));
  54. static int ppp_detach __P((dev_info_t *, ddi_detach_cmd_t));
  55. static int ppp_devinfo __P((dev_info_t *, ddi_info_cmd_t, void *, void **));
  56. extern struct streamtab pppinfo;
  57. extern krwlock_t ppp_lower_lock;
  58. static dev_info_t *ppp_dip;
  59. static struct cb_ops cb_ppp_ops = {
  60. nulldev, nulldev, nodev, nodev, /* cb_open, ... */
  61. nodev, nodev, nodev, nodev, /* cb_dump, ... */
  62. nodev, nodev, nodev, nochpoll, /* cb_devmap, ... */
  63. ddi_prop_op, /* cb_prop_op */
  64. &pppinfo, /* cb_stream */
  65. D_NEW|D_MP|D_MTQPAIR|D_MTOUTPERIM|D_MTOCEXCL /* cb_flag */
  66. };
  67. static struct dev_ops ppp_ops = {
  68. DEVO_REV, /* devo_rev */
  69. 0, /* devo_refcnt */
  70. ppp_devinfo, /* devo_getinfo */
  71. ppp_identify, /* devo_identify */
  72. nulldev, /* devo_probe */
  73. ppp_attach, /* devo_attach */
  74. ppp_detach, /* devo_detach */
  75. nodev, /* devo_reset */
  76. &cb_ppp_ops, /* devo_cb_ops */
  77. NULL /* devo_bus_ops */
  78. };
  79. /*
  80. * Module linkage information
  81. */
  82. static struct modldrv modldrv = {
  83. &mod_driverops, /* says this is a pseudo driver */
  84. "PPP-2.4.7 multiplexing driver",
  85. &ppp_ops /* driver ops */
  86. };
  87. static struct modlinkage modlinkage = {
  88. MODREV_1,
  89. (void *) &modldrv,
  90. NULL
  91. };
  92. int
  93. _init(void)
  94. {
  95. return mod_install(&modlinkage);
  96. }
  97. int
  98. _fini(void)
  99. {
  100. return mod_remove(&modlinkage);
  101. }
  102. int
  103. _info(mip)
  104. struct modinfo *mip;
  105. {
  106. return mod_info(&modlinkage, mip);
  107. }
  108. static int
  109. ppp_identify(dip)
  110. dev_info_t *dip;
  111. {
  112. /* This entry point is not used as of Solaris 10 */
  113. #ifdef DDI_IDENTIFIED
  114. return strcmp(ddi_get_name(dip), "ppp") == 0? DDI_IDENTIFIED:
  115. DDI_NOT_IDENTIFIED;
  116. #else
  117. return 0;
  118. #endif
  119. }
  120. static int
  121. ppp_attach(dip, cmd)
  122. dev_info_t *dip;
  123. ddi_attach_cmd_t cmd;
  124. {
  125. if (cmd != DDI_ATTACH)
  126. return DDI_FAILURE;
  127. if (ddi_create_minor_node(dip, "ppp", S_IFCHR, 0, DDI_PSEUDO, CLONE_DEV)
  128. == DDI_FAILURE) {
  129. ddi_remove_minor_node(dip, NULL);
  130. return DDI_FAILURE;
  131. }
  132. rw_init(&ppp_lower_lock, NULL, RW_DRIVER, NULL);
  133. return DDI_SUCCESS;
  134. }
  135. static int
  136. ppp_detach(dip, cmd)
  137. dev_info_t *dip;
  138. ddi_detach_cmd_t cmd;
  139. {
  140. rw_destroy(&ppp_lower_lock);
  141. ddi_remove_minor_node(dip, NULL);
  142. return DDI_SUCCESS;
  143. }
  144. static int
  145. ppp_devinfo(dip, cmd, arg, result)
  146. dev_info_t *dip;
  147. ddi_info_cmd_t cmd;
  148. void *arg;
  149. void **result;
  150. {
  151. int error;
  152. error = DDI_SUCCESS;
  153. switch (cmd) {
  154. case DDI_INFO_DEVT2DEVINFO:
  155. if (ppp_dip == NULL)
  156. error = DDI_FAILURE;
  157. else
  158. *result = (void *) ppp_dip;
  159. break;
  160. case DDI_INFO_DEVT2INSTANCE:
  161. *result = NULL;
  162. break;
  163. default:
  164. error = DDI_FAILURE;
  165. }
  166. return error;
  167. }