1. //#include<tcp.c>
2. #include<ppp.h>
3. #include <string.h>
4. #include <absacc.h>
5.
6. /////////////////////////////////////////////////////////////
7. //
8. //Function: PPP_FCS_16(fcs,cp,len)
9. //
10. //Description: TO calculate FCS check
11. //
12. //Arguments: RFC1662;sending
13. //
14. //Returns: FCS,result of checking
15. //
16. /////////////////////////////////////////////////////////////
17. uint PPP_FCS_16(fcs,source,len)
18. uint xdata fcs;
19. uchar xdata *source;
20. uint xdata len;
21. {
22. while (len!=0)
23. {
24. len--;
25. fcs = (fcs>>8)^fcstab[(fcs^*source++)&0xff];
26. }
27. return(fcs);
28.
29. }
30. ///////////////////////////////////////////////////////////////
31. //
32. //Function: TRY_FCS_16(cp,len)
33. //
34. //Description: TO calculate crc check,
35. //
36. //Arguments: RFC1662;sending
37. //
38. //Returns: CRC,result of checking
39. //
40. ///////////////////////////////////////////////////////////////
41.
42. uint TRY_FCS_16(source,len)
43. uchar xdata *source;
44. uint xdata len;
45.
46. {
47. uint data trialfcs;
48. trialfcs = PPP_FCS_16(HDLC_FCS_START,source,len);
49. trialfcs ^= 0xffff; // complement
50. source[len] = (trialfcs&0x00ff); // least significant byte first
51. source[len+1] = ((trialfcs>>8)&0x00ff);
52. source[len+2] = 0x7E;
53. return (trialfcs);
54. }
55. ////////////////////////////////////////////////////////////////
56. //
57. //Function: RETRY_FCS_16(cp,len)
58. //
59. //Description: TO check the frame whether according with FCS ro not
60. //
61. //Arguments: RFC1662;sending
62. //
63. //Returns: TRUE OF FALSE
64. //
65. ///////////////////////////////////////////////////////////////
66.
67. uchar RETRY_FCS_16(source,len)
68. uchar xdata *source;
69. uint xdata len;
70.
71. {
72. uint data trialfcs;
73. trialfcs = PPP_FCS_16( HDLC_FCS_START , source , len );
74. if( trialfcs == HDLC_FCS_FINAL ) return ( 1 );
75. else return(0);
76. }
77.
78.
79. //#define _ppp_encode
80. #ifdef _ppp_encode
81.
82.
83. ////////////////////////////////////////////////////////////////
84. //
85. //Function: ENCODE_LCP_PPP(CP1,CP2)
86. //Description: TO calculate crc check,every frame of networking
87. // must calculate by this Function,and added FLAG_PPP,
88. // ADDRESS,PROTOCOL,AND CRC return value
89. //Arguments: LCP/PPP;sending
90. //
91. //Returns: fcs,result of checking
92. //
93. //"PPP协议编码打包
94. ////////////////////////////////////////////////////////////////
95.
96. void Encode_LCP_PPP(source,dest) //"HDLC-LIKE FRAMING
97. uchar xdata *dest;
98. uchar xdata *source;
99. {
100. uint data len = source[2] * 256 + source[3];
101. *dest = 0X7E;
102. *(dest+1) = 0XFF;
103. *(dest+2) = 0x03;
104. *(dest+3) = 0xc0;
105. *(dest+4) = 0x21;
106. memcpy((dest+5),source,len);
107. len+=4;
108. TRY_FCS_16(dest+1,len);
109. }
110.
111. ////////////////////////////////////////////////////////////////
112. //
113. //Function: ENCODE_PAP_PPP(CP1,CP2)
114. //Description: TO calculate crc check,every frame of networking
115. // must calculate by this Function,and added FLAG_PPP,
116. // ADDRESS,PROTOCOL,AND CRC return value
117. //Arguments: PAP/PPP;sending
118. //
119. //Returns: fcs,result of checking
120. //
121. //"PPP协议编码打包
122. //7E C0 23 02 02 00 0D 08 57 65 6C 63 6F 6D 65 21 A0 3B 7E
123. ////////////////////////////////////////////////////////////////
124.
125. void Encode_PAP_PPP(source,dest) //"HDLC-LIKE FRAMING
126. uchar xdata *dest;
127. uchar xdata *source;
128. {
129. uint data len = source[2] * 256 + source[3];
130. *dest = 0X7E;
131. *(dest+1) = 0XC0;
132. *(dest+2) = 0x23;
133. memcpy((dest+3),source,len);
134. len += 2;
135. TRY_FCS_16(dest+1,len);
136. }
137.
138.
139.
140. ////////////////////////////////////////////////////////////////
141. //
142. //Function: ENCODE_IPCP_PPP(CP1,CP2)
143. //Description: TO calculate crc check,every frame of networking
144. // must calculate by this Function,and added FLAG_PPP,
145. // ADDRESS,PROTOCOL,AND CRC return value
146. //Arguments: IPCP/PPP;sending
147. //
148. //Returns: fcs,result of checking
149. //
150. //"PPP协议编码打包
151. //7E 80 21 01 01 00 0A 03 06 0A 1F 00 01 18 C4 7E
152. ////////////////////////////////////////////////////////////////
153.
154. void Encode_IPCP_PPP(source,dest) //"HDLC-LIKE FRAMING
155. uchar xdata *source;
156. uchar xdata *dest;
157. {
158. uint data len = source[2] * 256 + source[3];
159. *dest = 0X7E;
160. *(dest+1) = 0X80;
161. *(dest+2) = 0x21;
162. memcpy( (dest+3) , source , len );
163. len += 2;
164. TRY_FCS_16( dest+1 , len );
165. }
166.
167.
168.
169. ////////////////////////////////////////////////////////////////
170. //
171. //Function: ENCODE_IP_PPP(CP1,CP2)
172. //Description: TO calculate crc check,every frame of networking
173. // must calculate by this Function,and added FLAG_PPP,
174. // ADDRESS,PROTOCOL,AND CRC return value
175. //Arguments: IP/PPP;sending
176. //
177. //Returns: fcs,result of checking
178. //
179. //"PPP协议编码打包
180. ////////////////////////////////////////////////////////////////
181.
182. //7E 21
183. //45 00 00 60 0E 0C 00 00 80 7D 31 05 A4 0A 1F 7D 31 C0 0A
184. //FF FF FF 00 89 00 89 00 4C E7 7F 01 7C 28 10 00 01 00 00 00 00
185. //00 01 20 46 48 45 4D 45 4B 46 44 44 41 44 43 43 41 43 41 43 41
186. //43 41 43 41 43 41 43 41 43 41 43 41 43 41 00 00 20 00 01 C0 0C
187. //00 20 00 01 00 04 7D B3 E0 00 06 00 00 0A 1F 7D 31 C0
188. //B1 67 7E
189.
190.
191. void Encode_IP_PPP(source,dest) //"HDLC-LIKE FRAMING
192. uchar xdata *source;//NETWORK FRAME
193. uchar xdata *dest;//IP DATA FRAME
194. {
195. uint data len = source[2] * 256 + source[3];
196. *dest = 0X7E;
197. *(dest+1) = 0x21;
198. memcpy( (dest+2) , source , len );
199. len += 1;
200. TRY_FCS_16( dest+1 , len );
201. }
202.
203.
204. #endif //_ppp_encode
205.
206. ///////////////////////////////////////////////////////////////
207. ////////////////////////////////////////////////////////////////
208. //
209. //Function: ENCODE_PPP(CP1,CP2)
210. //Description: TO calculate crc check,every frame of networking
211. // must calculate by this Function,and added FLAG_PPP,
212. // ADDRESS,PROTOCOL,AND CRC return value
213. //Arguments: IP/PPP,LCP/PPP,PAP/PPP,IPCP/PPP;send