OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [lwip_tcpip/] [current/] [include/] [netif/] [ppp/] [ppp.h] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/*****************************************************************************
2
* ppp.h - Network Point to Point Protocol header file.
3
*
4
* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
5
* portions Copyright (c) 1997 Global Election Systems Inc.
6
*
7
* The authors hereby grant permission to use, copy, modify, distribute,
8
* and license this software and its documentation for any purpose, provided
9
* that existing copyright notices are retained in all copies and that this
10
* notice and the following disclaimer are included verbatim in any
11
* distributions. No written agreement, license, or royalty fee is required
12
* for any of the authorized uses.
13
*
14
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
15
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
*
25
******************************************************************************
26
* REVISION HISTORY
27
*
28
* 03-01-01 Marc Boucher <marc@mbsi.ca>
29
*   Ported to lwIP.
30
* 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
31
*   Original derived from BSD codes.
32
*****************************************************************************/
33
 
34
#ifndef PPP_H
35
#define PPP_H
36
 
37
#include "lwip/opt.h"
38
 
39
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
40
 
41
#include "lwip/def.h"
42
#include "lwip/sio.h"
43
#include "lwip/api.h"
44
#include "lwip/sockets.h"
45
#include "lwip/stats.h"
46
#include "lwip/mem.h"
47
#include "lwip/tcpip.h"
48
#include "lwip/pbuf.h"
49
#include "lwip/netif.h"
50
 
51
/*
52
 * pppd.h - PPP daemon global declarations.
53
 *
54
 * Copyright (c) 1989 Carnegie Mellon University.
55
 * All rights reserved.
56
 *
57
 * Redistribution and use in source and binary forms are permitted
58
 * provided that the above copyright notice and this paragraph are
59
 * duplicated in all such forms and that any documentation,
60
 * advertising materials, and other materials related to such
61
 * distribution and use acknowledge that the software was developed
62
 * by Carnegie Mellon University.  The name of the
63
 * University may not be used to endorse or promote products derived
64
 * from this software without specific prior written permission.
65
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
66
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
67
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
68
 *
69
 */
70
/*
71
 * ppp_defs.h - PPP definitions.
72
 *
73
 * Copyright (c) 1994 The Australian National University.
74
 * All rights reserved.
75
 *
76
 * Permission to use, copy, modify, and distribute this software and its
77
 * documentation is hereby granted, provided that the above copyright
78
 * notice appears in all copies.  This software is provided without any
79
 * warranty, express or implied. The Australian National University
80
 * makes no representations about the suitability of this software for
81
 * any purpose.
82
 *
83
 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
84
 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
85
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
86
 * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
87
 * OF SUCH DAMAGE.
88
 *
89
 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
90
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
91
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
92
 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
93
 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
94
 * OR MODIFICATIONS.
95
 */
96
 
97
#define PPP_TMR_INTERVAL 100
98
 
99
/*
100
 * Constants and structures defined by the internet system,
101
 * Per RFC 790, September 1981, and numerous additions.
102
 */
103
 
104
/*
105
 * The basic PPP frame.
106
 */
107
#define PPP_HDRLEN      4       /* octets for standard ppp header */
108
#define PPP_FCSLEN      2       /* octets for FCS */
109
 
110
 
111
/*
112
 * Significant octet values.
113
 */
114
#define PPP_ALLSTATIONS 0xff    /* All-Stations broadcast address */
115
#define PPP_UI          0x03    /* Unnumbered Information */
116
#define PPP_FLAG        0x7e    /* Flag Sequence */
117
#define PPP_ESCAPE      0x7d    /* Asynchronous Control Escape */
118
#define PPP_TRANS       0x20    /* Asynchronous transparency modifier */
119
 
120
/*
121
 * Protocol field values.
122
 */
123
#define PPP_IP          0x21    /* Internet Protocol */
124
#define PPP_AT          0x29    /* AppleTalk Protocol */
125
#define PPP_VJC_COMP    0x2d    /* VJ compressed TCP */
126
#define PPP_VJC_UNCOMP  0x2f    /* VJ uncompressed TCP */
127
#define PPP_COMP        0xfd    /* compressed packet */
128
#define PPP_IPCP        0x8021  /* IP Control Protocol */
129
#define PPP_ATCP        0x8029  /* AppleTalk Control Protocol */
130
#define PPP_CCP         0x80fd  /* Compression Control Protocol */
131
#define PPP_LCP         0xc021  /* Link Control Protocol */
132
#define PPP_PAP         0xc023  /* Password Authentication Protocol */
133
#define PPP_LQR         0xc025  /* Link Quality Report protocol */
134
#define PPP_CHAP        0xc223  /* Cryptographic Handshake Auth. Protocol */
135
#define PPP_CBCP        0xc029  /* Callback Control Protocol */
136
 
