Merge lp:~phablet-team/ofono/pro5-support-and-more into lp:~phablet-team/ofono/ubuntu
- pro5-support-and-more
- Merge into ubuntu
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 |
Related bugs: |
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
- 6913. By Alfonso Sanchez-Beato
-
Add libsystemd dependency
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote : | # |
Preview Diff
1 | === modified file '.gitignore' | |||
2 | --- .gitignore 2015-07-31 12:46:34 +0000 | |||
3 | +++ .gitignore 2016-03-14 09:03:03 +0000 | |||
4 | @@ -52,6 +52,9 @@ | |||
5 | 52 | unit/test-mtkreply | 52 | unit/test-mtkreply |
6 | 53 | unit/test-mtkrequest | 53 | unit/test-mtkrequest |
7 | 54 | unit/test-mtkunsol | 54 | unit/test-mtkunsol |
8 | 55 | unit/test-rilmodem-cs | ||
9 | 56 | unit/test-rilmodem-sms | ||
10 | 57 | unit/test-rilmodem-cb | ||
11 | 55 | unit/test-*.log | 58 | unit/test-*.log |
12 | 56 | unit/test-*.trs | 59 | unit/test-*.trs |
13 | 57 | 60 | ||
14 | 58 | 61 | ||
15 | === modified file 'Makefile.am' | |||
16 | --- Makefile.am 2016-01-15 16:03:09 +0000 | |||
17 | +++ Makefile.am 2016-03-14 09:03:03 +0000 | |||
18 | @@ -23,7 +23,8 @@ | |||
19 | 23 | include/cdma-provision.h include/handsfree.h \ | 23 | include/cdma-provision.h include/handsfree.h \ |
20 | 24 | include/handsfree-audio.h include/siri.h \ | 24 | include/handsfree-audio.h include/siri.h \ |
21 | 25 | include/sim-mnclength.h include/spn-table.h \ | 25 | include/sim-mnclength.h include/spn-table.h \ |
23 | 26 | include/dns-client.h include/wakelock.h | 26 | include/dns-client.h include/wakelock.h \ |
24 | 27 | include/system-settings.h | ||
25 | 27 | 28 | ||
26 | 28 | nodist_pkginclude_HEADERS = include/version.h | 29 | nodist_pkginclude_HEADERS = include/version.h |
27 | 29 | 30 | ||
28 | @@ -621,6 +622,14 @@ | |||
29 | 621 | builtin_sources += plugins/android-wakelock.c | 622 | builtin_sources += plugins/android-wakelock.c |
30 | 622 | endif | 623 | endif |
31 | 623 | 624 | ||
32 | 625 | if ACCOUNTSSETTINGS | ||
33 | 626 | builtin_modules += accounts_settings | ||
34 | 627 | builtin_sources += plugins/accounts-settings.c | ||
35 | 628 | |||
36 | 629 | builtin_cflags += @SYSTEMD_CFLAGS@ | ||
37 | 630 | builtin_libadd += @SYSTEMD_LIBS@ | ||
38 | 631 | endif | ||
39 | 632 | |||
40 | 624 | sbin_PROGRAMS = src/ofonod | 633 | sbin_PROGRAMS = src/ofonod |
41 | 625 | 634 | ||
42 | 626 | src_ofonod_SOURCES = $(builtin_sources) src/ofono.ver \ | 635 | src_ofonod_SOURCES = $(builtin_sources) src/ofono.ver \ |
43 | @@ -650,7 +659,8 @@ | |||
44 | 650 | src/handsfree-audio.c src/bluetooth.h \ | 659 | src/handsfree-audio.c src/bluetooth.h \ |
45 | 651 | src/hfp.h src/siri.c \ | 660 | src/hfp.h src/siri.c \ |
46 | 652 | src/sim-mnclength.c src/spn-table.c \ | 661 | src/sim-mnclength.c src/spn-table.c \ |
48 | 653 | src/dns-client.c src/wakelock.c | 662 | src/dns-client.c src/wakelock.c \ |
49 | 663 | src/system-settings.c | ||
50 | 654 | 664 | ||
51 | 655 | src_ofonod_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \ | 665 | src_ofonod_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \ |
52 | 656 | @GLIB_LIBS@ @DBUS_LIBS@ -ldl | 666 | @GLIB_LIBS@ @DBUS_LIBS@ -ldl |
53 | @@ -817,7 +827,9 @@ | |||
54 | 817 | unit/test-mtkrequest \ | 827 | unit/test-mtkrequest \ |
55 | 818 | unit/test-mtkreply \ | 828 | unit/test-mtkreply \ |
56 | 819 | unit/test-mtkunsol \ | 829 | unit/test-mtkunsol \ |
58 | 820 | unit/test-rilmodem-cs | 830 | unit/test-rilmodem-cs \ |
59 | 831 | unit/test-rilmodem-sms \ | ||
60 | 832 | unit/test-rilmodem-cb | ||
61 | 821 | 833 | ||
62 | 822 | noinst_PROGRAMS = $(unit_tests) \ | 834 | noinst_PROGRAMS = $(unit_tests) \ |
63 | 823 | unit/test-sms-root unit/test-mux unit/test-caif | 835 | unit/test-sms-root unit/test-mux unit/test-caif |
64 | @@ -913,14 +925,33 @@ | |||
65 | 913 | unit_test_mnclength_LDADD = @GLIB_LIBS@ -ldl | 925 | unit_test_mnclength_LDADD = @GLIB_LIBS@ -ldl |
66 | 914 | unit_objects += $(unit_test_mnclength_OBJECTS) | 926 | unit_objects += $(unit_test_mnclength_OBJECTS) |
67 | 915 | 927 | ||
72 | 916 | unit_test_rilmodem_cs_SOURCES = unit/test-rilmodem-cs.c $(gril_sources) \ | 928 | test_rilmodem_sources = $(gril_sources) src/log.c src/common.c src/util.c \ |
73 | 917 | src/log.c src/common.c src/util.c \ | 929 | gatchat/ringbuffer.h gatchat/ringbuffer.c \ |
74 | 918 | drivers/rilmodem/call-settings.c \ | 930 | unit/rilmodem-test-server.h \ |
75 | 919 | src/simutil.c gatchat/ringbuffer.c | 931 | unit/rilmodem-test-server.c \ |
76 | 932 | src/simutil.c | ||
77 | 933 | |||
78 | 934 | unit_test_rilmodem_cs_SOURCES = $(test_rilmodem_sources) \ | ||
79 | 935 | unit/test-rilmodem-cs.c \ | ||
80 | 936 | drivers/rilmodem/call-settings.c | ||
81 | 920 | unit_test_rilmodem_cs_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \ | 937 | unit_test_rilmodem_cs_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \ |
83 | 921 | @GLIB_LIBS@ @DBUS_LIBS@ -ldl | 938 | @GLIB_LIBS@ @DBUS_LIBS@ -ldl |
84 | 922 | unit_objects += $(unit_test_rilmodem_cs_OBJECTS) | 939 | unit_objects += $(unit_test_rilmodem_cs_OBJECTS) |
85 | 923 | 940 | ||
86 | 941 | unit_test_rilmodem_sms_SOURCES = $(test_rilmodem_sources) \ | ||
87 | 942 | unit/test-rilmodem-sms.c \ | ||
88 | 943 | drivers/rilmodem/sms.c | ||
89 | 944 | unit_test_rilmodem_sms_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \ | ||
90 | 945 | @GLIB_LIBS@ @DBUS_LIBS@ -ldl | ||
91 | 946 | unit_objects += $(unit_test_rilmodem_sms_OBJECTS) | ||
92 | 947 | |||
93 | 948 | unit_test_rilmodem_cb_SOURCES = $(test_rilmodem_sources) \ | ||
94 | 949 | unit/test-rilmodem-cb.c \ | ||
95 | 950 | drivers/rilmodem/call-barring.c | ||
96 | 951 | unit_test_rilmodem_cb_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \ | ||
97 | 952 | @GLIB_LIBS@ @DBUS_LIBS@ -ldl | ||
98 | 953 | unit_objects += $(unit_test_rilmodem_cb_OBJECTS) | ||
99 | 954 | |||
100 | 924 | TESTS = $(unit_tests) | 955 | TESTS = $(unit_tests) |
101 | 925 | 956 | ||
102 | 926 | if TOOLS | 957 | if TOOLS |
103 | 927 | 958 | ||
104 | === modified file 'configure.ac' | |||
105 | --- configure.ac 2016-01-15 16:03:09 +0000 | |||
106 | +++ configure.ac 2016-03-14 09:03:03 +0000 | |||
107 | @@ -200,6 +200,17 @@ | |||
108 | 200 | AC_SUBST(CARES_LIBS) | 200 | AC_SUBST(CARES_LIBS) |
109 | 201 | AM_CONDITIONAL(CARES, test "${enable_cares}" != "no") | 201 | AM_CONDITIONAL(CARES, test "${enable_cares}" != "no") |
110 | 202 | 202 | ||
111 | 203 | AC_ARG_ENABLE(accounts-settings, AC_HELP_STRING([--disable-accounts-settings], | ||
112 | 204 | [disable using accounts service for system settings]), | ||
113 | 205 | [enable_accounts_settings=${enableval}]) | ||
114 | 206 | if (test "${enable_accounts_settings=$}" != "no"); then | ||
115 | 207 | PKG_CHECK_MODULES(SYSTEMD, libsystemd, dummy=yes, | ||
116 | 208 | AC_MSG_ERROR(libsystemd is required)) | ||
117 | 209 | fi | ||
118 | 210 | AC_SUBST(SYSTEMD_CFLAGS) | ||
119 | 211 | AC_SUBST(SYSTEMD_LIBS) | ||
120 | 212 | AM_CONDITIONAL(ACCOUNTSSETTINGS, test "${enable_accounts_settings=$}" != "no") | ||
121 | 213 | |||
122 | 203 | AC_ARG_ENABLE(nettime, AC_HELP_STRING([--disable-nettime], | 214 | AC_ARG_ENABLE(nettime, AC_HELP_STRING([--disable-nettime], |
123 | 204 | [disable Nettime plugin]), | 215 | [disable Nettime plugin]), |
124 | 205 | [enable_nettime=${enableval}]) | 216 | [enable_nettime=${enableval}]) |
125 | 206 | 217 | ||
126 | === modified file 'debian/changelog' | |||
127 | --- debian/changelog 2016-01-15 17:37:10 +0000 | |||
128 | +++ debian/changelog 2016-03-14 09:03:03 +0000 | |||
129 | @@ -1,3 +1,26 @@ | |||
130 | 1 | ofono (1.17.bzr6912+16.04.20160314.1-0ubuntu1) UNRELEASED; urgency=medium | ||
131 | 2 | |||
132 | 3 | [ Tony Espy ] | ||
133 | 4 | * unit: new rilmodem tests for sms and call barring | ||
134 | 5 | * plugins: address upower plugin upstream comments | ||
135 | 6 | * unit: fix test-grilreply set_facility_lock test | ||
136 | 7 | * style fixes for wakelock support | ||
137 | 8 | |||
138 | 9 | [ Ratchanan Srirattanamet ] | ||
139 | 10 | * qcommsimmodem: fix setting 3G pref when one of the slots is empty | ||
140 | 11 | |||
141 | 12 | [ Alfonso Sanchez-Beato ] | ||
142 | 13 | * ril: set properly gril vendor | ||
143 | 14 | * support for system settings | ||
144 | 15 | * unit: make tests parallelizable | ||
145 | 16 | |||
146 | 17 | [ Vicamo Yang ] | ||
147 | 18 | * ril, gril: support for pro 5 | ||
148 | 19 | * gril, rilmodem: set RIL version from CONNECTED event | ||
149 | 20 | * unit: fix warning | ||
150 | 21 | |||
151 | 22 | -- Alfonso Sanchez-Beato (email Canonical) <alfonso.sanchez-beato@canonical.com> Mon, 14 Mar 2016 09:07:47 +0100 | ||
152 | 23 | |||
153 | 1 | ofono (1.17.bzr6910+16.04.20160115.3-0ubuntu1) xenial; urgency=medium | 24 | ofono (1.17.bzr6910+16.04.20160115.3-0ubuntu1) xenial; urgency=medium |
154 | 2 | 25 | ||
155 | 3 | [ Simon Fels ] | 26 | [ Simon Fels ] |
156 | 4 | 27 | ||
157 | === modified file 'debian/control' | |||
158 | --- debian/control 2015-07-01 07:00:40 +0000 | |||
159 | +++ debian/control 2016-03-14 09:03:03 +0000 | |||
160 | @@ -14,7 +14,8 @@ | |||
161 | 14 | udev, | 14 | udev, |
162 | 15 | libbluetooth-dev (>= 4.30), | 15 | libbluetooth-dev (>= 4.30), |
163 | 16 | mobile-broadband-provider-info, | 16 | mobile-broadband-provider-info, |
165 | 17 | libc-ares-dev | 17 | libc-ares-dev, |
166 | 18 | libsystemd-dev | ||
167 | 18 | Standards-Version: 3.9.4 | 19 | Standards-Version: 3.9.4 |
168 | 19 | Homepage: http://www.ofono.org/ | 20 | Homepage: http://www.ofono.org/ |
169 | 20 | # If you aren't a member of ~phablet-team but need to upload | 21 | # If you aren't a member of ~phablet-team but need to upload |
170 | 21 | 22 | ||
171 | === modified file 'drivers/qcommsimmodem/radio-settings.c' | |||
172 | --- drivers/qcommsimmodem/radio-settings.c 2015-07-31 13:44:26 +0000 | |||
173 | +++ drivers/qcommsimmodem/radio-settings.c 2016-03-14 09:03:03 +0000 | |||
174 | @@ -31,10 +31,12 @@ | |||
175 | 31 | #include <errno.h> | 31 | #include <errno.h> |
176 | 32 | 32 | ||
177 | 33 | #include <glib.h> | 33 | #include <glib.h> |
178 | 34 | #include <ofono.h> | ||
179 | 34 | 35 | ||
180 | 35 | #include <ofono/log.h> | 36 | #include <ofono/log.h> |
181 | 36 | #include <ofono/modem.h> | 37 | #include <ofono/modem.h> |
182 | 37 | #include <ofono/radio-settings.h> | 38 | #include <ofono/radio-settings.h> |
183 | 39 | #include <ofono/sim.h> | ||
184 | 38 | 40 | ||
185 | 39 | #include "gril.h" | 41 | #include "gril.h" |
186 | 40 | #include "grilrequest.h" | 42 | #include "grilrequest.h" |
187 | @@ -58,7 +60,6 @@ | |||
188 | 58 | }; | 60 | }; |
189 | 59 | 61 | ||
190 | 60 | static struct ofono_radio_settings *multisim_rs[QCOMMSIM_NUM_SLOTS_MAX]; | 62 | static struct ofono_radio_settings *multisim_rs[QCOMMSIM_NUM_SLOTS_MAX]; |
191 | 61 | static int multisim_num_slots; | ||
192 | 62 | 63 | ||
193 | 63 | static void qcom_msim_set_rat_cb(struct ril_msg *message, gpointer user_data) | 64 | static void qcom_msim_set_rat_cb(struct ril_msg *message, gpointer user_data) |
194 | 64 | { | 65 | { |
195 | @@ -76,6 +77,24 @@ | |||
196 | 76 | } | 77 | } |
197 | 77 | } | 78 | } |
198 | 78 | 79 | ||
199 | 80 | static void qcom_msim_do_set_rat_mode(struct ofono_radio_settings *rs, int pref, | ||
200 | 81 | struct cb_data *cbd) | ||
201 | 82 | { | ||
202 | 83 | struct radio_data *rd = ofono_radio_settings_get_data(rs); | ||
203 | 84 | struct parcel rilp; | ||
204 | 85 | ofono_radio_settings_rat_mode_set_cb_t cb; | ||
205 | 86 | |||
206 | 87 | g_ril_request_set_preferred_network_type(rd->ril, pref, &rilp); | ||
207 | 88 | |||
208 | 89 | if (g_ril_send(rd->ril, RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, | ||
209 | 90 | &rilp, qcom_msim_set_rat_cb, cbd, g_free) == 0) { | ||
210 | 91 | ofono_error("%s: unable to set rat mode", __func__); | ||
211 | 92 | cb = cbd->cb; | ||
212 | 93 | CALLBACK_WITH_FAILURE(cb, cbd->data); | ||
213 | 94 | g_free(cbd); | ||
214 | 95 | } | ||
215 | 96 | } | ||
216 | 97 | |||
217 | 79 | static void qcom_msim_set_2g_rat_cb(struct ril_msg *message, | 98 | static void qcom_msim_set_2g_rat_cb(struct ril_msg *message, |
218 | 80 | gpointer user_data) | 99 | gpointer user_data) |
219 | 81 | { | 100 | { |
220 | @@ -84,7 +103,6 @@ | |||
221 | 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; |
222 | 85 | struct radio_data *rd = ofono_radio_settings_get_data(rs); | 104 | struct radio_data *rd = ofono_radio_settings_get_data(rs); |
223 | 86 | ofono_radio_settings_rat_mode_set_cb_t cb; | 105 | ofono_radio_settings_rat_mode_set_cb_t cb; |
224 | 87 | struct parcel rilp; | ||
225 | 88 | 106 | ||
226 | 89 | pps->pending_gsm_pref_remaining -= 1; | 107 | pps->pending_gsm_pref_remaining -= 1; |
227 | 90 | 108 | ||
228 | @@ -104,23 +122,8 @@ | |||
229 | 104 | } | 122 | } |
230 | 105 | 123 | ||
231 | 106 | if (pps->pending_gsm_pref_remaining == 0) { | 124 | if (pps->pending_gsm_pref_remaining == 0) { |
249 | 107 | if (pps->cbd != NULL) { | 125 | if (pps->cbd != NULL) |
250 | 108 | struct radio_data *pps_rd = | 126 | qcom_msim_do_set_rat_mode(pps->rs, pps->pref, pps->cbd); |
234 | 109 | ofono_radio_settings_get_data(pps->rs); | ||
235 | 110 | g_ril_request_set_preferred_network_type(pps_rd->ril, | ||
236 | 111 | pps->pref, &rilp); | ||
237 | 112 | |||
238 | 113 | if (g_ril_send(pps_rd->ril, | ||
239 | 114 | RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, | ||
240 | 115 | &rilp, qcom_msim_set_rat_cb, pps->cbd, | ||
241 | 116 | g_free) == 0) { | ||
242 | 117 | ofono_error("%s: unable to set rat mode", | ||
243 | 118 | __func__); | ||
244 | 119 | cb = pps->cbd->cb; | ||
245 | 120 | CALLBACK_WITH_FAILURE(cb, pps->cbd->data); | ||
246 | 121 | g_free(pps->cbd); | ||
247 | 122 | } | ||
248 | 123 | } | ||
251 | 124 | 127 | ||
252 | 125 | g_free(pps); | 128 | g_free(pps); |
253 | 126 | } | 129 | } |
254 | @@ -131,10 +134,10 @@ | |||
255 | 131 | ofono_radio_settings_rat_mode_set_cb_t cb, | 134 | ofono_radio_settings_rat_mode_set_cb_t cb, |
256 | 132 | void *data) | 135 | void *data) |
257 | 133 | { | 136 | { |
258 | 134 | struct radio_data *rd = ofono_radio_settings_get_data(rs); | ||
259 | 135 | struct cb_data *cbd = cb_data_new(cb, data, rs); | 137 | struct cb_data *cbd = cb_data_new(cb, data, rs); |
260 | 136 | struct parcel rilp; | 138 | struct parcel rilp; |
261 | 137 | int pref = PREF_NET_TYPE_GSM_WCDMA; | 139 | int pref = PREF_NET_TYPE_GSM_WCDMA; |
262 | 140 | struct qcom_msim_pending_pref_setting *pps = NULL; | ||
263 | 138 | 141 | ||
264 | 139 | switch (mode) { | 142 | switch (mode) { |
265 | 140 | case OFONO_RADIO_ACCESS_MODE_ANY: | 143 | case OFONO_RADIO_ACCESS_MODE_ANY: |
266 | @@ -151,24 +154,43 @@ | |||
267 | 151 | break; | 154 | break; |
268 | 152 | } | 155 | } |
269 | 153 | 156 | ||
273 | 154 | if (pref != PREF_NET_TYPE_GSM_ONLY && multisim_num_slots > 1) { | 157 | if (pref != PREF_NET_TYPE_GSM_ONLY) { |
271 | 155 | struct qcom_msim_pending_pref_setting *pps = | ||
272 | 156 | g_try_new0(struct qcom_msim_pending_pref_setting, 1); | ||
274 | 157 | int i; | 158 | int i; |
275 | 158 | |||
276 | 159 | pps->rs = rs; | ||
277 | 160 | pps->pref = pref; | ||
278 | 161 | pps->cbd = cbd; | ||
279 | 162 | pps->pending_gsm_pref_remaining = 0; | ||
280 | 163 | |||
281 | 164 | for (i = 0; i < QCOMMSIM_NUM_SLOTS_MAX; i++) { | 159 | for (i = 0; i < QCOMMSIM_NUM_SLOTS_MAX; i++) { |
282 | 165 | struct radio_data *temp_rd; | 160 | struct radio_data *temp_rd; |
283 | 166 | struct qcom_msim_set_2g_rat *set_2g_rat_data; | 161 | struct qcom_msim_set_2g_rat *set_2g_rat_data; |
284 | 162 | struct ofono_atom *sim_atom; | ||
285 | 163 | struct ofono_sim *sim; | ||
286 | 167 | 164 | ||
287 | 168 | if (multisim_rs[i] == rs || multisim_rs[i] == NULL) | 165 | if (multisim_rs[i] == rs || multisim_rs[i] == NULL) |
288 | 169 | continue; | 166 | continue; |
289 | 170 | 167 | ||
290 | 171 | temp_rd = ofono_radio_settings_get_data(multisim_rs[i]); | 168 | temp_rd = ofono_radio_settings_get_data(multisim_rs[i]); |
291 | 169 | sim_atom = __ofono_modem_find_atom(temp_rd->modem, | ||
292 | 170 | OFONO_ATOM_TYPE_SIM); | ||
293 | 171 | if (sim_atom == NULL) { | ||
294 | 172 | if (pps != NULL) | ||
295 | 173 | pps->cbd = NULL; | ||
296 | 174 | g_free(cbd); | ||
297 | 175 | CALLBACK_WITH_FAILURE(cb, data); | ||
298 | 176 | break; | ||
299 | 177 | } | ||
300 | 178 | |||
301 | 179 | sim = __ofono_atom_get_data(sim_atom); | ||
302 | 180 | if (ofono_sim_get_state(sim) == | ||
303 | 181 | OFONO_SIM_STATE_NOT_PRESENT) | ||
304 | 182 | continue; | ||
305 | 183 | |||
306 | 184 | if (pps == NULL) { | ||
307 | 185 | pps = g_try_new0( | ||
308 | 186 | struct qcom_msim_pending_pref_setting, | ||
309 | 187 | 1); | ||
310 | 188 | pps->rs = rs; | ||
311 | 189 | pps->pref = pref; | ||
312 | 190 | pps->cbd = cbd; | ||
313 | 191 | pps->pending_gsm_pref_remaining = 0; | ||
314 | 192 | } | ||
315 | 193 | |||
316 | 172 | set_2g_rat_data = | 194 | set_2g_rat_data = |
317 | 173 | g_try_new0(struct qcom_msim_set_2g_rat, 1); | 195 | g_try_new0(struct qcom_msim_set_2g_rat, 1); |
318 | 174 | set_2g_rat_data->pps = pps; | 196 | set_2g_rat_data->pps = pps; |
319 | @@ -192,20 +214,15 @@ | |||
320 | 192 | pps->pending_gsm_pref_remaining += 1; | 214 | pps->pending_gsm_pref_remaining += 1; |
321 | 193 | } | 215 | } |
322 | 194 | } | 216 | } |
337 | 195 | 217 | } | |
338 | 196 | if (pps->pending_gsm_pref_remaining == 0) | 218 | |
339 | 197 | g_free(pps); | 219 | if (pps && pps->pending_gsm_pref_remaining == 0) { |
340 | 198 | } else { | 220 | g_free(pps); |
341 | 199 | g_ril_request_set_preferred_network_type(rd->ril, pref, &rilp); | 221 | pps = NULL; |
342 | 200 | 222 | } | |
343 | 201 | if (g_ril_send(rd->ril, RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, | 223 | |
344 | 202 | &rilp, qcom_msim_set_rat_cb, cbd, | 224 | if (pps == NULL) |
345 | 203 | g_free) == 0) { | 225 | qcom_msim_do_set_rat_mode(rs, pref, cbd); |
332 | 204 | ofono_error("%s: unable to set rat mode", __func__); | ||
333 | 205 | g_free(cbd); | ||
334 | 206 | CALLBACK_WITH_FAILURE(cb, data); | ||
335 | 207 | } | ||
336 | 208 | } | ||
346 | 209 | } | 226 | } |
347 | 210 | 227 | ||
348 | 211 | static int qcom_msim_radio_settings_probe(struct ofono_radio_settings *rs, | 228 | static int qcom_msim_radio_settings_probe(struct ofono_radio_settings *rs, |
349 | @@ -229,7 +246,6 @@ | |||
350 | 229 | 246 | ||
351 | 230 | slot_id = ofono_modem_get_integer(rsd->modem, "Slot"); | 247 | slot_id = ofono_modem_get_integer(rsd->modem, "Slot"); |
352 | 231 | multisim_rs[slot_id] = rs; | 248 | multisim_rs[slot_id] = rs; |
353 | 232 | multisim_num_slots += 1; | ||
354 | 233 | 249 | ||
355 | 234 | return 0; | 250 | return 0; |
356 | 235 | } | 251 | } |
357 | @@ -240,7 +256,6 @@ | |||
358 | 240 | int slot_id = ofono_modem_get_integer(rd->modem, "Slot"); | 256 | int slot_id = ofono_modem_get_integer(rd->modem, "Slot"); |
359 | 241 | 257 | ||
360 | 242 | multisim_rs[slot_id] = NULL; | 258 | multisim_rs[slot_id] = NULL; |
361 | 243 | multisim_num_slots -= 1; | ||
362 | 244 | 259 | ||
363 | 245 | ofono_radio_settings_set_data(rs, NULL); | 260 | ofono_radio_settings_set_data(rs, NULL); |
364 | 246 | 261 | ||
365 | 247 | 262 | ||
366 | === modified file 'drivers/rilmodem/call-barring.c' | |||
367 | --- drivers/rilmodem/call-barring.c 2014-04-21 07:56:17 +0000 | |||
368 | +++ drivers/rilmodem/call-barring.c 2016-03-14 09:03:03 +0000 | |||
369 | @@ -105,8 +105,8 @@ | |||
370 | 105 | goto error; | 105 | goto error; |
371 | 106 | } | 106 | } |
372 | 107 | 107 | ||
375 | 108 | /* Just for printing return value */ | 108 | if (g_ril_reply_parse_set_facility_lock(bd->ril, message) < 0) |
376 | 109 | g_ril_reply_parse_set_facility_lock(bd->ril, message); | 109 | goto error; |
377 | 110 | 110 | ||
378 | 111 | CALLBACK_WITH_SUCCESS(cb, cbd->data); | 111 | CALLBACK_WITH_SUCCESS(cb, cbd->data); |
379 | 112 | return; | 112 | return; |
380 | 113 | 113 | ||
381 | === modified file 'drivers/rilmodem/sim.c' | |||
382 | --- drivers/rilmodem/sim.c 2015-10-07 07:14:11 +0000 | |||
383 | +++ drivers/rilmodem/sim.c 2016-03-14 09:03:03 +0000 | |||
384 | @@ -733,6 +733,12 @@ | |||
385 | 733 | struct reply_sim_status *status; | 733 | struct reply_sim_status *status; |
386 | 734 | guint search_index; | 734 | guint search_index; |
387 | 735 | 735 | ||
388 | 736 | if (message->error != RIL_E_SUCCESS) { | ||
389 | 737 | ofono_error("%s: RIL error %s", __func__, | ||
390 | 738 | ril_error_to_string(message->error)); | ||
391 | 739 | return; | ||
392 | 740 | } | ||
393 | 741 | |||
394 | 736 | status = g_ril_reply_parse_sim_status(sd->ril, message); | 742 | status = g_ril_reply_parse_sim_status(sd->ril, message); |
395 | 737 | if (status == NULL) { | 743 | if (status == NULL) { |
396 | 738 | ofono_error("%s: Cannot parse SIM status reply", __func__); | 744 | ofono_error("%s: Cannot parse SIM status reply", __func__); |
397 | 739 | 745 | ||
398 | === modified file 'drivers/rilmodem/sms.c' | |||
399 | --- drivers/rilmodem/sms.c 2014-04-15 23:42:56 +0000 | |||
400 | +++ drivers/rilmodem/sms.c 2016-03-14 09:03:03 +0000 | |||
401 | @@ -127,19 +127,17 @@ | |||
402 | 127 | static void ril_submit_sms_cb(struct ril_msg *message, gpointer user_data) | 127 | static void ril_submit_sms_cb(struct ril_msg *message, gpointer user_data) |
403 | 128 | { | 128 | { |
404 | 129 | struct cb_data *cbd = user_data; | 129 | struct cb_data *cbd = user_data; |
405 | 130 | struct ofono_error error; | ||
406 | 131 | ofono_sms_submit_cb_t cb = cbd->cb; | 130 | ofono_sms_submit_cb_t cb = cbd->cb; |
407 | 132 | struct sms_data *sd = cbd->user; | 131 | struct sms_data *sd = cbd->user; |
409 | 133 | int mr = 0; | 132 | int mr; |
410 | 134 | 133 | ||
416 | 135 | if (message->error == RIL_E_SUCCESS) { | 134 | if (message->error != RIL_E_SUCCESS) { |
417 | 136 | decode_ril_error(&error, "OK"); | 135 | CALLBACK_WITH_FAILURE(cb, 0, cbd->data); |
418 | 137 | mr = g_ril_reply_parse_sms_response(sd->ril, message); | 136 | return; |
414 | 138 | } else { | ||
415 | 139 | decode_ril_error(&error, "FAIL"); | ||
419 | 140 | } | 137 | } |
420 | 141 | 138 | ||
422 | 142 | cb(&error, mr, cbd->data); | 139 | mr = g_ril_reply_parse_sms_response(sd->ril, message); |
423 | 140 | CALLBACK_WITH_SUCCESS(cb, mr, cbd->data); | ||
424 | 143 | } | 141 | } |
425 | 144 | 142 | ||
426 | 145 | static void ril_cmgs(struct ofono_sms *sms, const unsigned char *pdu, | 143 | static void ril_cmgs(struct ofono_sms *sms, const unsigned char *pdu, |
427 | 146 | 144 | ||
428 | === modified file 'gril/gril.c' | |||
429 | --- gril/gril.c 2015-11-10 09:17:36 +0000 | |||
430 | +++ gril/gril.c 2016-03-14 09:03:03 +0000 | |||
431 | @@ -104,6 +104,7 @@ | |||
432 | 104 | int slot; | 104 | int slot; |
433 | 105 | GRilMsgIdToStrFunc req_to_string; | 105 | GRilMsgIdToStrFunc req_to_string; |
434 | 106 | GRilMsgIdToStrFunc unsol_to_string; | 106 | GRilMsgIdToStrFunc unsol_to_string; |
435 | 107 | int version; | ||
436 | 107 | }; | 108 | }; |
437 | 108 | 109 | ||
438 | 109 | struct _GRil { | 110 | struct _GRil { |
439 | @@ -1066,6 +1067,7 @@ | |||
440 | 1066 | ril->ref_count = 1; | 1067 | ril->ref_count = 1; |
441 | 1067 | 1068 | ||
442 | 1068 | ril->parent->vendor = vendor; | 1069 | ril->parent->vendor = vendor; |
443 | 1070 | ril->parent->version = RIL_VERSION_UNSPECIFIED; | ||
444 | 1069 | 1071 | ||
445 | 1070 | return ril; | 1072 | return ril; |
446 | 1071 | } | 1073 | } |
447 | @@ -1207,6 +1209,24 @@ | |||
448 | 1207 | return ril->parent->slot; | 1209 | return ril->parent->slot; |
449 | 1208 | } | 1210 | } |
450 | 1209 | 1211 | ||
451 | 1212 | gboolean g_ril_set_version(GRil *ril, int version) | ||
452 | 1213 | { | ||
453 | 1214 | if (ril == NULL || ril->parent == NULL || | ||
454 | 1215 | ril->parent->version != RIL_VERSION_UNSPECIFIED) | ||
455 | 1216 | return FALSE; | ||
456 | 1217 | |||
457 | 1218 | ril->parent->version = version; | ||
458 | 1219 | return TRUE; | ||
459 | 1220 | } | ||
460 | 1221 | |||
461 | 1222 | int g_ril_get_version(GRil *ril) | ||
462 | 1223 | { | ||
463 | 1224 | if (ril == NULL) | ||
464 | 1225 | return RIL_VERSION_UNSPECIFIED; | ||
465 | 1226 | |||
466 | 1227 | return ril->parent->version; | ||
467 | 1228 | } | ||
468 | 1229 | |||
469 | 1210 | gboolean g_ril_set_debugf(GRil *ril, | 1230 | gboolean g_ril_set_debugf(GRil *ril, |
470 | 1211 | GRilDebugFunc func, gpointer user_data) | 1231 | GRilDebugFunc func, gpointer user_data) |
471 | 1212 | { | 1232 | { |
472 | 1213 | 1233 | ||
473 | === modified file 'gril/gril.h' | |||
474 | --- gril/gril.h 2014-07-31 06:45:32 +0000 | |||
475 | +++ gril/gril.h 2016-03-14 09:03:03 +0000 | |||
476 | @@ -129,6 +129,9 @@ | |||
477 | 129 | int g_ril_get_slot(GRil *ril); | 129 | int g_ril_get_slot(GRil *ril); |
478 | 130 | gboolean g_ril_set_slot(GRil *ril, int slot); | 130 | gboolean g_ril_set_slot(GRil *ril, int slot); |
479 | 131 | 131 | ||
480 | 132 | int g_ril_get_version(GRil *ril); | ||
481 | 133 | gboolean g_ril_set_version(GRil *ril, int version); | ||
482 | 134 | |||
483 | 132 | /*! | 135 | /*! |
484 | 133 | * If the function is not NULL, then on every read/write from the GIOChannel | 136 | * If the function is not NULL, then on every read/write from the GIOChannel |
485 | 134 | * provided to GRil the logging function will be called with the | 137 | * provided to GRil the logging function will be called with the |
486 | 135 | 138 | ||
487 | === modified file 'gril/grilreply.c' | |||
488 | --- gril/grilreply.c 2015-10-23 07:09:51 +0000 | |||
489 | +++ gril/grilreply.c 2016-03-14 09:03:03 +0000 | |||
490 | @@ -1258,8 +1258,10 @@ | |||
491 | 1258 | g_ril_init_parcel(message, &rilp); | 1258 | g_ril_init_parcel(message, &rilp); |
492 | 1259 | 1259 | ||
493 | 1260 | /* mako reply has no payload for call barring */ | 1260 | /* mako reply has no payload for call barring */ |
496 | 1261 | if (parcel_data_avail(&rilp) == 0) | 1261 | if (parcel_data_avail(&rilp) == 0) { |
497 | 1262 | goto end; | 1262 | retries = 0; |
498 | 1263 | goto done; | ||
499 | 1264 | } | ||
500 | 1263 | 1265 | ||
501 | 1264 | numint = parcel_r_int32(&rilp); | 1266 | numint = parcel_r_int32(&rilp); |
502 | 1265 | if (numint != 1) { | 1267 | if (numint != 1) { |
503 | @@ -1271,13 +1273,19 @@ | |||
504 | 1271 | 1273 | ||
505 | 1272 | if (rilp.malformed) { | 1274 | if (rilp.malformed) { |
506 | 1273 | ofono_error("%s: malformed parcel", __func__); | 1275 | ofono_error("%s: malformed parcel", __func__); |
507 | 1276 | retries = -1; | ||
508 | 1274 | goto end; | 1277 | goto end; |
509 | 1275 | } | 1278 | } |
510 | 1276 | 1279 | ||
512 | 1277 | end: | 1280 | done: |
513 | 1278 | g_ril_append_print_buf(gril, "{%d}", retries); | 1281 | g_ril_append_print_buf(gril, "{%d}", retries); |
514 | 1279 | g_ril_print_response(gril, message); | 1282 | g_ril_print_response(gril, message); |
515 | 1280 | 1283 | ||
516 | 1284 | /* -1 indicates unknown; reset to 0 so as to not trigger failure */ | ||
517 | 1285 | if (retries == -1) | ||
518 | 1286 | retries = 0; | ||
519 | 1287 | |||
520 | 1288 | end: | ||
521 | 1281 | return retries; | 1289 | return retries; |
522 | 1282 | } | 1290 | } |
523 | 1283 | 1291 | ||
524 | 1284 | 1292 | ||
525 | === modified file 'gril/grilunsol.c' | |||
526 | --- gril/grilunsol.c 2015-09-29 08:47:19 +0000 | |||
527 | +++ gril/grilunsol.c 2016-03-14 09:03:03 +0000 | |||
528 | @@ -48,6 +48,30 @@ | |||
529 | 48 | */ | 48 | */ |
530 | 49 | #define MIN_NITZ_SIZE 17 | 49 | #define MIN_NITZ_SIZE 17 |
531 | 50 | 50 | ||
532 | 51 | int g_ril_unsol_parse_connected(GRil *gril, const struct ril_msg *message) | ||
533 | 52 | { | ||
534 | 53 | struct parcel rilp; | ||
535 | 54 | int size; | ||
536 | 55 | int version; | ||
537 | 56 | |||
538 | 57 | DBG(""); | ||
539 | 58 | |||
540 | 59 | g_ril_init_parcel(message, &rilp); | ||
541 | 60 | |||
542 | 61 | size = parcel_r_int32(&rilp); | ||
543 | 62 | version = parcel_r_int32(&rilp); | ||
544 | 63 | |||
545 | 64 | if (rilp.malformed) { | ||
546 | 65 | ofono_error("%s: malformed parcel", __func__); | ||
547 | 66 | version = RIL_VERSION_UNSPECIFIED; | ||
548 | 67 | } | ||
549 | 68 | |||
550 | 69 | g_ril_append_print_buf(gril, "{size:%d, [%d, ...]}", size, version); | ||
551 | 70 | g_ril_print_unsol(gril, message); | ||
552 | 71 | |||
553 | 72 | return version; | ||
554 | 73 | } | ||
555 | 74 | |||
556 | 51 | static gint data_call_compare(gconstpointer a, gconstpointer b) | 75 | static gint data_call_compare(gconstpointer a, gconstpointer b) |
557 | 52 | { | 76 | { |
558 | 53 | const struct ril_data_call *ca = a; | 77 | const struct ril_data_call *ca = a; |
559 | 54 | 78 | ||
560 | === modified file 'gril/grilunsol.h' | |||
561 | --- gril/grilunsol.h 2014-08-11 12:41:11 +0000 | |||
562 | +++ gril/grilunsol.h 2016-03-14 09:03:03 +0000 | |||
563 | @@ -64,6 +64,8 @@ | |||
564 | 64 | char *message; | 64 | char *message; |
565 | 65 | }; | 65 | }; |
566 | 66 | 66 | ||
567 | 67 | int g_ril_unsol_parse_connected(GRil *gril, const struct ril_msg *message); | ||
568 | 68 | |||
569 | 67 | void g_ril_unsol_free_data_call_list(struct ril_data_call_list *data_call_list); | 69 | void g_ril_unsol_free_data_call_list(struct ril_data_call_list *data_call_list); |
570 | 68 | 70 | ||
571 | 69 | 71 | ||
572 | 70 | 72 | ||
573 | === modified file 'gril/ril_constants.h' | |||
574 | --- gril/ril_constants.h 2015-02-18 13:54:39 +0000 | |||
575 | +++ gril/ril_constants.h 2016-03-14 09:03:03 +0000 | |||
576 | @@ -23,7 +23,8 @@ | |||
577 | 23 | 23 | ||
578 | 24 | #ifndef __RIL_CONSTANTS_H | 24 | #ifndef __RIL_CONSTANTS_H |
579 | 25 | #define __RIL_CONSTANTS_H 1 | 25 | #define __RIL_CONSTANTS_H 1 |
581 | 26 | #define RIL_VERSION 7 | 26 | |
582 | 27 | #define RIL_VERSION_UNSPECIFIED 0 | ||
583 | 27 | 28 | ||
584 | 28 | /* Error Codes */ | 29 | /* Error Codes */ |
585 | 29 | #define RIL_E_SUCCESS 0 | 30 | #define RIL_E_SUCCESS 0 |
586 | 30 | 31 | ||
587 | === modified file 'include/log.h' | |||
588 | --- include/log.h 2011-10-10 20:39:42 +0000 | |||
589 | +++ include/log.h 2016-03-14 09:03:03 +0000 | |||
590 | @@ -67,6 +67,8 @@ | |||
591 | 67 | __FILE__, __FUNCTION__ , ## arg); \ | 67 | __FILE__, __FUNCTION__ , ## arg); \ |
592 | 68 | } while (0) | 68 | } while (0) |
593 | 69 | 69 | ||
594 | 70 | #define PRINTABLE_STR(s) ((s) ? (s) : "(null)") | ||
595 | 71 | |||
596 | 70 | #ifdef __cplusplus | 72 | #ifdef __cplusplus |
597 | 71 | } | 73 | } |
598 | 72 | #endif | 74 | #endif |
599 | 73 | 75 | ||
600 | === added file 'include/system-settings.h' | |||
601 | --- include/system-settings.h 1970-01-01 00:00:00 +0000 | |||
602 | +++ include/system-settings.h 2016-03-14 09:03:03 +0000 | |||
603 | @@ -0,0 +1,51 @@ | |||
604 | 1 | /* | ||
605 | 2 | * | ||
606 | 3 | * oFono - Open Telephony stack for Linux | ||
607 | 4 | * | ||
608 | 5 | * Copyright (C) 2016 Canonical Ltd. | ||
609 | 6 | * | ||
610 | 7 | * This program is free software; you can redistribute it and/or modify | ||
611 | 8 | * it under the terms of the GNU General Public License version 2 as | ||
612 | 9 | * published by the Free Software Foundation. | ||
613 | 10 | * | ||
614 | 11 | * This program is distributed in the hope that it will be useful, | ||
615 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
616 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
617 | 14 | * GNU General Public License for more details. | ||
618 | 15 | * | ||
619 | 16 | * You should have received a copy of the GNU General Public License | ||
620 | 17 | * along with this program; if not, write to the Free Software | ||
621 | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
622 | 19 | * | ||
623 | 20 | */ | ||
624 | 21 | |||
625 | 22 | #ifndef OFONO_SYSTEM_SETTINGS_H | ||
626 | 23 | #define OFONO_SYSTEM_SETTINGS_H | ||
627 | 24 | |||
628 | 25 | #ifdef __cplusplus | ||
629 | 26 | extern "C" { | ||
630 | 27 | #endif | ||
631 | 28 | |||
632 | 29 | /* Settings names */ | ||
633 | 30 | #define PREFERRED_VOICE_MODEM "PreferredVoiceModem" | ||
634 | 31 | |||
635 | 32 | struct ofono_system_settings_driver { | ||
636 | 33 | const char *name; | ||
637 | 34 | /* The user must free the returned string */ | ||
638 | 35 | char *(*get_string_value)(const char *name); | ||
639 | 36 | }; | ||
640 | 37 | |||
641 | 38 | /* The user must free the returned string */ | ||
642 | 39 | char *__ofono_system_settings_get_string_value(const char *name); | ||
643 | 40 | |||
644 | 41 | int ofono_system_settings_driver_register( | ||
645 | 42 | struct ofono_system_settings_driver *driver); | ||
646 | 43 | |||
647 | 44 | void ofono_system_settings_driver_unregister( | ||
648 | 45 | const struct ofono_system_settings_driver *driver); | ||
649 | 46 | |||
650 | 47 | #ifdef __cplusplus | ||
651 | 48 | } | ||
652 | 49 | #endif | ||
653 | 50 | |||
654 | 51 | #endif /* OFONO_SYSTEM_SETTINGS_H */ | ||
655 | 0 | 52 | ||
656 | === added file 'include/wakelock.h' | |||
657 | --- include/wakelock.h 1970-01-01 00:00:00 +0000 | |||
658 | +++ include/wakelock.h 2016-03-14 09:03:03 +0000 | |||
659 | @@ -0,0 +1,100 @@ | |||
660 | 1 | /* | ||
661 | 2 | * | ||
662 | 3 | * oFono - Open Source Telephony | ||
663 | 4 | * | ||
664 | 5 | * Copyright (C) 2015 Jolla Ltd. All rights reserved. | ||
665 | 6 | * Contact: Hannu Mallat <hannu.mallat@jollamobile.com> | ||
666 | 7 | * | ||
667 | 8 | * This program is free software; you can redistribute it and/or modify | ||
668 | 9 | * it under the terms of the GNU General Public License as published by | ||
669 | 10 | * the Free Software Foundation; either version 2 of the License, or | ||
670 | 11 | * (at your option) any later version. | ||
671 | 12 | * | ||
672 | 13 | * This program is distributed in the hope that it will be useful, | ||
673 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
674 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
675 | 16 | * GNU General Public License for more details. | ||
676 | 17 | * | ||
677 | 18 | * You should have received a copy of the GNU General Public License | ||
678 | 19 | * along with this program; if not, write to the Free Software | ||
679 | 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
680 | 21 | * | ||
681 | 22 | */ | ||
682 | 23 | |||
683 | 24 | #ifndef __OFONO_WAKELOCK_H_ | ||
684 | 25 | #define __OFONO_WAKELOCK_H_ | ||
685 | 26 | |||
686 | 27 | #include <ofono/types.h> | ||
687 | 28 | |||
688 | 29 | /* Wakelock interface | ||
689 | 30 | * | ||
690 | 31 | * Wakelocks ensure system does not suspend/enter power save mode | ||
691 | 32 | * before an ongoing operation completes. This header declares a | ||
692 | 33 | * wakelock API that can be implemented by a OS-specific plugin. | ||
693 | 34 | */ | ||
694 | 35 | |||
695 | 36 | struct wakelock; /* Opaque */ | ||
696 | 37 | |||
697 | 38 | struct wakelock_table { | ||
698 | 39 | int (*create)(const char *name, struct wakelock **); | ||
699 | 40 | int (*free)(struct wakelock *); | ||
700 | 41 | int (*acquire)(struct wakelock *); | ||
701 | 42 | int (*release)(struct wakelock *); | ||
702 | 43 | ofono_bool_t (*is_locked)(struct wakelock *); | ||
703 | 44 | }; | ||
704 | 45 | |||
705 | 46 | |||
706 | 47 | /*** Functions for wakelock users ***/ | ||
707 | 48 | |||
708 | 49 | /* | ||
709 | 50 | * This will create a wakelock which will be held for a short duration | ||
710 | 51 | * and then automatically freed. If this is called multiple times the | ||
711 | 52 | * timeout will be restarted on every call. | ||
712 | 53 | */ | ||
713 | 54 | void wakelock_system_lock(void); | ||
714 | 55 | |||
715 | 56 | /* | ||
716 | 57 | * Create a wakelock. Multiple wakelocks can be created; if any one of | ||
717 | 58 | * them is activated, system will be prevented from going to suspend. | ||
718 | 59 | * This makes it possible to overlap locks to hand over from subsystem | ||
719 | 60 | * to subsystem, each with their own wakelock-guarded sections, | ||
720 | 61 | * without falling to suspend in between. | ||
721 | 62 | */ | ||
722 | 63 | int wakelock_create(const char *name, struct wakelock **wakelock); | ||
723 | 64 | |||
724 | 65 | /* | ||
725 | 66 | * Free a wakelock, releasing all acquisitions at the same time | ||
726 | 67 | * and deallocating the lock. | ||
727 | 68 | */ | ||
728 | 69 | int wakelock_free(struct wakelock *wakelock); | ||
729 | 70 | |||
730 | 71 | /* | ||
731 | 72 | * Acquire a wakelock. Multiple acquisitions are possible, meaning | ||
732 | 73 | * that the wakelock needs to be released the same number of times | ||
733 | 74 | * until it is actually deactivated. | ||
734 | 75 | */ | ||
735 | 76 | int wakelock_acquire(struct wakelock *wakelock); | ||
736 | 77 | |||
737 | 78 | /* | ||
738 | 79 | * Release a wakelock, deactivating it if all acquisitions are | ||
739 | 80 | * released, letting system suspend. | ||
740 | 81 | */ | ||
741 | 82 | int wakelock_release(struct wakelock *wakelock); | ||
742 | 83 | |||
743 | 84 | /* | ||
744 | 85 | * Check if a wakelock is currently locked or not. | ||
745 | 86 | */ | ||
746 | 87 | ofono_bool_t wakelock_is_locked(struct wakelock *wakelock); | ||
747 | 88 | |||
748 | 89 | /*** Functions for wakelock implementors ***/ | ||
749 | 90 | |||
750 | 91 | /* | ||
751 | 92 | * Register a wakelock implementation. Only one implementation may be | ||
752 | 93 | * registered at a time. In the absence of an implementation, all | ||
753 | 94 | * wakelock functions are no-ops. | ||
754 | 95 | */ | ||
755 | 96 | int wakelock_plugin_register(const char *name, struct wakelock_table *fns); | ||
756 | 97 | |||
757 | 98 | int wakelock_plugin_unregister(void); | ||
758 | 99 | |||
759 | 100 | #endif | ||
760 | 0 | 101 | ||
761 | === removed file 'include/wakelock.h' | |||
762 | --- include/wakelock.h 2016-01-15 16:03:09 +0000 | |||
763 | +++ include/wakelock.h 1970-01-01 00:00:00 +0000 | |||
764 | @@ -1,100 +0,0 @@ | |||
765 | 1 | /* | ||
766 | 2 | * | ||
767 | 3 | * oFono - Open Source Telephony | ||
768 | 4 | * | ||
769 | 5 | * Copyright (C) 2015 Jolla Ltd. All rights reserved. | ||
770 | 6 | * Contact: Hannu Mallat <hannu.mallat@jollamobile.com> | ||
771 | 7 | * | ||
772 | 8 | * This program is free software; you can redistribute it and/or modify | ||
773 | 9 | * it under the terms of the GNU General Public License as published by | ||
774 | 10 | * the Free Software Foundation; either version 2 of the License, or | ||
775 | 11 | * (at your option) any later version. | ||
776 | 12 | * | ||
777 | 13 | * This program is distributed in the hope that it will be useful, | ||
778 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
779 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
780 | 16 | * GNU General Public License for more details. | ||
781 | 17 | * | ||
782 | 18 | * You should have received a copy of the GNU General Public License | ||
783 | 19 | * along with this program; if not, write to the Free Software | ||
784 | 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
785 | 21 | * | ||
786 | 22 | */ | ||
787 | 23 | |||
788 | 24 | #ifndef __OFONO_WAKELOCK_H_ | ||
789 | 25 | #define __OFONO_WAKELOCK_H_ | ||
790 | 26 | |||
791 | 27 | #include <ofono/types.h> | ||
792 | 28 | |||
793 | 29 | /* Wakelock interface | ||
794 | 30 | * | ||
795 | 31 | * Wakelocks ensure system does not suspend/enter power save mode | ||
796 | 32 | * before an ongoing operation completes. This header declares a | ||
797 | 33 | * wakelock API that can be implemented by a OS-specific plugin. | ||
798 | 34 | */ | ||
799 | 35 | |||
800 | 36 | struct wakelock; /* Opaque */ | ||
801 | 37 | |||
802 | 38 | struct wakelock_table { | ||
803 | 39 | int (*create)(const char *name, struct wakelock **); | ||
804 | 40 | int (*free)(struct wakelock *); | ||
805 | 41 | int (*acquire)(struct wakelock *); | ||
806 | 42 | int (*release)(struct wakelock *); | ||
807 | 43 | ofono_bool_t (*is_locked)(struct wakelock *); | ||
808 | 44 | }; | ||
809 | 45 | |||
810 | 46 | |||
811 | 47 | /*** Functions for wakelock users ***/ | ||
812 | 48 | |||
813 | 49 | /* | ||
814 | 50 | * This will create a wakelock which will be held for a short duration | ||
815 | 51 | * and then automatically freed. If this is called multiple times the | ||
816 | 52 | * timeout will be restarted on every call. | ||
817 | 53 | */ | ||
818 | 54 | void wakelock_system_lock(void); | ||
819 | 55 | |||
820 | 56 | /* | ||
821 | 57 | * Create a wakelock. Multiple wakelocks can be created; if any one of | ||
822 | 58 | * them is activated, system will be prevented from going to suspend. | ||
823 | 59 | * This makes it possible to overlap locks to hand over from subsystem | ||
824 | 60 | * to subsystem, each with their own wakelock-guarded sections, | ||
825 | 61 | * without falling to suspend in between. | ||
826 | 62 | */ | ||
827 | 63 | int wakelock_create(const char *name, struct wakelock **wakelock); | ||
828 | 64 | |||
829 | 65 | /* | ||
830 | 66 | * Free a wakelock, releasing all acquisitions at the same time | ||
831 | 67 | * and deallocating the lock. | ||
832 | 68 | */ | ||
833 | 69 | int wakelock_free(struct wakelock *wakelock); | ||
834 | 70 | |||
835 | 71 | /* | ||
836 | 72 | * Acquire a wakelock. Multiple acquisitions are possible, meaning | ||
837 | 73 | * that the wakelock needs to be released the same number of times | ||
838 | 74 | * until it is actually deactivated. | ||
839 | 75 | */ | ||
840 | 76 | int wakelock_acquire(struct wakelock *wakelock); | ||
841 | 77 | |||
842 | 78 | /* | ||
843 | 79 | * Release a wakelock, deactivating it if all acquisitions are | ||
844 | 80 | * released, letting system suspend. | ||
845 | 81 | */ | ||
846 | 82 | int wakelock_release(struct wakelock *wakelock); | ||
847 | 83 | |||
848 | 84 | /* | ||
849 | 85 | * Check if a wakelock is currently locked or not. | ||
850 | 86 | */ | ||
851 | 87 | ofono_bool_t wakelock_is_locked(struct wakelock *wakelock); | ||
852 | 88 | |||
853 | 89 | /*** Functions for wakelock implementors ***/ | ||
854 | 90 | |||
855 | 91 | /* | ||
856 | 92 | * Register a wakelock implementation. Only one implementation may be | ||
857 | 93 | * registered at a time. In the absence of an implementation, all | ||
858 | 94 | * wakelock functions are no-ops. | ||
859 | 95 | */ | ||
860 | 96 | int wakelock_plugin_register(const char *name, struct wakelock_table *fns); | ||
861 | 97 | |||
862 | 98 | int wakelock_plugin_unregister(void); | ||
863 | 99 | |||
864 | 100 | #endif | ||
865 | 101 | 0 | ||
866 | === added file 'plugins/accounts-settings.c' | |||
867 | --- plugins/accounts-settings.c 1970-01-01 00:00:00 +0000 | |||
868 | +++ plugins/accounts-settings.c 2016-03-14 09:03:03 +0000 | |||
869 | @@ -0,0 +1,474 @@ | |||
870 | 1 | /* | ||
871 | 2 | * | ||
872 | 3 | * oFono - Open Source Telephony | ||
873 | 4 | * | ||
874 | 5 | * Copyright (C) 2016 Canonical Ltd. | ||
875 | 6 | * | ||
876 | 7 | * This program is free software; you can redistribute it and/or modify | ||
877 | 8 | * it under the terms of the GNU General Public License version 2 as | ||
878 | 9 | * published by the Free Software Foundation. | ||
879 | 10 | * | ||
880 | 11 | * This program is distributed in the hope that it will be useful, | ||
881 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
882 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
883 | 14 | * GNU General Public License for more details. | ||
884 | 15 | * | ||
885 | 16 | * You should have received a copy of the GNU General Public License | ||
886 | 17 | * along with this program; if not, write to the Free Software | ||
887 | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
888 | 19 | * | ||
889 | 20 | */ | ||
890 | 21 | |||
891 | 22 | #ifdef HAVE_CONFIG_H | ||
892 | 23 | #include <config.h> | ||
893 | 24 | #endif | ||
894 | 25 | |||
895 | 26 | #include <stdlib.h> | ||
896 | 27 | #include <string.h> | ||
897 | 28 | #include <stdio.h> | ||
898 | 29 | |||
899 | 30 | #include <sys/types.h> | ||
900 | 31 | #include <pwd.h> | ||
901 | 32 | #include <errno.h> | ||
902 | 33 | #include <unistd.h> | ||
903 | 34 | |||
904 | 35 | #include <glib.h> | ||
905 | 36 | #include <gdbus.h> | ||
906 | 37 | #include <systemd/sd-login.h> | ||
907 | 38 | |||
908 | 39 | #include <ofono.h> | ||
909 | 40 | |||
910 | 41 | #define OFONO_API_SUBJECT_TO_CHANGE | ||
911 | 42 | #include <ofono/types.h> | ||
912 | 43 | #include <ofono/log.h> | ||
913 | 44 | #include <ofono/plugin.h> | ||
914 | 45 | #include <ofono/system-settings.h> | ||
915 | 46 | |||
916 | 47 | #define ACCOUNTS_SERVICE "org.freedesktop.Accounts" | ||
917 | 48 | #define ACCOUNTS_PATH "/org/freedesktop/Accounts/User" | ||
918 | 49 | #define ACCOUNTS_PHONE_INTERFACE "com.ubuntu.touch.AccountsService.Phone" | ||
919 | 50 | #define DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties" | ||
920 | 51 | |||
921 | 52 | struct setting { | ||
922 | 53 | char* ofono_name; | ||
923 | 54 | char* property_name; | ||
924 | 55 | }; | ||
925 | 56 | |||
926 | 57 | static const struct setting setting_names[] = { | ||
927 | 58 | { PREFERRED_VOICE_MODEM, "DefaultSimForCalls" } | ||
928 | 59 | }; | ||
929 | 60 | |||
930 | 61 | #define NUM_SETTINGS G_N_ELEMENTS(setting_names) | ||
931 | 62 | |||
932 | 63 | struct accounts_data { | ||
933 | 64 | sd_login_monitor *login_monitor; | ||
934 | 65 | guint login_watch; | ||
935 | 66 | char *property_values[NUM_SETTINGS]; | ||
936 | 67 | uid_t current_uid; | ||
937 | 68 | guint prop_change_watch; | ||
938 | 69 | char uid_path[sizeof(ACCOUNTS_PATH) + 32]; | ||
939 | 70 | }; | ||
940 | 71 | |||
941 | 72 | static struct accounts_data g_accounts; | ||
942 | 73 | |||
943 | 74 | static int translate_name(const char *name) | ||
944 | 75 | { | ||
945 | 76 | size_t i; | ||
946 | 77 | |||
947 | 78 | for (i = 0; i < NUM_SETTINGS; ++i) { | ||
948 | 79 | if (g_strcmp0(setting_names[i].ofono_name, name) != 0) | ||
949 | 80 | continue; | ||
950 | 81 | |||
951 | 82 | return i; | ||
952 | 83 | } | ||
953 | 84 | |||
954 | 85 | return -1; | ||
955 | 86 | } | ||
956 | 87 | |||
957 | 88 | static char *accounts_settings_get_string_value(const char *name) | ||
958 | 89 | { | ||
959 | 90 | int id; | ||
960 | 91 | |||
961 | 92 | id = translate_name(name); | ||
962 | 93 | if (id < 0) | ||
963 | 94 | return NULL; | ||
964 | 95 | |||
965 | 96 | return g_strdup(g_accounts.property_values[id]); | ||
966 | 97 | } | ||
967 | 98 | |||
968 | 99 | static struct ofono_system_settings_driver accounts_settings_driver = { | ||
969 | 100 | .name = "Accounts Service System Settings", | ||
970 | 101 | .get_string_value = accounts_settings_get_string_value | ||
971 | 102 | }; | ||
972 | 103 | |||
973 | 104 | static int get_id_from_name(const char *name) | ||
974 | 105 | { | ||
975 | 106 | size_t i; | ||
976 | 107 | |||
977 | 108 | for (i = 0; i < NUM_SETTINGS; ++i) { | ||
978 | 109 | if (g_strcmp0(setting_names[i].property_name, name) != 0) | ||
979 | 110 | continue; | ||
980 | 111 | |||
981 | 112 | return i; | ||
982 | 113 | } | ||
983 | 114 | |||
984 | 115 | return -1; | ||
985 | 116 | } | ||
986 | 117 | |||
987 | 118 | static char *get_property_value(DBusMessage *reply) | ||
988 | 119 | { | ||
989 | 120 | DBusMessageIter iter, val; | ||
990 | 121 | const char *ptr; | ||
991 | 122 | char *property = NULL; | ||
992 | 123 | |||
993 | 124 | if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { | ||
994 | 125 | ofono_error("%s: ERROR reply to Get", __func__); | ||
995 | 126 | goto done; | ||
996 | 127 | } | ||
997 | 128 | |||
998 | 129 | if (dbus_message_iter_init(reply, &iter) == FALSE) { | ||
999 | 130 | ofono_error("%s: error initializing array iter", __func__); | ||
1000 | 131 | goto done; | ||
1001 | 132 | } | ||
1002 | 133 | |||
1003 | 134 | if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) { | ||
1004 | 135 | ofono_error("%s: type != VARIANT!", __func__); | ||
1005 | 136 | goto done; | ||
1006 | 137 | } | ||
1007 | 138 | |||
1008 | 139 | dbus_message_iter_recurse(&iter, &val); | ||
1009 | 140 | |||
1010 | 141 | if (dbus_message_iter_get_arg_type(&val) != DBUS_TYPE_STRING) { | ||
1011 | 142 | ofono_error("%s: type != STRING!", __func__); | ||
1012 | 143 | goto done; | ||
1013 | 144 | } | ||
1014 | 145 | |||
1015 | 146 | dbus_message_iter_get_basic(&val, &ptr); | ||
1016 | 147 | |||
1017 | 148 | property = g_strdup(ptr); | ||
1018 | 149 | |||
1019 | 150 | done: | ||
1020 | 151 | return property; | ||
1021 | 152 | } | ||
1022 | 153 | |||
1023 | 154 | struct get_property_data { | ||
1024 | 155 | struct accounts_data *accounts; | ||
1025 | 156 | int prop_id; | ||
1026 | 157 | }; | ||
1027 | 158 | |||
1028 | 159 | static void get_property_reply(DBusPendingCall *call, void *user_data) | ||
1029 | 160 | { | ||
1030 | 161 | DBusMessage *reply; | ||
1031 | 162 | struct get_property_data *gpd = user_data; | ||
1032 | 163 | char **values = gpd->accounts->property_values; | ||
1033 | 164 | int id = gpd->prop_id; | ||
1034 | 165 | |||
1035 | 166 | reply = dbus_pending_call_steal_reply(call); | ||
1036 | 167 | if (reply == NULL) { | ||
1037 | 168 | ofono_error("%s: failed to get reply", __func__); | ||
1038 | 169 | goto done; | ||
1039 | 170 | } | ||
1040 | 171 | |||
1041 | 172 | g_free(values[id]); | ||
1042 | 173 | values[id] = get_property_value(reply); | ||
1043 | 174 | dbus_message_unref(reply); | ||
1044 | 175 | |||
1045 | 176 | DBG("property %s has value %s", | ||
1046 | 177 | setting_names[id].property_name, PRINTABLE_STR(values[id])); | ||
1047 | 178 | |||
1048 | 179 | done: | ||
1049 | 180 | dbus_pending_call_unref(call); | ||
1050 | 181 | g_free(gpd); | ||
1051 | 182 | } | ||
1052 | 183 | |||
1053 | 184 | static void get_property(struct accounts_data *accounts, int id) | ||
1054 | 185 | { | ||
1055 | 186 | DBusMessageIter iter; | ||
1056 | 187 | DBusMessage *msg; | ||
1057 | 188 | const char *iface = ACCOUNTS_PHONE_INTERFACE; | ||
1058 | 189 | DBusConnection *conn = ofono_dbus_get_connection(); | ||
1059 | 190 | DBusPendingCall *call; | ||
1060 | 191 | struct get_property_data *gpd; | ||
1061 | 192 | |||
1062 | 193 | msg = dbus_message_new_method_call(ACCOUNTS_SERVICE, accounts->uid_path, | ||
1063 | 194 | DBUS_PROPERTIES_INTERFACE, | ||
1064 | 195 | "Get"); | ||
1065 | 196 | if (msg == NULL) { | ||
1066 | 197 | ofono_error("%s: dbus_message_new_method failed", __func__); | ||
1067 | 198 | return; | ||
1068 | 199 | } | ||
1069 | 200 | |||
1070 | 201 | dbus_message_iter_init_append(msg, &iter); | ||
1071 | 202 | dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &iface); | ||
1072 | 203 | dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, | ||
1073 | 204 | &setting_names[id].property_name); | ||
1074 | 205 | |||
1075 | 206 | if (!dbus_connection_send_with_reply(conn, msg, &call, -1)) { | ||
1076 | 207 | ofono_error("%s: Sending Get failed", __func__); | ||
1077 | 208 | goto done; | ||
1078 | 209 | } | ||
1079 | 210 | |||
1080 | 211 | gpd = g_malloc0(sizeof(*gpd)); | ||
1081 | 212 | gpd->accounts = accounts; | ||
1082 | 213 | gpd->prop_id = id; | ||
1083 | 214 | dbus_pending_call_set_notify(call, get_property_reply, gpd, NULL); | ||
1084 | 215 | |||
1085 | 216 | done: | ||
1086 | 217 | dbus_message_unref(msg); | ||
1087 | 218 | } | ||
1088 | 219 | |||
1089 | 220 | static gboolean property_changed(DBusConnection *conn, | ||
1090 | 221 | DBusMessage *msg, void *user_data) | ||
1091 | 222 | { | ||
1092 | 223 | struct accounts_data *accounts = user_data; | ||
1093 | 224 | const char *iface; | ||
1094 | 225 | DBusMessageIter iter, dict, inv_it; | ||
1095 | 226 | |||
1096 | 227 | dbus_message_iter_init(msg, &iter); | ||
1097 | 228 | |||
1098 | 229 | if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) { | ||
1099 | 230 | ofono_error("%s: iface != TYPE_STRING!", __func__); | ||
1100 | 231 | goto done; | ||
1101 | 232 | } | ||
1102 | 233 | |||
1103 | 234 | dbus_message_iter_get_basic(&iter, &iface); | ||
1104 | 235 | |||
1105 | 236 | /* We can receive notifications from other AccountsService interfaces */ | ||
1106 | 237 | if (g_str_equal(iface, ACCOUNTS_PHONE_INTERFACE) != TRUE) | ||
1107 | 238 | goto done; | ||
1108 | 239 | |||
1109 | 240 | if (!dbus_message_iter_next(&iter)) { | ||
1110 | 241 | ofono_error("%s: advance iter failed!", __func__); | ||
1111 | 242 | goto done; | ||
1112 | 243 | } | ||
1113 | 244 | |||
1114 | 245 | if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) { | ||
1115 | 246 | ofono_error("%s: type != ARRAY!", __func__); | ||
1116 | 247 | goto done; | ||
1117 | 248 | } | ||
1118 | 249 | |||
1119 | 250 | dbus_message_iter_recurse(&iter, &dict); | ||
1120 | 251 | |||
1121 | 252 | while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { | ||
1122 | 253 | DBusMessageIter entry, val; | ||
1123 | 254 | const char *key, *str_val; | ||
1124 | 255 | int id; | ||
1125 | 256 | |||
1126 | 257 | dbus_message_iter_recurse(&dict, &entry); | ||
1127 | 258 | |||
1128 | 259 | if (dbus_message_iter_get_arg_type(&entry) != | ||
1129 | 260 | DBUS_TYPE_STRING) { | ||
1130 | 261 | ofono_error("%s: key type != STRING!", __func__); | ||
1131 | 262 | goto done; | ||
1132 | 263 | } | ||
1133 | 264 | |||
1134 | 265 | dbus_message_iter_get_basic(&entry, &key); | ||
1135 | 266 | |||
1136 | 267 | dbus_message_iter_next(&entry); | ||
1137 | 268 | |||
1138 | 269 | if (dbus_message_iter_get_arg_type(&entry) != | ||
1139 | 270 | DBUS_TYPE_VARIANT) { | ||
1140 | 271 | ofono_error("%s: val != VARIANT", __func__); | ||
1141 | 272 | goto done; | ||
1142 | 273 | } | ||
1143 | 274 | |||
1144 | 275 | dbus_message_iter_recurse(&entry, &val); | ||
1145 | 276 | |||
1146 | 277 | if (dbus_message_iter_get_arg_type(&val) != DBUS_TYPE_STRING) { | ||
1147 | 278 | ofono_error("%s: *val != STRING", __func__); | ||
1148 | 279 | goto done; | ||
1149 | 280 | } | ||
1150 | 281 | |||
1151 | 282 | dbus_message_iter_get_basic(&val, &str_val); | ||
1152 | 283 | |||
1153 | 284 | DBG("property %s changed to %s", key, PRINTABLE_STR(str_val)); | ||
1154 | 285 | |||
1155 | 286 | id = get_id_from_name(key); | ||
1156 | 287 | if (id >= 0) | ||
1157 | 288 | accounts->property_values[id] = g_strdup(str_val); | ||
1158 | 289 | |||
1159 | 290 | dbus_message_iter_next(&dict); | ||
1160 | 291 | } | ||
1161 | 292 | |||
1162 | 293 | /* Check invalidated properties */ | ||
1163 | 294 | if (!dbus_message_iter_next(&iter)) { | ||
1164 | 295 | ofono_error("%s: advance iter failed!", __func__); | ||
1165 | 296 | goto done; | ||
1166 | 297 | } | ||
1167 | 298 | |||
1168 | 299 | if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) { | ||
1169 | 300 | ofono_error("%s: type != ARRAY!", __func__); | ||
1170 | 301 | goto done; | ||
1171 | 302 | } | ||
1172 | 303 | |||
1173 | 304 | dbus_message_iter_recurse(&iter, &inv_it); | ||
1174 | 305 | |||
1175 | 306 | while (dbus_message_iter_get_arg_type(&inv_it) == DBUS_TYPE_STRING) { | ||
1176 | 307 | const char *inv_name; | ||
1177 | 308 | int id; | ||
1178 | 309 | |||
1179 | 310 | dbus_message_iter_get_basic(&inv_it, &inv_name); | ||
1180 | 311 | |||
1181 | 312 | DBG("property %s invalidated", inv_name); | ||
1182 | 313 | |||
1183 | 314 | id = get_id_from_name(inv_name); | ||
1184 | 315 | if (id >= 0) | ||
1185 | 316 | get_property(accounts, id); | ||
1186 | 317 | |||
1187 | 318 | dbus_message_iter_next(&inv_it); | ||
1188 | 319 | } | ||
1189 | 320 | |||
1190 | 321 | done: | ||
1191 | 322 | return TRUE; | ||
1192 | 323 | } | ||
1193 | 324 | |||
1194 | 325 | static void get_user_settings(struct accounts_data *accounts) | ||
1195 | 326 | { | ||
1196 | 327 | DBusConnection *conn = ofono_dbus_get_connection(); | ||
1197 | 328 | size_t i; | ||
1198 | 329 | |||
1199 | 330 | snprintf(accounts->uid_path, sizeof(accounts->uid_path), | ||
1200 | 331 | ACCOUNTS_PATH"%u", (unsigned) accounts->current_uid); | ||
1201 | 332 | |||
1202 | 333 | /* | ||
1203 | 334 | * Register for property changes. Note that AccountsService is D-Bus, | ||
1204 | 335 | * initiated, so there is no risk for race conditions on start. | ||
1205 | 336 | */ | ||
1206 | 337 | accounts->prop_change_watch = | ||
1207 | 338 | g_dbus_add_signal_watch(conn, ACCOUNTS_SERVICE, | ||
1208 | 339 | accounts->uid_path, | ||
1209 | 340 | DBUS_INTERFACE_PROPERTIES, | ||
1210 | 341 | "PropertiesChanged", | ||
1211 | 342 | property_changed, | ||
1212 | 343 | accounts, NULL); | ||
1213 | 344 | |||
1214 | 345 | /* Retrieve AccountService properties */ | ||
1215 | 346 | for (i = 0; i < NUM_SETTINGS; ++i) | ||
1216 | 347 | get_property(accounts, i); | ||
1217 | 348 | } | ||
1218 | 349 | |||
1219 | 350 | static void release_accounts_data(struct accounts_data *accounts) | ||
1220 | 351 | { | ||
1221 | 352 | DBusConnection *conn = ofono_dbus_get_connection(); | ||
1222 | 353 | size_t i; | ||
1223 | 354 | |||
1224 | 355 | g_dbus_remove_watch(conn, accounts->prop_change_watch); | ||
1225 | 356 | |||
1226 | 357 | for (i = 0; i < NUM_SETTINGS; ++i) { | ||
1227 | 358 | g_free(accounts->property_values[i]); | ||
1228 | 359 | accounts->property_values[i] = NULL; | ||
1229 | 360 | } | ||
1230 | 361 | } | ||
1231 | 362 | |||
1232 | 363 | static uid_t get_active_seat_uid(void) | ||
1233 | 364 | { | ||
1234 | 365 | char **seats, **iter; | ||
1235 | 366 | int res; | ||
1236 | 367 | gboolean found = FALSE; | ||
1237 | 368 | uid_t uid; | ||
1238 | 369 | |||
1239 | 370 | res = sd_get_seats(&seats); | ||
1240 | 371 | if (res < 0) { | ||
1241 | 372 | ofono_error("Error retrieving seats: %s (%d)", | ||
1242 | 373 | strerror(-res), -res); | ||
1243 | 374 | goto end; | ||
1244 | 375 | } else if (res == 0) { | ||
1245 | 376 | ofono_info("No seats found"); | ||
1246 | 377 | goto end; | ||
1247 | 378 | } | ||
1248 | 379 | |||
1249 | 380 | for (iter = seats; *iter; ++iter) { | ||
1250 | 381 | |||
1251 | 382 | if (!found && sd_seat_get_active(*iter, NULL, &uid) >= 0) { | ||
1252 | 383 | DBG("seat %s with uid %d", *iter, uid); | ||
1253 | 384 | found = TRUE; | ||
1254 | 385 | } | ||
1255 | 386 | |||
1256 | 387 | free(*iter); | ||
1257 | 388 | } | ||
1258 | 389 | |||
1259 | 390 | free(seats); | ||
1260 | 391 | |||
1261 | 392 | end: | ||
1262 | 393 | if (!found) | ||
1263 | 394 | uid = geteuid(); | ||
1264 | 395 | |||
1265 | 396 | return uid; | ||
1266 | 397 | } | ||
1267 | 398 | |||
1268 | 399 | static gboolean sd_changed(GIOChannel *stream, GIOCondition condition, | ||
1269 | 400 | gpointer user_data) | ||
1270 | 401 | { | ||
1271 | 402 | struct accounts_data *accounts = user_data; | ||
1272 | 403 | uid_t new_uid; | ||
1273 | 404 | |||
1274 | 405 | sd_login_monitor_flush(accounts->login_monitor); | ||
1275 | 406 | |||
1276 | 407 | new_uid = get_active_seat_uid(); | ||
1277 | 408 | if (new_uid != accounts->current_uid) { | ||
1278 | 409 | /* User in seat changed, resetting data */ | ||
1279 | 410 | release_accounts_data(accounts); | ||
1280 | 411 | |||
1281 | 412 | accounts->current_uid = new_uid; | ||
1282 | 413 | get_user_settings(accounts); | ||
1283 | 414 | } | ||
1284 | 415 | |||
1285 | 416 | return TRUE; | ||
1286 | 417 | } | ||
1287 | 418 | |||
1288 | 419 | static void sd_init(struct accounts_data *accounts) | ||
1289 | 420 | { | ||
1290 | 421 | int status; | ||
1291 | 422 | GIOChannel *stream; | ||
1292 | 423 | int fd; | ||
1293 | 424 | |||
1294 | 425 | status = sd_login_monitor_new(NULL, &accounts->login_monitor); | ||
1295 | 426 | if (status < 0) { | ||
1296 | 427 | ofono_error("Error creating systemd login monitor: %d", status); | ||
1297 | 428 | accounts->login_monitor = NULL; | ||
1298 | 429 | return; | ||
1299 | 430 | } | ||
1300 | 431 | |||
1301 | 432 | fd = sd_login_monitor_get_fd(accounts->login_monitor); | ||
1302 | 433 | stream = g_io_channel_unix_new(fd); | ||
1303 | 434 | accounts->login_watch = | ||
1304 | 435 | g_io_add_watch(stream, G_IO_IN, sd_changed, accounts); | ||
1305 | 436 | |||
1306 | 437 | g_io_channel_unref(stream); | ||
1307 | 438 | } | ||
1308 | 439 | |||
1309 | 440 | static void sd_finalize(struct accounts_data *accounts) | ||
1310 | 441 | { | ||
1311 | 442 | if (accounts->login_monitor == NULL) | ||
1312 | 443 | return; | ||
1313 | 444 | |||
1314 | 445 | g_source_remove(accounts->login_watch); | ||
1315 | 446 | sd_login_monitor_unref(accounts->login_monitor); | ||
1316 | 447 | } | ||
1317 | 448 | |||
1318 | 449 | static int accounts_settings_init(void) | ||
1319 | 450 | { | ||
1320 | 451 | g_accounts.current_uid = get_active_seat_uid(); | ||
1321 | 452 | |||
1322 | 453 | /* Register for login changes */ | ||
1323 | 454 | sd_init(&g_accounts); | ||
1324 | 455 | |||
1325 | 456 | /* Get property values for current user */ | ||
1326 | 457 | get_user_settings(&g_accounts); | ||
1327 | 458 | |||
1328 | 459 | return ofono_system_settings_driver_register(&accounts_settings_driver); | ||
1329 | 460 | } | ||
1330 | 461 | |||
1331 | 462 | static void accounts_settings_exit(void) | ||
1332 | 463 | { | ||
1333 | 464 | ofono_system_settings_driver_unregister(&accounts_settings_driver); | ||
1334 | 465 | |||
1335 | 466 | sd_finalize(&g_accounts); | ||
1336 | 467 | |||
1337 | 468 | release_accounts_data(&g_accounts); | ||
1338 | 469 | } | ||
1339 | 470 | |||
1340 | 471 | OFONO_PLUGIN_DEFINE(accounts_settings, | ||
1341 | 472 | "Accounts Service System Settings Plugin", | ||
1342 | 473 | VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT, | ||
1343 | 474 | accounts_settings_init, accounts_settings_exit) | ||
1344 | 0 | 475 | ||
1345 | === added file 'plugins/android-wakelock.c' | |||
1346 | --- plugins/android-wakelock.c 1970-01-01 00:00:00 +0000 | |||
1347 | +++ plugins/android-wakelock.c 2016-03-14 09:03:03 +0000 | |||
1348 | @@ -0,0 +1,212 @@ | |||
1349 | 1 | /* | ||
1350 | 2 | * | ||
1351 | 3 | * oFono - Open Source Telephony - Android based wakelocks | ||
1352 | 4 | * | ||
1353 | 5 | * Copyright (C) 2016 Canonical Ltd. | ||
1354 | 6 | * | ||
1355 | 7 | * This program is free software; you can redistribute it and/or modify | ||
1356 | 8 | * it under the terms of the GNU General Public License as published by | ||
1357 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
1358 | 10 | * (at your option) any later version. | ||
1359 | 11 | * | ||
1360 | 12 | * This program is distributed in the hope that it will be useful, | ||
1361 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1362 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1363 | 15 | * GNU General Public License for more details. | ||
1364 | 16 | * | ||
1365 | 17 | * You should have received a copy of the GNU General Public License | ||
1366 | 18 | * along with this program; if not, write to the Free Software | ||
1367 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
1368 | 20 | * | ||
1369 | 21 | */ | ||
1370 | 22 | |||
1371 | 23 | #ifdef HAVE_CONFIG_H | ||
1372 | 24 | #include <config.h> | ||
1373 | 25 | #endif | ||
1374 | 26 | |||
1375 | 27 | #include <sys/types.h> | ||
1376 | 28 | #include <sys/stat.h> | ||
1377 | 29 | #include <fcntl.h> | ||
1378 | 30 | #include <unistd.h> | ||
1379 | 31 | #include <string.h> | ||
1380 | 32 | #include <errno.h> | ||
1381 | 33 | #include <glib.h> | ||
1382 | 34 | #include <dlfcn.h> | ||
1383 | 35 | |||
1384 | 36 | #include <glib.h> | ||
1385 | 37 | |||
1386 | 38 | #define OFONO_API_SUBJECT_TO_CHANGE | ||
1387 | 39 | |||
1388 | 40 | #include "plugin.h" | ||
1389 | 41 | #include "log.h" | ||
1390 | 42 | #include "wakelock.h" | ||
1391 | 43 | |||
1392 | 44 | #define ANDROID_WAKELOCK_LOCK_PATH "/sys/power/wake_lock" | ||
1393 | 45 | #define ANDROID_WAKELOCK_UNLOCK_PATH "/sys/power/wake_unlock" | ||
1394 | 46 | |||
1395 | 47 | struct wakelock { | ||
1396 | 48 | char *name; | ||
1397 | 49 | unsigned int acquisitions; | ||
1398 | 50 | }; | ||
1399 | 51 | |||
1400 | 52 | GSList *locks = NULL; | ||
1401 | 53 | |||
1402 | 54 | static int file_exists(char const *filename) | ||
1403 | 55 | { | ||
1404 | 56 | struct stat st; | ||
1405 | 57 | |||
1406 | 58 | return stat(filename, &st) == 0; | ||
1407 | 59 | } | ||
1408 | 60 | |||
1409 | 61 | static int write_file(const char *file, const char *content) | ||
1410 | 62 | { | ||
1411 | 63 | int fd; | ||
1412 | 64 | unsigned int r = 0; | ||
1413 | 65 | |||
1414 | 66 | fd = open(file, O_WRONLY); | ||
1415 | 67 | |||
1416 | 68 | if (fd == -1) | ||
1417 | 69 | return -EIO; | ||
1418 | 70 | |||
1419 | 71 | r = write(fd, content, strlen(content)); | ||
1420 | 72 | |||
1421 | 73 | close(fd); | ||
1422 | 74 | |||
1423 | 75 | if (r != strlen(content)) | ||
1424 | 76 | return -EIO; | ||
1425 | 77 | |||
1426 | 78 | return 0; | ||
1427 | 79 | } | ||
1428 | 80 | |||
1429 | 81 | static int wakelock_lock(const char *name) | ||
1430 | 82 | { | ||
1431 | 83 | return write_file(ANDROID_WAKELOCK_LOCK_PATH, name); | ||
1432 | 84 | } | ||
1433 | 85 | |||
1434 | 86 | static int wakelock_unlock(const char *name) | ||
1435 | 87 | { | ||
1436 | 88 | return write_file(ANDROID_WAKELOCK_UNLOCK_PATH, name); | ||
1437 | 89 | } | ||
1438 | 90 | |||
1439 | 91 | static int android_wakelock_acquire(struct wakelock *lock) | ||
1440 | 92 | { | ||
1441 | 93 | if (lock == NULL) | ||
1442 | 94 | return -EINVAL; | ||
1443 | 95 | |||
1444 | 96 | if (lock->acquisitions > 0) { | ||
1445 | 97 | lock->acquisitions++; | ||
1446 | 98 | return 0; | ||
1447 | 99 | } | ||
1448 | 100 | |||
1449 | 101 | if (wakelock_lock(lock->name) < 0) | ||
1450 | 102 | return -EIO; | ||
1451 | 103 | |||
1452 | 104 | lock->acquisitions++; | ||
1453 | 105 | |||
1454 | 106 | return 0; | ||
1455 | 107 | } | ||
1456 | 108 | |||
1457 | 109 | static int android_wakelock_release(struct wakelock *lock) | ||
1458 | 110 | { | ||
1459 | 111 | if (lock == NULL) | ||
1460 | 112 | return -EINVAL; | ||
1461 | 113 | |||
1462 | 114 | DBG("lock %p name %s acquisitions %d", | ||
1463 | 115 | lock, lock->name, lock->acquisitions); | ||
1464 | 116 | |||
1465 | 117 | if (!lock->acquisitions) { | ||
1466 | 118 | ofono_warn("Attempted to release already released lock %s", lock->name); | ||
1467 | 119 | return -EINVAL; | ||
1468 | 120 | } | ||
1469 | 121 | |||
1470 | 122 | if (lock->acquisitions > 1) { | ||
1471 | 123 | lock->acquisitions--; | ||
1472 | 124 | DBG("lock %s released acquisitions %d", lock->name, lock->acquisitions); | ||
1473 | 125 | return 0; | ||
1474 | 126 | } | ||
1475 | 127 | |||
1476 | 128 | if (wakelock_unlock(lock->name) < 0) | ||
1477 | 129 | return -EIO; | ||
1478 | 130 | |||
1479 | 131 | lock->acquisitions = 0; | ||
1480 | 132 | |||
1481 | 133 | DBG("lock %s was released", lock->name); | ||
1482 | 134 | |||
1483 | 135 | return 0; | ||
1484 | 136 | } | ||
1485 | 137 | |||
1486 | 138 | static int android_wakelock_create(const char *name, struct wakelock **lock) | ||
1487 | 139 | { | ||
1488 | 140 | if (lock == NULL) | ||
1489 | 141 | return -EINVAL; | ||
1490 | 142 | |||
1491 | 143 | *lock = g_new0(struct wakelock, 1); | ||
1492 | 144 | (*lock)->name = g_strdup(name); | ||
1493 | 145 | (*lock)->acquisitions = 0; | ||
1494 | 146 | |||
1495 | 147 | locks = g_slist_prepend(locks, *lock); | ||
1496 | 148 | |||
1497 | 149 | DBG("wakelock %s create", name); | ||
1498 | 150 | |||
1499 | 151 | return 0; | ||
1500 | 152 | } | ||
1501 | 153 | |||
1502 | 154 | static int android_wakelock_free(struct wakelock *lock) | ||
1503 | 155 | { | ||
1504 | 156 | if (lock == NULL) | ||
1505 | 157 | return -EINVAL; | ||
1506 | 158 | |||
1507 | 159 | if (lock->acquisitions) { | ||
1508 | 160 | /* Need to force releasing the lock here */ | ||
1509 | 161 | lock->acquisitions = 1; | ||
1510 | 162 | android_wakelock_release(lock); | ||
1511 | 163 | } | ||
1512 | 164 | |||
1513 | 165 | locks = g_slist_remove(locks, lock); | ||
1514 | 166 | |||
1515 | 167 | DBG("Freeing lock %s", lock->name); | ||
1516 | 168 | |||
1517 | 169 | g_free(lock->name); | ||
1518 | 170 | g_free(lock); | ||
1519 | 171 | |||
1520 | 172 | return 0; | ||
1521 | 173 | } | ||
1522 | 174 | |||
1523 | 175 | static ofono_bool_t android_wakelock_is_locked(struct wakelock *lock) | ||
1524 | 176 | { | ||
1525 | 177 | if (lock == NULL) | ||
1526 | 178 | return FALSE; | ||
1527 | 179 | |||
1528 | 180 | return lock->acquisitions > 0; | ||
1529 | 181 | } | ||
1530 | 182 | |||
1531 | 183 | struct wakelock_table driver = { | ||
1532 | 184 | .create = android_wakelock_create, | ||
1533 | 185 | .free = android_wakelock_free, | ||
1534 | 186 | .acquire = android_wakelock_acquire, | ||
1535 | 187 | .release = android_wakelock_release, | ||
1536 | 188 | .is_locked = android_wakelock_is_locked | ||
1537 | 189 | }; | ||
1538 | 190 | |||
1539 | 191 | static int android_wakelock_init(void) | ||
1540 | 192 | { | ||
1541 | 193 | if (!file_exists(ANDROID_WAKELOCK_LOCK_PATH)) { | ||
1542 | 194 | ofono_warn("System does not support Android wakelocks."); | ||
1543 | 195 | return 0; | ||
1544 | 196 | } | ||
1545 | 197 | |||
1546 | 198 | if (wakelock_plugin_register("android-wakelock", &driver) < 0) { | ||
1547 | 199 | ofono_error("Failed to register wakelock driver"); | ||
1548 | 200 | return -EIO; | ||
1549 | 201 | } | ||
1550 | 202 | |||
1551 | 203 | return 0; | ||
1552 | 204 | } | ||
1553 | 205 | |||
1554 | 206 | static void android_wakelock_exit(void) | ||
1555 | 207 | { | ||
1556 | 208 | wakelock_plugin_unregister(); | ||
1557 | 209 | } | ||
1558 | 210 | |||
1559 | 211 | OFONO_PLUGIN_DEFINE(android_wakelock, "Android Wakelock driver", VERSION, | ||
1560 | 212 | OFONO_PLUGIN_PRIORITY_DEFAULT, android_wakelock_init, android_wakelock_exit) | ||
1561 | 0 | 213 | ||
1562 | === removed file 'plugins/android-wakelock.c' | |||
1563 | --- plugins/android-wakelock.c 2016-01-15 16:03:09 +0000 | |||
1564 | +++ plugins/android-wakelock.c 1970-01-01 00:00:00 +0000 | |||
1565 | @@ -1,212 +0,0 @@ | |||
1566 | 1 | /* | ||
1567 | 2 | * | ||
1568 | 3 | * oFono - Open Source Telephony - Android based wakelocks | ||
1569 | 4 | * | ||
1570 | 5 | * Copyright (C) 2016 Canonical Ltd. | ||
1571 | 6 | * | ||
1572 | 7 | * This program is free software; you can redistribute it and/or modify | ||
1573 | 8 | * it under the terms of the GNU General Public License as published by | ||
1574 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
1575 | 10 | * (at your option) any later version. | ||
1576 | 11 | * | ||
1577 | 12 | * This program is distributed in the hope that it will be useful, | ||
1578 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1579 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1580 | 15 | * GNU General Public License for more details. | ||
1581 | 16 | * | ||
1582 | 17 | * You should have received a copy of the GNU General Public License | ||
1583 | 18 | * along with this program; if not, write to the Free Software | ||
1584 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
1585 | 20 | * | ||
1586 | 21 | */ | ||
1587 | 22 | |||
1588 | 23 | #ifdef HAVE_CONFIG_H | ||
1589 | 24 | #include <config.h> | ||
1590 | 25 | #endif | ||
1591 | 26 | |||
1592 | 27 | #include <sys/types.h> | ||
1593 | 28 | #include <sys/stat.h> | ||
1594 | 29 | #include <fcntl.h> | ||
1595 | 30 | #include <unistd.h> | ||
1596 | 31 | #include <string.h> | ||
1597 | 32 | #include <errno.h> | ||
1598 | 33 | #include <glib.h> | ||
1599 | 34 | #include <dlfcn.h> | ||
1600 | 35 | |||
1601 | 36 | #include <glib.h> | ||
1602 | 37 | |||
1603 | 38 | #define OFONO_API_SUBJECT_TO_CHANGE | ||
1604 | 39 | |||
1605 | 40 | #include "plugin.h" | ||
1606 | 41 | #include "log.h" | ||
1607 | 42 | #include "wakelock.h" | ||
1608 | 43 | |||
1609 | 44 | #define ANDROID_WAKELOCK_LOCK_PATH "/sys/power/wake_lock" | ||
1610 | 45 | #define ANDROID_WAKELOCK_UNLOCK_PATH "/sys/power/wake_unlock" | ||
1611 | 46 | |||
1612 | 47 | struct wakelock { | ||
1613 | 48 | char *name; | ||
1614 | 49 | unsigned int acquisitions; | ||
1615 | 50 | }; | ||
1616 | 51 | |||
1617 | 52 | GSList *locks = NULL; | ||
1618 | 53 | |||
1619 | 54 | static int file_exists(char const *filename) | ||
1620 | 55 | { | ||
1621 | 56 | struct stat st; | ||
1622 | 57 | |||
1623 | 58 | return stat(filename, &st) == 0; | ||
1624 | 59 | } | ||
1625 | 60 | |||
1626 | 61 | static int write_file(const char *file, const char *content) | ||
1627 | 62 | { | ||
1628 | 63 | int fd; | ||
1629 | 64 | unsigned int r = 0; | ||
1630 | 65 | |||
1631 | 66 | fd = open(file, O_WRONLY); | ||
1632 | 67 | |||
1633 | 68 | if (fd == -1) | ||
1634 | 69 | return -EIO; | ||
1635 | 70 | |||
1636 | 71 | r = write(fd, content, strlen(content)); | ||
1637 | 72 | |||
1638 | 73 | close(fd); | ||
1639 | 74 | |||
1640 | 75 | if (r != strlen(content)) | ||
1641 | 76 | return -EIO; | ||
1642 | 77 | |||
1643 | 78 | return 0; | ||
1644 | 79 | } | ||
1645 | 80 | |||
1646 | 81 | static int wakelock_lock(const char *name) | ||
1647 | 82 | { | ||
1648 | 83 | return write_file(ANDROID_WAKELOCK_LOCK_PATH, name); | ||
1649 | 84 | } | ||
1650 | 85 | |||
1651 | 86 | static int wakelock_unlock(const char *name) | ||
1652 | 87 | { | ||
1653 | 88 | return write_file(ANDROID_WAKELOCK_UNLOCK_PATH, name); | ||
1654 | 89 | } | ||
1655 | 90 | |||
1656 | 91 | static int android_wakelock_acquire(struct wakelock *lock) | ||
1657 | 92 | { | ||
1658 | 93 | if (!lock) | ||
1659 | 94 | return -EINVAL; | ||
1660 | 95 | |||
1661 | 96 | if (lock->acquisitions > 0) { | ||
1662 | 97 | lock->acquisitions++; | ||
1663 | 98 | return 0; | ||
1664 | 99 | } | ||
1665 | 100 | |||
1666 | 101 | if (wakelock_lock(lock->name) < 0) | ||
1667 | 102 | return -EIO; | ||
1668 | 103 | |||
1669 | 104 | lock->acquisitions++; | ||
1670 | 105 | |||
1671 | 106 | return 0; | ||
1672 | 107 | } | ||
1673 | 108 | |||
1674 | 109 | static int android_wakelock_release(struct wakelock *lock) | ||
1675 | 110 | { | ||
1676 | 111 | if (!lock) | ||
1677 | 112 | return -EINVAL; | ||
1678 | 113 | |||
1679 | 114 | DBG("lock %p name %s acquisitions %d", | ||
1680 | 115 | lock, lock->name, lock->acquisitions); | ||
1681 | 116 | |||
1682 | 117 | if (!lock->acquisitions) { | ||
1683 | 118 | ofono_warn("Attempted to release already released lock %s", lock->name); | ||
1684 | 119 | return -EINVAL; | ||
1685 | 120 | } | ||
1686 | 121 | |||
1687 | 122 | if (lock->acquisitions > 1) { | ||
1688 | 123 | lock->acquisitions--; | ||
1689 | 124 | DBG("lock %s released acquisitions %d", lock->name, lock->acquisitions); | ||
1690 | 125 | return 0; | ||
1691 | 126 | } | ||
1692 | 127 | |||
1693 | 128 | if (wakelock_unlock(lock->name) < 0) | ||
1694 | 129 | return -EIO; | ||
1695 | 130 | |||
1696 | 131 | lock->acquisitions = 0; | ||
1697 | 132 | |||
1698 | 133 | DBG("lock %s was released", lock->name); | ||
1699 | 134 | |||
1700 | 135 | return 0; | ||
1701 | 136 | } | ||
1702 | 137 | |||
1703 | 138 | static int android_wakelock_create(const char *name, struct wakelock **lock) | ||
1704 | 139 | { | ||
1705 | 140 | if (!lock) | ||
1706 | 141 | return -EINVAL; | ||
1707 | 142 | |||
1708 | 143 | *lock = g_new0(struct wakelock, 1); | ||
1709 | 144 | (*lock)->name = g_strdup(name); | ||
1710 | 145 | (*lock)->acquisitions = 0; | ||
1711 | 146 | |||
1712 | 147 | locks = g_slist_prepend(locks, *lock); | ||
1713 | 148 | |||
1714 | 149 | DBG("wakelock %s create", name); | ||
1715 | 150 | |||
1716 | 151 | return 0; | ||
1717 | 152 | } | ||
1718 | 153 | |||
1719 | 154 | static int android_wakelock_free(struct wakelock *lock) | ||
1720 | 155 | { | ||
1721 | 156 | if (!lock) | ||
1722 | 157 | return -EINVAL; | ||
1723 | 158 | |||
1724 | 159 | if (lock->acquisitions) { | ||
1725 | 160 | /* Need to force releasing the lock here */ | ||
1726 | 161 | lock->acquisitions = 1; | ||
1727 | 162 | android_wakelock_release(lock); | ||
1728 | 163 | } | ||
1729 | 164 | |||
1730 | 165 | locks = g_slist_remove(locks, lock); | ||
1731 | 166 | |||
1732 | 167 | DBG("Freeing lock %s", lock->name); | ||
1733 | 168 | |||
1734 | 169 | g_free(lock->name); | ||
1735 | 170 | g_free(lock); | ||
1736 | 171 | |||
1737 | 172 | return 0; | ||
1738 | 173 | } | ||
1739 | 174 | |||
1740 | 175 | static ofono_bool_t android_wakelock_is_locked(struct wakelock *lock) | ||
1741 | 176 | { | ||
1742 | 177 | if (!lock) | ||
1743 | 178 | return FALSE; | ||
1744 | 179 | |||
1745 | 180 | return lock->acquisitions > 0; | ||
1746 | 181 | } | ||
1747 | 182 | |||
1748 | 183 | struct wakelock_table driver = { | ||
1749 | 184 | .create = android_wakelock_create, | ||
1750 | 185 | .free = android_wakelock_free, | ||
1751 | 186 | .acquire = android_wakelock_acquire, | ||
1752 | 187 | .release = android_wakelock_release, | ||
1753 | 188 | .is_locked = android_wakelock_is_locked | ||
1754 | 189 | }; | ||
1755 | 190 | |||
1756 | 191 | static int android_wakelock_init(void) | ||
1757 | 192 | { | ||
1758 | 193 | if (!file_exists(ANDROID_WAKELOCK_LOCK_PATH)) { | ||
1759 | 194 | ofono_warn("System does not support Android wakelocks."); | ||
1760 | 195 | return 0; | ||
1761 | 196 | } | ||
1762 | 197 | |||
1763 | 198 | if (wakelock_plugin_register("android-wakelock", &driver) < 0) { | ||
1764 | 199 | ofono_error("Failed to register wakelock driver"); | ||
1765 | 200 | return -EIO; | ||
1766 | 201 | } | ||
1767 | 202 | |||
1768 | 203 | return 0; | ||
1769 | 204 | } | ||
1770 | 205 | |||
1771 | 206 | static void android_wakelock_exit(void) | ||
1772 | 207 | { | ||
1773 | 208 | wakelock_plugin_unregister(); | ||
1774 | 209 | } | ||
1775 | 210 | |||
1776 | 211 | OFONO_PLUGIN_DEFINE(android_wakelock, "Android Wakelock driver", VERSION, | ||
1777 | 212 | OFONO_PLUGIN_PRIORITY_DEFAULT, android_wakelock_init, android_wakelock_exit) | ||
1778 | 213 | 0 | ||
1779 | === modified file 'plugins/qcom-msim.c' | |||
1780 | --- plugins/qcom-msim.c 2015-04-23 13:08:30 +0000 | |||
1781 | +++ plugins/qcom-msim.c 2016-03-14 09:03:03 +0000 | |||
1782 | @@ -36,6 +36,18 @@ | |||
1783 | 36 | 36 | ||
1784 | 37 | static int qcom_msim_probe(struct ofono_modem *modem) | 37 | static int qcom_msim_probe(struct ofono_modem *modem) |
1785 | 38 | { | 38 | { |
1786 | 39 | int slot_id = ofono_modem_get_integer(modem, "Slot"); | ||
1787 | 40 | |||
1788 | 41 | /* qcom_msim has socket path "rild", "rild1", ... */ | ||
1789 | 42 | if (slot_id != 0) { | ||
1790 | 43 | char *socket; | ||
1791 | 44 | |||
1792 | 45 | socket = g_strdup_printf("/dev/socket/rild%d", slot_id); | ||
1793 | 46 | ofono_modem_set_string(modem, "Socket", socket); | ||
1794 | 47 | |||
1795 | 48 | g_free(socket); | ||
1796 | 49 | } | ||
1797 | 50 | |||
1798 | 39 | return ril_create(modem, OFONO_RIL_VENDOR_QCOM_MSIM); | 51 | return ril_create(modem, OFONO_RIL_VENDOR_QCOM_MSIM); |
1799 | 40 | } | 52 | } |
1800 | 41 | 53 | ||
1801 | 42 | 54 | ||
1802 | === modified file 'plugins/ril.c' | |||
1803 | --- plugins/ril.c 2015-10-07 07:14:11 +0000 | |||
1804 | +++ plugins/ril.c 2016-03-14 09:03:03 +0000 | |||
1805 | @@ -73,9 +73,6 @@ | |||
1806 | 73 | #define RILD_MAX_CONNECT_RETRIES 5 | 73 | #define RILD_MAX_CONNECT_RETRIES 5 |
1807 | 74 | #define RILD_CONNECT_RETRY_TIME_S 5 | 74 | #define RILD_CONNECT_RETRY_TIME_S 5 |
1808 | 75 | 75 | ||
1809 | 76 | char *RILD_CMD_SOCKET[] = {"/dev/socket/rild", "/dev/socket/rild1"}; | ||
1810 | 77 | char *GRIL_HEX_PREFIX[] = {"Device 0: ", "Device 1: "}; | ||
1811 | 78 | |||
1812 | 79 | struct ril_data { | 76 | struct ril_data { |
1813 | 80 | GRil *ril; | 77 | GRil *ril; |
1814 | 81 | enum ofono_ril_vendor vendor; | 78 | enum ofono_ril_vendor vendor; |
1815 | @@ -90,9 +87,9 @@ | |||
1816 | 90 | 87 | ||
1817 | 91 | static void ril_debug(const char *str, void *user_data) | 88 | static void ril_debug(const char *str, void *user_data) |
1818 | 92 | { | 89 | { |
1820 | 93 | const char *prefix = user_data; | 90 | struct ril_data *rd = user_data; |
1821 | 94 | 91 | ||
1823 | 95 | ofono_info("%s%s", prefix, str); | 92 | ofono_info("Device %d: %s", g_ril_get_slot(rd->ril), str); |
1824 | 96 | } | 93 | } |
1825 | 97 | 94 | ||
1826 | 98 | static void ril_radio_state_changed(struct ril_msg *message, gpointer user_data) | 95 | static void ril_radio_state_changed(struct ril_msg *message, gpointer user_data) |
1827 | @@ -169,7 +166,7 @@ | |||
1828 | 169 | 166 | ||
1829 | 170 | rd->vendor = vendor; | 167 | rd->vendor = vendor; |
1830 | 171 | rd->ofono_online = FALSE; | 168 | rd->ofono_online = FALSE; |
1832 | 172 | rd->radio_state = RADIO_STATE_OFF; | 169 | rd->radio_state = RADIO_STATE_UNAVAILABLE; |
1833 | 173 | 170 | ||
1834 | 174 | lte_cap = getenv("OFONO_RIL_RAT_LTE") ? TRUE : FALSE; | 171 | lte_cap = getenv("OFONO_RIL_RAT_LTE") ? TRUE : FALSE; |
1835 | 175 | ofono_modem_set_boolean(modem, MODEM_PROP_LTE_CAPABLE, lte_cap); | 172 | ofono_modem_set_boolean(modem, MODEM_PROP_LTE_CAPABLE, lte_cap); |
1836 | @@ -284,7 +281,9 @@ | |||
1837 | 284 | struct ril_data *rd = cbd->user; | 281 | struct ril_data *rd = cbd->user; |
1838 | 285 | ofono_modem_online_cb_t cb = cbd->cb; | 282 | ofono_modem_online_cb_t cb = cbd->cb; |
1839 | 286 | 283 | ||
1841 | 287 | if (message->error == RIL_E_SUCCESS) { | 284 | if (message != NULL && message->error == RIL_E_SUCCESS) { |
1842 | 285 | g_ril_print_response_no_args(rd->ril, message); | ||
1843 | 286 | |||
1844 | 288 | DBG("%s: set_online OK: rd->ofono_online: %d", __func__, | 287 | DBG("%s: set_online OK: rd->ofono_online: %d", __func__, |
1845 | 289 | rd->ofono_online); | 288 | rd->ofono_online); |
1846 | 290 | CALLBACK_WITH_SUCCESS(cb, cbd->data); | 289 | CALLBACK_WITH_SUCCESS(cb, cbd->data); |
1847 | @@ -293,31 +292,24 @@ | |||
1848 | 293 | rd->ofono_online); | 292 | rd->ofono_online); |
1849 | 294 | CALLBACK_WITH_FAILURE(cb, cbd->data); | 293 | CALLBACK_WITH_FAILURE(cb, cbd->data); |
1850 | 295 | } | 294 | } |
1851 | 295 | |||
1852 | 296 | g_free(cbd); | ||
1853 | 296 | } | 297 | } |
1854 | 297 | 298 | ||
1855 | 298 | static void ril_send_power(struct ril_data *rd, ofono_bool_t online, | 299 | static void ril_send_power(struct ril_data *rd, ofono_bool_t online, |
1856 | 299 | GRilResponseFunc func, | 300 | GRilResponseFunc func, |
1857 | 300 | gpointer user_data) | 301 | gpointer user_data) |
1858 | 301 | { | 302 | { |
1859 | 302 | struct cb_data *cbd = user_data; | ||
1860 | 303 | ofono_modem_online_cb_t cb; | ||
1861 | 304 | GDestroyNotify notify = NULL; | ||
1862 | 305 | struct parcel rilp; | 303 | struct parcel rilp; |
1863 | 306 | 304 | ||
1864 | 307 | if (cbd != NULL) { | ||
1865 | 308 | notify = g_free; | ||
1866 | 309 | cb = cbd->cb; | ||
1867 | 310 | } | ||
1868 | 311 | |||
1869 | 312 | DBG("(online = 1, offline = 0)): %i", online); | 305 | DBG("(online = 1, offline = 0)): %i", online); |
1870 | 313 | 306 | ||
1871 | 314 | g_ril_request_power(rd->ril, (const gboolean) online, &rilp); | 307 | g_ril_request_power(rd->ril, (const gboolean) online, &rilp); |
1872 | 315 | 308 | ||
1873 | 316 | if (g_ril_send(rd->ril, RIL_REQUEST_RADIO_POWER, &rilp, | 309 | if (g_ril_send(rd->ril, RIL_REQUEST_RADIO_POWER, &rilp, |
1875 | 317 | func, cbd, notify) == 0 && cbd != NULL) { | 310 | func, user_data, NULL) == 0 && func != NULL) { |
1876 | 318 | 311 | ||
1879 | 319 | CALLBACK_WITH_FAILURE(cb, cbd->data); | 312 | func(NULL, user_data); |
1878 | 320 | g_free(cbd); | ||
1880 | 321 | } | 313 | } |
1881 | 322 | } | 314 | } |
1882 | 323 | 315 | ||
1883 | @@ -334,30 +326,47 @@ | |||
1884 | 334 | ril_send_power(rd, online, ril_set_online_cb, cbd); | 326 | ril_send_power(rd, online, ril_set_online_cb, cbd); |
1885 | 335 | } | 327 | } |
1886 | 336 | 328 | ||
1887 | 329 | static void ril_set_powered_off_cb(struct ril_msg *message, gpointer user_data) | ||
1888 | 330 | { | ||
1889 | 331 | struct ofono_modem *modem = user_data; | ||
1890 | 332 | struct ril_data *rd = ofono_modem_get_data(modem); | ||
1891 | 333 | |||
1892 | 334 | if (message != NULL && message->error == RIL_E_SUCCESS) | ||
1893 | 335 | g_ril_print_response_no_args(rd->ril, message); | ||
1894 | 336 | |||
1895 | 337 | DBG("calling set_powered(TRUE)"); | ||
1896 | 338 | |||
1897 | 339 | ofono_modem_set_powered(modem, TRUE); | ||
1898 | 340 | } | ||
1899 | 341 | |||
1900 | 337 | static void ril_connected(struct ril_msg *message, gpointer user_data) | 342 | static void ril_connected(struct ril_msg *message, gpointer user_data) |
1901 | 338 | { | 343 | { |
1902 | 339 | struct ofono_modem *modem = (struct ofono_modem *) user_data; | 344 | struct ofono_modem *modem = (struct ofono_modem *) user_data; |
1903 | 340 | struct ril_data *rd = ofono_modem_get_data(modem); | 345 | struct ril_data *rd = ofono_modem_get_data(modem); |
1907 | 341 | 346 | int version; | |
1908 | 342 | ofono_info("[%d,UNSOL]< %s", g_ril_get_slot(rd->ril), | 347 | |
1909 | 343 | g_ril_unsol_request_to_string(rd->ril, message->req)); | 348 | version = g_ril_unsol_parse_connected(rd->ril, message); |
1910 | 349 | g_ril_set_version(rd->ril, version); | ||
1911 | 350 | |||
1912 | 351 | ofono_info("[%d,UNSOL]< %s, version %d", g_ril_get_slot(rd->ril), | ||
1913 | 352 | g_ril_unsol_request_to_string(rd->ril, message->req), version); | ||
1914 | 344 | 353 | ||
1915 | 345 | /* TODO: need a disconnect function to restart things! */ | 354 | /* TODO: need a disconnect function to restart things! */ |
1916 | 346 | rd->connected = TRUE; | 355 | rd->connected = TRUE; |
1917 | 347 | 356 | ||
1919 | 348 | DBG("calling set_powered(TRUE)"); | 357 | DBG("calling set_powered(FALSE) on connected"); |
1920 | 349 | 358 | ||
1922 | 350 | ofono_modem_set_powered(modem, TRUE); | 359 | ril_send_power(rd, FALSE, ril_set_powered_off_cb, modem); |
1923 | 351 | } | 360 | } |
1924 | 352 | 361 | ||
1925 | 353 | static int create_gril(struct ofono_modem *modem) | 362 | static int create_gril(struct ofono_modem *modem) |
1926 | 354 | { | 363 | { |
1927 | 355 | struct ril_data *rd = ofono_modem_get_data(modem); | 364 | struct ril_data *rd = ofono_modem_get_data(modem); |
1928 | 356 | int slot_id = ofono_modem_get_integer(modem, "Slot"); | 365 | int slot_id = ofono_modem_get_integer(modem, "Slot"); |
1929 | 366 | const gchar *socket = ofono_modem_get_string(modem, "Socket"); | ||
1930 | 357 | 367 | ||
1934 | 358 | ofono_info("Using %s as socket for slot %d.", | 368 | ofono_info("Using %s as socket for slot %d.", socket, slot_id); |
1935 | 359 | RILD_CMD_SOCKET[slot_id], slot_id); | 369 | rd->ril = g_ril_new(socket, rd->vendor); |
1933 | 360 | rd->ril = g_ril_new(RILD_CMD_SOCKET[slot_id], OFONO_RIL_VENDOR_AOSP); | ||
1936 | 361 | 370 | ||
1937 | 362 | /* NOTE: Since AT modems open a tty, and then call | 371 | /* NOTE: Since AT modems open a tty, and then call |
1938 | 363 | * g_at_chat_new(), they're able to return -EIO if | 372 | * g_at_chat_new(), they're able to return -EIO if |
1939 | @@ -377,7 +386,7 @@ | |||
1940 | 377 | g_ril_set_trace(rd->ril, TRUE); | 386 | g_ril_set_trace(rd->ril, TRUE); |
1941 | 378 | 387 | ||
1942 | 379 | if (getenv("OFONO_RIL_HEX_TRACE")) | 388 | if (getenv("OFONO_RIL_HEX_TRACE")) |
1944 | 380 | g_ril_set_debugf(rd->ril, ril_debug, GRIL_HEX_PREFIX[slot_id]); | 389 | g_ril_set_debugf(rd->ril, ril_debug, rd); |
1945 | 381 | 390 | ||
1946 | 382 | g_ril_register(rd->ril, RIL_UNSOL_RIL_CONNECTED, | 391 | g_ril_register(rd->ril, RIL_UNSOL_RIL_CONNECTED, |
1947 | 383 | ril_connected, modem); | 392 | ril_connected, modem); |
1948 | 384 | 393 | ||
1949 | === modified file 'plugins/rildev.c' | |||
1950 | --- plugins/rildev.c 2015-11-10 09:13:46 +0000 | |||
1951 | +++ plugins/rildev.c 2016-03-14 09:03:03 +0000 | |||
1952 | @@ -43,6 +43,7 @@ | |||
1953 | 43 | { | 43 | { |
1954 | 44 | struct ofono_modem *modem; | 44 | struct ofono_modem *modem; |
1955 | 45 | char dev_name[64]; | 45 | char dev_name[64]; |
1956 | 46 | char *socket; | ||
1957 | 46 | int retval; | 47 | int retval; |
1958 | 47 | 48 | ||
1959 | 48 | snprintf(dev_name, sizeof(dev_name), "ril_%d", slot); | 49 | snprintf(dev_name, sizeof(dev_name), "ril_%d", slot); |
1960 | @@ -58,6 +59,15 @@ | |||
1961 | 58 | 59 | ||
1962 | 59 | ofono_modem_set_integer(modem, "Slot", slot); | 60 | ofono_modem_set_integer(modem, "Slot", slot); |
1963 | 60 | 61 | ||
1964 | 62 | /* AOSP has socket path "rild", "rild2"..., while others may differ */ | ||
1965 | 63 | if (slot != 0) | ||
1966 | 64 | socket = g_strdup_printf("/dev/socket/rild%d", slot + 1); | ||
1967 | 65 | else | ||
1968 | 66 | socket = g_strdup("/dev/socket/rild"); | ||
1969 | 67 | |||
1970 | 68 | ofono_modem_set_string(modem, "Socket", socket); | ||
1971 | 69 | g_free(socket); | ||
1972 | 70 | |||
1973 | 61 | /* This causes driver->probe() to be called... */ | 71 | /* This causes driver->probe() to be called... */ |
1974 | 62 | retval = ofono_modem_register(modem); | 72 | retval = ofono_modem_register(modem); |
1975 | 63 | if (retval != 0) { | 73 | if (retval != 0) { |
1976 | 64 | 74 | ||
1977 | === modified file 'plugins/upower.c' | |||
1978 | --- plugins/upower.c 2015-11-02 09:18:14 +0000 | |||
1979 | +++ plugins/upower.c 2016-03-14 09:03:03 +0000 | |||
1980 | @@ -40,11 +40,8 @@ | |||
1981 | 40 | #define UPOWER_DEVICE_INTERFACE UPOWER_SERVICE ".Device" | 40 | #define UPOWER_DEVICE_INTERFACE UPOWER_SERVICE ".Device" |
1982 | 41 | 41 | ||
1983 | 42 | static guint modem_watch; | 42 | static guint modem_watch; |
1984 | 43 | static guint upower_battery_watch; | ||
1985 | 44 | static guint upower_daemon_watch; | 43 | static guint upower_daemon_watch; |
1986 | 45 | static DBusConnection *connection; | 44 | static DBusConnection *connection; |
1987 | 46 | static GHashTable *modem_hfp_watches; | ||
1988 | 47 | static GList *modems; | ||
1989 | 48 | static int last_battery_level; | 45 | static int last_battery_level; |
1990 | 49 | static char *battery_device_path; | 46 | static char *battery_device_path; |
1991 | 50 | 47 | ||
1992 | @@ -56,9 +53,17 @@ | |||
1993 | 56 | ofono_emulator_set_indicator(atom, OFONO_EMULATOR_IND_BATTERY, val); | 53 | ofono_emulator_set_indicator(atom, OFONO_EMULATOR_IND_BATTERY, val); |
1994 | 57 | } | 54 | } |
1995 | 58 | 55 | ||
1996 | 56 | static void update_modem_battery_indicator(struct ofono_modem *modem, | ||
1997 | 57 | void *data) | ||
1998 | 58 | { | ||
1999 | 59 | __ofono_modem_foreach_registered_atom(modem, | ||
2000 | 60 | OFONO_ATOM_TYPE_EMULATOR_HFP, | ||
2001 | 61 | emulator_battery_cb, | ||
2002 | 62 | data); | ||
2003 | 63 | } | ||
2004 | 64 | |||
2005 | 59 | static void update_battery_level(double percentage_val) | 65 | static void update_battery_level(double percentage_val) |
2006 | 60 | { | 66 | { |
2007 | 61 | GList *list; | ||
2008 | 62 | int battery_level; | 67 | int battery_level; |
2009 | 63 | 68 | ||
2010 | 64 | if (percentage_val <= 1.00) { | 69 | if (percentage_val <= 1.00) { |
2011 | @@ -69,27 +74,19 @@ | |||
2012 | 69 | ofono_error("%s: Invalid value for battery level: %f", | 74 | ofono_error("%s: Invalid value for battery level: %f", |
2013 | 70 | __func__, | 75 | __func__, |
2014 | 71 | percentage_val); | 76 | percentage_val); |
2016 | 72 | goto done; | 77 | return; |
2017 | 73 | } | 78 | } |
2018 | 74 | 79 | ||
2019 | 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, |
2020 | 76 | battery_level, percentage_val); | 81 | battery_level, percentage_val); |
2021 | 77 | 82 | ||
2022 | 78 | if (last_battery_level == battery_level) | 83 | if (last_battery_level == battery_level) |
2024 | 79 | goto done; | 84 | return; |
2025 | 80 | 85 | ||
2026 | 81 | last_battery_level = battery_level; | 86 | last_battery_level = battery_level; |
2027 | 82 | 87 | ||
2034 | 83 | for (list = modems; list; list = list->next) { | 88 | __ofono_modem_foreach(update_modem_battery_indicator, |
2029 | 84 | struct ofono_modem *modem = list->data; | ||
2030 | 85 | |||
2031 | 86 | __ofono_modem_foreach_registered_atom(modem, | ||
2032 | 87 | OFONO_ATOM_TYPE_EMULATOR_HFP, | ||
2033 | 88 | emulator_battery_cb, | ||
2035 | 89 | GINT_TO_POINTER(battery_level)); | 89 | GINT_TO_POINTER(battery_level)); |
2036 | 90 | } | ||
2037 | 91 | done: | ||
2038 | 92 | ; | ||
2039 | 93 | } | 90 | } |
2040 | 94 | 91 | ||
2041 | 95 | static gboolean battery_props_changed(DBusConnection *conn, DBusMessage *msg, | 92 | static gboolean battery_props_changed(DBusConnection *conn, DBusMessage *msg, |
2042 | @@ -102,6 +99,8 @@ | |||
2043 | 102 | gboolean percentage_found = FALSE; | 99 | gboolean percentage_found = FALSE; |
2044 | 103 | gboolean retval = FALSE; | 100 | gboolean retval = FALSE; |
2045 | 104 | 101 | ||
2046 | 102 | DBG(""); | ||
2047 | 103 | |||
2048 | 105 | dbus_message_iter_init(msg, &iter); | 104 | dbus_message_iter_init(msg, &iter); |
2049 | 106 | 105 | ||
2050 | 107 | if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) { | 106 | if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) { |
2051 | @@ -179,117 +178,19 @@ | |||
2052 | 179 | return retval; | 178 | return retval; |
2053 | 180 | } | 179 | } |
2054 | 181 | 180 | ||
2055 | 182 | static void get_property_reply(DBusPendingCall *call, void *user_data) | ||
2056 | 183 | { | ||
2057 | 184 | double percentage_val; | ||
2058 | 185 | DBusMessageIter iter, val; | ||
2059 | 186 | DBusMessage *reply; | ||
2060 | 187 | |||
2061 | 188 | DBG(""); | ||
2062 | 189 | |||
2063 | 190 | reply = dbus_pending_call_steal_reply(call); | ||
2064 | 191 | if (reply == NULL) { | ||
2065 | 192 | ofono_error("%s: dbus_message_new_method failed", __func__); | ||
2066 | 193 | goto done; | ||
2067 | 194 | } | ||
2068 | 195 | |||
2069 | 196 | if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { | ||
2070 | 197 | ofono_error("%s: ERROR reply to Get('Percentage')", __func__); | ||
2071 | 198 | goto done; | ||
2072 | 199 | } | ||
2073 | 200 | |||
2074 | 201 | if (dbus_message_iter_init(reply, &iter) == FALSE) { | ||
2075 | 202 | ofono_error("%s: error initializing array iter", __func__); | ||
2076 | 203 | goto done; | ||
2077 | 204 | } | ||
2078 | 205 | |||
2079 | 206 | if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) { | ||
2080 | 207 | ofono_error("%s: type != VARIANT!", __func__); | ||
2081 | 208 | goto done; | ||
2082 | 209 | } | ||
2083 | 210 | |||
2084 | 211 | dbus_message_iter_recurse(&iter, &val); | ||
2085 | 212 | |||
2086 | 213 | if (dbus_message_iter_get_arg_type(&val) != DBUS_TYPE_DOUBLE) { | ||
2087 | 214 | ofono_error("%s: type != DOUBLE!", __func__); | ||
2088 | 215 | goto done; | ||
2089 | 216 | } | ||
2090 | 217 | |||
2091 | 218 | dbus_message_iter_get_basic(&val, &percentage_val); | ||
2092 | 219 | |||
2093 | 220 | update_battery_level(percentage_val); | ||
2094 | 221 | |||
2095 | 222 | done: | ||
2096 | 223 | if (reply) | ||
2097 | 224 | dbus_message_unref(reply); | ||
2098 | 225 | |||
2099 | 226 | dbus_pending_call_unref(call); | ||
2100 | 227 | } | ||
2101 | 228 | |||
2102 | 229 | static void emulator_hfp_watch(struct ofono_atom *atom, | 181 | static void emulator_hfp_watch(struct ofono_atom *atom, |
2103 | 230 | enum ofono_atom_watch_condition cond, | 182 | enum ofono_atom_watch_condition cond, |
2104 | 231 | void *data) | 183 | void *data) |
2105 | 232 | { | 184 | { |
2166 | 233 | struct ofono_modem *modem = data; | 185 | if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) { |
2167 | 234 | DBusMessageIter iter; | 186 | DBG("REGISTERED; calling set_indicator: %d", last_battery_level); |
2168 | 235 | DBusPendingCall *call; | 187 | |
2169 | 236 | DBusMessage *msg; | 188 | ofono_emulator_set_indicator(atom, OFONO_EMULATOR_IND_BATTERY, |
2170 | 237 | const char *iface = UPOWER_DEVICE_INTERFACE; | 189 | last_battery_level); |
2171 | 238 | const char *property = "Percentage"; | 190 | return; |
2172 | 239 | 191 | } | |
2173 | 240 | if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) { | 192 | |
2174 | 241 | DBG("UNREGISTERED"); | 193 | DBG("UNREGISTERED"); |
2115 | 242 | |||
2116 | 243 | modems = g_list_remove(modems, modem); | ||
2117 | 244 | if (modems != NULL) | ||
2118 | 245 | return; | ||
2119 | 246 | |||
2120 | 247 | if (upower_battery_watch) { | ||
2121 | 248 | g_dbus_remove_watch(connection, upower_battery_watch); | ||
2122 | 249 | upower_battery_watch = 0; | ||
2123 | 250 | } | ||
2124 | 251 | |||
2125 | 252 | return; | ||
2126 | 253 | } | ||
2127 | 254 | |||
2128 | 255 | DBG("REGISTERED"); | ||
2129 | 256 | |||
2130 | 257 | /* TODO: handle removable batteries */ | ||
2131 | 258 | |||
2132 | 259 | modems = g_list_append(modems, modem); | ||
2133 | 260 | |||
2134 | 261 | if (modems->next != NULL) | ||
2135 | 262 | return; | ||
2136 | 263 | |||
2137 | 264 | upower_battery_watch = g_dbus_add_signal_watch(connection, | ||
2138 | 265 | UPOWER_SERVICE, | ||
2139 | 266 | battery_device_path, | ||
2140 | 267 | DBUS_INTERFACE_PROPERTIES, | ||
2141 | 268 | "PropertiesChanged", | ||
2142 | 269 | battery_props_changed, | ||
2143 | 270 | NULL, NULL); | ||
2144 | 271 | |||
2145 | 272 | /* Query current battery value */ | ||
2146 | 273 | msg = dbus_message_new_method_call(UPOWER_SERVICE, battery_device_path, | ||
2147 | 274 | DBUS_PROPERTIES_INTERFACE, | ||
2148 | 275 | "Get"); | ||
2149 | 276 | if (msg == NULL) { | ||
2150 | 277 | ofono_error("%s: dbus_message_new_method failed", __func__); | ||
2151 | 278 | return; | ||
2152 | 279 | } | ||
2153 | 280 | |||
2154 | 281 | dbus_message_iter_init_append(msg, &iter); | ||
2155 | 282 | dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &iface); | ||
2156 | 283 | dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &property); | ||
2157 | 284 | |||
2158 | 285 | if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) { | ||
2159 | 286 | ofono_error("%s: Sending EnumerateDevices failed", __func__); | ||
2160 | 287 | goto done; | ||
2161 | 288 | } | ||
2162 | 289 | |||
2163 | 290 | dbus_pending_call_set_notify(call, get_property_reply, NULL, NULL); | ||
2164 | 291 | done: | ||
2165 | 292 | dbus_message_unref(msg); | ||
2175 | 293 | } | 194 | } |
2176 | 294 | 195 | ||
2177 | 295 | static void modemwatch(struct ofono_modem *modem, gboolean added, void *user) | 196 | static void modemwatch(struct ofono_modem *modem, gboolean added, void *user) |
2178 | @@ -299,24 +200,10 @@ | |||
2179 | 299 | 200 | ||
2180 | 300 | DBG("modem: %s, added: %d", path, added); | 201 | DBG("modem: %s, added: %d", path, added); |
2181 | 301 | 202 | ||
2186 | 302 | if (added) { | 203 | if (added) |
2187 | 303 | guint watch_id; | 204 | __ofono_modem_add_atom_watch(modem, |
2184 | 304 | |||
2185 | 305 | watch_id = __ofono_modem_add_atom_watch(modem, | ||
2188 | 306 | OFONO_ATOM_TYPE_EMULATOR_HFP, | 205 | OFONO_ATOM_TYPE_EMULATOR_HFP, |
2202 | 307 | emulator_hfp_watch, modem, NULL); | 206 | emulator_hfp_watch, NULL, NULL); |
2190 | 308 | |||
2191 | 309 | g_hash_table_insert(modem_hfp_watches, g_strdup(path), | ||
2192 | 310 | GINT_TO_POINTER(watch_id)); | ||
2193 | 311 | |||
2194 | 312 | } else { | ||
2195 | 313 | guint *watch_id = g_hash_table_lookup(modem_hfp_watches, path); | ||
2196 | 314 | |||
2197 | 315 | if (watch_id != NULL) { | ||
2198 | 316 | __ofono_modem_remove_atom_watch(modem, *watch_id); | ||
2199 | 317 | g_hash_table_remove(modem_hfp_watches, path); | ||
2200 | 318 | } | ||
2201 | 319 | } | ||
2203 | 320 | } | 207 | } |
2204 | 321 | 208 | ||
2205 | 322 | static void call_modemwatch(struct ofono_modem *modem, void *user) | 209 | static void call_modemwatch(struct ofono_modem *modem, void *user) |
2206 | @@ -383,13 +270,23 @@ | |||
2207 | 383 | 270 | ||
2208 | 384 | DBG("parse_devices_reply OK"); | 271 | DBG("parse_devices_reply OK"); |
2209 | 385 | 272 | ||
2210 | 273 | /* TODO: handle removable batteries */ | ||
2211 | 274 | |||
2212 | 386 | if (battery_device_path == NULL) { | 275 | if (battery_device_path == NULL) { |
2213 | 387 | ofono_error("%s: no battery detected", __func__); | 276 | ofono_error("%s: no battery detected", __func__); |
2214 | 388 | goto done; | 277 | goto done; |
2215 | 389 | } | 278 | } |
2216 | 390 | 279 | ||
2217 | 280 | /* Always listen to PropertiesChanged for battery */ | ||
2218 | 281 | g_dbus_add_signal_watch(connection, UPOWER_SERVICE, battery_device_path, | ||
2219 | 282 | DBUS_INTERFACE_PROPERTIES, | ||
2220 | 283 | "PropertiesChanged", | ||
2221 | 284 | battery_props_changed, | ||
2222 | 285 | NULL, NULL); | ||
2223 | 286 | |||
2224 | 391 | modem_watch = __ofono_modemwatch_add(modemwatch, NULL, NULL); | 287 | modem_watch = __ofono_modemwatch_add(modemwatch, NULL, NULL); |
2225 | 392 | __ofono_modem_foreach(call_modemwatch, NULL); | 288 | __ofono_modem_foreach(call_modemwatch, NULL); |
2226 | 289 | |||
2227 | 393 | done: | 290 | done: |
2228 | 394 | if (reply) | 291 | if (reply) |
2229 | 395 | dbus_message_unref(reply); | 292 | dbus_message_unref(reply); |
2230 | @@ -449,9 +346,6 @@ | |||
2231 | 449 | upower_disconnect, | 346 | upower_disconnect, |
2232 | 450 | NULL, NULL); | 347 | NULL, NULL); |
2233 | 451 | 348 | ||
2234 | 452 | modem_hfp_watches = g_hash_table_new_full(g_str_hash, g_str_equal, | ||
2235 | 453 | g_free, NULL); | ||
2236 | 454 | |||
2237 | 455 | return 0; | 349 | return 0; |
2238 | 456 | } | 350 | } |
2239 | 457 | 351 | ||
2240 | @@ -465,8 +359,6 @@ | |||
2241 | 465 | 359 | ||
2242 | 466 | if (battery_device_path) | 360 | if (battery_device_path) |
2243 | 467 | g_free(battery_device_path); | 361 | g_free(battery_device_path); |
2244 | 468 | |||
2245 | 469 | g_hash_table_destroy(modem_hfp_watches); | ||
2246 | 470 | } | 362 | } |
2247 | 471 | 363 | ||
2248 | 472 | OFONO_PLUGIN_DEFINE(upower, "upower battery monitor", VERSION, | 364 | OFONO_PLUGIN_DEFINE(upower, "upower battery monitor", VERSION, |
2249 | 473 | 365 | ||
2250 | === modified file 'src/emulator.c' | |||
2251 | --- src/emulator.c 2015-11-27 16:53:45 +0000 | |||
2252 | +++ src/emulator.c 2016-03-14 09:03:03 +0000 | |||
2253 | @@ -37,6 +37,7 @@ | |||
2254 | 37 | #include "gatserver.h" | 37 | #include "gatserver.h" |
2255 | 38 | #include "gatppp.h" | 38 | #include "gatppp.h" |
2256 | 39 | #include "handsfree-audio.h" | 39 | #include "handsfree-audio.h" |
2257 | 40 | #include "system-settings.h" | ||
2258 | 40 | 41 | ||
2259 | 41 | #define RING_TIMEOUT 3 | 42 | #define RING_TIMEOUT 3 |
2260 | 42 | 43 | ||
2261 | @@ -1448,14 +1449,35 @@ | |||
2262 | 1448 | 1449 | ||
2263 | 1449 | static struct ofono_atom *get_preferred_atom(struct ofono_emulator *em) | 1450 | static struct ofono_atom *get_preferred_atom(struct ofono_emulator *em) |
2264 | 1450 | { | 1451 | { |
2265 | 1452 | char *path; | ||
2266 | 1453 | GSList *l; | ||
2267 | 1454 | struct ofono_atom *preferred = em->atoms->data; | ||
2268 | 1455 | |||
2269 | 1456 | path = __ofono_system_settings_get_string_value(PREFERRED_VOICE_MODEM); | ||
2270 | 1457 | if (path == NULL) | ||
2271 | 1458 | goto end; | ||
2272 | 1459 | |||
2273 | 1460 | for (l = em->atoms; l; l = l->next) { | ||
2274 | 1461 | struct ofono_atom *atom = l->data; | ||
2275 | 1462 | |||
2276 | 1463 | if (g_strcmp0(__ofono_atom_get_path(atom), path) == 0) { | ||
2277 | 1464 | preferred = atom; | ||
2278 | 1465 | break; | ||
2279 | 1466 | } | ||
2280 | 1467 | } | ||
2281 | 1468 | |||
2282 | 1469 | g_free(path); | ||
2283 | 1470 | |||
2284 | 1471 | end: | ||
2285 | 1472 | return preferred; | ||
2286 | 1473 | } | ||
2287 | 1474 | |||
2288 | 1475 | static struct ofono_atom *get_active_atom(struct ofono_emulator *em) | ||
2289 | 1476 | { | ||
2290 | 1451 | if (em->active_atom) | 1477 | if (em->active_atom) |
2291 | 1452 | return em->active_atom; | 1478 | return em->active_atom; |
2292 | 1453 | 1479 | ||
2298 | 1454 | /* | 1480 | return get_preferred_atom(em); |
2294 | 1455 | * TODO For the moment we just take the first on the list, we need to | ||
2295 | 1456 | * ask the modem and have something configurable from settings. | ||
2296 | 1457 | */ | ||
2297 | 1458 | return em->atoms->data; | ||
2299 | 1459 | } | 1481 | } |
2300 | 1460 | 1482 | ||
2301 | 1461 | static struct atom_callback *find_atom_callback(GSList *prefix_cbs, | 1483 | static struct atom_callback *find_atom_callback(GSList *prefix_cbs, |
2302 | @@ -1494,7 +1516,7 @@ | |||
2303 | 1494 | struct ofono_emulator_request req; | 1516 | struct ofono_emulator_request req; |
2304 | 1495 | struct ofono_atom *atom; | 1517 | struct ofono_atom *atom; |
2305 | 1496 | 1518 | ||
2307 | 1497 | atom = get_preferred_atom(h->em); | 1519 | atom = get_active_atom(h->em); |
2308 | 1498 | prefix_cbs = g_hash_table_lookup(h->em->prefixes, h->prefix); | 1520 | prefix_cbs = g_hash_table_lookup(h->em->prefixes, h->prefix); |
2309 | 1499 | atom_cb = find_atom_callback(prefix_cbs, atom); | 1521 | atom_cb = find_atom_callback(prefix_cbs, atom); |
2310 | 1500 | if (atom_cb == NULL) { | 1522 | if (atom_cb == NULL) { |
2311 | @@ -1689,11 +1711,7 @@ | |||
2312 | 1689 | } | 1711 | } |
2313 | 1690 | 1712 | ||
2314 | 1691 | /* Return FALSE if the modem is not the preferred one */ | 1713 | /* Return FALSE if the modem is not the preferred one */ |
2320 | 1692 | /* | 1714 | preferred = get_preferred_atom(em); |
2316 | 1693 | * TODO For the moment we just take the first on the list, we need to | ||
2317 | 1694 | * ask the modem and have some configurable from settings. | ||
2318 | 1695 | */ | ||
2319 | 1696 | preferred = em->atoms->data; | ||
2321 | 1697 | if (preferred == atom) | 1715 | if (preferred == atom) |
2322 | 1698 | return TRUE; | 1716 | return TRUE; |
2323 | 1699 | else | 1717 | else |
2324 | 1700 | 1718 | ||
2325 | === added file 'src/system-settings.c' | |||
2326 | --- src/system-settings.c 1970-01-01 00:00:00 +0000 | |||
2327 | +++ src/system-settings.c 2016-03-14 09:03:03 +0000 | |||
2328 | @@ -0,0 +1,74 @@ | |||
2329 | 1 | /* | ||
2330 | 2 | * | ||
2331 | 3 | * oFono - Open Source Telephony | ||
2332 | 4 | * | ||
2333 | 5 | * Copyright (C) 2016 Canonical Ltd. | ||
2334 | 6 | * | ||
2335 | 7 | * This program is free software; you can redistribute it and/or modify | ||
2336 | 8 | * it under the terms of the GNU General Public License version 2 as | ||
2337 | 9 | * published by the Free Software Foundation. | ||
2338 | 10 | * | ||
2339 | 11 | * This program is distributed in the hope that it will be useful, | ||
2340 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2341 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2342 | 14 | * GNU General Public License for more details. | ||
2343 | 15 | * | ||
2344 | 16 | * You should have received a copy of the GNU General Public License | ||
2345 | 17 | * along with this program; if not, write to the Free Software | ||
2346 | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
2347 | 19 | * | ||
2348 | 20 | */ | ||
2349 | 21 | |||
2350 | 22 | #ifdef HAVE_CONFIG_H | ||
2351 | 23 | #include <config.h> | ||
2352 | 24 | #endif | ||
2353 | 25 | |||
2354 | 26 | #include <errno.h> | ||
2355 | 27 | #include <string.h> | ||
2356 | 28 | #include <glib.h> | ||
2357 | 29 | #include "ofono.h" | ||
2358 | 30 | #include "system-settings.h" | ||
2359 | 31 | |||
2360 | 32 | static GSList *g_drivers = NULL; | ||
2361 | 33 | |||
2362 | 34 | char *__ofono_system_settings_get_string_value(const char *name) | ||
2363 | 35 | { | ||
2364 | 36 | GSList *d; | ||
2365 | 37 | char *value = NULL; | ||
2366 | 38 | |||
2367 | 39 | for (d = g_drivers; d != NULL; d = d->next) { | ||
2368 | 40 | const struct ofono_system_settings_driver *driver = d->data; | ||
2369 | 41 | |||
2370 | 42 | if (driver->get_string_value == NULL) | ||
2371 | 43 | continue; | ||
2372 | 44 | |||
2373 | 45 | DBG("Calling system settings plugin '%s'", driver->name); | ||
2374 | 46 | |||
2375 | 47 | value = driver->get_string_value(name); | ||
2376 | 48 | if (value == NULL) | ||
2377 | 49 | continue; | ||
2378 | 50 | |||
2379 | 51 | DBG("property %s value %s", name, value); | ||
2380 | 52 | |||
2381 | 53 | return value; | ||
2382 | 54 | } | ||
2383 | 55 | |||
2384 | 56 | return value; | ||
2385 | 57 | } | ||
2386 | 58 | |||
2387 | 59 | int ofono_system_settings_driver_register( | ||
2388 | 60 | struct ofono_system_settings_driver *driver) | ||
2389 | 61 | { | ||
2390 | 62 | DBG("driver: %p name: %s", driver, driver->name); | ||
2391 | 63 | |||
2392 | 64 | g_drivers = g_slist_prepend(g_drivers, driver); | ||
2393 | 65 | return 0; | ||
2394 | 66 | } | ||
2395 | 67 | |||
2396 | 68 | void ofono_system_settings_driver_unregister( | ||
2397 | 69 | const struct ofono_system_settings_driver *driver) | ||
2398 | 70 | { | ||
2399 | 71 | DBG("driver: %p name: %s", driver, driver->name); | ||
2400 | 72 | |||
2401 | 73 | g_drivers = g_slist_remove(g_drivers, driver); | ||
2402 | 74 | } | ||
2403 | 0 | 75 | ||
2404 | === modified file 'src/voicecall.c' | |||
2405 | --- src/voicecall.c 2016-01-15 16:03:09 +0000 | |||
2406 | +++ src/voicecall.c 2016-03-14 09:03:03 +0000 | |||
2407 | @@ -3463,9 +3463,11 @@ | |||
2408 | 3463 | char number[OFONO_MAX_PHONE_NUMBER_LENGTH + 1]; | 3463 | char number[OFONO_MAX_PHONE_NUMBER_LENGTH + 1]; |
2409 | 3464 | struct ofono_error result; | 3464 | struct ofono_error result; |
2410 | 3465 | 3465 | ||
2414 | 3466 | /* Make sure we keep the system awake if we get woken up | 3466 | /* |
2415 | 3467 | * shortly for processing the incoming request from the | 3467 | * If the device supports wakelocks, acquire one to |
2416 | 3468 | * HFP HF. */ | 3468 | * ensure the device is kept awake after being woken |
2417 | 3469 | * by an incoming request from the HFP HF. | ||
2418 | 3470 | */ | ||
2419 | 3469 | wakelock_system_lock(); | 3471 | wakelock_system_lock(); |
2420 | 3470 | 3472 | ||
2421 | 3471 | switch (ofono_emulator_request_get_type(req)) { | 3473 | switch (ofono_emulator_request_get_type(req)) { |
2422 | 3472 | 3474 | ||
2423 | === added file 'src/wakelock.c' | |||
2424 | --- src/wakelock.c 1970-01-01 00:00:00 +0000 | |||
2425 | +++ src/wakelock.c 2016-03-14 09:03:03 +0000 | |||
2426 | @@ -0,0 +1,152 @@ | |||
2427 | 1 | /* | ||
2428 | 2 | * | ||
2429 | 3 | * oFono - Open Source Telephony | ||
2430 | 4 | * | ||
2431 | 5 | * Copyright (C) 2015 Jolla Ltd. All rights reserved. | ||
2432 | 6 | * Contact: Hannu Mallat <hannu.mallat@jollamobile.com> | ||
2433 | 7 | * | ||
2434 | 8 | * This program is free software; you can redistribute it and/or modify | ||
2435 | 9 | * it under the terms of the GNU General Public License as published by | ||
2436 | 10 | * the Free Software Foundation; either version 2 of the License, or | ||
2437 | 11 | * (at your option) any later version. | ||
2438 | 12 | * | ||
2439 | 13 | * This program is distributed in the hope that it will be useful, | ||
2440 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2441 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2442 | 16 | * GNU General Public License for more details. | ||
2443 | 17 | * | ||
2444 | 18 | * You should have received a copy of the GNU General Public License | ||
2445 | 19 | * along with this program; if not, write to the Free Software | ||
2446 | 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
2447 | 21 | * | ||
2448 | 22 | */ | ||
2449 | 23 | |||
2450 | 24 | #ifdef HAVE_CONFIG_H | ||
2451 | 25 | #include <config.h> | ||
2452 | 26 | #endif | ||
2453 | 27 | |||
2454 | 28 | #include <errno.h> | ||
2455 | 29 | #include <string.h> | ||
2456 | 30 | #include <glib.h> | ||
2457 | 31 | |||
2458 | 32 | #include "log.h" | ||
2459 | 33 | #include "wakelock.h" | ||
2460 | 34 | #include "ofono.h" | ||
2461 | 35 | |||
2462 | 36 | #define SYSTEM_WAKELOCK_NAME "ofono-system" | ||
2463 | 37 | #define SYSTEM_WAKELOCK_DURATION 30 | ||
2464 | 38 | |||
2465 | 39 | static char *impl = NULL; | ||
2466 | 40 | static struct wakelock_table table; | ||
2467 | 41 | |||
2468 | 42 | static struct wakelock *system_wakelock = NULL; | ||
2469 | 43 | static guint system_wakelock_source = 0; | ||
2470 | 44 | |||
2471 | 45 | static gboolean system_wakelock_put(gpointer user_data) | ||
2472 | 46 | { | ||
2473 | 47 | DBG("Releasing system wakelock"); | ||
2474 | 48 | wakelock_release(system_wakelock); | ||
2475 | 49 | system_wakelock_source = 0; | ||
2476 | 50 | return FALSE; | ||
2477 | 51 | } | ||
2478 | 52 | |||
2479 | 53 | void wakelock_system_lock(void) | ||
2480 | 54 | { | ||
2481 | 55 | guint old_source; | ||
2482 | 56 | |||
2483 | 57 | if (impl == NULL) | ||
2484 | 58 | return; | ||
2485 | 59 | |||
2486 | 60 | DBG("Acquiring system wakelock"); | ||
2487 | 61 | |||
2488 | 62 | old_source = system_wakelock_source; | ||
2489 | 63 | |||
2490 | 64 | system_wakelock_source = g_timeout_add_seconds(SYSTEM_WAKELOCK_DURATION, | ||
2491 | 65 | system_wakelock_put, | ||
2492 | 66 | NULL); | ||
2493 | 67 | |||
2494 | 68 | if (system_wakelock_source) | ||
2495 | 69 | wakelock_acquire(system_wakelock); | ||
2496 | 70 | |||
2497 | 71 | if (old_source) { | ||
2498 | 72 | g_source_remove(old_source); | ||
2499 | 73 | wakelock_release(system_wakelock); | ||
2500 | 74 | } | ||
2501 | 75 | } | ||
2502 | 76 | |||
2503 | 77 | int wakelock_create(const char *name, struct wakelock **wakelock) | ||
2504 | 78 | { | ||
2505 | 79 | if (impl == NULL) { | ||
2506 | 80 | *wakelock = NULL; | ||
2507 | 81 | return -EINVAL; | ||
2508 | 82 | } | ||
2509 | 83 | |||
2510 | 84 | return (table.create)(name, wakelock); | ||
2511 | 85 | } | ||
2512 | 86 | |||
2513 | 87 | int wakelock_free(struct wakelock *wakelock) | ||
2514 | 88 | { | ||
2515 | 89 | if (impl == NULL) | ||
2516 | 90 | return -EINVAL; | ||
2517 | 91 | |||
2518 | 92 | return table.free(wakelock); | ||
2519 | 93 | } | ||
2520 | 94 | |||
2521 | 95 | int wakelock_acquire(struct wakelock *wakelock) | ||
2522 | 96 | { | ||
2523 | 97 | if (impl == NULL) | ||
2524 | 98 | return -EINVAL; | ||
2525 | 99 | |||
2526 | 100 | return table.acquire(wakelock); | ||
2527 | 101 | } | ||
2528 | 102 | |||
2529 | 103 | int wakelock_release(struct wakelock *wakelock) | ||
2530 | 104 | { | ||
2531 | 105 | if (impl == NULL) | ||
2532 | 106 | return -EINVAL; | ||
2533 | 107 | |||
2534 | 108 | return table.release(wakelock); | ||
2535 | 109 | } | ||
2536 | 110 | |||
2537 | 111 | ofono_bool_t wakelock_is_locked(struct wakelock *wakelock) { | ||
2538 | 112 | if (impl == NULL) | ||
2539 | 113 | return -EINVAL; | ||
2540 | 114 | |||
2541 | 115 | return table.is_locked(wakelock); | ||
2542 | 116 | } | ||
2543 | 117 | |||
2544 | 118 | int wakelock_plugin_register(const char *name, struct wakelock_table *fns) | ||
2545 | 119 | { | ||
2546 | 120 | if (impl) | ||
2547 | 121 | return -EALREADY; | ||
2548 | 122 | |||
2549 | 123 | impl = g_strdup(name); | ||
2550 | 124 | memcpy(&table, fns, sizeof(struct wakelock_table)); | ||
2551 | 125 | return 0; | ||
2552 | 126 | } | ||
2553 | 127 | |||
2554 | 128 | int wakelock_plugin_unregister(void) | ||
2555 | 129 | { | ||
2556 | 130 | if (impl == NULL) | ||
2557 | 131 | return -ENOENT; | ||
2558 | 132 | |||
2559 | 133 | memset(&table, 0, sizeof(struct wakelock_table)); | ||
2560 | 134 | g_free(impl); | ||
2561 | 135 | impl = NULL; | ||
2562 | 136 | |||
2563 | 137 | return 0; | ||
2564 | 138 | } | ||
2565 | 139 | |||
2566 | 140 | int __ofono_wakelock_init(void) | ||
2567 | 141 | { | ||
2568 | 142 | if (wakelock_create(SYSTEM_WAKELOCK_NAME, &system_wakelock) < 0) | ||
2569 | 143 | ofono_warn("Failed to create system keep alive wakelock"); | ||
2570 | 144 | |||
2571 | 145 | return 0; | ||
2572 | 146 | } | ||
2573 | 147 | |||
2574 | 148 | void __ofono_wakelock_cleanup(void) | ||
2575 | 149 | { | ||
2576 | 150 | if (system_wakelock) | ||
2577 | 151 | wakelock_free(system_wakelock); | ||
2578 | 152 | } | ||
2579 | 0 | 153 | ||
2580 | === removed file 'src/wakelock.c' | |||
2581 | --- src/wakelock.c 2016-01-15 16:03:09 +0000 | |||
2582 | +++ src/wakelock.c 1970-01-01 00:00:00 +0000 | |||
2583 | @@ -1,151 +0,0 @@ | |||
2584 | 1 | /* | ||
2585 | 2 | * | ||
2586 | 3 | * oFono - Open Source Telephony | ||
2587 | 4 | * | ||
2588 | 5 | * Copyright (C) 2015 Jolla Ltd. All rights reserved. | ||
2589 | 6 | * Contact: Hannu Mallat <hannu.mallat@jollamobile.com> | ||
2590 | 7 | * | ||
2591 | 8 | * This program is free software; you can redistribute it and/or modify | ||
2592 | 9 | * it under the terms of the GNU General Public License as published by | ||
2593 | 10 | * the Free Software Foundation; either version 2 of the License, or | ||
2594 | 11 | * (at your option) any later version. | ||
2595 | 12 | * | ||
2596 | 13 | * This program is distributed in the hope that it will be useful, | ||
2597 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2598 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2599 | 16 | * GNU General Public License for more details. | ||
2600 | 17 | * | ||
2601 | 18 | * You should have received a copy of the GNU General Public License | ||
2602 | 19 | * along with this program; if not, write to the Free Software | ||
2603 | 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
2604 | 21 | * | ||
2605 | 22 | */ | ||
2606 | 23 | |||
2607 | 24 | #ifdef HAVE_CONFIG_H | ||
2608 | 25 | #include <config.h> | ||
2609 | 26 | #endif | ||
2610 | 27 | |||
2611 | 28 | #include <errno.h> | ||
2612 | 29 | #include <string.h> | ||
2613 | 30 | #include <glib.h> | ||
2614 | 31 | |||
2615 | 32 | #include "log.h" | ||
2616 | 33 | #include "wakelock.h" | ||
2617 | 34 | #include "ofono.h" | ||
2618 | 35 | |||
2619 | 36 | #define SYSTEM_WAKELOCK_NAME "ofono-system" | ||
2620 | 37 | #define SYSTEM_WAKELOCK_DURATION 30 | ||
2621 | 38 | |||
2622 | 39 | static char *impl = NULL; | ||
2623 | 40 | static struct wakelock_table table; | ||
2624 | 41 | |||
2625 | 42 | static struct wakelock *system_wakelock = NULL; | ||
2626 | 43 | static guint system_wakelock_source = 0; | ||
2627 | 44 | |||
2628 | 45 | static gboolean system_wakelock_put(gpointer user_data) | ||
2629 | 46 | { | ||
2630 | 47 | DBG("Releasing system wakelock"); | ||
2631 | 48 | wakelock_release(system_wakelock); | ||
2632 | 49 | system_wakelock_source = 0; | ||
2633 | 50 | return FALSE; | ||
2634 | 51 | } | ||
2635 | 52 | |||
2636 | 53 | void wakelock_system_lock(void) | ||
2637 | 54 | { | ||
2638 | 55 | guint old_source; | ||
2639 | 56 | |||
2640 | 57 | if (!impl) | ||
2641 | 58 | return; | ||
2642 | 59 | |||
2643 | 60 | DBG("Acquiring system wakelock"); | ||
2644 | 61 | |||
2645 | 62 | old_source = system_wakelock_source; | ||
2646 | 63 | |||
2647 | 64 | system_wakelock_source = g_timeout_add_seconds(SYSTEM_WAKELOCK_DURATION, | ||
2648 | 65 | system_wakelock_put, | ||
2649 | 66 | NULL); | ||
2650 | 67 | if (system_wakelock_source) | ||
2651 | 68 | wakelock_acquire(system_wakelock); | ||
2652 | 69 | |||
2653 | 70 | if (old_source) { | ||
2654 | 71 | g_source_remove(old_source); | ||
2655 | 72 | wakelock_release(system_wakelock); | ||
2656 | 73 | } | ||
2657 | 74 | } | ||
2658 | 75 | |||
2659 | 76 | int wakelock_create(const char *name, struct wakelock **wakelock) | ||
2660 | 77 | { | ||
2661 | 78 | if (!impl) { | ||
2662 | 79 | *wakelock = NULL; | ||
2663 | 80 | return -EINVAL; | ||
2664 | 81 | } | ||
2665 | 82 | |||
2666 | 83 | return (table.create)(name, wakelock); | ||
2667 | 84 | } | ||
2668 | 85 | |||
2669 | 86 | int wakelock_free(struct wakelock *wakelock) | ||
2670 | 87 | { | ||
2671 | 88 | if (!impl) | ||
2672 | 89 | return -EINVAL; | ||
2673 | 90 | |||
2674 | 91 | return table.free(wakelock); | ||
2675 | 92 | } | ||
2676 | 93 | |||
2677 | 94 | int wakelock_acquire(struct wakelock *wakelock) | ||
2678 | 95 | { | ||
2679 | 96 | if (!impl) | ||
2680 | 97 | return -EINVAL; | ||
2681 | 98 | |||
2682 | 99 | return table.acquire(wakelock); | ||
2683 | 100 | } | ||
2684 | 101 | |||
2685 | 102 | int wakelock_release(struct wakelock *wakelock) | ||
2686 | 103 | { | ||
2687 | 104 | if (!impl) | ||
2688 | 105 | return -EINVAL; | ||
2689 | 106 | |||
2690 | 107 | return table.release(wakelock); | ||
2691 | 108 | } | ||
2692 | 109 | |||
2693 | 110 | ofono_bool_t wakelock_is_locked(struct wakelock *wakelock) { | ||
2694 | 111 | if (!impl) | ||
2695 | 112 | return -EINVAL; | ||
2696 | 113 | |||
2697 | 114 | return table.is_locked(wakelock); | ||
2698 | 115 | } | ||
2699 | 116 | |||
2700 | 117 | int wakelock_plugin_register(const char *name, struct wakelock_table *fns) | ||
2701 | 118 | { | ||
2702 | 119 | if (impl) | ||
2703 | 120 | return -EALREADY; | ||
2704 | 121 | |||
2705 | 122 | impl = g_strdup(name); | ||
2706 | 123 | memcpy(&table, fns, sizeof(struct wakelock_table)); | ||
2707 | 124 | return 0; | ||
2708 | 125 | } | ||
2709 | 126 | |||
2710 | 127 | int wakelock_plugin_unregister(void) | ||
2711 | 128 | { | ||
2712 | 129 | if (!impl) | ||
2713 | 130 | return -ENOENT; | ||
2714 | 131 | |||
2715 | 132 | memset(&table, 0, sizeof(struct wakelock_table)); | ||
2716 | 133 | g_free(impl); | ||
2717 | 134 | impl = NULL; | ||
2718 | 135 | |||
2719 | 136 | return 0; | ||
2720 | 137 | } | ||
2721 | 138 | |||
2722 | 139 | int __ofono_wakelock_init(void) | ||
2723 | 140 | { | ||
2724 | 141 | if (wakelock_create(SYSTEM_WAKELOCK_NAME, &system_wakelock) < 0) | ||
2725 | 142 | ofono_warn("Failed to create system keep alive wakelock"); | ||
2726 | 143 | |||
2727 | 144 | return 0; | ||
2728 | 145 | } | ||
2729 | 146 | |||
2730 | 147 | void __ofono_wakelock_cleanup(void) | ||
2731 | 148 | { | ||
2732 | 149 | if (system_wakelock) | ||
2733 | 150 | wakelock_free(system_wakelock); | ||
2734 | 151 | } | ||
2735 | 152 | 0 | ||
2736 | === added file 'unit/rilmodem-test-server.c' | |||
2737 | --- unit/rilmodem-test-server.c 1970-01-01 00:00:00 +0000 | |||
2738 | +++ unit/rilmodem-test-server.c 2016-03-14 09:03:03 +0000 | |||
2739 | @@ -0,0 +1,237 @@ | |||
2740 | 1 | /* | ||
2741 | 2 | * | ||
2742 | 3 | * oFono - Open Source Telephony | ||
2743 | 4 | * | ||
2744 | 5 | * Copyright (C) 2015 Canonical Ltd. | ||
2745 | 6 | * | ||
2746 | 7 | * This program is free software; you can redistribute it and/or modify | ||
2747 | 8 | * it under the terms of the GNU General Public License version 2 as | ||
2748 | 9 | * published by the Free Software Foundation. | ||
2749 | 10 | * | ||
2750 | 11 | * This program is distributed in the hope that it will be useful, | ||
2751 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2752 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2753 | 14 | * GNU General Public License for more details. | ||
2754 | 15 | * | ||
2755 | 16 | * You should have received a copy of the GNU General Public License | ||
2756 | 17 | * along with this program; if not, write to the Free Software | ||
2757 | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
2758 | 19 | * | ||
2759 | 20 | */ | ||
2760 | 21 | |||
2761 | 22 | #ifdef HAVE_CONFIG_H | ||
2762 | 23 | #include <config.h> | ||
2763 | 24 | #endif | ||
2764 | 25 | |||
2765 | 26 | #define _GNU_SOURCE | ||
2766 | 27 | #include <stdio.h> | ||
2767 | 28 | #include <netinet/in.h> | ||
2768 | 29 | #include <sys/socket.h> | ||
2769 | 30 | #include <sys/un.h> | ||
2770 | 31 | #include <unistd.h> | ||
2771 | 32 | |||
2772 | 33 | #include <ofono/types.h> | ||
2773 | 34 | |||
2774 | 35 | #include <gril.h> | ||
2775 | 36 | |||
2776 | 37 | #include "rilmodem-test-server.h" | ||
2777 | 38 | |||
2778 | 39 | #define MAX_REQUEST_SIZE 4096 | ||
2779 | 40 | #define RIL_SERVER_SOCK_PATH "/tmp/unittestril" | ||
2780 | 41 | |||
2781 | 42 | struct server_data { | ||
2782 | 43 | int server_sk; | ||
2783 | 44 | ConnectFunc connect_func; | ||
2784 | 45 | GIOChannel *server_io; | ||
2785 | 46 | char *sock_name; | ||
2786 | 47 | const struct rilmodem_test_data *rtd; | ||
2787 | 48 | void *user_data; | ||
2788 | 49 | }; | ||
2789 | 50 | |||
2790 | 51 | /* Warning: length is stored in network order */ | ||
2791 | 52 | struct rsp_hdr { | ||
2792 | 53 | uint32_t length; | ||
2793 | 54 | uint32_t unsolicited; | ||
2794 | 55 | uint32_t serial; | ||
2795 | 56 | uint32_t error; | ||
2796 | 57 | }; | ||
2797 | 58 | |||
2798 | 59 | static gboolean read_server(gpointer data) | ||
2799 | 60 | { | ||
2800 | 61 | struct server_data *sd = data; | ||
2801 | 62 | GIOStatus status; | ||
2802 | 63 | gsize offset, rbytes, wbytes; | ||
2803 | 64 | gchar *buf, *bufp; | ||
2804 | 65 | uint32_t req_serial; | ||
2805 | 66 | struct rsp_hdr rsp; | ||
2806 | 67 | |||
2807 | 68 | buf = g_malloc0(MAX_REQUEST_SIZE); | ||
2808 | 69 | |||
2809 | 70 | status = g_io_channel_read_chars(sd->server_io, buf, MAX_REQUEST_SIZE, | ||
2810 | 71 | &rbytes, NULL); | ||
2811 | 72 | g_assert(status == G_IO_STATUS_NORMAL); | ||
2812 | 73 | g_assert(rbytes == sd->rtd->req_size); | ||
2813 | 74 | |||
2814 | 75 | /* validate len, and request_id */ | ||
2815 | 76 | g_assert(!memcmp(buf, sd->rtd->req_data, (sizeof(uint32_t) * 2))); | ||
2816 | 77 | |||
2817 | 78 | /* | ||
2818 | 79 | * header: size (uint32), reqid (uin32), serial (uint32) | ||
2819 | 80 | * header size == 16 ( excludes sizeof(size) ) | ||
2820 | 81 | */ | ||
2821 | 82 | |||
2822 | 83 | /* advance past request_no */ | ||
2823 | 84 | bufp = buf + (sizeof(uint32_t) * 2); | ||
2824 | 85 | |||
2825 | 86 | req_serial = (uint32_t) *bufp; | ||
2826 | 87 | |||
2827 | 88 | /* advance past serial_no */ | ||
2828 | 89 | bufp += sizeof(uint32_t); | ||
2829 | 90 | |||
2830 | 91 | /* validate the rest of the parcel... */ | ||
2831 | 92 | offset = (sizeof(uint32_t) * 3); | ||
2832 | 93 | g_assert(!memcmp(bufp, sd->rtd->req_data + offset, | ||
2833 | 94 | sd->rtd->req_size - offset)); | ||
2834 | 95 | |||
2835 | 96 | /* Length does not include the length field. Network order. */ | ||
2836 | 97 | rsp.length = htonl(sizeof(rsp) - sizeof(rsp.length) + | ||
2837 | 98 | sd->rtd->rsp_size); | ||
2838 | 99 | rsp.unsolicited = 0; | ||
2839 | 100 | rsp.serial = req_serial; | ||
2840 | 101 | rsp.error = sd->rtd->rsp_error; | ||
2841 | 102 | |||
2842 | 103 | /* copy header */ | ||
2843 | 104 | memcpy(buf, &rsp, sizeof(rsp)); | ||
2844 | 105 | |||
2845 | 106 | if (sd->rtd->rsp_size) { | ||
2846 | 107 | bufp = buf + sizeof(rsp); | ||
2847 | 108 | |||
2848 | 109 | memcpy(bufp, sd->rtd->rsp_data, sd->rtd->rsp_size); | ||
2849 | 110 | } | ||
2850 | 111 | |||
2851 | 112 | status = g_io_channel_write_chars(sd->server_io, | ||
2852 | 113 | buf, | ||
2853 | 114 | sizeof(rsp) + sd->rtd->rsp_size, | ||
2854 | 115 | &wbytes, NULL); | ||
2855 | 116 | |||
2856 | 117 | /* FIXME: assert wbytes is correct */ | ||
2857 | 118 | |||
2858 | 119 | g_assert(status == G_IO_STATUS_NORMAL); | ||
2859 | 120 | |||
2860 | 121 | g_free(buf); | ||
2861 | 122 | g_io_channel_unref(sd->server_io); | ||
2862 | 123 | |||
2863 | 124 | return FALSE; | ||
2864 | 125 | } | ||
2865 | 126 | |||
2866 | 127 | static gboolean on_socket_connected(GIOChannel *chan, GIOCondition cond, | ||
2867 | 128 | gpointer data) | ||
2868 | 129 | { | ||
2869 | 130 | struct server_data *sd = data; | ||
2870 | 131 | struct sockaddr saddr; | ||
2871 | 132 | unsigned int len = sizeof(saddr); | ||
2872 | 133 | int fd; | ||
2873 | 134 | GIOStatus status; | ||
2874 | 135 | |||
2875 | 136 | g_assert(cond == G_IO_IN); | ||
2876 | 137 | |||
2877 | 138 | fd = accept(sd->server_sk, &saddr, &len); | ||
2878 | 139 | g_assert(fd != -1); | ||
2879 | 140 | |||
2880 | 141 | sd->server_io = g_io_channel_unix_new(fd); | ||
2881 | 142 | g_assert(sd->server_io != NULL); | ||
2882 | 143 | |||
2883 | 144 | status = g_io_channel_set_encoding(sd->server_io, NULL, NULL); | ||
2884 | 145 | g_assert(status == G_IO_STATUS_NORMAL); | ||
2885 | 146 | |||
2886 | 147 | g_io_channel_set_buffered(sd->server_io, FALSE); | ||
2887 | 148 | g_io_channel_set_close_on_unref(sd->server_io, TRUE); | ||
2888 | 149 | |||
2889 | 150 | if (sd->connect_func) | ||
2890 | 151 | sd->connect_func(sd->user_data); | ||
2891 | 152 | |||
2892 | 153 | if (sd->rtd->unsol_test == FALSE) | ||
2893 | 154 | g_idle_add(read_server, sd); | ||
2894 | 155 | |||
2895 | 156 | return FALSE; | ||
2896 | 157 | } | ||
2897 | 158 | |||
2898 | 159 | void rilmodem_test_server_close(struct server_data *sd) | ||
2899 | 160 | { | ||
2900 | 161 | g_assert(sd->server_sk); | ||
2901 | 162 | close(sd->server_sk); | ||
2902 | 163 | remove(sd->sock_name); | ||
2903 | 164 | g_free(sd->sock_name); | ||
2904 | 165 | g_free(sd); | ||
2905 | 166 | } | ||
2906 | 167 | |||
2907 | 168 | struct server_data *rilmodem_test_server_create(ConnectFunc connect, | ||
2908 | 169 | const struct rilmodem_test_data *test_data, | ||
2909 | 170 | void *data) | ||
2910 | 171 | { | ||
2911 | 172 | GIOChannel *io; | ||
2912 | 173 | struct sockaddr_un addr; | ||
2913 | 174 | int retval; | ||
2914 | 175 | struct server_data *sd; | ||
2915 | 176 | |||
2916 | 177 | sd = g_new0(struct server_data, 1); | ||
2917 | 178 | |||
2918 | 179 | sd->connect_func = connect; | ||
2919 | 180 | sd->user_data = data; | ||
2920 | 181 | sd->rtd = test_data; | ||
2921 | 182 | |||
2922 | 183 | sd->server_sk = socket(AF_UNIX, SOCK_STREAM, 0); | ||
2923 | 184 | g_assert(sd->server_sk); | ||
2924 | 185 | |||
2925 | 186 | sd->sock_name = | ||
2926 | 187 | g_strdup_printf(RIL_SERVER_SOCK_PATH"%u", (unsigned) getpid()); | ||
2927 | 188 | |||
2928 | 189 | memset(&addr, 0, sizeof(addr)); | ||
2929 | 190 | addr.sun_family = AF_UNIX; | ||
2930 | 191 | strncpy(addr.sun_path, sd->sock_name, sizeof(addr.sun_path) - 1); | ||
2931 | 192 | |||
2932 | 193 | /* Unlink any existing socket for this session */ | ||
2933 | 194 | unlink(addr.sun_path); | ||
2934 | 195 | |||
2935 | 196 | retval = bind(sd->server_sk, (struct sockaddr *) &addr, sizeof(addr)); | ||
2936 | 197 | g_assert(retval >= 0); | ||
2937 | 198 | |||
2938 | 199 | retval = listen(sd->server_sk, 0); | ||
2939 | 200 | g_assert(retval >= 0); | ||
2940 | 201 | |||
2941 | 202 | io = g_io_channel_unix_new(sd->server_sk); | ||
2942 | 203 | g_assert(io != NULL); | ||
2943 | 204 | |||
2944 | 205 | g_io_channel_set_close_on_unref(io, TRUE); | ||
2945 | 206 | g_io_add_watch_full(io, G_PRIORITY_DEFAULT, | ||
2946 | 207 | G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, | ||
2947 | 208 | on_socket_connected, sd, NULL); | ||
2948 | 209 | |||
2949 | 210 | g_io_channel_unref(io); | ||
2950 | 211 | |||
2951 | 212 | return sd; | ||
2952 | 213 | } | ||
2953 | 214 | |||
2954 | 215 | void rilmodem_test_server_write(struct server_data *sd, | ||
2955 | 216 | const unsigned char *buf, | ||
2956 | 217 | const size_t buf_len) | ||
2957 | 218 | { | ||
2958 | 219 | GIOStatus status; | ||
2959 | 220 | gsize wbytes; | ||
2960 | 221 | |||
2961 | 222 | status = g_io_channel_write_chars(sd->server_io, | ||
2962 | 223 | (const char *) buf, | ||
2963 | 224 | buf_len, | ||
2964 | 225 | &wbytes, NULL); | ||
2965 | 226 | |||
2966 | 227 | g_assert(status == G_IO_STATUS_NORMAL); | ||
2967 | 228 | |||
2968 | 229 | status = g_io_channel_flush(sd->server_io, NULL); | ||
2969 | 230 | |||
2970 | 231 | g_assert(status == G_IO_STATUS_NORMAL); | ||
2971 | 232 | } | ||
2972 | 233 | |||
2973 | 234 | const char *rilmodem_test_get_socket_name(struct server_data *sd) | ||
2974 | 235 | { | ||
2975 | 236 | return sd->sock_name; | ||
2976 | 237 | } | ||
2977 | 0 | 238 | ||
2978 | === added file 'unit/rilmodem-test-server.h' | |||
2979 | --- unit/rilmodem-test-server.h 1970-01-01 00:00:00 +0000 | |||
2980 | +++ unit/rilmodem-test-server.h 2016-03-14 09:03:03 +0000 | |||
2981 | @@ -0,0 +1,47 @@ | |||
2982 | 1 | /* | ||
2983 | 2 | * | ||
2984 | 3 | * oFono - Open Source Telephony | ||
2985 | 4 | * | ||
2986 | 5 | * Copyright (C) 2015 Canonical Ltd. | ||
2987 | 6 | * | ||
2988 | 7 | * This program is free software; you can redistribute it and/or modify | ||
2989 | 8 | * it under the terms of the GNU General Public License version 2 as | ||
2990 | 9 | * published by the Free Software Foundation. | ||
2991 | 10 | * | ||
2992 | 11 | * This program is distributed in the hope that it will be useful, | ||
2993 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2994 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2995 | 14 | * GNU General Public License for more details. | ||
2996 | 15 | * | ||
2997 | 16 | * You should have received a copy of the GNU General Public License | ||
2998 | 17 | * along with this program; if not, write to the Free Software | ||
2999 | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
3000 | 19 | * | ||
3001 | 20 | */ | ||
3002 | 21 | |||
3003 | 22 | struct server_data; | ||
3004 | 23 | |||
3005 | 24 | struct rilmodem_test_data { | ||
3006 | 25 | const unsigned char *req_data; | ||
3007 | 26 | |||
3008 | 27 | const size_t req_size; | ||
3009 | 28 | |||
3010 | 29 | uint32_t rsp_error; | ||
3011 | 30 | const unsigned char *rsp_data; | ||
3012 | 31 | const size_t rsp_size; | ||
3013 | 32 | gboolean unsol_test; | ||
3014 | 33 | }; | ||
3015 | 34 | |||
3016 | 35 | typedef void (*ConnectFunc)(void *data); | ||
3017 | 36 | |||
3018 | 37 | void rilmodem_test_server_close(struct server_data *sd); | ||
3019 | 38 | |||
3020 | 39 | struct server_data *rilmodem_test_server_create(ConnectFunc connect, | ||
3021 | 40 | const struct rilmodem_test_data *test_data, | ||
3022 | 41 | void *data); | ||
3023 | 42 | |||
3024 | 43 | void rilmodem_test_server_write(struct server_data *sd, | ||
3025 | 44 | const unsigned char *buf, | ||
3026 | 45 | const size_t buf_len); | ||
3027 | 46 | |||
3028 | 47 | const char *rilmodem_test_get_socket_name(struct server_data *sd); | ||
3029 | 0 | 48 | ||
3030 | === modified file 'unit/test-grilreply.c' | |||
3031 | --- unit/test-grilreply.c 2015-10-07 07:14:11 +0000 | |||
3032 | +++ unit/test-grilreply.c 2016-03-14 09:03:03 +0000 | |||
3033 | @@ -1420,7 +1420,7 @@ | |||
3034 | 1420 | * RIL_REQUEST_SET_FACILITY_LOCK reply with no parameters. | 1420 | * RIL_REQUEST_SET_FACILITY_LOCK reply with no parameters. |
3035 | 1421 | */ | 1421 | */ |
3036 | 1422 | static const struct set_facility_lock_test reply_set_facility_lock_valid_1 = { | 1422 | static const struct set_facility_lock_test reply_set_facility_lock_valid_1 = { |
3038 | 1423 | .retries = -1, | 1423 | .retries = 0, |
3039 | 1424 | .msg = { | 1424 | .msg = { |
3040 | 1425 | .buf = NULL, | 1425 | .buf = NULL, |
3041 | 1426 | .buf_len = 0, | 1426 | .buf_len = 0, |
3042 | @@ -1686,7 +1686,7 @@ | |||
3043 | 1686 | 1686 | ||
3044 | 1687 | reason = g_ril_reply_parse_call_fail_cause(NULL, data); | 1687 | reason = g_ril_reply_parse_call_fail_cause(NULL, data); |
3045 | 1688 | 1688 | ||
3047 | 1689 | g_assert(reason >= 0); | 1689 | g_assert(reason == OFONO_DISCONNECT_REASON_REMOTE_HANGUP); |
3048 | 1690 | } | 1690 | } |
3049 | 1691 | 1691 | ||
3050 | 1692 | static void test_reply_get_mute_off(gconstpointer data) | 1692 | static void test_reply_get_mute_off(gconstpointer data) |
3051 | 1693 | 1693 | ||
3052 | === modified file 'unit/test-grilunsol.c' | |||
3053 | --- unit/test-grilunsol.c 2014-08-19 16:29:51 +0000 | |||
3054 | +++ unit/test-grilunsol.c 2016-03-14 09:03:03 +0000 | |||
3055 | @@ -525,6 +525,115 @@ | |||
3056 | 525 | .error = 0, | 525 | .error = 0, |
3057 | 526 | }; | 526 | }; |
3058 | 527 | 527 | ||
3059 | 528 | /* | ||
3060 | 529 | * The following hexadecimal data represents a serialized Binder parcel | ||
3061 | 530 | * instance containing a valid RIL_UNSOL_RIL_CONNECTED message with the | ||
3062 | 531 | * following parameters: | ||
3063 | 532 | * | ||
3064 | 533 | * [1, 10] | ||
3065 | 534 | */ | ||
3066 | 535 | static const guchar unsol_on_ril_connected_valid_parcel1[] = { | ||
3067 | 536 | 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 | ||
3068 | 537 | }; | ||
3069 | 538 | |||
3070 | 539 | static const struct ril_msg unsol_on_ril_connected_valid_1 = { | ||
3071 | 540 | .buf = (gchar *) &unsol_on_ril_connected_valid_parcel1, | ||
3072 | 541 | .buf_len = sizeof(unsol_on_ril_connected_valid_parcel1), | ||
3073 | 542 | .unsolicited = TRUE, | ||
3074 | 543 | .req = RIL_UNSOL_RIL_CONNECTED, | ||
3075 | 544 | .serial_no = 0, | ||
3076 | 545 | .error = 0, | ||
3077 | 546 | }; | ||
3078 | 547 | |||
3079 | 548 | /* | ||
3080 | 549 | * The following hexadecimal data represents a serialized Binder parcel | ||
3081 | 550 | * instance containing a valid RIL_UNSOL_RIL_CONNECTED message with the | ||
3082 | 551 | * following parameters: | ||
3083 | 552 | * | ||
3084 | 553 | * [2, 10, 11] | ||
3085 | 554 | */ | ||
3086 | 555 | static const guchar unsol_on_ril_connected_valid_parcel2[] = { | ||
3087 | 556 | 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00 | ||
3088 | 557 | }; | ||
3089 | 558 | |||
3090 | 559 | static const struct ril_msg unsol_on_ril_connected_valid_2 = { | ||
3091 | 560 | .buf = (gchar *) &unsol_on_ril_connected_valid_parcel2, | ||
3092 | 561 | .buf_len = sizeof(unsol_on_ril_connected_valid_parcel2), | ||
3093 | 562 | .unsolicited = TRUE, | ||
3094 | 563 | .req = RIL_UNSOL_RIL_CONNECTED, | ||
3095 | 564 | .serial_no = 0, | ||
3096 | 565 | .error = 0, | ||
3097 | 566 | }; | ||
3098 | 567 | |||
3099 | 568 | /* | ||
3100 | 569 | * The following hexadecimal data represents a serialized Binder parcel | ||
3101 | 570 | * instance containing a valid RIL_UNSOL_RIL_CONNECTED message with the | ||
3102 | 571 | * following parameters: | ||
3103 | 572 | * | ||
3104 | 573 | * [1, 10, 11] | ||
3105 | 574 | */ | ||
3106 | 575 | static const guchar unsol_on_ril_connected_valid_parcel3[] = { | ||
3107 | 576 | 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00 | ||
3108 | 577 | }; | ||
3109 | 578 | |||
3110 | 579 | static const struct ril_msg unsol_on_ril_connected_valid_3 = { | ||
3111 | 580 | .buf = (gchar *) &unsol_on_ril_connected_valid_parcel3, | ||
3112 | 581 | .buf_len = sizeof(unsol_on_ril_connected_valid_parcel3), | ||
3113 | 582 | .unsolicited = TRUE, | ||
3114 | 583 | .req = RIL_UNSOL_RIL_CONNECTED, | ||
3115 | 584 | .serial_no = 0, | ||
3116 | 585 | .error = 0, | ||
3117 | 586 | }; | ||
3118 | 587 | |||
3119 | 588 | static const struct ril_msg unsol_on_ril_connected_invalid_1 = { | ||
3120 | 589 | .buf = "", | ||
3121 | 590 | .buf_len = 0, | ||
3122 | 591 | .unsolicited = TRUE, | ||
3123 | 592 | .req = RIL_UNSOL_RIL_CONNECTED, | ||
3124 | 593 | .serial_no = 0, | ||
3125 | 594 | .error = 0, | ||
3126 | 595 | }; | ||
3127 | 596 | |||
3128 | 597 | /* | ||
3129 | 598 | * The following hexadecimal data represents a serialized Binder parcel | ||
3130 | 599 | * instance containing an invalid RIL_UNSOL_RIL_CONNECTED message with the | ||
3131 | 600 | * following parameters: | ||
3132 | 601 | * | ||
3133 | 602 | * [0] | ||
3134 | 603 | */ | ||
3135 | 604 | static const guchar unsol_on_ril_connected_invalid_parcel2[] = { | ||
3136 | 605 | 0x00, 0x00, 0x00, 0x00 | ||
3137 | 606 | }; | ||
3138 | 607 | |||
3139 | 608 | static const struct ril_msg unsol_on_ril_connected_invalid_2 = { | ||
3140 | 609 | .buf = (gchar *) &unsol_on_ril_connected_invalid_parcel2, | ||
3141 | 610 | .buf_len = sizeof(unsol_on_ril_connected_invalid_parcel2), | ||
3142 | 611 | .unsolicited = TRUE, | ||
3143 | 612 | .req = RIL_UNSOL_RIL_CONNECTED, | ||
3144 | 613 | .serial_no = 0, | ||
3145 | 614 | .error = 0, | ||
3146 | 615 | }; | ||
3147 | 616 | |||
3148 | 617 | /* | ||
3149 | 618 | * The following hexadecimal data represents a serialized Binder parcel | ||
3150 | 619 | * instance containing an invalid RIL_UNSOL_RIL_CONNECTED message with the | ||
3151 | 620 | * following parameters: | ||
3152 | 621 | * | ||
3153 | 622 | * [1] | ||
3154 | 623 | */ | ||
3155 | 624 | static const guchar unsol_on_ril_connected_invalid_parcel3[] = { | ||
3156 | 625 | 0x01, 0x00, 0x00, 0x00 | ||
3157 | 626 | }; | ||
3158 | 627 | |||
3159 | 628 | static const struct ril_msg unsol_on_ril_connected_invalid_3 = { | ||
3160 | 629 | .buf = (gchar *) &unsol_on_ril_connected_invalid_parcel3, | ||
3161 | 630 | .buf_len = sizeof(unsol_on_ril_connected_invalid_parcel3), | ||
3162 | 631 | .unsolicited = TRUE, | ||
3163 | 632 | .req = RIL_UNSOL_RIL_CONNECTED, | ||
3164 | 633 | .serial_no = 0, | ||
3165 | 634 | .error = 0, | ||
3166 | 635 | }; | ||
3167 | 636 | |||
3168 | 528 | static void test_reply_data_call_invalid(gconstpointer data) | 637 | static void test_reply_data_call_invalid(gconstpointer data) |
3169 | 529 | { | 638 | { |
3170 | 530 | struct ril_data_call_list *call_list; | 639 | struct ril_data_call_list *call_list; |
3171 | @@ -599,6 +708,24 @@ | |||
3172 | 599 | g_assert(unsol != NULL); | 708 | g_assert(unsol != NULL); |
3173 | 600 | g_ril_unsol_free_ussd(unsol); | 709 | g_ril_unsol_free_ussd(unsol); |
3174 | 601 | } | 710 | } |
3175 | 711 | |||
3176 | 712 | static void test_unsol_on_ril_connected_valid(gconstpointer data) | ||
3177 | 713 | { | ||
3178 | 714 | int version; | ||
3179 | 715 | |||
3180 | 716 | version = g_ril_unsol_parse_connected(NULL, (struct ril_msg *) data); | ||
3181 | 717 | |||
3182 | 718 | g_assert(version == 10); | ||
3183 | 719 | } | ||
3184 | 720 | |||
3185 | 721 | static void test_unsol_on_ril_connected_invalid(gconstpointer data) | ||
3186 | 722 | { | ||
3187 | 723 | int version; | ||
3188 | 724 | |||
3189 | 725 | version = g_ril_unsol_parse_connected(NULL, (struct ril_msg *) data); | ||
3190 | 726 | |||
3191 | 727 | g_assert(version == RIL_VERSION_UNSPECIFIED); | ||
3192 | 728 | } | ||
3193 | 602 | #endif | 729 | #endif |
3194 | 603 | 730 | ||
3195 | 604 | int main(int argc, char **argv) | 731 | int main(int argc, char **argv) |
3196 | @@ -693,6 +820,36 @@ | |||
3197 | 693 | &unsol_on_ussd_valid_1, | 820 | &unsol_on_ussd_valid_1, |
3198 | 694 | test_unsol_on_ussd_valid); | 821 | test_unsol_on_ussd_valid); |
3199 | 695 | 822 | ||
3200 | 823 | g_test_add_data_func("/testgrilunsol/ril-connected: " | ||
3201 | 824 | "valid RIL_CONNECTED Test 1", | ||
3202 | 825 | &unsol_on_ril_connected_valid_1, | ||
3203 | 826 | test_unsol_on_ril_connected_valid); | ||
3204 | 827 | |||
3205 | 828 | g_test_add_data_func("/testgrilunsol/ril-connected: " | ||
3206 | 829 | "valid RIL_CONNECTED Test 2", | ||
3207 | 830 | &unsol_on_ril_connected_valid_2, | ||
3208 | 831 | test_unsol_on_ril_connected_valid); | ||
3209 | 832 | |||
3210 | 833 | g_test_add_data_func("/testgrilunsol/ril-connected: " | ||
3211 | 834 | "valid RIL_CONNECTED Test 3", | ||
3212 | 835 | &unsol_on_ril_connected_valid_3, | ||
3213 | 836 | test_unsol_on_ril_connected_valid); | ||
3214 | 837 | |||
3215 | 838 | g_test_add_data_func("/testgrilunsol/ril-connected: " | ||
3216 | 839 | "invalid RIL_CONNECTED Test 1", | ||
3217 | 840 | &unsol_on_ril_connected_invalid_1, | ||
3218 | 841 | test_unsol_on_ril_connected_invalid); | ||
3219 | 842 | |||
3220 | 843 | g_test_add_data_func("/testgrilunsol/ril-connected: " | ||
3221 | 844 | "invalid RIL_CONNECTED Test 2", | ||
3222 | 845 | &unsol_on_ril_connected_invalid_2, | ||
3223 | 846 | test_unsol_on_ril_connected_invalid); | ||
3224 | 847 | |||
3225 | 848 | g_test_add_data_func("/testgrilunsol/ril-connected: " | ||
3226 | 849 | "invalid RIL_CONNECTED Test 3", | ||
3227 | 850 | &unsol_on_ril_connected_invalid_3, | ||
3228 | 851 | test_unsol_on_ril_connected_invalid); | ||
3229 | 852 | |||
3230 | 696 | #endif | 853 | #endif |
3231 | 697 | return g_test_run(); | 854 | return g_test_run(); |
3232 | 698 | } | 855 | } |
3233 | 699 | 856 | ||
3234 | === added file 'unit/test-rilmodem-cb.c' | |||
3235 | --- unit/test-rilmodem-cb.c 1970-01-01 00:00:00 +0000 | |||
3236 | +++ unit/test-rilmodem-cb.c 2016-03-14 09:03:03 +0000 | |||
3237 | @@ -0,0 +1,605 @@ | |||
3238 | 1 | /* | ||
3239 | 2 | * | ||
3240 | 3 | * oFono - Open Source Telephony | ||
3241 | 4 | * | ||
3242 | 5 | * Copyright (C) 2015 Canonical Ltd. | ||
3243 | 6 | * | ||
3244 | 7 | * This program is free software; you can redistribute it and/or modify | ||
3245 | 8 | * it under the terms of the GNU General Public License version 2 as | ||
3246 | 9 | * published by the Free Software Foundation. | ||
3247 | 10 | * | ||
3248 | 11 | * This program is distributed in the hope that it will be useful, | ||
3249 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3250 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3251 | 14 | * GNU General Public License for more details. | ||
3252 | 15 | * | ||
3253 | 16 | * You should have received a copy of the GNU General Public License | ||
3254 | 17 | * along with this program; if not, write to the Free Software | ||
3255 | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
3256 | 19 | * | ||
3257 | 20 | */ | ||
3258 | 21 | |||
3259 | 22 | #ifdef HAVE_CONFIG_H | ||
3260 | 23 | #include <config.h> | ||
3261 | 24 | #endif | ||
3262 | 25 | |||
3263 | 26 | #define _GNU_SOURCE | ||
3264 | 27 | #include <assert.h> | ||
3265 | 28 | #include <errno.h> | ||
3266 | 29 | #include <glib.h> | ||
3267 | 30 | #include <stdio.h> | ||
3268 | 31 | #include <netinet/in.h> | ||
3269 | 32 | #include <sys/socket.h> | ||
3270 | 33 | #include <sys/un.h> | ||
3271 | 34 | #include <unistd.h> | ||
3272 | 35 | |||
3273 | 36 | #include <ofono/modem.h> | ||
3274 | 37 | #include <ofono/types.h> | ||
3275 | 38 | #include <ofono/call-barring.h> | ||
3276 | 39 | #include <gril.h> | ||
3277 | 40 | |||
3278 | 41 | #include "common.h" | ||
3279 | 42 | #include "ril_constants.h" | ||
3280 | 43 | #include "rilmodem-test-server.h" | ||
3281 | 44 | |||
3282 | 45 | static GMainLoop *mainloop; | ||
3283 | 46 | |||
3284 | 47 | static const struct ofono_call_barring_driver *cbdriver; | ||
3285 | 48 | |||
3286 | 49 | struct rilmodem_cb_data { | ||
3287 | 50 | GRil *ril; | ||
3288 | 51 | struct ofono_modem *modem; | ||
3289 | 52 | gconstpointer test_data; | ||
3290 | 53 | struct ofono_call_barring *cb; | ||
3291 | 54 | struct server_data *serverd; | ||
3292 | 55 | }; | ||
3293 | 56 | |||
3294 | 57 | typedef gboolean (*StartFunc)(gpointer data); | ||
3295 | 58 | |||
3296 | 59 | struct cb_data { | ||
3297 | 60 | StartFunc start_func; | ||
3298 | 61 | |||
3299 | 62 | const char *lock; | ||
3300 | 63 | int enable; | ||
3301 | 64 | const char *passwd; | ||
3302 | 65 | const char *new_passwd; | ||
3303 | 66 | int cls; | ||
3304 | 67 | |||
3305 | 68 | struct rilmodem_test_data rtd; | ||
3306 | 69 | enum ofono_error_type error_type; | ||
3307 | 70 | |||
3308 | 71 | int status; | ||
3309 | 72 | }; | ||
3310 | 73 | |||
3311 | 74 | static void query_callback(const struct ofono_error *error, int status, | ||
3312 | 75 | gpointer data) | ||
3313 | 76 | { | ||
3314 | 77 | struct rilmodem_cb_data *rsd = data; | ||
3315 | 78 | const struct cb_data *cbd = rsd->test_data; | ||
3316 | 79 | |||
3317 | 80 | g_assert(error->type == cbd->error_type); | ||
3318 | 81 | |||
3319 | 82 | if (error->type == OFONO_ERROR_TYPE_NO_ERROR) | ||
3320 | 83 | g_assert(status == cbd->status); | ||
3321 | 84 | |||
3322 | 85 | g_main_loop_quit(mainloop); | ||
3323 | 86 | } | ||
3324 | 87 | |||
3325 | 88 | static gboolean trigger_query(gpointer data) | ||
3326 | 89 | { | ||
3327 | 90 | struct rilmodem_cb_data *rsd = data; | ||
3328 | 91 | const struct cb_data *cbd = rsd->test_data; | ||
3329 | 92 | |||
3330 | 93 | g_assert(cbdriver->query != NULL); | ||
3331 | 94 | cbdriver->query(rsd->cb, cbd->lock, cbd->cls, query_callback, rsd); | ||
3332 | 95 | |||
3333 | 96 | return FALSE; | ||
3334 | 97 | } | ||
3335 | 98 | |||
3336 | 99 | static void set_callback(const struct ofono_error *error, gpointer data) | ||
3337 | 100 | { | ||
3338 | 101 | struct rilmodem_cb_data *rsd = data; | ||
3339 | 102 | const struct cb_data *cbd = rsd->test_data; | ||
3340 | 103 | |||
3341 | 104 | g_assert(error->type == cbd->error_type); | ||
3342 | 105 | |||
3343 | 106 | g_main_loop_quit(mainloop); | ||
3344 | 107 | } | ||
3345 | 108 | |||
3346 | 109 | static gboolean trigger_set(gpointer data) | ||
3347 | 110 | { | ||
3348 | 111 | struct rilmodem_cb_data *rsd = data; | ||
3349 | 112 | const struct cb_data *cbd = rsd->test_data; | ||
3350 | 113 | |||
3351 | 114 | g_assert(cbdriver->set != NULL); | ||
3352 | 115 | cbdriver->set(rsd->cb, cbd->lock, cbd->enable, cbd->passwd, cbd->cls, | ||
3353 | 116 | set_callback, rsd); | ||
3354 | 117 | |||
3355 | 118 | return FALSE; | ||
3356 | 119 | } | ||
3357 | 120 | |||
3358 | 121 | static void set_passwd_callback(const struct ofono_error *error, gpointer data) | ||
3359 | 122 | { | ||
3360 | 123 | struct rilmodem_cb_data *rsd = data; | ||
3361 | 124 | const struct cb_data *cbd = rsd->test_data; | ||
3362 | 125 | |||
3363 | 126 | g_assert(error->type == cbd->error_type); | ||
3364 | 127 | |||
3365 | 128 | g_main_loop_quit(mainloop); | ||
3366 | 129 | } | ||
3367 | 130 | |||
3368 | 131 | static gboolean trigger_set_passwd(gpointer data) | ||
3369 | 132 | { | ||
3370 | 133 | struct rilmodem_cb_data *rsd = data; | ||
3371 | 134 | const struct cb_data *cbd = rsd->test_data; | ||
3372 | 135 | |||
3373 | 136 | g_assert(cbdriver->set_passwd != NULL); | ||
3374 | 137 | cbdriver->set_passwd(rsd->cb, cbd->lock, cbd->passwd, cbd->new_passwd, | ||
3375 | 138 | set_passwd_callback, rsd); | ||
3376 | 139 | |||
3377 | 140 | return FALSE; | ||
3378 | 141 | } | ||
3379 | 142 | |||
3380 | 143 | /* RIL_REQUEST_GET_FACILITY_LOCK witht the following parameters: | ||
3381 | 144 | * | ||
3382 | 145 | * facility="OI" (outgoing international calls) | ||
3383 | 146 | * service class=1 ( VOICE ) | ||
3384 | 147 | */ | ||
3385 | 148 | static const guchar req_get_facility_lock_parcel_1[] = { | ||
3386 | 149 | 0x00, 0x00, 0x00, 0x2c, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3387 | 150 | 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x49, 0x00, | ||
3388 | 151 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3389 | 152 | 0x01, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff | ||
3390 | 153 | }; | ||
3391 | 154 | |||
3392 | 155 | /* | ||
3393 | 156 | * The following structure contains test data for a valid | ||
3394 | 157 | * RIL_REQUEST_GET_FACILITY_LOCK reply with parameter {1} | ||
3395 | 158 | * which indicates that call-barring is activated for the | ||
3396 | 159 | * previously specified facility for the VOICE class. | ||
3397 | 160 | */ | ||
3398 | 161 | static const guchar reply_get_facility_lock_data_valid_1[] = { | ||
3399 | 162 | 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 | ||
3400 | 163 | }; | ||
3401 | 164 | |||
3402 | 165 | static const struct cb_data testdata_query_valid_1 = { | ||
3403 | 166 | .start_func = trigger_query, | ||
3404 | 167 | .lock = "OI", | ||
3405 | 168 | .cls = BEARER_CLASS_VOICE, | ||
3406 | 169 | .rtd = { | ||
3407 | 170 | .req_data = req_get_facility_lock_parcel_1, | ||
3408 | 171 | .req_size = sizeof(req_get_facility_lock_parcel_1), | ||
3409 | 172 | .rsp_data = reply_get_facility_lock_data_valid_1, | ||
3410 | 173 | .rsp_size = sizeof(reply_get_facility_lock_data_valid_1), | ||
3411 | 174 | }, | ||
3412 | 175 | .status = BEARER_CLASS_VOICE, | ||
3413 | 176 | }; | ||
3414 | 177 | |||
3415 | 178 | /* GENERIC_FAILURE returned in RIL reply */ | ||
3416 | 179 | static const struct cb_data testdata_query_invalid_1 = { | ||
3417 | 180 | .start_func = trigger_query, | ||
3418 | 181 | .lock = "OI", | ||
3419 | 182 | .cls = BEARER_CLASS_VOICE, | ||
3420 | 183 | .rtd = { | ||
3421 | 184 | .req_data = req_get_facility_lock_parcel_1, | ||
3422 | 185 | .req_size = sizeof(req_get_facility_lock_parcel_1), | ||
3423 | 186 | .rsp_data = reply_get_facility_lock_data_valid_1, | ||
3424 | 187 | .rsp_size = sizeof(reply_get_facility_lock_data_valid_1), | ||
3425 | 188 | .rsp_error = RIL_E_GENERIC_FAILURE, | ||
3426 | 189 | }, | ||
3427 | 190 | .error_type = OFONO_ERROR_TYPE_FAILURE, | ||
3428 | 191 | }; | ||
3429 | 192 | |||
3430 | 193 | /* | ||
3431 | 194 | * The following structure contains test data for a valid | ||
3432 | 195 | * RIL_REQUEST_GET_FACILITY_LOCK reply with invalid number | ||
3433 | 196 | * of parameters {0} specified. | ||
3434 | 197 | */ | ||
3435 | 198 | static const guchar reply_get_facility_lock_data_invalid_2[] = { | ||
3436 | 199 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 | ||
3437 | 200 | }; | ||
3438 | 201 | |||
3439 | 202 | static const struct cb_data testdata_query_invalid_2 = { | ||
3440 | 203 | .start_func = trigger_query, | ||
3441 | 204 | .lock = "OI", | ||
3442 | 205 | .cls = BEARER_CLASS_VOICE, | ||
3443 | 206 | .rtd = { | ||
3444 | 207 | .req_data = req_get_facility_lock_parcel_1, | ||
3445 | 208 | .req_size = sizeof(req_get_facility_lock_parcel_1), | ||
3446 | 209 | .rsp_data = reply_get_facility_lock_data_invalid_2, | ||
3447 | 210 | .rsp_size = sizeof(reply_get_facility_lock_data_invalid_2), | ||
3448 | 211 | }, | ||
3449 | 212 | .error_type = OFONO_ERROR_TYPE_FAILURE, | ||
3450 | 213 | }; | ||
3451 | 214 | |||
3452 | 215 | /* | ||
3453 | 216 | * The following structure contains test data for an invalid | ||
3454 | 217 | * RIL_REQUEST_GET_FACILITY_LOCK reply with an invalid class | ||
3455 | 218 | * mask (-255). | ||
3456 | 219 | */ | ||
3457 | 220 | static const guchar reply_get_facility_lock_data_invalid_3[] = { | ||
3458 | 221 | 0x01, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff | ||
3459 | 222 | }; | ||
3460 | 223 | |||
3461 | 224 | static const struct cb_data testdata_query_invalid_3 = { | ||
3462 | 225 | .start_func = trigger_query, | ||
3463 | 226 | .lock = "OI", | ||
3464 | 227 | .cls = BEARER_CLASS_VOICE, | ||
3465 | 228 | .rtd = { | ||
3466 | 229 | .req_data = req_get_facility_lock_parcel_1, | ||
3467 | 230 | .req_size = sizeof(req_get_facility_lock_parcel_1), | ||
3468 | 231 | .rsp_data = reply_get_facility_lock_data_invalid_3, | ||
3469 | 232 | .rsp_size = sizeof(reply_get_facility_lock_data_invalid_3), | ||
3470 | 233 | }, | ||
3471 | 234 | .error_type = OFONO_ERROR_TYPE_FAILURE, | ||
3472 | 235 | }; | ||
3473 | 236 | |||
3474 | 237 | /* | ||
3475 | 238 | * The following structure contains test data for a | ||
3476 | 239 | * RIL_REQUEST_GET_FACILITY_LOCK reply with an incomplete | ||
3477 | 240 | * integer parameter, which will trigger a malformed parcel | ||
3478 | 241 | * error. | ||
3479 | 242 | */ | ||
3480 | 243 | static const guchar reply_get_facility_lock_data_invalid_4[] = { | ||
3481 | 244 | 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 | ||
3482 | 245 | }; | ||
3483 | 246 | |||
3484 | 247 | static const struct cb_data testdata_query_invalid_4 = { | ||
3485 | 248 | .start_func = trigger_query, | ||
3486 | 249 | .lock = "OI", | ||
3487 | 250 | .cls = BEARER_CLASS_VOICE, | ||
3488 | 251 | .rtd = { | ||
3489 | 252 | .req_data = req_get_facility_lock_parcel_1, | ||
3490 | 253 | .req_size = sizeof(req_get_facility_lock_parcel_1), | ||
3491 | 254 | .rsp_data = reply_get_facility_lock_data_invalid_4, | ||
3492 | 255 | .rsp_size = sizeof(reply_get_facility_lock_data_invalid_4), | ||
3493 | 256 | }, | ||
3494 | 257 | .error_type = OFONO_ERROR_TYPE_FAILURE, | ||
3495 | 258 | }; | ||
3496 | 259 | |||
3497 | 260 | /* RIL_REQUEST_SET_FACILITY_LOCK witht the following parameters: | ||
3498 | 261 | * | ||
3499 | 262 | * facility="OI" (outgoing international calls) | ||
3500 | 263 | * unlock (0) | ||
3501 | 264 | * passwd="0000" | ||
3502 | 265 | * service class=1 ( VOICE ) | ||
3503 | 266 | */ | ||
3504 | 267 | static const guchar req_set_facility_lock_parcel_1[] = { | ||
3505 | 268 | 0x00, 0x00, 0x00, 0x3c, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3506 | 269 | 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x49, 0x00, | ||
3507 | 270 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, | ||
3508 | 271 | 0x04, 0x00, 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, | ||
3509 | 272 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, | ||
3510 | 273 | 0xff, 0xff, 0xff, 0xff | ||
3511 | 274 | }; | ||
3512 | 275 | |||
3513 | 276 | /* | ||
3514 | 277 | * This test doesn't specify any data for RIL_REQUEST_SET_FACILITY_LOCK reply | ||
3515 | 278 | * to simulate a reply generated by mako. | ||
3516 | 279 | */ | ||
3517 | 280 | static const struct cb_data testdata_set_valid_1 = { | ||
3518 | 281 | .start_func = trigger_set, | ||
3519 | 282 | .lock = "OI", | ||
3520 | 283 | .passwd = "0000", | ||
3521 | 284 | .cls = BEARER_CLASS_VOICE, | ||
3522 | 285 | .rtd = { | ||
3523 | 286 | .req_data = req_set_facility_lock_parcel_1, | ||
3524 | 287 | .req_size = sizeof(req_set_facility_lock_parcel_1), | ||
3525 | 288 | }, | ||
3526 | 289 | }; | ||
3527 | 290 | |||
3528 | 291 | /* RIL_REQUEST_SET_FACILITY_LOCK witht the following parameters: | ||
3529 | 292 | * | ||
3530 | 293 | * facility="OI" (outgoing international calls) | ||
3531 | 294 | * unlock (1) | ||
3532 | 295 | * passwd="0000" | ||
3533 | 296 | * service class=0 ( NONE ) | ||
3534 | 297 | */ | ||
3535 | 298 | static const guchar req_set_facility_lock_parcel_2[] = { | ||
3536 | 299 | 0x00, 0x00, 0x00, 0x3c, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3537 | 300 | 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x49, 0x00, | ||
3538 | 301 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, | ||
3539 | 302 | 0x04, 0x00, 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, | ||
3540 | 303 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, | ||
3541 | 304 | 0xff, 0xff, 0xff, 0xff | ||
3542 | 305 | }; | ||
3543 | 306 | |||
3544 | 307 | /* | ||
3545 | 308 | * The following structure contains test data for a valid | ||
3546 | 309 | * RIL_REQUEST_SET_FACILITY_LOCK reply with parameter {1} | ||
3547 | 310 | */ | ||
3548 | 311 | static const guchar reply_set_facility_lock_data_valid_2[] = { | ||
3549 | 312 | 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 | ||
3550 | 313 | }; | ||
3551 | 314 | |||
3552 | 315 | static const struct cb_data testdata_set_valid_2 = { | ||
3553 | 316 | .start_func = trigger_set, | ||
3554 | 317 | .lock = "OI", | ||
3555 | 318 | .enable = 1, | ||
3556 | 319 | .passwd = "0000", | ||
3557 | 320 | .cls = BEARER_CLASS_DEFAULT, /* updated to NONE in outgoing parcel */ | ||
3558 | 321 | .rtd = { | ||
3559 | 322 | .req_data = req_set_facility_lock_parcel_2, | ||
3560 | 323 | .req_size = sizeof(req_set_facility_lock_parcel_2), | ||
3561 | 324 | .rsp_data = reply_set_facility_lock_data_valid_2, | ||
3562 | 325 | .rsp_size = sizeof(reply_set_facility_lock_data_valid_2), | ||
3563 | 326 | }, | ||
3564 | 327 | }; | ||
3565 | 328 | |||
3566 | 329 | /* GENERIC_FAILURE returned in RIL reply */ | ||
3567 | 330 | static const struct cb_data testdata_set_invalid_1 = { | ||
3568 | 331 | .start_func = trigger_set, | ||
3569 | 332 | .lock = "OI", | ||
3570 | 333 | .enable = 1, | ||
3571 | 334 | .passwd = "0000", | ||
3572 | 335 | .cls = BEARER_CLASS_DEFAULT, | ||
3573 | 336 | .rtd = { | ||
3574 | 337 | .req_data = req_set_facility_lock_parcel_2, | ||
3575 | 338 | .req_size = sizeof(req_set_facility_lock_parcel_2), | ||
3576 | 339 | .rsp_error = RIL_E_GENERIC_FAILURE, | ||
3577 | 340 | }, | ||
3578 | 341 | .error_type = OFONO_ERROR_TYPE_FAILURE, | ||
3579 | 342 | }; | ||
3580 | 343 | |||
3581 | 344 | |||
3582 | 345 | /* | ||
3583 | 346 | * The following structure contains test data for a | ||
3584 | 347 | * RIL_REQUEST_SET_FACILITY_LOCK reply with an invalid | ||
3585 | 348 | * number of parameters {2} | ||
3586 | 349 | */ | ||
3587 | 350 | static const guchar reply_set_facility_lock_data_invalid_2[] = { | ||
3588 | 351 | 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 | ||
3589 | 352 | }; | ||
3590 | 353 | |||
3591 | 354 | static const struct cb_data testdata_set_invalid_2 = { | ||
3592 | 355 | .start_func = trigger_set, | ||
3593 | 356 | .lock = "OI", | ||
3594 | 357 | .enable = 1, | ||
3595 | 358 | .passwd = "0000", | ||
3596 | 359 | .cls = BEARER_CLASS_DEFAULT, | ||
3597 | 360 | .rtd = { | ||
3598 | 361 | .req_data = req_set_facility_lock_parcel_2, | ||
3599 | 362 | .req_size = sizeof(req_set_facility_lock_parcel_2), | ||
3600 | 363 | .rsp_data = reply_set_facility_lock_data_invalid_2, | ||
3601 | 364 | .rsp_size = sizeof(reply_set_facility_lock_data_invalid_2), | ||
3602 | 365 | }, | ||
3603 | 366 | .error_type = OFONO_ERROR_TYPE_FAILURE, | ||
3604 | 367 | }; | ||
3605 | 368 | |||
3606 | 369 | /* | ||
3607 | 370 | * The following structure contains test data for a | ||
3608 | 371 | * RIL_REQUEST_SET_FACILITY_LOCK reply with an incomplete | ||
3609 | 372 | * integer parameter, which will trigger a malformed parcel | ||
3610 | 373 | * error. | ||
3611 | 374 | */ | ||
3612 | 375 | static const guchar reply_set_facility_lock_data_invalid_3[] = { | ||
3613 | 376 | 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 | ||
3614 | 377 | }; | ||
3615 | 378 | |||
3616 | 379 | static const struct cb_data testdata_set_invalid_3 = { | ||
3617 | 380 | .start_func = trigger_set, | ||
3618 | 381 | .lock = "OI", | ||
3619 | 382 | .enable = 1, | ||
3620 | 383 | .passwd = "0000", | ||
3621 | 384 | .cls = BEARER_CLASS_DEFAULT, | ||
3622 | 385 | .rtd = { | ||
3623 | 386 | .req_data = req_set_facility_lock_parcel_2, | ||
3624 | 387 | .req_size = sizeof(req_set_facility_lock_parcel_2), | ||
3625 | 388 | .rsp_data = reply_set_facility_lock_data_invalid_3, | ||
3626 | 389 | .rsp_size = sizeof(reply_set_facility_lock_data_invalid_3), | ||
3627 | 390 | }, | ||
3628 | 391 | .error_type = OFONO_ERROR_TYPE_FAILURE, | ||
3629 | 392 | }; | ||
3630 | 393 | |||
3631 | 394 | /* RIL_REQUEST_CHANGE_BARRING_PASSWORD with the following parameters: | ||
3632 | 395 | * | ||
3633 | 396 | * facility="OI" (outgoing international calls) | ||
3634 | 397 | * old passwd="1111" | ||
3635 | 398 | * new_passwd="0000" | ||
3636 | 399 | */ | ||
3637 | 400 | static const guchar req_change_barring_passwd_parcel_1[] = { | ||
3638 | 401 | 0x00, 0x00, 0x00, 0x38, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
3639 | 402 | 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x49, 0x00, | ||
3640 | 403 | 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x31, 0x00, 0x31, 0x00, | ||
3641 | 404 | 0x31, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, | ||
3642 | 405 | 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
3643 | 406 | }; | ||
3644 | 407 | |||
3645 | 408 | /* | ||
3646 | 409 | * This test doesn't specify any data for RIL_REQUEST_SET_FACILITY_LOCK reply | ||
3647 | 410 | * to simulate a reply generated by mako. | ||
3648 | 411 | */ | ||
3649 | 412 | static const struct cb_data testdata_set_passwd_valid_1 = { | ||
3650 | 413 | .start_func = trigger_set_passwd, | ||
3651 | 414 | .lock = "OI", | ||
3652 | 415 | .passwd = "1111", | ||
3653 | 416 | .new_passwd = "0000", | ||
3654 | 417 | .rtd = { | ||
3655 | 418 | .req_data = req_change_barring_passwd_parcel_1, | ||
3656 | 419 | .req_size = sizeof(req_change_barring_passwd_parcel_1), | ||
3657 | 420 | }, | ||
3658 | 421 | }; | ||
3659 | 422 | |||
3660 | 423 | /* GENERIC_FAILURE returned in RIL reply */ | ||
3661 | 424 | static const struct cb_data testdata_set_passwd_invalid_1 = { | ||
3662 | 425 | .start_func = trigger_set_passwd, | ||
3663 | 426 | .lock = "OI", | ||
3664 | 427 | .passwd = "1111", | ||
3665 | 428 | .new_passwd = "0000", | ||
3666 | 429 | .rtd = { | ||
3667 | 430 | .req_data = req_change_barring_passwd_parcel_1, | ||
3668 | 431 | .req_size = sizeof(req_change_barring_passwd_parcel_1), | ||
3669 | 432 | .rsp_error = RIL_E_GENERIC_FAILURE, | ||
3670 | 433 | }, | ||
3671 | 434 | .error_type = OFONO_ERROR_TYPE_FAILURE, | ||
3672 | 435 | }; | ||
3673 | 436 | |||
3674 | 437 | /* Declarations && Re-implementations of core functions. */ | ||
3675 | 438 | void ril_call_barring_exit(void); | ||
3676 | 439 | void ril_call_barring_init(void); | ||
3677 | 440 | |||
3678 | 441 | struct ofono_call_barring { | ||
3679 | 442 | void *driver_data; | ||
3680 | 443 | const struct cb_data *cbd; | ||
3681 | 444 | }; | ||
3682 | 445 | |||
3683 | 446 | struct ofono_call_barring *ofono_call_barring_create(struct ofono_modem *modem, | ||
3684 | 447 | unsigned int vendor, | ||
3685 | 448 | const char *driver, | ||
3686 | 449 | void *data) | ||
3687 | 450 | { | ||
3688 | 451 | struct rilmodem_cb_data *rsd = data; | ||
3689 | 452 | struct ofono_call_barring *cb = g_new0(struct ofono_call_barring, 1); | ||
3690 | 453 | int retval; | ||
3691 | 454 | |||
3692 | 455 | retval = cbdriver->probe(cb, OFONO_RIL_VENDOR_AOSP, rsd->ril); | ||
3693 | 456 | g_assert(retval == 0); | ||
3694 | 457 | |||
3695 | 458 | return cb; | ||
3696 | 459 | } | ||
3697 | 460 | |||
3698 | 461 | int ofono_call_barring_driver_register(const struct ofono_call_barring_driver *d) | ||
3699 | 462 | { | ||
3700 | 463 | if (cbdriver == NULL) | ||
3701 | 464 | cbdriver = d; | ||
3702 | 465 | |||
3703 | 466 | return 0; | ||
3704 | 467 | } | ||
3705 | 468 | |||
3706 | 469 | void ofono_call_barring_set_data(struct ofono_call_barring *cb, void *data) | ||
3707 | 470 | { | ||
3708 | 471 | cb->driver_data = data; | ||
3709 | 472 | } | ||
3710 | 473 | |||
3711 | 474 | void *ofono_call_barring_get_data(struct ofono_call_barring *cb) | ||
3712 | 475 | { | ||
3713 | 476 | return cb->driver_data; | ||
3714 | 477 | } | ||
3715 | 478 | |||
3716 | 479 | void ofono_call_barring_register(struct ofono_call_barring *cb) | ||
3717 | 480 | { | ||
3718 | 481 | } | ||
3719 | 482 | |||
3720 | 483 | void ofono_call_barring_driver_unregister(const struct ofono_call_barring_driver *d) | ||
3721 | 484 | { | ||
3722 | 485 | } | ||
3723 | 486 | |||
3724 | 487 | /* | ||
3725 | 488 | * As all our architectures are little-endian except for | ||
3726 | 489 | * PowerPC, and the Binder wire-format differs slightly | ||
3727 | 490 | * depending on endian-ness, the following guards against test | ||
3728 | 491 | * failures when run on PowerPC. | ||
3729 | 492 | */ | ||
3730 | 493 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
3731 | 494 | |||
3732 | 495 | static void server_connect_cb(gpointer data) | ||
3733 | 496 | { | ||
3734 | 497 | struct rilmodem_cb_data *rsd = data; | ||
3735 | 498 | const struct cb_data *cbd = rsd->test_data; | ||
3736 | 499 | |||
3737 | 500 | /* This causes local impl of _create() to call driver's probe func. */ | ||
3738 | 501 | rsd->cb = ofono_call_barring_create(NULL, OFONO_RIL_VENDOR_AOSP, | ||
3739 | 502 | "rilmodem", rsd); | ||
3740 | 503 | rsd->cb->cbd = cbd; | ||
3741 | 504 | |||
3742 | 505 | /* add_idle doesn't work, read blocks main loop!!! */ | ||
3743 | 506 | |||
3744 | 507 | if (cbd->rtd.unsol_test) | ||
3745 | 508 | g_idle_add(cbd->start_func, (void *) rsd); | ||
3746 | 509 | else | ||
3747 | 510 | g_assert(cbd->start_func(rsd) == FALSE); | ||
3748 | 511 | } | ||
3749 | 512 | |||
3750 | 513 | /* | ||
3751 | 514 | * This unit test: | ||
3752 | 515 | * - does some test data setup | ||
3753 | 516 | * - configures a dummy server socket | ||
3754 | 517 | * - creates a new gril client instance | ||
3755 | 518 | * - triggers a connect to the dummy | ||
3756 | 519 | * server socket | ||
3757 | 520 | * - starts a mainloop | ||
3758 | 521 | */ | ||
3759 | 522 | static void test_call_barring_func(gconstpointer data) | ||
3760 | 523 | { | ||
3761 | 524 | const struct cb_data *sd = data; | ||
3762 | 525 | struct rilmodem_cb_data *rsd; | ||
3763 | 526 | |||
3764 | 527 | ril_call_barring_init(); | ||
3765 | 528 | |||
3766 | 529 | rsd = g_new0(struct rilmodem_cb_data, 1); | ||
3767 | 530 | |||
3768 | 531 | rsd->test_data = sd; | ||
3769 | 532 | |||
3770 | 533 | rsd->serverd = rilmodem_test_server_create(&server_connect_cb, | ||
3771 | 534 | &sd->rtd, rsd); | ||
3772 | 535 | |||
3773 | 536 | rsd->ril = g_ril_new(rilmodem_test_get_socket_name(rsd->serverd), | ||
3774 | 537 | OFONO_RIL_VENDOR_AOSP); | ||
3775 | 538 | g_assert(rsd->ril != NULL); | ||
3776 | 539 | |||
3777 | 540 | mainloop = g_main_loop_new(NULL, FALSE); | ||
3778 | 541 | |||
3779 | 542 | g_main_loop_run(mainloop); | ||
3780 | 543 | g_main_loop_unref(mainloop); | ||
3781 | 544 | |||
3782 | 545 | cbdriver->remove(rsd->cb); | ||
3783 | 546 | g_ril_unref(rsd->ril); | ||
3784 | 547 | g_free(rsd); | ||
3785 | 548 | |||
3786 | 549 | rilmodem_test_server_close(rsd->serverd); | ||
3787 | 550 | |||
3788 | 551 | ril_call_barring_exit(); | ||
3789 | 552 | } | ||
3790 | 553 | |||
3791 | 554 | #endif | ||
3792 | 555 | |||
3793 | 556 | int main(int argc, char **argv) | ||
3794 | 557 | { | ||
3795 | 558 | g_test_init(&argc, &argv, NULL); | ||
3796 | 559 | |||
3797 | 560 | /* | ||
3798 | 561 | * As all our architectures are little-endian except for | ||
3799 | 562 | * PowerPC, and the Binder wire-format differs slightly | ||
3800 | 563 | * depending on endian-ness, the following guards against test | ||
3801 | 564 | * failures when run on PowerPC. | ||
3802 | 565 | */ | ||
3803 | 566 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
3804 | 567 | g_test_add_data_func("/testrilmodemcallbarring/query/valid/1", | ||
3805 | 568 | &testdata_query_valid_1, | ||
3806 | 569 | test_call_barring_func); | ||
3807 | 570 | g_test_add_data_func("/testrilmodemcallbarring/query/invalid/1", | ||
3808 | 571 | &testdata_query_invalid_1, | ||
3809 | 572 | test_call_barring_func); | ||
3810 | 573 | g_test_add_data_func("/testrilmodemcallbarring/query/invalid/2", | ||
3811 | 574 | &testdata_query_invalid_2, | ||
3812 | 575 | test_call_barring_func); | ||
3813 | 576 | g_test_add_data_func("/testrilmodemcallbarring/query/invalid/3", | ||
3814 | 577 | &testdata_query_invalid_3, | ||
3815 | 578 | test_call_barring_func); | ||
3816 | 579 | g_test_add_data_func("/testrilmodemcallbarring/query/invalid/4", | ||
3817 | 580 | &testdata_query_invalid_3, | ||
3818 | 581 | test_call_barring_func); | ||
3819 | 582 | g_test_add_data_func("/testrilmodemcallbarring/set/valid/1", | ||
3820 | 583 | &testdata_set_valid_1, | ||
3821 | 584 | test_call_barring_func); | ||
3822 | 585 | g_test_add_data_func("/testrilmodemcallbarring/set/valid/2", | ||
3823 | 586 | &testdata_set_valid_2, | ||
3824 | 587 | test_call_barring_func); | ||
3825 | 588 | g_test_add_data_func("/testrilmodemcallbarring/set/invalid/1", | ||
3826 | 589 | &testdata_set_invalid_1, | ||
3827 | 590 | test_call_barring_func); | ||
3828 | 591 | g_test_add_data_func("/testrilmodemcallbarring/set/invalid/2", | ||
3829 | 592 | &testdata_set_invalid_2, | ||
3830 | 593 | test_call_barring_func); | ||
3831 | 594 | g_test_add_data_func("/testrilmodemcallbarring/set/invalid/3", | ||
3832 | 595 | &testdata_set_invalid_3, | ||
3833 | 596 | test_call_barring_func); | ||
3834 | 597 | g_test_add_data_func("/testrilmodemcallbarring/set_passwd/valid/1", | ||
3835 | 598 | &testdata_set_passwd_valid_1, | ||
3836 | 599 | test_call_barring_func); | ||
3837 | 600 | g_test_add_data_func("/testrilmodemcallbarring/set_passwd/invalid/1", | ||
3838 | 601 | &testdata_set_passwd_invalid_1, | ||
3839 | 602 | test_call_barring_func); | ||
3840 | 603 | #endif | ||
3841 | 604 | return g_test_run(); | ||
3842 | 605 | } | ||
3843 | 0 | 606 | ||
3844 | === modified file 'unit/test-rilmodem-cs.c' | |||
3845 | --- unit/test-rilmodem-cs.c 2015-11-05 21:28:06 +0000 | |||
3846 | +++ unit/test-rilmodem-cs.c 2016-03-14 09:03:03 +0000 | |||
3847 | @@ -40,29 +40,18 @@ | |||
3848 | 40 | 40 | ||
3849 | 41 | #include "common.h" | 41 | #include "common.h" |
3850 | 42 | #include "ril_constants.h" | 42 | #include "ril_constants.h" |
3853 | 43 | 43 | #include "rilmodem-test-server.h" | |
3852 | 44 | #define MAX_REQUEST_SIZE 4096 | ||
3854 | 45 | 44 | ||
3855 | 46 | static GMainLoop *mainloop; | 45 | static GMainLoop *mainloop; |
3856 | 47 | 46 | ||
3857 | 48 | static const struct ofono_call_settings_driver *csdriver; | 47 | static const struct ofono_call_settings_driver *csdriver; |
3858 | 49 | 48 | ||
3860 | 50 | struct rilmodemcs_data { | 49 | struct rilmodem_cs_data { |
3861 | 51 | GRil *ril; | 50 | GRil *ril; |
3862 | 52 | int sk; | ||
3863 | 53 | gint server_watch; | ||
3864 | 54 | GIOChannel *server_io; | ||
3865 | 55 | struct ofono_modem *modem; | 51 | struct ofono_modem *modem; |
3866 | 56 | gconstpointer test_data; | 52 | gconstpointer test_data; |
3867 | 57 | struct ofono_call_settings *cs; | 53 | struct ofono_call_settings *cs; |
3876 | 58 | }; | 54 | struct server_data *serverd; |
3869 | 59 | |||
3870 | 60 | /* Warning: length is stored in network order */ | ||
3871 | 61 | struct rsp_hdr { | ||
3872 | 62 | uint32_t length; | ||
3873 | 63 | uint32_t unsolicited; | ||
3874 | 64 | uint32_t serial; | ||
3875 | 65 | uint32_t error; | ||
3877 | 66 | }; | 55 | }; |
3878 | 67 | 56 | ||
3879 | 68 | typedef gboolean (*StartFunc)(gpointer data); | 57 | typedef gboolean (*StartFunc)(gpointer data); |
3880 | @@ -72,13 +61,7 @@ | |||
3881 | 72 | gint param_int1; | 61 | gint param_int1; |
3882 | 73 | gint param_int2; | 62 | gint param_int2; |
3883 | 74 | 63 | ||
3891 | 75 | const guchar *parcel_data; | 64 | struct rilmodem_test_data rtd; |
3885 | 76 | |||
3886 | 77 | const gsize parcel_size; | ||
3887 | 78 | |||
3888 | 79 | uint32_t rsp_error; | ||
3889 | 80 | const guchar *rsp_data; | ||
3890 | 81 | const gsize rsp_size; | ||
3892 | 82 | enum ofono_error_type error_type; | 65 | enum ofono_error_type error_type; |
3893 | 83 | gint cb_int1; | 66 | gint cb_int1; |
3894 | 84 | gint cb_int2; | 67 | gint cb_int2; |
3895 | @@ -87,8 +70,8 @@ | |||
3896 | 87 | static void status_query_callback(const struct ofono_error *error, int status, | 70 | static void status_query_callback(const struct ofono_error *error, int status, |
3897 | 88 | gpointer data) | 71 | gpointer data) |
3898 | 89 | { | 72 | { |
3901 | 90 | struct rilmodemcs_data *rcsd = data; | 73 | struct rilmodem_cs_data *rcd = data; |
3902 | 91 | const struct cs_data *csd = rcsd->test_data; | 74 | const struct cs_data *csd = rcd->test_data; |
3903 | 92 | 75 | ||
3904 | 93 | g_assert(error->type == csd->error_type); | 76 | g_assert(error->type == csd->error_type); |
3905 | 94 | 77 | ||
3906 | @@ -101,8 +84,8 @@ | |||
3907 | 101 | static void clir_query_callback(const struct ofono_error *error, int override, | 84 | static void clir_query_callback(const struct ofono_error *error, int override, |
3908 | 102 | int network, gpointer data) | 85 | int network, gpointer data) |
3909 | 103 | { | 86 | { |
3912 | 104 | struct rilmodemcs_data *rcsd = data; | 87 | struct rilmodem_cs_data *rcd = data; |
3913 | 105 | const struct cs_data *csd = rcsd->test_data; | 88 | const struct cs_data *csd = rcd->test_data; |
3914 | 106 | 89 | ||
3915 | 107 | g_assert(error->type == csd->error_type); | 90 | g_assert(error->type == csd->error_type); |
3916 | 108 | 91 | ||
3917 | @@ -116,8 +99,8 @@ | |||
3918 | 116 | 99 | ||
3919 | 117 | static void set_callback(const struct ofono_error *error, gpointer data) | 100 | static void set_callback(const struct ofono_error *error, gpointer data) |
3920 | 118 | { | 101 | { |
3923 | 119 | struct rilmodemcs_data *rcsd = data; | 102 | struct rilmodem_cs_data *rcd = data; |
3924 | 120 | const struct cs_data *csd = rcsd->test_data; | 103 | const struct cs_data *csd = rcd->test_data; |
3925 | 121 | 104 | ||
3926 | 122 | g_assert(error->type == csd->error_type); | 105 | g_assert(error->type == csd->error_type); |
3927 | 123 | 106 | ||
3928 | @@ -126,56 +109,56 @@ | |||
3929 | 126 | 109 | ||
3930 | 127 | static gboolean trigger_clip_query(gpointer data) | 110 | static gboolean trigger_clip_query(gpointer data) |
3931 | 128 | { | 111 | { |
3933 | 129 | struct rilmodemcs_data *rcsd = data; | 112 | struct rilmodem_cs_data *rcd = data; |
3934 | 130 | 113 | ||
3935 | 131 | g_assert(csdriver->clip_query != NULL); | 114 | g_assert(csdriver->clip_query != NULL); |
3937 | 132 | csdriver->clip_query(rcsd->cs, status_query_callback, rcsd); | 115 | csdriver->clip_query(rcd->cs, status_query_callback, rcd); |
3938 | 133 | 116 | ||
3939 | 134 | return FALSE; | 117 | return FALSE; |
3940 | 135 | } | 118 | } |
3941 | 136 | 119 | ||
3942 | 137 | static gboolean trigger_cw_query(gpointer data) | 120 | static gboolean trigger_cw_query(gpointer data) |
3943 | 138 | { | 121 | { |
3945 | 139 | struct rilmodemcs_data *rcsd = data; | 122 | struct rilmodem_cs_data *rcd = data; |
3946 | 140 | 123 | ||
3947 | 141 | g_assert(csdriver->cw_query != NULL); | 124 | g_assert(csdriver->cw_query != NULL); |
3948 | 142 | 125 | ||
3949 | 143 | /* cls is explicitly ignored by rilmodem; just use 0 */ | 126 | /* cls is explicitly ignored by rilmodem; just use 0 */ |
3951 | 144 | csdriver->cw_query(rcsd->cs, 0, status_query_callback, rcsd); | 127 | csdriver->cw_query(rcd->cs, 0, status_query_callback, rcd); |
3952 | 145 | 128 | ||
3953 | 146 | return FALSE; | 129 | return FALSE; |
3954 | 147 | } | 130 | } |
3955 | 148 | 131 | ||
3956 | 149 | static gboolean trigger_cw_set(gpointer data) | 132 | static gboolean trigger_cw_set(gpointer data) |
3957 | 150 | { | 133 | { |
3960 | 151 | struct rilmodemcs_data *rcsd = data; | 134 | struct rilmodem_cs_data *rcd = data; |
3961 | 152 | const struct cs_data *csd = rcsd->test_data; | 135 | const struct cs_data *csd = rcd->test_data; |
3962 | 153 | 136 | ||
3963 | 154 | g_assert(csdriver->cw_set != NULL); | 137 | g_assert(csdriver->cw_set != NULL); |
3964 | 155 | 138 | ||
3967 | 156 | csdriver->cw_set(rcsd->cs, csd->param_int1, csd->param_int2, | 139 | csdriver->cw_set(rcd->cs, csd->param_int1, csd->param_int2, |
3968 | 157 | set_callback, rcsd); | 140 | set_callback, rcd); |
3969 | 158 | 141 | ||
3970 | 159 | return FALSE; | 142 | return FALSE; |
3971 | 160 | } | 143 | } |
3972 | 161 | 144 | ||
3973 | 162 | static gboolean trigger_clir_query(gpointer data) | 145 | static gboolean trigger_clir_query(gpointer data) |
3974 | 163 | { | 146 | { |
3976 | 164 | struct rilmodemcs_data *rcsd = data; | 147 | struct rilmodem_cs_data *rcd = data; |
3977 | 165 | 148 | ||
3978 | 166 | g_assert(csdriver->clir_query != NULL); | 149 | g_assert(csdriver->clir_query != NULL); |
3980 | 167 | csdriver->clir_query(rcsd->cs, clir_query_callback, rcsd); | 150 | csdriver->clir_query(rcd->cs, clir_query_callback, rcd); |
3981 | 168 | 151 | ||
3982 | 169 | return FALSE; | 152 | return FALSE; |
3983 | 170 | } | 153 | } |
3984 | 171 | 154 | ||
3985 | 172 | static gboolean trigger_clir_set(gpointer data) | 155 | static gboolean trigger_clir_set(gpointer data) |
3986 | 173 | { | 156 | { |
3989 | 174 | struct rilmodemcs_data *rcsd = data; | 157 | struct rilmodem_cs_data *rcd = data; |
3990 | 175 | const struct cs_data *csd = rcsd->test_data; | 158 | const struct cs_data *csd = rcd->test_data; |
3991 | 176 | 159 | ||
3992 | 177 | g_assert(csdriver->clir_set != NULL); | 160 | g_assert(csdriver->clir_set != NULL); |
3994 | 178 | csdriver->clir_set(rcsd->cs, csd->param_int1, set_callback, rcsd); | 161 | csdriver->clir_set(rcd->cs, csd->param_int1, set_callback, rcd); |
3995 | 179 | 162 | ||
3996 | 180 | return FALSE; | 163 | return FALSE; |
3997 | 181 | } | 164 | } |
3998 | @@ -192,11 +175,13 @@ | |||
3999 | 192 | 175 | ||
4000 | 193 | static const struct cs_data testdata_clip_query_valid_1 = { | 176 | static const struct cs_data testdata_clip_query_valid_1 = { |
4001 | 194 | .start_func = trigger_clip_query, | 177 | .start_func = trigger_clip_query, |
4007 | 195 | .parcel_data = req_clip_query_parcel_1, | 178 | .rtd = { |
4008 | 196 | .parcel_size = sizeof(req_clip_query_parcel_1), | 179 | .req_data = req_clip_query_parcel_1, |
4009 | 197 | .rsp_data = rsp_clip_query_data_1, | 180 | .req_size = sizeof(req_clip_query_parcel_1), |
4010 | 198 | .rsp_size = sizeof(rsp_clip_query_data_1), | 181 | .rsp_data = rsp_clip_query_data_1, |
4011 | 199 | .rsp_error = RIL_E_SUCCESS, | 182 | .rsp_size = sizeof(rsp_clip_query_data_1), |
4012 | 183 | .rsp_error = RIL_E_SUCCESS, | ||
4013 | 184 | }, | ||
4014 | 200 | .cb_int1 = 1, | 185 | .cb_int1 = 1, |
4015 | 201 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, | 186 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, |
4016 | 202 | }; | 187 | }; |
4017 | @@ -209,21 +194,25 @@ | |||
4018 | 209 | /* reply parse error causes status to be returned as -1 */ | 194 | /* reply parse error causes status to be returned as -1 */ |
4019 | 210 | static const struct cs_data testdata_clip_query_invalid_1 = { | 195 | static const struct cs_data testdata_clip_query_invalid_1 = { |
4020 | 211 | .start_func = trigger_clip_query, | 196 | .start_func = trigger_clip_query, |
4025 | 212 | .parcel_data = req_clip_query_parcel_1, | 197 | .rtd = { |
4026 | 213 | .parcel_size = sizeof(req_clip_query_parcel_1), | 198 | .req_data = req_clip_query_parcel_1, |
4027 | 214 | .rsp_data = rsp_clip_query_data_2, | 199 | .req_size = sizeof(req_clip_query_parcel_1), |
4028 | 215 | .rsp_size = sizeof(rsp_clip_query_data_2), | 200 | .rsp_data = rsp_clip_query_data_2, |
4029 | 201 | .rsp_size = sizeof(rsp_clip_query_data_2), | ||
4030 | 202 | .rsp_error = RIL_E_SUCCESS, | ||
4031 | 203 | }, | ||
4032 | 216 | .cb_int1 = -1, | 204 | .cb_int1 = -1, |
4033 | 217 | .rsp_error = RIL_E_SUCCESS, | ||
4034 | 218 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, | 205 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, |
4035 | 219 | }; | 206 | }; |
4036 | 220 | 207 | ||
4037 | 221 | /* error triggered by RIL reply error */ | 208 | /* error triggered by RIL reply error */ |
4038 | 222 | static const struct cs_data testdata_clip_query_invalid_2 = { | 209 | static const struct cs_data testdata_clip_query_invalid_2 = { |
4039 | 223 | .start_func = trigger_clip_query, | 210 | .start_func = trigger_clip_query, |
4043 | 224 | .parcel_data = req_clip_query_parcel_1, | 211 | .rtd = { |
4044 | 225 | .parcel_size = sizeof(req_clip_query_parcel_1), | 212 | .req_data = req_clip_query_parcel_1, |
4045 | 226 | .rsp_error = RIL_E_GENERIC_FAILURE, | 213 | .req_size = sizeof(req_clip_query_parcel_1), |
4046 | 214 | .rsp_error = RIL_E_GENERIC_FAILURE, | ||
4047 | 215 | }, | ||
4048 | 227 | .error_type = OFONO_ERROR_TYPE_FAILURE, | 216 | .error_type = OFONO_ERROR_TYPE_FAILURE, |
4049 | 228 | }; | 217 | }; |
4050 | 229 | 218 | ||
4051 | @@ -240,11 +229,13 @@ | |||
4052 | 240 | 229 | ||
4053 | 241 | static const struct cs_data testdata_cw_query_valid_1 = { | 230 | static const struct cs_data testdata_cw_query_valid_1 = { |
4054 | 242 | .start_func = trigger_cw_query, | 231 | .start_func = trigger_cw_query, |
4060 | 243 | .parcel_data = req_cw_query_parcel_1, | 232 | .rtd = { |
4061 | 244 | .parcel_size = sizeof(req_cw_query_parcel_1), | 233 | .req_data = req_cw_query_parcel_1, |
4062 | 245 | .rsp_data = rsp_cw_query_data_1, | 234 | .req_size = sizeof(req_cw_query_parcel_1), |
4063 | 246 | .rsp_size = sizeof(rsp_cw_query_data_1), | 235 | .rsp_data = rsp_cw_query_data_1, |
4064 | 247 | .rsp_error = RIL_E_SUCCESS, | 236 | .rsp_size = sizeof(rsp_cw_query_data_1), |
4065 | 237 | .rsp_error = RIL_E_SUCCESS, | ||
4066 | 238 | }, | ||
4067 | 248 | .cb_int1 = 3, | 239 | .cb_int1 = 3, |
4068 | 249 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, | 240 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, |
4069 | 250 | }; | 241 | }; |
4070 | @@ -257,24 +248,28 @@ | |||
4071 | 257 | /* reply parse error causes status to be returned as -1 */ | 248 | /* reply parse error causes status to be returned as -1 */ |
4072 | 258 | static const struct cs_data testdata_cw_query_invalid_1 = { | 249 | static const struct cs_data testdata_cw_query_invalid_1 = { |
4073 | 259 | .start_func = trigger_cw_query, | 250 | .start_func = trigger_cw_query, |
4078 | 260 | .parcel_data = req_cw_query_parcel_1, | 251 | .rtd = { |
4079 | 261 | .parcel_size = sizeof(req_cw_query_parcel_1), | 252 | .req_data = req_cw_query_parcel_1, |
4080 | 262 | .rsp_data = rsp_cw_query_data_2, | 253 | .req_size = sizeof(req_cw_query_parcel_1), |
4081 | 263 | .rsp_size = sizeof(rsp_cw_query_data_2), | 254 | .rsp_data = rsp_cw_query_data_2, |
4082 | 255 | .rsp_size = sizeof(rsp_cw_query_data_2), | ||
4083 | 256 | .rsp_error = RIL_E_SUCCESS, | ||
4084 | 257 | }, | ||
4085 | 264 | .cb_int1 = -1, | 258 | .cb_int1 = -1, |
4086 | 265 | .rsp_error = RIL_E_SUCCESS, | ||
4087 | 266 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, | 259 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, |
4088 | 267 | }; | 260 | }; |
4089 | 268 | 261 | ||
4090 | 269 | /* GENERIC_FAILURE returned in RIL reply */ | 262 | /* GENERIC_FAILURE returned in RIL reply */ |
4091 | 270 | static const struct cs_data testdata_cw_query_invalid_2 = { | 263 | static const struct cs_data testdata_cw_query_invalid_2 = { |
4092 | 271 | .start_func = trigger_cw_query, | 264 | .start_func = trigger_cw_query, |
4097 | 272 | .parcel_data = req_cw_query_parcel_1, | 265 | .rtd = { |
4098 | 273 | .parcel_size = sizeof(req_cw_query_parcel_1), | 266 | .req_data = req_cw_query_parcel_1, |
4099 | 274 | .rsp_data = rsp_cw_query_data_2, | 267 | .req_size = sizeof(req_cw_query_parcel_1), |
4100 | 275 | .rsp_size = sizeof(rsp_cw_query_data_2), | 268 | .rsp_data = rsp_cw_query_data_2, |
4101 | 269 | .rsp_size = sizeof(rsp_cw_query_data_2), | ||
4102 | 270 | .rsp_error = RIL_E_GENERIC_FAILURE, | ||
4103 | 271 | }, | ||
4104 | 276 | .cb_int1 = -1, | 272 | .cb_int1 = -1, |
4105 | 277 | .rsp_error = RIL_E_GENERIC_FAILURE, | ||
4106 | 278 | .error_type = OFONO_ERROR_TYPE_FAILURE, | 273 | .error_type = OFONO_ERROR_TYPE_FAILURE, |
4107 | 279 | }; | 274 | }; |
4108 | 280 | 275 | ||
4109 | @@ -289,9 +284,11 @@ | |||
4110 | 289 | .start_func = trigger_cw_set, | 284 | .start_func = trigger_cw_set, |
4111 | 290 | .param_int1 = 1, | 285 | .param_int1 = 1, |
4112 | 291 | .param_int2 = BEARER_CLASS_DEFAULT, | 286 | .param_int2 = BEARER_CLASS_DEFAULT, |
4116 | 292 | .parcel_data = req_cw_set_enabled_parcel_1, | 287 | .rtd = { |
4117 | 293 | .parcel_size = sizeof(req_cw_set_enabled_parcel_1), | 288 | .req_data = req_cw_set_enabled_parcel_1, |
4118 | 294 | .rsp_error = RIL_E_SUCCESS, | 289 | .req_size = sizeof(req_cw_set_enabled_parcel_1), |
4119 | 290 | .rsp_error = RIL_E_SUCCESS, | ||
4120 | 291 | }, | ||
4121 | 295 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, | 292 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, |
4122 | 296 | }; | 293 | }; |
4123 | 297 | 294 | ||
4124 | @@ -306,9 +303,11 @@ | |||
4125 | 306 | .start_func = trigger_cw_set, | 303 | .start_func = trigger_cw_set, |
4126 | 307 | .param_int1 = 0, | 304 | .param_int1 = 0, |
4127 | 308 | .param_int2 = 0, | 305 | .param_int2 = 0, |
4131 | 309 | .parcel_data = req_cw_set_disabled_parcel_2, | 306 | .rtd = { |
4132 | 310 | .parcel_size = sizeof(req_cw_set_disabled_parcel_2), | 307 | .req_data = req_cw_set_disabled_parcel_2, |
4133 | 311 | .rsp_error = RIL_E_GENERIC_FAILURE, | 308 | .req_size = sizeof(req_cw_set_disabled_parcel_2), |
4134 | 309 | .rsp_error = RIL_E_GENERIC_FAILURE, | ||
4135 | 310 | }, | ||
4136 | 312 | .error_type = OFONO_ERROR_TYPE_FAILURE, | 311 | .error_type = OFONO_ERROR_TYPE_FAILURE, |
4137 | 313 | }; | 312 | }; |
4138 | 314 | 313 | ||
4139 | @@ -324,13 +323,15 @@ | |||
4140 | 324 | 323 | ||
4141 | 325 | static const struct cs_data testdata_clir_query_valid_1 = { | 324 | static const struct cs_data testdata_clir_query_valid_1 = { |
4142 | 326 | .start_func = trigger_clir_query, | 325 | .start_func = trigger_clir_query, |
4147 | 327 | .parcel_data = req_clir_query_parcel_1, | 326 | .rtd = { |
4148 | 328 | .parcel_size = sizeof(req_clir_query_parcel_1), | 327 | .req_data = req_clir_query_parcel_1, |
4149 | 329 | .rsp_data = rsp_clir_query_data_1, | 328 | .req_size = sizeof(req_clir_query_parcel_1), |
4150 | 330 | .rsp_size = sizeof(rsp_clir_query_data_1), | 329 | .rsp_data = rsp_clir_query_data_1, |
4151 | 330 | .rsp_size = sizeof(rsp_clir_query_data_1), | ||
4152 | 331 | .rsp_error = RIL_E_SUCCESS, | ||
4153 | 332 | }, | ||
4154 | 331 | .cb_int1 = 2, | 333 | .cb_int1 = 2, |
4155 | 332 | .cb_int2 = 4, | 334 | .cb_int2 = 4, |
4156 | 333 | .rsp_error = RIL_E_SUCCESS, | ||
4157 | 334 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, | 335 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, |
4158 | 335 | }; | 336 | }; |
4159 | 336 | 337 | ||
4160 | @@ -340,11 +341,13 @@ | |||
4161 | 340 | }; | 341 | }; |
4162 | 341 | static const struct cs_data testdata_clir_query_invalid_1 = { | 342 | static const struct cs_data testdata_clir_query_invalid_1 = { |
4163 | 342 | .start_func = trigger_clir_query, | 343 | .start_func = trigger_clir_query, |
4169 | 343 | .parcel_data = req_clir_query_parcel_1, | 344 | .rtd = { |
4170 | 344 | .parcel_size = sizeof(req_clir_query_parcel_1), | 345 | .req_data = req_clir_query_parcel_1, |
4171 | 345 | .rsp_data = rsp_clir_query_data_2, | 346 | .req_size = sizeof(req_clir_query_parcel_1), |
4172 | 346 | .rsp_size = sizeof(rsp_clir_query_data_2), | 347 | .rsp_data = rsp_clir_query_data_2, |
4173 | 347 | .rsp_error = RIL_E_SUCCESS, | 348 | .rsp_size = sizeof(rsp_clir_query_data_2), |
4174 | 349 | .rsp_error = RIL_E_SUCCESS, | ||
4175 | 350 | }, | ||
4176 | 348 | .error_type = OFONO_ERROR_TYPE_FAILURE, | 351 | .error_type = OFONO_ERROR_TYPE_FAILURE, |
4177 | 349 | }; | 352 | }; |
4178 | 350 | 353 | ||
4179 | @@ -357,9 +360,11 @@ | |||
4180 | 357 | static const struct cs_data testdata_clir_set_valid_1 = { | 360 | static const struct cs_data testdata_clir_set_valid_1 = { |
4181 | 358 | .start_func = trigger_clir_set, | 361 | .start_func = trigger_clir_set, |
4182 | 359 | .param_int1 = OFONO_CLIR_OPTION_DEFAULT, | 362 | .param_int1 = OFONO_CLIR_OPTION_DEFAULT, |
4186 | 360 | .parcel_data = req_clir_set_mode0_parcel_1, | 363 | .rtd = { |
4187 | 361 | .parcel_size = sizeof(req_clir_set_mode0_parcel_1), | 364 | .req_data = req_clir_set_mode0_parcel_1, |
4188 | 362 | .rsp_error = RIL_E_SUCCESS, | 365 | .req_size = sizeof(req_clir_set_mode0_parcel_1), |
4189 | 366 | .rsp_error = RIL_E_SUCCESS, | ||
4190 | 367 | }, | ||
4191 | 363 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, | 368 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, |
4192 | 364 | }; | 369 | }; |
4193 | 365 | 370 | ||
4194 | @@ -373,9 +378,12 @@ | |||
4195 | 373 | static const struct cs_data testdata_clir_set_invalid_1 = { | 378 | static const struct cs_data testdata_clir_set_invalid_1 = { |
4196 | 374 | .start_func = trigger_clir_set, | 379 | .start_func = trigger_clir_set, |
4197 | 375 | .param_int1 = OFONO_CLIR_OPTION_INVOCATION, | 380 | .param_int1 = OFONO_CLIR_OPTION_INVOCATION, |
4201 | 376 | .parcel_data = req_clir_set_mode0_parcel_2, | 381 | |
4202 | 377 | .parcel_size = sizeof(req_clir_set_mode0_parcel_2), | 382 | .rtd = { |
4203 | 378 | .rsp_error = RIL_E_GENERIC_FAILURE, | 383 | .req_data = req_clir_set_mode0_parcel_2, |
4204 | 384 | .req_size = sizeof(req_clir_set_mode0_parcel_2), | ||
4205 | 385 | .rsp_error = RIL_E_GENERIC_FAILURE, | ||
4206 | 386 | }, | ||
4207 | 379 | .error_type = OFONO_ERROR_TYPE_FAILURE, | 387 | .error_type = OFONO_ERROR_TYPE_FAILURE, |
4208 | 380 | }; | 388 | }; |
4209 | 381 | 389 | ||
4210 | @@ -392,11 +400,11 @@ | |||
4211 | 392 | const char *driver, | 400 | const char *driver, |
4212 | 393 | void *data) | 401 | void *data) |
4213 | 394 | { | 402 | { |
4215 | 395 | struct rilmodemcs_data *rcsd = data; | 403 | struct rilmodem_cs_data *rcd = data; |
4216 | 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); |
4217 | 397 | int retval; | 405 | int retval; |
4218 | 398 | 406 | ||
4220 | 399 | retval = csdriver->probe(cs, OFONO_RIL_VENDOR_AOSP, rcsd->ril); | 407 | retval = csdriver->probe(cs, OFONO_RIL_VENDOR_AOSP, rcd->ril); |
4221 | 400 | g_assert(retval == 0); | 408 | g_assert(retval == 0); |
4222 | 401 | 409 | ||
4223 | 402 | return cs; | 410 | return cs; |
4224 | @@ -422,12 +430,10 @@ | |||
4225 | 422 | 430 | ||
4226 | 423 | void ofono_call_settings_register(struct ofono_call_settings *cs) | 431 | void ofono_call_settings_register(struct ofono_call_settings *cs) |
4227 | 424 | { | 432 | { |
4228 | 425 | ; | ||
4229 | 426 | } | 433 | } |
4230 | 427 | 434 | ||
4231 | 428 | void ofono_call_settings_driver_unregister(const struct ofono_call_settings_driver *d) | 435 | void ofono_call_settings_driver_unregister(const struct ofono_call_settings_driver *d) |
4232 | 429 | { | 436 | { |
4233 | 430 | ; | ||
4234 | 431 | } | 437 | } |
4235 | 432 | 438 | ||
4236 | 433 | /* | 439 | /* |
4237 | @@ -438,163 +444,23 @@ | |||
4238 | 438 | */ | 444 | */ |
4239 | 439 | #if BYTE_ORDER == LITTLE_ENDIAN | 445 | #if BYTE_ORDER == LITTLE_ENDIAN |
4240 | 440 | 446 | ||
4333 | 441 | static gboolean read_server(gpointer data) | 447 | static void server_connect_cb(gpointer data) |
4334 | 442 | { | 448 | { |
4335 | 443 | GIOStatus status; | 449 | struct rilmodem_cs_data *rcd = data; |
4336 | 444 | struct rilmodemcs_data *rcsd = data; | 450 | const struct cs_data *csd = rcd->test_data; |
4245 | 445 | gsize offset, rbytes, wbytes; | ||
4246 | 446 | gchar *buf, *bufp; | ||
4247 | 447 | uint32_t req_serial; | ||
4248 | 448 | struct rsp_hdr rsp; | ||
4249 | 449 | |||
4250 | 450 | /* | ||
4251 | 451 | * FIXME: separate out verification from here, so read_server doesn't | ||
4252 | 452 | * need to know about cs_data. | ||
4253 | 453 | */ | ||
4254 | 454 | const struct cs_data *csd = rcsd->test_data; | ||
4255 | 455 | |||
4256 | 456 | buf = g_malloc0(MAX_REQUEST_SIZE); | ||
4257 | 457 | |||
4258 | 458 | status = g_io_channel_read_chars(rcsd->server_io, buf, MAX_REQUEST_SIZE, | ||
4259 | 459 | &rbytes, NULL); | ||
4260 | 460 | g_assert(status == G_IO_STATUS_NORMAL); | ||
4261 | 461 | g_assert(rbytes == csd->parcel_size); | ||
4262 | 462 | |||
4263 | 463 | /* validate len, and request_id */ | ||
4264 | 464 | g_assert(!memcmp(buf, csd->parcel_data, (sizeof(uint32_t) * 2))); | ||
4265 | 465 | |||
4266 | 466 | /* | ||
4267 | 467 | * header: size (uint32), reqid (uin32), serial (uint32) | ||
4268 | 468 | * header size == 16 ( excludes sizeof(size) ) | ||
4269 | 469 | */ | ||
4270 | 470 | |||
4271 | 471 | /* advance past request_no */ | ||
4272 | 472 | bufp = buf + (sizeof(uint32_t) * 2); | ||
4273 | 473 | |||
4274 | 474 | req_serial = (uint32_t) *bufp; | ||
4275 | 475 | |||
4276 | 476 | /* advance past serial_no */ | ||
4277 | 477 | bufp += sizeof(uint32_t); | ||
4278 | 478 | |||
4279 | 479 | /* validate the rest of the parcel... */ | ||
4280 | 480 | offset = (sizeof(uint32_t) * 3); | ||
4281 | 481 | g_assert(!memcmp(bufp, csd->parcel_data + offset, | ||
4282 | 482 | csd->parcel_size - offset)); | ||
4283 | 483 | |||
4284 | 484 | /* Length does not include the length field. Network order. */ | ||
4285 | 485 | rsp.length = htonl(sizeof(rsp) - sizeof(rsp.length) + csd->rsp_size); | ||
4286 | 486 | rsp.unsolicited = 0; | ||
4287 | 487 | rsp.serial = req_serial; | ||
4288 | 488 | rsp.error = csd->rsp_error; | ||
4289 | 489 | |||
4290 | 490 | /* copy header */ | ||
4291 | 491 | memcpy(buf, &rsp, sizeof(rsp)); | ||
4292 | 492 | |||
4293 | 493 | if (csd->rsp_size) { | ||
4294 | 494 | bufp = buf + sizeof(rsp); | ||
4295 | 495 | |||
4296 | 496 | memcpy(bufp, csd->rsp_data, csd->rsp_size); | ||
4297 | 497 | } | ||
4298 | 498 | |||
4299 | 499 | |||
4300 | 500 | status = g_io_channel_write_chars(rcsd->server_io, | ||
4301 | 501 | buf, | ||
4302 | 502 | sizeof(rsp) + csd->rsp_size, | ||
4303 | 503 | &wbytes, NULL); | ||
4304 | 504 | |||
4305 | 505 | /* FIXME: assert wbytes is correct */ | ||
4306 | 506 | |||
4307 | 507 | g_assert(status == G_IO_STATUS_NORMAL); | ||
4308 | 508 | |||
4309 | 509 | g_free(buf); | ||
4310 | 510 | g_io_channel_unref(rcsd->server_io); | ||
4311 | 511 | |||
4312 | 512 | return FALSE; | ||
4313 | 513 | } | ||
4314 | 514 | |||
4315 | 515 | static gboolean on_socket_connected(GIOChannel *chan, GIOCondition cond, | ||
4316 | 516 | gpointer data) | ||
4317 | 517 | { | ||
4318 | 518 | struct rilmodemcs_data *rcsd = data; | ||
4319 | 519 | const struct cs_data *csd = rcsd->test_data; | ||
4320 | 520 | struct sockaddr saddr; | ||
4321 | 521 | unsigned int len = sizeof(saddr); | ||
4322 | 522 | int fd; | ||
4323 | 523 | GIOChannel *server_io = NULL; | ||
4324 | 524 | GIOStatus status; | ||
4325 | 525 | |||
4326 | 526 | g_assert(cond == G_IO_IN); | ||
4327 | 527 | |||
4328 | 528 | fd = accept(rcsd->sk, &saddr, &len); | ||
4329 | 529 | g_assert(fd != -1); | ||
4330 | 530 | |||
4331 | 531 | server_io = g_io_channel_unix_new(fd); | ||
4332 | 532 | g_assert(server_io != NULL); | ||
4337 | 533 | 451 | ||
4338 | 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. */ |
4341 | 535 | rcsd->cs = ofono_call_settings_create(NULL, OFONO_RIL_VENDOR_AOSP, | 453 | rcd->cs = ofono_call_settings_create(NULL, OFONO_RIL_VENDOR_AOSP, |
4342 | 536 | "rilmodem", rcsd); | 454 | "rilmodem", rcd); |
4343 | 537 | 455 | ||
4344 | 538 | /* add_idle doesn't work, read blocks main loop!!! */ | 456 | /* add_idle doesn't work, read blocks main loop!!! */ |
4396 | 539 | g_assert(csd->start_func(rcsd) == FALSE); | 457 | g_assert(csd->start_func(rcd) == FALSE); |
4346 | 540 | |||
4347 | 541 | status = g_io_channel_set_encoding(server_io, NULL, NULL); | ||
4348 | 542 | g_assert(status == G_IO_STATUS_NORMAL); | ||
4349 | 543 | |||
4350 | 544 | g_io_channel_set_buffered(server_io, FALSE); | ||
4351 | 545 | g_io_channel_set_close_on_unref(server_io, TRUE); | ||
4352 | 546 | |||
4353 | 547 | rcsd->server_io = server_io; | ||
4354 | 548 | |||
4355 | 549 | g_idle_add(read_server, rcsd); | ||
4356 | 550 | |||
4357 | 551 | /* single-shot callback */ | ||
4358 | 552 | return FALSE; | ||
4359 | 553 | } | ||
4360 | 554 | |||
4361 | 555 | static void create_server_socket(const char *sock_path, | ||
4362 | 556 | struct rilmodemcs_data *rcsd) | ||
4363 | 557 | { | ||
4364 | 558 | GIOChannel *io; | ||
4365 | 559 | struct sockaddr_un addr; | ||
4366 | 560 | int retval; | ||
4367 | 561 | |||
4368 | 562 | rcsd->sk = socket(AF_UNIX, SOCK_STREAM, 0); | ||
4369 | 563 | g_assert(rcsd->sk); | ||
4370 | 564 | |||
4371 | 565 | memset(&addr, 0, sizeof(addr)); | ||
4372 | 566 | addr.sun_family = AF_UNIX; | ||
4373 | 567 | strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1); | ||
4374 | 568 | |||
4375 | 569 | /* Unlink any existing socket for this session */ | ||
4376 | 570 | unlink(addr.sun_path); | ||
4377 | 571 | |||
4378 | 572 | retval = bind(rcsd->sk, (struct sockaddr *) &addr, sizeof(addr)); | ||
4379 | 573 | g_assert(retval >= 0); | ||
4380 | 574 | |||
4381 | 575 | retval = listen(rcsd->sk, 0); | ||
4382 | 576 | g_assert(retval >= 0); | ||
4383 | 577 | |||
4384 | 578 | io = g_io_channel_unix_new(rcsd->sk); | ||
4385 | 579 | g_assert(io != NULL); | ||
4386 | 580 | |||
4387 | 581 | g_io_channel_set_close_on_unref(io, TRUE); | ||
4388 | 582 | g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL); | ||
4389 | 583 | |||
4390 | 584 | rcsd->server_watch = g_io_add_watch_full(io, | ||
4391 | 585 | G_PRIORITY_DEFAULT, | ||
4392 | 586 | G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, | ||
4393 | 587 | on_socket_connected, rcsd, NULL); | ||
4394 | 588 | |||
4395 | 589 | g_io_channel_unref(io); | ||
4397 | 590 | } | 458 | } |
4398 | 591 | 459 | ||
4399 | 592 | /* | 460 | /* |
4400 | 593 | * This unit test: | 461 | * This unit test: |
4401 | 594 | * - does some test data setup | 462 | * - does some test data setup |
4402 | 595 | * - configures a dummy server socket | 463 | * - configures a dummy server socket |
4403 | 596 | * - on_socket_connected: callback for | ||
4404 | 597 | * incoming socket connects | ||
4405 | 598 | * - creates a new gril client instance | 464 | * - creates a new gril client instance |
4406 | 599 | * - triggers a connect to the dummy | 465 | * - triggers a connect to the dummy |
4407 | 600 | * server socket | 466 | * server socket |
4408 | @@ -603,27 +469,31 @@ | |||
4409 | 603 | static void test_cs_func(gconstpointer data) | 469 | static void test_cs_func(gconstpointer data) |
4410 | 604 | { | 470 | { |
4411 | 605 | const struct cs_data *csd = data; | 471 | const struct cs_data *csd = data; |
4413 | 606 | struct rilmodemcs_data *rcsd; | 472 | struct rilmodem_cs_data *rcd; |
4414 | 607 | 473 | ||
4415 | 608 | ril_call_settings_init(); | 474 | ril_call_settings_init(); |
4416 | 609 | 475 | ||
4425 | 610 | rcsd = g_new0(struct rilmodemcs_data, 1); | 476 | rcd = g_new0(struct rilmodem_cs_data, 1); |
4426 | 611 | 477 | ||
4427 | 612 | rcsd->test_data = csd; | 478 | rcd->test_data = csd; |
4428 | 613 | 479 | ||
4429 | 614 | create_server_socket("/tmp/unittestril", rcsd); | 480 | rcd->serverd = rilmodem_test_server_create(&server_connect_cb, |
4430 | 615 | 481 | &csd->rtd, rcd); | |
4431 | 616 | rcsd->ril = g_ril_new("/tmp/unittestril", OFONO_RIL_VENDOR_AOSP); | 482 | |
4432 | 617 | g_assert(rcsd->ril != NULL); | 483 | rcd->ril = g_ril_new(rilmodem_test_get_socket_name(rcd->serverd), |
4433 | 484 | OFONO_RIL_VENDOR_AOSP); | ||
4434 | 485 | g_assert(rcd->ril != NULL); | ||
4435 | 618 | 486 | ||
4436 | 619 | mainloop = g_main_loop_new(NULL, FALSE); | 487 | mainloop = g_main_loop_new(NULL, FALSE); |
4437 | 620 | 488 | ||
4438 | 621 | g_main_loop_run(mainloop); | 489 | g_main_loop_run(mainloop); |
4439 | 622 | g_main_loop_unref(mainloop); | 490 | g_main_loop_unref(mainloop); |
4440 | 623 | 491 | ||
4444 | 624 | csdriver->remove(rcsd->cs); | 492 | csdriver->remove(rcd->cs); |
4445 | 625 | g_ril_unref(rcsd->ril); | 493 | g_ril_unref(rcd->ril); |
4446 | 626 | g_free(rcsd); | 494 | g_free(rcd); |
4447 | 495 | |||
4448 | 496 | rilmodem_test_server_close(rcd->serverd); | ||
4449 | 627 | 497 | ||
4450 | 628 | ril_call_settings_exit(); | 498 | ril_call_settings_exit(); |
4451 | 629 | } | 499 | } |
4452 | 630 | 500 | ||
4453 | === added file 'unit/test-rilmodem-sms.c' | |||
4454 | --- unit/test-rilmodem-sms.c 1970-01-01 00:00:00 +0000 | |||
4455 | +++ unit/test-rilmodem-sms.c 2016-03-14 09:03:03 +0000 | |||
4456 | @@ -0,0 +1,596 @@ | |||
4457 | 1 | /* | ||
4458 | 2 | * | ||
4459 | 3 | * oFono - Open Source Telephony | ||
4460 | 4 | * | ||
4461 | 5 | * Copyright (C) 2015 Canonical Ltd. | ||
4462 | 6 | * | ||
4463 | 7 | * This program is free software; you can redistribute it and/or modify | ||
4464 | 8 | * it under the terms of the GNU General Public License version 2 as | ||
4465 | 9 | * published by the Free Software Foundation. | ||
4466 | 10 | * | ||
4467 | 11 | * This program is distributed in the hope that it will be useful, | ||
4468 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4469 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4470 | 14 | * GNU General Public License for more details. | ||
4471 | 15 | * | ||
4472 | 16 | * You should have received a copy of the GNU General Public License | ||
4473 | 17 | * along with this program; if not, write to the Free Software | ||
4474 | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
4475 | 19 | * | ||
4476 | 20 | */ | ||
4477 | 21 | |||
4478 | 22 | #ifdef HAVE_CONFIG_H | ||
4479 | 23 | #include <config.h> | ||
4480 | 24 | #endif | ||
4481 | 25 | |||
4482 | 26 | #define _GNU_SOURCE | ||
4483 | 27 | #include <assert.h> | ||
4484 | 28 | #include <errno.h> | ||
4485 | 29 | #include <glib.h> | ||
4486 | 30 | #include <stdio.h> | ||
4487 | 31 | #include <netinet/in.h> | ||
4488 | 32 | #include <sys/socket.h> | ||
4489 | 33 | #include <sys/un.h> | ||
4490 | 34 | #include <unistd.h> | ||
4491 | 35 | |||
4492 | 36 | #include <ofono/modem.h> | ||
4493 | 37 | #include <ofono/types.h> | ||
4494 | 38 | #include <ofono/sms.h> | ||
4495 | 39 | #include <gril.h> | ||
4496 | 40 | |||
4497 | 41 | #include "common.h" | ||
4498 | 42 | #include "ril_constants.h" | ||
4499 | 43 | #include "rilmodem-test-server.h" | ||
4500 | 44 | |||
4501 | 45 | static GMainLoop *mainloop; | ||
4502 | 46 | |||
4503 | 47 | static const struct ofono_sms_driver *smsdriver; | ||
4504 | 48 | |||
4505 | 49 | struct rilmodem_sms_data { | ||
4506 | 50 | GRil *ril; | ||
4507 | 51 | struct ofono_modem *modem; | ||
4508 | 52 | gconstpointer test_data; | ||
4509 | 53 | struct ofono_sms *sms; | ||
4510 | 54 | struct server_data *serverd; | ||
4511 | 55 | }; | ||
4512 | 56 | |||
4513 | 57 | typedef gboolean (*StartFunc)(gpointer data); | ||
4514 | 58 | |||
4515 | 59 | struct sms_data { | ||
4516 | 60 | StartFunc start_func; | ||
4517 | 61 | |||
4518 | 62 | const unsigned char *pdu; | ||
4519 | 63 | gint pdu_len; | ||
4520 | 64 | gint tpdu_len; | ||
4521 | 65 | gint mms; | ||
4522 | 66 | |||
4523 | 67 | struct rilmodem_test_data rtd; | ||
4524 | 68 | enum ofono_error_type error_type; | ||
4525 | 69 | |||
4526 | 70 | const struct ofono_phone_number ph; | ||
4527 | 71 | gint mr; | ||
4528 | 72 | }; | ||
4529 | 73 | |||
4530 | 74 | static void sca_query_callback(const struct ofono_error *error, | ||
4531 | 75 | const struct ofono_phone_number *ph, | ||
4532 | 76 | gpointer data) | ||
4533 | 77 | { | ||
4534 | 78 | struct rilmodem_sms_data *rsd = data; | ||
4535 | 79 | const struct sms_data *sd = rsd->test_data; | ||
4536 | 80 | |||
4537 | 81 | g_assert(error->type == sd->error_type); | ||
4538 | 82 | |||
4539 | 83 | if (error->type == OFONO_ERROR_TYPE_NO_ERROR) { | ||
4540 | 84 | g_assert(ph->type == sd->ph.type); | ||
4541 | 85 | g_assert(strcmp(ph->number, sd->ph.number) == 0); | ||
4542 | 86 | } | ||
4543 | 87 | |||
4544 | 88 | g_main_loop_quit(mainloop); | ||
4545 | 89 | } | ||
4546 | 90 | |||
4547 | 91 | static void sca_set_callback(const struct ofono_error *error, gpointer data) | ||
4548 | 92 | { | ||
4549 | 93 | struct rilmodem_sms_data *rsd = data; | ||
4550 | 94 | const struct sms_data *sd = rsd->test_data; | ||
4551 | 95 | |||
4552 | 96 | g_assert(error->type == sd->error_type); | ||
4553 | 97 | |||
4554 | 98 | g_main_loop_quit(mainloop); | ||
4555 | 99 | } | ||
4556 | 100 | |||
4557 | 101 | static void submit_callback(const struct ofono_error *error, int mr, | ||
4558 | 102 | gpointer data) | ||
4559 | 103 | { | ||
4560 | 104 | struct rilmodem_sms_data *rsd = data; | ||
4561 | 105 | const struct sms_data *sd = rsd->test_data; | ||
4562 | 106 | |||
4563 | 107 | g_assert(error->type == sd->error_type); | ||
4564 | 108 | g_assert(mr == sd->mr); | ||
4565 | 109 | |||
4566 | 110 | g_main_loop_quit(mainloop); | ||
4567 | 111 | } | ||
4568 | 112 | |||
4569 | 113 | static gboolean trigger_sca_query(gpointer data) | ||
4570 | 114 | { | ||
4571 | 115 | struct rilmodem_sms_data *rsd = data; | ||
4572 | 116 | |||
4573 | 117 | g_assert(smsdriver->sca_query != NULL); | ||
4574 | 118 | smsdriver->sca_query(rsd->sms, sca_query_callback, rsd); | ||
4575 | 119 | |||
4576 | 120 | return FALSE; | ||
4577 | 121 | } | ||
4578 | 122 | |||
4579 | 123 | static gboolean trigger_sca_set(gpointer data) | ||
4580 | 124 | { | ||
4581 | 125 | struct rilmodem_sms_data *rsd = data; | ||
4582 | 126 | const struct sms_data *sd = rsd->test_data; | ||
4583 | 127 | |||
4584 | 128 | g_assert(smsdriver->sca_set != NULL); | ||
4585 | 129 | smsdriver->sca_set(rsd->sms, &sd->ph, sca_set_callback, rsd); | ||
4586 | 130 | |||
4587 | 131 | return FALSE; | ||
4588 | 132 | } | ||
4589 | 133 | |||
4590 | 134 | static gboolean trigger_submit(gpointer data) | ||
4591 | 135 | { | ||
4592 | 136 | struct rilmodem_sms_data *rsd = data; | ||
4593 | 137 | const struct sms_data *sd = rsd->test_data; | ||
4594 | 138 | |||
4595 | 139 | g_assert(smsdriver->submit != NULL); | ||
4596 | 140 | |||
4597 | 141 | smsdriver->submit(rsd->sms, sd->pdu, sd->pdu_len, sd->tpdu_len, | ||
4598 | 142 | sd->mms, submit_callback, rsd); | ||
4599 | 143 | |||
4600 | 144 | return FALSE; | ||
4601 | 145 | } | ||
4602 | 146 | |||
4603 | 147 | static gboolean trigger_new_sms(gpointer data) | ||
4604 | 148 | { | ||
4605 | 149 | struct rilmodem_sms_data *rsd = data; | ||
4606 | 150 | const struct sms_data *sd = rsd->test_data; | ||
4607 | 151 | |||
4608 | 152 | rilmodem_test_server_write(rsd->serverd, sd->rtd.req_data, | ||
4609 | 153 | sd->rtd.req_size); | ||
4610 | 154 | |||
4611 | 155 | return FALSE; | ||
4612 | 156 | } | ||
4613 | 157 | |||
4614 | 158 | /* RIL_REQUEST_GET_SMSC_ADDRESS */ | ||
4615 | 159 | static const guchar req_get_smsc_address_parcel_1[] = { | ||
4616 | 160 | 0x00, 0x00, 0x00, 0x08, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
4617 | 161 | }; | ||
4618 | 162 | |||
4619 | 163 | |||
4620 | 164 | /* | ||
4621 | 165 | * RIL_REQUEST_GET_SMSC_ADDRESS reply with the following data: | ||
4622 | 166 | * | ||
4623 | 167 | * {number="+34607003110"} | ||
4624 | 168 | */ | ||
4625 | 169 | static const guchar rsp_get_smsc_address_data_1[] = { | ||
4626 | 170 | 0x0d, 0x00, 0x00, 0x00, 0x22, 0x00, 0x2b, 0x00, 0x33, 0x00, 0x34, 0x00, | ||
4627 | 171 | 0x36, 0x00, 0x30, 0x00, 0x37, 0x00, 0x30, 0x00, 0x30, 0x00, 0x33, 0x00, | ||
4628 | 172 | 0x31, 0x00, 0x31, 0x00, 0x30, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
4629 | 173 | }; | ||
4630 | 174 | |||
4631 | 175 | static const struct sms_data testdata_sca_query_valid_1 = { | ||
4632 | 176 | .start_func = trigger_sca_query, | ||
4633 | 177 | .rtd = { | ||
4634 | 178 | .req_data = req_get_smsc_address_parcel_1, | ||
4635 | 179 | .req_size = sizeof(req_get_smsc_address_parcel_1), | ||
4636 | 180 | .rsp_data = rsp_get_smsc_address_data_1, | ||
4637 | 181 | .rsp_size = sizeof(rsp_get_smsc_address_data_1), | ||
4638 | 182 | .rsp_error = RIL_E_SUCCESS, | ||
4639 | 183 | }, | ||
4640 | 184 | .ph = { .number = "34607003110", .type = 145 }, | ||
4641 | 185 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, | ||
4642 | 186 | }; | ||
4643 | 187 | |||
4644 | 188 | /* | ||
4645 | 189 | * RIL_REQUEST_GET_SMSC_ADDRESS reply with no data, which should | ||
4646 | 190 | * trigger a callback failure. | ||
4647 | 191 | */ | ||
4648 | 192 | static const struct sms_data testdata_sca_query_invalid_1 = { | ||
4649 | 193 | .start_func = trigger_sca_query, | ||
4650 | 194 | .rtd = { | ||
4651 | 195 | .req_data = req_get_smsc_address_parcel_1, | ||
4652 | 196 | .req_size = sizeof(req_get_smsc_address_parcel_1), | ||
4653 | 197 | .rsp_error = RIL_E_SUCCESS, | ||
4654 | 198 | }, | ||
4655 | 199 | .error_type = OFONO_ERROR_TYPE_FAILURE, | ||
4656 | 200 | }; | ||
4657 | 201 | |||
4658 | 202 | /* | ||
4659 | 203 | * RIL_REQUEST_GET_SMSC_ADDRESS reply with no quotes found which | ||
4660 | 204 | * should trigger a callback failure. | ||
4661 | 205 | */ | ||
4662 | 206 | static const guchar rsp_get_smsc_address_data_3[] = { | ||
4663 | 207 | 0x02, 0x00, 0x00, 0x00, 0x22, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
4664 | 208 | }; | ||
4665 | 209 | |||
4666 | 210 | static const struct sms_data testdata_sca_query_invalid_2 = { | ||
4667 | 211 | .start_func = trigger_sca_query, | ||
4668 | 212 | .ph = { .number = "34607003110", .type = 145 }, | ||
4669 | 213 | .rtd = { | ||
4670 | 214 | .req_data = req_get_smsc_address_parcel_1, | ||
4671 | 215 | .req_size = sizeof(req_get_smsc_address_parcel_1), | ||
4672 | 216 | .rsp_data = rsp_get_smsc_address_data_3, | ||
4673 | 217 | .rsp_size = sizeof(rsp_get_smsc_address_data_3), | ||
4674 | 218 | .rsp_error = RIL_E_SUCCESS, | ||
4675 | 219 | }, | ||
4676 | 220 | .error_type = OFONO_ERROR_TYPE_FAILURE, | ||
4677 | 221 | }; | ||
4678 | 222 | |||
4679 | 223 | /* GENERIC_FAILURE returned in RIL reply */ | ||
4680 | 224 | static const struct sms_data testdata_sca_query_invalid_3 = { | ||
4681 | 225 | .start_func = trigger_sca_query, | ||
4682 | 226 | .rtd = { | ||
4683 | 227 | .req_data = req_get_smsc_address_parcel_1, | ||
4684 | 228 | .req_size = sizeof(req_get_smsc_address_parcel_1), | ||
4685 | 229 | .rsp_error = RIL_E_GENERIC_FAILURE, | ||
4686 | 230 | }, | ||
4687 | 231 | .error_type = OFONO_ERROR_TYPE_FAILURE, | ||
4688 | 232 | }; | ||
4689 | 233 | |||
4690 | 234 | /* | ||
4691 | 235 | * RIL_REQUEST_SET_SMSC_ADDRESS with the following data: | ||
4692 | 236 | * | ||
4693 | 237 | * {number="+34607003110"} | ||
4694 | 238 | */ | ||
4695 | 239 | static const guchar req_set_smsc_address_parcel_1[] = { | ||
4696 | 240 | +0x00, 0x00, 0x00, 0x2C, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
4697 | 241 | +0x0e, 0x00, 0x00, 0x00, 0x22, 0x00, 0x2b, 0x00, 0x33, 0x00, 0x34, 0x00, | ||
4698 | 242 | +0x36, 0x00, 0x30, 0x00, 0x37, 0x00, 0x30, 0x00, 0x30, 0x00, 0x33, 0x00, | ||
4699 | 243 | +0x31, 0x00, 0x31, 0x00, 0x30, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
4700 | 244 | }; | ||
4701 | 245 | |||
4702 | 246 | static const struct sms_data testdata_sca_set_valid_1 = { | ||
4703 | 247 | .start_func = trigger_sca_set, | ||
4704 | 248 | .ph = { .number = "34607003110", .type = 145 }, | ||
4705 | 249 | .rtd = { | ||
4706 | 250 | .req_data = req_set_smsc_address_parcel_1, | ||
4707 | 251 | .req_size = sizeof(req_set_smsc_address_parcel_1), | ||
4708 | 252 | .rsp_error = RIL_E_SUCCESS, | ||
4709 | 253 | }, | ||
4710 | 254 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, | ||
4711 | 255 | }; | ||
4712 | 256 | |||
4713 | 257 | /* GENERIC_FAILURE returned in RIL reply */ | ||
4714 | 258 | static const struct sms_data testdata_sca_set_invalid_1 = { | ||
4715 | 259 | .start_func = trigger_sca_set, | ||
4716 | 260 | .ph = { .number = "34607003110", .type = 145 }, | ||
4717 | 261 | .rtd = { | ||
4718 | 262 | .req_data = req_set_smsc_address_parcel_1, | ||
4719 | 263 | .req_size = sizeof(req_set_smsc_address_parcel_1), | ||
4720 | 264 | .rsp_error = RIL_E_GENERIC_FAILURE, | ||
4721 | 265 | }, | ||
4722 | 266 | .error_type = OFONO_ERROR_TYPE_FAILURE, | ||
4723 | 267 | }; | ||
4724 | 268 | |||
4725 | 269 | static const unsigned char req_send_sms_pdu_valid_1[] = { | ||
4726 | 270 | 0x00, 0x11, 0x00, 0x09, 0x81, 0x36, 0x54, 0x39, 0x80, 0xf5, 0x00, 0x00, | ||
4727 | 271 | 0xa7, 0x0a, 0xc8, 0x37, 0x3b, 0x0c, 0x6a, 0xd7, 0xdd, 0xe4, 0x37 | ||
4728 | 272 | }; | ||
4729 | 273 | |||
4730 | 274 | static const guchar req_send_sms_parcel_1[] = { | ||
4731 | 275 | 0x00, 0x00, 0x00, 0x70, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
4732 | 276 | 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, | ||
4733 | 277 | 0x31, 0x00, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x39, 0x00, | ||
4734 | 278 | 0x38, 0x00, 0x31, 0x00, 0x33, 0x00, 0x36, 0x00, 0x35, 0x00, 0x34, 0x00, | ||
4735 | 279 | 0x33, 0x00, 0x39, 0x00, 0x38, 0x00, 0x30, 0x00, 0x46, 0x00, 0x35, 0x00, | ||
4736 | 280 | 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x41, 0x00, 0x37, 0x00, | ||
4737 | 281 | 0x30, 0x00, 0x41, 0x00, 0x43, 0x00, 0x38, 0x00, 0x33, 0x00, 0x37, 0x00, | ||
4738 | 282 | 0x33, 0x00, 0x42, 0x00, 0x30, 0x00, 0x43, 0x00, 0x36, 0x00, 0x41, 0x00, | ||
4739 | 283 | 0x44, 0x00, 0x37, 0x00, 0x44, 0x00, 0x44, 0x00, 0x45, 0x00, 0x34, 0x00, | ||
4740 | 284 | 0x33, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
4741 | 285 | }; | ||
4742 | 286 | |||
4743 | 287 | /* | ||
4744 | 288 | * SEND_SMS reply with the following data: | ||
4745 | 289 | * | ||
4746 | 290 | * messageRef=1 | ||
4747 | 291 | * ackPDU=NULL | ||
4748 | 292 | * errorCode=0 | ||
4749 | 293 | */ | ||
4750 | 294 | static const guchar rsp_send_sms_valid_1[] = { | ||
4751 | 295 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
4752 | 296 | }; | ||
4753 | 297 | |||
4754 | 298 | static const struct sms_data testdata_submit_valid_1 = { | ||
4755 | 299 | .start_func = trigger_submit, | ||
4756 | 300 | .pdu = req_send_sms_pdu_valid_1, | ||
4757 | 301 | .pdu_len = sizeof(req_send_sms_pdu_valid_1), | ||
4758 | 302 | .tpdu_len = sizeof(req_send_sms_pdu_valid_1) - 1, | ||
4759 | 303 | .mms = 0, | ||
4760 | 304 | .rtd = { | ||
4761 | 305 | .req_data = req_send_sms_parcel_1, | ||
4762 | 306 | .req_size = sizeof(req_send_sms_parcel_1), | ||
4763 | 307 | .rsp_data = rsp_send_sms_valid_1, | ||
4764 | 308 | .rsp_size = sizeof(rsp_send_sms_valid_1), | ||
4765 | 309 | .rsp_error = RIL_E_SUCCESS, | ||
4766 | 310 | }, | ||
4767 | 311 | .mr = 1, | ||
4768 | 312 | .error_type = OFONO_ERROR_TYPE_NO_ERROR, | ||
4769 | 313 | }; | ||
4770 | 314 | |||
4771 | 315 | /* | ||
4772 | 316 | * SEND_SMS reply with failure indicated | ||
4773 | 317 | */ | ||
4774 | 318 | static const struct sms_data testdata_submit_invalid_1 = { | ||
4775 | 319 | .start_func = trigger_submit, | ||
4776 | 320 | .pdu = req_send_sms_pdu_valid_1, | ||
4777 | 321 | .pdu_len = sizeof(req_send_sms_pdu_valid_1), | ||
4778 | 322 | .tpdu_len = sizeof(req_send_sms_pdu_valid_1) - 1, | ||
4779 | 323 | .mms = 0, | ||
4780 | 324 | .rtd = { | ||
4781 | 325 | .req_data = req_send_sms_parcel_1, | ||
4782 | 326 | .req_size = sizeof(req_send_sms_parcel_1), | ||
4783 | 327 | .rsp_error = RIL_E_GENERIC_FAILURE, | ||
4784 | 328 | }, | ||
4785 | 329 | .error_type = OFONO_ERROR_TYPE_FAILURE, | ||
4786 | 330 | }; | ||
4787 | 331 | |||
4788 | 332 | /* | ||
4789 | 333 | * The following hexadecimal data represents a serialized Binder parcel | ||
4790 | 334 | * instance containing a valid RIL_UNSOL_RESPONSE_NEW_SMS message | ||
4791 | 335 | * with the following parameter (SMSC address length is 7): | ||
4792 | 336 | * | ||
4793 | 337 | * {07914306073011F0040B914336543980F50000310113212002400AC8373B0C6AD7DDE437} | ||
4794 | 338 | * {069143060730F0040B914336543980F50000310113212002400AC8373B0C6AD7DDE437} | ||
4795 | 339 | */ | ||
4796 | 340 | static const guchar unsol_response_new_sms_parcel_1[] = { | ||
4797 | 341 | 0x00, 0x00, 0x00, 0xA0, 0x01, 0x00, 0x00, 0x00, 0xEB, 0x03, 0x00, 0x00, | ||
4798 | 342 | 0x48, 0x00, 0x00, 0x00, 0x30, 0x00, 0x37, 0x00, 0x39, 0x00, 0x31, 0x00, | ||
4799 | 343 | 0x34, 0x00, 0x33, 0x00, 0x30, 0x00, 0x36, 0x00, 0x30, 0x00, 0x37, 0x00, | ||
4800 | 344 | 0x33, 0x00, 0x30, 0x00, 0x31, 0x00, 0x31, 0x00, 0x46, 0x00, 0x30, 0x00, | ||
4801 | 345 | 0x30, 0x00, 0x34, 0x00, 0x30, 0x00, 0x42, 0x00, 0x39, 0x00, 0x31, 0x00, | ||
4802 | 346 | 0x34, 0x00, 0x33, 0x00, 0x33, 0x00, 0x36, 0x00, 0x35, 0x00, 0x34, 0x00, | ||
4803 | 347 | 0x33, 0x00, 0x39, 0x00, 0x38, 0x00, 0x30, 0x00, 0x46, 0x00, 0x35, 0x00, | ||
4804 | 348 | 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x33, 0x00, 0x31, 0x00, | ||
4805 | 349 | 0x30, 0x00, 0x31, 0x00, 0x31, 0x00, 0x33, 0x00, 0x32, 0x00, 0x31, 0x00, | ||
4806 | 350 | 0x32, 0x00, 0x30, 0x00, 0x30, 0x00, 0x32, 0x00, 0x34, 0x00, 0x30, 0x00, | ||
4807 | 351 | 0x30, 0x00, 0x41, 0x00, 0x43, 0x00, 0x38, 0x00, 0x33, 0x00, 0x37, 0x00, | ||
4808 | 352 | 0x33, 0x00, 0x42, 0x00, 0x30, 0x00, 0x43, 0x00, 0x36, 0x00, 0x41, 0x00, | ||
4809 | 353 | 0x44, 0x00, 0x37, 0x00, 0x44, 0x00, 0x44, 0x00, 0x45, 0x00, 0x34, 0x00, | ||
4810 | 354 | 0x33, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
4811 | 355 | }; | ||
4812 | 356 | |||
4813 | 357 | const unsigned char new_sms_pdu_valid_1[] = { | ||
4814 | 358 | 0x07, 0x91, 0x43, 0x06, 0x07, 0x30, 0x11, 0xf0, 0x04, 0x0b, 0x91, 0x43, | ||
4815 | 359 | 0x36, 0x54, 0x39, 0x80, 0xf5, 0x00, 0x00, 0x31, 0x01, 0x13, 0x21, 0x20, | ||
4816 | 360 | 0x02, 0x40, 0x0a, 0xc8, 0x37, 0x3b, 0x0c, 0x6a, 0xd7, 0xdd, 0xe4, 0x37 | ||
4817 | 361 | }; | ||
4818 | 362 | |||
4819 | 363 | static const struct sms_data testdata_new_sms_valid_1 = { | ||
4820 | 364 | .start_func = trigger_new_sms, | ||
4821 | 365 | .rtd = { | ||
4822 | 366 | .req_data = unsol_response_new_sms_parcel_1, | ||
4823 | 367 | .req_size = sizeof(unsol_response_new_sms_parcel_1), | ||
4824 | 368 | .unsol_test = TRUE, | ||
4825 | 369 | }, | ||
4826 | 370 | .pdu = new_sms_pdu_valid_1, | ||
4827 | 371 | .pdu_len = sizeof(new_sms_pdu_valid_1), | ||
4828 | 372 | .tpdu_len = 28, | ||
4829 | 373 | }; | ||
4830 | 374 | |||
4831 | 375 | /* | ||
4832 | 376 | * The following hexadecimal data represents a serialized Binder parcel | ||
4833 | 377 | * instance containing a valid UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT message | ||
4834 | 378 | * with the following parameter (SMSC address length is 6): | ||
4835 | 379 | * | ||
4836 | 380 | * {069143060730F0040B914336543980F50000310113212002400AC8373B0C6AD7DDE437} | ||
4837 | 381 | */ | ||
4838 | 382 | static const guchar unsol_response_new_sms_parcel_2[] = { | ||
4839 | 383 | 0x00, 0x00, 0x00, 0x9C, 0x01, 0x00, 0x00, 0x00, 0xEC, 0x03, 0x00, 0x00, | ||
4840 | 384 | 0x46, 0x00, 0x00, 0x00, 0x30, 0x00, 0x36, 0x00, 0x39, 0x00, 0x31, 0x00, | ||
4841 | 385 | 0x34, 0x00, 0x33, 0x00, 0x30, 0x00, 0x36, 0x00, 0x30, 0x00, 0x37, 0x00, | ||
4842 | 386 | 0x33, 0x00, 0x30, 0x00, 0x46, 0x00, 0x30, 0x00, 0x30, 0x00, 0x34, 0x00, | ||
4843 | 387 | 0x30, 0x00, 0x42, 0x00, 0x39, 0x00, 0x31, 0x00, 0x34, 0x00, 0x33, 0x00, | ||
4844 | 388 | 0x33, 0x00, 0x36, 0x00, 0x35, 0x00, 0x34, 0x00, 0x33, 0x00, 0x39, 0x00, | ||
4845 | 389 | 0x38, 0x00, 0x30, 0x00, 0x46, 0x00, 0x35, 0x00, 0x30, 0x00, 0x30, 0x00, | ||
4846 | 390 | 0x30, 0x00, 0x30, 0x00, 0x33, 0x00, 0x31, 0x00, 0x30, 0x00, 0x31, 0x00, | ||
4847 | 391 | 0x31, 0x00, 0x33, 0x00, 0x32, 0x00, 0x31, 0x00, 0x32, 0x00, 0x30, 0x00, | ||
4848 | 392 | 0x30, 0x00, 0x32, 0x00, 0x34, 0x00, 0x30, 0x00, 0x30, 0x00, 0x41, 0x00, | ||
4849 | 393 | 0x43, 0x00, 0x38, 0x00, 0x33, 0x00, 0x37, 0x00, 0x33, 0x00, 0x42, 0x00, | ||
4850 | 394 | 0x30, 0x00, 0x43, 0x00, 0x36, 0x00, 0x41, 0x00, 0x44, 0x00, 0x37, 0x00, | ||
4851 | 395 | 0x44, 0x00, 0x44, 0x00, 0x45, 0x00, 0x34, 0x00, 0x33, 0x00, 0x37, 0x00, | ||
4852 | 396 | 0x00, 0x00, 0x00, 0x00 | ||
4853 | 397 | }; | ||
4854 | 398 | |||
4855 | 399 | const unsigned char new_sms_pdu_valid_2[] = { | ||
4856 | 400 | 0x06, 0x91, 0x43, 0x06, 0x07, 0x30, 0xf0, 0x04, 0x0b, 0x91, 0x43, 0x36, | ||
4857 | 401 | 0x54, 0x39, 0x80, 0xf5, 0x00, 0x00, 0x31, 0x01, 0x13, 0x21, 0x20, 0x02, | ||
4858 | 402 | 0x40, 0x0a, 0xc8, 0x37, 0x3b, 0x0c, 0x6a, 0xd7, 0xdd, 0xe4, 0x37 | ||
4859 | 403 | }; | ||
4860 | 404 | |||
4861 | 405 | static const struct sms_data testdata_new_sms_valid_2 = { | ||
4862 | 406 | .start_func = trigger_new_sms, | ||
4863 | 407 | .rtd = { | ||
4864 | 408 | .req_data = unsol_response_new_sms_parcel_2, | ||
4865 | 409 | .req_size = sizeof(unsol_response_new_sms_parcel_2), | ||
4866 | 410 | .unsol_test = TRUE, | ||
4867 | 411 | }, | ||
4868 | 412 | .pdu = new_sms_pdu_valid_2, | ||
4869 | 413 | .pdu_len = sizeof(new_sms_pdu_valid_2), | ||
4870 | 414 | .tpdu_len = 28, | ||
4871 | 415 | }; | ||
4872 | 416 | |||
4873 | 417 | /* Declarations && Re-implementations of core functions. */ | ||
4874 | 418 | void ril_sms_exit(void); | ||
4875 | 419 | void ril_sms_init(void); | ||
4876 | 420 | |||
4877 | 421 | struct ofono_sms { | ||
4878 | 422 | void *driver_data; | ||
4879 | 423 | const struct sms_data *sd; | ||
4880 | 424 | }; | ||
4881 | 425 | |||
4882 | 426 | struct ofono_sms *ofono_sms_create(struct ofono_modem *modem, | ||
4883 | 427 | unsigned int vendor, | ||
4884 | 428 | const char *driver, | ||
4885 | 429 | void *data) | ||
4886 | 430 | { | ||
4887 | 431 | struct rilmodem_sms_data *rsd = data; | ||
4888 | 432 | struct ofono_sms *sms = g_new0(struct ofono_sms, 1); | ||
4889 | 433 | int retval; | ||
4890 | 434 | |||
4891 | 435 | retval = smsdriver->probe(sms, OFONO_RIL_VENDOR_AOSP, rsd->ril); | ||
4892 | 436 | g_assert(retval == 0); | ||
4893 | 437 | |||
4894 | 438 | return sms; | ||
4895 | 439 | } | ||
4896 | 440 | |||
4897 | 441 | int ofono_sms_driver_register(const struct ofono_sms_driver *d) | ||
4898 | 442 | { | ||
4899 | 443 | if (smsdriver == NULL) | ||
4900 | 444 | smsdriver = d; | ||
4901 | 445 | |||
4902 | 446 | return 0; | ||
4903 | 447 | } | ||
4904 | 448 | |||
4905 | 449 | void ofono_sms_set_data(struct ofono_sms *sms, void *data) | ||
4906 | 450 | { | ||
4907 | 451 | sms->driver_data = data; | ||
4908 | 452 | } | ||
4909 | 453 | |||
4910 | 454 | void *ofono_sms_get_data(struct ofono_sms *sms) | ||
4911 | 455 | { | ||
4912 | 456 | return sms->driver_data; | ||
4913 | 457 | } | ||
4914 | 458 | |||
4915 | 459 | void ofono_sms_register(struct ofono_sms *sms) | ||
4916 | 460 | { | ||
4917 | 461 | } | ||
4918 | 462 | |||
4919 | 463 | void ofono_sms_driver_unregister(const struct ofono_sms_driver *d) | ||
4920 | 464 | { | ||
4921 | 465 | } | ||
4922 | 466 | |||
4923 | 467 | void ofono_sms_deliver_notify(struct ofono_sms *sms, const unsigned char *pdu, | ||
4924 | 468 | int len, int tpdu_len) | ||
4925 | 469 | { | ||
4926 | 470 | g_assert(sms->sd->pdu_len == len); | ||
4927 | 471 | g_assert(sms->sd->tpdu_len == tpdu_len); | ||
4928 | 472 | g_assert(!memcmp(pdu, sms->sd->pdu, len)); | ||
4929 | 473 | |||
4930 | 474 | g_main_loop_quit(mainloop); | ||
4931 | 475 | } | ||
4932 | 476 | |||
4933 | 477 | void ofono_sms_status_notify(struct ofono_sms *sms, const unsigned char *pdu, | ||
4934 | 478 | int len, int tpdu_len) | ||
4935 | 479 | { | ||
4936 | 480 | ofono_sms_deliver_notify(sms, pdu, len, tpdu_len); | ||
4937 | 481 | } | ||
4938 | 482 | |||
4939 | 483 | /* | ||
4940 | 484 | * As all our architectures are little-endian except for | ||
4941 | 485 | * PowerPC, and the Binder wire-format differs slightly | ||
4942 | 486 | * depending on endian-ness, the following guards against test | ||
4943 | 487 | * failures when run on PowerPC. | ||
4944 | 488 | */ | ||
4945 | 489 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
4946 | 490 | |||
4947 | 491 | static void server_connect_cb(gpointer data) | ||
4948 | 492 | { | ||
4949 | 493 | struct rilmodem_sms_data *rsd = data; | ||
4950 | 494 | const struct sms_data *sd = rsd->test_data; | ||
4951 | 495 | |||
4952 | 496 | /* This causes local impl of _create() to call driver's probe func. */ | ||
4953 | 497 | rsd->sms = ofono_sms_create(NULL, OFONO_RIL_VENDOR_AOSP, | ||
4954 | 498 | "rilmodem", rsd); | ||
4955 | 499 | rsd->sms->sd = sd; | ||
4956 | 500 | |||
4957 | 501 | /* add_idle doesn't work, read blocks main loop!!! */ | ||
4958 | 502 | |||
4959 | 503 | if (sd->rtd.unsol_test) | ||
4960 | 504 | g_idle_add(sd->start_func, (void *) rsd); | ||
4961 | 505 | else | ||
4962 | 506 | g_assert(sd->start_func(rsd) == FALSE); | ||
4963 | 507 | } | ||
4964 | 508 | |||
4965 | 509 | /* | ||
4966 | 510 | * This unit test: | ||
4967 | 511 | * - does some test data setup | ||
4968 | 512 | * - configures a dummy server socket | ||
4969 | 513 | * - creates a new gril client instance | ||
4970 | 514 | * - triggers a connect to the dummy | ||
4971 | 515 | * server socket | ||
4972 | 516 | * - starts a mainloop | ||
4973 | 517 | */ | ||
4974 | 518 | static void test_sms_func(gconstpointer data) | ||
4975 | 519 | { | ||
4976 | 520 | const struct sms_data *sd = data; | ||
4977 | 521 | struct rilmodem_sms_data *rsd; | ||
4978 | 522 | |||
4979 | 523 | ril_sms_init(); | ||
4980 | 524 | |||
4981 | 525 | rsd = g_new0(struct rilmodem_sms_data, 1); | ||
4982 | 526 | |||
4983 | 527 | rsd->test_data = sd; | ||
4984 | 528 | |||
4985 | 529 | rsd->serverd = rilmodem_test_server_create(&server_connect_cb, | ||
4986 | 530 | &sd->rtd, rsd); | ||
4987 | 531 | |||
4988 | 532 | rsd->ril = g_ril_new(rilmodem_test_get_socket_name(rsd->serverd), | ||
4989 | 533 | OFONO_RIL_VENDOR_AOSP); | ||
4990 | 534 | g_assert(rsd->ril != NULL); | ||
4991 | 535 | |||
4992 | 536 | mainloop = g_main_loop_new(NULL, FALSE); | ||
4993 | 537 | |||
4994 | 538 | g_main_loop_run(mainloop); | ||
4995 | 539 | g_main_loop_unref(mainloop); | ||
4996 | 540 | |||
4997 | 541 | smsdriver->remove(rsd->sms); | ||
4998 | 542 | g_ril_unref(rsd->ril); | ||
4999 | 543 | g_free(rsd); | ||
5000 | 544 |
Basic tests performed on krillin, rc-proposed/ bq-aquaris. en #279, all looked good.