1 | /*
|
---|
2 | * TINET (TCP/IP Protocol Stack)
|
---|
3 | *
|
---|
4 | * Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
|
---|
5 | * Tomakomai National College of Technology, JAPAN
|
---|
6 | *
|
---|
7 | * ä¸è¨èä½æ¨©è
|
---|
8 | ã¯ï¼ä»¥ä¸ã® (1)ï½(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
9 | * ã«ãã£ã¦å
|
---|
10 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
11 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
12 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
13 | å¸ï¼ä»¥ä¸ï¼
|
---|
14 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
15 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
16 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
17 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
18 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
19 | * ç¨ã§ããå½¢ã§åé
|
---|
20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
22 | * è
|
---|
23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
24 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
25 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
26 | * ç¨ã§ããªãå½¢ã§åé
|
---|
27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®æ¡ä»¶ãæºãããã¨ï¼
|
---|
28 | * (a) åé
|
---|
29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
31 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
32 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
33 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
34 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
35 | 責ãããã¨ï¼
|
---|
36 | *
|
---|
37 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
38 | ã
|
---|
39 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
40 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
41 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
42 | *
|
---|
43 | * @(#) $Id: ppp_hdlc.c 270 2017-02-09 04:03:47Z coas-nagasima $
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * PPP High Level Link Control (HDLC) Module
|
---|
48 | *
|
---|
49 | * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
|
---|
50 | *
|
---|
51 | * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
|
---|
52 | *
|
---|
53 | * Redistribution and use in source and binary forms are permitted
|
---|
54 | * provided that the above copyright notice and this paragraph are
|
---|
55 | * duplicated in all such forms and that any documentation,
|
---|
56 | * advertising materials, and other materials related to such
|
---|
57 | * distribution and use acknowledge that the software was developed
|
---|
58 | * by the Internet Initiative Japan, Inc. The name of the
|
---|
59 | * IIJ may not be used to endorse or promote products derived
|
---|
60 | * from this software without specific prior written permission.
|
---|
61 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
---|
62 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
---|
63 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
64 | *
|
---|
65 | * $FreeBSD: src/usr.sbin/ppp/hdlc.c,v 1.46 1999/12/20 20:29:42 brian Exp $
|
---|
66 | *
|
---|
67 | * TODO:
|
---|
68 | */
|
---|
69 |
|
---|
70 | #include <s_services.h>
|
---|
71 | #include <t_services.h>
|
---|
72 |
|
---|
73 | #include <tinet_defs.h>
|
---|
74 | #include <tinet_config.h>
|
---|
75 |
|
---|
76 | #include <net/if.h>
|
---|
77 | #include <net/if_ppp.h>
|
---|
78 | #include <net/net.h>
|
---|
79 | #include <net/net_buf.h>
|
---|
80 | #include <net/net_count.h>
|
---|
81 | #include <net/ppp.h>
|
---|
82 | #include <net/ppp_var.h>
|
---|
83 | #include <net/ppp_hdlc.h>
|
---|
84 | #include <net/ppp_fsm.h>
|
---|
85 | #include <net/ppp_lcp.h>
|
---|
86 | #include <net/ppp_modem.h>
|
---|
87 |
|
---|
88 | #ifdef SUPPORT_PPP
|
---|
89 |
|
---|
90 | /*
|
---|
91 | * RFC1171 (PPP) ã® HDLC é¨ã®å®ç¾©
|
---|
92 | */
|
---|
93 |
|
---|
94 | /*
|
---|
95 | * å¤æ°
|
---|
96 | */
|
---|
97 |
|
---|
98 | uint32_t remote_ACCM = DEF_REMOTE_ACCM;
|
---|
99 |
|
---|
100 | /*
|
---|
101 | * é¢æ°
|
---|
102 | */
|
---|
103 |
|
---|
104 | static ER HDLC_putoctet (uint8_t octet);
|
---|
105 | static ER HDLC_getoctet (uint8_t *octet);
|
---|
106 |
|
---|
107 | /*
|
---|
108 | * genfcstab.c ã«ããä½æãã FCS ã®ã«ãã¯ã¢ãã表
|
---|
109 | * RFC1171 åç
|
---|
110 | §
|
---|
111 | */
|
---|
112 |
|
---|
113 | static uint16_t fcstab[256] = {
|
---|
114 | UINT_C(0x0000), UINT_C(0x1189), UINT_C(0x2312), UINT_C(0x329b),
|
---|
115 | UINT_C(0x4624), UINT_C(0x57ad), UINT_C(0x6536), UINT_C(0x74bf),
|
---|
116 | UINT_C(0x8c48), UINT_C(0x9dc1), UINT_C(0xaf5a), UINT_C(0xbed3),
|
---|
117 | UINT_C(0xca6c), UINT_C(0xdbe5), UINT_C(0xe97e), UINT_C(0xf8f7),
|
---|
118 | UINT_C(0x1081), UINT_C(0x0108), UINT_C(0x3393), UINT_C(0x221a),
|
---|
119 | UINT_C(0x56a5), UINT_C(0x472c), UINT_C(0x75b7), UINT_C(0x643e),
|
---|
120 | UINT_C(0x9cc9), UINT_C(0x8d40), UINT_C(0xbfdb), UINT_C(0xae52),
|
---|
121 | UINT_C(0xdaed), UINT_C(0xcb64), UINT_C(0xf9ff), UINT_C(0xe876),
|
---|
122 | UINT_C(0x2102), UINT_C(0x308b), UINT_C(0x0210), UINT_C(0x1399),
|
---|
123 | UINT_C(0x6726), UINT_C(0x76af), UINT_C(0x4434), UINT_C(0x55bd),
|
---|
124 | UINT_C(0xad4a), UINT_C(0xbcc3), UINT_C(0x8e58), UINT_C(0x9fd1),
|
---|
125 | UINT_C(0xeb6e), UINT_C(0xfae7), UINT_C(0xc87c), UINT_C(0xd9f5),
|
---|
126 | UINT_C(0x3183), UINT_C(0x200a), UINT_C(0x1291), UINT_C(0x0318),
|
---|
127 | UINT_C(0x77a7), UINT_C(0x662e), UINT_C(0x54b5), UINT_C(0x453c),
|
---|
128 | UINT_C(0xbdcb), UINT_C(0xac42), UINT_C(0x9ed9), UINT_C(0x8f50),
|
---|
129 | UINT_C(0xfbef), UINT_C(0xea66), UINT_C(0xd8fd), UINT_C(0xc974),
|
---|
130 | UINT_C(0x4204), UINT_C(0x538d), UINT_C(0x6116), UINT_C(0x709f),
|
---|
131 | UINT_C(0x0420), UINT_C(0x15a9), UINT_C(0x2732), UINT_C(0x36bb),
|
---|
132 | UINT_C(0xce4c), UINT_C(0xdfc5), UINT_C(0xed5e), UINT_C(0xfcd7),
|
---|
133 | UINT_C(0x8868), UINT_C(0x99e1), UINT_C(0xab7a), UINT_C(0xbaf3),
|
---|
134 | UINT_C(0x5285), UINT_C(0x430c), UINT_C(0x7197), UINT_C(0x601e),
|
---|
135 | UINT_C(0x14a1), UINT_C(0x0528), UINT_C(0x37b3), UINT_C(0x263a),
|
---|
136 | UINT_C(0xdecd), UINT_C(0xcf44), UINT_C(0xfddf), UINT_C(0xec56),
|
---|
137 | UINT_C(0x98e9), UINT_C(0x8960), UINT_C(0xbbfb), UINT_C(0xaa72),
|
---|
138 | UINT_C(0x6306), UINT_C(0x728f), UINT_C(0x4014), UINT_C(0x519d),
|
---|
139 | UINT_C(0x2522), UINT_C(0x34ab), UINT_C(0x0630), UINT_C(0x17b9),
|
---|
140 | UINT_C(0xef4e), UINT_C(0xfec7), UINT_C(0xcc5c), UINT_C(0xddd5),
|
---|
141 | UINT_C(0xa96a), UINT_C(0xb8e3), UINT_C(0x8a78), UINT_C(0x9bf1),
|
---|
142 | UINT_C(0x7387), UINT_C(0x620e), UINT_C(0x5095), UINT_C(0x411c),
|
---|
143 | UINT_C(0x35a3), UINT_C(0x242a), UINT_C(0x16b1), UINT_C(0x0738),
|
---|
144 | UINT_C(0xffcf), UINT_C(0xee46), UINT_C(0xdcdd), UINT_C(0xcd54),
|
---|
145 | UINT_C(0xb9eb), UINT_C(0xa862), UINT_C(0x9af9), UINT_C(0x8b70),
|
---|
146 | UINT_C(0x8408), UINT_C(0x9581), UINT_C(0xa71a), UINT_C(0xb693),
|
---|
147 | UINT_C(0xc22c), UINT_C(0xd3a5), UINT_C(0xe13e), UINT_C(0xf0b7),
|
---|
148 | UINT_C(0x0840), UINT_C(0x19c9), UINT_C(0x2b52), UINT_C(0x3adb),
|
---|
149 | UINT_C(0x4e64), UINT_C(0x5fed), UINT_C(0x6d76), UINT_C(0x7cff),
|
---|
150 | UINT_C(0x9489), UINT_C(0x8500), UINT_C(0xb79b), UINT_C(0xa612),
|
---|
151 | UINT_C(0xd2ad), UINT_C(0xc324), UINT_C(0xf1bf), UINT_C(0xe036),
|
---|
152 | UINT_C(0x18c1), UINT_C(0x0948), UINT_C(0x3bd3), UINT_C(0x2a5a),
|
---|
153 | UINT_C(0x5ee5), UINT_C(0x4f6c), UINT_C(0x7df7), UINT_C(0x6c7e),
|
---|
154 | UINT_C(0xa50a), UINT_C(0xb483), UINT_C(0x8618), UINT_C(0x9791),
|
---|
155 | UINT_C(0xe32e), UINT_C(0xf2a7), UINT_C(0xc03c), UINT_C(0xd1b5),
|
---|
156 | UINT_C(0x2942), UINT_C(0x38cb), UINT_C(0x0a50), UINT_C(0x1bd9),
|
---|
157 | UINT_C(0x6f66), UINT_C(0x7eef), UINT_C(0x4c74), UINT_C(0x5dfd),
|
---|
158 | UINT_C(0xb58b), UINT_C(0xa402), UINT_C(0x9699), UINT_C(0x8710),
|
---|
159 | UINT_C(0xf3af), UINT_C(0xe226), UINT_C(0xd0bd), UINT_C(0xc134),
|
---|
160 | UINT_C(0x39c3), UINT_C(0x284a), UINT_C(0x1ad1), UINT_C(0x0b58),
|
---|
161 | UINT_C(0x7fe7), UINT_C(0x6e6e), UINT_C(0x5cf5), UINT_C(0x4d7c),
|
---|
162 | UINT_C(0xc60c), UINT_C(0xd785), UINT_C(0xe51e), UINT_C(0xf497),
|
---|
163 | UINT_C(0x8028), UINT_C(0x91a1), UINT_C(0xa33a), UINT_C(0xb2b3),
|
---|
164 | UINT_C(0x4a44), UINT_C(0x5bcd), UINT_C(0x6956), UINT_C(0x78df),
|
---|
165 | UINT_C(0x0c60), UINT_C(0x1de9), UINT_C(0x2f72), UINT_C(0x3efb),
|
---|
166 | UINT_C(0xd68d), UINT_C(0xc704), UINT_C(0xf59f), UINT_C(0xe416),
|
---|
167 | UINT_C(0x90a9), UINT_C(0x8120), UINT_C(0xb3bb), UINT_C(0xa232),
|
---|
168 | UINT_C(0x5ac5), UINT_C(0x4b4c), UINT_C(0x79d7), UINT_C(0x685e),
|
---|
169 | UINT_C(0x1ce1), UINT_C(0x0d68), UINT_C(0x3ff3), UINT_C(0x2e7a),
|
---|
170 | UINT_C(0xe70e), UINT_C(0xf687), UINT_C(0xc41c), UINT_C(0xd595),
|
---|
171 | UINT_C(0xa12a), UINT_C(0xb0a3), UINT_C(0x8238), UINT_C(0x93b1),
|
---|
172 | UINT_C(0x6b46), UINT_C(0x7acf), UINT_C(0x4854), UINT_C(0x59dd),
|
---|
173 | UINT_C(0x2d62), UINT_C(0x3ceb), UINT_C(0x0e70), UINT_C(0x1ff9),
|
---|
174 | UINT_C(0xf78f), UINT_C(0xe606), UINT_C(0xd49d), UINT_C(0xc514),
|
---|
175 | UINT_C(0xb1ab), UINT_C(0xa022), UINT_C(0x92b9), UINT_C(0x8330),
|
---|
176 | UINT_C(0x7bc7), UINT_C(0x6a4e), UINT_C(0x58d5), UINT_C(0x495c),
|
---|
177 | UINT_C(0x3de3), UINT_C(0x2c6a), UINT_C(0x1ef1), UINT_C(0x0f78),
|
---|
178 | };
|
---|
179 |
|
---|
180 | /*
|
---|
181 | * ã¤ã³ã©ã¤ã³é¢æ°
|
---|
182 | */
|
---|
183 |
|
---|
184 | Inline uint16_t Next_FCS (uint16_t FCS, uint8_t Octet) {
|
---|
185 | return (FCS >> 8) ^ fcstab[(FCS ^ Octet) & 0xff];
|
---|
186 | };
|
---|
187 |
|
---|
188 | /*
|
---|
189 | * HDLC_putoctet -- HDLC ãªã¯ãããåºå
|
---|
190 | */
|
---|
191 |
|
---|
192 | static
|
---|
193 | ER HDLC_putoctet (uint8_t octet)
|
---|
194 | {
|
---|
195 | static uint8_t escape[2] = { HDLC_CNTL_ESC };
|
---|
196 |
|
---|
197 | ER error;
|
---|
198 |
|
---|
199 | NET_COUNT_PPP_HDLC(net_count_hdlc.out_octets, 1);
|
---|
200 |
|
---|
201 | if ((octet < 0x20 && ((1 << octet) & lcp_remote_ack_cfg.ACCM)) ||
|
---|
202 | octet == HDLC_CNTL_ESC || octet == HDLC_FLAG_SEQ) {
|
---|
203 | escape[1] = octet ^ HDLC_ESC_MASK;
|
---|
204 | error = serial_wri_dat(HDLC_PORTID, escape, sizeof(escape));
|
---|
205 | }
|
---|
206 | else
|
---|
207 | error = serial_wri_dat(HDLC_PORTID, &octet, sizeof(octet));
|
---|
208 |
|
---|
209 | return error > 0 ? E_OK : error;
|
---|
210 | }
|
---|
211 |
|
---|
212 | /*
|
---|
213 | * HDLC_wirte -- HDLC åºå
|
---|
214 | */
|
---|
215 |
|
---|
216 | ER HDLC_write (T_NET_BUF *nbuf)
|
---|
217 | {
|
---|
218 | static char flag_seq_ac[4] = {
|
---|
219 | HDLC_FLAG_SEQ,
|
---|
220 | HDLC_ADDR_ALL,
|
---|
221 | HDLC_CNTL_ESC,
|
---|
222 | HDLC_CNTL_UI ^ HDLC_ESC_MASK,
|
---|
223 | };
|
---|
224 |
|
---|
225 | #ifdef LCP_CFG_ACCOMP
|
---|
226 |
|
---|
227 | static char flag_seq = HDLC_FLAG_SEQ;
|
---|
228 |
|
---|
229 | #endif /* of #ifdef LCP_CFG_ACCOMP */
|
---|
230 |
|
---|
231 | ER error;
|
---|
232 | uint32_t fcs;
|
---|
233 | uint16_t len;
|
---|
234 | uint8_t *buf;
|
---|
235 |
|
---|
236 | NET_COUNT_PPP_HDLC(net_count_hdlc.out_packets, 1);
|
---|
237 |
|
---|
238 | #ifdef LCP_CFG_ACCOMP
|
---|
239 |
|
---|
240 | if (lcp_local_ack_cfg.options & LCP_CFG_ACCOMP) {
|
---|
241 | NET_COUNT_PPP_HDLC(net_count_hdlc.out_octets, sizeof(flag_seq));
|
---|
242 | /* ãã¬ã¼ã éå§ãã©ã°ã·ã¼ã±ã³ã¹ ãéä¿¡ãã */
|
---|
243 | if ((error = serial_wri_dat(HDLC_PORTID, &flag_seq, sizeof(flag_seq))) < 0) {
|
---|
244 | goto err_ret;
|
---|
245 | }
|
---|
246 | fcs = HDLC_INIT_FCS;
|
---|
247 | }
|
---|
248 | else {
|
---|
249 |
|
---|
250 | NET_COUNT_PPP_HDLC(net_count_hdlc.out_octets, sizeof(flag_seq_ac));
|
---|
251 | /* ãã¬ã¼ã éå§ãã©ã°ã·ã¼ã±ã³ã¹ãAddress 㨠Control ãéä¿¡ãã */
|
---|
252 | if ((error = serial_wri_dat(HDLC_PORTID, flag_seq_ac, sizeof(flag_seq_ac))) < 0) {
|
---|
253 | goto err_ret;
|
---|
254 | }
|
---|
255 | /* Address 㨠Control ã® FCS ã®è¨ç®ã¯ HDLC_INIT_FCS_AC ã«å«ãã¦ãã */
|
---|
256 | fcs = HDLC_INIT_FCS_AC;
|
---|
257 | }
|
---|
258 |
|
---|
259 | #else /* of #ifdef LCP_CFG_ACCOMP */
|
---|
260 |
|
---|
261 | NET_COUNT_PPP_HDLC(net_count_hdlc.out_octets, sizeof(flag_seq_ac));
|
---|
262 | /* ãã¬ã¼ã éå§ãã©ã°ã·ã¼ã±ã³ã¹ãAddress 㨠Control ãéä¿¡ãã */
|
---|
263 | if ((error = serial_wri_dat(HDLC_PORTID, flag_seq_ac, sizeof(flag_seq_ac))) < 0) {
|
---|
264 | goto err_ret;
|
---|
265 | }
|
---|
266 | /* Address 㨠Control ã® FCS ã®è¨ç®ã¯ HDLC_INIT_FCS_AC ã«å«ãã¦ãã */
|
---|
267 | fcs = HDLC_INIT_FCS_AC;
|
---|
268 |
|
---|
269 | #endif /* of #ifdef LCP_CFG_ACCOMP */
|
---|
270 |
|
---|
271 | buf = nbuf->buf;
|
---|
272 | len = nbuf->len;
|
---|
273 |
|
---|
274 | #ifdef LCP_CFG_PCOMP
|
---|
275 |
|
---|
276 | if ((lcp_local_ack_cfg.options & LCP_CFG_ACCOMP) && *buf == 0 && *(buf + 1) < 0xff) {
|
---|
277 | buf ++;
|
---|
278 | len --;
|
---|
279 | }
|
---|
280 |
|
---|
281 | #endif /* of #ifdef LCP_CFG_PCOMP */
|
---|
282 |
|
---|
283 | /* ãã¼ã¿ãéä¿¡ãã */
|
---|
284 | while (len -- > 0) {
|
---|
285 |
|
---|
286 | if ((error = HDLC_putoctet(*buf)) != E_OK)
|
---|
287 | goto err_ret;
|
---|
288 | fcs = Next_FCS(fcs, *buf);
|
---|
289 | buf ++;
|
---|
290 | }
|
---|
291 |
|
---|
292 | /* FCS ãéä¿¡ãã */
|
---|
293 | fcs = ~fcs;
|
---|
294 | if ((error = HDLC_putoctet(fcs & 0xff)) != E_OK)
|
---|
295 | goto err_ret;
|
---|
296 | if ((error = HDLC_putoctet(fcs >> 8)) != E_OK)
|
---|
297 | goto err_ret;
|
---|
298 |
|
---|
299 | /* ãã¬ã¼ã çµäºãã©ã°ã·ã¼ã±ã³ã¹ãéä¿¡ãã */
|
---|
300 | if ((error = serial_wri_dat(HDLC_PORTID, &flag_seq_ac[0], sizeof(char))) < 0)
|
---|
301 | goto err_ret;
|
---|
302 |
|
---|
303 | return E_OK;
|
---|
304 |
|
---|
305 | err_ret:
|
---|
306 | NET_COUNT_PPP_HDLC(net_count_hdlc.out_err_packets, 1);
|
---|
307 | return error;
|
---|
308 | }
|
---|
309 |
|
---|
310 | /*
|
---|
311 | * HDLC_getoctet -- HDLC ãªã¯ãããå
|
---|
312 | ¥å
|
---|
313 | *
|
---|
314 | * æ»ãå¤ã true ãªããã©ã°ã·ã¼ã±ã³ã¹
|
---|
315 | */
|
---|
316 |
|
---|
317 | static
|
---|
318 | ER_BOOL HDLC_getoctet (uint8_t *octet)
|
---|
319 | {
|
---|
320 | ER error;
|
---|
321 |
|
---|
322 | /* 1ãªã¯ãããå
|
---|
323 | ¥åãã */
|
---|
324 | if ((error = serial_rea_dat(HDLC_PORTID, octet, sizeof(uint8_t))) <= 0) {
|
---|
325 | return error;
|
---|
326 | }
|
---|
327 |
|
---|
328 | /* å
|
---|
329 | ¥åãããªã¯ãããããã©ã°ã·ã¼ã±ã³ã¹ãªã true ãè¿ã */
|
---|
330 | if (*octet == HDLC_FLAG_SEQ)
|
---|
331 | return true;
|
---|
332 |
|
---|
333 | /* å
|
---|
334 | ¥åãããªã¯ããããã¨ã¹ã±ã¼ããªããããï¼ãªã¯ãããå
|
---|
335 | ¥åããã¹ã¯ã解é¤ãã */
|
---|
336 | if (*octet == HDLC_CNTL_ESC) {
|
---|
337 | if ((error = serial_rea_dat(HDLC_PORTID, octet, sizeof(uint8_t))) <= 0)
|
---|
338 | return error;
|
---|
339 | *octet ^= HDLC_ESC_MASK;
|
---|
340 | }
|
---|
341 |
|
---|
342 | NET_COUNT_PPP_HDLC(net_count_hdlc.in_octets, 1);
|
---|
343 | return E_OK;
|
---|
344 | }
|
---|
345 |
|
---|
346 | /*
|
---|
347 | * HDLC_read -- HDLC å
|
---|
348 | ¥å
|
---|
349 | *
|
---|
350 | * HDLC ãã¬ã¼ã ãå
|
---|
351 | ¥åããã
|
---|
352 | */
|
---|
353 |
|
---|
354 | ER HDLC_read (T_NET_BUF *nbuf, uint16_t size)
|
---|
355 | {
|
---|
356 | ER error;
|
---|
357 | uint32_t fcs = 0;
|
---|
358 | uint16_t olen = 0;
|
---|
359 | uint8_t *buf, octet;
|
---|
360 |
|
---|
361 | buf = nbuf->buf;
|
---|
362 |
|
---|
363 | /* ãã¬ã¼ã éå§ãã©ã°ã·ã¼ã±ã³ã¹ã¾ã§å
|
---|
364 | ¥åãèªã¿é£ã°ã */
|
---|
365 | while ((error = HDLC_getoctet(&octet)) != true) {
|
---|
366 |
|
---|
367 | if (error != E_OK)
|
---|
368 | goto err_ret;
|
---|
369 |
|
---|
370 | #ifdef PPP_CFG_MODEM
|
---|
371 |
|
---|
372 | else if (octet == '\n') {
|
---|
373 | /* ã¢ãã å¶å¾¡ãå¼ã³åºãã*/
|
---|
374 | modem_cntl(modem_getline(nbuf, size));
|
---|
375 | /* ä¸åº¦ããã®é¢æ°ãçµäºããã*/
|
---|
376 | nbuf->len = 0;
|
---|
377 | return E_OK;
|
---|
378 | }
|
---|
379 |
|
---|
380 | #endif/* of #ifdef PPP_CFG_MODEM */
|
---|
381 |
|
---|
382 | }
|
---|
383 |
|
---|
384 | /* ãã¬ã¼ã éå§ãã©ã°ã·ã¼ã±ã³ã¹ã®éã¯å
|
---|
385 | ¥åãèªã¿é£ã°ã */
|
---|
386 | while (1) {
|
---|
387 | if ((error = HDLC_getoctet(&octet)) == E_OK)
|
---|
388 | break;
|
---|
389 | else if (error != true)
|
---|
390 | goto err_ret;
|
---|
391 | }
|
---|
392 |
|
---|
393 | NET_COUNT_PPP_HDLC(net_count_hdlc.in_packets, 1);
|
---|
394 |
|
---|
395 | /* å
|
---|
396 | ¥åãããªã¯ããã㯠Address: All-Stations ã */
|
---|
397 | if (octet == HDLC_ADDR_ALL) {
|
---|
398 |
|
---|
399 | /* 次㯠Control: UI */
|
---|
400 | if ((error = HDLC_getoctet(&octet)) != E_OK || octet != HDLC_CNTL_UI) {
|
---|
401 | error = E_SYS;
|
---|
402 | goto err_ret;
|
---|
403 | }
|
---|
404 | if ((error = HDLC_getoctet(&octet)) != E_OK)
|
---|
405 | goto err_ret;
|
---|
406 | /* Address 㨠Control ã® FCS ã®è¨ç®ã¯ HDLC_INIT_FCS_AC ã«å«ãã¦ãã */
|
---|
407 | fcs = HDLC_INIT_FCS_AC;
|
---|
408 | }
|
---|
409 |
|
---|
410 | #ifdef LCP_CFG_ACCOMP
|
---|
411 |
|
---|
412 | else if (lcp_remote_ack_cfg.options & LCP_CFG_ACCOMP) {
|
---|
413 | fcs = HDLC_INIT_FCS;
|
---|
414 | }
|
---|
415 |
|
---|
416 | #endif/* of #ifdef LCP_CFG_ACCOMP */
|
---|
417 |
|
---|
418 | else {
|
---|
419 | error = E_SYS;
|
---|
420 | goto err_ret;
|
---|
421 | }
|
---|
422 |
|
---|
423 | nbuf->len = 0;
|
---|
424 |
|
---|
425 | #ifdef LCP_CFG_PCOMP
|
---|
426 |
|
---|
427 | if ((lcp_remote_ack_cfg.options & LCP_CFG_PCOMP) && (octet & 0x01) != 0) {
|
---|
428 | *buf ++ = 0x00;
|
---|
429 | size --;
|
---|
430 | nbuf->len ++;
|
---|
431 | }
|
---|
432 |
|
---|
433 | #endif /* of #ifdef LCP_CFG_PCOMP */
|
---|
434 |
|
---|
435 | fcs = Next_FCS(fcs, octet);
|
---|
436 | *buf ++ = octet;
|
---|
437 | size --;
|
---|
438 | nbuf->len ++;
|
---|
439 |
|
---|
440 | /* SUD + FCS ãå
|
---|
441 | ¥åãã */
|
---|
442 | while ((error = HDLC_getoctet(&octet)) == E_OK) {
|
---|
443 | fcs = Next_FCS(fcs, octet);
|
---|
444 | if (size > 0) {
|
---|
445 | *buf ++ = octet;
|
---|
446 | size --;
|
---|
447 | }
|
---|
448 | else
|
---|
449 | olen ++;
|
---|
450 | nbuf->len ++;
|
---|
451 | }
|
---|
452 |
|
---|
453 | if (error == true) {
|
---|
454 | if (size > 0)
|
---|
455 | nbuf->len -= 2;
|
---|
456 | else if (olen <= 2)
|
---|
457 | nbuf->len -= olen;
|
---|
458 | else {
|
---|
459 | error = E_BOVR;
|
---|
460 | goto err_ret;
|
---|
461 | }
|
---|
462 | }
|
---|
463 | else
|
---|
464 | goto err_ret;
|
---|
465 |
|
---|
466 | /* FCS ããã§ãã¯ãã */
|
---|
467 | if (fcs != HDLC_GOOD_FCS) {
|
---|
468 | error = E_SYS;
|
---|
469 | goto err_ret;
|
---|
470 | }
|
---|
471 |
|
---|
472 | return E_OK;
|
---|
473 |
|
---|
474 | err_ret:
|
---|
475 | NET_COUNT_PPP_HDLC(net_count_hdlc.in_err_packets, 1);
|
---|
476 | return error;
|
---|
477 | }
|
---|
478 |
|
---|
479 | /*
|
---|
480 | * HDLC_dummy_read -- HDLC å
|
---|
481 | ¥å (空èªã¿)
|
---|
482 | *
|
---|
483 | * HDLC ãã¬ã¼ã ã空èªã¿ããã
|
---|
484 | */
|
---|
485 |
|
---|
486 | void
|
---|
487 | HDLC_dummy_read (void)
|
---|
488 | {
|
---|
489 | uint8_t octet;
|
---|
490 | ER error;
|
---|
491 |
|
---|
492 | /* ãã¬ã¼ã éå§ãã©ã°ã·ã¼ã±ã³ã¹ã¾ã§å
|
---|
493 | ¥åãèªã¿é£ã°ã */
|
---|
494 | while ((error = HDLC_getoctet(&octet)) != true) {
|
---|
495 | if (error != E_OK)
|
---|
496 | return;
|
---|
497 | }
|
---|
498 |
|
---|
499 | /* ãã¬ã¼ã éå§ãã©ã°ã·ã¼ã±ã³ã¹ã®éã¯å
|
---|
500 | ¥åãèªã¿é£ã°ã */
|
---|
501 | while (octet == HDLC_FLAG_SEQ)
|
---|
502 | if (HDLC_getoctet(&octet) != E_OK)
|
---|
503 | return;
|
---|
504 |
|
---|
505 | /* å
|
---|
506 | ¥åãããªã¯ããã㯠Address: All-Stations ã */
|
---|
507 | if (octet == HDLC_ADDR_ALL) {
|
---|
508 |
|
---|
509 | /* 次㯠Control: UI */
|
---|
510 | if (HDLC_getoctet(&octet) != E_OK || octet != HDLC_CNTL_UI)
|
---|
511 | return;
|
---|
512 | if (HDLC_getoctet(&octet) != E_OK)
|
---|
513 | return;
|
---|
514 | }
|
---|
515 |
|
---|
516 | #ifdef LCP_CFG_ACCOMP
|
---|
517 |
|
---|
518 | else if (lcp_remote_ack_cfg.options & LCP_CFG_ACCOMP)
|
---|
519 | ;
|
---|
520 |
|
---|
521 | #endif/* of #ifdef LCP_CFG_ACCOMP */
|
---|
522 |
|
---|
523 | else
|
---|
524 | return;
|
---|
525 |
|
---|
526 | while (HDLC_getoctet(&octet) == E_OK)
|
---|
527 | ;
|
---|
528 | }
|
---|
529 |
|
---|
530 | #ifdef PPP_CFG_MODEM
|
---|
531 |
|
---|
532 | /*
|
---|
533 | * HDLC_raw_getoctet -- HDLC ãªã¯ããã (Raw) å
|
---|
534 | ¥å
|
---|
535 | */
|
---|
536 |
|
---|
537 | int HDLC_raw_getoctet (void)
|
---|
538 | {
|
---|
539 | uint8_t ch;
|
---|
540 |
|
---|
541 | /* 1ãªã¯ãããå
|
---|
542 | ¥åãã */
|
---|
543 | if (serial_rea_dat(HDLC_PORTID, &ch, sizeof(ch)) <= 0)
|
---|
544 | return '\0';
|
---|
545 |
|
---|
546 | NET_COUNT_PPP_HDLC(net_count_hdlc.in_octets, 1);
|
---|
547 | return ch;
|
---|
548 | }
|
---|
549 |
|
---|
550 | /*
|
---|
551 | * HDLC_raw_putoctet -- HDLC ãªã¯ããã (Raw) åºå
|
---|
552 | */
|
---|
553 |
|
---|
554 | void HDLC_raw_putoctet (uint8_t ch)
|
---|
555 | {
|
---|
556 | NET_COUNT_PPP_HDLC(net_count_hdlc.out_octets, 1);
|
---|
557 | /* 1ãªã¯ãããåºåãã */
|
---|
558 | serial_wri_dat(HDLC_PORTID, &ch, sizeof(ch));
|
---|
559 | }
|
---|
560 |
|
---|
561 | #endif /* of #ifdef PPP_CFG_MODEM */
|
---|
562 |
|
---|
563 | #endif /* fo #ifdef SUPPORT_PPP */
|
---|