hdlc_ppp.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Generic HDLC support routines for Linux
  3. * Point-to-point protocol support
  4. *
  5. * Copyright (C) 1999 - 2003 Krzysztof Halasa <khc@pm.waw.pl>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of version 2 of the GNU General Public License
  9. * as published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/slab.h>
  14. #include <linux/poll.h>
  15. #include <linux/errno.h>
  16. #include <linux/if_arp.h>
  17. #include <linux/init.h>
  18. #include <linux/skbuff.h>
  19. #include <linux/pkt_sched.h>
  20. #include <linux/inetdevice.h>
  21. #include <linux/lapb.h>
  22. #include <linux/rtnetlink.h>
  23. #include <linux/hdlc.h>
  24. static int ppp_open(struct net_device *dev)
  25. {
  26. hdlc_device *hdlc = dev_to_hdlc(dev);
  27. void *old_ioctl;
  28. int result;
  29. dev->priv = &hdlc->state.ppp.syncppp_ptr;
  30. hdlc->state.ppp.syncppp_ptr = &hdlc->state.ppp.pppdev;
  31. hdlc->state.ppp.pppdev.dev = dev;
  32. old_ioctl = dev->do_ioctl;
  33. hdlc->state.ppp.old_change_mtu = dev->change_mtu;
  34. sppp_attach(&hdlc->state.ppp.pppdev);
  35. /* sppp_attach nukes them. We don't need syncppp's ioctl */
  36. dev->do_ioctl = old_ioctl;
  37. hdlc->state.ppp.pppdev.sppp.pp_flags &= ~PP_CISCO;
  38. dev->type = ARPHRD_PPP;
  39. result = sppp_open(dev);
  40. if (result) {
  41. sppp_detach(dev);
  42. return result;
  43. }
  44. return 0;
  45. }
  46. static void ppp_close(struct net_device *dev)
  47. {
  48. hdlc_device *hdlc = dev_to_hdlc(dev);
  49. sppp_close(dev);
  50. sppp_detach(dev);
  51. dev->rebuild_header = NULL;
  52. dev->change_mtu = hdlc->state.ppp.old_change_mtu;
  53. dev->mtu = HDLC_MAX_MTU;
  54. dev->hard_header_len = 16;
  55. }
  56. static __be16 ppp_type_trans(struct sk_buff *skb, struct net_device *dev)
  57. {
  58. return __constant_htons(ETH_P_WAN_PPP);
  59. }
  60. int hdlc_ppp_ioctl(struct net_device *dev, struct ifreq *ifr)
  61. {
  62. hdlc_device *hdlc = dev_to_hdlc(dev);
  63. int result;
  64. switch (ifr->ifr_settings.type) {
  65. case IF_GET_PROTO:
  66. ifr->ifr_settings.type = IF_PROTO_PPP;
  67. return 0; /* return protocol only, no settable parameters */
  68. case IF_PROTO_PPP:
  69. if(!capable(CAP_NET_ADMIN))
  70. return -EPERM;
  71. if(dev->flags & IFF_UP)
  72. return -EBUSY;
  73. /* no settable parameters */
  74. result=hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT);
  75. if (result)
  76. return result;
  77. hdlc_proto_detach(hdlc);
  78. memset(&hdlc->proto, 0, sizeof(hdlc->proto));
  79. hdlc->proto.open = ppp_open;
  80. hdlc->proto.close = ppp_close;
  81. hdlc->proto.type_trans = ppp_type_trans;
  82. hdlc->proto.id = IF_PROTO_PPP;
  83. dev->hard_start_xmit = hdlc->xmit;
  84. dev->hard_header = NULL;
  85. dev->type = ARPHRD_PPP;
  86. dev->addr_len = 0;
  87. return 0;
  88. }
  89. return -EINVAL;
  90. }