blob: 9e55220ce7c4e57f5f65bb59c53f53e43231fd42 [file] [log] [blame]
oliverschmidt3396e9a2004-08-20 12:29:54 +00001/*www.mycal.net
2 *---------------------------------------------------------------------------
3 *pap.c - PAP processor for the PPP module - -
4 *---------------------------------------------------------------------------
5 *Version - 0.1 Original Version Jun 3, 2000 - -
6 *---------------------------------------------------------------------------
7 *- Copyright (C) 2000, Mycal Labs www.mycal.com - -
8 *---------------------------------------------------------------------------
9*/
10/*
11 * Copyright (c) 2003, Mike Johnson, Mycal Labs, www.mycal.net
12 * All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 * This product includes software developed by Mike Johnson/Mycal Labs
25 * www.mycal.net.
26 * 4. The name of the author may not be used to endorse or promote
27 * products derived from this software without specific prior
28 * written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
31 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
34 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
36 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * This file is part of the Mycal Modified uIP TCP/IP stack.
43 *
oliverschmidt85729cb2005-01-26 23:36:22 +000044 * $Id: pap.c,v 1.4 2005/01/26 23:36:22 oliverschmidt Exp $
oliverschmidt3396e9a2004-08-20 12:29:54 +000045 *
46 */
47
48/* */
49/* include files */
50/* */
51
52#include <string.h>
53#include "ppp.h"
54#include "pap.h"
55#include "lcp.h"
56
oliverschmidt85729cb2005-01-26 23:36:22 +000057#if 0
oliverschmidtacc63952004-08-29 15:11:45 +000058#define DEBUG1(x)
59#else
60#include <stdio.h>
oliverschmidt85729cb2005-01-26 23:36:22 +000061#define DEBUG1(x) debug_printf x
oliverschmidtacc63952004-08-29 15:11:45 +000062#endif
oliverschmidt3396e9a2004-08-20 12:29:54 +000063
64/*#include "time.h"*/
65/*#include "utils.h" */
66#define TIMER_expire()
67#define TIMER_set()
68#define TIMER_timeout(x) 1
69
70
71u8_t pap_state;
72
oliverschmidta0f331a2004-08-22 21:10:02 +000073u8_t pap_username[PAP_USERNAME_SIZE];
74u8_t pap_password[PAP_PASSWORD_SIZE];
75
oliverschmidt3396e9a2004-08-20 12:29:54 +000076/*u16_t pap_tx_time;
77 u8_t pap_timeout;*/
78
79/*---------------------------------------------------------------------------*/
80void
81pap_init(void)
82{
83 ppp_retry = 0; /* We reuse ppp_retry */
84 pap_state = 0;
85}
86/*---------------------------------------------------------------------------*/
87/* pap_rx() - PAP RX protocol Handler */
88/*---------------------------------------------------------------------------*/
89void
90pap_rx(u8_t *buffer, u16_t count)
91{
92 u8_t *bptr=buffer;
93 u8_t len;
94
95 switch(*bptr++) {
96 case CONF_REQ:
97 DEBUG1(("CONF ACK - only for server, no support\n"));
98 break;
99 case CONF_ACK: /* config Ack */
100 DEBUG1(("CONF ACK - PAP good - "));
101 /* Display message if debug */
102 len = *bptr++;
103 *(bptr + len) = 0;
104 DEBUG1((" %s \n",bptr));
105 pap_state |= PAP_TX_UP;
106 /* expire the timer to make things happen after a state change */
107 TIMER_expire();
108 break;
109 case CONF_NAK:
110 DEBUG1(("CONF NAK - Failed Auth - "));
111 pap_state |= PAP_TX_AUTH_FAIL;
112 /* display message if debug */
113 len = *bptr++;
114 *(bptr + len)=0;
115 DEBUG1((" %s \n",bptr));
116 break;
117 }
118}
119/*---------------------------------------------------------------------------*/
120/* pap_task() - This task needs to be called every so often during the PAP
121 * negotiation phase. This task sends PAP REQ packets.
122 */
123/*---------------------------------------------------------------------------*/
124void
oliverschmidta0f331a2004-08-22 21:10:02 +0000125pap_task(u8_t *buffer)
oliverschmidt3396e9a2004-08-20 12:29:54 +0000126{
127 u8_t *bptr;
128 u16_t t;
129 PAPPKT *pkt;
130
131 /* If LCP is up and PAP negotiated, try to bring up PAP */
132 if(!(pap_state & PAP_TX_UP) && !(pap_state & PAP_TX_TIMEOUT)) {
133 /* Do we need to send a PAP auth packet?
134 Check if we have a request pending*/
135 if(1 == TIMER_timeout(PAP_TIMEOUT)) {
136 /* Check if we have a request pending */
137 /* t=get_seconds()-pap_tx_time;
138 if( t > pap_timeout)
139 {
140 */
141 /* We need to send a PAP authentication request */
142 DEBUG1(("\nSending PAP Request packet - "));
143
144 /* Build a PAP request packet */
145 pkt = (PAPPKT *)buffer;
146
147 /* Configure-Request only here, write id */
148 pkt->code = CONF_REQ;
149 pkt->id = ppp_id;
150 bptr = pkt->data;
151
152 /* Write options */
oliverschmidta0f331a2004-08-22 21:10:02 +0000153 t = strlen(pap_username);
oliverschmidt3396e9a2004-08-20 12:29:54 +0000154 /* Write peer length */
155 *bptr++ = (u8_t)t;
oliverschmidta0f331a2004-08-22 21:10:02 +0000156 bptr = memcpy(bptr, pap_username, t);
oliverschmidt3396e9a2004-08-20 12:29:54 +0000157
oliverschmidta0f331a2004-08-22 21:10:02 +0000158 t = strlen(pap_password);
oliverschmidt3396e9a2004-08-20 12:29:54 +0000159 *bptr++ = (u8_t)t;
oliverschmidta0f331a2004-08-22 21:10:02 +0000160 bptr = memcpy(bptr, pap_password, t);
oliverschmidt3396e9a2004-08-20 12:29:54 +0000161
162 /* Write length */
163 t = bptr - buffer;
164 /* length here - code and ID + */
165 pkt->len = htons(t);
166
167 DEBUG1((" Len %d\n",t));
168
169 /* Send packet */
170 ahdlc_tx(PAP, buffer, 0, t, 0);
171
172 /* Set timer */
173 TIMER_set();
174
175 ppp_retry++;
176
177 /* Have we failed? */
178 if(ppp_retry > 3) {
179 DEBUG1(("PAP - timout\n"));
180 pap_state &= PAP_TX_TIMEOUT;
181
182 }
183 }
184 }
185}
186/*---------------------------------------------------------------------------*/