rose_out.c 2.6 KB

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