summaryrefslogtreecommitdiffstats
path: root/gatchat/ppp_cp.h
blob: 8d2975c1895027d291ef062b93dee5b1fec67b14 (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
/*
 *
 *  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
};

/* 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_data {
	unsigned char state;
	struct pppcp_timer_data config_timer_data;
	struct pppcp_timer_data terminate_timer_data;
	guint max_failure;
	guint failure_counter;
	guint32 magic_number;
	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);
	gpointer priv;
	guint16 proto;
	const char *prefix;
	const char **option_strings;
};

struct pppcp_data *pppcp_new(GAtPPP *ppp, guint16 proto);
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_process_packet(gpointer priv, guint8 *new_packet);
void pppcp_send_protocol_reject(struct pppcp_data *data,
				guint8 *rejected_packet, gsize len);
void pppcp_signal_open(struct pppcp_data *data);
void pppcp_signal_close(struct pppcp_data *data);
void pppcp_signal_up(struct pppcp_data *data);