3 * PPP library with GLib integration
5 * Copyright (C) 2009-2011 Intel Corporation. All rights reserved.
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.
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.
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
24 #define LCP_PROTOCOL 0xc021
25 #define PAP_PROTOCOL 0xc023
26 #define CHAP_PROTOCOL 0xc223
27 #define IPCP_PROTO 0x8021
28 #define IPV6CP_PROTO 0x8057
29 #define PPP_IP_PROTO 0x0021
30 #define PPP_IPV6_PROTO 0x0057
33 #define DBG(p, fmt, arg...) do { \
34 char *str = g_strdup_printf("%s:%s() " fmt, __FILE__, \
35 __FUNCTION__ , ## arg); \
49 } __attribute__((packed));
53 } __attribute__((packed));
57 } __attribute__((packed));
59 static inline guint32 __get_unaligned_long(const void *p)
61 const struct packed_long *ptr = p;
65 static inline guint16 __get_unaligned_short(const void *p)
67 const struct packed_short *ptr = p;
71 static inline void __put_unaligned_short(void *p, guint16 val)
73 struct packed_short *ptr = p;
77 #define get_host_long(p) \
78 (ntohl(__get_unaligned_long(p)))
80 #define get_host_short(p) \
81 (ntohs(__get_unaligned_short(p)))
83 #define put_network_short(p, val) \
84 (__put_unaligned_short(p, htons(val)))
86 #define ppp_proto(packet) \
87 (get_host_short(packet + 2))
89 /* LCP related functions */
90 struct pppcp_data *lcp_new(GAtPPP *ppp, gboolean dormant);
91 void lcp_free(struct pppcp_data *lcp);
92 void lcp_protocol_reject(struct pppcp_data *lcp, guint8 *packet, gsize len);
93 void lcp_set_acfc_enabled(struct pppcp_data *pppcp, gboolean enabled);
94 void lcp_set_pfc_enabled(struct pppcp_data *pppcp, gboolean enabled);
96 /* IPCP related functions */
97 struct pppcp_data *ipcp_new(GAtPPP *ppp, gboolean is_server, guint32 ip);
98 void ipcp_free(struct pppcp_data *data);
99 void ipcp_set_server_info(struct pppcp_data *ipcp, guint32 peer_addr,
100 guint32 dns1, guint32 dns2);
102 /* IPv6 CP related functions */
103 struct pppcp_data *ipv6cp_new(GAtPPP *ppp, gboolean is_server,
104 const char *local, const char *peer,
106 void ipv6cp_free(struct pppcp_data *data);
108 /* CHAP related functions */
109 struct ppp_chap *ppp_chap_new(GAtPPP *ppp, guint8 method);
110 void ppp_chap_free(struct ppp_chap *chap);
111 void ppp_chap_process_packet(struct ppp_chap *chap, const guint8 *new_packet,
114 /* PAP related functions */
115 struct ppp_pap *ppp_pap_new(GAtPPP *ppp);
116 void ppp_pap_free(struct ppp_pap *pap);
117 gboolean ppp_pap_start(struct ppp_pap *pap);
118 void ppp_pap_process_packet(struct ppp_pap *pap, const guint8 *new_packet,
121 /* TUN / Network related functions */
122 struct ppp_net *ppp_net_new(GAtPPP *ppp, int fd);
123 const char *ppp_net_get_interface(struct ppp_net *net);
124 void ppp_net_process_packet(struct ppp_net *net, const guint8 *packet,
126 void ppp_net_free(struct ppp_net *net);
127 gboolean ppp_net_set_mtu(struct ppp_net *net, guint16 mtu);
128 void ppp_net_suspend_interface(struct ppp_net *net);
129 void ppp_net_resume_interface(struct ppp_net *net);
131 /* PPP functions related to main GAtPPP object */
132 void ppp_debug(GAtPPP *ppp, const char *str);
133 void ppp_transmit(GAtPPP *ppp, guint8 *packet, guint infolen);
134 void ppp_set_auth(GAtPPP *ppp, const guint8 *auth_data);
135 void ppp_auth_notify(GAtPPP *ppp, gboolean success);
136 void ppp_ipcp_up_notify(GAtPPP *ppp, const char *local, const char *peer,
137 const char *dns1, const char *dns2);
138 void ppp_ipcp_down_notify(GAtPPP *ppp);
139 void ppp_ipcp_finished_notify(GAtPPP *ppp);
140 void ppp_lcp_up_notify(GAtPPP *ppp);
141 void ppp_lcp_down_notify(GAtPPP *ppp);
142 void ppp_lcp_finished_notify(GAtPPP *ppp);
143 void ppp_set_recv_accm(GAtPPP *ppp, guint32 accm);
144 void ppp_set_xmit_accm(GAtPPP *ppp, guint32 accm);
145 void ppp_set_mtu(GAtPPP *ppp, const guint8 *data);
146 void ppp_set_xmit_acfc(GAtPPP *ppp, gboolean acfc);
147 void ppp_set_xmit_pfc(GAtPPP *ppp, gboolean pfc);
148 struct ppp_header *ppp_packet_new(gsize infolen, guint16 protocol);