comparison network/PPP.h @ 107:56d09a0969b5 avr-http

Import uIP and the PPP implementation from https://code.google.com/p/avrusbmodem/
author Matt Johnston <matt@ucc.asn.au>
date Fri, 07 Sep 2012 23:53:53 +0800
parents
children
comparison
equal deleted inserted replaced
106:5c8404549cc0 107:56d09a0969b5
1 /*
2 LUFA Powered Wireless 3G Modem Host
3
4 Copyright (C) Mike Alexander, 2010.
5 Copyright (C) Dean Camera, 2010.
6 */
7
8 /*
9 Copyright 2010 Mike Alexander (mike [at] mikealex [dot] com)
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 #ifndef _PPP_H_
32 #define _PPP_H_
33
34 /* Includes: */
35 #include <util/crc16.h>
36 #include <stdbool.h>
37 #include <stdint.h>
38
39 #include "LinkManagement.h"
40 #include "Lib/RingBuff.h"
41 #include "Lib/Debug.h"
42
43 /* Enums: */
44
45 typedef enum
46 {
47 PPP_LAYER_Physical,
48 PPP_LAYER_Authentication,
49 PPP_LAYER_Network,
50 } PPP_Layers_t;
51
52 typedef enum
53 {
54 PPP_PHASE_Dead,
55 PPP_PHASE_Establish,
56 PPP_PHASE_Authenticate,
57 PPP_PHASE_Network,
58 PPP_PHASE_Terminate
59 } PPP_Phases_t;
60
61 typedef enum
62 {
63 PPP_STATE_Initial,
64 PPP_STATE_Starting,
65 PPP_STATE_Closed,
66 PPP_STATE_Stopped,
67 PPP_STATE_Closing,
68 PPP_STATE_Stopping,
69 PPP_STATE_Req_Sent,
70 PPP_STATE_Ack_Rcvd,
71 PPP_STATE_Ack_Sent,
72 PPP_STATE_Opened
73 } PPP_States_t;
74
75 typedef enum
76 {
77 PPP_EVENT_Up,
78 PPP_EVENT_Down,
79 PPP_EVENT_Open,
80 PPP_EVENT_Close,
81 PPP_EVENT_TOPlus,
82 PPP_EVENT_TOMinus,
83 PPP_EVENT_RCRPlus,
84 PPP_EVENT_RCRMinus,
85 PPP_EVENT_RCA,
86 PPP_EVENT_RCN,
87 PPP_EVENT_RTR,
88 PPP_EVENT_RTA,
89 PPP_EVENT_RUC,
90 PPP_EVENT_RXJPlus,
91 PPP_EVENT_RXJMinus,
92 PPP_EVENT_RXR
93 } PPP_Events_t;
94
95 /* Type Defines: */
96 typedef struct
97 {
98 uint8_t Type;
99 uint8_t Length;
100 uint8_t Data[];
101 } PPP_Option_t;
102
103 typedef struct
104 {
105 uint8_t Code;
106 uint8_t PacketID;
107 uint16_t Length;
108 PPP_Option_t Options[];
109 } PPP_Packet_t;
110
111 /* Macros: */
112 #define CALC_CRC16(crcvalue, c) _crc_ccitt_update(crcvalue, c);
113
114 // Defines for LCP Negotiation Codes
115 #define REQ 1 // Request options list for PPP negotiations
116 #define ACK 2 // Acknowledge options list for PPP negotiations
117 #define NAK 3 // Not acknowledged options list for PPP negotiations
118 #define REJ 4 // Reject options list for PPP negotiations
119 #define TERMREQ 5 // Termination request for LCP to close connection
120 #define TERMREPLY 6 // Termination reply
121 #define CODEREJ 7 // Code reject
122 #define PROTREJ 8 // Protocol reject
123 #define ECHOREQ 9 // Echo Request
124 #define ECHOREPLY 10 // Echo Reply
125 #define DISC 11 // Discard request
126
127 // Packet Types (Protocols)
128 #define IP 0x0021 // Internet Protocol packet
129 #define IPCP 0x8021 // Internet Protocol Configure Protocol packet
130 #define LCP 0xC021 // Link Configure Protocol packet
131 #define PAP 0xC023 // Password Authentication Protocol packet
132 #define CHAP 0xC223 // Challenge Handshake Authentication Protocol packet
133 #define NONE 0x0000
134
135 #define LCP_OPTION_Maximum_Receive_Unit 0x1 // LCP Option 1
136 #define LCP_OPTION_Async_Control_Character_Map 0x2 // LCP Option 2
137 #define LCP_OPTION_Authentication_Protocol 0x3 // LCP Option 3
138 #define LCP_OPTION_Quality_Protocol 0x4 // LCP Option 4
139 #define LCP_OPTION_Magic_Number 0x5 // LCP Option 5
140 #define LCP_OPTION_Reserved 0x6 // LCP Option 6
141 #define LCP_OPTION_Protocol_Field_Compression 0x7 // LCP Option 7
142 #define LCP_OPTION_Address_and_Control_Field_Compression 0x8 // LCP Option 8
143 #define LCP_OPTION_Callback 0xd // LCP Option D
144
145 #define IPCP_OPTION_IP_Compression_Protocol 0x2 // IPCP Option 2
146 #define IPCP_OPTION_IP_address 0x3 // IPCP Option 3
147 #define IPCP_OPTION_Primary_DNS 0x81 // IPCP Option 81
148 #define IPCP_OPTION_Secondary_DNS 0x83 // IPCP Option 83
149
150 #define MAX_RESTARTS 5
151 #define OUTGOING_PACKET_BUFFER_SIZE 48
152
153 /* External Variables: */
154 extern uint8_t ConnectedState;
155
156 /* Function Prototypes: */
157 void PPP_ManageLink(void);
158 void PPP_InitPPP(void);
159 void PPP_LinkTimer(void);
160 void PPP_LinkUp(void);
161 void PPP_LinkOpen(void);
162 void PPP_StartLink(void);
163
164 #if defined(INCLUDE_FROM_PPP_C)
165 static PPP_Option_t* PPP_GetNextOption(const PPP_Packet_t* const ThisPacket,
166 const PPP_Option_t* const CurrentOption);
167 static void PPP_RemoveOption(PPP_Packet_t* const ThisPacket,
168 const uint8_t Type);
169 static void PPP_AddOption(const PPP_Option_t*);
170 static bool PPP_CheckForOption(const PPP_Option_t*);
171 static void PPP_ChangeOption(PPP_Packet_t* const ThisPacket,
172 const PPP_Option_t* const Option);
173 static void PPP_ProcessNAK(void);
174 static void PPP_ProcessREJ(void);
175 static bool PPP_TestForNAK(const PPP_Option_t* const Option);
176 static bool PPP_TestForREJ(const uint8_t Options[],
177 const uint8_t NumOptions);
178 static void PPP_ManageState(const PPP_Events_t Event,
179 PPP_States_t* const State,
180 PPP_Layers_t const Layer);
181 static void Send_Configure_Request(void);
182 static void Send_Configure_Ack(void);
183 static void Send_Configure_Nak_Rej(void);
184 static void Send_Terminate_Request(void);
185 static void Send_Terminate_Ack(void);
186 static void Send_Code_Reject(void);
187 static void Send_Echo_Reply(void);
188 static void This_Layer_Up(PPP_Layers_t Layer);
189 static void This_Layer_Down(PPP_Layers_t Layer);
190 static void This_Layer_Started(PPP_Layers_t Layer);
191 static void This_Layer_Finished(PPP_Layers_t Layer);
192 #endif
193
194 #endif
195
196