rose_out.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
  8. */
  9. #include <linux/errno.h>
  10. #include <linux/types.h>
  11. #include <linux/socket.h>
  12. #include <linux/in.h>
  13. #include <linux/kernel.h>
  14. #include <linux/timer.h>
  15. #include <linux/string.h>
  16. #include <linux/sockios.h>
  17. #include <linux/net.h>
  18. #include <linux/gfp.h>
  19. #include <net/ax25.h>
  20. #include <linux/inet.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/skbuff.h>
  23. #include <net/sock.h>
  24. #include <asm/system.h>
  25. #include <linux/fcntl.h>
  26. #include <linux/mm.h>
  27. #include <linux/interrupt.h>
  28. #include <net/rose.h>
  29. /*
  30. * This procedure is passed a buffer descriptor for an iframe. It builds
  31. * the rest of the control part of the frame and then writes it out.
  32. */
  33. static void rose_send_iframe(struct sock *sk, struct sk_buff *skb)
  34. {
  35. struct rose_sock *rose = rose_sk(sk);
  36. if (skb == NULL)
  37. return;
  38. skb->data[2] |= (rose->vr << 5) & 0xE0;
  39. skb->data[2] |= (rose->vs << 1) & 0x0E;
  40. rose_start_idletimer(sk);
  41. rose_transmit_link(skb, rose->neighbour);
  42. }
  43. void rose_kick(struct sock *sk)
  44. {
  45. struct rose_sock *rose = rose_sk(sk);
  46. struct sk_buff *skb, *skbn;
  47. unsigned short start, end;
  48. if (rose->state != ROSE_STATE_3)
  49. return;
  50. if (rose->condition & ROSE_COND_PEER_RX_BUSY)
  51. return;
  52. if (!skb_peek(&sk->sk_write_queue))
  53. return;
  54. start = (skb_peek(&rose->ack_queue) == NULL) ? rose->va : rose->vs;
  55. end = (rose->va + sysctl_rose_window_size) % ROSE_MODULUS;
  56. if (start == end)
  57. return;
  58. rose->vs = start;
  59. /*
  60. * Transmit data until either we're out of data to send or
  61. * the window is full.
  62. */
  63. skb = skb_dequeue(&sk->sk_write_queue);
  64. do {
  65. if ((skbn = skb_clone(skb, GFP_ATOMIC)) == NULL) {
  66. skb_queue_head(&sk->sk_write_queue, skb);
  67. break;
  68. }
  69. skb_set_owner_w(skbn, sk);
  70. /*
  71. * Transmit the frame copy.
  72. */
  73. rose_send_iframe(sk, skbn);
  74. rose->vs = (rose->vs + 1) % ROSE_MODULUS;
  75. /*
  76. * Requeue the original data frame.
  77. */
  78. skb_queue_tail(&rose->ack_queue, skb);
  79. } while (rose->vs != end &&
  80. (skb = skb_dequeue(&sk->sk_write_queue)) != NULL);
  81. rose->vl = rose->vr;
  82. rose->condition &= ~ROSE_COND_ACK_PENDING;
  83. rose_stop_timer(sk);
  84. }
  85. /*
  86. * The following routines are taken from page 170 of the 7th ARRL Computer
  87. * Networking Conference paper, as is the whole state machine.
  88. */
  89. void rose_enquiry_response(struct sock *sk)
  90. {
  91. struct rose_sock *rose = rose_sk(sk);
  92. if (rose->condition & ROSE_COND_OWN_RX_BUSY)
  93. rose_write_internal(sk, ROSE_RNR);
  94. else
  95. rose_write_internal(sk, ROSE_RR);
  96. rose->vl = rose->vr;
  97. rose->condition &= ~ROSE_COND_ACK_PENDING;
  98. rose_stop_timer(sk);
  99. }