isdn_net.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* $Id: isdn_net.h,v 1.1.2.2 2004/01/12 22:37:19 keil Exp $
  2. *
  3. * header for Linux ISDN subsystem, network related functions (linklevel).
  4. *
  5. * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
  6. * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
  7. * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. *
  12. */
  13. /* Definitions for hupflags: */
  14. #define ISDN_WAITCHARGE 1 /* did not get a charge info yet */
  15. #define ISDN_HAVECHARGE 2 /* We know a charge info */
  16. #define ISDN_CHARGEHUP 4 /* We want to use the charge mechanism */
  17. #define ISDN_INHUP 8 /* Even if incoming, close after huptimeout */
  18. #define ISDN_MANCHARGE 16 /* Charge Interval manually set */
  19. /*
  20. * Definitions for Cisco-HDLC header.
  21. */
  22. #define CISCO_ADDR_UNICAST 0x0f
  23. #define CISCO_ADDR_BROADCAST 0x8f
  24. #define CISCO_CTRL 0x00
  25. #define CISCO_TYPE_CDP 0x2000
  26. #define CISCO_TYPE_SLARP 0x8035
  27. #define CISCO_SLARP_REQUEST 0
  28. #define CISCO_SLARP_REPLY 1
  29. #define CISCO_SLARP_KEEPALIVE 2
  30. extern char *isdn_net_new(char *, struct net_device *);
  31. extern char *isdn_net_newslave(char *);
  32. extern int isdn_net_rm(char *);
  33. extern int isdn_net_rmall(void);
  34. extern int isdn_net_stat_callback(int, isdn_ctrl *);
  35. extern int isdn_net_setcfg(isdn_net_ioctl_cfg *);
  36. extern int isdn_net_getcfg(isdn_net_ioctl_cfg *);
  37. extern int isdn_net_addphone(isdn_net_ioctl_phone *);
  38. extern int isdn_net_getphones(isdn_net_ioctl_phone *, char __user *);
  39. extern int isdn_net_getpeer(isdn_net_ioctl_phone *, isdn_net_ioctl_phone __user *);
  40. extern int isdn_net_delphone(isdn_net_ioctl_phone *);
  41. extern int isdn_net_find_icall(int, int, int, setup_parm *);
  42. extern void isdn_net_hangup(struct net_device *);
  43. extern void isdn_net_dial(void);
  44. extern void isdn_net_autohup(void);
  45. extern int isdn_net_force_hangup(char *);
  46. extern int isdn_net_force_dial(char *);
  47. extern isdn_net_dev *isdn_net_findif(char *);
  48. extern int isdn_net_rcv_skb(int, struct sk_buff *);
  49. extern int isdn_net_dial_req(isdn_net_local *);
  50. extern void isdn_net_writebuf_skb(isdn_net_local *lp, struct sk_buff *skb);
  51. extern void isdn_net_write_super(isdn_net_local *lp, struct sk_buff *skb);
  52. #define ISDN_NET_MAX_QUEUE_LENGTH 2
  53. /*
  54. * is this particular channel busy?
  55. */
  56. static __inline__ int isdn_net_lp_busy(isdn_net_local *lp)
  57. {
  58. if (atomic_read(&lp->frame_cnt) < ISDN_NET_MAX_QUEUE_LENGTH)
  59. return 0;
  60. else
  61. return 1;
  62. }
  63. /*
  64. * For the given net device, this will get a non-busy channel out of the
  65. * corresponding bundle. The returned channel is locked.
  66. */
  67. static __inline__ isdn_net_local * isdn_net_get_locked_lp(isdn_net_dev *nd)
  68. {
  69. unsigned long flags;
  70. isdn_net_local *lp;
  71. spin_lock_irqsave(&nd->queue_lock, flags);
  72. lp = nd->queue; /* get lp on top of queue */
  73. spin_lock(&nd->queue->xmit_lock);
  74. while (isdn_net_lp_busy(nd->queue)) {
  75. spin_unlock(&nd->queue->xmit_lock);
  76. nd->queue = nd->queue->next;
  77. if (nd->queue == lp) { /* not found -- should never happen */
  78. lp = NULL;
  79. goto errout;
  80. }
  81. spin_lock(&nd->queue->xmit_lock);
  82. }
  83. lp = nd->queue;
  84. nd->queue = nd->queue->next;
  85. local_bh_disable();
  86. errout:
  87. spin_unlock_irqrestore(&nd->queue_lock, flags);
  88. return lp;
  89. }
  90. /*
  91. * add a channel to a bundle
  92. */
  93. static __inline__ void isdn_net_add_to_bundle(isdn_net_dev *nd, isdn_net_local *nlp)
  94. {
  95. isdn_net_local *lp;
  96. unsigned long flags;
  97. spin_lock_irqsave(&nd->queue_lock, flags);
  98. lp = nd->queue;
  99. // printk(KERN_DEBUG "%s: lp:%s(%p) nlp:%s(%p) last(%p)\n",
  100. // __func__, lp->name, lp, nlp->name, nlp, lp->last);
  101. nlp->last = lp->last;
  102. lp->last->next = nlp;
  103. lp->last = nlp;
  104. nlp->next = lp;
  105. nd->queue = nlp;
  106. spin_unlock_irqrestore(&nd->queue_lock, flags);
  107. }
  108. /*
  109. * remove a channel from the bundle it belongs to
  110. */
  111. static __inline__ void isdn_net_rm_from_bundle(isdn_net_local *lp)
  112. {
  113. isdn_net_local *master_lp = lp;
  114. unsigned long flags;
  115. if (lp->master)
  116. master_lp = (isdn_net_local *) lp->master->priv;
  117. // printk(KERN_DEBUG "%s: lp:%s(%p) mlp:%s(%p) last(%p) next(%p) mndq(%p)\n",
  118. // __func__, lp->name, lp, master_lp->name, master_lp, lp->last, lp->next, master_lp->netdev->queue);
  119. spin_lock_irqsave(&master_lp->netdev->queue_lock, flags);
  120. lp->last->next = lp->next;
  121. lp->next->last = lp->last;
  122. if (master_lp->netdev->queue == lp) {
  123. master_lp->netdev->queue = lp->next;
  124. if (lp->next == lp) { /* last in queue */
  125. master_lp->netdev->queue = master_lp->netdev->local;
  126. }
  127. }
  128. lp->next = lp->last = lp; /* (re)set own pointers */
  129. // printk(KERN_DEBUG "%s: mndq(%p)\n",
  130. // __func__, master_lp->netdev->queue);
  131. spin_unlock_irqrestore(&master_lp->netdev->queue_lock, flags);
  132. }
  133. static inline int
  134. put_u8(unsigned char *p, u8 x)
  135. {
  136. *p = x;
  137. return 1;
  138. }
  139. static inline int
  140. put_u16(unsigned char *p, u16 x)
  141. {
  142. *((u16 *)p) = htons(x);
  143. return 2;
  144. }
  145. static inline int
  146. put_u32(unsigned char *p, u32 x)
  147. {
  148. *((u32 *)p) = htonl(x);
  149. return 4;
  150. }
  151. static inline int
  152. get_u8(unsigned char *p, u8 *x)
  153. {
  154. *x = *p;
  155. return 1;
  156. }
  157. static inline int
  158. get_u16(unsigned char *p, u16 *x)
  159. {
  160. *x = ntohs(*((u16 *)p));
  161. return 2;
  162. }
  163. static inline int
  164. get_u32(unsigned char *p, u32 *x)
  165. {
  166. *x = ntohl(*((u32 *)p));
  167. return 4;
  168. }