137
/*
138
 * Values for FCS calculations.
139
 */
140
#define PPP_INITFCS     0xffff  /* Initial FCS value */
141
#define PPP_GOODFCS     0xf0b8  /* Good final FCS value */
142
#define PPP_FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
143
 
144
/*
145
 * Extended asyncmap - allows any character to be escaped.
146
 */
147
typedef u8_t  ext_accm[32];
148
 
149
/*
150
 * What to do with network protocol (NP) packets.
151
 */
152
enum ppp_np_mode {
153
  NPMODE_PASS,        /* pass the packet through */
154
  NPMODE_DROP,        /* silently drop the packet */
155
  NPMODE_ERROR,       /* return an error */
156
  NPMODE_QUEUE        /* save it up for later. */
157
};
158
 
159
/*
160
 * Inline versions of get/put char/short/long.
161
 * Pointer is advanced; we assume that both arguments
162
 * are lvalues and will already be in registers.
163
 * cp MUST be u8_t *.
164
 */
165
#define GETCHAR(c, cp) { \
166
    (c) = *(cp)++; \
167
}
168
#define PUTCHAR(c, cp) { \
169
    *(cp)++ = (u8_t) (c); \
170
}
171
 
172
 
173
#define GETSHORT(s, cp) { \
174
    (s) = *(cp); (cp)++; (s) <<= 8; \
175
    (s) |= *(cp); (cp)++; \
176
}
177
#define PUTSHORT(s, cp) { \
178
    *(cp)++ = (u8_t) ((s) >> 8); \
179
    *(cp)++ = (u8_t) (s & 0xff); \
180
}
181
 
182
#define GETLONG(l, cp) { \
183
    (l) = *(cp); (cp)++; (l) <<= 8; \
184
    (l) |= *(cp); (cp)++; (l) <<= 8; \
185
    (l) |= *(cp); (cp)++; (l) <<= 8; \
186
    (l) |= *(cp); (cp)++; \
187
}
188
#define PUTLONG(l, cp) { \
189
    *(cp)++ = (u8_t) ((l) >> 24); \
190
    *(cp)++ = (u8_t) ((l) >> 16); \
191
    *(cp)++ = (u8_t) ((l) >> 8); \
192
    *(cp)++ = (u8_t) (l); \
193
}
194
 
195
 
196
#define INCPTR(n, cp)   ((cp) += (n))
197
#define DECPTR(n, cp)   ((cp) -= (n))
198
 
199
#define BCMP(s0, s1, l)     memcmp((u8_t *)(s0), (u8_t *)(s1), (l))
200
#define BCOPY(s, d, l)      MEMCPY((d), (s), (l))
201
#define BZERO(s, n)         memset(s, 0, n)
202
 
203
#if PPP_DEBUG
204
#define PRINTMSG(m, l)  { m[l] = '\0'; ppp_trace(LOG_INFO, "Remote message: %s\n", m); }
205
#else  /* PPP_DEBUG */
206
#define PRINTMSG(m, l)
207
#endif /* PPP_DEBUG */
208
 
209
/*
210
 * MAKEHEADER - Add PPP Header fields to a packet.
211
 */
212
#define MAKEHEADER(p, t) { \
213
    PUTCHAR(PPP_ALLSTATIONS, p); \
214
    PUTCHAR(PPP_UI, p); \
215
    PUTSHORT(t, p); }
216
 
217
/*************************
218
*** PUBLIC DEFINITIONS ***
219
*************************/
220
 
221
/* Error codes. */
222
#define PPPERR_NONE      0 /* No error. */
223
#define PPPERR_PARAM    -1 /* Invalid parameter. */
224
#define PPPERR_OPEN     -2 /* Unable to open PPP session. */
225
#define PPPERR_DEVICE   -3 /* Invalid I/O device for PPP. */
226
#define PPPERR_ALLOC    -4 /* Unable to allocate resources. */
227
#define PPPERR_USER     -5 /* User interrupt. */
228
#define PPPERR_CONNECT  -6 /* Connection lost. */
229
#define PPPERR_AUTHFAIL -7 /* Failed authentication challenge. */
230
#define PPPERR_PROTOCOL -8 /* Failed to meet protocol. */
231
 
232
/*
233
 * PPP IOCTL commands.
234
 */
235
/*
236
 * Get the up status - 0 for down, non-zero for up.  The argument must
237
 * point to an int.
238
 */
