FreeCalypso > hg > fc-tourmaline
comparison src/g23m-fad/ppp/ppp_papf.c @ 1:fa8dc04885d8
src/g23m-*: import from Magnetite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 16 Oct 2020 06:25:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:4e78acac3d88 | 1:fa8dc04885d8 |
---|---|
1 /* | |
2 +----------------------------------------------------------------------------- | |
3 | Project : | |
4 | Modul : | |
5 +----------------------------------------------------------------------------- | |
6 | Copyright 2002 Texas Instruments Berlin, AG | |
7 | All rights reserved. | |
8 | | |
9 | This file is confidential and a trade secret of Texas | |
10 | Instruments Berlin, AG | |
11 | The receipt of or possession of this file does not convey | |
12 | any rights to reproduce or disclose its contents or to | |
13 | manufacture, use, or sell anything it may describe, in | |
14 | whole, or in part, without the specific written consent of | |
15 | Texas Instruments Berlin, AG. | |
16 +----------------------------------------------------------------------------- | |
17 | Purpose : This modul is part of the entity PPP and implements all | |
18 | procedures and functions as described in the | |
19 | SDL-documentation (PAP-statemachine) | |
20 +----------------------------------------------------------------------------- | |
21 */ | |
22 | |
23 #ifndef PPP_PAPF_C | |
24 #define PPP_PAPF_C | |
25 #endif /* !PPP_PAPF_C */ | |
26 | |
27 #define ENTITY_PPP | |
28 | |
29 /*==== INCLUDES =============================================================*/ | |
30 | |
31 #include "typedefs.h" /* to get Condat data types */ | |
32 #include "vsi.h" /* to get a lot of macros */ | |
33 #include "macdef.h" /* to get a lot of macros */ | |
34 #include "custom.h" /* to get a lot of macros */ | |
35 #include "gsm.h" /* to get a lot of macros */ | |
36 #include "cnf_ppp.h" /* to get cnf-definitions */ | |
37 #include "mon_ppp.h" /* to get mon-definitions */ | |
38 #include "prim.h" /* to get the definitions of used SAP and directions */ | |
39 #include "dti.h" /* to get the DTILIB definitions */ | |
40 #include "ppp.h" /* to get the global entity definitions */ | |
41 | |
42 #include "ppp_arbf.h" /* to get function interface from arb */ | |
43 #include <string.h> /* to get memcpy */ | |
44 | |
45 /*==== CONST ================================================================*/ | |
46 | |
47 #define PAP_AUTH_ACK_LENGTH 5 | |
48 | |
49 /* | |
50 * the authentication request packet must be passable to the ISP in protocol | |
51 * configuration options (pco). The maximum length of pco is | |
52 * 251 octets (253 - 2 (identification overhead) = 251). There must also be | |
53 * space for other protocol packet, like LCP and IPCP. | |
54 * LCP needs | |
55 * 15 octets (3 (overhead pco) + 4 (overhead packet) + 4 (mru) + 4 | |
56 * (authentication protocol PAP) = 15) for server packet and | |
57 * 11 octets (3 (overhead pco) + 4 (overhead packet) + 4 (mru) = 11) for | |
58 * client packet. | |
59 * IPCP needs | |
60 * 31 octets (3 (overhead pco) + 4 (overhead packet) + 6 (IP address) + 6 | |
61 * (VJ header compression) + 6 (primary DNS) + 6 (secondary DNS) = 31) for | |
62 * client packet and | |
63 * 13 octets (3 (overhead pco) + 4 (overhead packet) + 6 | |
64 * (Gateway address) = 13) for gateway address packet. | |
65 * PAP needs | |
66 * 3 octets for pco overhead. | |
67 */ | |
68 #define PAP_AUTH_REQ_LENGTH_MAX (251 - 15 - 11 - 31 - 13 - 3) | |
69 | |
70 #define PAP_AUTH_NAK_TEXT "authentication packet to long" | |
71 #define PAP_AUTH_NAK_TEXT_LENGTH sizeof(PAP_AUTH_NAK_TEXT) | |
72 #define PAP_AUTH_NAK_LENGTH (5 + PAP_AUTH_NAK_TEXT_LENGTH) | |
73 | |
74 /*==== LOCAL VARS ===========================================================*/ | |
75 | |
76 /*==== PRIVATE FUNCTIONS ====================================================*/ | |
77 | |
78 /*==== PUBLIC FUNCTIONS =====================================================*/ | |
79 | |
80 | |
81 | |
82 /* | |
83 +------------------------------------------------------------------------------ | |
84 | Function : pap_init | |
85 +------------------------------------------------------------------------------ | |
86 | Description : The function pap_init() initializes Password Authentication | |
87 | Protocol | |
88 | | |
89 | Parameters : no parameters | |
90 | | |
91 +------------------------------------------------------------------------------ | |
92 */ | |
93 GLOBAL void pap_init () | |
94 { | |
95 TRACE_FUNCTION( "pap_init" ); | |
96 | |
97 /* | |
98 * initialize values | |
99 */ | |
100 ppp_data->pap.counter = 0; | |
101 ppp_data->pap.nari = 0; | |
102 ppp_data->pap.ar_packet = NULL; | |
103 | |
104 INIT_STATE( PPP_SERVICE_PAP , PAP_DOWN ); | |
105 } /* pap_init() */ | |
106 | |
107 | |
108 | |
109 /* | |
110 +------------------------------------------------------------------------------ | |
111 | Function : pap_fill_out_packet | |
112 +------------------------------------------------------------------------------ | |
113 | Description : The function pap_fill_out_packet() puts a PAP packet into | |
114 | the protocol configuration list | |
115 | | |
116 | Parameters : pco_buf - pco list buffer | |
117 | ptr_pos - position where to write the PAP packet, this value | |
118 | must get back to the calling funtion | |
119 | | |
120 +------------------------------------------------------------------------------ | |
121 */ | |
122 GLOBAL void pap_fill_out_packet (UBYTE pco_buf[], USHORT* ptr_pos) | |
123 { | |
124 USHORT pos; | |
125 | |
126 TRACE_FUNCTION( "pap_fill_out_packet" ); | |
127 | |
128 pos = *ptr_pos; | |
129 | |
130 /* | |
131 * copy stored authentication request packet | |
132 */ | |
133 /* | |
134 * Protocol ID | |
135 */ | |
136 pco_buf[pos] = PROTOCOL_PAP_MSB; | |
137 pos++; | |
138 pco_buf[pos] = PROTOCOL_PAP_LSB; | |
139 pos++; | |
140 /* | |
141 * Length of Protocol contents | |
142 */ | |
143 pco_buf[pos] = (UBYTE)ppp_data->pap.ar_packet->len; | |
144 pos++; | |
145 /* | |
146 * copy packet | |
147 */ | |
148 memcpy(&pco_buf[pos], | |
149 ppp_data->pap.ar_packet->buffer, | |
150 ppp_data->pap.ar_packet->len); | |
151 pos+= ppp_data->pap.ar_packet->len; | |
152 /* | |
153 * return new position | |
154 */ | |
155 *ptr_pos = pos; | |
156 } /* pap_fill_out_packet() */ | |
157 | |
158 | |
159 | |
160 /* | |
161 +------------------------------------------------------------------------------ | |
162 | Function : pap_get_sar | |
163 +------------------------------------------------------------------------------ | |
164 | Description : The function pap_get_sar() returns a PAP Authenticate Request | |
165 | packet. | |
166 | | |
167 | Parameters : ptr_packet - returns the Authenticate Request packet | |
168 | THE MEMORY FOR THE PACKET WILL BE ALLOCATED BY | |
169 | THIS FUNCTION | |
170 | | |
171 +------------------------------------------------------------------------------ | |
172 */ | |
173 GLOBAL void pap_get_sar (T_desc2** ptr_packet) | |
174 { | |
175 T_desc2* ret_desc; | |
176 USHORT len_pos; | |
177 USHORT pos; | |
178 UBYTE i; | |
179 | |
180 TRACE_FUNCTION( "pap_get_sar" ); | |
181 | |
182 /* | |
183 * Allocate the necessary size for the data descriptor. The size is | |
184 * calculated as follows: | |
185 * - take the size of a descriptor structure | |
186 * - subtract one because of the array buffer[1] to get the size of | |
187 * descriptor control information | |
188 * - add number of octets of descriptor data | |
189 */ | |
190 MALLOC (ret_desc, (USHORT)(sizeof(T_desc2) - 1 + | |
191 5 + /* | |
192 * 1 octet code field | |
193 * 1 octet identifier field | |
194 * 2 octets packet length field | |
195 * 1 octet peer id length field | |
196 */ | |
197 ppp_data->login.name_len + | |
198 1 + /* size of password length field */ | |
199 ppp_data->login.password_len)); | |
200 /* | |
201 * fill the packet | |
202 */ | |
203 ret_desc->next = (ULONG)NULL; | |
204 pos = 0; | |
205 /* | |
206 * Code field | |
207 */ | |
208 ret_desc->buffer[pos] = CODE_AUTH_REQ; | |
209 pos++; | |
210 /* | |
211 * Identifier field | |
212 */ | |
213 ret_desc->buffer[pos] = ppp_data->pap.nari;/*lint !e415 (Warning -- access of out-of-bounds pointer)*/ | |
214 pos++; | |
215 /* | |
216 * Length field (store the position) | |
217 */ | |
218 len_pos = pos; | |
219 pos++; | |
220 pos++; | |
221 /* | |
222 * authentication: peer-id and passwort | |
223 */ | |
224 ret_desc->buffer[pos] = ppp_data->login.name_len;/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer)*/ | |
225 pos++; | |
226 for (i = 0; i < ppp_data->login.name_len; i++) | |
227 { | |
228 ret_desc->buffer[pos] = ppp_data->login.name[i];/*lint !e661 !e662 (Warning -- Possible access/creation of out-of-bounds pointer)*/ | |
229 pos++; | |
230 } | |
231 ret_desc->buffer[pos] = ppp_data->login.password_len;/*lint !e661 !e662 (Warning -- Possible access/creation of out-of-bounds pointer)*/ | |
232 pos++; | |
233 for (i = 0; i < ppp_data->login.password_len; i++) | |
234 { | |
235 ret_desc->buffer[pos] = ppp_data->login.password[i];/*lint !e661 !e662 (Warning -- Possible access/creation of out-of-bounds pointer)*/ | |
236 pos++; | |
237 } | |
238 /* | |
239 * insert packet length | |
240 */ | |
241 ret_desc->len = pos; | |
242 ret_desc->buffer[len_pos] = (UBYTE)(pos >> 8);/*lint !e661 !e662 (Warning -- Possible access/creation of out-of-bounds pointer)*/ | |
243 len_pos++; | |
244 ret_desc->buffer[len_pos] = (UBYTE)(pos & 0x00ff);/*lint !e661 !e662 (Warning -- Possible access/creation of out-of-bounds pointer)*/ | |
245 | |
246 /* | |
247 * return the created packet | |
248 */ | |
249 *ptr_packet = ret_desc; | |
250 } /* pap_get_sar() */ | |
251 | |
252 | |
253 | |
254 /* | |
255 +------------------------------------------------------------------------------ | |
256 | Function : pap_get_saa | |
257 +------------------------------------------------------------------------------ | |
258 | Description : The function pap_get_saa() returns a PAP Authenticate Ack | |
259 | packet. | |
260 | | |
261 | Parameters : ptr_packet - returns the Authenticate Ack packet | |
262 | THE MEMORY FOR THE PACKET WILL BE ALLOCATED BY | |
263 | THIS FUNCTION | |
264 | | |
265 +------------------------------------------------------------------------------ | |
266 */ | |
267 GLOBAL void pap_get_saa (T_desc2** ptr_packet) | |
268 { | |
269 T_desc2* packet; | |
270 USHORT pos; | |
271 | |
272 TRACE_FUNCTION( "pap_get_saa" ); | |
273 | |
274 /* | |
275 * Allocate the necessary size for the data descriptor. The size is | |
276 * calculated as follows: | |
277 * - take the size of a descriptor structure | |
278 * - subtract one because of the array buffer[1] to get the size of | |
279 * descriptor control information | |
280 * - add number of octets of descriptor data | |
281 */ | |
282 MALLOC (packet, (USHORT)(sizeof(T_desc2) - 1 + PAP_AUTH_ACK_LENGTH)); | |
283 packet->len = PAP_AUTH_ACK_LENGTH; | |
284 packet->next = (ULONG)NULL; | |
285 pos = 0; | |
286 /* | |
287 * code field | |
288 */ | |
289 packet->buffer[pos] = CODE_AUTH_ACK; | |
290 pos++; | |
291 /* | |
292 * identifier field | |
293 */ | |
294 packet->buffer[pos] = ppp_data->pap.nari;/*lint !e415 (Warning -- access of out-of-bounds pointer)*/ | |
295 pos++; | |
296 /* | |
297 * length field | |
298 */ | |
299 packet->buffer[pos] = 0;/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer)*/ | |
300 pos++; | |
301 packet->buffer[pos] = PAP_AUTH_ACK_LENGTH;/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer)*/ | |
302 pos++; | |
303 /* | |
304 * set Msg-Length field | |
305 */ | |
306 packet->buffer[pos] = 0;/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer)*/ | |
307 /* | |
308 * return the created packet | |
309 */ | |
310 *ptr_packet = packet; | |
311 } /* pap_get_saa() */ | |
312 | |
313 | |
314 | |
315 /* | |
316 +------------------------------------------------------------------------------ | |
317 | Function : pap_rar | |
318 +------------------------------------------------------------------------------ | |
319 | Description : The function pap_rar() checks whether the given | |
320 | Authenticate Request packet is valid and if so it returns | |
321 | FORWARD_RARP and an Authentication Ack packet. | |
322 | | |
323 | Parameters : ptr_packet - Authenticate Request packet | |
324 | forward - returns result of analysis | |
325 | | |
326 +------------------------------------------------------------------------------ | |
327 */ | |
328 GLOBAL void pap_rar (T_desc2** ptr_packet, UBYTE* forward) | |
329 { | |
330 T_desc2* packet; | |
331 USHORT packet_len; | |
332 USHORT pos; | |
333 | |
334 TRACE_FUNCTION( "pap_rar" ); | |
335 | |
336 /* | |
337 * this packet can only reveiced in server mode | |
338 */ | |
339 if(ppp_data->mode NEQ PPP_SERVER) | |
340 { | |
341 *forward = FORWARD_DISCARD; | |
342 return; | |
343 } | |
344 /* | |
345 * check correct length | |
346 */ | |
347 packet = *ptr_packet; | |
348 packet_len = packet->buffer[2];/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer)*/ | |
349 packet_len = packet_len << 8; | |
350 packet_len+= packet->buffer[3];/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer)*/ | |
351 if((packet_len < 6) || (packet_len > packet->len)) | |
352 { | |
353 *forward = FORWARD_DISCARD; | |
354 return; | |
355 } | |
356 | |
357 /* | |
358 * check consistence of length of packet and length of log on information | |
359 */ | |
360 pos = 4; | |
361 pos+= packet->buffer[pos];/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer)*/ | |
362 pos++; | |
363 pos+= packet->buffer[pos]; | |
364 pos++; | |
365 if(pos > packet_len) | |
366 { | |
367 *forward = FORWARD_DISCARD; | |
368 return; | |
369 } | |
370 | |
371 /* | |
372 * store authentication packet | |
373 */ | |
374 if(packet_len > PAP_AUTH_REQ_LENGTH_MAX) | |
375 { | |
376 /* | |
377 * create Authentication Nak | |
378 */ | |
379 /* | |
380 * change code field | |
381 */ | |
382 packet->buffer[0] = CODE_AUTH_NAK; | |
383 /* | |
384 * change length field | |
385 */ | |
386 packet->buffer[2] = 0;/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer)*/ | |
387 packet->buffer[3] = PAP_AUTH_NAK_LENGTH;/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer)*/ | |
388 packet->len = PAP_AUTH_NAK_LENGTH; | |
389 /* | |
390 * set Msg-Length field | |
391 */ | |
392 packet->buffer[4] = PAP_AUTH_NAK_TEXT_LENGTH;/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer)*/ | |
393 /* | |
394 * fill out Message | |
395 */ | |
396 memcpy(&packet->buffer[5], PAP_AUTH_NAK_TEXT, PAP_AUTH_NAK_TEXT_LENGTH);/*lint !e419 !e416 (Warning -- creation of out-of-bounds pointer, Apparent data overrun)*/ | |
397 /* | |
398 * set return values | |
399 */ | |
400 *forward = FORWARD_RARN; | |
401 *ptr_packet = packet; | |
402 return; | |
403 } | |
404 arb_discard_packet(ppp_data->pap.ar_packet); | |
405 ppp_data->pap.ar_packet = packet; | |
406 ppp_data->pap.nari = packet->buffer[1];/*lint !e415 (Warning -- access of out-of-bounds pointer)*/ | |
407 /* | |
408 * create Authenticate Ack packet and | |
409 * set return values | |
410 */ | |
411 pap_get_saa(ptr_packet); | |
412 *forward = FORWARD_RARP; | |
413 } /* pap_rar */ | |
414 | |
415 | |
416 | |
417 /* | |
418 +------------------------------------------------------------------------------ | |
419 | Function : pap_raa | |
420 +------------------------------------------------------------------------------ | |
421 | Description : The function pap_raa() checks whether the given | |
422 | Authenticate Ack packet is valid and if so it returns | |
423 | FORWARD_RAA. | |
424 | | |
425 | Parameters : packet - Authenticate Ack packet | |
426 | forward - returns result of analysis | |
427 | | |
428 +------------------------------------------------------------------------------ | |
429 */ | |
430 GLOBAL void pap_raa (T_desc2* packet, UBYTE* forward) | |
431 { | |
432 USHORT packet_len; | |
433 | |
434 TRACE_FUNCTION( "pap_raa" ); | |
435 | |
436 /* | |
437 * this packet can only reveiced in client mode | |
438 */ | |
439 if(ppp_data->mode NEQ PPP_CLIENT) | |
440 { | |
441 *forward = FORWARD_DISCARD; | |
442 return; | |
443 } | |
444 /* | |
445 * check correct length | |
446 */ | |
447 packet_len = packet->buffer[2];/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer)*/ | |
448 packet_len = packet_len << 8; | |
449 packet_len+= packet->buffer[3];/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer)*/ | |
450 if((packet_len < 5) || (packet_len > packet->len)) | |
451 { | |
452 *forward = FORWARD_DISCARD; | |
453 return; | |
454 } | |
455 | |
456 if(packet->buffer[1] NEQ ppp_data->pap.nari)/*lint !e415 (Warning -- access of out-of-bounds pointer)*/ | |
457 { | |
458 /* | |
459 * invalid packet | |
460 */ | |
461 *forward = FORWARD_DISCARD; | |
462 return; | |
463 } | |
464 /* | |
465 * acceptable packet | |
466 */ | |
467 arb_discard_packet(packet); | |
468 ppp_data->pap.nari++; | |
469 *forward = FORWARD_RAA; | |
470 } /* pap_raa */ | |
471 | |
472 | |
473 | |
474 /* | |
475 +------------------------------------------------------------------------------ | |
476 | Function : pap_ran | |
477 +------------------------------------------------------------------------------ | |
478 | Description : The function pap_ran() checks whether the given | |
479 | Authenticate Nak packet is valid and if so it returns | |
480 | FORWARD_RAN. | |
481 | | |
482 | Parameters : packet - Authenticate Nak packet | |
483 | forward - returns result of analysis | |
484 | | |
485 +------------------------------------------------------------------------------ | |
486 */ | |
487 GLOBAL void pap_ran (T_desc2* packet, UBYTE* forward) | |
488 { | |
489 USHORT packet_len; | |
490 | |
491 TRACE_FUNCTION( "pap_ran" ); | |
492 | |
493 /* | |
494 * this packet can only reveiced in client mode | |
495 */ | |
496 if(ppp_data->mode NEQ PPP_CLIENT) | |
497 { | |
498 *forward = FORWARD_DISCARD; | |
499 return; | |
500 } | |
501 /* | |
502 * check correct length | |
503 */ | |
504 packet_len = packet->buffer[2];/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer)*/ | |
505 packet_len = packet_len << 8; | |
506 packet_len+= packet->buffer[3];/*lint !e415 !e416 (Warning -- access/creation of out-of-bounds pointer)*/ | |
507 if((packet_len < 5) || (packet_len > packet->len)) | |
508 { | |
509 *forward = FORWARD_DISCARD; | |
510 return; | |
511 } | |
512 | |
513 if(packet->buffer[1] NEQ ppp_data->pap.nari)/*lint !e415 (Warning -- access of out-of-bounds pointer)*/ | |
514 { | |
515 /* | |
516 * invalid packet | |
517 */ | |
518 *forward = FORWARD_DISCARD; | |
519 return; | |
520 } | |
521 /* | |
522 * acceptable packet | |
523 */ | |
524 arb_discard_packet(packet); | |
525 *forward = FORWARD_RAN; | |
526 } /* pap_ran */ |