ax25_std_subr.c 2.3 KB

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