test: Add support for CSSI/CSSU notifications
[platform/upstream/ofono.git] / examples / provision.c
1 /*
2  *
3  *  oFono - Open Source Telephony
4  *
5  *  Copyright (C) 2011  Nokia Corporation and/or its subsidiary(-ies).
6  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <string.h>
27 #include <glib.h>
28
29 #include <errno.h>
30
31 #define OFONO_API_SUBJECT_TO_CHANGE
32
33 #include <ofono/modem.h>
34 #include <ofono/gprs-provision.h>
35 #include <ofono/types.h>
36 #include <ofono/plugin.h>
37 #include <ofono/log.h>
38
39 static int example_provision_get_settings(const char *mcc, const char *mnc,
40                                 const char *spn,
41                                 struct ofono_gprs_provision_data **settings,
42                                 int *count)
43 {
44         ofono_debug("Provisioning...");
45         *count = 0;
46         *settings = NULL;
47
48         ofono_debug("Finding settings for MCC %s, MNC %s, SPN '%s'",
49                         mcc, mnc, spn);
50
51         if (strcmp(mcc, "246") != 0 || strcmp(mnc, "81") != 0 ||
52                                                 g_strcmp0(spn, "oFono") != 0)
53                 return -ENOENT;
54
55         ofono_debug("Creating example settings for phonesim");
56
57         *settings = g_try_new0(struct ofono_gprs_provision_data, 2);
58         if (*settings == NULL)
59                 return -ENOMEM;
60
61         *count = 2;
62
63         /* Internet context settings */
64         (*settings)[0].proto = OFONO_GPRS_PROTO_IP;
65         (*settings)[0].type = OFONO_GPRS_CONTEXT_TYPE_INTERNET;
66         (*settings)[0].name = g_strdup("Phonesim Internet");
67         (*settings)[0].apn = g_strdup("internetapn");
68
69         /* MMS context settings */
70         (*settings)[1].proto = OFONO_GPRS_PROTO_IP;
71         (*settings)[1].type = OFONO_GPRS_CONTEXT_TYPE_MMS;
72         (*settings)[1].name = g_strdup("Phonesim MMS");
73         (*settings)[1].apn = g_strdup("mmsapn");
74         (*settings)[1].username = g_strdup("mmsuser");
75         (*settings)[1].password = g_strdup("mmspass");
76         (*settings)[1].message_proxy = g_strdup("10.11.12.13:8080");
77         (*settings)[1].message_center = g_strdup("http://mms.example.com:8000");
78
79         return 0;
80 }
81
82 static struct ofono_gprs_provision_driver example_driver = {
83         .name           = "Example GPRS context provisioning",
84         .priority       = OFONO_PLUGIN_PRIORITY_LOW,
85         .get_settings   = example_provision_get_settings,
86 };
87
88 static int example_provision_init(void)
89 {
90         return ofono_gprs_provision_driver_register(&example_driver);
91 }
92
93 static void example_provision_exit(void)
94 {
95         ofono_gprs_provision_driver_unregister(&example_driver);
96 }
97
98 OFONO_PLUGIN_DEFINE(example_provision, "Example Provisioning Plugin",
99                         VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT,
100                         example_provision_init,
101                         example_provision_exit)