blob: 9dce14f2ed80371ddab320251bc40df35efe6f25 [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 *
oliverschmidta0f331a2004-08-22 21:10:02 +000044 * $Id: pap.c,v 1.2 2004/08/22 21:10:02 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
57#define DEBUG1(x) printf x
58
59/*#include "time.h"*/
60/*#include "utils.h" */
61#define TIMER_expire()
62#define TIMER_set()
63#define TIMER_timeout(x) 1
64
65
66u8_t pap_state;
67
oliverschmidta0f331a2004-08-22 21:10:02 +000068u8_t pap_username[PAP_USERNAME_SIZE];
69u8_t pap_password[PAP_PASSWORD_SIZE];
70
oliverschmidt3396e9a2004-08-20 12:29:54 +000071/*u16_t pap_tx_time;
72 u8_t pap_timeout;*/
73
74/*---------------------------------------------------------------------------*/
75void
76pap_init(void)
77{
78 ppp_retry = 0; /* We reuse ppp_retry */
79 pap_state = 0;
80}
81/*---------------------------------------------------------------------------*/
82/* pap_rx() - PAP RX protocol Handler */
83/*---------------------------------------------------------------------------*/
84void
85pap_rx(u8_t *buffer, u16_t count)
86{
87 u8_t *bptr=buffer;
88 u8_t len;
89
90 switch(*bptr++) {
91 case CONF_REQ:
92 DEBUG1(("CONF ACK - only for server, no support\n"));
93 break;
94 case CONF_ACK: /* config Ack */
95 DEBUG1(("CONF ACK - PAP good - "));
96 /* Display message if debug */
97 len = *bptr++;
98 *(bptr + len) = 0;
99 DEBUG1((" %s \n",bptr));
100 pap_state |= PAP_TX_UP;
101 /* expire the timer to make things happen after a state change */
102 TIMER_expire();
103 break;
104 case CONF_NAK:
105 DEBUG1(("CONF NAK - Failed Auth - "));
106 pap_state |= PAP_TX_AUTH_FAIL;
107 /* display message if debug */
108 len = *bptr++;
109 *(bptr + len)=0;
110 DEBUG1((" %s \n",bptr));
111 break;
112 }
113}
114/*---------------------------------------------------------------------------*/
115/* pap_task() - This task needs to be called every so often during the PAP
116 * negotiation phase. This task sends PAP REQ packets.
117 */
118/*---------------------------------------------------------------------------*/
119void
oliverschmidta0f331a2004-08-22 21:10:02 +0000120pap_task(u8_t *buffer)
oliverschmidt3396e9a2004-08-20 12:29:54 +0000121{
122 u8_t *bptr;
123 u16_t t;
124 PAPPKT *pkt;
125
126 /* If LCP is up and PAP negotiated, try to bring up PAP */
127 if(!(pap_state & PAP_TX_UP) && !(pap_state & PAP_TX_TIMEOUT)) {
128 /* Do we need to send a PAP auth packet?
129 Check if we have a request pending*/
130 if(1 == TIMER_timeout(PAP_TIMEOUT)) {
131 /* Check if we have a request pending */
132 /* t=get_seconds()-pap_tx_time;
133 if( t > pap_timeout)
134 {
135 */
136 /* We need to send a PAP authentication request */
137 DEBUG1(("\nSending PAP Request packet - "));
138
139 /* Build a PAP request packet */
140 pkt = (PAPPKT *)buffer;
141
142 /* Configure-Request only here, write id */
143 pkt->code = CONF_REQ;
144 pkt->id = ppp_id;
145 bptr = pkt->data;
146
147 /* Write options */
oliverschmidta0f331a2004-08-22 21:10:02 +0000148 t = strlen(pap_username);
oliverschmidt3396e9a2004-08-20 12:29:54 +0000149 /* Write peer length */
150 *bptr++ = (u8_t)t;
oliverschmidta0f331a2004-08-22 21:10:02 +0000151 bptr = memcpy(bptr, pap_username, t);
oliverschmidt3396e9a2004-08-20 12:29:54 +0000152
oliverschmidta0f331a2004-08-22 21:10:02 +0000153 t = strlen(pap_password);
oliverschmidt3396e9a2004-08-20 12:29:54 +0000154 *bptr++ = (u8_t)t;
oliverschmidta0f331a2004-08-22 21:10:02 +0000155 bptr = memcpy(bptr, pap_password, t);
oliverschmidt3396e9a2004-08-20 12:29:54 +0000156
157 /* Write length */
158 t = bptr - buffer;
159 /* length here - code and ID + */
160 pkt->len = htons(t);
161
162 DEBUG1((" Len %d\n",t));
163
164 /* Send packet */
165 ahdlc_tx(PAP, buffer, 0, t, 0);
166
167 /* Set timer */
168 TIMER_set();
169
170 ppp_retry++;
171
172 /* Have we failed? */
173 if(ppp_retry > 3) {
174 DEBUG1(("PAP - timout\n"));
175 pap_state &= PAP_TX_TIMEOUT;
176
177 }
178 }
179 }
180}
181/*---------------------------------------------------------------------------*/