hdlc.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. struct module *module;
  34. struct hdlc_proto *next; /* next protocol in the list */
  35. };
  36. /* Pointed to by netdev_priv(dev) */
  37. typedef struct hdlc_device {
  38. /* used by HDLC layer to take control over HDLC device from hw driver*/
  39. int (*attach)(struct net_device *dev,
  40. unsigned short encoding, unsigned short parity);
  41. /* hardware driver must handle this instead of dev->hard_start_xmit */
  42. int (*xmit)(struct sk_buff *skb, struct net_device *dev);
  43. /* Things below are for HDLC layer internal use only */
  44. const struct hdlc_proto *proto;
  45. int carrier;
  46. int open;
  47. spinlock_t state_lock;
  48. void *state;
  49. void *priv;
  50. }hdlc_device;
  51. /* Exported from hdlc module */
  52. /* Called by hardware driver when a user requests HDLC service */
  53. int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
  54. /* Must be used by hardware driver on module startup/exit */
  55. #define register_hdlc_device(dev) register_netdev(dev)
  56. void unregister_hdlc_device(struct net_device *dev);
  57. void register_hdlc_protocol(struct hdlc_proto *proto);
  58. void unregister_hdlc_protocol(struct hdlc_proto *proto);
  59. struct net_device *alloc_hdlcdev(void *priv);
  60. static inline struct hdlc_device* dev_to_hdlc(struct net_device *dev)
  61. {
  62. return netdev_priv(dev);
  63. }
  64. static __inline__ void debug_frame(const struct sk_buff *skb)
  65. {
  66. int i;
  67. for (i=0; i < skb->len; i++) {
  68. if (i == 100) {
  69. printk("...\n");
  70. return;
  71. }
  72. printk(" %02X", skb->data[i]);
  73. }
  74. printk("\n");
  75. }
  76. /* Must be called by hardware driver when HDLC device is being opened */
  77. int hdlc_open(struct net_device *dev);
  78. /* Must be called by hardware driver when HDLC device is being closed */
  79. void hdlc_close(struct net_device *dev);
  80. int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
  81. size_t size);
  82. /* May be used by hardware driver to gain control over HDLC device */
  83. void detach_hdlc_protocol(struct net_device *dev);
  84. static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb,
  85. struct net_device *dev)
  86. {
  87. hdlc_device *hdlc = dev_to_hdlc(dev);
  88. skb->dev = dev;
  89. skb_reset_mac_header(skb);
  90. if (hdlc->proto->type_trans)
  91. return hdlc->proto->type_trans(skb, dev);
  92. else
  93. return htons(ETH_P_HDLC);
  94. }
  95. #endif /* __KERNEL */
  96. #endif /* __HDLC_H */