hdlc.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #include <linux/skbuff.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/hdlc/ioctl.h>
  15. #include <uapi/linux/hdlc.h>
  16. /* This structure is a private property of HDLC protocols.
  17. Hardware drivers have no interest here */
  18. struct hdlc_proto {
  19. int (*open)(struct net_device *dev);
  20. void (*close)(struct net_device *dev);
  21. void (*start)(struct net_device *dev); /* if open & DCD */
  22. void (*stop)(struct net_device *dev); /* if open & !DCD */
  23. void (*detach)(struct net_device *dev);
  24. int (*ioctl)(struct net_device *dev, struct ifreq *ifr);
  25. __be16 (*type_trans)(struct sk_buff *skb, struct net_device *dev);
  26. int (*netif_rx)(struct sk_buff *skb);
  27. netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
  28. struct module *module;
  29. struct hdlc_proto *next; /* next protocol in the list */
  30. };
  31. /* Pointed to by netdev_priv(dev) */
  32. typedef struct hdlc_device {
  33. /* used by HDLC layer to take control over HDLC device from hw driver*/
  34. int (*attach)(struct net_device *dev,
  35. unsigned short encoding, unsigned short parity);
  36. /* hardware driver must handle this instead of dev->hard_start_xmit */
  37. netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
  38. /* Things below are for HDLC layer internal use only */
  39. const struct hdlc_proto *proto;
  40. int carrier;
  41. int open;
  42. spinlock_t state_lock;
  43. void *state;
  44. void *priv;
  45. } hdlc_device;
  46. /* Exported from hdlc module */
  47. /* Called by hardware driver when a user requests HDLC service */
  48. int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
  49. /* Must be used by hardware driver on module startup/exit */
  50. #define register_hdlc_device(dev) register_netdev(dev)
  51. void unregister_hdlc_device(struct net_device *dev);
  52. void register_hdlc_protocol(struct hdlc_proto *proto);
  53. void unregister_hdlc_protocol(struct hdlc_proto *proto);
  54. struct net_device *alloc_hdlcdev(void *priv);
  55. static inline struct hdlc_device* dev_to_hdlc(struct net_device *dev)
  56. {
  57. return netdev_priv(dev);
  58. }
  59. static __inline__ void debug_frame(const struct sk_buff *skb)
  60. {
  61. int i;
  62. for (i=0; i < skb->len; i++) {
  63. if (i == 100) {
  64. printk("...\n");
  65. return;
  66. }
  67. printk(" %02X", skb->data[i]);
  68. }
  69. printk("\n");
  70. }
  71. /* Must be called by hardware driver when HDLC device is being opened */
  72. int hdlc_open(struct net_device *dev);
  73. /* Must be called by hardware driver when HDLC device is being closed */
  74. void hdlc_close(struct net_device *dev);
  75. /* May be used by hardware driver */
  76. int hdlc_change_mtu(struct net_device *dev, int new_mtu);
  77. /* Must be pointed to by hw driver's dev->netdev_ops->ndo_start_xmit */
  78. netdev_tx_t hdlc_start_xmit(struct sk_buff *skb, struct net_device *dev);
  79. int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
  80. size_t size);
  81. /* May be used by hardware driver to gain control over HDLC device */
  82. void detach_hdlc_protocol(struct net_device *dev);
  83. static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb,
  84. struct net_device *dev)
  85. {
  86. hdlc_device *hdlc = dev_to_hdlc(dev);
  87. skb->dev = dev;
  88. skb_reset_mac_header(skb);
  89. if (hdlc->proto->type_trans)
  90. return hdlc->proto->type_trans(skb, dev);
  91. else
  92. return htons(ETH_P_HDLC);
  93. }
  94. #endif /* __HDLC_H */