239
#define PPPCTLG_UPSTATUS 100 /* Get the up status - 0 down else up */
240
#define PPPCTLS_ERRCODE  101 /* Set the error code */
241
#define PPPCTLG_ERRCODE  102 /* Get the error code */
242
#define PPPCTLG_FD       103 /* Get the fd associated with the ppp */
243
 
244
/************************
245
*** PUBLIC DATA TYPES ***
246
************************/
247
 
248
/*
249
 * The following struct gives the addresses of procedures to call
250
 * for a particular protocol.
251
 */
252
struct protent {
253
  u16_t protocol;           /* PPP protocol number */
254
  /* Initialization procedure */
255
  void (*init) (int unit);
256
  /* Process a received packet */
257
  void (*input) (int unit, u8_t *pkt, int len);
258
  /* Process a received protocol-reject */
259
  void (*protrej) (int unit);
260
  /* Lower layer has come up */
261
  void (*lowerup) (int unit);
262
  /* Lower layer has gone down */
263
  void (*lowerdown) (int unit);
264
  /* Open the protocol */
265
  void (*open) (int unit);
266
  /* Close the protocol */
267
  void (*close) (int unit, char *reason);
268
#if 0
269
  /* Print a packet in readable form */
270
  int  (*printpkt) (u8_t *pkt, int len, void (*printer) (void *, char *, ...),
271
                    void *arg);
272
  /* Process a received data packet */
273
  void (*datainput) (int unit, u8_t *pkt, int len);
274
#endif
275
  int enabled_flag;         /* 0 if protocol is disabled */
276
  char *name;               /* Text name of protocol */
277
#if 0
278
  /* Check requested options, assign defaults */
279
  void (*check_options) (u32_t);
280
  /* Configure interface for demand-dial */
281
  int  (*demand_conf) (int unit);
282
  /* Say whether to bring up link for this pkt */
283
  int  (*active_pkt) (u8_t *pkt, int len);
284
#endif
285
};
286
 
287
/*
288
 * The following structure records the time in seconds since
289
 * the last NP packet was sent or received.
290
 */
291
struct ppp_idle {
292
  u16_t xmit_idle;      /* seconds since last NP packet sent */
293
  u16_t recv_idle;      /* seconds since last NP packet received */
294
};
295
 
296
struct ppp_settings {
297
  u32_t disable_defaultip : 1;          /* Don't use hostname for default IP addrs */
298
  u32_t auth_required     : 1;          /* Peer is required to authenticate */
299
  u32_t explicit_remote   : 1;          /* remote_name specified with remotename opt */
300
  u32_t refuse_pap        : 1;          /* Don't wanna auth. ourselves with PAP */
301
  u32_t refuse_chap       : 1;          /* Don't wanna auth. ourselves with CHAP */
302
  u32_t usehostname       : 1;          /* Use hostname for our_name */
303
  u32_t usepeerdns        : 1;          /* Ask peer for DNS adds */
304
 
305
  u16_t idle_time_limit;                /* Shut down link if idle for this long */
306
  int maxconnect;                       /* Maximum connect time (seconds) */
307
 
308
  char user       [MAXNAMELEN   + 1];   /* Username for PAP */
309
  char passwd     [MAXSECRETLEN + 1];   /* Password for PAP, secret for CHAP */
310
  char our_name   [MAXNAMELEN   + 1];   /* Our name for authentication purposes */
311
  char remote_name[MAXNAMELEN   + 1];   /* Peer's name for authentication */
312
};
313
 
314
struct ppp_addrs {
315
  struct ip_addr our_ipaddr, his_ipaddr, netmask, dns1, dns2;
316
};
317
 
318
/*****************************
319
*** PUBLIC DATA STRUCTURES ***
320
*****************************/
321
 
322
/* Buffers for outgoing packets. */
323
extern u8_t *outpacket_buf[NUM_PPP];
324
 
325
extern struct ppp_settings ppp_settings;
326
 
327
extern struct protent *ppp_protocols[]; /* Table of pointers to supported protocols */
328
 
329
 
330
/***********************
331
*** PUBLIC FUNCTIONS ***
332
***********************/
333
 
334
/* PPP link status callback */
335
typedef void (*ppp_status_cb_t)(void *ctx, int err, void *arg);
336
 
337
 
338
/* Initialize the PPP subsystem. */
339
err_t ppp_init(void);
340
 
341
/**
342
 * This should be called every PPP_TMR_INTERVAL milliseconds.
343
 */
344
void ppp_tmr(void);
345
 
