Merge lp:~phablet-team/ofono/pro5-support-and-more into lp:~phablet-team/ofono/ubuntu

Proposed by Alfonso Sanchez-Beato
Status: Merged
Approved by: Tony Espy
Approved revision: 6913
Merged at revision: 6912
Proposed branch: lp:~phablet-team/ofono/pro5-support-and-more
Merge into: lp:~phablet-team/ofono/ubuntu
Diff against target: 5052 lines (+2710/-971)
35 files modified
.gitignore (+3/-0)
Makefile.am (+39/-8)
configure.ac (+11/-0)
debian/changelog (+23/-0)
debian/control (+2/-1)
drivers/qcommsimmodem/radio-settings.c (+60/-45)
drivers/rilmodem/call-barring.c (+2/-2)
drivers/rilmodem/sim.c (+6/-0)
drivers/rilmodem/sms.c (+6/-8)
gril/gril.c (+20/-0)
gril/gril.h (+3/-0)
gril/grilreply.c (+11/-3)
gril/grilunsol.c (+24/-0)
gril/grilunsol.h (+2/-0)
gril/ril_constants.h (+2/-1)
include/log.h (+2/-0)
include/system-settings.h (+51/-0)
include/wakelock.h (+0/-100)
plugins/accounts-settings.c (+474/-0)
plugins/android-wakelock.c (+0/-212)
plugins/qcom-msim.c (+12/-0)
plugins/ril.c (+36/-27)
plugins/rildev.c (+10/-0)
plugins/upower.c (+36/-144)
src/emulator.c (+29/-11)
src/system-settings.c (+74/-0)
src/voicecall.c (+5/-3)
src/wakelock.c (+0/-151)
unit/rilmodem-test-server.c (+237/-0)
unit/rilmodem-test-server.h (+47/-0)
unit/test-grilreply.c (+2/-2)
unit/test-grilunsol.c (+157/-0)
unit/test-rilmodem-cb.c (+605/-0)
unit/test-rilmodem-cs.c (+123/-253)
unit/test-rilmodem-sms.c (+596/-0)
To merge this branch: bzr merge lp:~phablet-team/ofono/pro5-support-and-more
Reviewer Review Type Date Requested Status
Tony Espy Approve
Review via email: mp+288897@code.launchpad.net

Commit message

[ Tony Espy ]
* unit: new rilmodem tests for sms and call barring
* plugins: address upower plugin upstream comments
* unit: fix test-grilreply set_facility_lock test
* style fixes for wakelock support

[ Ratchanan Srirattanamet ]
* qcommsimmodem: fix setting 3G pref when one of the slots is empty

[ Alfonso Sanchez-Beato ]
* ril: set properly gril vendor
* support for system settings
* unit: make unit tests parallelizable

[ Vicamo Yang ]
* ril, gril: support for pro 5
* gril, rilmodem: set RIL version from CONNECTED event
* unit: fix warning

Description of the change

[ Tony Espy ]
* unit: new rilmodem tests for sms and call barring
* plugins: address upower plugin upstream comments
* unit: fix test-grilreply set_facility_lock test
* style fixes for wakelock support

[ Ratchanan Srirattanamet ]
* qcommsimmodem: fix setting 3G pref when one of the slots is empty

[ Alfonso Sanchez-Beato ]
* ril: set properly gril vendor
* support for system settings
* unit: make unit tests parallelizable

[ Vicamo Yang ]
* ril, gril: support for pro 5
* gril, rilmodem: set RIL version from CONNECTED event
* unit: fix warning

To post a comment you must log in.
6913. By Alfonso Sanchez-Beato

Add libsystemd dependency

Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

Basic tests performed on krillin, rc-proposed/bq-aquaris.en #279, all looked good.

Revision history for this message
Tony Espy (awe) wrote :

