ax25_std_subr.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * AX.25 release 037
  3.  *
  4.  * This code REQUIRES 2.1.15 or higher/ NET3.038
  5.  *
  6.  * This module:
  7.  * This module is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU General Public License
  9.  * as published by the Free Software Foundation; either version
  10.  * 2 of the License, or (at your option) any later version.
  11.  *
  12.  * Most of this code is based on the SDL diagrams published in the 7th
  13.  * ARRL Computer Networking Conference papers. The diagrams have mistakes
  14.  * in them, but are mostly correct. Before you modify the code could you
  15.  * read the SDL diagrams as the code is not obvious and probably very
  16.  * easy to break;
  17.  *
  18.  * History
  19.  * AX.25 036 Jonathan(G4KLX) Split from ax25_out.c.
  20.  * AX.25 037 Jonathan(G4KLX) New timer architecture.
  21.  */
  22. #include <linux/errno.h>
  23. #include <linux/types.h>
  24. #include <linux/socket.h>
  25. #include <linux/in.h>
  26. #include <linux/kernel.h>
  27. #include <linux/sched.h>
  28. #include <linux/timer.h>
  29. #include <linux/string.h>
  30. #include <linux/sockios.h>
  31. #include <linux/net.h>
  32. #include <net/ax25.h>
  33. #include <linux/inet.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/skbuff.h>
  36. #include <net/sock.h>
  37. #include <asm/uaccess.h>
  38. #include <asm/system.h>
  39. #include <linux/fcntl.h>
  40. #include <linux/mm.h>
  41. #include <linux/interrupt.h>
  42. /*
  43.  * The following routines are taken from page 170 of the 7th ARRL Computer
  44.  * Networking Conference paper, as is the whole state machine.
  45.  */
  46. void ax25_std_nr_error_recovery(ax25_cb *ax25)
  47. {
  48. ax25_std_establish_data_link(ax25);
  49. }
  50. void ax25_std_establish_data_link(ax25_cb *ax25)
  51. {
  52. ax25->condition = 0x00;
  53. ax25->n2count   = 0;
  54. if (ax25->modulus == AX25_MODULUS)
  55. ax25_send_control(ax25, AX25_SABM, AX25_POLLON, AX25_COMMAND);
  56. else
  57. ax25_send_control(ax25, AX25_SABME, AX25_POLLON, AX25_COMMAND);
  58. ax25_calculate_t1(ax25);
  59. ax25_stop_idletimer(ax25);
  60. ax25_stop_t3timer(ax25);
  61. ax25_stop_t2timer(ax25);
  62. ax25_start_t1timer(ax25);
  63. }
  64. void ax25_std_transmit_enquiry(ax25_cb *ax25)
  65. {
  66. if (ax25->condition & AX25_COND_OWN_RX_BUSY)
  67. ax25_send_control(ax25, AX25_RNR, AX25_POLLON, AX25_COMMAND);
  68. else
  69. ax25_send_control(ax25, AX25_RR, AX25_POLLON, AX25_COMMAND);
  70. ax25->condition &= ~AX25_COND_ACK_PENDING;
  71. ax25_calculate_t1(ax25);
  72. ax25_start_t1timer(ax25);
  73. }
  74.  
  75. void ax25_std_enquiry_response(ax25_cb *ax25)
  76. {
  77. if (ax25->condition & AX25_COND_OWN_RX_BUSY)
  78. ax25_send_control(ax25, AX25_RNR, AX25_POLLON, AX25_RESPONSE);
  79. else
  80. ax25_send_control(ax25, AX25_RR, AX25_POLLON, AX25_RESPONSE);
  81. ax25->condition &= ~AX25_COND_ACK_PENDING;
  82. }
  83. void ax25_std_timeout_response(ax25_cb *ax25)
  84. {
  85. if (ax25->condition & AX25_COND_OWN_RX_BUSY)
  86. ax25_send_control(ax25, AX25_RNR, AX25_POLLOFF, AX25_RESPONSE);
  87. else
  88. ax25_send_control(ax25, AX25_RR, AX25_POLLOFF, AX25_RESPONSE);
  89. ax25->condition &= ~AX25_COND_ACK_PENDING;
  90. }