346
/* Warning: Using PPPAUTHTYPE_ANY might have security consequences.
347
 * RFC 1994 says:
348
 *
349
 * In practice, within or associated with each PPP server, there is a
350
 * database which associates "user" names with authentication
351
 * information ("secrets").  It is not anticipated that a particular
352
 * named user would be authenticated by multiple methods.  This would
353
 * make the user vulnerable to attacks which negotiate the least secure
354
 * method from among a set (such as PAP rather than CHAP).  If the same
355
 * secret was used, PAP would reveal the secret to be used later with
356
 * CHAP.
357
 *
358
 * Instead, for each user name there should be an indication of exactly
359
 * one method used to authenticate that user name.  If a user needs to
360
 * make use of different authentication methods under different
361
 * circumstances, then distinct user names SHOULD be employed, each of
362
 * which identifies exactly one authentication method.
363
 *
364
 */
365
enum ppp_auth_type {
366
    PPPAUTHTYPE_NONE,
367
    PPPAUTHTYPE_ANY,
368
    PPPAUTHTYPE_PAP,
369
    PPPAUTHTYPE_CHAP
370
};
371
 
372
void ppp_set_auth(enum ppp_auth_type auth_type, const char *user, const char *passwd);
373
 
374
/*
375
 * Open a new PPP connection using the given serial I/O device.
376
 * This initializes the PPP control block but does not
377
 * attempt to negotiate the LCP session.
378
 * Return a new PPP connection descriptor on success or
379
 * an error code (negative) on failure.
380
 */
381
int ppp_open_serial(sio_fd_t fd, ppp_status_cb_t status_cb, void *status_ctx);
382
 
383
 
384
/*
385
 * Open a new PPP Over Ethernet (PPPOE) connection.
386
 */
387
int ppp_open_ethernet(struct netif *ethif,
388
                      const char *service_name, const char *concentrator_name,
389
                      ppp_status_cb_t status_cb, void *status_ctx);
390
 
391
 
392
void ppp_poll(int pd);
393
 
394
/*
395
 * Close a PPP connection and release the descriptor.
396
 * Any outstanding packets in the queues are dropped.
397
 * Return 0 on success, an error code on failure.
398
 */
399
int ppp_close(int pd);
400
 
401
/*
402
 * Check if the PPP connection is open.
403
 */
404
int ppp_is_open(int pd);
405
 
406
/*
407
 * Indicate to the PPP process that the line has disconnected.
408
 */
409
void ppp_sig_hup(int pd);
410
 
411
/*
412
 * Get and set parameters for the given connection.
413
 * Return 0 on success, an error code on failure.
414
 */
415
int ppp_ioctl(int pd, int cmd, void *arg);
416
 
417
/*
418
 * Return the Maximum Transmission Unit for the given PPP connection.
419
 */
420
u32_t ppp_mtu(int pd);
421
 
422
/*
423
 * Write n characters to a ppp link.
424
 * RETURN: >= 0 Number of characters written, -1 Failed to write to device.
425
 */
426
int ppp_write(int pd, const u8_t *s, int n);
427
 
428
void ppp_in_proc_over_ethernet(int pd, struct pbuf *pb);
429
 
430
struct pbuf *ppp_single_buf(struct pbuf *p);
431
 
432
void ppp_link_terminated(int pd);
433
 
434
void ppp_link_down(int pd);
435
 
436
void ppp_main_wakeup(int pd);
437
 
438
 
439
/* Configure i/f transmit parameters */
440
void ppp_send_config (int, int, u32_t, int, int);
441
/* Set extended transmit ACCM */
442
void ppp_set_xaccm (int, ext_accm *);
443
/* Configure i/f receive parameters */
444
void ppp_recv_config (int, int, u32_t, int, int);
445
/* Find out how long link has been idle */
446
int  get_idle_time (int, struct ppp_idle *);
447
 
448
/* Configure VJ TCP header compression */
449
int  sifvjcomp (int, int, int, int);
450
/* Configure i/f down (for IP) */
451
int  sifup (int);
452
/* Set mode for handling packets for proto */
453
int  sifnpmode (int u, int proto, enum ppp_np_mode mode);
454
/* Configure i/f down (for IP) */
455
int  sifdown (int);
456
/* Configure IP addresses for i/f */
457
int  sifaddr (int, u32_t, u32_t, u32_t, u32_t, u32_t);
458
/* Reset i/f IP addresses */
459
int  cifaddr (int, u32_t, u32_t);
460
/* Create default route through i/f */
461
int  sifdefaultroute (int, u32_t, u32_t);
462
/* Delete default route through i/f */
463
int  cifdefaultroute (int, u32_t, u32_t);
464
 
465
/* Get appropriate netmask for address */
466
u32_t GetMask (u32_t);
467
 
468
#endif /* PPP_SUPPORT */
469
 
470
#endif /* PPP_H */

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.