upgrade to the version 1.8
[profile/ivi/ofono.git] / drivers / qmimodem / ussd.c
1 /*
2  *
3  *  oFono - Open Source Telephony
4  *
5  *  Copyright (C) 2011-2012  Intel Corporation. All rights reserved.
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 <ofono/log.h>
27 #include <ofono/modem.h>
28 #include <ofono/ussd.h>
29
30 #include "qmi.h"
31
32 #include "qmimodem.h"
33
34 struct ussd_data {
35         struct qmi_service *voice;
36         uint16_t major;
37         uint16_t minor;
38 };
39
40 static void create_voice_cb(struct qmi_service *service, void *user_data)
41 {
42         struct ofono_ussd *ussd = user_data;
43         struct ussd_data *data = ofono_ussd_get_data(ussd);
44
45         DBG("");
46
47         if (!service) {
48                 ofono_error("Failed to request Voice service");
49                 ofono_ussd_remove(ussd);
50                 return;
51         }
52
53         if (!qmi_service_get_version(service, &data->major, &data->minor)) {
54                 ofono_error("Failed to get Voice service version");
55                 ofono_ussd_remove(ussd);
56                 return;
57         }
58
59         data->voice = qmi_service_ref(service);
60
61         ofono_ussd_register(ussd);
62 }
63
64 static int qmi_ussd_probe(struct ofono_ussd *ussd,
65                                 unsigned int vendor, void *user_data)
66 {
67         struct qmi_device *device = user_data;
68         struct ussd_data *data;
69
70         DBG("");
71
72         data = g_new0(struct ussd_data, 1);
73
74         ofono_ussd_set_data(ussd, data);
75
76         qmi_service_create_shared(device, QMI_SERVICE_VOICE,
77                                                 create_voice_cb, ussd, NULL);
78
79         return 0;
80
81 }
82
83 static void qmi_ussd_remove(struct ofono_ussd *ussd)
84 {
85         struct ussd_data *data = ofono_ussd_get_data(ussd);
86
87         DBG("");
88
89         ofono_ussd_set_data(ussd, NULL);
90
91         qmi_service_unref(data->voice);
92
93         g_free(data);
94 }
95
96 static struct ofono_ussd_driver driver = {
97         .name           = "qmimodem",
98         .probe          = qmi_ussd_probe,
99         .remove         = qmi_ussd_remove,
100 };
101
102 void qmi_ussd_init(void)
103 {
104         ofono_ussd_driver_register(&driver);
105 }
106
107 void qmi_ussd_exit(void)
108 {
109         ofono_ussd_driver_unregister(&driver);
110 }