Upgrade ofono to 1.2
[profile/ivi/ofono.git] / gatchat / ppp.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 #include "ppp_cp.h"
23
24 #define LCP_PROTOCOL    0xc021
25 #define CHAP_PROTOCOL   0xc223
26 #define IPCP_PROTO      0x8021
27 #define IPV6CP_PROTO    0x8057
28 #define PPP_IP_PROTO    0x0021
29 #define PPP_IPV6_PROTO  0x0057
30 #define MD5             5
31
32 #define DBG(p, fmt, arg...) do {                                \
33         char *str = g_strdup_printf("%s:%s() " fmt, __FILE__,   \
34                                         __FUNCTION__ , ## arg); \
35         ppp_debug(p, str);                                      \
36         g_free(str);                                            \
37 } while (0)
38
39 struct ppp_chap;
40 struct ppp_net;
41
42 struct ppp_header {
43         guint8 address;
44         guint8 control;
45         guint16 proto;
46         guint8 info[0];
47 } __attribute__((packed));
48
49 struct packed_short {
50         guint16 s;
51 } __attribute__((packed));
52
53 struct packed_long {
54         guint32 l;
55 } __attribute__((packed));
56
57 static inline guint32 __get_unaligned_long(const void *p)
58 {
59         const struct packed_long *ptr = p;
60         return ptr->l;
61 }
62
63 static inline guint16 __get_unaligned_short(const void *p)
64 {
65         const struct packed_short *ptr = p;
66         return ptr->s;
67 }
68
69 static inline void __put_unaligned_short(void *p, guint16 val)
70 {
71         struct packed_short *ptr = p;
72         ptr->s = val;
73 }
74
75 #define get_host_long(p) \
76         (ntohl(__get_unaligned_long(p)))
77
78 #define get_host_short(p) \
79         (ntohs(__get_unaligned_short(p)))
80
81 #define put_network_short(p, val) \
82         (__put_unaligned_short(p, htons(val)))
83
84 #define ppp_proto(packet) \
85         (get_host_short(packet + 2))
86
87 /* LCP related functions */
88 struct pppcp_data *lcp_new(GAtPPP *ppp, gboolean dormant);
89 void lcp_free(struct pppcp_data *lcp);
90 void lcp_protocol_reject(struct pppcp_data *lcp, guint8 *packet, gsize len);
91 void lcp_set_acfc_enabled(struct pppcp_data *pppcp, gboolean enabled);
92 void lcp_set_pfc_enabled(struct pppcp_data *pppcp, gboolean enabled);
93
94 /* IPCP related functions */
95 struct pppcp_data *ipcp_new(GAtPPP *ppp, gboolean is_server, guint32 ip);
96 void ipcp_free(struct pppcp_data *data);
97 void ipcp_set_server_info(struct pppcp_data *ipcp, guint32 peer_addr,
98                                 guint32 dns1, guint32 dns2);
99
100 /* IPv6 CP related functions */
101 struct pppcp_data *ipv6cp_new(GAtPPP *ppp, gboolean is_server,
102                                         const char *local, const char *peer,
103                                         GError **error);
104 void ipv6cp_free(struct pppcp_data *data);
105
106 /* CHAP related functions */
107 struct ppp_chap *ppp_chap_new(GAtPPP *ppp, guint8 method);
108 void ppp_chap_free(struct ppp_chap *chap);
109 void ppp_chap_process_packet(struct ppp_chap *chap, const guint8 *new_packet,
110                                 gsize len);
111
112 /* TUN / Network related functions */
113 struct ppp_net *ppp_net_new(GAtPPP *ppp, int fd);
114 const char *ppp_net_get_interface(struct ppp_net *net);
115 void ppp_net_process_packet(struct ppp_net *net, const guint8 *packet,
116                                 gsize len);
117 void ppp_net_free(struct ppp_net *net);
118 gboolean ppp_net_set_mtu(struct ppp_net *net, guint16 mtu);
119 void ppp_net_suspend_interface(struct ppp_net *net);
120 void ppp_net_resume_interface(struct ppp_net *net);
121
122 /* PPP functions related to main GAtPPP object */
123 void ppp_debug(GAtPPP *ppp, const char *str);
124 void ppp_transmit(GAtPPP *ppp, guint8 *packet, guint infolen);
125 void ppp_set_auth(GAtPPP *ppp, const guint8 *auth_data);
126 void ppp_auth_notify(GAtPPP *ppp, gboolean success);
127 void ppp_ipcp_up_notify(GAtPPP *ppp, const char *local, const char *peer,
128                                         const char *dns1, const char *dns2);
129 void ppp_ipcp_down_notify(GAtPPP *ppp);
130 void ppp_ipcp_finished_notify(GAtPPP *ppp);
131 void ppp_lcp_up_notify(GAtPPP *ppp);
132 void ppp_lcp_down_notify(GAtPPP *ppp);
133 void ppp_lcp_finished_notify(GAtPPP *ppp);
134 void ppp_set_recv_accm(GAtPPP *ppp, guint32 accm);
135 void ppp_set_xmit_accm(GAtPPP *ppp, guint32 accm);
136 void ppp_set_mtu(GAtPPP *ppp, const guint8 *data);
137 void ppp_set_xmit_acfc(GAtPPP *ppp, gboolean acfc);
138 void ppp_set_xmit_pfc(GAtPPP *ppp, gboolean pfc);
139 struct ppp_header *ppp_packet_new(gsize infolen, guint16 protocol);