2010-03-23 00:05:56 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2010-03-23 03:01:28 +00:00
|
|
|
|
2010-03-23 00:05:57 +00:00
|
|
|
#include "ppp_cp.h"
|
|
|
|
|
2010-03-23 00:05:56 +00:00
|
|
|
#define LCP_PROTOCOL 0xc021
|
|
|
|
#define CHAP_PROTOCOL 0xc223
|
2010-04-01 16:13:44 +00:00
|
|
|
#define IPCP_PROTO 0x8021
|
2010-04-02 17:42:04 +00:00
|
|
|
#define PPP_IP_PROTO 0x0021
|
2010-03-23 00:05:56 +00:00
|
|
|
|
2010-04-13 19:11:44 +00:00
|
|
|
enum ppp_phase {
|
|
|
|
PPP_PHASE_DEAD = 0, /* Link dead */
|
|
|
|
PPP_PHASE_ESTABLISHMENT, /* LCP started */
|
|
|
|
PPP_PHASE_AUTHENTICATION, /* Auth started */
|
|
|
|
PPP_PHASE_NETWORK, /* IPCP started */
|
|
|
|
PPP_PHASE_TERMINATION, /* LCP Terminate phase */
|
2010-03-23 00:05:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ppp_header {
|
|
|
|
guint16 proto;
|
|
|
|
guint8 info[0];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct packed_short {
|
|
|
|
guint16 s;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct packed_long {
|
|
|
|
guint32 l;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2010-04-08 21:40:41 +00:00
|
|
|
static inline guint32 __get_unaligned_long(const void *p)
|
2010-03-23 00:05:56 +00:00
|
|
|
{
|
|
|
|
const struct packed_long *ptr = p;
|
|
|
|
return ptr->l;
|
|
|
|
}
|
|
|
|
|
2010-04-08 21:40:41 +00:00
|
|
|
static inline guint16 __get_unaligned_short(const void *p)
|
2010-03-23 00:05:56 +00:00
|
|
|
{
|
|
|
|
const struct packed_short *ptr = p;
|
|
|
|
return ptr->s;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define get_host_long(p) \
|
|
|
|
(ntohl(__get_unaligned_long(p)))
|
|
|
|
|
|
|
|
#define get_host_short(p) \
|
|
|
|
(ntohs(__get_unaligned_short(p)))
|
|
|
|
|
|
|
|
#define ppp_info(packet) \
|
|
|
|
(packet + 4)
|
|
|
|
|
|
|
|
#define ppp_proto(packet) \
|
|
|
|
(get_host_short(packet + 2))
|
|
|
|
|
2010-03-23 00:05:59 +00:00
|
|
|
struct auth_data {
|
|
|
|
guint16 proto;
|
|
|
|
gpointer proto_data;
|
|
|
|
void (*process_packet)(struct auth_data *data, guint8 *packet);
|
|
|
|
char *username;
|
2010-03-23 03:13:55 +00:00
|
|
|
char *password;
|
2010-03-23 00:05:59 +00:00
|
|
|
GAtPPP *ppp;
|
|
|
|
};
|
|
|
|
|
2010-03-23 00:06:00 +00:00
|
|
|
struct ppp_net_data {
|
|
|
|
GAtPPP *ppp;
|
|
|
|
char *if_name;
|
|
|
|
GIOChannel *channel;
|
2010-04-02 23:45:24 +00:00
|
|
|
gint watch;
|
2010-03-23 00:06:00 +00:00
|
|
|
};
|
|
|
|
|
2010-04-04 05:25:09 +00:00
|
|
|
void ppp_debug(GAtPPP *ppp, const char *str);
|
2010-04-13 19:11:44 +00:00
|
|
|
void ppp_enter_phase(GAtPPP *ppp, enum ppp_phase phase);
|
2010-03-23 00:05:56 +00:00
|
|
|
void ppp_transmit(GAtPPP *ppp, guint8 *packet, guint infolen);
|
2010-04-08 21:40:41 +00:00
|
|
|
void ppp_set_auth(GAtPPP *ppp, const guint8 *auth_data);
|
2010-04-13 19:19:04 +00:00
|
|
|
void ppp_auth_notify(GAtPPP *ppp, gboolean success);
|
2010-03-23 00:05:56 +00:00
|
|
|
void ppp_set_recv_accm(GAtPPP *ppp, guint32 accm);
|
2010-04-07 03:45:14 +00:00
|
|
|
void ppp_set_xmit_accm(GAtPPP *ppp, guint32 accm);
|
2010-03-23 00:05:56 +00:00
|
|
|
void ppp_set_pfc(GAtPPP *ppp, gboolean pfc);
|
|
|
|
gboolean ppp_get_pfc(GAtPPP *ppp);
|
|
|
|
void ppp_set_acfc(GAtPPP *ppp, gboolean acfc);
|
|
|
|
gboolean ppp_get_acfc(GAtPPP *ppp);
|
2010-03-23 00:05:58 +00:00
|
|
|
struct pppcp_data * lcp_new(GAtPPP *ppp);
|
|
|
|
void lcp_free(struct pppcp_data *lcp);
|
2010-03-27 01:34:28 +00:00
|
|
|
void lcp_protocol_reject(struct pppcp_data *lcp, guint8 *packet, gsize len);
|
2010-04-02 20:10:29 +00:00
|
|
|
void auth_process_packet(struct auth_data *data, guint8 *new_packet);
|
2010-03-23 00:05:59 +00:00
|
|
|
void auth_set_credentials(struct auth_data *data, const char *username,
|
|
|
|
const char *passwd);
|
|
|
|
void auth_set_proto(struct auth_data *data, guint16 proto, guint8 method);
|
|
|
|
struct auth_data *auth_new(GAtPPP *ppp);
|
|
|
|
void auth_free(struct auth_data *auth);
|
2010-03-23 00:06:00 +00:00
|
|
|
struct ppp_net_data *ppp_net_new(GAtPPP *ppp);
|
|
|
|
void ppp_net_open(struct ppp_net_data *data);
|
2010-04-02 20:10:29 +00:00
|
|
|
void ppp_net_process_packet(struct ppp_net_data *data, guint8 *packet);
|
2010-03-23 00:06:00 +00:00
|
|
|
void ppp_net_close(struct ppp_net_data *data);
|
2010-04-02 20:10:29 +00:00
|
|
|
void ppp_net_free(struct ppp_net_data *data);
|
2010-04-02 17:42:04 +00:00
|
|
|
struct pppcp_data *ipcp_new(GAtPPP *ppp);
|
|
|
|
void ipcp_free(struct pppcp_data *data);
|
2010-04-04 05:25:09 +00:00
|
|
|
void ppp_connect_cb(GAtPPP *ppp, GAtPPPConnectStatus success,
|
|
|
|
const char *ip, const char *dns1, const char *dns2);
|