ax25_std_subr.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
  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 <net/ax25.h>
  16. #include <linux/inet.h>
  17. #include <linux/netdevice.h>
  18. #include <linux/skbuff.h>
  19. #include <net/sock.h>
  20. #include <linux/uaccess.h>
  21. #include <linux/fcntl.h>
  22. #include <linux/mm.h>
  23. #include <linux/interrupt.h>
  24. /*
  25. * The following routines are taken from page 170 of the 7th ARRL Computer
  26. * Networking Conference paper, as is the whole state machine.
  27. */
  28. void ax25_std_nr_error_recovery(ax25_cb *ax25)
  29. {
  30. ax25_std_establish_data_link(ax25);
  31. }
  32. void ax25_std_establish_data_link(ax25_cb *ax25)
  33. {
  34. ax25->condition = 0x00;
  35. ax25->n2count = 0;
  36. if (ax25->modulus == AX25_MODULUS)
  37. ax25_send_control(ax25, AX25_SABM, AX25_POLLON, AX25_COMMAND);
  38. else
  39. ax25_send_control(ax25, AX25_SABME, AX25_POLLON, AX25_COMMAND);
  40. ax25_calculate_t1(ax25);
  41. ax25_stop_idletimer(ax25);
  42. ax25_stop_t3timer(ax25);
  43. ax25_stop_t2timer(ax25);
  44. ax25_start_t1timer(ax25);
  45. }
  46. void ax25_std_transmit_enquiry(ax25_cb *ax25)
  47. {
  48. if (ax25->condition & AX25_COND_OWN_RX_BUSY)
  49. ax25_send_control(ax25, AX25_RNR, AX25_POLLON, AX25_COMMAND);
  50. else
  51. ax25_send_control(ax25, AX25_RR, AX25_POLLON, AX25_COMMAND);
  52. ax25->condition &= ~AX25_COND_ACK_PENDING;
  53. ax25_calculate_t1(ax25);
  54. ax25_start_t1timer(ax25);
  55. }
  56. void ax25_std_enquiry_response(ax25_cb *ax25)
  57. {
  58. if (ax25->condition & AX25_COND_OWN_RX_BUSY)
  59. ax25_send_control(ax25, AX25_RNR, AX25_POLLON, AX25_RESPONSE);
  60. else
  61. ax25_send_control(ax25, AX25_RR, AX25_POLLON, AX25_RESPONSE);
  62. ax25->condition &= ~AX25_COND_ACK_PENDING;
  63. }
  64. void ax25_std_timeout_response(ax25_cb *ax25)
  65. {
  66. if (ax25->condition & AX25_COND_OWN_RX_BUSY)
  67. ax25_send_control(ax25, AX25_RNR, AX25_POLLOFF, AX25_RESPONSE);
  68. else
  69. ax25_send_control(ax25, AX25_RR, AX25_POLLOFF, AX25_RESPONSE);
  70. ax25->condition &= ~AX25_COND_ACK_PENDING;
  71. }