Upgrade ofono to 1.2
[profile/ivi/ofono.git] / gatchat / ppp_cp.h
1 /*
2  *
3  *  PPP library with GLib integration
4  *
5  *  Copyright (C) 2009-2011  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 struct pppcp_data;
23 struct ppp_option_iter;
24
25 /* option format */
26 struct ppp_option {
27         guint8 type;
28         guint8 length;
29         guint8 data[0];
30 };
31
32 enum rcr_result {
33         RCR_ACCEPT,
34         RCR_REJECT,
35         RCR_NAK,
36 };
37
38 enum pppcp_code {
39         PPPCP_CODE_TYPE_CONFIGURE_REQUEST = 1,
40         PPPCP_CODE_TYPE_CONFIGURE_ACK,
41         PPPCP_CODE_TYPE_CONFIGURE_NAK,
42         PPPCP_CODE_TYPE_CONFIGURE_REJECT,
43         PPPCP_CODE_TYPE_TERMINATE_REQUEST,
44         PPPCP_CODE_TYPE_TERMINATE_ACK,
45         PPPCP_CODE_TYPE_CODE_REJECT,
46         PPPCP_CODE_TYPE_PROTOCOL_REJECT,
47         PPPCP_CODE_TYPE_ECHO_REQUEST,
48         PPPCP_CODE_TYPE_ECHO_REPLY,
49         PPPCP_CODE_TYPE_DISCARD_REQUEST
50 };
51
52 struct pppcp_packet {
53         guint8 code;
54         guint8 identifier;
55         guint16 length;
56         guint8 data[0];
57 } __attribute__((packed));
58
59 struct ppp_option_iter {
60         guint16 max;
61         guint16 pos;
62         const guint8 *pdata;
63         guint8 type;
64         guint8 len;
65         const guint8 *option_data;
66 };
67
68 struct pppcp_proto {
69         guint16 proto;
70         const char *name;
71         guint16 supported_codes;
72         void (*this_layer_up)(struct pppcp_data *data);
73         void (*this_layer_down)(struct pppcp_data *data);
74         void (*this_layer_started)(struct pppcp_data *data);
75         void (*this_layer_finished)(struct pppcp_data *data);
76         /* Remote side acked these options, we can now use them */
77         void (*rca)(struct pppcp_data *pppcp, const struct pppcp_packet *pkt);
78         /*
79          * Remote side sent us an Conf-Req-Nak or Conf-Req-Rej.  The protocol
80          * driver should examine the packet and update its options accordingly,
81          * then use set_local_options to set a new set of options to try
82          * before returning
83          */
84         void (*rcn_nak)(struct pppcp_data *pppcp,
85                                         const struct pppcp_packet *pkt);
86         void (*rcn_rej)(struct pppcp_data *pppcp,
87                                         const struct pppcp_packet *pkt);
88         /*
89          * Remote side has sent us a request with its options, return whether
90          * we should ack / nak / rej these options.  In the case of nak / rej,
91          * the list of options to be sent to the peer is given in the
92          * new_options & new_len out arguments
93          */
94         enum rcr_result (*rcr)(struct pppcp_data *pppcp,
95                                         const struct pppcp_packet *pkt,
96                                         guint8 **new_options, guint16 *new_len);
97 };
98
99 void ppp_option_iter_init(struct ppp_option_iter *iter,
100                                         const struct pppcp_packet *packet);
101 gboolean ppp_option_iter_next(struct ppp_option_iter *iter);
102 guint8 ppp_option_iter_get_type(struct ppp_option_iter *iter);
103 guint8 ppp_option_iter_get_length(struct ppp_option_iter *iter);
104 const guint8 *ppp_option_iter_get_data(struct ppp_option_iter *iter);
105
106 struct pppcp_data *pppcp_new(GAtPPP *ppp, const struct pppcp_proto *proto,
107                                 gboolean dormant, guint max_failure);
108 void pppcp_free(struct pppcp_data *data);
109
110 void pppcp_set_data(struct pppcp_data *pppcp, gpointer data);
111 gpointer pppcp_get_data(struct pppcp_data *pppcp);
112 GAtPPP *pppcp_get_ppp(struct pppcp_data *pppcp);
113
114 guint8 pppcp_get_code(const guint8 *data);
115
116 void pppcp_set_local_options(struct pppcp_data *data,
117                                 const guint8 *options,
118                                 guint16 len);
119
120 void pppcp_process_packet(gpointer priv, const guint8 *new_packet, gsize len);
121 void pppcp_send_protocol_reject(struct pppcp_data *data,
122                                 const guint8 *rejected_packet, gsize len);
123 void pppcp_signal_open(struct pppcp_data *data);
124 void pppcp_signal_close(struct pppcp_data *data);
125 void pppcp_signal_up(struct pppcp_data *data);
126 void pppcp_signal_down(struct pppcp_data *data);