Looks good to me...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.gitignore'
--- .gitignore 2015-07-31 12:46:34 +0000
+++ .gitignore 2016-03-14 09:03:03 +0000
@@ -52,6 +52,9 @@
52unit/test-mtkreply52unit/test-mtkreply
53unit/test-mtkrequest53unit/test-mtkrequest
54unit/test-mtkunsol54unit/test-mtkunsol
55unit/test-rilmodem-cs
56unit/test-rilmodem-sms
57unit/test-rilmodem-cb
55unit/test-*.log58unit/test-*.log
56unit/test-*.trs59unit/test-*.trs
5760
5861
=== modified file 'Makefile.am'
--- Makefile.am 2016-01-15 16:03:09 +0000
+++ Makefile.am 2016-03-14 09:03:03 +0000
@@ -23,7 +23,8 @@
23 include/cdma-provision.h include/handsfree.h \23 include/cdma-provision.h include/handsfree.h \
24 include/handsfree-audio.h include/siri.h \24 include/handsfree-audio.h include/siri.h \
25 include/sim-mnclength.h include/spn-table.h \25 include/sim-mnclength.h include/spn-table.h \
26 include/dns-client.h include/wakelock.h26 include/dns-client.h include/wakelock.h \
27 include/system-settings.h
2728
28nodist_pkginclude_HEADERS = include/version.h29nodist_pkginclude_HEADERS = include/version.h
2930
@@ -621,6 +622,14 @@
621builtin_sources += plugins/android-wakelock.c622builtin_sources += plugins/android-wakelock.c
622endif623endif
623624
625if ACCOUNTSSETTINGS
626builtin_modules += accounts_settings
627builtin_sources += plugins/accounts-settings.c
628
629builtin_cflags += @SYSTEMD_CFLAGS@
630builtin_libadd += @SYSTEMD_LIBS@
631endif
632
624sbin_PROGRAMS = src/ofonod633sbin_PROGRAMS = src/ofonod
625634
626src_ofonod_SOURCES = $(builtin_sources) src/ofono.ver \635src_ofonod_SOURCES = $(builtin_sources) src/ofono.ver \
@@ -650,7 +659,8 @@
650 src/handsfree-audio.c src/bluetooth.h \659 src/handsfree-audio.c src/bluetooth.h \
651 src/hfp.h src/siri.c \660 src/hfp.h src/siri.c \
652 src/sim-mnclength.c src/spn-table.c \661 src/sim-mnclength.c src/spn-table.c \
653 src/dns-client.c src/wakelock.c662 src/dns-client.c src/wakelock.c \
663 src/system-settings.c
654664
655src_ofonod_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \665src_ofonod_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \
656 @GLIB_LIBS@ @DBUS_LIBS@ -ldl666 @GLIB_LIBS@ @DBUS_LIBS@ -ldl
@@ -817,7 +827,9 @@
817 unit/test-mtkrequest \827 unit/test-mtkrequest \
818 unit/test-mtkreply \828 unit/test-mtkreply \
819 unit/test-mtkunsol \829 unit/test-mtkunsol \
820 unit/test-rilmodem-cs830 unit/test-rilmodem-cs \
831 unit/test-rilmodem-sms \
832 unit/test-rilmodem-cb
821833
822noinst_PROGRAMS = $(unit_tests) \834noinst_PROGRAMS = $(unit_tests) \
823 unit/test-sms-root unit/test-mux unit/test-caif835 unit/test-sms-root unit/test-mux unit/test-caif
@@ -913,14 +925,33 @@
913unit_test_mnclength_LDADD = @GLIB_LIBS@ -ldl925unit_test_mnclength_LDADD = @GLIB_LIBS@ -ldl
914unit_objects += $(unit_test_mnclength_OBJECTS)926unit_objects += $(unit_test_mnclength_OBJECTS)
915927
916unit_test_rilmodem_cs_SOURCES = unit/test-rilmodem-cs.c $(gril_sources) \928test_rilmodem_sources = $(gril_sources) src/log.c src/common.c src/util.c \
917 src/log.c src/common.c src/util.c \929 gatchat/ringbuffer.h gatchat/ringbuffer.c \
918 drivers/rilmodem/call-settings.c \930 unit/rilmodem-test-server.h \
919 src/simutil.c gatchat/ringbuffer.c931 unit/rilmodem-test-server.c \
932 src/simutil.c
933
934unit_test_rilmodem_cs_SOURCES = $(test_rilmodem_sources) \
935 unit/test-rilmodem-cs.c \
936 drivers/rilmodem/call-settings.c
920unit_test_rilmodem_cs_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \937unit_test_rilmodem_cs_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \
921 @GLIB_LIBS@ @DBUS_LIBS@ -ldl938 @GLIB_LIBS@ @DBUS_LIBS@ -ldl
922unit_objects += $(unit_test_rilmodem_cs_OBJECTS)939unit_objects += $(unit_test_rilmodem_cs_OBJECTS)
923940
941unit_test_rilmodem_sms_SOURCES = $(test_rilmodem_sources) \
942 unit/test-rilmodem-sms.c \
943 drivers/rilmodem/sms.c
944unit_test_rilmodem_sms_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \
945 @GLIB_LIBS@ @DBUS_LIBS@ -ldl
946unit_objects += $(unit_test_rilmodem_sms_OBJECTS)
947
948unit_test_rilmodem_cb_SOURCES = $(test_rilmodem_sources) \
949 unit/test-rilmodem-cb.c \
950 drivers/rilmodem/call-barring.c
951unit_test_rilmodem_cb_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \
952 @GLIB_LIBS@ @DBUS_LIBS@ -ldl
953unit_objects += $(unit_test_rilmodem_cb_OBJECTS)
954
924TESTS = $(unit_tests)955TESTS = $(unit_tests)
925956
926if TOOLS957if TOOLS
927958
=== modified file 'configure.ac'
--- configure.ac 2016-01-15 16:03:09 +0000
+++ configure.ac 2016-03-14 09:03:03 +0000
@@ -200,6 +200,17 @@
200AC_SUBST(CARES_LIBS)200AC_SUBST(CARES_LIBS)
201AM_CONDITIONAL(CARES, test "${enable_cares}" != "no")201AM_CONDITIONAL(CARES, test "${enable_cares}" != "no")
202202
203AC_ARG_ENABLE(accounts-settings, AC_HELP_STRING([--disable-accounts-settings],
204 [disable using accounts service for system settings]),
205 [enable_accounts_settings=${enableval}])
206if (test "${enable_accounts_settings=$}" != "no"); then
207 PKG_CHECK_MODULES(SYSTEMD, libsystemd, dummy=yes,
208 AC_MSG_ERROR(libsystemd is required))
209fi
210AC_SUBST(SYSTEMD_CFLAGS)
211AC_SUBST(SYSTEMD_LIBS)
212AM_CONDITIONAL(ACCOUNTSSETTINGS, test "${enable_accounts_settings=$}" != "no")
213
203AC_ARG_ENABLE(nettime, AC_HELP_STRING([--disable-nettime],214AC_ARG_ENABLE(nettime, AC_HELP_STRING([--disable-nettime],
204 [disable Nettime plugin]),215 [disable Nettime plugin]),
205 [enable_nettime=${enableval}])216 [enable_nettime=${enableval}])
206217
=== modified file 'debian/changelog'
--- debian/changelog 2016-01-15 17:37:10 +0000
+++ debian/changelog 2016-03-14 09:03:03 +0000
@@ -1,3 +1,26 @@
1ofono (1.17.bzr6912+16.04.20160314.1-0ubuntu1) UNRELEASED; urgency=medium
2
3 [ Tony Espy ]
4 * unit: new rilmodem tests for sms and call barring
5 * plugins: address upower plugin upstream comments
6 * unit: fix test-grilreply set_facility_lock test
7 * style fixes for wakelock support
8
9 [ Ratchanan Srirattanamet ]
10 * qcommsimmodem: fix setting 3G pref when one of the slots is empty
11
12 [ Alfonso Sanchez-Beato ]
13 * ril: set properly gril vendor
14 * support for system settings
15 * unit: make tests parallelizable
16
17 [ Vicamo Yang ]
18 * ril, gril: support for pro 5
19 * gril, rilmodem: set RIL version from CONNECTED event
20 * unit: fix warning
21
22 -- Alfonso Sanchez-Beato (email Canonical) <alfonso.sanchez-beato@canonical.com> Mon, 14 Mar 2016 09:07:47 +0100
23
1ofono (1.17.bzr6910+16.04.20160115.3-0ubuntu1) xenial; urgency=medium24ofono (1.17.bzr6910+16.04.20160115.3-0ubuntu1) xenial; urgency=medium
225
3 [ Simon Fels ]26 [ Simon Fels ]
427
=== modified file 'debian/control'
--- debian/control 2015-07-01 07:00:40 +0000
+++ debian/control 2016-03-14 09:03:03 +0000
@@ -14,7 +14,8 @@
14 udev,14 udev,
15 libbluetooth-dev (>= 4.30),15 libbluetooth-dev (>= 4.30),
16 mobile-broadband-provider-info,16 mobile-broadband-provider-info,
17 libc-ares-dev17 libc-ares-dev,
18 libsystemd-dev
18Standards-Version: 3.9.419Standards-Version: 3.9.4
19Homepage: http://www.ofono.org/20Homepage: http://www.ofono.org/
20# If you aren't a member of ~phablet-team but need to upload21# If you aren't a member of ~phablet-team but need to upload
2122
=== modified file 'drivers/qcommsimmodem/radio-settings.c'
--- drivers/qcommsimmodem/radio-settings.c 2015-07-31 13:44:26 +0000
+++ drivers/qcommsimmodem/radio-settings.c 2016-03-14 09:03:03 +0000
@@ -31,10 +31,12 @@
31#include <errno.h>31#include <errno.h>
3232
33#include <glib.h>33#include <glib.h>
34#include <ofono.h>
3435
35#include <ofono/log.h>36#include <ofono/log.h>
36#include <ofono/modem.h>37#include <ofono/modem.h>
37#include <ofono/radio-settings.h>38#include <ofono/radio-settings.h>
39#include <ofono/sim.h>
3840
39#include "gril.h"41#include "gril.h"
40#include "grilrequest.h"42#include "grilrequest.h"
@@ -58,7 +60,6 @@
58};60};
5961
60static struct ofono_radio_settings *multisim_rs[QCOMMSIM_NUM_SLOTS_MAX];62static struct ofono_radio_settings *multisim_rs[QCOMMSIM_NUM_SLOTS_MAX];
61static int multisim_num_slots;
6263
63static void qcom_msim_set_rat_cb(struct ril_msg *message, gpointer user_data)64static void qcom_msim_set_rat_cb(struct ril_msg *message, gpointer user_data)
64{65{
@@ -76,6 +77,24 @@
76 }77 }
77}78}
7879
80static void qcom_msim_do_set_rat_mode(struct ofono_radio_settings *rs, int pref,
81 struct cb_data *cbd)
82{
83 struct radio_data *rd = ofono_radio_settings_get_data(rs);
84 struct parcel rilp;
85 ofono_radio_settings_rat_mode_set_cb_t cb;
86
87 g_ril_request_set_preferred_network_type(rd->ril, pref, &rilp);
88
89 if (g_ril_send(rd->ril, RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE,
90 &rilp, qcom_msim_set_rat_cb, cbd, g_free) == 0) {
91 ofono_error("%s: unable to set rat mode", __func__);
92 cb = cbd->cb;
93 CALLBACK_WITH_FAILURE(cb, cbd->data);
94 g_free(cbd);
95 }
96}
97
79static void qcom_msim_set_2g_rat_cb(struct ril_msg *message,98static void qcom_msim_set_2g_rat_cb(struct ril_msg *message,
80 gpointer user_data)99 gpointer user_data)
81{100{
@@ -84,7 +103,6 @@
84 struct qcom_msim_pending_pref_setting *pps = set_2g_rat_data->pps;103 struct qcom_msim_pending_pref_setting *pps = set_2g_rat_data->pps;
85 struct radio_data *rd = ofono_radio_settings_get_data(rs);104 struct radio_data *rd = ofono_radio_settings_get_data(rs);
86 ofono_radio_settings_rat_mode_set_cb_t cb;105 ofono_radio_settings_rat_mode_set_cb_t cb;
87 struct parcel rilp;
88106
89 pps->pending_gsm_pref_remaining -= 1;107 pps->pending_gsm_pref_remaining -= 1;
90108
@@ -104,23 +122,8 @@
104 }122 }
105123
106 if (pps->pending_gsm_pref_remaining == 0) {124 if (pps->pending_gsm_pref_remaining == 0) {
107 if (pps->cbd != NULL) {125 if (pps->cbd != NULL)
108 struct radio_data *pps_rd =126 qcom_msim_do_set_rat_mode(pps->rs, pps->pref, pps->cbd);
109 ofono_radio_settings_get_data(pps->rs);
110 g_ril_request_set_preferred_network_type(pps_rd->ril,
111 pps->pref, &rilp);
112
113 if (g_ril_send(pps_rd->ril,
114 RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE,
115 &rilp, qcom_msim_set_rat_cb, pps->cbd,
116 g_free) == 0) {
117 ofono_error("%s: unable to set rat mode",
118 __func__);
119 cb = pps->cbd->cb;
120 CALLBACK_WITH_FAILURE(cb, pps->cbd->data);
121 g_free(pps->cbd);
122 }
123 }
124127
125 g_free(pps);128 g_free(pps);
126 }129 }
@@ -131,10 +134,10 @@
131 ofono_radio_settings_rat_mode_set_cb_t cb,134 ofono_radio_settings_rat_mode_set_cb_t cb,
132 void *data)135 void *data)
133{136{
134 struct radio_data *rd = ofono_radio_settings_get_data(rs);
135 struct cb_data *cbd = cb_data_new(cb, data, rs);137 struct cb_data *cbd = cb_data_new(cb, data, rs);
136 struct parcel rilp;138 struct parcel rilp;
137 int pref = PREF_NET_TYPE_GSM_WCDMA;139 int pref = PREF_NET_TYPE_GSM_WCDMA;
140 struct qcom_msim_pending_pref_setting *pps = NULL;
138141
139 switch (mode) {142 switch (mode) {
140 case OFONO_RADIO_ACCESS_MODE_ANY:143 case OFONO_RADIO_ACCESS_MODE_ANY:
@@ -151,24 +154,43 @@
151 break;154 break;
152 }155 }
153156
154 if (pref != PREF_NET_TYPE_GSM_ONLY && multisim_num_slots > 1) {157 if (pref != PREF_NET_TYPE_GSM_ONLY) {
155 struct qcom_msim_pending_pref_setting *pps =
156 g_try_new0(struct qcom_msim_pending_pref_setting, 1);
157 int i;158 int i;
158
159 pps->rs = rs;
160 pps->pref = pref;
161 pps->cbd = cbd;
162 pps->pending_gsm_pref_remaining = 0;
163
164 for (i = 0; i < QCOMMSIM_NUM_SLOTS_MAX; i++) {159 for (i = 0; i < QCOMMSIM_NUM_SLOTS_MAX; i++) {
165 struct radio_data *temp_rd;160 struct radio_data *temp_rd;
166 struct qcom_msim_set_2g_rat *set_2g_rat_data;161 struct qcom_msim_set_2g_rat *set_2g_rat_data;
162 struct ofono_atom *sim_atom;
163 struct ofono_sim *sim;
167164
168 if (multisim_rs[i] == rs || multisim_rs[i] == NULL)165 if (multisim_rs[i] == rs || multisim_rs[i] == NULL)
169 continue;166 continue;
170167
171 temp_rd = ofono_radio_settings_get_data(multisim_rs[i]);168 temp_rd = ofono_radio_settings_get_data(multisim_rs[i]);
169 sim_atom = __ofono_modem_find_atom(temp_rd->modem,
170 OFONO_ATOM_TYPE_SIM);
171 if (sim_atom == NULL) {
172 if (pps != NULL)
173 pps->cbd = NULL;
174 g_free(cbd);
175 CALLBACK_WITH_FAILURE(cb, data);
176 break;
177 }
178
179 sim = __ofono_atom_get_data(sim_atom);
180 if (ofono_sim_get_state(sim) ==
181 OFONO_SIM_STATE_NOT_PRESENT)
182 continue;
183
184 if (pps == NULL) {
185 pps = g_try_new0(
186 struct qcom_msim_pending_pref_setting,
187 1);
188 pps->rs = rs;
189 pps->pref = pref;
190 pps->cbd = cbd;
191 pps->pending_gsm_pref_remaining = 0;
192 }
193
172 set_2g_rat_data =194 set_2g_rat_data =
173 g_try_new0(struct qcom_msim_set_2g_rat, 1);195 g_try_new0(struct qcom_msim_set_2g_rat, 1);
174 set_2g_rat_data->pps = pps;196 set_2g_rat_data->pps = pps;
@@ -192,20 +214,15 @@
192 pps->pending_gsm_pref_remaining += 1;214 pps->pending_gsm_pref_remaining += 1;
193 }215 }
194 }216 }
195217 }
196 if (pps->pending_gsm_pref_remaining == 0)218
197 g_free(pps);219 if (pps && pps->pending_gsm_pref_remaining == 0) {
198 } else {220 g_free(pps);
199 g_ril_request_set_preferred_network_type(rd->ril, pref, &rilp);221 pps = NULL;
200222 }
201 if (g_ril_send(rd->ril, RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE,223
202 &rilp, qcom_msim_set_rat_cb, cbd,224 if (pps == NULL)
203 g_free) == 0) {225 qcom_msim_do_set_rat_mode(rs, pref, cbd);
204 ofono_error("%s: unable to set rat mode", __func__);
205 g_free(cbd);
206 CALLBACK_WITH_FAILURE(cb, data);
207 }
208 }
209}226}
210227
211static int qcom_msim_radio_settings_probe(struct ofono_radio_settings *rs,228static int qcom_msim_radio_settings_probe(struct ofono_radio_settings *rs,
@@ -229,7 +246,6 @@
229246
230 slot_id = ofono_modem_get_integer(rsd->modem, "Slot");247 slot_id = ofono_modem_get_integer(rsd->modem, "Slot");
231 multisim_rs[slot_id] = rs;248 multisim_rs[slot_id] = rs;
232 multisim_num_slots += 1;
233249
234 return 0;250 return 0;
235}251}
@@ -240,7 +256,6 @@
240 int slot_id = ofono_modem_get_integer(rd->modem, "Slot");256 int slot_id = ofono_modem_get_integer(rd->modem, "Slot");
241257
242 multisim_rs[slot_id] = NULL;258 multisim_rs[slot_id] = NULL;
243 multisim_num_slots -= 1;
244259
245 ofono_radio_settings_set_data(rs, NULL);260 ofono_radio_settings_set_data(rs, NULL);
246261
247262
=== modified file 'drivers/rilmodem/call-barring.c'
--- drivers/rilmodem/call-barring.c 2014-04-21 07:56:17 +0000
+++ drivers/rilmodem/call-barring.c 2016-03-14 09:03:03 +0000
@@ -105,8 +105,8 @@
105 goto error;105 goto error;
106 }106 }
107107
108 /* Just for printing return value */108 if (g_ril_reply_parse_set_facility_lock(bd->ril, message) < 0)
109 g_ril_reply_parse_set_facility_lock(bd->ril, message);109 goto error;
110110
111 CALLBACK_WITH_SUCCESS(cb, cbd->data);111 CALLBACK_WITH_SUCCESS(cb, cbd->data);
112 return;112 return;
113113
=== modified file 'drivers/rilmodem/sim.c'
--- drivers/rilmodem/sim.c 2015-10-07 07:14:11 +0000
+++ drivers/rilmodem/sim.c 2016-03-14 09:03:03 +0000
@@ -733,6 +733,12 @@
733 struct reply_sim_status *status;733 struct reply_sim_status *status;
734 guint search_index;734 guint search_index;
735735
736 if (message->error != RIL_E_SUCCESS) {
737 ofono_error("%s: RIL error %s", __func__,
738 ril_error_to_string(message->error));
739 return;
740 }
741
736 status = g_ril_reply_parse_sim_status(sd->ril, message);742 status = g_ril_reply_parse_sim_status(sd->ril, message);
737 if (status == NULL) {743 if (status == NULL) {
738 ofono_error("%s: Cannot parse SIM status reply", __func__);744 ofono_error("%s: Cannot parse SIM status reply", __func__);
739745
=== modified file 'drivers/rilmodem/sms.c'
--- drivers/rilmodem/sms.c 2014-04-15 23:42:56 +0000
+++ drivers/rilmodem/sms.c 2016-03-14 09:03:03 +0000
@@ -127,19 +127,17 @@
127static void ril_submit_sms_cb(struct ril_msg *message, gpointer user_data)127static void ril_submit_sms_cb(struct ril_msg *message, gpointer user_data)
128{128{
129 struct cb_data *cbd = user_data;129 struct cb_data *cbd = user_data;
130 struct ofono_error error;
131 ofono_sms_submit_cb_t cb = cbd->cb;130 ofono_sms_submit_cb_t cb = cbd->cb;
132 struct sms_data *sd = cbd->user;131 struct sms_data *sd = cbd->user;
133 int mr = 0;132 int mr;
134133
135 if (message->error == RIL_E_SUCCESS) {134 if (message->error != RIL_E_SUCCESS) {
136 decode_ril_error(&error, "OK");135 CALLBACK_WITH_FAILURE(cb, 0, cbd->data);
137 mr = g_ril_reply_parse_sms_response(sd->ril, message);136 return;
138 } else {
139 decode_ril_error(&error, "FAIL");
140 }137 }
141138
142 cb(&error, mr, cbd->data);139 mr = g_ril_reply_parse_sms_response(sd->ril, message);
140 CALLBACK_WITH_SUCCESS(cb, mr, cbd->data);
143}141}
144142
145static void ril_cmgs(struct ofono_sms *sms, const unsigned char *pdu,143static void ril_cmgs(struct ofono_sms *sms, const unsigned char *pdu,
146144
=== modified file 'gril/gril.c'
--- gril/gril.c 2015-11-10 09:17:36 +0000
+++ gril/gril.c 2016-03-14 09:03:03 +0000
@@ -104,6 +104,7 @@
104 int slot;104 int slot;
105 GRilMsgIdToStrFunc req_to_string;105 GRilMsgIdToStrFunc req_to_string;
106 GRilMsgIdToStrFunc unsol_to_string;106 GRilMsgIdToStrFunc unsol_to_string;
107 int version;
107};108};
108109
109struct _GRil {110struct _GRil {
@@ -1066,6 +1067,7 @@
1066 ril->ref_count = 1;1067 ril->ref_count = 1;
10671068
1068 ril->parent->vendor = vendor;1069 ril->parent->vendor = vendor;
1070 ril->parent->version = RIL_VERSION_UNSPECIFIED;
10691071
1070 return ril;1072 return ril;
1071}1073}
@@ -1207,6 +1209,24 @@
1207 return ril->parent->slot;1209 return ril->parent->slot;
1208}1210}
12091211
1212gboolean g_ril_set_version(GRil *ril, int version)
1213{
1214 if (ril == NULL || ril->parent == NULL ||
1215 ril->parent->version != RIL_VERSION_UNSPECIFIED)
1216 return FALSE;
1217
1218 ril->parent->version = version;
1219 return TRUE;
1220}
1221
1222int g_ril_get_version(GRil *ril)
1223{
1224 if (ril == NULL)
1225 return RIL_VERSION_UNSPECIFIED;
1226
1227 return ril->parent->version;
1228}
1229
1210gboolean g_ril_set_debugf(GRil *ril,1230gboolean g_ril_set_debugf(GRil *ril,
1211 GRilDebugFunc func, gpointer user_data)1231 GRilDebugFunc func, gpointer user_data)
1212{1232{
12131233
=== modified file 'gril/gril.h'
--- gril/gril.h 2014-07-31 06:45:32 +0000
+++ gril/gril.h 2016-03-14 09:03:03 +0000
@@ -129,6 +129,9 @@
129int g_ril_get_slot(GRil *ril);129int g_ril_get_slot(GRil *ril);
130gboolean g_ril_set_slot(GRil *ril, int slot);130gboolean g_ril_set_slot(GRil *ril, int slot);
131131
132int g_ril_get_version(GRil *ril);
133gboolean g_ril_set_version(GRil *ril, int version);
134
132/*!135/*!
133 * If the function is not NULL, then on every read/write from the GIOChannel136 * If the function is not NULL, then on every read/write from the GIOChannel
134 * provided to GRil the logging function will be called with the137 * provided to GRil the logging function will be called with the
135138
=== modified file 'gril/grilreply.c'
--- gril/grilreply.c 2015-10-23 07:09:51 +0000
+++ gril/grilreply.c 2016-03-14 09:03:03 +0000
@@ -1258,8 +1258,10 @@
1258 g_ril_init_parcel(message, &rilp);1258 g_ril_init_parcel(message, &rilp);
12591259
1260 /* mako reply has no payload for call barring */1260 /* mako reply has no payload for call barring */
1261 if (parcel_data_avail(&rilp) == 0)1261 if (parcel_data_avail(&rilp) == 0) {
1262 goto end;1262 retries = 0;
1263 goto done;
1264 }
12631265
1264 numint = parcel_r_int32(&rilp);1266 numint = parcel_r_int32(&rilp);
1265 if (numint != 1) {1267 if (numint != 1) {
@@ -1271,13 +1273,19 @@
12711273
1272 if (rilp.malformed) {1274 if (rilp.malformed) {
1273 ofono_error("%s: malformed parcel", __func__);1275 ofono_error("%s: malformed parcel", __func__);
1276 retries = -1;
1274 goto end;1277 goto end;
1275 }1278 }
12761279
1277end:1280done:
1278 g_ril_append_print_buf(gril, "{%d}", retries);1281 g_ril_append_print_buf(gril, "{%d}", retries);
1279 g_ril_print_response(gril, message);1282 g_ril_print_response(gril, message);
12801283
1284 /* -1 indicates unknown; reset to 0 so as to not trigger failure */
1285 if (retries == -1)
1286 retries = 0;
1287
1288end:
1281 return retries;1289 return retries;
1282}1290}
12831291
12841292
=== modified file 'gril/grilunsol.c'
--- gril/grilunsol.c 2015-09-29 08:47:19 +0000
+++ gril/grilunsol.c 2016-03-14 09:03:03 +0000
@@ -48,6 +48,30 @@
48 */48 */
49#define MIN_NITZ_SIZE 1749#define MIN_NITZ_SIZE 17
5050
51int g_ril_unsol_parse_connected(GRil *gril, const struct ril_msg *message)
52{
53 struct parcel rilp;
54 int size;
55 int version;
56
57 DBG("");
58
59 g_ril_init_parcel(message, &rilp);
60
61 size = parcel_r_int32(&rilp);
62 version = parcel_r_int32(&rilp);
63
64 if (rilp.malformed) {
65 ofono_error("%s: malformed parcel", __func__);
66 version = RIL_VERSION_UNSPECIFIED;
67 }
68
69 g_ril_append_print_buf(gril, "{size:%d, [%d, ...]}", size, version);
70 g_ril_print_unsol(gril, message);
71
72 return version;
73}
74
51static gint data_call_compare(gconstpointer a, gconstpointer b)75static gint data_call_compare(gconstpointer a, gconstpointer b)
52{76{
53 const struct ril_data_call *ca = a;77 const struct ril_data_call *ca = a;
5478
=== modified file 'gril/grilunsol.h'
--- gril/grilunsol.h 2014-08-11 12:41:11 +0000
+++ gril/grilunsol.h 2016-03-14 09:03:03 +0000
@@ -64,6 +64,8 @@
64 char *message;64 char *message;
65};65};
6666
67int g_ril_unsol_parse_connected(GRil *gril, const struct ril_msg *message);
68
67void g_ril_unsol_free_data_call_list(struct ril_data_call_list *data_call_list);69void g_ril_unsol_free_data_call_list(struct ril_data_call_list *data_call_list);
6870
6971
7072
=== modified file 'gril/ril_constants.h'
--- gril/ril_constants.h 2015-02-18 13:54:39 +0000
+++ gril/ril_constants.h 2016-03-14 09:03:03 +0000
@@ -23,7 +23,8 @@
2323
24#ifndef __RIL_CONSTANTS_H24#ifndef __RIL_CONSTANTS_H
25#define __RIL_CONSTANTS_H 125#define __RIL_CONSTANTS_H 1
26#define RIL_VERSION 726
27#define RIL_VERSION_UNSPECIFIED 0
2728
28/* Error Codes */29/* Error Codes */
29#define RIL_E_SUCCESS 030#define RIL_E_SUCCESS 0
3031
=== modified file 'include/log.h'
--- include/log.h 2011-10-10 20:39:42 +0000
+++ include/log.h 2016-03-14 09:03:03 +0000
@@ -67,6 +67,8 @@
67 __FILE__, __FUNCTION__ , ## arg); \67 __FILE__, __FUNCTION__ , ## arg); \
68} while (0)68} while (0)
6969
70#define PRINTABLE_STR(s) ((s) ? (s) : "(null)")
71
70#ifdef __cplusplus72#ifdef __cplusplus
71}73}
72#endif74#endif
7375
=== added file 'include/system-settings.h'
--- include/system-settings.h 1970-01-01 00:00:00 +0000
+++ include/system-settings.h 2016-03-14 09:03:03 +0000
@@ -0,0 +1,51 @@
1/*
2 *
3 * oFono - Open Telephony stack for Linux
4 *
5 * Copyright (C) 2016 Canonical Ltd.
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#ifndef OFONO_SYSTEM_SETTINGS_H
23#define OFONO_SYSTEM_SETTINGS_H
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/* Settings names */
30#define PREFERRED_VOICE_MODEM "PreferredVoiceModem"
31
32struct ofono_system_settings_driver {
33 const char *name;
34 /* The user must free the returned string */
35 char *(*get_string_value)(const char *name);
36};
37
38/* The user must free the returned string */
39char *__ofono_system_settings_get_string_value(const char *name);
40
41int ofono_system_settings_driver_register(
42 struct ofono_system_settings_driver *driver);
43
44void ofono_system_settings_driver_unregister(
45 const struct ofono_system_settings_driver *driver);
46
47#ifdef __cplusplus
48}
49#endif
50
51#endif /* OFONO_SYSTEM_SETTINGS_H */
052
=== added file 'include/wakelock.h'
--- include/wakelock.h 1970-01-01 00:00:00 +0000
+++ include/wakelock.h 2016-03-14 09:03:03 +0000
@@ -0,0 +1,100 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2015 Jolla Ltd. All rights reserved.
6 * Contact: Hannu Mallat <hannu.mallat@jollamobile.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24#ifndef __OFONO_WAKELOCK_H_
25#define __OFONO_WAKELOCK_H_
26
27#include <ofono/types.h>
28
29/* Wakelock interface
30 *
31 * Wakelocks ensure system does not suspend/enter power save mode
32 * before an ongoing operation completes. This header declares a
33 * wakelock API that can be implemented by a OS-specific plugin.
34 */
35
36struct wakelock; /* Opaque */
37
38struct wakelock_table {
39 int (*create)(const char *name, struct wakelock **);
40 int (*free)(struct wakelock *);
41 int (*acquire)(struct wakelock *);
42 int (*release)(struct wakelock *);
43 ofono_bool_t (*is_locked)(struct wakelock *);
44};
45
46
47/*** Functions for wakelock users ***/
48
49/*
50 * This will create a wakelock which will be held for a short duration
51 * and then automatically freed. If this is called multiple times the
52 * timeout will be restarted on every call.
53 */
54void wakelock_system_lock(void);
55
56/*
57 * Create a wakelock. Multiple wakelocks can be created; if any one of
58 * them is activated, system will be prevented from going to suspend.
59 * This makes it possible to overlap locks to hand over from subsystem
60 * to subsystem, each with their own wakelock-guarded sections,
61 * without falling to suspend in between.
62 */
63int wakelock_create(const char *name, struct wakelock **wakelock);
64
65/*
66 * Free a wakelock, releasing all acquisitions at the same time
67 * and deallocating the lock.
68 */
69int wakelock_free(struct wakelock *wakelock);
70
71/*
72 * Acquire a wakelock. Multiple acquisitions are possible, meaning
73 * that the wakelock needs to be released the same number of times
74 * until it is actually deactivated.
75 */
76int wakelock_acquire(struct wakelock *wakelock);
77
78/*
79 * Release a wakelock, deactivating it if all acquisitions are
80 * released, letting system suspend.
81 */
82int wakelock_release(struct wakelock *wakelock);
83
84/*
85 * Check if a wakelock is currently locked or not.
86 */
87ofono_bool_t wakelock_is_locked(struct wakelock *wakelock);
88
89/*** Functions for wakelock implementors ***/
90
91/*
92 * Register a wakelock implementation. Only one implementation may be
93 * registered at a time. In the absence of an implementation, all
94 * wakelock functions are no-ops.
95 */
96int wakelock_plugin_register(const char *name, struct wakelock_table *fns);
97
98int wakelock_plugin_unregister(void);
99
100#endif
0101
=== removed file 'include/wakelock.h'
--- include/wakelock.h 2016-01-15 16:03:09 +0000
+++ include/wakelock.h 1970-01-01 00:00:00 +0000
@@ -1,100 +0,0 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2015 Jolla Ltd. All rights reserved.
6 * Contact: Hannu Mallat <hannu.mallat@jollamobile.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24#ifndef __OFONO_WAKELOCK_H_
25#define __OFONO_WAKELOCK_H_
26
27#include <ofono/types.h>
28
29/* Wakelock interface
30 *
31 * Wakelocks ensure system does not suspend/enter power save mode
32 * before an ongoing operation completes. This header declares a
33 * wakelock API that can be implemented by a OS-specific plugin.
34 */
35
36struct wakelock; /* Opaque */
37
38struct wakelock_table {
39 int (*create)(const char *name, struct wakelock **);
40 int (*free)(struct wakelock *);
41 int (*acquire)(struct wakelock *);
42 int (*release)(struct wakelock *);
43 ofono_bool_t (*is_locked)(struct wakelock *);
44};
45
46
47/*** Functions for wakelock users ***/
48
49/*
50 * This will create a wakelock which will be held for a short duration
51 * and then automatically freed. If this is called multiple times the
52 * timeout will be restarted on every call.
53 */
54void wakelock_system_lock(void);
55
56/*
57 * Create a wakelock. Multiple wakelocks can be created; if any one of
58 * them is activated, system will be prevented from going to suspend.
59 * This makes it possible to overlap locks to hand over from subsystem
60 * to subsystem, each with their own wakelock-guarded sections,
61 * without falling to suspend in between.
62 */
63int wakelock_create(const char *name, struct wakelock **wakelock);
64
65/*
66 * Free a wakelock, releasing all acquisitions at the same time
67 * and deallocating the lock.
68 */
69int wakelock_free(struct wakelock *wakelock);
70
71/*
72 * Acquire a wakelock. Multiple acquisitions are possible, meaning
73 * that the wakelock needs to be released the same number of times
74 * until it is actually deactivated.
75 */
76int wakelock_acquire(struct wakelock *wakelock);
77
78/*
79 * Release a wakelock, deactivating it if all acquisitions are
80 * released, letting system suspend.
81 */
82int wakelock_release(struct wakelock *wakelock);
83
84/*
85 * Check if a wakelock is currently locked or not.
86 */
87ofono_bool_t wakelock_is_locked(struct wakelock *wakelock);
88
89/*** Functions for wakelock implementors ***/
90
91/*
92 * Register a wakelock implementation. Only one implementation may be
93 * registered at a time. In the absence of an implementation, all
94 * wakelock functions are no-ops.
95 */
96int wakelock_plugin_register(const char *name, struct wakelock_table *fns);
97
98int wakelock_plugin_unregister(void);
99
100#endif
1010
=== added file 'plugins/accounts-settings.c'
--- plugins/accounts-settings.c 1970-01-01 00:00:00 +0000
+++ plugins/accounts-settings.c 2016-03-14 09:03:03 +0000
@@ -0,0 +1,474 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2016 Canonical Ltd.
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 <stdlib.h>
27#include <string.h>
28#include <stdio.h>
29
30#include <sys/types.h>
31#include <pwd.h>
32#include <errno.h>
33#include <unistd.h>
34
35#include <glib.h>
36#include <gdbus.h>
37#include <systemd/sd-login.h>
38
39#include <ofono.h>
40
41#define OFONO_API_SUBJECT_TO_CHANGE
42#include <ofono/types.h>
43#include <ofono/log.h>
44#include <ofono/plugin.h>
45#include <ofono/system-settings.h>
46
47#define ACCOUNTS_SERVICE "org.freedesktop.Accounts"
48#define ACCOUNTS_PATH "/org/freedesktop/Accounts/User"
49#define ACCOUNTS_PHONE_INTERFACE "com.ubuntu.touch.AccountsService.Phone"
50#define DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
51
52struct setting {
53 char* ofono_name;
54 char* property_name;
55};
56
57static const struct setting setting_names[] = {
58 { PREFERRED_VOICE_MODEM, "DefaultSimForCalls" }
59};
60
61#define NUM_SETTINGS G_N_ELEMENTS(setting_names)
62
63struct accounts_data {
64 sd_login_monitor *login_monitor;
65 guint login_watch;
66 char *property_values[NUM_SETTINGS];
67 uid_t current_uid;
68 guint prop_change_watch;
69 char uid_path[sizeof(ACCOUNTS_PATH) + 32];
70};
71
72static struct accounts_data g_accounts;
73
74static int translate_name(const char *name)
75{
76 size_t i;
77
78 for (i = 0; i < NUM_SETTINGS; ++i) {
79 if (g_strcmp0(setting_names[i].ofono_name, name) != 0)
80 continue;
81
82 return i;
83 }
84
85 return -1;
86}
87
88static char *accounts_settings_get_string_value(const char *name)
89{
90 int id;
91
92 id = translate_name(name);
93 if (id < 0)
94 return NULL;
95
96 return g_strdup(g_accounts.property_values[id]);
97}
98
99static struct ofono_system_settings_driver accounts_settings_driver = {
100 .name = "Accounts Service System Settings",
101 .get_string_value = accounts_settings_get_string_value
102};
103
104static int get_id_from_name(const char *name)
105{
106 size_t i;
107
108 for (i = 0; i < NUM_SETTINGS; ++i) {
109 if (g_strcmp0(setting_names[i].property_name, name) != 0)
110 continue;
111
112 return i;
113 }
114
115 return -1;
116}
117
118static char *get_property_value(DBusMessage *reply)
119{
120 DBusMessageIter iter, val;
121 const char *ptr;
122 char *property = NULL;
123
124 if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
125 ofono_error("%s: ERROR reply to Get", __func__);
126 goto done;
127 }
128
129 if (dbus_message_iter_init(reply, &iter) == FALSE) {
130 ofono_error("%s: error initializing array iter", __func__);
131 goto done;
132 }
133
134 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) {
135 ofono_error("%s: type != VARIANT!", __func__);
136 goto done;
137 }
138
139 dbus_message_iter_recurse(&iter, &val);
140
141 if (dbus_message_iter_get_arg_type(&val) != DBUS_TYPE_STRING) {
142 ofono_error("%s: type != STRING!", __func__);
143 goto done;
144 }
145
146 dbus_message_iter_get_basic(&val, &ptr);
147
148 property = g_strdup(ptr);
149
150done:
151 return property;
152}
153
154struct get_property_data {
155 struct accounts_data *accounts;
156 int prop_id;
157};
158
159static void get_property_reply(DBusPendingCall *call, void *user_data)
160{
161 DBusMessage *reply;
162 struct get_property_data *gpd = user_data;
163 char **values = gpd->accounts->property_values;
164 int id = gpd->prop_id;
165
166 reply = dbus_pending_call_steal_reply(call);
167 if (reply == NULL) {
168 ofono_error("%s: failed to get reply", __func__);
169 goto done;
170 }
171
172 g_free(values[id]);
173 values[id] = get_property_value(reply);
174 dbus_message_unref(reply);
175
176 DBG("property %s has value %s",
177 setting_names[id].property_name, PRINTABLE_STR(values[id]));
178
179done:
180 dbus_pending_call_unref(call);
181 g_free(gpd);
182}
183
184static void get_property(struct accounts_data *accounts, int id)
185{
186 DBusMessageIter iter;
187 DBusMessage *msg;
188 const char *iface = ACCOUNTS_PHONE_INTERFACE;
189 DBusConnection *conn = ofono_dbus_get_connection();
190 DBusPendingCall *call;
191 struct get_property_data *gpd;
192
193 msg = dbus_message_new_method_call(ACCOUNTS_SERVICE, accounts->uid_path,
194 DBUS_PROPERTIES_INTERFACE,
195 "Get");
196 if (msg == NULL) {
197 ofono_error("%s: dbus_message_new_method failed", __func__);
198 return;
199 }
200
201 dbus_message_iter_init_append(msg, &iter);
202 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &iface);
203 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
204 &setting_names[id].property_name);
205
206 if (!dbus_connection_send_with_reply(conn, msg, &call, -1)) {
207 ofono_error("%s: Sending Get failed", __func__);
208 goto done;
209 }
210
211 gpd = g_malloc0(sizeof(*gpd));
212 gpd->accounts = accounts;
213 gpd->prop_id = id;
214 dbus_pending_call_set_notify(call, get_property_reply, gpd, NULL);
215
216done:
217 dbus_message_unref(msg);
218}
219
220static gboolean property_changed(DBusConnection *conn,
221 DBusMessage *msg, void *user_data)
222{
223 struct accounts_data *accounts = user_data;
224 const char *iface;
225 DBusMessageIter iter, dict, inv_it;
226
227 dbus_message_iter_init(msg, &iter);
228
229 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) {
230 ofono_error("%s: iface != TYPE_STRING!", __func__);
231 goto done;
232 }
233
234 dbus_message_iter_get_basic(&iter, &iface);
235
236 /* We can receive notifications from other AccountsService interfaces */
237 if (g_str_equal(iface, ACCOUNTS_PHONE_INTERFACE) != TRUE)
238 goto done;
239
240 if (!dbus_message_iter_next(&iter)) {
241 ofono_error("%s: advance iter failed!", __func__);
242 goto done;
243 }
244
245 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
246 ofono_error("%s: type != ARRAY!", __func__);
247 goto done;
248 }
249
250 dbus_message_iter_recurse(&iter, &dict);
251
252 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
253 DBusMessageIter entry, val;
254 const char *key, *str_val;
255 int id;
256
257 dbus_message_iter_recurse(&dict, &entry);
258
259 if (dbus_message_iter_get_arg_type(&entry) !=
260 DBUS_TYPE_STRING) {
261 ofono_error("%s: key type != STRING!", __func__);
262 goto done;
263 }
264
265 dbus_message_iter_get_basic(&entry, &key);
266
267 dbus_message_iter_next(&entry);
268
269 if (dbus_message_iter_get_arg_type(&entry) !=
270 DBUS_TYPE_VARIANT) {
271 ofono_error("%s: val != VARIANT", __func__);
272 goto done;
273 }
274
275 dbus_message_iter_recurse(&entry, &val);
276
277 if (dbus_message_iter_get_arg_type(&val) != DBUS_TYPE_STRING) {
278 ofono_error("%s: *val != STRING", __func__);
279 goto done;
280 }
281
282 dbus_message_iter_get_basic(&val, &str_val);
283
284 DBG("property %s changed to %s", key, PRINTABLE_STR(str_val));
285
286 id = get_id_from_name(key);
287 if (id >= 0)
288 accounts->property_values[id] = g_strdup(str_val);
289
290 dbus_message_iter_next(&dict);
291 }
292
293 /* Check invalidated properties */
294 if (!dbus_message_iter_next(&iter)) {
295 ofono_error("%s: advance iter failed!", __func__);
296 goto done;
297 }
298
299 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
300 ofono_error("%s: type != ARRAY!", __func__);
301 goto done;
302 }
303
304 dbus_message_iter_recurse(&iter, &inv_it);
305
306 while (dbus_message_iter_get_arg_type(&inv_it) == DBUS_TYPE_STRING) {
307 const char *inv_name;
308 int id;
309
310 dbus_message_iter_get_basic(&inv_it, &inv_name);
311
312 DBG("property %s invalidated", inv_name);
313
314 id = get_id_from_name(inv_name);
315 if (id >= 0)
316 get_property(accounts, id);
317
318 dbus_message_iter_next(&inv_it);
319 }
320
321done:
322 return TRUE;
323}
324
325static void get_user_settings(struct accounts_data *accounts)
326{
327 DBusConnection *conn = ofono_dbus_get_connection();
328 size_t i;
329
330 snprintf(accounts->uid_path, sizeof(accounts->uid_path),
331 ACCOUNTS_PATH"%u", (unsigned) accounts->current_uid);
332
333 /*
334 * Register for property changes. Note that AccountsService is D-Bus,
335 * initiated, so there is no risk for race conditions on start.
336 */
337 accounts->prop_change_watch =
338 g_dbus_add_signal_watch(conn, ACCOUNTS_SERVICE,
339 accounts->uid_path,
340 DBUS_INTERFACE_PROPERTIES,
341 "PropertiesChanged",
342 property_changed,
343 accounts, NULL);
344
345 /* Retrieve AccountService properties */
346 for (i = 0; i < NUM_SETTINGS; ++i)
347 get_property(accounts, i);
348}
349
350static void release_accounts_data(struct accounts_data *accounts)
351{
352 DBusConnection *conn = ofono_dbus_get_connection();
353 size_t i;
354
355 g_dbus_remove_watch(conn, accounts->prop_change_watch);
356
357 for (i = 0; i < NUM_SETTINGS; ++i) {
358 g_free(accounts->property_values[i]);
359 accounts->property_values[i] = NULL;
360 }
361}
362
363static uid_t get_active_seat_uid(void)
364{
365 char **seats, **iter;
366 int res;
367 gboolean found = FALSE;
368 uid_t uid;
369
370 res = sd_get_seats(&seats);
371 if (res < 0) {
372 ofono_error("Error retrieving seats: %s (%d)",
373 strerror(-res), -res);
374 goto end;
375 } else if (res == 0) {
376 ofono_info("No seats found");
377 goto end;
378 }
379
380 for (iter = seats; *iter; ++iter) {
381
382 if (!found && sd_seat_get_active(*iter, NULL, &uid) >= 0) {
383 DBG("seat %s with uid %d", *iter, uid);
384 found = TRUE;
385 }
386
387 free(*iter);
388 }
389
390 free(seats);
391
392end:
393 if (!found)
394 uid = geteuid();
395
396 return uid;
397}
398
399static gboolean sd_changed(GIOChannel *stream, GIOCondition condition,
400 gpointer user_data)
401{
402 struct accounts_data *accounts = user_data;
403 uid_t new_uid;
404
405 sd_login_monitor_flush(accounts->login_monitor);
406
407 new_uid = get_active_seat_uid();
408 if (new_uid != accounts->current_uid) {
409 /* User in seat changed, resetting data */
410 release_accounts_data(accounts);
411
412 accounts->current_uid = new_uid;
413 get_user_settings(accounts);
414 }
415
416 return TRUE;
417}
418
419static void sd_init(struct accounts_data *accounts)
420{
421 int status;
422 GIOChannel *stream;
423 int fd;
424
425 status = sd_login_monitor_new(NULL, &accounts->login_monitor);
426 if (status < 0) {
427 ofono_error("Error creating systemd login monitor: %d", status);
428 accounts->login_monitor = NULL;
429 return;
430 }
431
432 fd = sd_login_monitor_get_fd(accounts->login_monitor);
433 stream = g_io_channel_unix_new(fd);
434 accounts->login_watch =
435 g_io_add_watch(stream, G_IO_IN, sd_changed, accounts);
436
437 g_io_channel_unref(stream);
438}
439
440static void sd_finalize(struct accounts_data *accounts)
441{
442 if (accounts->login_monitor == NULL)
443 return;
444
445 g_source_remove(accounts->login_watch);
446 sd_login_monitor_unref(accounts->login_monitor);
447}
448
449static int accounts_settings_init(void)
450{
451 g_accounts.current_uid = get_active_seat_uid();
452
453 /* Register for login changes */
454 sd_init(&g_accounts);
455
456 /* Get property values for current user */
457 get_user_settings(&g_accounts);
458
459 return ofono_system_settings_driver_register(&accounts_settings_driver);
460}
461
462static void accounts_settings_exit(void)
463{
464 ofono_system_settings_driver_unregister(&accounts_settings_driver);
465
466 sd_finalize(&g_accounts);
467
468 release_accounts_data(&g_accounts);
469}
470
471OFONO_PLUGIN_DEFINE(accounts_settings,
472 "Accounts Service System Settings Plugin",
473 VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT,
474 accounts_settings_init, accounts_settings_exit)
0475
=== added file 'plugins/android-wakelock.c'
--- plugins/android-wakelock.c 1970-01-01 00:00:00 +0000
+++ plugins/android-wakelock.c 2016-03-14 09:03:03 +0000
@@ -0,0 +1,212 @@
1/*
2 *
3 * oFono - Open Source Telephony - Android based wakelocks
4 *
5 * Copyright (C) 2016 Canonical Ltd.
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 as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <fcntl.h>
30#include <unistd.h>
31#include <string.h>
32#include <errno.h>
33#include <glib.h>
34#include <dlfcn.h>
35
36#include <glib.h>
37
38#define OFONO_API_SUBJECT_TO_CHANGE
39
40#include "plugin.h"
41#include "log.h"
42#include "wakelock.h"
43
44#define ANDROID_WAKELOCK_LOCK_PATH "/sys/power/wake_lock"
45#define ANDROID_WAKELOCK_UNLOCK_PATH "/sys/power/wake_unlock"
46
47struct wakelock {
48 char *name;
49 unsigned int acquisitions;
50};
51
52GSList *locks = NULL;
53
54static int file_exists(char const *filename)
55{
56 struct stat st;
57
58 return stat(filename, &st) == 0;
59}
60
61static int write_file(const char *file, const char *content)
62{
63 int fd;
64 unsigned int r = 0;
65
66 fd = open(file, O_WRONLY);
67
68 if (fd == -1)
69 return -EIO;
70
71 r = write(fd, content, strlen(content));
72
73 close(fd);
74
75 if (r != strlen(content))
76 return -EIO;
77
78 return 0;
79}
80
81static int wakelock_lock(const char *name)
82{
83 return write_file(ANDROID_WAKELOCK_LOCK_PATH, name);
84}
85
86static int wakelock_unlock(const char *name)
87{
88 return write_file(ANDROID_WAKELOCK_UNLOCK_PATH, name);
89}
90
91static int android_wakelock_acquire(struct wakelock *lock)
92{
93 if (lock == NULL)
94 return -EINVAL;
95
96 if (lock->acquisitions > 0) {
97 lock->acquisitions++;
98 return 0;
99 }
100
101 if (wakelock_lock(lock->name) < 0)
102 return -EIO;
103
104 lock->acquisitions++;
105
106 return 0;
107}
108
109static int android_wakelock_release(struct wakelock *lock)
110{
111 if (lock == NULL)
112 return -EINVAL;
113
114 DBG("lock %p name %s acquisitions %d",
115 lock, lock->name, lock->acquisitions);
116
117 if (!lock->acquisitions) {
118 ofono_warn("Attempted to release already released lock %s", lock->name);
119 return -EINVAL;
120 }
121
122 if (lock->acquisitions > 1) {
123 lock->acquisitions--;
124 DBG("lock %s released acquisitions %d", lock->name, lock->acquisitions);
125 return 0;
126 }
127
128 if (wakelock_unlock(lock->name) < 0)
129 return -EIO;
130
131 lock->acquisitions = 0;
132
133 DBG("lock %s was released", lock->name);
134
135 return 0;
136}
137
138static int android_wakelock_create(const char *name, struct wakelock **lock)
139{
140 if (lock == NULL)
141 return -EINVAL;
142
143 *lock = g_new0(struct wakelock, 1);
144 (*lock)->name = g_strdup(name);
145 (*lock)->acquisitions = 0;
146
147 locks = g_slist_prepend(locks, *lock);
148
149 DBG("wakelock %s create", name);
150
151 return 0;
152}
153
154static int android_wakelock_free(struct wakelock *lock)
155{
156 if (lock == NULL)
157 return -EINVAL;
158
159 if (lock->acquisitions) {
160 /* Need to force releasing the lock here */
161 lock->acquisitions = 1;
162 android_wakelock_release(lock);
163 }
164
165 locks = g_slist_remove(locks, lock);
166
167 DBG("Freeing lock %s", lock->name);
168
169 g_free(lock->name);
170 g_free(lock);
171
172 return 0;
173}
174
175static ofono_bool_t android_wakelock_is_locked(struct wakelock *lock)
176{
177 if (lock == NULL)
178 return FALSE;
179
180 return lock->acquisitions > 0;
181}
182
183struct wakelock_table driver = {
184 .create = android_wakelock_create,
185 .free = android_wakelock_free,
186 .acquire = android_wakelock_acquire,
187 .release = android_wakelock_release,
188 .is_locked = android_wakelock_is_locked
189};
190
191static int android_wakelock_init(void)
192{
193 if (!file_exists(ANDROID_WAKELOCK_LOCK_PATH)) {
194 ofono_warn("System does not support Android wakelocks.");
195 return 0;
196 }
197
198 if (wakelock_plugin_register("android-wakelock", &driver) < 0) {
199 ofono_error("Failed to register wakelock driver");
200 return -EIO;
201 }
202
203 return 0;
204}
205
206static void android_wakelock_exit(void)
207{
208 wakelock_plugin_unregister();
209}
210
211OFONO_PLUGIN_DEFINE(android_wakelock, "Android Wakelock driver", VERSION,
212 OFONO_PLUGIN_PRIORITY_DEFAULT, android_wakelock_init, android_wakelock_exit)
0213
=== removed file 'plugins/android-wakelock.c'
--- plugins/android-wakelock.c 2016-01-15 16:03:09 +0000
+++ plugins/android-wakelock.c 1970-01-01 00:00:00 +0000
@@ -1,212 +0,0 @@
1/*
2 *
3 * oFono - Open Source Telephony - Android based wakelocks
4 *
5 * Copyright (C) 2016 Canonical Ltd.
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 as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <fcntl.h>
30#include <unistd.h>
31#include <string.h>
32#include <errno.h>
33#include <glib.h>
34#include <dlfcn.h>
35
36#include <glib.h>
37
38#define OFONO_API_SUBJECT_TO_CHANGE
39
40#include "plugin.h"
41#include "log.h"
42#include "wakelock.h"
43
44#define ANDROID_WAKELOCK_LOCK_PATH "/sys/power/wake_lock"
45#define ANDROID_WAKELOCK_UNLOCK_PATH "/sys/power/wake_unlock"
46
47struct wakelock {
48 char *name;
49 unsigned int acquisitions;
50};
51
52GSList *locks = NULL;
53
54static int file_exists(char const *filename)
55{
56 struct stat st;
57
58 return stat(filename, &st) == 0;
59}
60
61static int write_file(const char *file, const char *content)
62{
63 int fd;
64 unsigned int r = 0;
65
66 fd = open(file, O_WRONLY);
67
68 if (fd == -1)
69 return -EIO;
70
71 r = write(fd, content, strlen(content));
72
73 close(fd);
74
75 if (r != strlen(content))
76 return -EIO;
77
78 return 0;
79}
80
81static int wakelock_lock(const char *name)
82{
83 return write_file(ANDROID_WAKELOCK_LOCK_PATH, name);
84}
85
86static int wakelock_unlock(const char *name)
87{
88 return write_file(ANDROID_WAKELOCK_UNLOCK_PATH, name);
89}
90
91static int android_wakelock_acquire(struct wakelock *lock)
92{
93 if (!lock)
94 return -EINVAL;
95
96 if (lock->acquisitions > 0) {
97 lock->acquisitions++;
98 return 0;
99 }
100
101 if (wakelock_lock(lock->name) < 0)
102 return -EIO;
103
104 lock->acquisitions++;
105
106 return 0;
107}
108
109static int android_wakelock_release(struct wakelock *lock)
110{
111 if (!lock)
112 return -EINVAL;
113
114 DBG("lock %p name %s acquisitions %d",
115 lock, lock->name, lock->acquisitions);
116
117 if (!lock->acquisitions) {
118 ofono_warn("Attempted to release already released lock %s", lock->name);
119 return -EINVAL;
120 }
121
122 if (lock->acquisitions > 1) {
123 lock->acquisitions--;
124 DBG("lock %s released acquisitions %d", lock->name, lock->acquisitions);
125 return 0;
126 }
127
128 if (wakelock_unlock(lock->name) < 0)
129 return -EIO;
130
131 lock->acquisitions = 0;
132
133 DBG("lock %s was released", lock->name);
134
135 return 0;
136}
137
138static int android_wakelock_create(const char *name, struct wakelock **lock)
139{
140 if (!lock)
141 return -EINVAL;
142
143 *lock = g_new0(struct wakelock, 1);
144 (*lock)->name = g_strdup(name);
145 (*lock)->acquisitions = 0;
146
147 locks = g_slist_prepend(locks, *lock);
148
149 DBG("wakelock %s create", name);
150
151 return 0;
152}
153
154static int android_wakelock_free(struct wakelock *lock)
155{
156 if (!lock)
157 return -EINVAL;
158
159 if (lock->acquisitions) {
160 /* Need to force releasing the lock here */
161 lock->acquisitions = 1;
162 android_wakelock_release(lock);
163 }
164
165 locks = g_slist_remove(locks, lock);
166
167 DBG("Freeing lock %s", lock->name);
168
169 g_free(lock->name);
170 g_free(lock);
171
172 return 0;
173}
174
175static ofono_bool_t android_wakelock_is_locked(struct wakelock *lock)
176{
177 if (!lock)
178 return FALSE;
179
180 return lock->acquisitions > 0;
181}
182
183struct wakelock_table driver = {
184 .create = android_wakelock_create,
185 .free = android_wakelock_free,
186 .acquire = android_wakelock_acquire,
187 .release = android_wakelock_release,
188 .is_locked = android_wakelock_is_locked
189};
190
191static int android_wakelock_init(void)
192{
193 if (!file_exists(ANDROID_WAKELOCK_LOCK_PATH)) {
194 ofono_warn("System does not support Android wakelocks.");
195 return 0;
196 }
197
198 if (wakelock_plugin_register("android-wakelock", &driver) < 0) {
199 ofono_error("Failed to register wakelock driver");
200 return -EIO;
201 }
202
203 return 0;
204}
205
206static void android_wakelock_exit(void)
207{
208 wakelock_plugin_unregister();
209}
210
211OFONO_PLUGIN_DEFINE(android_wakelock, "Android Wakelock driver", VERSION,
212 OFONO_PLUGIN_PRIORITY_DEFAULT, android_wakelock_init, android_wakelock_exit)
2130
=== modified file 'plugins/qcom-msim.c'
--- plugins/qcom-msim.c 2015-04-23 13:08:30 +0000
+++ plugins/qcom-msim.c 2016-03-14 09:03:03 +0000
@@ -36,6 +36,18 @@
3636
37static int qcom_msim_probe(struct ofono_modem *modem)37static int qcom_msim_probe(struct ofono_modem *modem)
38{38{
39 int slot_id = ofono_modem_get_integer(modem, "Slot");
40
41 /* qcom_msim has socket path "rild", "rild1", ... */
42 if (slot_id != 0) {
43 char *socket;
44
45 socket = g_strdup_printf("/dev/socket/rild%d", slot_id);
46 ofono_modem_set_string(modem, "Socket", socket);
47
48 g_free(socket);
49 }
50
39 return ril_create(modem, OFONO_RIL_VENDOR_QCOM_MSIM);51 return ril_create(modem, OFONO_RIL_VENDOR_QCOM_MSIM);
40}52}
4153
4254
=== modified file 'plugins/ril.c'
--- plugins/ril.c 2015-10-07 07:14:11 +0000
+++ plugins/ril.c 2016-03-14 09:03:03 +0000
@@ -73,9 +73,6 @@
73#define RILD_MAX_CONNECT_RETRIES 573#define RILD_MAX_CONNECT_RETRIES 5
74#define RILD_CONNECT_RETRY_TIME_S 574#define RILD_CONNECT_RETRY_TIME_S 5
7575
76char *RILD_CMD_SOCKET[] = {"/dev/socket/rild", "/dev/socket/rild1"};
77char *GRIL_HEX_PREFIX[] = {"Device 0: ", "Device 1: "};
78
79struct ril_data {76struct ril_data {
80 GRil *ril;77 GRil *ril;
81 enum ofono_ril_vendor vendor;78 enum ofono_ril_vendor vendor;
@@ -90,9 +87,9 @@
9087
91static void ril_debug(const char *str, void *user_data)88static void ril_debug(const char *str, void *user_data)
92{89{
93 const char *prefix = user_data;90 struct ril_data *rd = user_data;
9491
95 ofono_info("%s%s", prefix, str);92 ofono_info("Device %d: %s", g_ril_get_slot(rd->ril), str);
96}93}
9794
98static void ril_radio_state_changed(struct ril_msg *message, gpointer user_data)95static void ril_radio_state_changed(struct ril_msg *message, gpointer user_data)
@@ -169,7 +166,7 @@
169166
170 rd->vendor = vendor;167 rd->vendor = vendor;
171 rd->ofono_online = FALSE;168 rd->ofono_online = FALSE;
172 rd->radio_state = RADIO_STATE_OFF;169 rd->radio_state = RADIO_STATE_UNAVAILABLE;
173170
174 lte_cap = getenv("OFONO_RIL_RAT_LTE") ? TRUE : FALSE;171 lte_cap = getenv("OFONO_RIL_RAT_LTE") ? TRUE : FALSE;
175 ofono_modem_set_boolean(modem, MODEM_PROP_LTE_CAPABLE, lte_cap);172 ofono_modem_set_boolean(modem, MODEM_PROP_LTE_CAPABLE, lte_cap);
@@ -284,7 +281,9 @@
284 struct ril_data *rd = cbd->user;281 struct ril_data *rd = cbd->user;
285 ofono_modem_online_cb_t cb = cbd->cb;282 ofono_modem_online_cb_t cb = cbd->cb;
286283
287 if (message->error == RIL_E_SUCCESS) {284 if (message != NULL && message->error == RIL_E_SUCCESS) {
285 g_ril_print_response_no_args(rd->ril, message);
286
288 DBG("%s: set_online OK: rd->ofono_online: %d", __func__,287 DBG("%s: set_online OK: rd->ofono_online: %d", __func__,
289 rd->ofono_online);288 rd->ofono_online);
290 CALLBACK_WITH_SUCCESS(cb, cbd->data);289 CALLBACK_WITH_SUCCESS(cb, cbd->data);
@@ -293,31 +292,24 @@
293 rd->ofono_online);292 rd->ofono_online);
294 CALLBACK_WITH_FAILURE(cb, cbd->data);293 CALLBACK_WITH_FAILURE(cb, cbd->data);
295 }294 }
295
296 g_free(cbd);
296}297}
297298
298static void ril_send_power(struct ril_data *rd, ofono_bool_t online,299static void ril_send_power(struct ril_data *rd, ofono_bool_t online,
299 GRilResponseFunc func,300 GRilResponseFunc func,
300 gpointer user_data)301 gpointer user_data)
301{302{
302 struct cb_data *cbd = user_data;
303 ofono_modem_online_cb_t cb;
304 GDestroyNotify notify = NULL;
305 struct parcel rilp;303 struct parcel rilp;
306304
307 if (cbd != NULL) {
308 notify = g_free;
309 cb = cbd->cb;
310 }
311
312 DBG("(online = 1, offline = 0)): %i", online);305 DBG("(online = 1, offline = 0)): %i", online);
313306
314 g_ril_request_power(rd->ril, (const gboolean) online, &rilp);307 g_ril_request_power(rd->ril, (const gboolean) online, &rilp);
315308
316 if (g_ril_send(rd->ril, RIL_REQUEST_RADIO_POWER, &rilp,309 if (g_ril_send(rd->ril, RIL_REQUEST_RADIO_POWER, &rilp,
317 func, cbd, notify) == 0 && cbd != NULL) {310 func, user_data, NULL) == 0 && func != NULL) {
318311
319 CALLBACK_WITH_FAILURE(cb, cbd->data);312 func(NULL, user_data);
320 g_free(cbd);
321 }313 }
322}314}
323315
@@ -334,30 +326,47 @@
334 ril_send_power(rd, online, ril_set_online_cb, cbd);326 ril_send_power(rd, online, ril_set_online_cb, cbd);
335}327}
336328
329static void ril_set_powered_off_cb(struct ril_msg *message, gpointer user_data)
330{
331 struct ofono_modem *modem = user_data;
332 struct ril_data *rd = ofono_modem_get_data(modem);
333
334 if (message != NULL && message->error == RIL_E_SUCCESS)
335 g_ril_print_response_no_args(rd->ril, message);
336
337 DBG("calling set_powered(TRUE)");
338
339 ofono_modem_set_powered(modem, TRUE);
340}
341
337static void ril_connected(struct ril_msg *message, gpointer user_data)342static void ril_connected(struct ril_msg *message, gpointer user_data)
338{343{
339 struct ofono_modem *modem = (struct ofono_modem *) user_data;344 struct ofono_modem *modem = (struct ofono_modem *) user_data;
340 struct ril_data *rd = ofono_modem_get_data(modem);345 struct ril_data *rd = ofono_modem_get_data(modem);
341346 int version;
342 ofono_info("[%d,UNSOL]< %s", g_ril_get_slot(rd->ril),347
343 g_ril_unsol_request_to_string(rd->ril, message->req));348 version = g_ril_unsol_parse_connected(rd->ril, message);
349 g_ril_set_version(rd->ril, version);
350
351 ofono_info("[%d,UNSOL]< %s, version %d", g_ril_get_slot(rd->ril),
352 g_ril_unsol_request_to_string(rd->ril, message->req), version);
344353
345 /* TODO: need a disconnect function to restart things! */354 /* TODO: need a disconnect function to restart things! */
346 rd->connected = TRUE;355 rd->connected = TRUE;
347356
348 DBG("calling set_powered(TRUE)");357 DBG("calling set_powered(FALSE) on connected");
349358
350 ofono_modem_set_powered(modem, TRUE);359 ril_send_power(rd, FALSE, ril_set_powered_off_cb, modem);
351}360}
352361
353static int create_gril(struct ofono_modem *modem)362static int create_gril(struct ofono_modem *modem)
354{363{
355 struct ril_data *rd = ofono_modem_get_data(modem);364 struct ril_data *rd = ofono_modem_get_data(modem);
356 int slot_id = ofono_modem_get_integer(modem, "Slot");365 int slot_id = ofono_modem_get_integer(modem, "Slot");
366 const gchar *socket = ofono_modem_get_string(modem, "Socket");
357367
358 ofono_info("Using %s as socket for slot %d.",368 ofono_info("Using %s as socket for slot %d.", socket, slot_id);
359 RILD_CMD_SOCKET[slot_id], slot_id);369 rd->ril = g_ril_new(socket, rd->vendor);
360 rd->ril = g_ril_new(RILD_CMD_SOCKET[slot_id], OFONO_RIL_VENDOR_AOSP);
361370
362 /* NOTE: Since AT modems open a tty, and then call371 /* NOTE: Since AT modems open a tty, and then call
363 * g_at_chat_new(), they're able to return -EIO if372 * g_at_chat_new(), they're able to return -EIO if
@@ -377,7 +386,7 @@
377 g_ril_set_trace(rd->ril, TRUE);386 g_ril_set_trace(rd->ril, TRUE);
378387
379 if (getenv("OFONO_RIL_HEX_TRACE"))388 if (getenv("OFONO_RIL_HEX_TRACE"))
380 g_ril_set_debugf(rd->ril, ril_debug, GRIL_HEX_PREFIX[slot_id]);389 g_ril_set_debugf(rd->ril, ril_debug, rd);
381390
382 g_ril_register(rd->ril, RIL_UNSOL_RIL_CONNECTED,391 g_ril_register(rd->ril, RIL_UNSOL_RIL_CONNECTED,
383 ril_connected, modem);392 ril_connected, modem);
384393
=== modified file 'plugins/rildev.c'
--- plugins/rildev.c 2015-11-10 09:13:46 +0000
+++ plugins/rildev.c 2016-03-14 09:03:03 +0000
@@ -43,6 +43,7 @@
43{43{
44 struct ofono_modem *modem;44 struct ofono_modem *modem;
45 char dev_name[64];45 char dev_name[64];
46 char *socket;
46 int retval;47 int retval;
4748
48 snprintf(dev_name, sizeof(dev_name), "ril_%d", slot);49 snprintf(dev_name, sizeof(dev_name), "ril_%d", slot);
@@ -58,6 +59,15 @@
5859
59 ofono_modem_set_integer(modem, "Slot", slot);60 ofono_modem_set_integer(modem, "Slot", slot);
6061
62 /* AOSP has socket path "rild", "rild2"..., while others may differ */
63 if (slot != 0)
64 socket = g_strdup_printf("/dev/socket/rild%d", slot + 1);
65 else
66 socket = g_strdup("/dev/socket/rild");
67
68 ofono_modem_set_string(modem, "Socket", socket);
69 g_free(socket);
70
61 /* This causes driver->probe() to be called... */71 /* This causes driver->probe() to be called... */
62 retval = ofono_modem_register(modem);72 retval = ofono_modem_register(modem);
63 if (retval != 0) {73 if (retval != 0) {
6474
=== modified file 'plugins/upower.c'
--- plugins/upower.c 2015-11-02 09:18:14 +0000
+++ plugins/upower.c 2016-03-14 09:03:03 +0000
@@ -40,11 +40,8 @@
40#define UPOWER_DEVICE_INTERFACE UPOWER_SERVICE ".Device"40#define UPOWER_DEVICE_INTERFACE UPOWER_SERVICE ".Device"
4141
42static guint modem_watch;42static guint modem_watch;
43static guint upower_battery_watch;
44static guint upower_daemon_watch;43static guint upower_daemon_watch;
45static DBusConnection *connection;44static DBusConnection *connection;
46static GHashTable *modem_hfp_watches;
47static GList *modems;
48static int last_battery_level;45static int last_battery_level;
49static char *battery_device_path;46static char *battery_device_path;
5047
@@ -56,9 +53,17 @@
56 ofono_emulator_set_indicator(atom, OFONO_EMULATOR_IND_BATTERY, val);53 ofono_emulator_set_indicator(atom, OFONO_EMULATOR_IND_BATTERY, val);
57}54}
5855
56static void update_modem_battery_indicator(struct ofono_modem *modem,
57 void *data)
58{
59 __ofono_modem_foreach_registered_atom(modem,
60 OFONO_ATOM_TYPE_EMULATOR_HFP,
61 emulator_battery_cb,
62 data);
63}
64
59static void update_battery_level(double percentage_val)65static void update_battery_level(double percentage_val)
60{66{
61 GList *list;
62 int battery_level;67 int battery_level;
6368
64 if (percentage_val <= 1.00) {69 if (percentage_val <= 1.00) {
@@ -69,27 +74,19 @@
69 ofono_error("%s: Invalid value for battery level: %f",74 ofono_error("%s: Invalid value for battery level: %f",
70 __func__,75 __func__,
71 percentage_val);76 percentage_val);
72 goto done;77 return;
73 }78 }
7479
75 DBG("last_battery_level: %d battery_level: %d (%f)", last_battery_level,80 DBG("last_battery_level: %d battery_level: %d (%f)", last_battery_level,
76 battery_level, percentage_val);81 battery_level, percentage_val);
7782
78 if (last_battery_level == battery_level)83 if (last_battery_level == battery_level)
79 goto done;84 return;
8085
81 last_battery_level = battery_level;86 last_battery_level = battery_level;
8287
83 for (list = modems; list; list = list->next) {88 __ofono_modem_foreach(update_modem_battery_indicator,
84 struct ofono_modem *modem = list->data;
85
86 __ofono_modem_foreach_registered_atom(modem,
87 OFONO_ATOM_TYPE_EMULATOR_HFP,
88 emulator_battery_cb,
89 GINT_TO_POINTER(battery_level));89 GINT_TO_POINTER(battery_level));
90 }
91done:
92 ;
93}90}
9491
95static gboolean battery_props_changed(DBusConnection *conn, DBusMessage *msg,92static gboolean battery_props_changed(DBusConnection *conn, DBusMessage *msg,
@@ -102,6 +99,8 @@
102 gboolean percentage_found = FALSE;99 gboolean percentage_found = FALSE;
103 gboolean retval = FALSE;100 gboolean retval = FALSE;
104101
102 DBG("");
103
105 dbus_message_iter_init(msg, &iter);104 dbus_message_iter_init(msg, &iter);
106105
107 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) {106 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) {
@@ -179,117 +178,19 @@
179 return retval;178 return retval;
180}179}
181180
182static void get_property_reply(DBusPendingCall *call, void *user_data)
183{
184 double percentage_val;
185 DBusMessageIter iter, val;
186 DBusMessage *reply;
187
188 DBG("");
189
190 reply = dbus_pending_call_steal_reply(call);
191 if (reply == NULL) {
192 ofono_error("%s: dbus_message_new_method failed", __func__);
193 goto done;
194 }
195
196 if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
197 ofono_error("%s: ERROR reply to Get('Percentage')", __func__);
198 goto done;
199 }
200
201 if (dbus_message_iter_init(reply, &iter) == FALSE) {
202 ofono_error("%s: error initializing array iter", __func__);
203 goto done;
204 }
205
206 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) {
207 ofono_error("%s: type != VARIANT!", __func__);
208 goto done;
209 }
210
211 dbus_message_iter_recurse(&iter, &val);
212
213 if (dbus_message_iter_get_arg_type(&val) != DBUS_TYPE_DOUBLE) {
214 ofono_error("%s: type != DOUBLE!", __func__);
215 goto done;
216 }
217
218 dbus_message_iter_get_basic(&val, &percentage_val);
219
220 update_battery_level(percentage_val);
221
222done:
223 if (reply)
224 dbus_message_unref(reply);
225
226 dbus_pending_call_unref(call);
227}
228
229static void emulator_hfp_watch(struct ofono_atom *atom,181static void emulator_hfp_watch(struct ofono_atom *atom,
230 enum ofono_atom_watch_condition cond,182 enum ofono_atom_watch_condition cond,
231 void *data)183 void *data)
232{184{
233 struct ofono_modem *modem = data;185 if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) {
234 DBusMessageIter iter;186 DBG("REGISTERED; calling set_indicator: %d", last_battery_level);
235 DBusPendingCall *call;187
236 DBusMessage *msg;188 ofono_emulator_set_indicator(atom, OFONO_EMULATOR_IND_BATTERY,
237 const char *iface = UPOWER_DEVICE_INTERFACE;189 last_battery_level);
238 const char *property = "Percentage";190 return;
239191 }
240 if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) {192
241 DBG("UNREGISTERED");193 DBG("UNREGISTERED");
242
243 modems = g_list_remove(modems, modem);
244 if (modems != NULL)
245 return;
246
247 if (upower_battery_watch) {
248 g_dbus_remove_watch(connection, upower_battery_watch);
249 upower_battery_watch = 0;
250 }
251
252 return;
253 }
254
255 DBG("REGISTERED");
256
257 /* TODO: handle removable batteries */
258
259 modems = g_list_append(modems, modem);
260
261 if (modems->next != NULL)
262 return;
263
264 upower_battery_watch = g_dbus_add_signal_watch(connection,
265 UPOWER_SERVICE,
266 battery_device_path,
267 DBUS_INTERFACE_PROPERTIES,
268 "PropertiesChanged",
269 battery_props_changed,
270 NULL, NULL);
271
272 /* Query current battery value */
273 msg = dbus_message_new_method_call(UPOWER_SERVICE, battery_device_path,
274 DBUS_PROPERTIES_INTERFACE,
275 "Get");
276 if (msg == NULL) {
277 ofono_error("%s: dbus_message_new_method failed", __func__);
278 return;
279 }
280
281 dbus_message_iter_init_append(msg, &iter);
282 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &iface);
283 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &property);
284
285 if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
286 ofono_error("%s: Sending EnumerateDevices failed", __func__);
287 goto done;
288 }
289
290 dbus_pending_call_set_notify(call, get_property_reply, NULL, NULL);
291done:
292 dbus_message_unref(msg);
293}194}
294195
295static void modemwatch(struct ofono_modem *modem, gboolean added, void *user)196static void modemwatch(struct ofono_modem *modem, gboolean added, void *user)
@@ -299,24 +200,10 @@
299200
300 DBG("modem: %s, added: %d", path, added);201 DBG("modem: %s, added: %d", path, added);
301202
302 if (added) {203 if (added)
303 guint watch_id;204 __ofono_modem_add_atom_watch(modem,
304
305 watch_id = __ofono_modem_add_atom_watch(modem,
306 OFONO_ATOM_TYPE_EMULATOR_HFP,205 OFONO_ATOM_TYPE_EMULATOR_HFP,
307 emulator_hfp_watch, modem, NULL);206 emulator_hfp_watch, NULL, NULL);
308
309 g_hash_table_insert(modem_hfp_watches, g_strdup(path),
310 GINT_TO_POINTER(watch_id));
311
312 } else {
313 guint *watch_id = g_hash_table_lookup(modem_hfp_watches, path);
314
315 if (watch_id != NULL) {
316 __ofono_modem_remove_atom_watch(modem, *watch_id);
317 g_hash_table_remove(modem_hfp_watches, path);
318 }
319 }
320}207}
321208
322static void call_modemwatch(struct ofono_modem *modem, void *user)209static void call_modemwatch(struct ofono_modem *modem, void *user)
@@ -383,13 +270,23 @@
383270
384 DBG("parse_devices_reply OK");271 DBG("parse_devices_reply OK");
385272
273 /* TODO: handle removable batteries */
274
386 if (battery_device_path == NULL) {275 if (battery_device_path == NULL) {
387 ofono_error("%s: no battery detected", __func__);276 ofono_error("%s: no battery detected", __func__);
388 goto done;277 goto done;
389 }278 }
390279
280 /* Always listen to PropertiesChanged for battery */
281 g_dbus_add_signal_watch(connection, UPOWER_SERVICE, battery_device_path,
282 DBUS_INTERFACE_PROPERTIES,
283 "PropertiesChanged",
284 battery_props_changed,
285 NULL, NULL);
286
391 modem_watch = __ofono_modemwatch_add(modemwatch, NULL, NULL);287 modem_watch = __ofono_modemwatch_add(modemwatch, NULL, NULL);
392 __ofono_modem_foreach(call_modemwatch, NULL);288 __ofono_modem_foreach(call_modemwatch, NULL);
289
393done:290done:
394 if (reply)291 if (reply)
395 dbus_message_unref(reply);292 dbus_message_unref(reply);
@@ -449,9 +346,6 @@
449 upower_disconnect,346 upower_disconnect,
450 NULL, NULL);347 NULL, NULL);
451348
452 modem_hfp_watches = g_hash_table_new_full(g_str_hash, g_str_equal,
453 g_free, NULL);
454
455 return 0;349 return 0;
456}350}
457351
@@ -465,8 +359,6 @@
465359
466 if (battery_device_path)360 if (battery_device_path)
467 g_free(battery_device_path);361 g_free(battery_device_path);
468
469 g_hash_table_destroy(modem_hfp_watches);
470}362}
471363
472OFONO_PLUGIN_DEFINE(upower, "upower battery monitor", VERSION,364OFONO_PLUGIN_DEFINE(upower, "upower battery monitor", VERSION,
473365
=== modified file 'src/emulator.c'
--- src/emulator.c 2015-11-27 16:53:45 +0000
+++ src/emulator.c 2016-03-14 09:03:03 +0000
@@ -37,6 +37,7 @@
37#include "gatserver.h"37#include "gatserver.h"
38#include "gatppp.h"38#include "gatppp.h"
39#include "handsfree-audio.h"39#include "handsfree-audio.h"
40#include "system-settings.h"
4041
41#define RING_TIMEOUT 342#define RING_TIMEOUT 3
4243
@@ -1448,14 +1449,35 @@
14481449
1449static struct ofono_atom *get_preferred_atom(struct ofono_emulator *em)1450static struct ofono_atom *get_preferred_atom(struct ofono_emulator *em)
1450{1451{
1452 char *path;
1453 GSList *l;
1454 struct ofono_atom *preferred = em->atoms->data;
1455
1456 path = __ofono_system_settings_get_string_value(PREFERRED_VOICE_MODEM);
1457 if (path == NULL)
1458 goto end;
1459
1460 for (l = em->atoms; l; l = l->next) {
1461 struct ofono_atom *atom = l->data;
1462
1463 if (g_strcmp0(__ofono_atom_get_path(atom), path) == 0) {
1464 preferred = atom;
1465 break;
1466 }
1467 }
1468
1469 g_free(path);
1470
1471end:
1472 return preferred;
1473}
1474
1475static struct ofono_atom *get_active_atom(struct ofono_emulator *em)
1476{
1451 if (em->active_atom)1477 if (em->active_atom)
1452 return em->active_atom;1478 return em->active_atom;
14531479
1454 /*1480 return get_preferred_atom(em);
1455 * TODO For the moment we just take the first on the list, we need to
1456 * ask the modem and have something configurable from settings.
1457 */
1458 return em->atoms->data;
1459}1481}
14601482
1461static struct atom_callback *find_atom_callback(GSList *prefix_cbs,1483static struct atom_callback *find_atom_callback(GSList *prefix_cbs,
@@ -1494,7 +1516,7 @@
1494 struct ofono_emulator_request req;1516 struct ofono_emulator_request req;
1495 struct ofono_atom *atom;1517 struct ofono_atom *atom;
14961518
1497 atom = get_preferred_atom(h->em);1519 atom = get_active_atom(h->em);
1498 prefix_cbs = g_hash_table_lookup(h->em->prefixes, h->prefix);1520 prefix_cbs = g_hash_table_lookup(h->em->prefixes, h->prefix);
1499 atom_cb = find_atom_callback(prefix_cbs, atom);1521 atom_cb = find_atom_callback(prefix_cbs, atom);
1500 if (atom_cb == NULL) {1522 if (atom_cb == NULL) {
@@ -1689,11 +1711,7 @@
1689 }1711 }
16901712
1691 /* Return FALSE if the modem is not the preferred one */1713 /* Return FALSE if the modem is not the preferred one */
1692 /*1714 preferred = get_preferred_atom(em);
1693 * TODO For the moment we just take the first on the list, we need to
1694 * ask the modem and have some configurable from settings.
1695 */
1696 preferred = em->atoms->data;
1697 if (preferred == atom)1715 if (preferred == atom)
1698 return TRUE;1716 return TRUE;
1699 else1717 else
17001718
=== added file 'src/system-settings.c'
--- src/system-settings.c 1970-01-01 00:00:00 +0000
+++ src/system-settings.c 2016-03-14 09:03:03 +0000
@@ -0,0 +1,74 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2016 Canonical Ltd.
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 <errno.h>
27#include <string.h>
28#include <glib.h>
29#include "ofono.h"
30#include "system-settings.h"
31
32static GSList *g_drivers = NULL;
33
34char *__ofono_system_settings_get_string_value(const char *name)
35{
36 GSList *d;
37 char *value = NULL;
38
39 for (d = g_drivers; d != NULL; d = d->next) {
40 const struct ofono_system_settings_driver *driver = d->data;
41
42 if (driver->get_string_value == NULL)
43 continue;
44
45 DBG("Calling system settings plugin '%s'", driver->name);
46
47 value = driver->get_string_value(name);
48 if (value == NULL)
49 continue;
50
51 DBG("property %s value %s", name, value);
52
53 return value;
54 }
55
56 return value;
57}
58
59int ofono_system_settings_driver_register(
60 struct ofono_system_settings_driver *driver)
61{
62 DBG("driver: %p name: %s", driver, driver->name);
63
64 g_drivers = g_slist_prepend(g_drivers, driver);
65 return 0;
66}
67
68void ofono_system_settings_driver_unregister(
69 const struct ofono_system_settings_driver *driver)
70{
71 DBG("driver: %p name: %s", driver, driver->name);
72
73 g_drivers = g_slist_remove(g_drivers, driver);
74}
075
=== modified file 'src/voicecall.c'
--- src/voicecall.c 2016-01-15 16:03:09 +0000
+++ src/voicecall.c 2016-03-14 09:03:03 +0000
@@ -3463,9 +3463,11 @@
3463 char number[OFONO_MAX_PHONE_NUMBER_LENGTH + 1];3463 char number[OFONO_MAX_PHONE_NUMBER_LENGTH + 1];
3464 struct ofono_error result;3464 struct ofono_error result;
34653465
3466 /* Make sure we keep the system awake if we get woken up3466 /*
3467 * shortly for processing the incoming request from the3467 * If the device supports wakelocks, acquire one to
3468 * HFP HF. */3468 * ensure the device is kept awake after being woken
3469 * by an incoming request from the HFP HF.
3470 */
3469 wakelock_system_lock();3471 wakelock_system_lock();
34703472
3471 switch (ofono_emulator_request_get_type(req)) {3473 switch (ofono_emulator_request_get_type(req)) {
34723474
=== added file 'src/wakelock.c'
--- src/wakelock.c 1970-01-01 00:00:00 +0000
+++ src/wakelock.c 2016-03-14 09:03:03 +0000
@@ -0,0 +1,152 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2015 Jolla Ltd. All rights reserved.
6 * Contact: Hannu Mallat <hannu.mallat@jollamobile.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <errno.h>
29#include <string.h>
30#include <glib.h>
31
32#include "log.h"
33#include "wakelock.h"
34#include "ofono.h"
35
36#define SYSTEM_WAKELOCK_NAME "ofono-system"
37#define SYSTEM_WAKELOCK_DURATION 30
38
39static char *impl = NULL;
40static struct wakelock_table table;
41
42static struct wakelock *system_wakelock = NULL;
43static guint system_wakelock_source = 0;
44
45static gboolean system_wakelock_put(gpointer user_data)
46{
47 DBG("Releasing system wakelock");
48 wakelock_release(system_wakelock);
49 system_wakelock_source = 0;
50 return FALSE;
51}
52
53void wakelock_system_lock(void)
54{
55 guint old_source;
56
57 if (impl == NULL)
58 return;
59
60 DBG("Acquiring system wakelock");
61
62 old_source = system_wakelock_source;
63
64 system_wakelock_source = g_timeout_add_seconds(SYSTEM_WAKELOCK_DURATION,
65 system_wakelock_put,
66 NULL);
67
68 if (system_wakelock_source)
69 wakelock_acquire(system_wakelock);
70
71 if (old_source) {
72 g_source_remove(old_source);
73 wakelock_release(system_wakelock);
74 }
75}
76
77int wakelock_create(const char *name, struct wakelock **wakelock)
78{
79 if (impl == NULL) {
80 *wakelock = NULL;
81 return -EINVAL;
82 }
83
84 return (table.create)(name, wakelock);
85}
86
87int wakelock_free(struct wakelock *wakelock)
88{
89 if (impl == NULL)
90 return -EINVAL;
91
92 return table.free(wakelock);
93}
94
95int wakelock_acquire(struct wakelock *wakelock)
96{
97 if (impl == NULL)
98 return -EINVAL;
99
100 return table.acquire(wakelock);
101}
102
103int wakelock_release(struct wakelock *wakelock)
104{
105 if (impl == NULL)
106 return -EINVAL;
107
108 return table.release(wakelock);
109}
110
111ofono_bool_t wakelock_is_locked(struct wakelock *wakelock) {
112 if (impl == NULL)
113 return -EINVAL;
114
115 return table.is_locked(wakelock);
116}
117
118int wakelock_plugin_register(const char *name, struct wakelock_table *fns)
119{
120 if (impl)
121 return -EALREADY;
122
123 impl = g_strdup(name);
124 memcpy(&table, fns, sizeof(struct wakelock_table));
125 return 0;
126}
127
128int wakelock_plugin_unregister(void)
129{
130 if (impl == NULL)
131 return -ENOENT;
132
133 memset(&table, 0, sizeof(struct wakelock_table));
134 g_free(impl);
135 impl = NULL;
136
137 return 0;
138}
139
140int __ofono_wakelock_init(void)
141{
142 if (wakelock_create(SYSTEM_WAKELOCK_NAME, &system_wakelock) < 0)
143 ofono_warn("Failed to create system keep alive wakelock");
144
145 return 0;
146}
147
148void __ofono_wakelock_cleanup(void)
149{
150 if (system_wakelock)
151 wakelock_free(system_wakelock);
152}
0153
=== removed file 'src/wakelock.c'
--- src/wakelock.c 2016-01-15 16:03:09 +0000
+++ src/wakelock.c 1970-01-01 00:00:00 +0000
@@ -1,151 +0,0 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2015 Jolla Ltd. All rights reserved.
6 * Contact: Hannu Mallat <hannu.mallat@jollamobile.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <errno.h>
29#include <string.h>
30#include <glib.h>
31
32#include "log.h"
33#include "wakelock.h"
34#include "ofono.h"
35
36#define SYSTEM_WAKELOCK_NAME "ofono-system"
37#define SYSTEM_WAKELOCK_DURATION 30
38
39static char *impl = NULL;
40static struct wakelock_table table;
41
42static struct wakelock *system_wakelock = NULL;
43static guint system_wakelock_source = 0;
44
45static gboolean system_wakelock_put(gpointer user_data)
46{
47 DBG("Releasing system wakelock");
48 wakelock_release(system_wakelock);
49 system_wakelock_source = 0;
50 return FALSE;
51}
52
53void wakelock_system_lock(void)
54{
55 guint old_source;
56
57 if (!impl)
58 return;
59
60 DBG("Acquiring system wakelock");
61
62 old_source = system_wakelock_source;
63
64 system_wakelock_source = g_timeout_add_seconds(SYSTEM_WAKELOCK_DURATION,
65 system_wakelock_put,
66 NULL);
67 if (system_wakelock_source)
68 wakelock_acquire(system_wakelock);
69
70 if (old_source) {
71 g_source_remove(old_source);
72 wakelock_release(system_wakelock);
73 }
74}
75
76int wakelock_create(const char *name, struct wakelock **wakelock)
77{
78 if (!impl) {
79 *wakelock = NULL;
80 return -EINVAL;
81 }
82
83 return (table.create)(name, wakelock);
84}
85
86int wakelock_free(struct wakelock *wakelock)
87{
88 if (!impl)
89 return -EINVAL;
90
91 return table.free(wakelock);
92}
93
94int wakelock_acquire(struct wakelock *wakelock)
95{
96 if (!impl)
97 return -EINVAL;
98
99 return table.acquire(wakelock);
100}
101
102int wakelock_release(struct wakelock *wakelock)
103{
104 if (!impl)
105 return -EINVAL;
106
107 return table.release(wakelock);
108}
109
110ofono_bool_t wakelock_is_locked(struct wakelock *wakelock) {
111 if (!impl)
112 return -EINVAL;
113
114 return table.is_locked(wakelock);
115}
116
117int wakelock_plugin_register(const char *name, struct wakelock_table *fns)
118{
119 if (impl)
120 return -EALREADY;
121
122 impl = g_strdup(name);
123 memcpy(&table, fns, sizeof(struct wakelock_table));
124 return 0;
125}
126
127int wakelock_plugin_unregister(void)
128{
129 if (!impl)
130 return -ENOENT;
131
132 memset(&table, 0, sizeof(struct wakelock_table));
133 g_free(impl);
134 impl = NULL;
135
136 return 0;
137}
138
139int __ofono_wakelock_init(void)
140{
141 if (wakelock_create(SYSTEM_WAKELOCK_NAME, &system_wakelock) < 0)
142 ofono_warn("Failed to create system keep alive wakelock");
143
144 return 0;
145}
146
147void __ofono_wakelock_cleanup(void)
148{
149 if (system_wakelock)
150 wakelock_free(system_wakelock);
151}
1520
=== added file 'unit/rilmodem-test-server.c'
--- unit/rilmodem-test-server.c 1970-01-01 00:00:00 +0000
+++ unit/rilmodem-test-server.c 2016-03-14 09:03:03 +0000
@@ -0,0 +1,237 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2015 Canonical Ltd.
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#define _GNU_SOURCE
27#include <stdio.h>
28#include <netinet/in.h>
29#include <sys/socket.h>
30#include <sys/un.h>
31#include <unistd.h>
32
33#include <ofono/types.h>
34
35#include <gril.h>
36
37#include "rilmodem-test-server.h"
38
39#define MAX_REQUEST_SIZE 4096
40#define RIL_SERVER_SOCK_PATH "/tmp/unittestril"
41
42struct server_data {
43 int server_sk;
44 ConnectFunc connect_func;
45 GIOChannel *server_io;
46 char *sock_name;
47 const struct rilmodem_test_data *rtd;
48 void *user_data;
49};
50
51/* Warning: length is stored in network order */
52struct rsp_hdr {
53 uint32_t length;
54 uint32_t unsolicited;
55 uint32_t serial;
56 uint32_t error;
57};
58
59static gboolean read_server(gpointer data)
60{
61 struct server_data *sd = data;
62 GIOStatus status;
63 gsize offset, rbytes, wbytes;
64 gchar *buf, *bufp;
65 uint32_t req_serial;
66 struct rsp_hdr rsp;
67
68 buf = g_malloc0(MAX_REQUEST_SIZE);
69
70 status = g_io_channel_read_chars(sd->server_io, buf, MAX_REQUEST_SIZE,
71 &rbytes, NULL);
72 g_assert(status == G_IO_STATUS_NORMAL);
73 g_assert(rbytes == sd->rtd->req_size);
74
75 /* validate len, and request_id */
76 g_assert(!memcmp(buf, sd->rtd->req_data, (sizeof(uint32_t) * 2)));
77
78 /*
79 * header: size (uint32), reqid (uin32), serial (uint32)
80 * header size == 16 ( excludes sizeof(size) )
81 */
82
83 /* advance past request_no */
84 bufp = buf + (sizeof(uint32_t) * 2);
85
86 req_serial = (uint32_t) *bufp;
87
88 /* advance past serial_no */
89 bufp += sizeof(uint32_t);
90
91 /* validate the rest of the parcel... */
92 offset = (sizeof(uint32_t) * 3);
93 g_assert(!memcmp(bufp, sd->rtd->req_data + offset,
94 sd->rtd->req_size - offset));
95
96 /* Length does not include the length field. Network order. */
97 rsp.length = htonl(sizeof(rsp) - sizeof(rsp.length) +
98 sd->rtd->rsp_size);
99 rsp.unsolicited = 0;
100 rsp.serial = req_serial;
101 rsp.error = sd->rtd->rsp_error;
102
103 /* copy header */
104 memcpy(buf, &rsp, sizeof(rsp));
105
106 if (sd->rtd->rsp_size) {
107 bufp = buf + sizeof(rsp);
108
109 memcpy(bufp, sd->rtd->rsp_data, sd->rtd->rsp_size);
110 }
111
112 status = g_io_channel_write_chars(sd->server_io,
113 buf,
114 sizeof(rsp) + sd->rtd->rsp_size,
115 &wbytes, NULL);
116
117 /* FIXME: assert wbytes is correct */
118
119 g_assert(status == G_IO_STATUS_NORMAL);
120
121 g_free(buf);
122 g_io_channel_unref(sd->server_io);
123
124 return FALSE;
125}
126
127static gboolean on_socket_connected(GIOChannel *chan, GIOCondition cond,
128 gpointer data)
129{
130 struct server_data *sd = data;
131 struct sockaddr saddr;
132 unsigned int len = sizeof(saddr);
133 int fd;
134 GIOStatus status;
135
136 g_assert(cond == G_IO_IN);
137
138 fd = accept(sd->server_sk, &saddr, &len);
139 g_assert(fd != -1);
140
141 sd->server_io = g_io_channel_unix_new(fd);
142 g_assert(sd->server_io != NULL);
143
144 status = g_io_channel_set_encoding(sd->server_io, NULL, NULL);
145 g_assert(status == G_IO_STATUS_NORMAL);
146
147 g_io_channel_set_buffered(sd->server_io, FALSE);
148 g_io_channel_set_close_on_unref(sd->server_io, TRUE);
149
150 if (sd->connect_func)
151 sd->connect_func(sd->user_data);
152
153 if (sd->rtd->unsol_test == FALSE)
154 g_idle_add(read_server, sd);
155
156 return FALSE;
157}
158
159void rilmodem_test_server_close(struct server_data *sd)
160{
161 g_assert(sd->server_sk);
162 close(sd->server_sk);
163 remove(sd->sock_name);
164 g_free(sd->sock_name);
165 g_free(sd);
166}
167
168struct server_data *rilmodem_test_server_create(ConnectFunc connect,
169 const struct rilmodem_test_data *test_data,
170 void *data)
171{
172 GIOChannel *io;
173 struct sockaddr_un addr;
174 int retval;
175 struct server_data *sd;
176
177 sd = g_new0(struct server_data, 1);
178
179 sd->connect_func = connect;
180 sd->user_data = data;
181 sd->rtd = test_data;
182
183 sd->server_sk = socket(AF_UNIX, SOCK_STREAM, 0);
184 g_assert(sd->server_sk);
185
186 sd->sock_name =
187 g_strdup_printf(RIL_SERVER_SOCK_PATH"%u", (unsigned) getpid());
188
189 memset(&addr, 0, sizeof(addr));
190 addr.sun_family = AF_UNIX;
191 strncpy(addr.sun_path, sd->sock_name, sizeof(addr.sun_path) - 1);
192
193 /* Unlink any existing socket for this session */
194 unlink(addr.sun_path);
195
196 retval = bind(sd->server_sk, (struct sockaddr *) &addr, sizeof(addr));
197 g_assert(retval >= 0);
198
199 retval = listen(sd->server_sk, 0);
200 g_assert(retval >= 0);
201
202 io = g_io_channel_unix_new(sd->server_sk);
203 g_assert(io != NULL);
204
205 g_io_channel_set_close_on_unref(io, TRUE);
206 g_io_add_watch_full(io, G_PRIORITY_DEFAULT,
207 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
208 on_socket_connected, sd, NULL);
209
210 g_io_channel_unref(io);
211
212 return sd;
213}
214
215void rilmodem_test_server_write(struct server_data *sd,
216 const unsigned char *buf,
217 const size_t buf_len)
218{
219 GIOStatus status;
220 gsize wbytes;
221
222 status = g_io_channel_write_chars(sd->server_io,
223 (const char *) buf,
224 buf_len,
225 &wbytes, NULL);
226
227 g_assert(status == G_IO_STATUS_NORMAL);
228
229 status = g_io_channel_flush(sd->server_io, NULL);
230
231 g_assert(status == G_IO_STATUS_NORMAL);
232}
233
234const char *rilmodem_test_get_socket_name(struct server_data *sd)
235{
236 return sd->sock_name;
237}
0238
=== added file 'unit/rilmodem-test-server.h'
--- unit/rilmodem-test-server.h 1970-01-01 00:00:00 +0000
+++ unit/rilmodem-test-server.h 2016-03-14 09:03:03 +0000
@@ -0,0 +1,47 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2015 Canonical Ltd.
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
22struct server_data;
23
24struct rilmodem_test_data {
25 const unsigned char *req_data;
26
27 const size_t req_size;
28
29 uint32_t rsp_error;
30 const unsigned char *rsp_data;
31 const size_t rsp_size;
32 gboolean unsol_test;
33};
34
35typedef void (*ConnectFunc)(void *data);
36
37void rilmodem_test_server_close(struct server_data *sd);
38
39struct server_data *rilmodem_test_server_create(ConnectFunc connect,
40 const struct rilmodem_test_data *test_data,
41 void *data);
42
43void rilmodem_test_server_write(struct server_data *sd,
44 const unsigned char *buf,
45 const size_t buf_len);
46
47const char *rilmodem_test_get_socket_name(struct server_data *sd);
048
=== modified file 'unit/test-grilreply.c'
--- unit/test-grilreply.c 2015-10-07 07:14:11 +0000
+++ unit/test-grilreply.c 2016-03-14 09:03:03 +0000
@@ -1420,7 +1420,7 @@
1420 * RIL_REQUEST_SET_FACILITY_LOCK reply with no parameters.1420 * RIL_REQUEST_SET_FACILITY_LOCK reply with no parameters.
1421 */1421 */
1422static const struct set_facility_lock_test reply_set_facility_lock_valid_1 = {1422static const struct set_facility_lock_test reply_set_facility_lock_valid_1 = {
1423 .retries = -1,1423 .retries = 0,
1424 .msg = {1424 .msg = {
1425 .buf = NULL,1425 .buf = NULL,
1426 .buf_len = 0,1426 .buf_len = 0,
@@ -1686,7 +1686,7 @@
16861686
1687 reason = g_ril_reply_parse_call_fail_cause(NULL, data);1687 reason = g_ril_reply_parse_call_fail_cause(NULL, data);
16881688
1689 g_assert(reason >= 0);1689 g_assert(reason == OFONO_DISCONNECT_REASON_REMOTE_HANGUP);
1690}1690}
16911691
1692static void test_reply_get_mute_off(gconstpointer data)1692static void test_reply_get_mute_off(gconstpointer data)
16931693
=== modified file 'unit/test-grilunsol.c'
--- unit/test-grilunsol.c 2014-08-19 16:29:51 +0000
+++ unit/test-grilunsol.c 2016-03-14 09:03:03 +0000
@@ -525,6 +525,115 @@
525 .error = 0,525 .error = 0,
526};526};
527527
528/*
529 * The following hexadecimal data represents a serialized Binder parcel
530 * instance containing a valid RIL_UNSOL_RIL_CONNECTED message with the
531 * following parameters:
532 *
533 * [1, 10]
534 */
535static const guchar unsol_on_ril_connected_valid_parcel1[] = {
536 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00
537};
538
539static const struct ril_msg unsol_on_ril_connected_valid_1 = {
540 .buf = (gchar *) &unsol_on_ril_connected_valid_parcel1,
541 .buf_len = sizeof(unsol_on_ril_connected_valid_parcel1),
542 .unsolicited = TRUE,
543 .req = RIL_UNSOL_RIL_CONNECTED,
544 .serial_no = 0,
545 .error = 0,
546};
547
548/*
549 * The following hexadecimal data represents a serialized Binder parcel
550 * instance containing a valid RIL_UNSOL_RIL_CONNECTED message with the
551 * following parameters:
552 *
553 * [2, 10, 11]
554 */
555static const guchar unsol_on_ril_connected_valid_parcel2[] = {
556 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00
557};
558
559static const struct ril_msg unsol_on_ril_connected_valid_2 = {
560 .buf = (gchar *) &unsol_on_ril_connected_valid_parcel2,
561 .buf_len = sizeof(unsol_on_ril_connected_valid_parcel2),
562 .unsolicited = TRUE,
563 .req = RIL_UNSOL_RIL_CONNECTED,
564 .serial_no = 0,
565 .error = 0,
566};
567
568/*
569 * The following hexadecimal data represents a serialized Binder parcel
570 * instance containing a valid RIL_UNSOL_RIL_CONNECTED message with the
571 * following parameters:
572 *
573 * [1, 10, 11]
574 */
575static const guchar unsol_on_ril_connected_valid_parcel3[] = {
576 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00
577};
578
579static const struct ril_msg unsol_on_ril_connected_valid_3 = {
580 .buf = (gchar *) &unsol_on_ril_connected_valid_parcel3,
581 .buf_len = sizeof(unsol_on_ril_connected_valid_parcel3),
582 .unsolicited = TRUE,
583 .req = RIL_UNSOL_RIL_CONNECTED,
584 .serial_no = 0,
585 .error = 0,
586};
587
588static const struct ril_msg unsol_on_ril_connected_invalid_1 = {
589 .buf = "",
590 .buf_len = 0,
591 .unsolicited = TRUE,
592 .req = RIL_UNSOL_RIL_CONNECTED,
593 .serial_no = 0,
594 .error = 0,
595};
596
597/*
598 * The following hexadecimal data represents a serialized Binder parcel
599 * instance containing an invalid RIL_UNSOL_RIL_CONNECTED message with the
600 * following parameters:
601 *
602 * [0]
603 */
604static const guchar unsol_on_ril_connected_invalid_parcel2[] = {
605 0x00, 0x00, 0x00, 0x00
606};
607
608static const struct ril_msg unsol_on_ril_connected_invalid_2 = {
609 .buf = (gchar *) &unsol_on_ril_connected_invalid_parcel2,
610 .buf_len = sizeof(unsol_on_ril_connected_invalid_parcel2),
611 .unsolicited = TRUE,
612 .req = RIL_UNSOL_RIL_CONNECTED,
613 .serial_no = 0,
614 .error = 0,
615};
616
617/*
618 * The following hexadecimal data represents a serialized Binder parcel
619 * instance containing an invalid RIL_UNSOL_RIL_CONNECTED message with the
620 * following parameters:
621 *
622 * [1]
623 */
624static const guchar unsol_on_ril_connected_invalid_parcel3[] = {
625 0x01, 0x00, 0x00, 0x00
626};
627
628static const struct ril_msg unsol_on_ril_connected_invalid_3 = {
629 .buf = (gchar *) &unsol_on_ril_connected_invalid_parcel3,
630 .buf_len = sizeof(unsol_on_ril_connected_invalid_parcel3),
631 .unsolicited = TRUE,
632 .req = RIL_UNSOL_RIL_CONNECTED,
633 .serial_no = 0,
634 .error = 0,
635};
636
528static void test_reply_data_call_invalid(gconstpointer data)637static void test_reply_data_call_invalid(gconstpointer data)
529{638{
530 struct ril_data_call_list *call_list;639 struct ril_data_call_list *call_list;
@@ -599,6 +708,24 @@
599 g_assert(unsol != NULL);708 g_assert(unsol != NULL);
600 g_ril_unsol_free_ussd(unsol);709 g_ril_unsol_free_ussd(unsol);
601}710}
711
712static void test_unsol_on_ril_connected_valid(gconstpointer data)
713{
714 int version;
715
716 version = g_ril_unsol_parse_connected(NULL, (struct ril_msg *) data);
717
718 g_assert(version == 10);
719}
720
721static void test_unsol_on_ril_connected_invalid(gconstpointer data)
722{
723 int version;
724
725 version = g_ril_unsol_parse_connected(NULL, (struct ril_msg *) data);
726
727 g_assert(version == RIL_VERSION_UNSPECIFIED);
728}
602#endif729#endif
603730
604int main(int argc, char **argv)731int main(int argc, char **argv)
@@ -693,6 +820,36 @@
693 &unsol_on_ussd_valid_1,820 &unsol_on_ussd_valid_1,
694 test_unsol_on_ussd_valid);821 test_unsol_on_ussd_valid);
695822
823 g_test_add_data_func("/testgrilunsol/ril-connected: "
824 "valid RIL_CONNECTED Test 1",
825 &unsol_on_ril_connected_valid_1,
826 test_unsol_on_ril_connected_valid);
827
828 g_test_add_data_func("/testgrilunsol/ril-connected: "
829 "valid RIL_CONNECTED Test 2",
830 &unsol_on_ril_connected_valid_2,
831 test_unsol_on_ril_connected_valid);
832
833 g_test_add_data_func("/testgrilunsol/ril-connected: "
834 "valid RIL_CONNECTED Test 3",
835 &unsol_on_ril_connected_valid_3,
836 test_unsol_on_ril_connected_valid);
837
838 g_test_add_data_func("/testgrilunsol/ril-connected: "
839 "invalid RIL_CONNECTED Test 1",
840 &unsol_on_ril_connected_invalid_1,
841 test_unsol_on_ril_connected_invalid);
842
843 g_test_add_data_func("/testgrilunsol/ril-connected: "
844 "invalid RIL_CONNECTED Test 2",
845 &unsol_on_ril_connected_invalid_2,
846 test_unsol_on_ril_connected_invalid);
847
848 g_test_add_data_func("/testgrilunsol/ril-connected: "
849 "invalid RIL_CONNECTED Test 3",
850 &unsol_on_ril_connected_invalid_3,
851 test_unsol_on_ril_connected_invalid);
852
696#endif853#endif
697 return g_test_run();854 return g_test_run();
698}855}
699856
=== added file 'unit/test-rilmodem-cb.c'
--- unit/test-rilmodem-cb.c 1970-01-01 00:00:00 +0000
+++ unit/test-rilmodem-cb.c 2016-03-14 09:03:03 +0000
@@ -0,0 +1,605 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2015 Canonical Ltd.
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#define _GNU_SOURCE
27#include <assert.h>
28#include <errno.h>
29#include <glib.h>
30#include <stdio.h>
31#include <netinet/in.h>
32#include <sys/socket.h>
33#include <sys/un.h>
34#include <unistd.h>
35
36#include <ofono/modem.h>
37#include <ofono/types.h>
38#include <ofono/call-barring.h>
39#include <gril.h>
40
41#include "common.h"
42#include "ril_constants.h"
43#include "rilmodem-test-server.h"
44
45static GMainLoop *mainloop;
46
47static const struct ofono_call_barring_driver *cbdriver;
48
49struct rilmodem_cb_data {
50 GRil *ril;
51 struct ofono_modem *modem;
52 gconstpointer test_data;
53 struct ofono_call_barring *cb;
54 struct server_data *serverd;
55};
56
57typedef gboolean (*StartFunc)(gpointer data);
58
59struct cb_data {
60 StartFunc start_func;
61
62 const char *lock;
63 int enable;
64 const char *passwd;
65 const char *new_passwd;
66 int cls;
67
68 struct rilmodem_test_data rtd;
69 enum ofono_error_type error_type;
70
71 int status;
72};
73
74static void query_callback(const struct ofono_error *error, int status,
75 gpointer data)
76{
77 struct rilmodem_cb_data *rsd = data;
78 const struct cb_data *cbd = rsd->test_data;
79
80 g_assert(error->type == cbd->error_type);
81
82 if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
83 g_assert(status == cbd->status);
84
85 g_main_loop_quit(mainloop);
86}
87
88static gboolean trigger_query(gpointer data)
89{
90 struct rilmodem_cb_data *rsd = data;
91 const struct cb_data *cbd = rsd->test_data;
92
93 g_assert(cbdriver->query != NULL);
94 cbdriver->query(rsd->cb, cbd->lock, cbd->cls, query_callback, rsd);
95
96 return FALSE;
97}
98
99static void set_callback(const struct ofono_error *error, gpointer data)
100{
101 struct rilmodem_cb_data *rsd = data;
102 const struct cb_data *cbd = rsd->test_data;
103
104 g_assert(error->type == cbd->error_type);
105
106 g_main_loop_quit(mainloop);
107}
108
109static gboolean trigger_set(gpointer data)
110{
111 struct rilmodem_cb_data *rsd = data;
112 const struct cb_data *cbd = rsd->test_data;
113
114 g_assert(cbdriver->set != NULL);
115 cbdriver->set(rsd->cb, cbd->lock, cbd->enable, cbd->passwd, cbd->cls,
116 set_callback, rsd);
117
118 return FALSE;
119}
120
121static void set_passwd_callback(const struct ofono_error *error, gpointer data)
122{
123 struct rilmodem_cb_data *rsd = data;
124 const struct cb_data *cbd = rsd->test_data;
125
126 g_assert(error->type == cbd->error_type);
127
128 g_main_loop_quit(mainloop);
129}
130
131static gboolean trigger_set_passwd(gpointer data)
132{
133 struct rilmodem_cb_data *rsd = data;
134 const struct cb_data *cbd = rsd->test_data;
135
136 g_assert(cbdriver->set_passwd != NULL);
137 cbdriver->set_passwd(rsd->cb, cbd->lock, cbd->passwd, cbd->new_passwd,
138 set_passwd_callback, rsd);
139
140 return FALSE;
141}
142
143/* RIL_REQUEST_GET_FACILITY_LOCK witht the following parameters:
144 *
145 * facility="OI" (outgoing international calls)
146 * service class=1 ( VOICE )
147 */
148static const guchar req_get_facility_lock_parcel_1[] = {
149 0x00, 0x00, 0x00, 0x2c, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x49, 0x00,
151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
152 0x01, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
153};
154
155/*
156 * The following structure contains test data for a valid
157 * RIL_REQUEST_GET_FACILITY_LOCK reply with parameter {1}
158 * which indicates that call-barring is activated for the
159 * previously specified facility for the VOICE class.
160 */
161static const guchar reply_get_facility_lock_data_valid_1[] = {
162 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00
163};
164
165static const struct cb_data testdata_query_valid_1 = {
166 .start_func = trigger_query,
167 .lock = "OI",
168 .cls = BEARER_CLASS_VOICE,
169 .rtd = {
170 .req_data = req_get_facility_lock_parcel_1,
171 .req_size = sizeof(req_get_facility_lock_parcel_1),
172 .rsp_data = reply_get_facility_lock_data_valid_1,
173 .rsp_size = sizeof(reply_get_facility_lock_data_valid_1),
174 },
175 .status = BEARER_CLASS_VOICE,
176};
177
178/* GENERIC_FAILURE returned in RIL reply */
179static const struct cb_data testdata_query_invalid_1 = {
180 .start_func = trigger_query,
181 .lock = "OI",
182 .cls = BEARER_CLASS_VOICE,
183 .rtd = {
184 .req_data = req_get_facility_lock_parcel_1,
185 .req_size = sizeof(req_get_facility_lock_parcel_1),
186 .rsp_data = reply_get_facility_lock_data_valid_1,
187 .rsp_size = sizeof(reply_get_facility_lock_data_valid_1),
188 .rsp_error = RIL_E_GENERIC_FAILURE,
189 },
190 .error_type = OFONO_ERROR_TYPE_FAILURE,
191};
192
193/*
194 * The following structure contains test data for a valid
195 * RIL_REQUEST_GET_FACILITY_LOCK reply with invalid number
196 * of parameters {0} specified.
197 */
198static const guchar reply_get_facility_lock_data_invalid_2[] = {
199 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00
200};
201
202static const struct cb_data testdata_query_invalid_2 = {
203 .start_func = trigger_query,
204 .lock = "OI",
205 .cls = BEARER_CLASS_VOICE,
206 .rtd = {
207 .req_data = req_get_facility_lock_parcel_1,
208 .req_size = sizeof(req_get_facility_lock_parcel_1),
209 .rsp_data = reply_get_facility_lock_data_invalid_2,
210 .rsp_size = sizeof(reply_get_facility_lock_data_invalid_2),
211 },
212 .error_type = OFONO_ERROR_TYPE_FAILURE,
213};
214
215/*
216 * The following structure contains test data for an invalid
217 * RIL_REQUEST_GET_FACILITY_LOCK reply with an invalid class
218 * mask (-255).
219 */
220static const guchar reply_get_facility_lock_data_invalid_3[] = {
221 0x01, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff
222};
223
224static const struct cb_data testdata_query_invalid_3 = {
225 .start_func = trigger_query,
226 .lock = "OI",
227 .cls = BEARER_CLASS_VOICE,
228 .rtd = {
229 .req_data = req_get_facility_lock_parcel_1,
230 .req_size = sizeof(req_get_facility_lock_parcel_1),
231 .rsp_data = reply_get_facility_lock_data_invalid_3,
232 .rsp_size = sizeof(reply_get_facility_lock_data_invalid_3),
233 },
234 .error_type = OFONO_ERROR_TYPE_FAILURE,
235};
236
237/*
238 * The following structure contains test data for a
239 * RIL_REQUEST_GET_FACILITY_LOCK reply with an incomplete
240 * integer parameter, which will trigger a malformed parcel
241 * error.
242 */
243static const guchar reply_get_facility_lock_data_invalid_4[] = {
244 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00
245};
246
247static const struct cb_data testdata_query_invalid_4 = {
248 .start_func = trigger_query,
249 .lock = "OI",
250 .cls = BEARER_CLASS_VOICE,
251 .rtd = {
252 .req_data = req_get_facility_lock_parcel_1,
253 .req_size = sizeof(req_get_facility_lock_parcel_1),
254 .rsp_data = reply_get_facility_lock_data_invalid_4,
255 .rsp_size = sizeof(reply_get_facility_lock_data_invalid_4),
256 },
257 .error_type = OFONO_ERROR_TYPE_FAILURE,
258};
259
260/* RIL_REQUEST_SET_FACILITY_LOCK witht the following parameters:
261 *
262 * facility="OI" (outgoing international calls)
263 * unlock (0)
264 * passwd="0000"
265 * service class=1 ( VOICE )
266 */
267static const guchar req_set_facility_lock_parcel_1[] = {
268 0x00, 0x00, 0x00, 0x3c, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
269 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x49, 0x00,
270 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
271 0x04, 0x00, 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00,
272 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00,
273 0xff, 0xff, 0xff, 0xff
274};
275
276/*
277 * This test doesn't specify any data for RIL_REQUEST_SET_FACILITY_LOCK reply
278 * to simulate a reply generated by mako.
279 */
280static const struct cb_data testdata_set_valid_1 = {
281 .start_func = trigger_set,
282 .lock = "OI",
283 .passwd = "0000",
284 .cls = BEARER_CLASS_VOICE,
285 .rtd = {
286 .req_data = req_set_facility_lock_parcel_1,
287 .req_size = sizeof(req_set_facility_lock_parcel_1),
288 },
289};
290
291/* RIL_REQUEST_SET_FACILITY_LOCK witht the following parameters:
292 *
293 * facility="OI" (outgoing international calls)
294 * unlock (1)
295 * passwd="0000"
296 * service class=0 ( NONE )
297 */
298static const guchar req_set_facility_lock_parcel_2[] = {
299 0x00, 0x00, 0x00, 0x3c, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
300 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x49, 0x00,
301 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00,
302 0x04, 0x00, 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00,
303 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
304 0xff, 0xff, 0xff, 0xff
305};
306
307/*
308 * The following structure contains test data for a valid
309 * RIL_REQUEST_SET_FACILITY_LOCK reply with parameter {1}
310 */
311static const guchar reply_set_facility_lock_data_valid_2[] = {
312 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00
313};
314
315static const struct cb_data testdata_set_valid_2 = {
316 .start_func = trigger_set,
317 .lock = "OI",
318 .enable = 1,
319 .passwd = "0000",
320 .cls = BEARER_CLASS_DEFAULT, /* updated to NONE in outgoing parcel */
321 .rtd = {
322 .req_data = req_set_facility_lock_parcel_2,
323 .req_size = sizeof(req_set_facility_lock_parcel_2),
324 .rsp_data = reply_set_facility_lock_data_valid_2,
325 .rsp_size = sizeof(reply_set_facility_lock_data_valid_2),
326 },
327};
328
329/* GENERIC_FAILURE returned in RIL reply */
330static const struct cb_data testdata_set_invalid_1 = {
331 .start_func = trigger_set,
332 .lock = "OI",
333 .enable = 1,
334 .passwd = "0000",
335 .cls = BEARER_CLASS_DEFAULT,
336 .rtd = {
337 .req_data = req_set_facility_lock_parcel_2,
338 .req_size = sizeof(req_set_facility_lock_parcel_2),
339 .rsp_error = RIL_E_GENERIC_FAILURE,
340 },
341 .error_type = OFONO_ERROR_TYPE_FAILURE,
342};
343
344
345/*
346 * The following structure contains test data for a
347 * RIL_REQUEST_SET_FACILITY_LOCK reply with an invalid
348 * number of parameters {2}
349 */
350static const guchar reply_set_facility_lock_data_invalid_2[] = {
351 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00
352};
353
354static const struct cb_data testdata_set_invalid_2 = {
355 .start_func = trigger_set,
356 .lock = "OI",
357 .enable = 1,
358 .passwd = "0000",
359 .cls = BEARER_CLASS_DEFAULT,
360 .rtd = {
361 .req_data = req_set_facility_lock_parcel_2,
362 .req_size = sizeof(req_set_facility_lock_parcel_2),
363 .rsp_data = reply_set_facility_lock_data_invalid_2,
364 .rsp_size = sizeof(reply_set_facility_lock_data_invalid_2),
365 },
366 .error_type = OFONO_ERROR_TYPE_FAILURE,
367};
368
369/*
370 * The following structure contains test data for a
371 * RIL_REQUEST_SET_FACILITY_LOCK reply with an incomplete
372 * integer parameter, which will trigger a malformed parcel
373 * error.
374 */
375static const guchar reply_set_facility_lock_data_invalid_3[] = {
376 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00
377};
378
379static const struct cb_data testdata_set_invalid_3 = {
380 .start_func = trigger_set,
381 .lock = "OI",
382 .enable = 1,
383 .passwd = "0000",
384 .cls = BEARER_CLASS_DEFAULT,
385 .rtd = {
386 .req_data = req_set_facility_lock_parcel_2,
387 .req_size = sizeof(req_set_facility_lock_parcel_2),
388 .rsp_data = reply_set_facility_lock_data_invalid_3,
389 .rsp_size = sizeof(reply_set_facility_lock_data_invalid_3),
390 },
391 .error_type = OFONO_ERROR_TYPE_FAILURE,
392};
393
394/* RIL_REQUEST_CHANGE_BARRING_PASSWORD with the following parameters:
395 *
396 * facility="OI" (outgoing international calls)
397 * old passwd="1111"
398 * new_passwd="0000"
399 */
400static const guchar req_change_barring_passwd_parcel_1[] = {
401 0x00, 0x00, 0x00, 0x38, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
402 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x49, 0x00,
403 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x31, 0x00, 0x31, 0x00,
404 0x31, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
405 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00
406};
407
408/*
409 * This test doesn't specify any data for RIL_REQUEST_SET_FACILITY_LOCK reply
410 * to simulate a reply generated by mako.
411 */
412static const struct cb_data testdata_set_passwd_valid_1 = {
413 .start_func = trigger_set_passwd,
414 .lock = "OI",
415 .passwd = "1111",
416 .new_passwd = "0000",
417 .rtd = {
418 .req_data = req_change_barring_passwd_parcel_1,
419 .req_size = sizeof(req_change_barring_passwd_parcel_1),
420 },
421};
422
423/* GENERIC_FAILURE returned in RIL reply */
424static const struct cb_data testdata_set_passwd_invalid_1 = {
425 .start_func = trigger_set_passwd,
426 .lock = "OI",
427 .passwd = "1111",
428 .new_passwd = "0000",
429 .rtd = {
430 .req_data = req_change_barring_passwd_parcel_1,
431 .req_size = sizeof(req_change_barring_passwd_parcel_1),
432 .rsp_error = RIL_E_GENERIC_FAILURE,
433 },
434 .error_type = OFONO_ERROR_TYPE_FAILURE,
435};
436
437/* Declarations && Re-implementations of core functions. */
438void ril_call_barring_exit(void);
439void ril_call_barring_init(void);
440
441struct ofono_call_barring {
442 void *driver_data;
443 const struct cb_data *cbd;
444};
445
446struct ofono_call_barring *ofono_call_barring_create(struct ofono_modem *modem,
447 unsigned int vendor,
448 const char *driver,
449 void *data)
450{
451 struct rilmodem_cb_data *rsd = data;
452 struct ofono_call_barring *cb = g_new0(struct ofono_call_barring, 1);
453 int retval;
454
455 retval = cbdriver->probe(cb, OFONO_RIL_VENDOR_AOSP, rsd->ril);
456 g_assert(retval == 0);
457
458 return cb;
459}
460
461int ofono_call_barring_driver_register(const struct ofono_call_barring_driver *d)
462{
463 if (cbdriver == NULL)
464 cbdriver = d;
465
466 return 0;
467}
468
469void ofono_call_barring_set_data(struct ofono_call_barring *cb, void *data)
470{
471 cb->driver_data = data;
472}
473
474void *ofono_call_barring_get_data(struct ofono_call_barring *cb)
475{
476 return cb->driver_data;
477}
478
479void ofono_call_barring_register(struct ofono_call_barring *cb)
480{
481}
482
483void ofono_call_barring_driver_unregister(const struct ofono_call_barring_driver *d)
484{
485}
486
487/*
488 * As all our architectures are little-endian except for
489 * PowerPC, and the Binder wire-format differs slightly
490 * depending on endian-ness, the following guards against test
491 * failures when run on PowerPC.
492 */
493#if BYTE_ORDER == LITTLE_ENDIAN
494
495static void server_connect_cb(gpointer data)
496{
497 struct rilmodem_cb_data *rsd = data;
498 const struct cb_data *cbd = rsd->test_data;
499
500 /* This causes local impl of _create() to call driver's probe func. */
501 rsd->cb = ofono_call_barring_create(NULL, OFONO_RIL_VENDOR_AOSP,
502 "rilmodem", rsd);
503 rsd->cb->cbd = cbd;
504
505 /* add_idle doesn't work, read blocks main loop!!! */
506
507 if (cbd->rtd.unsol_test)
508 g_idle_add(cbd->start_func, (void *) rsd);
509 else
510 g_assert(cbd->start_func(rsd) == FALSE);
511}
512
513/*
514 * This unit test:
515 * - does some test data setup
516 * - configures a dummy server socket
517 * - creates a new gril client instance
518 * - triggers a connect to the dummy
519 * server socket
520 * - starts a mainloop
521 */
522static void test_call_barring_func(gconstpointer data)
523{
524 const struct cb_data *sd = data;
525 struct rilmodem_cb_data *rsd;
526
527 ril_call_barring_init();
528
529 rsd = g_new0(struct rilmodem_cb_data, 1);
530
531 rsd->test_data = sd;
532
533 rsd->serverd = rilmodem_test_server_create(&server_connect_cb,
534 &sd->rtd, rsd);
535
536 rsd->ril = g_ril_new(rilmodem_test_get_socket_name(rsd->serverd),
537 OFONO_RIL_VENDOR_AOSP);
538 g_assert(rsd->ril != NULL);
539
540 mainloop = g_main_loop_new(NULL, FALSE);
541
542 g_main_loop_run(mainloop);
543 g_main_loop_unref(mainloop);
544
545 cbdriver->remove(rsd->cb);
546 g_ril_unref(rsd->ril);
547 g_free(rsd);
548
549 rilmodem_test_server_close(rsd->serverd);
550
551 ril_call_barring_exit();
552}
553
554#endif
555
556int main(int argc, char **argv)
557{
558 g_test_init(&argc, &argv, NULL);
559
560/*
561 * As all our architectures are little-endian except for
562 * PowerPC, and the Binder wire-format differs slightly
563 * depending on endian-ness, the following guards against test
564 * failures when run on PowerPC.
565 */
566#if BYTE_ORDER == LITTLE_ENDIAN
567 g_test_add_data_func("/testrilmodemcallbarring/query/valid/1",
568 &testdata_query_valid_1,
569 test_call_barring_func);
570 g_test_add_data_func("/testrilmodemcallbarring/query/invalid/1",
571 &testdata_query_invalid_1,
572 test_call_barring_func);
573 g_test_add_data_func("/testrilmodemcallbarring/query/invalid/2",
574 &testdata_query_invalid_2,
575 test_call_barring_func);
576 g_test_add_data_func("/testrilmodemcallbarring/query/invalid/3",
577 &testdata_query_invalid_3,
578 test_call_barring_func);
579 g_test_add_data_func("/testrilmodemcallbarring/query/invalid/4",
580 &testdata_query_invalid_3,
581 test_call_barring_func);
582 g_test_add_data_func("/testrilmodemcallbarring/set/valid/1",
583 &testdata_set_valid_1,
584 test_call_barring_func);
585 g_test_add_data_func("/testrilmodemcallbarring/set/valid/2",
586 &testdata_set_valid_2,
587 test_call_barring_func);
588 g_test_add_data_func("/testrilmodemcallbarring/set/invalid/1",
589 &testdata_set_invalid_1,
590 test_call_barring_func);
591 g_test_add_data_func("/testrilmodemcallbarring/set/invalid/2",
592 &testdata_set_invalid_2,
593 test_call_barring_func);
594 g_test_add_data_func("/testrilmodemcallbarring/set/invalid/3",
595 &testdata_set_invalid_3,
596 test_call_barring_func);
597 g_test_add_data_func("/testrilmodemcallbarring/set_passwd/valid/1",
598 &testdata_set_passwd_valid_1,
599 test_call_barring_func);
600 g_test_add_data_func("/testrilmodemcallbarring/set_passwd/invalid/1",
601 &testdata_set_passwd_invalid_1,
602 test_call_barring_func);
603#endif
604 return g_test_run();
605}
0606
=== modified file 'unit/test-rilmodem-cs.c'
--- unit/test-rilmodem-cs.c 2015-11-05 21:28:06 +0000
+++ unit/test-rilmodem-cs.c 2016-03-14 09:03:03 +0000
@@ -40,29 +40,18 @@
4040
41#include "common.h"41#include "common.h"
42#include "ril_constants.h"42#include "ril_constants.h"
4343#include "rilmodem-test-server.h"
44#define MAX_REQUEST_SIZE 4096
4544
46static GMainLoop *mainloop;45static GMainLoop *mainloop;
4746
48static const struct ofono_call_settings_driver *csdriver;47static const struct ofono_call_settings_driver *csdriver;
4948
50struct rilmodemcs_data {49struct rilmodem_cs_data {
51 GRil *ril;50 GRil *ril;
52 int sk;
53 gint server_watch;
54 GIOChannel *server_io;
55 struct ofono_modem *modem;51 struct ofono_modem *modem;
56 gconstpointer test_data;52 gconstpointer test_data;
57 struct ofono_call_settings *cs;53 struct ofono_call_settings *cs;
58};54 struct server_data *serverd;
59
60/* Warning: length is stored in network order */
61struct rsp_hdr {
62 uint32_t length;
63 uint32_t unsolicited;
64 uint32_t serial;
65 uint32_t error;
66};55};
6756
68typedef gboolean (*StartFunc)(gpointer data);57typedef gboolean (*StartFunc)(gpointer data);
@@ -72,13 +61,7 @@
72 gint param_int1;61 gint param_int1;
73 gint param_int2;62 gint param_int2;
7463
75 const guchar *parcel_data;64 struct rilmodem_test_data rtd;
76
77 const gsize parcel_size;
78
79 uint32_t rsp_error;
80 const guchar *rsp_data;
81 const gsize rsp_size;
82 enum ofono_error_type error_type;65 enum ofono_error_type error_type;
83 gint cb_int1;66 gint cb_int1;
84 gint cb_int2;67 gint cb_int2;
@@ -87,8 +70,8 @@
87static void status_query_callback(const struct ofono_error *error, int status,70static void status_query_callback(const struct ofono_error *error, int status,
88 gpointer data)71 gpointer data)
89{72{
90 struct rilmodemcs_data *rcsd = data;73 struct rilmodem_cs_data *rcd = data;
91 const struct cs_data *csd = rcsd->test_data;74 const struct cs_data *csd = rcd->test_data;
9275
93 g_assert(error->type == csd->error_type);76 g_assert(error->type == csd->error_type);
9477
@@ -101,8 +84,8 @@
101static void clir_query_callback(const struct ofono_error *error, int override,84static void clir_query_callback(const struct ofono_error *error, int override,
102 int network, gpointer data)85 int network, gpointer data)
103{86{
104 struct rilmodemcs_data *rcsd = data;87 struct rilmodem_cs_data *rcd = data;
105 const struct cs_data *csd = rcsd->test_data;88 const struct cs_data *csd = rcd->test_data;
10689
107 g_assert(error->type == csd->error_type);90 g_assert(error->type == csd->error_type);
10891
@@ -116,8 +99,8 @@
11699
117static void set_callback(const struct ofono_error *error, gpointer data)100static void set_callback(const struct ofono_error *error, gpointer data)
118{101{
119 struct rilmodemcs_data *rcsd = data;102 struct rilmodem_cs_data *rcd = data;
120 const struct cs_data *csd = rcsd->test_data;103 const struct cs_data *csd = rcd->test_data;
121104
122 g_assert(error->type == csd->error_type);105 g_assert(error->type == csd->error_type);
123106
@@ -126,56 +109,56 @@
126109
127static gboolean trigger_clip_query(gpointer data)110static gboolean trigger_clip_query(gpointer data)
128{111{
129 struct rilmodemcs_data *rcsd = data;112 struct rilmodem_cs_data *rcd = data;
130113
131 g_assert(csdriver->clip_query != NULL);114 g_assert(csdriver->clip_query != NULL);
132 csdriver->clip_query(rcsd->cs, status_query_callback, rcsd);115 csdriver->clip_query(rcd->cs, status_query_callback, rcd);
133116
134 return FALSE;117 return FALSE;
135}118}
136119
137static gboolean trigger_cw_query(gpointer data)120static gboolean trigger_cw_query(gpointer data)
138{121{
139 struct rilmodemcs_data *rcsd = data;122 struct rilmodem_cs_data *rcd = data;
140123
141 g_assert(csdriver->cw_query != NULL);124 g_assert(csdriver->cw_query != NULL);
142125
143 /* cls is explicitly ignored by rilmodem; just use 0 */126 /* cls is explicitly ignored by rilmodem; just use 0 */
144 csdriver->cw_query(rcsd->cs, 0, status_query_callback, rcsd);127 csdriver->cw_query(rcd->cs, 0, status_query_callback, rcd);
145128
146 return FALSE;129 return FALSE;
147}130}
148131
149static gboolean trigger_cw_set(gpointer data)132static gboolean trigger_cw_set(gpointer data)
150{133{
151 struct rilmodemcs_data *rcsd = data;134 struct rilmodem_cs_data *rcd = data;
152 const struct cs_data *csd = rcsd->test_data;135 const struct cs_data *csd = rcd->test_data;
153136
154 g_assert(csdriver->cw_set != NULL);137 g_assert(csdriver->cw_set != NULL);
155138
156 csdriver->cw_set(rcsd->cs, csd->param_int1, csd->param_int2,139 csdriver->cw_set(rcd->cs, csd->param_int1, csd->param_int2,
157 set_callback, rcsd);140 set_callback, rcd);
158141
159 return FALSE;142 return FALSE;
160}143}
161144
162static gboolean trigger_clir_query(gpointer data)145static gboolean trigger_clir_query(gpointer data)
163{146{
164 struct rilmodemcs_data *rcsd = data;147 struct rilmodem_cs_data *rcd = data;
165148
166 g_assert(csdriver->clir_query != NULL);149 g_assert(csdriver->clir_query != NULL);
167 csdriver->clir_query(rcsd->cs, clir_query_callback, rcsd);150 csdriver->clir_query(rcd->cs, clir_query_callback, rcd);
168151
169 return FALSE;152 return FALSE;
170}153}
171154
172static gboolean trigger_clir_set(gpointer data)155static gboolean trigger_clir_set(gpointer data)
173{156{
174 struct rilmodemcs_data *rcsd = data;157 struct rilmodem_cs_data *rcd = data;
175 const struct cs_data *csd = rcsd->test_data;158 const struct cs_data *csd = rcd->test_data;
176159
177 g_assert(csdriver->clir_set != NULL);160 g_assert(csdriver->clir_set != NULL);
178 csdriver->clir_set(rcsd->cs, csd->param_int1, set_callback, rcsd);161 csdriver->clir_set(rcd->cs, csd->param_int1, set_callback, rcd);
179162
180 return FALSE;163 return FALSE;
181}164}
@@ -192,11 +175,13 @@
192175
193static const struct cs_data testdata_clip_query_valid_1 = {176static const struct cs_data testdata_clip_query_valid_1 = {
194 .start_func = trigger_clip_query,177 .start_func = trigger_clip_query,
195 .parcel_data = req_clip_query_parcel_1,178 .rtd = {
196 .parcel_size = sizeof(req_clip_query_parcel_1),179 .req_data = req_clip_query_parcel_1,
197 .rsp_data = rsp_clip_query_data_1,180 .req_size = sizeof(req_clip_query_parcel_1),
198 .rsp_size = sizeof(rsp_clip_query_data_1),181 .rsp_data = rsp_clip_query_data_1,
199 .rsp_error = RIL_E_SUCCESS,182 .rsp_size = sizeof(rsp_clip_query_data_1),
183 .rsp_error = RIL_E_SUCCESS,
184 },
200 .cb_int1 = 1,185 .cb_int1 = 1,
201 .error_type = OFONO_ERROR_TYPE_NO_ERROR,186 .error_type = OFONO_ERROR_TYPE_NO_ERROR,
202};187};
@@ -209,21 +194,25 @@
209/* reply parse error causes status to be returned as -1 */194/* reply parse error causes status to be returned as -1 */
210static const struct cs_data testdata_clip_query_invalid_1 = {195static const struct cs_data testdata_clip_query_invalid_1 = {
211 .start_func = trigger_clip_query,196 .start_func = trigger_clip_query,
212 .parcel_data = req_clip_query_parcel_1,197 .rtd = {
213 .parcel_size = sizeof(req_clip_query_parcel_1),198 .req_data = req_clip_query_parcel_1,
214 .rsp_data = rsp_clip_query_data_2,199 .req_size = sizeof(req_clip_query_parcel_1),
215 .rsp_size = sizeof(rsp_clip_query_data_2),200 .rsp_data = rsp_clip_query_data_2,
201 .rsp_size = sizeof(rsp_clip_query_data_2),
202 .rsp_error = RIL_E_SUCCESS,
203 },
216 .cb_int1 = -1,204 .cb_int1 = -1,
217 .rsp_error = RIL_E_SUCCESS,
218 .error_type = OFONO_ERROR_TYPE_NO_ERROR,205 .error_type = OFONO_ERROR_TYPE_NO_ERROR,
219};206};
220207
221/* error triggered by RIL reply error */208/* error triggered by RIL reply error */
222static const struct cs_data testdata_clip_query_invalid_2 = {209static const struct cs_data testdata_clip_query_invalid_2 = {
223 .start_func = trigger_clip_query,210 .start_func = trigger_clip_query,
224 .parcel_data = req_clip_query_parcel_1,211 .rtd = {
225 .parcel_size = sizeof(req_clip_query_parcel_1),212 .req_data = req_clip_query_parcel_1,
226 .rsp_error = RIL_E_GENERIC_FAILURE,213 .req_size = sizeof(req_clip_query_parcel_1),
214 .rsp_error = RIL_E_GENERIC_FAILURE,
215 },
227 .error_type = OFONO_ERROR_TYPE_FAILURE,216 .error_type = OFONO_ERROR_TYPE_FAILURE,
228};217};
229218
@@ -240,11 +229,13 @@
240229
241static const struct cs_data testdata_cw_query_valid_1 = {230static const struct cs_data testdata_cw_query_valid_1 = {
242 .start_func = trigger_cw_query,231 .start_func = trigger_cw_query,
243 .parcel_data = req_cw_query_parcel_1,232 .rtd = {
244 .parcel_size = sizeof(req_cw_query_parcel_1),233 .req_data = req_cw_query_parcel_1,
245 .rsp_data = rsp_cw_query_data_1,234 .req_size = sizeof(req_cw_query_parcel_1),
246 .rsp_size = sizeof(rsp_cw_query_data_1),235 .rsp_data = rsp_cw_query_data_1,
247 .rsp_error = RIL_E_SUCCESS,236 .rsp_size = sizeof(rsp_cw_query_data_1),
237 .rsp_error = RIL_E_SUCCESS,
238 },
248 .cb_int1 = 3,239 .cb_int1 = 3,
249 .error_type = OFONO_ERROR_TYPE_NO_ERROR,240 .error_type = OFONO_ERROR_TYPE_NO_ERROR,
250};241};
@@ -257,24 +248,28 @@
257/* reply parse error causes status to be returned as -1 */248/* reply parse error causes status to be returned as -1 */
258static const struct cs_data testdata_cw_query_invalid_1 = {249static const struct cs_data testdata_cw_query_invalid_1 = {
259 .start_func = trigger_cw_query,250 .start_func = trigger_cw_query,
260 .parcel_data = req_cw_query_parcel_1,251 .rtd = {
261 .parcel_size = sizeof(req_cw_query_parcel_1),252 .req_data = req_cw_query_parcel_1,
262 .rsp_data = rsp_cw_query_data_2,253 .req_size = sizeof(req_cw_query_parcel_1),
263 .rsp_size = sizeof(rsp_cw_query_data_2),254 .rsp_data = rsp_cw_query_data_2,
255 .rsp_size = sizeof(rsp_cw_query_data_2),
256 .rsp_error = RIL_E_SUCCESS,
257 },
264 .cb_int1 = -1,258 .cb_int1 = -1,
265 .rsp_error = RIL_E_SUCCESS,
266 .error_type = OFONO_ERROR_TYPE_NO_ERROR,259 .error_type = OFONO_ERROR_TYPE_NO_ERROR,
267};260};
268261
269/* GENERIC_FAILURE returned in RIL reply */262/* GENERIC_FAILURE returned in RIL reply */
270static const struct cs_data testdata_cw_query_invalid_2 = {263static const struct cs_data testdata_cw_query_invalid_2 = {
271 .start_func = trigger_cw_query,264 .start_func = trigger_cw_query,
272 .parcel_data = req_cw_query_parcel_1,265 .rtd = {
273 .parcel_size = sizeof(req_cw_query_parcel_1),266 .req_data = req_cw_query_parcel_1,
274 .rsp_data = rsp_cw_query_data_2,267 .req_size = sizeof(req_cw_query_parcel_1),
275 .rsp_size = sizeof(rsp_cw_query_data_2),268 .rsp_data = rsp_cw_query_data_2,
269 .rsp_size = sizeof(rsp_cw_query_data_2),
270 .rsp_error = RIL_E_GENERIC_FAILURE,
271 },
276 .cb_int1 = -1,272 .cb_int1 = -1,
277 .rsp_error = RIL_E_GENERIC_FAILURE,
278 .error_type = OFONO_ERROR_TYPE_FAILURE,273 .error_type = OFONO_ERROR_TYPE_FAILURE,
279};274};
280275
@@ -289,9 +284,11 @@
289 .start_func = trigger_cw_set,284 .start_func = trigger_cw_set,
290 .param_int1 = 1,285 .param_int1 = 1,
291 .param_int2 = BEARER_CLASS_DEFAULT,286 .param_int2 = BEARER_CLASS_DEFAULT,
292 .parcel_data = req_cw_set_enabled_parcel_1,287 .rtd = {
293 .parcel_size = sizeof(req_cw_set_enabled_parcel_1),288 .req_data = req_cw_set_enabled_parcel_1,
294 .rsp_error = RIL_E_SUCCESS,289 .req_size = sizeof(req_cw_set_enabled_parcel_1),
290 .rsp_error = RIL_E_SUCCESS,
291 },
295 .error_type = OFONO_ERROR_TYPE_NO_ERROR,292 .error_type = OFONO_ERROR_TYPE_NO_ERROR,
296};293};
297294
@@ -306,9 +303,11 @@
306 .start_func = trigger_cw_set,303 .start_func = trigger_cw_set,
307 .param_int1 = 0,304 .param_int1 = 0,
308 .param_int2 = 0,305 .param_int2 = 0,
309 .parcel_data = req_cw_set_disabled_parcel_2,306 .rtd = {
310 .parcel_size = sizeof(req_cw_set_disabled_parcel_2),307 .req_data = req_cw_set_disabled_parcel_2,
311 .rsp_error = RIL_E_GENERIC_FAILURE,308 .req_size = sizeof(req_cw_set_disabled_parcel_2),
309 .rsp_error = RIL_E_GENERIC_FAILURE,
310 },
312 .error_type = OFONO_ERROR_TYPE_FAILURE,311 .error_type = OFONO_ERROR_TYPE_FAILURE,
313};312};
314313
@@ -324,13 +323,15 @@
324323
325static const struct cs_data testdata_clir_query_valid_1 = {324static const struct cs_data testdata_clir_query_valid_1 = {
326 .start_func = trigger_clir_query,325 .start_func = trigger_clir_query,
327 .parcel_data = req_clir_query_parcel_1,326 .rtd = {
328 .parcel_size = sizeof(req_clir_query_parcel_1),327 .req_data = req_clir_query_parcel_1,
329 .rsp_data = rsp_clir_query_data_1,328 .req_size = sizeof(req_clir_query_parcel_1),
330 .rsp_size = sizeof(rsp_clir_query_data_1),329 .rsp_data = rsp_clir_query_data_1,
330 .rsp_size = sizeof(rsp_clir_query_data_1),
331 .rsp_error = RIL_E_SUCCESS,
332 },
331 .cb_int1 = 2,333 .cb_int1 = 2,
332 .cb_int2 = 4,334 .cb_int2 = 4,
333 .rsp_error = RIL_E_SUCCESS,
334 .error_type = OFONO_ERROR_TYPE_NO_ERROR,335 .error_type = OFONO_ERROR_TYPE_NO_ERROR,
335};336};
336337
@@ -340,11 +341,13 @@
340};341};
341static const struct cs_data testdata_clir_query_invalid_1 = {342static const struct cs_data testdata_clir_query_invalid_1 = {
342 .start_func = trigger_clir_query,343 .start_func = trigger_clir_query,
343 .parcel_data = req_clir_query_parcel_1,344 .rtd = {
344 .parcel_size = sizeof(req_clir_query_parcel_1),345 .req_data = req_clir_query_parcel_1,
345 .rsp_data = rsp_clir_query_data_2,346 .req_size = sizeof(req_clir_query_parcel_1),
346 .rsp_size = sizeof(rsp_clir_query_data_2),347 .rsp_data = rsp_clir_query_data_2,
347 .rsp_error = RIL_E_SUCCESS,348 .rsp_size = sizeof(rsp_clir_query_data_2),
349 .rsp_error = RIL_E_SUCCESS,
350 },
348 .error_type = OFONO_ERROR_TYPE_FAILURE,351 .error_type = OFONO_ERROR_TYPE_FAILURE,
349};352};
350353
@@ -357,9 +360,11 @@
357static const struct cs_data testdata_clir_set_valid_1 = {360static const struct cs_data testdata_clir_set_valid_1 = {
358 .start_func = trigger_clir_set,361 .start_func = trigger_clir_set,
359 .param_int1 = OFONO_CLIR_OPTION_DEFAULT,362 .param_int1 = OFONO_CLIR_OPTION_DEFAULT,
360 .parcel_data = req_clir_set_mode0_parcel_1,363 .rtd = {
361 .parcel_size = sizeof(req_clir_set_mode0_parcel_1),364 .req_data = req_clir_set_mode0_parcel_1,
362 .rsp_error = RIL_E_SUCCESS,365 .req_size = sizeof(req_clir_set_mode0_parcel_1),
366 .rsp_error = RIL_E_SUCCESS,
367 },
363 .error_type = OFONO_ERROR_TYPE_NO_ERROR,368 .error_type = OFONO_ERROR_TYPE_NO_ERROR,
364};369};
365370
@@ -373,9 +378,12 @@
373static const struct cs_data testdata_clir_set_invalid_1 = {378static const struct cs_data testdata_clir_set_invalid_1 = {
374 .start_func = trigger_clir_set,379 .start_func = trigger_clir_set,
375 .param_int1 = OFONO_CLIR_OPTION_INVOCATION,380 .param_int1 = OFONO_CLIR_OPTION_INVOCATION,
376 .parcel_data = req_clir_set_mode0_parcel_2,381
377 .parcel_size = sizeof(req_clir_set_mode0_parcel_2),382 .rtd = {
378 .rsp_error = RIL_E_GENERIC_FAILURE,383 .req_data = req_clir_set_mode0_parcel_2,
384 .req_size = sizeof(req_clir_set_mode0_parcel_2),
385 .rsp_error = RIL_E_GENERIC_FAILURE,
386 },
379 .error_type = OFONO_ERROR_TYPE_FAILURE,387 .error_type = OFONO_ERROR_TYPE_FAILURE,
380};388};
381389
@@ -392,11 +400,11 @@
392 const char *driver,400 const char *driver,
393 void *data)401 void *data)
394{402{
395 struct rilmodemcs_data *rcsd = data;403 struct rilmodem_cs_data *rcd = data;
396 struct ofono_call_settings *cs = g_new0(struct ofono_call_settings, 1);404 struct ofono_call_settings *cs = g_new0(struct ofono_call_settings, 1);
397 int retval;405 int retval;
398406
399 retval = csdriver->probe(cs, OFONO_RIL_VENDOR_AOSP, rcsd->ril);407 retval = csdriver->probe(cs, OFONO_RIL_VENDOR_AOSP, rcd->ril);
400 g_assert(retval == 0);408 g_assert(retval == 0);
401409
402 return cs;410 return cs;
@@ -422,12 +430,10 @@
422430
423void ofono_call_settings_register(struct ofono_call_settings *cs)431void ofono_call_settings_register(struct ofono_call_settings *cs)
424{432{
425 ;
426}433}
427434
428void ofono_call_settings_driver_unregister(const struct ofono_call_settings_driver *d)435void ofono_call_settings_driver_unregister(const struct ofono_call_settings_driver *d)
429{436{
430 ;
431}437}
432438
433/*439/*
@@ -438,163 +444,23 @@
438 */444 */
439#if BYTE_ORDER == LITTLE_ENDIAN445#if BYTE_ORDER == LITTLE_ENDIAN
440446
441static gboolean read_server(gpointer data)447static void server_connect_cb(gpointer data)
442{448{
443 GIOStatus status;449 struct rilmodem_cs_data *rcd = data;
444 struct rilmodemcs_data *rcsd = data;450 const struct cs_data *csd = rcd->test_data;
445 gsize offset, rbytes, wbytes;
446 gchar *buf, *bufp;
447 uint32_t req_serial;
448 struct rsp_hdr rsp;
449
450 /*
451 * FIXME: separate out verification from here, so read_server doesn't
452 * need to know about cs_data.
453 */
454 const struct cs_data *csd = rcsd->test_data;
455
456 buf = g_malloc0(MAX_REQUEST_SIZE);
457
458 status = g_io_channel_read_chars(rcsd->server_io, buf, MAX_REQUEST_SIZE,
459 &rbytes, NULL);
460 g_assert(status == G_IO_STATUS_NORMAL);
461 g_assert(rbytes == csd->parcel_size);
462
463 /* validate len, and request_id */
464 g_assert(!memcmp(buf, csd->parcel_data, (sizeof(uint32_t) * 2)));
465
466 /*
467 * header: size (uint32), reqid (uin32), serial (uint32)
468 * header size == 16 ( excludes sizeof(size) )
469 */
470
471 /* advance past request_no */
472 bufp = buf + (sizeof(uint32_t) * 2);
473
474 req_serial = (uint32_t) *bufp;
475
476 /* advance past serial_no */
477 bufp += sizeof(uint32_t);
478
479 /* validate the rest of the parcel... */
480 offset = (sizeof(uint32_t) * 3);
481 g_assert(!memcmp(bufp, csd->parcel_data + offset,
482 csd->parcel_size - offset));
483
484 /* Length does not include the length field. Network order. */
485 rsp.length = htonl(sizeof(rsp) - sizeof(rsp.length) + csd->rsp_size);
486 rsp.unsolicited = 0;
487 rsp.serial = req_serial;
488 rsp.error = csd->rsp_error;
489
490 /* copy header */
491 memcpy(buf, &rsp, sizeof(rsp));
492
493 if (csd->rsp_size) {
494 bufp = buf + sizeof(rsp);
495
496 memcpy(bufp, csd->rsp_data, csd->rsp_size);
497 }
498
499
500 status = g_io_channel_write_chars(rcsd->server_io,
501 buf,
502 sizeof(rsp) + csd->rsp_size,
503 &wbytes, NULL);
504
505 /* FIXME: assert wbytes is correct */
506
507 g_assert(status == G_IO_STATUS_NORMAL);
508
509 g_free(buf);
510 g_io_channel_unref(rcsd->server_io);
511
512 return FALSE;
513}
514
515static gboolean on_socket_connected(GIOChannel *chan, GIOCondition cond,
516 gpointer data)
517{
518 struct rilmodemcs_data *rcsd = data;
519 const struct cs_data *csd = rcsd->test_data;
520 struct sockaddr saddr;
521 unsigned int len = sizeof(saddr);
522 int fd;
523 GIOChannel *server_io = NULL;
524 GIOStatus status;
525
526 g_assert(cond == G_IO_IN);
527
528 fd = accept(rcsd->sk, &saddr, &len);
529 g_assert(fd != -1);
530
531 server_io = g_io_channel_unix_new(fd);
532 g_assert(server_io != NULL);
533451
534 /* This causes local impl of _create() to call driver's probe func. */452 /* This causes local impl of _create() to call driver's probe func. */
535 rcsd->cs = ofono_call_settings_create(NULL, OFONO_RIL_VENDOR_AOSP,453 rcd->cs = ofono_call_settings_create(NULL, OFONO_RIL_VENDOR_AOSP,
536 "rilmodem", rcsd);454 "rilmodem", rcd);
537455
538 /* add_idle doesn't work, read blocks main loop!!! */456 /* add_idle doesn't work, read blocks main loop!!! */
539 g_assert(csd->start_func(rcsd) == FALSE);457 g_assert(csd->start_func(rcd) == FALSE);
540
541 status = g_io_channel_set_encoding(server_io, NULL, NULL);
542 g_assert(status == G_IO_STATUS_NORMAL);
543
544 g_io_channel_set_buffered(server_io, FALSE);
545 g_io_channel_set_close_on_unref(server_io, TRUE);
546
547 rcsd->server_io = server_io;
548
549 g_idle_add(read_server, rcsd);
550
551 /* single-shot callback */
552 return FALSE;
553}
554
555static void create_server_socket(const char *sock_path,
556 struct rilmodemcs_data *rcsd)
557{
558 GIOChannel *io;
559 struct sockaddr_un addr;
560 int retval;
561
562 rcsd->sk = socket(AF_UNIX, SOCK_STREAM, 0);
563 g_assert(rcsd->sk);
564
565 memset(&addr, 0, sizeof(addr));
566 addr.sun_family = AF_UNIX;
567 strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1);
568
569 /* Unlink any existing socket for this session */
570 unlink(addr.sun_path);
571
572 retval = bind(rcsd->sk, (struct sockaddr *) &addr, sizeof(addr));
573 g_assert(retval >= 0);
574
575 retval = listen(rcsd->sk, 0);
576 g_assert(retval >= 0);
577
578 io = g_io_channel_unix_new(rcsd->sk);
579 g_assert(io != NULL);
580
581 g_io_channel_set_close_on_unref(io, TRUE);
582 g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
583
584 rcsd->server_watch = g_io_add_watch_full(io,
585 G_PRIORITY_DEFAULT,
586 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
587 on_socket_connected, rcsd, NULL);
588
589 g_io_channel_unref(io);
590}458}
591459
592/*460/*
593 * This unit test:461 * This unit test:
594 * - does some test data setup462 * - does some test data setup
595 * - configures a dummy server socket463 * - configures a dummy server socket
596 * - on_socket_connected: callback for
597 * incoming socket connects
598 * - creates a new gril client instance464 * - creates a new gril client instance
599 * - triggers a connect to the dummy465 * - triggers a connect to the dummy
600 * server socket466 * server socket
@@ -603,27 +469,31 @@
603static void test_cs_func(gconstpointer data)469static void test_cs_func(gconstpointer data)
604{470{
605 const struct cs_data *csd = data;471 const struct cs_data *csd = data;
606 struct rilmodemcs_data *rcsd;472 struct rilmodem_cs_data *rcd;
607473
608 ril_call_settings_init();474 ril_call_settings_init();
609475
610 rcsd = g_new0(struct rilmodemcs_data, 1);476 rcd = g_new0(struct rilmodem_cs_data, 1);
611477
612 rcsd->test_data = csd;478 rcd->test_data = csd;
613479
614 create_server_socket("/tmp/unittestril", rcsd);480 rcd->serverd = rilmodem_test_server_create(&server_connect_cb,
615481 &csd->rtd, rcd);
616 rcsd->ril = g_ril_new("/tmp/unittestril", OFONO_RIL_VENDOR_AOSP);482
617 g_assert(rcsd->ril != NULL);483 rcd->ril = g_ril_new(rilmodem_test_get_socket_name(rcd->serverd),
484 OFONO_RIL_VENDOR_AOSP);
485 g_assert(rcd->ril != NULL);
618486
619 mainloop = g_main_loop_new(NULL, FALSE);487 mainloop = g_main_loop_new(NULL, FALSE);
620488
621 g_main_loop_run(mainloop);489 g_main_loop_run(mainloop);
622 g_main_loop_unref(mainloop);490 g_main_loop_unref(mainloop);
623491
624 csdriver->remove(rcsd->cs);492 csdriver->remove(rcd->cs);
625 g_ril_unref(rcsd->ril);493 g_ril_unref(rcd->ril);
626 g_free(rcsd);494 g_free(rcd);
495
496 rilmodem_test_server_close(rcd->serverd);
627497
628 ril_call_settings_exit();498 ril_call_settings_exit();
629}499}
630500
=== added file 'unit/test-rilmodem-sms.c'
--- unit/test-rilmodem-sms.c 1970-01-01 00:00:00 +0000
+++ unit/test-rilmodem-sms.c 2016-03-14 09:03:03 +0000
@@ -0,0 +1,596 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2015 Canonical Ltd.
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#define _GNU_SOURCE
27#include <assert.h>
28#include <errno.h>
29#include <glib.h>
30#include <stdio.h>
31#include <netinet/in.h>
32#include <sys/socket.h>
33#include <sys/un.h>
34#include <unistd.h>
35
36#include <ofono/modem.h>
37#include <ofono/types.h>
38#include <ofono/sms.h>
39#include <gril.h>
40
41#include "common.h"
42#include "ril_constants.h"
43#include "rilmodem-test-server.h"
44
45static GMainLoop *mainloop;
46
47static const struct ofono_sms_driver *smsdriver;
48
49struct rilmodem_sms_data {
50 GRil *ril;
51 struct ofono_modem *modem;
52 gconstpointer test_data;
53 struct ofono_sms *sms;
54 struct server_data *serverd;
55};
56
57typedef gboolean (*StartFunc)(gpointer data);
58
59struct sms_data {
60 StartFunc start_func;
61
62 const unsigned char *pdu;
63 gint pdu_len;
64 gint tpdu_len;
65 gint mms;
66
67 struct rilmodem_test_data rtd;
68 enum ofono_error_type error_type;
69
70 const struct ofono_phone_number ph;
71 gint mr;
72};
73
74static void sca_query_callback(const struct ofono_error *error,
75 const struct ofono_phone_number *ph,
76 gpointer data)
77{
78 struct rilmodem_sms_data *rsd = data;
79 const struct sms_data *sd = rsd->test_data;
80
81 g_assert(error->type == sd->error_type);
82
83 if (error->type == OFONO_ERROR_TYPE_NO_ERROR) {
84 g_assert(ph->type == sd->ph.type);
85 g_assert(strcmp(ph->number, sd->ph.number) == 0);
86 }
87
88 g_main_loop_quit(mainloop);
89}
90
91static void sca_set_callback(const struct ofono_error *error, gpointer data)
92{
93 struct rilmodem_sms_data *rsd = data;
94 const struct sms_data *sd = rsd->test_data;
95
96 g_assert(error->type == sd->error_type);
97
98 g_main_loop_quit(mainloop);
99}
100
101static void submit_callback(const struct ofono_error *error, int mr,
102 gpointer data)
103{
104 struct rilmodem_sms_data *rsd = data;
105 const struct sms_data *sd = rsd->test_data;
106
107 g_assert(error->type == sd->error_type);
108 g_assert(mr == sd->mr);
109
110 g_main_loop_quit(mainloop);
111}
112
113static gboolean trigger_sca_query(gpointer data)
114{
115 struct rilmodem_sms_data *rsd = data;
116
117 g_assert(smsdriver->sca_query != NULL);
118 smsdriver->sca_query(rsd->sms, sca_query_callback, rsd);
119
120 return FALSE;
121}
122
123static gboolean trigger_sca_set(gpointer data)
124{
125 struct rilmodem_sms_data *rsd = data;
126 const struct sms_data *sd = rsd->test_data;
127
128 g_assert(smsdriver->sca_set != NULL);
129 smsdriver->sca_set(rsd->sms, &sd->ph, sca_set_callback, rsd);
130
131 return FALSE;
132}
133
134static gboolean trigger_submit(gpointer data)
135{
136 struct rilmodem_sms_data *rsd = data;
137 const struct sms_data *sd = rsd->test_data;
138
139 g_assert(smsdriver->submit != NULL);
140
141 smsdriver->submit(rsd->sms, sd->pdu, sd->pdu_len, sd->tpdu_len,
142 sd->mms, submit_callback, rsd);
143
144 return FALSE;
145}
146
147static gboolean trigger_new_sms(gpointer data)
148{
149 struct rilmodem_sms_data *rsd = data;
150 const struct sms_data *sd = rsd->test_data;
151
152 rilmodem_test_server_write(rsd->serverd, sd->rtd.req_data,
153 sd->rtd.req_size);
154
155 return FALSE;
156}
157
158/* RIL_REQUEST_GET_SMSC_ADDRESS */
159static const guchar req_get_smsc_address_parcel_1[] = {
160 0x00, 0x00, 0x00, 0x08, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
161};
162
163
164/*
165 * RIL_REQUEST_GET_SMSC_ADDRESS reply with the following data:
166 *
167 * {number="+34607003110"}
168 */
169static const guchar rsp_get_smsc_address_data_1[] = {
170 0x0d, 0x00, 0x00, 0x00, 0x22, 0x00, 0x2b, 0x00, 0x33, 0x00, 0x34, 0x00,
171 0x36, 0x00, 0x30, 0x00, 0x37, 0x00, 0x30, 0x00, 0x30, 0x00, 0x33, 0x00,
172 0x31, 0x00, 0x31, 0x00, 0x30, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00
173};
174
175static const struct sms_data testdata_sca_query_valid_1 = {
176 .start_func = trigger_sca_query,
177 .rtd = {
178 .req_data = req_get_smsc_address_parcel_1,
179 .req_size = sizeof(req_get_smsc_address_parcel_1),
180 .rsp_data = rsp_get_smsc_address_data_1,
181 .rsp_size = sizeof(rsp_get_smsc_address_data_1),
182 .rsp_error = RIL_E_SUCCESS,
183 },
184 .ph = { .number = "34607003110", .type = 145 },
185 .error_type = OFONO_ERROR_TYPE_NO_ERROR,
186};
187
188/*
189 * RIL_REQUEST_GET_SMSC_ADDRESS reply with no data, which should
190 * trigger a callback failure.
191 */
192static const struct sms_data testdata_sca_query_invalid_1 = {
193 .start_func = trigger_sca_query,
194 .rtd = {
195 .req_data = req_get_smsc_address_parcel_1,
196 .req_size = sizeof(req_get_smsc_address_parcel_1),
197 .rsp_error = RIL_E_SUCCESS,
198 },
199 .error_type = OFONO_ERROR_TYPE_FAILURE,
200};
201
202/*
203 * RIL_REQUEST_GET_SMSC_ADDRESS reply with no quotes found which
204 * should trigger a callback failure.
205 */
206static const guchar rsp_get_smsc_address_data_3[] = {
207 0x02, 0x00, 0x00, 0x00, 0x22, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00
208};
209
210static const struct sms_data testdata_sca_query_invalid_2 = {
211 .start_func = trigger_sca_query,
212 .ph = { .number = "34607003110", .type = 145 },
213 .rtd = {
214 .req_data = req_get_smsc_address_parcel_1,
215 .req_size = sizeof(req_get_smsc_address_parcel_1),
216 .rsp_data = rsp_get_smsc_address_data_3,
217 .rsp_size = sizeof(rsp_get_smsc_address_data_3),
218 .rsp_error = RIL_E_SUCCESS,
219 },
220 .error_type = OFONO_ERROR_TYPE_FAILURE,
221};
222
223/* GENERIC_FAILURE returned in RIL reply */
224static const struct sms_data testdata_sca_query_invalid_3 = {
225 .start_func = trigger_sca_query,
226 .rtd = {
227 .req_data = req_get_smsc_address_parcel_1,
228 .req_size = sizeof(req_get_smsc_address_parcel_1),
229 .rsp_error = RIL_E_GENERIC_FAILURE,
230 },
231 .error_type = OFONO_ERROR_TYPE_FAILURE,
232};
233
234/*
235 * RIL_REQUEST_SET_SMSC_ADDRESS with the following data:
236 *
237 * {number="+34607003110"}
238 */
239static const guchar req_set_smsc_address_parcel_1[] = {
240 +0x00, 0x00, 0x00, 0x2C, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
241 +0x0e, 0x00, 0x00, 0x00, 0x22, 0x00, 0x2b, 0x00, 0x33, 0x00, 0x34, 0x00,
242 +0x36, 0x00, 0x30, 0x00, 0x37, 0x00, 0x30, 0x00, 0x30, 0x00, 0x33, 0x00,
243 +0x31, 0x00, 0x31, 0x00, 0x30, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00
244};
245
246static const struct sms_data testdata_sca_set_valid_1 = {
247 .start_func = trigger_sca_set,
248 .ph = { .number = "34607003110", .type = 145 },
249 .rtd = {
250 .req_data = req_set_smsc_address_parcel_1,
251 .req_size = sizeof(req_set_smsc_address_parcel_1),
252 .rsp_error = RIL_E_SUCCESS,
253 },
254 .error_type = OFONO_ERROR_TYPE_NO_ERROR,
255};
256
257/* GENERIC_FAILURE returned in RIL reply */
258static const struct sms_data testdata_sca_set_invalid_1 = {
259 .start_func = trigger_sca_set,
260 .ph = { .number = "34607003110", .type = 145 },
261 .rtd = {
262 .req_data = req_set_smsc_address_parcel_1,
263 .req_size = sizeof(req_set_smsc_address_parcel_1),
264 .rsp_error = RIL_E_GENERIC_FAILURE,
265 },
266 .error_type = OFONO_ERROR_TYPE_FAILURE,
267};
268
269static const unsigned char req_send_sms_pdu_valid_1[] = {
270 0x00, 0x11, 0x00, 0x09, 0x81, 0x36, 0x54, 0x39, 0x80, 0xf5, 0x00, 0x00,
271 0xa7, 0x0a, 0xc8, 0x37, 0x3b, 0x0c, 0x6a, 0xd7, 0xdd, 0xe4, 0x37
272};
273
274static const guchar req_send_sms_parcel_1[] = {
275 0x00, 0x00, 0x00, 0x70, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
276 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00,
277 0x31, 0x00, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x39, 0x00,
278 0x38, 0x00, 0x31, 0x00, 0x33, 0x00, 0x36, 0x00, 0x35, 0x00, 0x34, 0x00,
279 0x33, 0x00, 0x39, 0x00, 0x38, 0x00, 0x30, 0x00, 0x46, 0x00, 0x35, 0x00,
280 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x41, 0x00, 0x37, 0x00,
281 0x30, 0x00, 0x41, 0x00, 0x43, 0x00, 0x38, 0x00, 0x33, 0x00, 0x37, 0x00,
282 0x33, 0x00, 0x42, 0x00, 0x30, 0x00, 0x43, 0x00, 0x36, 0x00, 0x41, 0x00,
283 0x44, 0x00, 0x37, 0x00, 0x44, 0x00, 0x44, 0x00, 0x45, 0x00, 0x34, 0x00,
284 0x33, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00
285};
286
287/*
288 * SEND_SMS reply with the following data:
289 *
290 * messageRef=1
291 * ackPDU=NULL
292 * errorCode=0
293 */
294static const guchar rsp_send_sms_valid_1[] = {
295 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
296};
297
298static const struct sms_data testdata_submit_valid_1 = {
299 .start_func = trigger_submit,
300 .pdu = req_send_sms_pdu_valid_1,
301 .pdu_len = sizeof(req_send_sms_pdu_valid_1),
302 .tpdu_len = sizeof(req_send_sms_pdu_valid_1) - 1,
303 .mms = 0,
304 .rtd = {
305 .req_data = req_send_sms_parcel_1,
306 .req_size = sizeof(req_send_sms_parcel_1),
307 .rsp_data = rsp_send_sms_valid_1,
308 .rsp_size = sizeof(rsp_send_sms_valid_1),
309 .rsp_error = RIL_E_SUCCESS,
310 },
311 .mr = 1,
312 .error_type = OFONO_ERROR_TYPE_NO_ERROR,
313};
314
315/*
316 * SEND_SMS reply with failure indicated
317 */
318static const struct sms_data testdata_submit_invalid_1 = {
319 .start_func = trigger_submit,
320 .pdu = req_send_sms_pdu_valid_1,
321 .pdu_len = sizeof(req_send_sms_pdu_valid_1),
322 .tpdu_len = sizeof(req_send_sms_pdu_valid_1) - 1,
323 .mms = 0,
324 .rtd = {
325 .req_data = req_send_sms_parcel_1,
326 .req_size = sizeof(req_send_sms_parcel_1),
327 .rsp_error = RIL_E_GENERIC_FAILURE,
328 },
329 .error_type = OFONO_ERROR_TYPE_FAILURE,
330};
331
332/*
333 * The following hexadecimal data represents a serialized Binder parcel
334 * instance containing a valid RIL_UNSOL_RESPONSE_NEW_SMS message
335 * with the following parameter (SMSC address length is 7):
336 *
337 * {07914306073011F0040B914336543980F50000310113212002400AC8373B0C6AD7DDE437}
338 * {069143060730F0040B914336543980F50000310113212002400AC8373B0C6AD7DDE437}
339 */
340static const guchar unsol_response_new_sms_parcel_1[] = {
341 0x00, 0x00, 0x00, 0xA0, 0x01, 0x00, 0x00, 0x00, 0xEB, 0x03, 0x00, 0x00,
342 0x48, 0x00, 0x00, 0x00, 0x30, 0x00, 0x37, 0x00, 0x39, 0x00, 0x31, 0x00,
343 0x34, 0x00, 0x33, 0x00, 0x30, 0x00, 0x36, 0x00, 0x30, 0x00, 0x37, 0x00,
344 0x33, 0x00, 0x30, 0x00, 0x31, 0x00, 0x31, 0x00, 0x46, 0x00, 0x30, 0x00,
345 0x30, 0x00, 0x34, 0x00, 0x30, 0x00, 0x42, 0x00, 0x39, 0x00, 0x31, 0x00,
346 0x34, 0x00, 0x33, 0x00, 0x33, 0x00, 0x36, 0x00, 0x35, 0x00, 0x34, 0x00,
347 0x33, 0x00, 0x39, 0x00, 0x38, 0x00, 0x30, 0x00, 0x46, 0x00, 0x35, 0x00,
348 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x33, 0x00, 0x31, 0x00,
349 0x30, 0x00, 0x31, 0x00, 0x31, 0x00, 0x33, 0x00, 0x32, 0x00, 0x31, 0x00,
350 0x32, 0x00, 0x30, 0x00, 0x30, 0x00, 0x32, 0x00, 0x34, 0x00, 0x30, 0x00,
351 0x30, 0x00, 0x41, 0x00, 0x43, 0x00, 0x38, 0x00, 0x33, 0x00, 0x37, 0x00,
352 0x33, 0x00, 0x42, 0x00, 0x30, 0x00, 0x43, 0x00, 0x36, 0x00, 0x41, 0x00,
353 0x44, 0x00, 0x37, 0x00, 0x44, 0x00, 0x44, 0x00, 0x45, 0x00, 0x34, 0x00,
354 0x33, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00
355};
356
357const unsigned char new_sms_pdu_valid_1[] = {
358 0x07, 0x91, 0x43, 0x06, 0x07, 0x30, 0x11, 0xf0, 0x04, 0x0b, 0x91, 0x43,
359 0x36, 0x54, 0x39, 0x80, 0xf5, 0x00, 0x00, 0x31, 0x01, 0x13, 0x21, 0x20,
360 0x02, 0x40, 0x0a, 0xc8, 0x37, 0x3b, 0x0c, 0x6a, 0xd7, 0xdd, 0xe4, 0x37
361};
362
363static const struct sms_data testdata_new_sms_valid_1 = {
364 .start_func = trigger_new_sms,
365 .rtd = {
366 .req_data = unsol_response_new_sms_parcel_1,
367 .req_size = sizeof(unsol_response_new_sms_parcel_1),
368 .unsol_test = TRUE,
369 },
370 .pdu = new_sms_pdu_valid_1,
371 .pdu_len = sizeof(new_sms_pdu_valid_1),
372 .tpdu_len = 28,
373};
374
375/*
376 * The following hexadecimal data represents a serialized Binder parcel
377 * instance containing a valid UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT message
378 * with the following parameter (SMSC address length is 6):
379 *
380 * {069143060730F0040B914336543980F50000310113212002400AC8373B0C6AD7DDE437}
381 */
382static const guchar unsol_response_new_sms_parcel_2[] = {
383 0x00, 0x00, 0x00, 0x9C, 0x01, 0x00, 0x00, 0x00, 0xEC, 0x03, 0x00, 0x00,
384 0x46, 0x00, 0x00, 0x00, 0x30, 0x00, 0x36, 0x00, 0x39, 0x00, 0x31, 0x00,
385 0x34, 0x00, 0x33, 0x00, 0x30, 0x00, 0x36, 0x00, 0x30, 0x00, 0x37, 0x00,
386 0x33, 0x00, 0x30, 0x00, 0x46, 0x00, 0x30, 0x00, 0x30, 0x00, 0x34, 0x00,
387 0x30, 0x00, 0x42, 0x00, 0x39, 0x00, 0x31, 0x00, 0x34, 0x00, 0x33, 0x00,
388 0x33, 0x00, 0x36, 0x00, 0x35, 0x00, 0x34, 0x00, 0x33, 0x00, 0x39, 0x00,
389 0x38, 0x00, 0x30, 0x00, 0x46, 0x00, 0x35, 0x00, 0x30, 0x00, 0x30, 0x00,
390 0x30, 0x00, 0x30, 0x00, 0x33, 0x00, 0x31, 0x00, 0x30, 0x00, 0x31, 0x00,
391 0x31, 0x00, 0x33, 0x00, 0x32, 0x00, 0x31, 0x00, 0x32, 0x00, 0x30, 0x00,
392 0x30, 0x00, 0x32, 0x00, 0x34, 0x00, 0x30, 0x00, 0x30, 0x00, 0x41, 0x00,
393 0x43, 0x00, 0x38, 0x00, 0x33, 0x00, 0x37, 0x00, 0x33, 0x00, 0x42, 0x00,
394 0x30, 0x00, 0x43, 0x00, 0x36, 0x00, 0x41, 0x00, 0x44, 0x00, 0x37, 0x00,
395 0x44, 0x00, 0x44, 0x00, 0x45, 0x00, 0x34, 0x00, 0x33, 0x00, 0x37, 0x00,
396 0x00, 0x00, 0x00, 0x00
397};
398
399const unsigned char new_sms_pdu_valid_2[] = {
400 0x06, 0x91, 0x43, 0x06, 0x07, 0x30, 0xf0, 0x04, 0x0b, 0x91, 0x43, 0x36,
401 0x54, 0x39, 0x80, 0xf5, 0x00, 0x00, 0x31, 0x01, 0x13, 0x21, 0x20, 0x02,
402 0x40, 0x0a, 0xc8, 0x37, 0x3b, 0x0c, 0x6a, 0xd7, 0xdd, 0xe4, 0x37
403};
404
405static const struct sms_data testdata_new_sms_valid_2 = {
406 .start_func = trigger_new_sms,
407 .rtd = {
408 .req_data = unsol_response_new_sms_parcel_2,
409 .req_size = sizeof(unsol_response_new_sms_parcel_2),
410 .unsol_test = TRUE,
411 },
412 .pdu = new_sms_pdu_valid_2,
413 .pdu_len = sizeof(new_sms_pdu_valid_2),
414 .tpdu_len = 28,
415};
416
417/* Declarations && Re-implementations of core functions. */
418void ril_sms_exit(void);
419void ril_sms_init(void);
420
421struct ofono_sms {
422 void *driver_data;
423 const struct sms_data *sd;
424};
425
426struct ofono_sms *ofono_sms_create(struct ofono_modem *modem,
427 unsigned int vendor,
428 const char *driver,
429 void *data)
430{
431 struct rilmodem_sms_data *rsd = data;
432 struct ofono_sms *sms = g_new0(struct ofono_sms, 1);
433 int retval;
434
435 retval = smsdriver->probe(sms, OFONO_RIL_VENDOR_AOSP, rsd->ril);
436 g_assert(retval == 0);
437
438 return sms;
439}
440
441int ofono_sms_driver_register(const struct ofono_sms_driver *d)
442{
443 if (smsdriver == NULL)
444 smsdriver = d;
445
446 return 0;
447}
448
449void ofono_sms_set_data(struct ofono_sms *sms, void *data)
450{
451 sms->driver_data = data;
452}
453
454void *ofono_sms_get_data(struct ofono_sms *sms)
455{
456 return sms->driver_data;
457}
458
459void ofono_sms_register(struct ofono_sms *sms)
460{
461}
462
463void ofono_sms_driver_unregister(const struct ofono_sms_driver *d)
464{
465}
466
467void ofono_sms_deliver_notify(struct ofono_sms *sms, const unsigned char *pdu,
468 int len, int tpdu_len)
469{
470 g_assert(sms->sd->pdu_len == len);
471 g_assert(sms->sd->tpdu_len == tpdu_len);
472 g_assert(!memcmp(pdu, sms->sd->pdu, len));
473
474 g_main_loop_quit(mainloop);
475}
476
477void ofono_sms_status_notify(struct ofono_sms *sms, const unsigned char *pdu,
478 int len, int tpdu_len)
479{
480 ofono_sms_deliver_notify(sms, pdu, len, tpdu_len);
481}
482
483/*
484 * As all our architectures are little-endian except for
485 * PowerPC, and the Binder wire-format differs slightly
486 * depending on endian-ness, the following guards against test
487 * failures when run on PowerPC.
488 */
489#if BYTE_ORDER == LITTLE_ENDIAN
490
491static void server_connect_cb(gpointer data)
492{
493 struct rilmodem_sms_data *rsd = data;
494 const struct sms_data *sd = rsd->test_data;
495
496 /* This causes local impl of _create() to call driver's probe func. */
497 rsd->sms = ofono_sms_create(NULL, OFONO_RIL_VENDOR_AOSP,
498 "rilmodem", rsd);
499 rsd->sms->sd = sd;
500
501 /* add_idle doesn't work, read blocks main loop!!! */
502
503 if (sd->rtd.unsol_test)
504 g_idle_add(sd->start_func, (void *) rsd);
505 else
506 g_assert(sd->start_func(rsd) == FALSE);
507}
508
509/*
510 * This unit test:
511 * - does some test data setup
512 * - configures a dummy server socket
513 * - creates a new gril client instance
514 * - triggers a connect to the dummy
515 * server socket
516 * - starts a mainloop
517 */
518static void test_sms_func(gconstpointer data)
519{
520 const struct sms_data *sd = data;
521 struct rilmodem_sms_data *rsd;
522
523 ril_sms_init();
524
525 rsd = g_new0(struct rilmodem_sms_data, 1);
526
527 rsd->test_data = sd;
528
529 rsd->serverd = rilmodem_test_server_create(&server_connect_cb,
530 &sd->rtd, rsd);
531
532 rsd->ril = g_ril_new(rilmodem_test_get_socket_name(rsd->serverd),
533 OFONO_RIL_VENDOR_AOSP);
534 g_assert(rsd->ril != NULL);
535
536 mainloop = g_main_loop_new(NULL, FALSE);
537
538 g_main_loop_run(mainloop);
539 g_main_loop_unref(mainloop);
540
541 smsdriver->remove(rsd->sms);
542 g_ril_unref(rsd->ril);
543 g_free(rsd);
544
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches

to all changes: