~morphis/phablet-extras/ofono-sms-status-report

« back to all changes in this revision

Viewing changes to gatchat/ppp_net.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-08-22 19:59:08 UTC
  • mfrom: (1.3.3) (6.1.5 experimental)
  • Revision ID: package-import@ubuntu.com-20120822195908-0bmmk1hlh989bgk6
Tags: 1.9-1ubuntu1
* Merge with Debian experimental; remaining changes:
  - debian/control: explicitly Conflicts with modemmanager: having both
    installed / running at the same time causes issues causes issues with
    both claiming modem devices.
  - debian/patches/02-dont-handle-stacktraces.patch: stop catching stacktraces
    and printing the information internally, so apport can catch and report
    the possible bugs.
  - debian/ofono.postinst: on configure, notify the user that a reboot is
    required (so ofono can get started by upstart). (LP: #600501)
  - debian/rules: pass --no-restart-on-upgrade so ofono isn't automatically
    restarted when upgrades.
  - Adding upstart config / Removing standard init script
  - Adding Apport support
  - Patch for recognizing special Huawei devices with weird serial
  - Override lintian to avoid script-in-etc-init.d... warnings.
  - Update debian/compat to 7
* debian/series: add our patches to debian/patches/series now that the package
  uses quilt.
* debian/patches/02-dont-handle-stacktraces.patch: refreshed.
* debian/ofono-dev.install, debian/ofono.install:
  - Install usr/sbin/dundee and ofono.pc to the proper packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *
3
3
 *  PPP library with GLib integration
4
4
 *
5
 
 *  Copyright (C) 2009-2010  Intel Corporation. All rights reserved.
 
5
 *  Copyright (C) 2009-2011  Intel Corporation. All rights reserved.
6
6
 *
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
77
77
        return TRUE;
78
78
}
79
79
 
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,
 
81
                                gsize plen)
81
82
{
82
83
        GIOStatus status;
83
84
        gsize bytes_written;
84
85
        guint16 len;
85
86
 
 
87
        if (plen < 4)
 
88
                return;
 
89
 
86
90
        /* find the length of the packet to transmit */
87
91
        len = get_host_short(&packet[2]);
88
92
        status = g_io_channel_write_chars(net->channel, (gchar *) packet,
89
 
                                                len, &bytes_written, NULL);
 
93
                                                MIN(len, plen),
 
94
                                                &bytes_written, NULL);
 
95
 
 
96
        if (status != G_IO_STATUS_NORMAL)
 
97
                return;
90
98
}
91
99
 
92
100
/*
123
131
        return net->if_name;
124
132
}
125
133
 
126
 
struct ppp_net *ppp_net_new(GAtPPP *ppp)
 
134
struct ppp_net *ppp_net_new(GAtPPP *ppp, int fd)
127
135
{
128
136
        struct ppp_net *net;
129
137
        GIOChannel *channel = NULL;
130
138
        struct ifreq ifr;
131
 
        int fd, err;
 
139
        int err;
132
140
 
133
141
        net = g_try_new0(struct ppp_net, 1);
134
142
        if (net == NULL)
135
 
                return NULL;
 
143
                goto badalloc;
136
144
 
137
145
        net->ppp_packet = ppp_packet_new(MAX_PACKET, PPP_IP_PROTO);
138
 
        if (net->ppp_packet == NULL) {
139
 
                g_free(net);
140
 
                return NULL;
 
146
        if (net->ppp_packet == NULL)
 
147
                goto error;
 
148
 
 
149
        /*
 
150
         * If the fd value is still the default one,
 
151
         * open the tun interface and configure it.
 
152
         */
 
153
        memset(&ifr, 0, sizeof(ifr));
 
154
 
 
155
        if (fd < 0) {
 
156
                /* open a tun interface */
 
157
                fd = open("/dev/net/tun", O_RDWR);
 
158
                if (fd < 0)
 
159
                        goto error;
 
160
 
 
161
                ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
 
162
                strcpy(ifr.ifr_name, "ppp%d");
 
163
 
 
164
                err = ioctl(fd, TUNSETIFF, (void *) &ifr);
 
165
                if (err < 0)
 
166
                        goto error;
 
167
        } else {
 
168
                err = ioctl(fd, TUNGETIFF, (void *) &ifr);
 
169
                if (err < 0)
 
170
                        goto error;
141
171
        }
142
172
 
143
 
        /* open a tun interface */
144
 
        fd = open("/dev/net/tun", O_RDWR);
145
 
        if (fd < 0)
146
 
                goto error;
147
 
 
148
 
        memset(&ifr, 0, sizeof(ifr));
149
 
        ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
150
 
        strcpy(ifr.ifr_name, "ppp%d");
151
 
 
152
 
        err = ioctl(fd, TUNSETIFF, (void *) &ifr);
153
 
        if (err < 0)
154
 
                goto error;
155
 
 
156
173
        net->if_name = strdup(ifr.ifr_name);
157
174
 
158
175
        /* create a channel for reading and writing to this interface */
178
195
        if (channel)
179
196
                g_io_channel_unref(channel);
180
197
 
 
198
        g_free(net->if_name);
 
199
        g_free(net->ppp_packet);
 
200
        g_free(net);
 
201
 
 
202
badalloc:
181
203
        if (fd >= 0)
182
204
                close(fd);
183
205
 
184
 
        g_free(net->if_name);
185
 
        g_free(net->ppp_packet);
186
 
        g_free(net);
187
206
        return NULL;
188
207
}
189
208
 
190
209
void ppp_net_free(struct ppp_net *net)
191
210
{
 
211
        if (net->watch) {
 
212
                g_source_remove(net->watch);
 
213
                net->watch = 0;
 
214
        }
 
215
 
 
216
        g_io_channel_unref(net->channel);
 
217
 
 
218
        g_free(net->ppp_packet);
 
219
        g_free(net->if_name);
 
220
        g_free(net);
 
221
}
 
222
 
 
223
void ppp_net_suspend_interface(struct ppp_net *net)
 
224
{
 
225
        if (net == NULL || net->channel == NULL)
 
226
                return;
 
227
 
 
228
        if (net->watch == 0)
 
229
                return;
 
230
 
192
231
        g_source_remove(net->watch);
193
 
        g_io_channel_unref(net->channel);
194
 
 
195
 
        g_free(net->ppp_packet);
196
 
        g_free(net->if_name);
197
 
        g_free(net);
 
232
        net->watch = 0;
 
233
}
 
234
 
 
235
void ppp_net_resume_interface(struct ppp_net *net)
 
236
{
 
237
        if (net == NULL || net->channel == NULL)
 
238
                return;
 
239
 
 
240
        net->watch = g_io_add_watch(net->channel,
 
241
                        G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
 
242
                        ppp_net_callback, net);
198
243
}