3
3
* PPP library with GLib integration
5
* Copyright (C) 2009-2011 Intel Corporation. All rights reserved.
5
* Copyright (C) 2009-2010 Intel Corporation. All rights reserved.
7
7
* This program is free software; you can redistribute it and/or modify
8
8
* it under the terms of the GNU General Public License version 2 as
80
void ppp_net_process_packet(struct ppp_net *net, const guint8 *packet,
80
void ppp_net_process_packet(struct ppp_net *net, const guint8 *packet)
84
83
gsize bytes_written;
90
86
/* find the length of the packet to transmit */
91
87
len = get_host_short(&packet[2]);
92
88
status = g_io_channel_write_chars(net->channel, (gchar *) packet,
94
&bytes_written, NULL);
96
if (status != G_IO_STATUS_NORMAL)
89
len, &bytes_written, NULL);
131
123
return net->if_name;
134
struct ppp_net *ppp_net_new(GAtPPP *ppp, int fd)
126
struct ppp_net *ppp_net_new(GAtPPP *ppp)
136
128
struct ppp_net *net;
137
129
GIOChannel *channel = NULL;
138
130
struct ifreq ifr;
141
133
net = g_try_new0(struct ppp_net, 1);
145
137
net->ppp_packet = ppp_packet_new(MAX_PACKET, PPP_IP_PROTO);
146
if (net->ppp_packet == NULL)
138
if (net->ppp_packet == NULL) {
143
/* open a tun interface */
144
fd = open("/dev/net/tun", O_RDWR);
150
* If the fd value is still the default one,
151
* open the tun interface and configure it.
153
148
memset(&ifr, 0, sizeof(ifr));
156
/* open a tun interface */
157
fd = open("/dev/net/tun", O_RDWR);
159
ppp_debug(ppp, "Couldn't open tun device. "
160
"Do you run oFono as root and do you "
161
"have the TUN module loaded?");
165
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
166
strcpy(ifr.ifr_name, "ppp%d");
168
err = ioctl(fd, TUNSETIFF, (void *) &ifr);
172
err = ioctl(fd, TUNGETIFF, (void *) &ifr);
149
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
150
strcpy(ifr.ifr_name, "ppp%d");
152
err = ioctl(fd, TUNSETIFF, (void *) &ifr);
177
156
net->if_name = strdup(ifr.ifr_name);
200
179
g_io_channel_unref(channel);
202
g_free(net->if_name);
203
g_free(net->ppp_packet);
184
g_free(net->if_name);
185
g_free(net->ppp_packet);
213
190
void ppp_net_free(struct ppp_net *net)
216
g_source_remove(net->watch);
192
g_source_remove(net->watch);
220
193
g_io_channel_unref(net->channel);
222
195
g_free(net->ppp_packet);
223
196
g_free(net->if_name);
227
void ppp_net_suspend_interface(struct ppp_net *net)
229
if (net == NULL || net->channel == NULL)
235
g_source_remove(net->watch);
239
void ppp_net_resume_interface(struct ppp_net *net)
241
if (net == NULL || net->channel == NULL)
244
net->watch = g_io_add_watch(net->channel,
245
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
246
ppp_net_callback, net);