summaryrefslogtreecommitdiffstats
path: root/gatchat/ppp_cp.h
blob: 58f58b28f916338d5e6dd9b639bff93a416c71ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 *
 *  PPP library with GLib integration
 *
 *  Copyright (C) 2009-2010  Intel Corporation. All rights reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

struct pppcp_data;

enum pppcp_code {
	CONFIGURE_REQUEST = 1,
	CONFIGURE_ACK,
	CONFIGURE_NAK,
	CONFIGURE_REJECT,
	TERMINATE_REQUEST,
	TERMINATE_ACK,
	CODE_REJECT,
	PROTOCOL_REJECT,
	ECHO_REQUEST,
	ECHO_REPLY,
	DISCARD_REQUEST
};

enum pppcp_event_type {
	UP,
	DOWN,
	OPEN,
	CLOSE,
	TO_PLUS,
	TO_MINUS,
	RCR_PLUS,
	RCR_MINUS,
	RCA,
	RCN,
	RTR,
	RTA,
	RUC,
	RXJ_PLUS,
	RXJ_MINUS,
	RXR,
};

enum pppcp_state {
	INITIAL,
	STARTING,
	CLOSED,
	STOPPED,
	CLOSING,
	STOPPING,
	REQSENT,
	ACKRCVD,
	ACKSENT,
	OPENED,
};

/* option format */
struct ppp_option {
	guint8 type;
	guint8 length;
	guint8 data[0];
};

enum option_rval {
	OPTION_ACCEPT,
	OPTION_REJECT,
	OPTION_NAK,
	OPTION_ERR,
};

struct pppcp_action {
	void (*this_layer_up)(struct pppcp_data *data);
	void (*this_layer_down)(struct pppcp_data *data);
	void (*this_layer_started)(struct pppcp_data *data);
	void (*this_layer_finished)(struct pppcp_data *data);
	enum option_rval (*option_scan)(struct ppp_option *option,
						gpointer user_data);
	void (*option_process)(gpointer option, gpointer user_data);
};

struct pppcp_packet {
	guint8 code;
	guint8 identifier;
	guint16 length;
	guint8 data[0];
} __attribute__((packed));

struct pppcp_timer_data {
	struct pppcp_data *data;
	guint restart_counter;
	guint restart_interval;
	guint max_counter;
	guint restart_timer;
};

struct pppcp_protocol_data {
	guint16 proto;
	const char *prefix;
	const char **options;
	gpointer priv;
	GAtPPP *ppp;
};

struct pppcp_data {
	enum pppcp_state state;
	struct pppcp_timer_data config_timer_data;
	struct pppcp_timer_data terminate_timer_data;
	guint max_failure;
	guint32 magic_number;
	GQueue *event_queue;
	GList *config_options;
	GList *acceptable_options;
	GList *unacceptable_options;
	GList *rejected_options;
	GList *applied_options;
	GAtPPP *ppp;
	guint8 identifier;  /* don't think I need this now */
	guint8 config_identifier;
	guint8 terminate_identifier;
	guint8 reject_identifier;
	struct pppcp_action *action;
	guint16 valid_codes;
	guint8 (*packet_ops[11])(struct pppcp_data *data,
					struct pppcp_packet *packet);
	void (*event_ops[16])(struct pppcp_data *data, guint8 *packet,
				guint length);
	gpointer priv;
	guint16 proto;
	const char *prefix;
	const char **options;
};

struct pppcp_data *pppcp_new(struct pppcp_protocol_data *proto_data);
void pppcp_free(struct pppcp_data *data);
void pppcp_add_config_option(struct pppcp_data *data,
				struct ppp_option *option);
void pppcp_set_valid_codes(struct pppcp_data *data, guint16 codes);
void pppcp_generate_event(struct pppcp_data *data,
				enum pppcp_event_type event_type,
				gpointer event_data, guint data_len);
void pppcp_process_packet(gpointer priv, guint8 *new_packet);
void pppcp_send_protocol_reject(struct pppcp_data *data,
				guint8 *rejected_packet, gsize len);