hdlc.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Generic HDLC support routines for Linux
  3. *
  4. * Copyright (C) 1999-2005 Krzysztof Halasa <khc@pm.waw.pl>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of version 2 of the GNU General Public License
  8. * as published by the Free Software Foundation.
  9. */
  10. #ifndef __HDLC_H
  11. #define __HDLC_H
  12. #define HDLC_MAX_MTU 1500 /* Ethernet 1500 bytes */
  13. #if 0
  14. #define HDLC_MAX_MRU (HDLC_MAX_MTU + 10 + 14 + 4) /* for ETH+VLAN over FR */
  15. #else
  16. #define HDLC_MAX_MRU 1600 /* as required for FR network */
  17. #endif
  18. #ifdef __KERNEL__
  19. #include <linux/skbuff.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/hdlc/ioctl.h>
  22. /* This structure is a private property of HDLC protocols.
  23. Hardware drivers have no interest here */
  24. struct hdlc_proto {
  25. int (*open)(struct net_device *dev);
  26. void (*close)(struct net_device *dev);
  27. void (*start)(struct net_device *dev); /* if open & DCD */
  28. void (*stop)(struct net_device *dev); /* if open & !DCD */
  29. void (*detach)(struct net_device *dev);
  30. int (*ioctl)(struct net_device *dev, struct ifreq *ifr);
  31. __be16 (*type_trans)(struct sk_buff *skb, struct net_device *dev);
  32. int (*netif_rx)(struct sk_buff *skb);
  33. netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
  34. struct module *module;
  35. struct hdlc_proto *next; /* next protocol in the list */
  36. };
  37. /* Pointed to by netdev_priv(dev) */
  38. typedef struct hdlc_device {
  39. /* used by HDLC layer to take control over HDLC device from hw driver*/
  40. int (*attach)(struct net_device *dev,
  41. unsigned short encoding, unsigned short parity);
  42. /* hardware driver must handle this instead of dev->hard_start_xmit */
  43. netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
  44. /* Things below are for HDLC layer internal use only */
  45. const struct hdlc_proto *proto;
  46. int carrier;
  47. int open;
  48. spinlock_t state_lock;
  49. void *state;
  50. void *priv;
  51. } hdlc_device;
  52. /* Exported from hdlc module */
  53. /* Called by hardware driver when a user requests HDLC service */
  54. int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
  55. /* Must be used by hardware driver on module startup/exit */
  56. #define register_hdlc_device(dev) register_netdev(dev)
  57. void unregister_hdlc_device(struct net_device *dev);
  58. void register_hdlc_protocol(struct hdlc_proto *proto);
  59. void unregister_hdlc_protocol(struct hdlc_proto *proto);
  60. struct net_device *alloc_hdlcdev(void *priv);
  61. static inline struct hdlc_device* dev_to_hdlc(struct net_device *dev)
  62. {
  63. return netdev_priv(dev);
  64. }
  65. static __inline__ void debug_frame(const struct sk_buff *skb)
  66. {
  67. int i;
  68. for (i=0; i < skb->len; i++) {
  69. if (i == 100) {
  70. printk("...\n");
  71. return;
  72. }
  73. printk(" %02X", skb->data[i]);
  74. }
  75. printk("\n");
  76. }
  77. /* Must be called by hardware driver when HDLC device is being opened */
  78. int hdlc_open(struct net_device *dev);
  79. /* Must be called by hardware driver when HDLC device is being closed */
  80. void hdlc_close(struct net_device *dev);
  81. /* May be used by hardware driver */
  82. int hdlc_change_mtu(struct net_device *dev, int new_mtu);
  83. /* Must be pointed to by hw driver's dev->netdev_ops->ndo_start_xmit */
  84. netdev_tx_t hdlc_start_xmit(struct sk_buff *skb, struct net_device *dev);
  85. int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
  86. size_t size);
  87. /* May be used by hardware driver to gain control over HDLC device */
  88. void detach_hdlc_protocol(struct net_device *dev);
  89. static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb,
  90. struct net_device *dev)
  91. {
  92. hdlc_device *hdlc = dev_to_hdlc(dev);
  93. skb->dev = dev;
  94. skb_reset_mac_header(skb);
  95. if (hdlc->proto->type_trans)
  96. return hdlc->proto->type_trans(skb, dev);
  97. else
  98. return htons(ETH_P_HDLC);
  99. }
  100. #endif /* __KERNEL */
  101. #endif /* __HDLC_H */