3 * oFono - Open Source Telephony
5 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
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
32 #include <linux/if_tun.h>
34 #include <sys/ioctl.h>
37 #define OFONO_API_SUBJECT_TO_CHANGE
39 #include <ofono/modem.h>
40 #include <ofono/types.h>
41 #include <ofono/plugin.h>
42 #include <ofono/log.h>
43 #include <ofono/private-network.h>
45 #define SERVER_ADDRESS "192.168.1.1"
46 #define DNS_SERVER_1 "10.10.10.10"
47 #define DNS_SERVER_2 "10.10.10.11"
48 #define PEER_ADDRESS_PREFIX "192.168.1."
50 static int next_peer = 2;
53 ofono_private_network_cb_t cb;
57 static gboolean request_cb(gpointer data)
59 struct req_data *rd = data;
60 struct ofono_private_network_settings pns;
65 fd = open("/dev/net/tun", O_RDWR);
69 memset(&ifr, 0, sizeof(ifr));
70 ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
71 strcpy(ifr.ifr_name, "ppp%d");
73 err = ioctl(fd, TUNSETIFF, (void *) &ifr);
77 sprintf(ip, "%s%d", PEER_ADDRESS_PREFIX, next_peer++);
80 pns.server_ip = SERVER_ADDRESS;
82 pns.primary_dns = DNS_SERVER_1;
83 pns.secondary_dns = DNS_SERVER_2;
85 rd->cb(&pns, rd->userdata);
93 rd->cb(NULL, rd->userdata);
98 static int example_request(ofono_private_network_cb_t cb, void *data)
100 struct req_data *rd = g_new0(struct req_data, 1);
107 return g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, 2, request_cb,
108 rd, (GDestroyNotify) g_free);
111 static void example_release(int id)
118 static struct ofono_private_network_driver example_driver = {
119 .name = "Example Private Network Driver",
120 .request = example_request,
121 .release = example_release,
124 static int example_private_network_init(void)
126 return ofono_private_network_driver_register(&example_driver);
129 static void example_private_network_exit(void)
131 ofono_private_network_driver_unregister(&example_driver);
134 OFONO_PLUGIN_DEFINE(example_private_network, "Example Private Network Plugin",
135 VERSION, OFONO_PLUGIN_PRIORITY_LOW,
136 example_private_network_init,
137 example_private_network_exit)