Merge lp:~awe/phablet-extras/ofono-raring into lp:phablet-extras/ofono
- ofono-raring
- Merge into ofono
Status: | Merged |
---|---|
Approved by: | Ricardo Salveti |
Approved revision: | 35 |
Merged at revision: | 30 |
Proposed branch: | lp:~awe/phablet-extras/ofono-raring |
Merge into: | lp:phablet-extras/ofono |
Prerequisite: | lp:~awe/phablet-extras/ofono-flatten |
Diff against target: |
6188 lines (+5905/-14) 31 files modified
Makefile.am (+37/-9) configure.ac (+5/-0) debian/changelog (+56/-0) debian/control (+3/-0) debian/ofono.install (+0/-2) debian/ofono.upstart (+6/-1) debian/rules (+2/-2) drivers/rilmodem/call-volume.c (+186/-0) drivers/rilmodem/devinfo.c (+171/-0) drivers/rilmodem/network-registration.c (+595/-0) drivers/rilmodem/rilmodem.c (+61/-0) drivers/rilmodem/rilmodem.h (+38/-0) drivers/rilmodem/rilutil.c (+372/-0) drivers/rilmodem/rilutil.h (+125/-0) drivers/rilmodem/sms.c (+357/-0) drivers/rilmodem/voicecall.c (+537/-0) gril/gfunc.h (+42/-0) gril/gril.c (+1160/-0) gril/gril.h (+102/-0) gril/grilio.c (+396/-0) gril/grilio.h (+69/-0) gril/grilresponse.h (+46/-0) gril/grilutil.c (+499/-0) gril/grilutil.h (+53/-0) gril/parcel.c (+181/-0) gril/parcel.h (+43/-0) gril/ril_constants.h (+244/-0) gril/ringbuffer.h (+107/-0) include/modem.h (+1/-0) plugins/ril.c (+395/-0) src/modem.c (+16/-0) |
To merge this branch: | bzr merge lp:~awe/phablet-extras/ofono-raring |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ricardo Salveti (community) | Approve | ||
PS Jenkins bot | continuous-integration | Approve | |
Review via email: mp+156908@code.launchpad.net |
Commit message
Re-based ofono/RILD code on new upstream version ofono-1.
Description of the change
This MR represents a re-base of the oFono RILD code from the quantal version (ofono-1.9) to the raring version (ofono-1.12).
Basic functional testing was run on a Galaxy Nexus using a recent daily build. Phone calls and SMSs were both tested.
PS Jenkins bot (ps-jenkins) wrote : | # |
Ricardo Salveti (rsalveti) wrote : | # |
There are quite a few things missing here:
* Not running autoreconf during configure (as we change configure.ac and makefile.am)
* makefile.am not covering all changes we had (missing -lwaudio for example)
* build fails when building the plugins:
plugins/phonesim.o: In function `localhfp_enable':
/home/phablet/
/home/phablet/
plugins/hfp_hf.o: In function `hfp_agent_
/home/phablet/
plugins/hfp_hf.o: In function `service_
/home/phablet/
collect2: error: ld returned 1 exit status
make[2]: *** [src/ofonod] Error 1
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/
make: *** [debian/
dpkg-buildpackage: error: debian/rules build gave error exit status 2
Trying to build the package with dpkg-buildpackage -uc -us.
Ricardo Salveti (rsalveti) wrote : | # |
Needed changes just to make it get to the failed point pointed above:
$ bzr diff
=== modified file 'Makefile.am'
--- Makefile.am 2013-03-28 12:50:26 +0000
+++ Makefile.am 2013-04-09 02:28:20 +0000
@@ -526,7 +526,7 @@
src/cdma-sms.c src/private-
src/
-src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ -ldl
+src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ -ldl -lwaudio
src_ofonod_LDFLAGS = -Wl,--export-
-Wl,
=== modified file 'debian/control'
--- debian/control 2013-03-28 12:50:26 +0000
+++ debian/control 2013-04-09 02:14:30 +0000
@@ -6,10 +6,12 @@
Uploaders: Jonny Lamb <email address hidden>, Hector Oron <email address hidden>, Konstantinos Margaritis <email address hidden>
Build-Depends: debhelper (>= 7.0.50~),
+ dh-autoreconf,
+ libwaudio1-dev (>= 1.4~quantal1),
=== modified file 'debian/rules'
--- debian/rules 2012-08-22 19:59:08 +0000
+++ debian/rules 2013-04-09 02:05:25 +0000
@@ -2,6 +2,7 @@
DEB_AUTO_
include /usr/share/
+include /usr/share/
include /usr/share/
#include /usr/share/
include /usr/share/
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:32
http://
Executed test runs:
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:34
http://
Executed test runs:
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Tony Espy (awe) wrote : | # |
Should be all set.
I verified the latest branch builds, installs and runs on a quantal touch daily ( today's ). I verified that incoming/outgoing sms and voice calls worked.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:35
http://
Executed test runs:
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Ricardo Salveti (rsalveti) wrote : | # |
Good, worked fine at both quantal and raring, with phone calls and sms.
Thanks!
Preview Diff
1 | === modified file 'Makefile.am' | |||
2 | --- Makefile.am 2013-01-28 16:25:32 +0000 | |||
3 | +++ Makefile.am 2013-04-09 20:01:20 +0000 | |||
4 | @@ -89,6 +89,12 @@ | |||
5 | 89 | gisi/server.c gisi/server.h \ | 89 | gisi/server.c gisi/server.h \ |
6 | 90 | gisi/socket.c gisi/socket.h | 90 | gisi/socket.c gisi/socket.h |
7 | 91 | 91 | ||
8 | 92 | gril_sources = gril/gril.h gril/gril.c gril/grilio.h \ | ||
9 | 93 | gril/grilio.c gril/grilutil.h \ | ||
10 | 94 | gril/grilutil.c gril/ringbuffer.h \ | ||
11 | 95 | gril/gfunc.h gril/ril.h \ | ||
12 | 96 | gril/parcel.c gril/parcel.h | ||
13 | 97 | |||
14 | 92 | btio_sources = btio/btio.h btio/btio.c | 98 | btio_sources = btio/btio.h btio/btio.c |
15 | 93 | 99 | ||
16 | 94 | if UDEV | 100 | if UDEV |
17 | @@ -101,6 +107,25 @@ | |||
18 | 101 | builtin_sources += plugins/udevng.c | 107 | builtin_sources += plugins/udevng.c |
19 | 102 | endif | 108 | endif |
20 | 103 | 109 | ||
21 | 110 | if RILMODEM | ||
22 | 111 | builtin_sources += $(gril_sources) | ||
23 | 112 | |||
24 | 113 | builtin_modules += ril | ||
25 | 114 | builtin_sources += plugins/ril.c | ||
26 | 115 | |||
27 | 116 | builtin_modules += rilmodem | ||
28 | 117 | builtin_sources += drivers/rilmodem/rilmodem.h \ | ||
29 | 118 | drivers/rilmodem/rilmodem.c \ | ||
30 | 119 | drivers/rilmodem/devinfo.c \ | ||
31 | 120 | drivers/rilmodem/network-registration.c \ | ||
32 | 121 | drivers/rilmodem/voicecall.c \ | ||
33 | 122 | drivers/rilmodem/call-volume.c \ | ||
34 | 123 | drivers/rilmodem/sms.c \ | ||
35 | 124 | drivers/rilmodem/rilutil.c \ | ||
36 | 125 | drivers/rilmodem/rilutil.h | ||
37 | 126 | |||
38 | 127 | endif | ||
39 | 128 | |||
40 | 104 | if ISIMODEM | 129 | if ISIMODEM |
41 | 105 | builtin_modules += isimodem | 130 | builtin_modules += isimodem |
42 | 106 | builtin_sources += $(gisi_sources) \ | 131 | builtin_sources += $(gisi_sources) \ |
43 | @@ -210,7 +235,7 @@ | |||
44 | 210 | drivers/atmodem/gprs-context.c \ | 235 | drivers/atmodem/gprs-context.c \ |
45 | 211 | drivers/atmodem/sim-auth.c \ | 236 | drivers/atmodem/sim-auth.c \ |
46 | 212 | drivers/atmodem/gnss.c | 237 | drivers/atmodem/gnss.c |
48 | 213 | 238 | if !RILMODEM | |
49 | 214 | builtin_modules += nwmodem | 239 | builtin_modules += nwmodem |
50 | 215 | builtin_sources += drivers/atmodem/atutil.h \ | 240 | builtin_sources += drivers/atmodem/atutil.h \ |
51 | 216 | drivers/nwmodem/nwmodem.h \ | 241 | drivers/nwmodem/nwmodem.h \ |
52 | @@ -299,6 +324,13 @@ | |||
53 | 299 | drivers/dunmodem/network-registration.c \ | 324 | drivers/dunmodem/network-registration.c \ |
54 | 300 | drivers/dunmodem/gprs.c | 325 | drivers/dunmodem/gprs.c |
55 | 301 | 326 | ||
56 | 327 | builtin_modules += speedupmodem | ||
57 | 328 | builtin_sources += drivers/atmodem/atutil.h \ | ||
58 | 329 | drivers/speedupmodem/speedupmodem.h \ | ||
59 | 330 | drivers/speedupmodem/speedupmodem.c \ | ||
60 | 331 | drivers/speedupmodem/ussd.c | ||
61 | 332 | endif | ||
62 | 333 | |||
63 | 302 | builtin_modules += hfpmodem | 334 | builtin_modules += hfpmodem |
64 | 303 | builtin_sources += drivers/atmodem/atutil.h \ | 335 | builtin_sources += drivers/atmodem/atutil.h \ |
65 | 304 | drivers/hfpmodem/hfpmodem.h \ | 336 | drivers/hfpmodem/hfpmodem.h \ |
66 | @@ -311,12 +343,6 @@ | |||
67 | 311 | drivers/hfpmodem/devinfo.c \ | 343 | drivers/hfpmodem/devinfo.c \ |
68 | 312 | drivers/hfpmodem/handsfree.c | 344 | drivers/hfpmodem/handsfree.c |
69 | 313 | 345 | ||
70 | 314 | builtin_modules += speedupmodem | ||
71 | 315 | builtin_sources += drivers/atmodem/atutil.h \ | ||
72 | 316 | drivers/speedupmodem/speedupmodem.h \ | ||
73 | 317 | drivers/speedupmodem/speedupmodem.c \ | ||
74 | 318 | drivers/speedupmodem/ussd.c | ||
75 | 319 | |||
76 | 320 | if PHONESIM | 346 | if PHONESIM |
77 | 321 | builtin_modules += phonesim | 347 | builtin_modules += phonesim |
78 | 322 | builtin_sources += plugins/phonesim.c | 348 | builtin_sources += plugins/phonesim.c |
79 | @@ -335,6 +361,7 @@ | |||
80 | 335 | drivers/cdmamodem/connman.c | 361 | drivers/cdmamodem/connman.c |
81 | 336 | endif | 362 | endif |
82 | 337 | 363 | ||
83 | 364 | if !RILMODEM | ||
84 | 338 | builtin_modules += g1 | 365 | builtin_modules += g1 |
85 | 339 | builtin_sources += plugins/g1.c | 366 | builtin_sources += plugins/g1.c |
86 | 340 | 367 | ||
87 | @@ -406,6 +433,7 @@ | |||
88 | 406 | 433 | ||
89 | 407 | builtin_modules += sim900 | 434 | builtin_modules += sim900 |
90 | 408 | builtin_sources += plugins/sim900.c | 435 | builtin_sources += plugins/sim900.c |
91 | 436 | endif | ||
92 | 409 | 437 | ||
93 | 410 | if BLUETOOTH | 438 | if BLUETOOTH |
94 | 411 | builtin_modules += bluetooth | 439 | builtin_modules += bluetooth |
95 | @@ -498,7 +526,7 @@ | |||
96 | 498 | src/cdma-sms.c src/private-network.c src/cdma-netreg.c \ | 526 | src/cdma-sms.c src/private-network.c src/cdma-netreg.c \ |
97 | 499 | src/cdma-provision.c src/handsfree.c | 527 | src/cdma-provision.c src/handsfree.c |
98 | 500 | 528 | ||
100 | 501 | src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ -ldl | 529 | src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ -ldl -lwaudio |
101 | 502 | 530 | ||
102 | 503 | src_ofonod_LDFLAGS = -Wl,--export-dynamic \ | 531 | src_ofonod_LDFLAGS = -Wl,--export-dynamic \ |
103 | 504 | -Wl,--version-script=$(srcdir)/src/ofono.ver | 532 | -Wl,--version-script=$(srcdir)/src/ofono.ver |
104 | @@ -522,7 +550,7 @@ | |||
105 | 522 | 550 | ||
106 | 523 | INCLUDES = -I$(builddir)/include -I$(builddir)/src -I$(srcdir)/src \ | 551 | INCLUDES = -I$(builddir)/include -I$(builddir)/src -I$(srcdir)/src \ |
107 | 524 | -I$(srcdir)/gdbus -I$(srcdir)/gisi -I$(srcdir)/gatchat \ | 552 | -I$(srcdir)/gdbus -I$(srcdir)/gisi -I$(srcdir)/gatchat \ |
109 | 525 | -I$(srcdir)/btio | 553 | -I$(srcdir)/btio -I$(srcdir)/gril |
110 | 526 | 554 | ||
111 | 527 | doc_files = doc/overview.txt doc/ofono-paper.txt doc/release-faq.txt \ | 555 | doc_files = doc/overview.txt doc/ofono-paper.txt doc/release-faq.txt \ |
112 | 528 | doc/manager-api.txt doc/modem-api.txt doc/network-api.txt \ | 556 | doc/manager-api.txt doc/modem-api.txt doc/network-api.txt \ |
113 | 529 | 557 | ||
114 | === modified file 'configure.ac' | |||
115 | --- configure.ac 2013-01-28 16:25:32 +0000 | |||
116 | +++ configure.ac 2013-04-09 20:01:20 +0000 | |||
117 | @@ -167,6 +167,11 @@ | |||
118 | 167 | [enable_isimodem=${enableval}]) | 167 | [enable_isimodem=${enableval}]) |
119 | 168 | AM_CONDITIONAL(ISIMODEM, test "${enable_isimodem}" != "no") | 168 | AM_CONDITIONAL(ISIMODEM, test "${enable_isimodem}" != "no") |
120 | 169 | 169 | ||
121 | 170 | AC_ARG_ENABLE(rilmodem, AC_HELP_STRING([--disable-rilmodem], | ||
122 | 171 | [disable RIL modem support]), | ||
123 | 172 | [enable_rilmodem=${enableval}]) | ||
124 | 173 | AM_CONDITIONAL(RILMODEM, test "${enable_rilmodem}" != "no") | ||
125 | 174 | |||
126 | 170 | AC_ARG_ENABLE(qmimodem, AC_HELP_STRING([--disable-qmimodem], | 175 | AC_ARG_ENABLE(qmimodem, AC_HELP_STRING([--disable-qmimodem], |
127 | 171 | [disable Qualcomm QMI modem support]), | 176 | [disable Qualcomm QMI modem support]), |
128 | 172 | [enable_qmimodem=${enableval}]) | 177 | [enable_qmimodem=${enableval}]) |
129 | 173 | 178 | ||
130 | === modified file 'debian/changelog' | |||
131 | --- debian/changelog 2013-04-03 16:11:02 +0000 | |||
132 | +++ debian/changelog 2013-04-09 20:01:20 +0000 | |||
133 | @@ -1,5 +1,61 @@ | |||
134 | 1 | ofono (1.12phablet1) UNRELEASED; urgency=low | 1 | ofono (1.12phablet1) UNRELEASED; urgency=low |
135 | 2 | 2 | ||
136 | 3 | [ Ricardo Salveti de Araujo ] | ||
137 | 4 | * ofono.upstart: not starting with debug by default, not needed anymore | ||
138 | 5 | * drivers/rilmodem/devinfo.c: fake data should just use Fake instead of | ||
139 | 6 | Galaxy Nexus | ||
140 | 7 | |||
141 | 8 | [ Tony Espy ] | ||
142 | 9 | * gril/*, plugins/ril.c, drivers/rilmodem/*: fixed copyright headers, | ||
143 | 10 | sanitized comments. | ||
144 | 11 | |||
145 | 12 | [ Ricardo Salveti de Araujo ] | ||
146 | 13 | * Fixing audio states during and after a call, previously broken with | ||
147 | 14 | JellyBean (LP: #1101339) | ||
148 | 15 | |||
149 | 16 | [ Tony Espy ] | ||
150 | 17 | * Re-named the galaxynexus plugin to ril. | ||
151 | 18 | * [galaxynexus] Add SIM checking to modem initialization. | ||
152 | 19 | * [gril] Add ril_request_id_to_string function. | ||
153 | 20 | * [core] Modify ofono_modem_set_online() to call modem_change_state(), | ||
154 | 21 | which triggers our new modem initialization logic in galaxynexus' | ||
155 | 22 | post_online function. | ||
156 | 23 | |||
157 | 24 | [ Ricardo Salveti de Araujo ] | ||
158 | 25 | * parcel.c: fixing data padding boundary for parcel_w_string (LP: #1088559) | ||
159 | 26 | * Only setting audio mode in call when actually dialing or answering (to | ||
160 | 27 | allow ringtones at the ubuntu side) | ||
161 | 28 | |||
162 | 29 | [ Tony Espy ] | ||
163 | 30 | * Disable atmodem plugin on starup. | ||
164 | 31 | |||
165 | 32 | [ Ricardo Salveti de Araujo ] | ||
166 | 33 | * Adding proper support for network registration and network state changes | ||
167 | 34 | * Support registering for network time update reports | ||
168 | 35 | * Extending network registration to support current operator, list of | ||
169 | 36 | operators and auto/manual registration | ||
170 | 37 | * Enabling support to retrieve the signal strength | ||
171 | 38 | * Enabling initial support for DTMF | ||
172 | 39 | * Adding support for answering a call | ||
173 | 40 | * Tuning start sleep for 8 and running with debug messages enabled | ||
174 | 41 | * Sync ril_delayed_register timeout to 2 for all services in rilmodem | ||
175 | 42 | * Setting up voice state and enabling voice call support at AudioFlinger | ||
176 | 43 | |||
177 | 44 | [ Tony Espy ] | ||
178 | 45 | * Initial version of notification framework for RIL | ||
179 | 46 | unsolicited events ( signal strength, new sms, ... ). | ||
180 | 47 | * Support for incoming SMS messages (LP: #1085896). | ||
181 | 48 | |||
182 | 49 | [ Ricardo Salveti de Araujo ] | ||
183 | 50 | * Adding support for voice call (LP: #1085893) | ||
184 | 51 | * Adding utils files for parcel and string handling | ||
185 | 52 | * Enable basic support for voice volume (mute/unmute) | ||
186 | 53 | |||
187 | 54 | [ Michael Frey ] | ||
188 | 55 | * debian/ofono.upstart: Fix for hang on shutdown. | ||
189 | 56 | |||
190 | 57 | [ Tony Espy ] | ||
191 | 58 | * First hard-coded support for RIL modem on Galaxy Nexus. | ||
192 | 3 | * Initial phablet version, converted to native for | 59 | * Initial phablet version, converted to native for |
193 | 4 | easier development of new RIL driver/plugin code. | 60 | easier development of new RIL driver/plugin code. |
194 | 5 | - debian/source/format: changed to 3.0 (native) | 61 | - debian/source/format: changed to 3.0 (native) |
195 | 6 | 62 | ||
196 | === modified file 'debian/control' | |||
197 | --- debian/control 2012-08-22 19:59:08 +0000 | |||
198 | +++ debian/control 2013-04-09 20:01:20 +0000 | |||
199 | @@ -6,9 +6,12 @@ | |||
200 | 6 | Uploaders: Jonny Lamb <jonny@debian.org>, Hector Oron <zumbi@debian.org>, Konstantinos Margaritis <markos@debian.org> | 6 | Uploaders: Jonny Lamb <jonny@debian.org>, Hector Oron <zumbi@debian.org>, Konstantinos Margaritis <markos@debian.org> |
201 | 7 | Build-Depends: debhelper (>= 7.0.50~), | 7 | Build-Depends: debhelper (>= 7.0.50~), |
202 | 8 | cdbs, | 8 | cdbs, |
203 | 9 | dh-autoreconf, | ||
204 | 10 | libtool, | ||
205 | 9 | libglib2.0-dev (>= 2.22), | 11 | libglib2.0-dev (>= 2.22), |
206 | 10 | libdbus-glib-1-dev, | 12 | libdbus-glib-1-dev, |
207 | 11 | libudev-dev, | 13 | libudev-dev, |
208 | 14 | libwaudio1-dev, | ||
209 | 12 | udev, | 15 | udev, |
210 | 13 | libbluetooth-dev (>= 4.30), | 16 | libbluetooth-dev (>= 4.30), |
211 | 14 | mobile-broadband-provider-info | 17 | mobile-broadband-provider-info |
212 | 15 | 18 | ||
213 | === modified file 'debian/ofono.install' | |||
214 | --- debian/ofono.install 2012-08-22 19:59:08 +0000 | |||
215 | +++ debian/ofono.install 2013-04-09 20:01:20 +0000 | |||
216 | @@ -1,6 +1,4 @@ | |||
217 | 1 | debian/tmp/etc/dbus-1/system.d/* | 1 | debian/tmp/etc/dbus-1/system.d/* |
218 | 2 | debian/tmp/usr/sbin/ofonod | 2 | debian/tmp/usr/sbin/ofonod |
219 | 3 | debian/tmp/usr/sbin/dundee | ||
220 | 4 | debian/tmp/etc/ofono | 3 | debian/tmp/etc/ofono |
221 | 5 | debian/tmp/lib/udev/rules.d/* | ||
222 | 6 | debian/tmp/usr/share/man | 4 | debian/tmp/usr/share/man |
223 | 7 | 5 | ||
224 | === modified file 'debian/ofono.upstart' | |||
225 | --- debian/ofono.upstart 2010-09-02 18:21:57 +0000 | |||
226 | +++ debian/ofono.upstart 2013-04-09 20:01:20 +0000 | |||
227 | @@ -6,4 +6,9 @@ | |||
228 | 6 | expect fork | 6 | expect fork |
229 | 7 | respawn | 7 | respawn |
230 | 8 | 8 | ||
232 | 9 | exec ofonod | 9 | exec ofonod --noplugin=atmodem |
233 | 10 | |||
234 | 11 | pre-start script | ||
235 | 12 | sleep 8 | ||
236 | 13 | end script | ||
237 | 14 | |||
238 | 10 | 15 | ||
239 | === modified file 'debian/rules' | |||
240 | --- debian/rules 2012-08-22 19:59:08 +0000 | |||
241 | +++ debian/rules 2013-04-09 20:01:20 +0000 | |||
242 | @@ -2,14 +2,14 @@ | |||
243 | 2 | DEB_AUTO_CLEANUP_RCS := yes | 2 | DEB_AUTO_CLEANUP_RCS := yes |
244 | 3 | 3 | ||
245 | 4 | include /usr/share/cdbs/1/class/autotools.mk | 4 | include /usr/share/cdbs/1/class/autotools.mk |
246 | 5 | include /usr/share/cdbs/1/rules/autoreconf.mk | ||
247 | 5 | include /usr/share/cdbs/1/rules/debhelper.mk | 6 | include /usr/share/cdbs/1/rules/debhelper.mk |
248 | 6 | #include /usr/share/cdbs/1/rules/simple-patchsys.mk | ||
249 | 7 | include /usr/share/cdbs/1/rules/utils.mk | 7 | include /usr/share/cdbs/1/rules/utils.mk |
250 | 8 | 8 | ||
251 | 9 | DEB_DH_INSTALLINIT_ARGS := --no-restart-on-upgrade | 9 | DEB_DH_INSTALLINIT_ARGS := --no-restart-on-upgrade |
252 | 10 | 10 | ||
253 | 11 | common-binary-post-install-arch:: list-missing | 11 | common-binary-post-install-arch:: list-missing |
254 | 12 | 12 | ||
256 | 13 | DEB_CONFIGURE_EXTRA_FLAGS := --enable-bluetooth --enable-dundee | 13 | DEB_CONFIGURE_EXTRA_FLAGS := --disable-bluetooth --disable-dundee --disable-udev |
257 | 14 | 14 | ||
258 | 15 | include $(CURDIR)/debian/update-patches.mk | 15 | include $(CURDIR)/debian/update-patches.mk |
259 | 16 | 16 | ||
260 | === added directory 'drivers/rilmodem' | |||
261 | === added file 'drivers/rilmodem/call-volume.c' | |||
262 | --- drivers/rilmodem/call-volume.c 1970-01-01 00:00:00 +0000 | |||
263 | +++ drivers/rilmodem/call-volume.c 2013-04-09 20:01:20 +0000 | |||
264 | @@ -0,0 +1,186 @@ | |||
265 | 1 | /* | ||
266 | 2 | * | ||
267 | 3 | * oFono - Open Source Telephony | ||
268 | 4 | * | ||
269 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
270 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
271 | 7 | * | ||
272 | 8 | * This program is free software; you can redistribute it and/or modify | ||
273 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
274 | 10 | * published by the Free Software Foundation. | ||
275 | 11 | * | ||
276 | 12 | * This program is distributed in the hope that it will be useful, | ||
277 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
278 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
279 | 15 | * GNU General Public License for more details. | ||
280 | 16 | * | ||
281 | 17 | * You should have received a copy of the GNU General Public License | ||
282 | 18 | * along with this program; if not, write to the Free Software | ||
283 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
284 | 20 | * | ||
285 | 21 | */ | ||
286 | 22 | |||
287 | 23 | #ifdef HAVE_CONFIG_H | ||
288 | 24 | #include <config.h> | ||
289 | 25 | #endif | ||
290 | 26 | |||
291 | 27 | #define _GNU_SOURCE | ||
292 | 28 | #include <string.h> | ||
293 | 29 | #include <stdio.h> | ||
294 | 30 | #include <errno.h> | ||
295 | 31 | |||
296 | 32 | #include <glib.h> | ||
297 | 33 | |||
298 | 34 | #include <ofono/log.h> | ||
299 | 35 | #include <ofono/modem.h> | ||
300 | 36 | #include <ofono/call-volume.h> | ||
301 | 37 | |||
302 | 38 | #include "gril.h" | ||
303 | 39 | #include "grilutil.h" | ||
304 | 40 | |||
305 | 41 | #include "common.h" | ||
306 | 42 | |||
307 | 43 | #include "rilmodem.h" | ||
308 | 44 | #include "parcel.h" | ||
309 | 45 | |||
310 | 46 | struct cv_data { | ||
311 | 47 | GRil *ril; | ||
312 | 48 | unsigned int vendor; | ||
313 | 49 | }; | ||
314 | 50 | |||
315 | 51 | static void volume_mute_cb(struct ril_msg *message, gpointer user_data) | ||
316 | 52 | { | ||
317 | 53 | struct cb_data *cbd = user_data; | ||
318 | 54 | ofono_call_volume_cb_t cb = cbd->cb; | ||
319 | 55 | struct ofono_error error; | ||
320 | 56 | |||
321 | 57 | DBG(""); | ||
322 | 58 | |||
323 | 59 | if (message->error == RIL_E_SUCCESS) { | ||
324 | 60 | decode_ril_error(&error, "OK"); | ||
325 | 61 | } else { | ||
326 | 62 | ofono_error("Could not set the ril mute state"); | ||
327 | 63 | decode_ril_error(&error, "FAIL"); | ||
328 | 64 | } | ||
329 | 65 | |||
330 | 66 | cb(&error, cbd->data); | ||
331 | 67 | } | ||
332 | 68 | |||
333 | 69 | static void ril_call_volume_mute(struct ofono_call_volume *cv, int muted, | ||
334 | 70 | ofono_call_volume_cb_t cb, void *data) | ||
335 | 71 | { | ||
336 | 72 | struct cv_data *cvd = ofono_call_volume_get_data(cv); | ||
337 | 73 | struct cb_data *cbd = cb_data_new(cb, data); | ||
338 | 74 | struct parcel rilp; | ||
339 | 75 | |||
340 | 76 | DBG(""); | ||
341 | 77 | |||
342 | 78 | parcel_init(&rilp); | ||
343 | 79 | parcel_w_int32(&rilp, 1); | ||
344 | 80 | parcel_w_int32(&rilp, muted); | ||
345 | 81 | g_ril_send(cvd->ril, RIL_REQUEST_SET_MUTE, rilp.data, | ||
346 | 82 | rilp.size, volume_mute_cb, cbd, g_free); | ||
347 | 83 | parcel_free(&rilp); | ||
348 | 84 | |||
349 | 85 | return; | ||
350 | 86 | } | ||
351 | 87 | |||
352 | 88 | static void probe_mute_cb(struct ril_msg *message, gpointer user_data) | ||
353 | 89 | { | ||
354 | 90 | struct ofono_call_volume *cv = user_data; | ||
355 | 91 | struct parcel rilp; | ||
356 | 92 | int muted; | ||
357 | 93 | |||
358 | 94 | DBG(""); | ||
359 | 95 | |||
360 | 96 | if (message->error != RIL_E_SUCCESS) { | ||
361 | 97 | ofono_error("Could not retrive the ril mute state"); | ||
362 | 98 | return; | ||
363 | 99 | } | ||
364 | 100 | |||
365 | 101 | /* Set up Parcel struct for proper parsing */ | ||
366 | 102 | rilp.data = message->buf; | ||
367 | 103 | rilp.size = message->buf_len; | ||
368 | 104 | rilp.capacity = message->buf_len; | ||
369 | 105 | rilp.offset = 0; | ||
370 | 106 | |||
371 | 107 | muted = parcel_r_int32(&rilp); | ||
372 | 108 | DBG("Initial ril muted state: %d", muted); | ||
373 | 109 | |||
374 | 110 | ofono_call_volume_set_muted(cv, muted); | ||
375 | 111 | } | ||
376 | 112 | |||
377 | 113 | static void call_probe_mute(gpointer user_data) | ||
378 | 114 | { | ||
379 | 115 | struct ofono_call_volume *cv = user_data; | ||
380 | 116 | struct cv_data *cvd = ofono_call_volume_get_data(cv); | ||
381 | 117 | |||
382 | 118 | DBG("Requesting mute from RIL"); | ||
383 | 119 | |||
384 | 120 | g_ril_send(cvd->ril, RIL_REQUEST_GET_MUTE, NULL, 0, | ||
385 | 121 | probe_mute_cb, cv, NULL); | ||
386 | 122 | |||
387 | 123 | return; | ||
388 | 124 | } | ||
389 | 125 | |||
390 | 126 | static gboolean ril_delayed_register(gpointer user_data) | ||
391 | 127 | { | ||
392 | 128 | struct ofono_call_volume *cv = user_data; | ||
393 | 129 | DBG(""); | ||
394 | 130 | ofono_call_volume_register(cv); | ||
395 | 131 | |||
396 | 132 | /* Probe the mute state */ | ||
397 | 133 | call_probe_mute(user_data); | ||
398 | 134 | |||
399 | 135 | /* This makes the timeout a single-shot */ | ||
400 | 136 | return FALSE; | ||
401 | 137 | } | ||
402 | 138 | |||
403 | 139 | static int ril_call_volume_probe(struct ofono_call_volume *cv, | ||
404 | 140 | unsigned int vendor, void *data) | ||
405 | 141 | { | ||
406 | 142 | GRil *ril = data; | ||
407 | 143 | struct cv_data *cvd; | ||
408 | 144 | |||
409 | 145 | DBG(""); | ||
410 | 146 | |||
411 | 147 | cvd = g_new0(struct cv_data, 1); | ||
412 | 148 | if (cvd == NULL) | ||
413 | 149 | return -ENOMEM; | ||
414 | 150 | |||
415 | 151 | cvd->ril = g_ril_clone(ril); | ||
416 | 152 | cvd->vendor = vendor; | ||
417 | 153 | |||
418 | 154 | ofono_call_volume_set_data(cv, cvd); | ||
419 | 155 | |||
420 | 156 | g_timeout_add_seconds(2, ril_delayed_register, cv); | ||
421 | 157 | |||
422 | 158 | return 0; | ||
423 | 159 | } | ||
424 | 160 | |||
425 | 161 | static void ril_call_volume_remove(struct ofono_call_volume *cv) | ||
426 | 162 | { | ||
427 | 163 | struct cv_data *cvd = ofono_call_volume_get_data(cv); | ||
428 | 164 | |||
429 | 165 | ofono_call_volume_set_data(cv, NULL); | ||
430 | 166 | |||
431 | 167 | g_ril_unref(cvd->ril); | ||
432 | 168 | g_free(cvd); | ||
433 | 169 | } | ||
434 | 170 | |||
435 | 171 | static struct ofono_call_volume_driver driver = { | ||
436 | 172 | .name = "rilmodem", | ||
437 | 173 | .probe = ril_call_volume_probe, | ||
438 | 174 | .remove = ril_call_volume_remove, | ||
439 | 175 | .mute = ril_call_volume_mute, | ||
440 | 176 | }; | ||
441 | 177 | |||
442 | 178 | void ril_call_volume_init(void) | ||
443 | 179 | { | ||
444 | 180 | ofono_call_volume_driver_register(&driver); | ||
445 | 181 | } | ||
446 | 182 | |||
447 | 183 | void ril_call_volume_exit(void) | ||
448 | 184 | { | ||
449 | 185 | ofono_call_volume_driver_unregister(&driver); | ||
450 | 186 | } | ||
451 | 0 | 187 | ||
452 | === added file 'drivers/rilmodem/devinfo.c' | |||
453 | --- drivers/rilmodem/devinfo.c 1970-01-01 00:00:00 +0000 | |||
454 | +++ drivers/rilmodem/devinfo.c 2013-04-09 20:01:20 +0000 | |||
455 | @@ -0,0 +1,171 @@ | |||
456 | 1 | /* | ||
457 | 2 | * | ||
458 | 3 | * oFono - Open Source Telephony - RIL Modem Support | ||
459 | 4 | * | ||
460 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
461 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
462 | 7 | * | ||
463 | 8 | * This program is free software; you can redistribute it and/or modify | ||
464 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
465 | 10 | * published by the Free Software Foundation. | ||
466 | 11 | * | ||
467 | 12 | * This program is distributed in the hope that it will be useful, | ||
468 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
469 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
470 | 15 | * GNU General Public License for more details. | ||
471 | 16 | * | ||
472 | 17 | * You should have received a copy of the GNU General Public License | ||
473 | 18 | * along with this program; if not, write to the Free Software | ||
474 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
475 | 20 | * | ||
476 | 21 | */ | ||
477 | 22 | |||
478 | 23 | #ifdef HAVE_CONFIG_H | ||
479 | 24 | #include <config.h> | ||
480 | 25 | #endif | ||
481 | 26 | |||
482 | 27 | #define _GNU_SOURCE | ||
483 | 28 | #include <stdio.h> | ||
484 | 29 | #include <stdlib.h> | ||
485 | 30 | #include <string.h> | ||
486 | 31 | #include <errno.h> | ||
487 | 32 | |||
488 | 33 | #include <glib.h> | ||
489 | 34 | |||
490 | 35 | #include <ofono/log.h> | ||
491 | 36 | #include <ofono/modem.h> | ||
492 | 37 | #include <ofono/devinfo.h> | ||
493 | 38 | |||
494 | 39 | #include "gril.h" | ||
495 | 40 | |||
496 | 41 | #include "rilmodem.h" | ||
497 | 42 | |||
498 | 43 | /* | ||
499 | 44 | * TODO: The functions in this file are stubbed out, and | ||
500 | 45 | * will need to be re-worked to talk to the /gril layer | ||
501 | 46 | * in order to get real values from RILD. | ||
502 | 47 | */ | ||
503 | 48 | |||
504 | 49 | static void ril_query_manufacturer(struct ofono_devinfo *info, | ||
505 | 50 | ofono_devinfo_query_cb_t cb, | ||
506 | 51 | void *data) | ||
507 | 52 | { | ||
508 | 53 | const char *attr = "Fake Manufacturer"; | ||
509 | 54 | struct cb_data *cbd = cb_data_new(cb, data); | ||
510 | 55 | struct ofono_error error; | ||
511 | 56 | decode_ril_error(&error, "OK"); | ||
512 | 57 | |||
513 | 58 | cb(&error, attr, cbd->data); | ||
514 | 59 | |||
515 | 60 | /* Note: this will need to change if cbd passed to gril layer */ | ||
516 | 61 | g_free(cbd); | ||
517 | 62 | } | ||
518 | 63 | |||
519 | 64 | static void ril_query_model(struct ofono_devinfo *info, | ||
520 | 65 | ofono_devinfo_query_cb_t cb, | ||
521 | 66 | void *data) | ||
522 | 67 | { | ||
523 | 68 | const char *attr = "Fake Modem Model"; | ||
524 | 69 | struct cb_data *cbd = cb_data_new(cb, data); | ||
525 | 70 | struct ofono_error error; | ||
526 | 71 | decode_ril_error(&error, "OK"); | ||
527 | 72 | |||
528 | 73 | cb(&error, attr, cbd->data); | ||
529 | 74 | |||
530 | 75 | /* Note: this will need to change if cbd passed to gril layer */ | ||
531 | 76 | g_free(cbd); | ||
532 | 77 | } | ||
533 | 78 | |||
534 | 79 | static void ril_query_revision(struct ofono_devinfo *info, | ||
535 | 80 | ofono_devinfo_query_cb_t cb, | ||
536 | 81 | void *data) | ||
537 | 82 | { | ||
538 | 83 | const char *attr = "Fake Revision"; | ||
539 | 84 | struct cb_data *cbd = cb_data_new(cb, data); | ||
540 | 85 | struct ofono_error error; | ||
541 | 86 | decode_ril_error(&error, "OK"); | ||
542 | 87 | |||
543 | 88 | cb(&error, attr, cbd->data); | ||
544 | 89 | |||
545 | 90 | /* Note: this will need to change if cbd passed to gril layer */ | ||
546 | 91 | g_free(cbd); | ||
547 | 92 | } | ||
548 | 93 | |||
549 | 94 | static void ril_query_serial(struct ofono_devinfo *info, | ||
550 | 95 | ofono_devinfo_query_cb_t cb, | ||
551 | 96 | void *data) | ||
552 | 97 | { | ||
553 | 98 | const char *attr = "THIS-IS-A-FAKE-SERIAL-NO"; | ||
554 | 99 | struct cb_data *cbd = cb_data_new(cb, data); | ||
555 | 100 | struct ofono_error error; | ||
556 | 101 | decode_ril_error(&error, "OK"); | ||
557 | 102 | |||
558 | 103 | cb(&error, attr, cbd->data); | ||
559 | 104 | |||
560 | 105 | /* Note: this will need to change if cbd passed to gril layer */ | ||
561 | 106 | g_free(cbd); | ||
562 | 107 | } | ||
563 | 108 | |||
564 | 109 | static gboolean ril_delayed_register(gpointer user_data) | ||
565 | 110 | { | ||
566 | 111 | struct ofono_devinfo *info = user_data; | ||
567 | 112 | DBG(""); | ||
568 | 113 | ofono_devinfo_register(info); | ||
569 | 114 | |||
570 | 115 | /* This makes the timeout a single-shot */ | ||
571 | 116 | return FALSE; | ||
572 | 117 | } | ||
573 | 118 | |||
574 | 119 | static int ril_devinfo_probe(struct ofono_devinfo *info, unsigned int vendor, | ||
575 | 120 | void *data) | ||
576 | 121 | { | ||
577 | 122 | GRil *ril = NULL; | ||
578 | 123 | |||
579 | 124 | if (data != NULL) | ||
580 | 125 | ril = g_ril_clone(data); | ||
581 | 126 | |||
582 | 127 | ofono_devinfo_set_data(info, ril); | ||
583 | 128 | |||
584 | 129 | DBG(""); | ||
585 | 130 | |||
586 | 131 | /* Nothing to send... | ||
587 | 132 | * | ||
588 | 133 | * ofono_devinfo_register() needs to be called after | ||
589 | 134 | * the driver has been set in devinfo_create() which | ||
590 | 135 | * calls this function. Most other drivers use a | ||
591 | 136 | * callback after getting some return from the modem | ||
592 | 137 | * itself... | ||
593 | 138 | */ | ||
594 | 139 | g_timeout_add_seconds(1, ril_delayed_register, info); | ||
595 | 140 | |||
596 | 141 | return 0; | ||
597 | 142 | } | ||
598 | 143 | |||
599 | 144 | static void ril_devinfo_remove(struct ofono_devinfo *info) | ||
600 | 145 | { | ||
601 | 146 | GRil *ril = ofono_devinfo_get_data(info); | ||
602 | 147 | |||
603 | 148 | ofono_devinfo_set_data(info, NULL); | ||
604 | 149 | |||
605 | 150 | g_ril_unref(ril); | ||
606 | 151 | } | ||
607 | 152 | |||
608 | 153 | static struct ofono_devinfo_driver driver = { | ||
609 | 154 | .name = "rilmodem", | ||
610 | 155 | .probe = ril_devinfo_probe, | ||
611 | 156 | .remove = ril_devinfo_remove, | ||
612 | 157 | .query_manufacturer = ril_query_manufacturer, | ||
613 | 158 | .query_model = ril_query_model, | ||
614 | 159 | .query_revision = ril_query_revision, | ||
615 | 160 | .query_serial = ril_query_serial | ||
616 | 161 | }; | ||
617 | 162 | |||
618 | 163 | void ril_devinfo_init(void) | ||
619 | 164 | { | ||
620 | 165 | ofono_devinfo_driver_register(&driver); | ||
621 | 166 | } | ||
622 | 167 | |||
623 | 168 | void ril_devinfo_exit(void) | ||
624 | 169 | { | ||
625 | 170 | ofono_devinfo_driver_unregister(&driver); | ||
626 | 171 | } | ||
627 | 0 | 172 | ||
628 | === added file 'drivers/rilmodem/network-registration.c' | |||
629 | --- drivers/rilmodem/network-registration.c 1970-01-01 00:00:00 +0000 | |||
630 | +++ drivers/rilmodem/network-registration.c 2013-04-09 20:01:20 +0000 | |||
631 | @@ -0,0 +1,595 @@ | |||
632 | 1 | /* | ||
633 | 2 | * | ||
634 | 3 | * oFono - Open Source Telephony - RIL Modem Support | ||
635 | 4 | * | ||
636 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
637 | 6 | * Copyright (C) 2010 ST-Ericsson AB. | ||
638 | 7 | * Copyright (C) 2012 Canonical Ltd. | ||
639 | 8 | * | ||
640 | 9 | * This program is free software; you can redistribute it and/or modify | ||
641 | 10 | * it under the terms of the GNU General Public License version 2 as | ||
642 | 11 | * published by the Free Software Foundation. | ||
643 | 12 | * | ||
644 | 13 | * This program is distributed in the hope that it will be useful, | ||
645 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
646 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
647 | 16 | * GNU General Public License for more details. | ||
648 | 17 | * | ||
649 | 18 | * You should have received a copy of the GNU General Public License | ||
650 | 19 | * along with this program; if not, write to the Free Software | ||
651 | 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
652 | 21 | * | ||
653 | 22 | */ | ||
654 | 23 | |||
655 | 24 | #ifdef HAVE_CONFIG_H | ||
656 | 25 | #include <config.h> | ||
657 | 26 | #endif | ||
658 | 27 | |||
659 | 28 | #define _GNU_SOURCE | ||
660 | 29 | #include <string.h> | ||
661 | 30 | #include <stdlib.h> | ||
662 | 31 | #include <stdio.h> | ||
663 | 32 | |||
664 | 33 | #include <glib.h> | ||
665 | 34 | |||
666 | 35 | #include <ofono/log.h> | ||
667 | 36 | #include <ofono/modem.h> | ||
668 | 37 | #include <ofono/netreg.h> | ||
669 | 38 | |||
670 | 39 | #include "gril.h" | ||
671 | 40 | |||
672 | 41 | #include "rilmodem.h" | ||
673 | 42 | #include "parcel.h" | ||
674 | 43 | #include "common.h" | ||
675 | 44 | #include "parcel.h" | ||
676 | 45 | |||
677 | 46 | struct netreg_data { | ||
678 | 47 | GRil *ril; | ||
679 | 48 | char mcc[OFONO_MAX_MCC_LENGTH + 1]; | ||
680 | 49 | char mnc[OFONO_MAX_MNC_LENGTH + 1]; | ||
681 | 50 | int signal_index; /* If strength is reported via CIND */ | ||
682 | 51 | int signal_min; /* min strength reported via CIND */ | ||
683 | 52 | int signal_max; /* max strength reported via CIND */ | ||
684 | 53 | int signal_invalid; /* invalid strength reported via CIND */ | ||
685 | 54 | int tech; | ||
686 | 55 | struct ofono_network_time time; | ||
687 | 56 | guint nitz_timeout; | ||
688 | 57 | unsigned int vendor; | ||
689 | 58 | }; | ||
690 | 59 | |||
691 | 60 | /* 27.007 Section 7.3 <stat> */ | ||
692 | 61 | enum operator_status { | ||
693 | 62 | OPERATOR_STATUS_UNKNOWN = 0, | ||
694 | 63 | OPERATOR_STATUS_AVAILABLE = 1, | ||
695 | 64 | OPERATOR_STATUS_CURRENT = 2, | ||
696 | 65 | OPERATOR_STATUS_FORBIDDEN = 3, | ||
697 | 66 | }; | ||
698 | 67 | |||
699 | 68 | static void extract_mcc_mnc(const char *str, char *mcc, char *mnc) | ||
700 | 69 | { | ||
701 | 70 | /* Three digit country code */ | ||
702 | 71 | strncpy(mcc, str, OFONO_MAX_MCC_LENGTH); | ||
703 | 72 | mcc[OFONO_MAX_MCC_LENGTH] = '\0'; | ||
704 | 73 | |||
705 | 74 | /* Usually a 2 but sometimes 3 digit network code */ | ||
706 | 75 | strncpy(mnc, str + OFONO_MAX_MCC_LENGTH, OFONO_MAX_MNC_LENGTH); | ||
707 | 76 | mnc[OFONO_MAX_MNC_LENGTH] = '\0'; | ||
708 | 77 | } | ||
709 | 78 | |||
710 | 79 | /* | ||
711 | 80 | * TODO: The functions in this file are stubbed out, and | ||
712 | 81 | * will need to be re-worked to talk to the /gril layer | ||
713 | 82 | * in order to get real values from RILD. | ||
714 | 83 | */ | ||
715 | 84 | |||
716 | 85 | static void ril_creg_cb(struct ril_msg *message, gpointer user_data) | ||
717 | 86 | { | ||
718 | 87 | struct cb_data *cbd = user_data; | ||
719 | 88 | ofono_netreg_status_cb_t cb = cbd->cb; | ||
720 | 89 | struct netreg_data *nd = cbd->user; | ||
721 | 90 | struct ofono_error error; | ||
722 | 91 | int status, lac, ci, tech; | ||
723 | 92 | |||
724 | 93 | DBG(""); | ||
725 | 94 | |||
726 | 95 | if (message->error != RIL_E_SUCCESS) { | ||
727 | 96 | decode_ril_error(&error, "FAIL"); | ||
728 | 97 | ofono_error("Failed to pull registration state"); | ||
729 | 98 | cb(&error, -1, -1, -1, -1, cbd->data); | ||
730 | 99 | return; | ||
731 | 100 | } | ||
732 | 101 | |||
733 | 102 | decode_ril_error(&error, "OK"); | ||
734 | 103 | |||
735 | 104 | if (ril_util_parse_reg(message, &status, | ||
736 | 105 | &lac, &ci, &tech) == FALSE) { | ||
737 | 106 | CALLBACK_WITH_FAILURE(cb, -1, -1, -1, -1, cbd->data); | ||
738 | 107 | return; | ||
739 | 108 | } | ||
740 | 109 | |||
741 | 110 | DBG("oFono reg - status: %s, lac: %x, ci: %x, tech: %s", | ||
742 | 111 | registration_status_to_string(status), | ||
743 | 112 | lac, ci, | ||
744 | 113 | registration_tech_to_string(tech)); | ||
745 | 114 | |||
746 | 115 | nd->tech = tech; | ||
747 | 116 | cb(&error, status, lac, ci, tech, cbd->data); | ||
748 | 117 | } | ||
749 | 118 | |||
750 | 119 | static void ril_creg_notify(struct ofono_error *error, int status, int lac, | ||
751 | 120 | int ci, int tech, gpointer user_data) | ||
752 | 121 | { | ||
753 | 122 | struct ofono_netreg *netreg = user_data; | ||
754 | 123 | |||
755 | 124 | DBG(""); | ||
756 | 125 | |||
757 | 126 | if (error->type != OFONO_ERROR_TYPE_NO_ERROR) { | ||
758 | 127 | DBG("Error during status notification"); | ||
759 | 128 | return; | ||
760 | 129 | } | ||
761 | 130 | |||
762 | 131 | ofono_netreg_status_notify(netreg, status, lac, ci, tech); | ||
763 | 132 | } | ||
764 | 133 | |||
765 | 134 | static void ril_network_state_change(struct ril_msg *message, gpointer user_data) | ||
766 | 135 | { | ||
767 | 136 | struct ofono_netreg *netreg = user_data; | ||
768 | 137 | struct netreg_data *nd = ofono_netreg_get_data(netreg); | ||
769 | 138 | struct cb_data *cbd = cb_data_new(ril_creg_notify, netreg); | ||
770 | 139 | |||
771 | 140 | DBG(""); | ||
772 | 141 | |||
773 | 142 | cbd->user = nd; | ||
774 | 143 | |||
775 | 144 | if (message->req != RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED) | ||
776 | 145 | goto error; | ||
777 | 146 | |||
778 | 147 | if (g_ril_send(nd->ril, RIL_REQUEST_VOICE_REGISTRATION_STATE, NULL, | ||
779 | 148 | 0, ril_creg_cb, cbd, g_free) > 0) | ||
780 | 149 | return; | ||
781 | 150 | |||
782 | 151 | /* For operator update ofono will use the current_operator cb | ||
783 | 152 | * so we don't need to probe ril here */ | ||
784 | 153 | |||
785 | 154 | error: | ||
786 | 155 | g_free(cbd); | ||
787 | 156 | |||
788 | 157 | ofono_error("Unable to request network state changed"); | ||
789 | 158 | } | ||
790 | 159 | |||
791 | 160 | static void ril_registration_status(struct ofono_netreg *netreg, | ||
792 | 161 | ofono_netreg_status_cb_t cb, | ||
793 | 162 | void *data) | ||
794 | 163 | { | ||
795 | 164 | struct netreg_data *nd = ofono_netreg_get_data(netreg); | ||
796 | 165 | struct cb_data *cbd = cb_data_new(cb, data); | ||
797 | 166 | |||
798 | 167 | cbd->user = nd; | ||
799 | 168 | |||
800 | 169 | if (g_ril_send(nd->ril, RIL_REQUEST_VOICE_REGISTRATION_STATE, NULL, | ||
801 | 170 | 0, ril_creg_cb, cbd, g_free) > 0) | ||
802 | 171 | return; | ||
803 | 172 | |||
804 | 173 | g_free(cbd); | ||
805 | 174 | |||
806 | 175 | CALLBACK_WITH_FAILURE(cb, -1, -1, -1, -1, data); | ||
807 | 176 | } | ||
808 | 177 | |||
809 | 178 | static void ril_cops_cb(struct ril_msg *message, gpointer user_data) | ||
810 | 179 | { | ||
811 | 180 | struct cb_data *cbd = user_data; | ||
812 | 181 | ofono_netreg_operator_cb_t cb = cbd->cb; | ||
813 | 182 | struct netreg_data *nd = cbd->user; | ||
814 | 183 | struct ofono_error error; | ||
815 | 184 | struct parcel rilp; | ||
816 | 185 | struct ofono_network_operator op; | ||
817 | 186 | gchar *lalpha, *salpha, *numeric; | ||
818 | 187 | |||
819 | 188 | if (message->error == RIL_E_SUCCESS) { | ||
820 | 189 | decode_ril_error(&error, "OK"); | ||
821 | 190 | } else { | ||
822 | 191 | ofono_error("Failed to retrive the current operator"); | ||
823 | 192 | goto error; | ||
824 | 193 | } | ||
825 | 194 | |||
826 | 195 | /* Set up Parcel struct for proper parsing */ | ||
827 | 196 | rilp.data = message->buf; | ||
828 | 197 | rilp.size = message->buf_len; | ||
829 | 198 | rilp.capacity = message->buf_len; | ||
830 | 199 | rilp.offset = 0; | ||
831 | 200 | |||
832 | 201 | /* Size of char ** */ | ||
833 | 202 | if (parcel_r_int32(&rilp) == 0) | ||
834 | 203 | goto error; | ||
835 | 204 | |||
836 | 205 | lalpha = parcel_r_string(&rilp); | ||
837 | 206 | salpha = parcel_r_string(&rilp); | ||
838 | 207 | numeric = parcel_r_string(&rilp); | ||
839 | 208 | |||
840 | 209 | DBG("RIL cops - lalpha: %s, salpha: %s, numeric: %s", | ||
841 | 210 | lalpha, salpha, numeric); | ||
842 | 211 | |||
843 | 212 | /* Try to use long by default */ | ||
844 | 213 | if (lalpha) | ||
845 | 214 | strncpy(op.name, lalpha, OFONO_MAX_OPERATOR_NAME_LENGTH); | ||
846 | 215 | else | ||
847 | 216 | strncpy(op.name, salpha, OFONO_MAX_OPERATOR_NAME_LENGTH); | ||
848 | 217 | |||
849 | 218 | extract_mcc_mnc(numeric, op.mcc, op.mnc); | ||
850 | 219 | |||
851 | 220 | /* Set to current */ | ||
852 | 221 | op.status = OPERATOR_STATUS_CURRENT; | ||
853 | 222 | op.tech = nd->tech; | ||
854 | 223 | |||
855 | 224 | DBG("ril_cops_cb: %s, %s, %s, %s", op.name, op.mcc, op.mnc, | ||
856 | 225 | registration_tech_to_string(op.tech)); | ||
857 | 226 | |||
858 | 227 | g_free(lalpha); | ||
859 | 228 | g_free(salpha); | ||
860 | 229 | g_free(numeric); | ||
861 | 230 | |||
862 | 231 | cb(&error, &op, cbd->data); | ||
863 | 232 | |||
864 | 233 | return; | ||
865 | 234 | |||
866 | 235 | error: | ||
867 | 236 | CALLBACK_WITH_FAILURE(cb, NULL, cbd->data); | ||
868 | 237 | } | ||
869 | 238 | |||
870 | 239 | static void ril_current_operator(struct ofono_netreg *netreg, | ||
871 | 240 | ofono_netreg_operator_cb_t cb, void *data) | ||
872 | 241 | { | ||
873 | 242 | struct netreg_data *nd = ofono_netreg_get_data(netreg); | ||
874 | 243 | struct cb_data *cbd = cb_data_new(cb, data); | ||
875 | 244 | |||
876 | 245 | cbd->user = nd; | ||
877 | 246 | |||
878 | 247 | if (g_ril_send(nd->ril, RIL_REQUEST_OPERATOR, NULL, | ||
879 | 248 | 0, ril_cops_cb, cbd, g_free) > 0) | ||
880 | 249 | return; | ||
881 | 250 | |||
882 | 251 | g_free(cbd); | ||
883 | 252 | |||
884 | 253 | CALLBACK_WITH_FAILURE(cb, NULL, data); | ||
885 | 254 | } | ||
886 | 255 | |||
887 | 256 | static void ril_cops_list_cb(struct ril_msg *message, gpointer user_data) | ||
888 | 257 | { | ||
889 | 258 | struct cb_data *cbd = user_data; | ||
890 | 259 | ofono_netreg_operator_list_cb_t cb = cbd->cb; | ||
891 | 260 | struct ofono_network_operator *list; | ||
892 | 261 | struct ofono_error error; | ||
893 | 262 | struct parcel rilp; | ||
894 | 263 | int noperators, i; | ||
895 | 264 | gchar *lalpha, *salpha, *numeric, *status; | ||
896 | 265 | |||
897 | 266 | if (message->error == RIL_E_SUCCESS) { | ||
898 | 267 | decode_ril_error(&error, "OK"); | ||
899 | 268 | } else { | ||
900 | 269 | ofono_error("Failed to retrive the list of operators"); | ||
901 | 270 | goto error; | ||
902 | 271 | } | ||
903 | 272 | |||
904 | 273 | /* Set up Parcel struct for proper parsing */ | ||
905 | 274 | rilp.data = message->buf; | ||
906 | 275 | rilp.size = message->buf_len; | ||
907 | 276 | rilp.capacity = message->buf_len; | ||
908 | 277 | rilp.offset = 0; | ||
909 | 278 | |||
910 | 279 | /* Number of operators at the list (4 strings for every operator) */ | ||
911 | 280 | noperators = parcel_r_int32(&rilp) / 4; | ||
912 | 281 | DBG("noperators = %d", noperators); | ||
913 | 282 | |||
914 | 283 | list = g_try_new0(struct ofono_network_operator, noperators); | ||
915 | 284 | if (list == NULL) | ||
916 | 285 | goto error; | ||
917 | 286 | |||
918 | 287 | for (i = 0; i < noperators; i++) { | ||
919 | 288 | lalpha = parcel_r_string(&rilp); | ||
920 | 289 | salpha = parcel_r_string(&rilp); | ||
921 | 290 | numeric = parcel_r_string(&rilp); | ||
922 | 291 | status = parcel_r_string(&rilp); | ||
923 | 292 | |||
924 | 293 | /* Try to use long by default */ | ||
925 | 294 | if (lalpha) { | ||
926 | 295 | strncpy(list[i].name, lalpha, | ||
927 | 296 | OFONO_MAX_OPERATOR_NAME_LENGTH); | ||
928 | 297 | } else { | ||
929 | 298 | strncpy(list[i].name, salpha, | ||
930 | 299 | OFONO_MAX_OPERATOR_NAME_LENGTH); | ||
931 | 300 | } | ||
932 | 301 | |||
933 | 302 | extract_mcc_mnc(numeric, list[i].mcc, list[i].mnc); | ||
934 | 303 | |||
935 | 304 | /* Use GSM as default, as RIL doesn't pass that info to us */ | ||
936 | 305 | list[i].tech = ACCESS_TECHNOLOGY_GSM; | ||
937 | 306 | |||
938 | 307 | /* Set the proper status */ | ||
939 | 308 | if (!strcmp(status, "unknown")) | ||
940 | 309 | list[i].status = OPERATOR_STATUS_UNKNOWN; | ||
941 | 310 | else if (!strcmp(status, "available")) | ||
942 | 311 | list[i].status = OPERATOR_STATUS_AVAILABLE; | ||
943 | 312 | else if (!strcmp(status, "current")) | ||
944 | 313 | list[i].status = OPERATOR_STATUS_CURRENT; | ||
945 | 314 | else if (!strcmp(status, "forbidden")) | ||
946 | 315 | list[i].status = OPERATOR_STATUS_FORBIDDEN; | ||
947 | 316 | |||
948 | 317 | DBG("Operator: %s, %s, %s, status: %s", | ||
949 | 318 | list[i].name, list[i].mcc, | ||
950 | 319 | list[i].mnc, status); | ||
951 | 320 | |||
952 | 321 | g_free(lalpha); | ||
953 | 322 | g_free(salpha); | ||
954 | 323 | g_free(numeric); | ||
955 | 324 | g_free(status); | ||
956 | 325 | } | ||
957 | 326 | |||
958 | 327 | cb(&error, noperators, list, cbd->data); | ||
959 | 328 | |||
960 | 329 | return; | ||
961 | 330 | |||
962 | 331 | error: | ||
963 | 332 | CALLBACK_WITH_FAILURE(cb, 0, NULL, cbd->data); | ||
964 | 333 | } | ||
965 | 334 | |||
966 | 335 | static void ril_list_operators(struct ofono_netreg *netreg, | ||
967 | 336 | ofono_netreg_operator_list_cb_t cb, void *data) | ||
968 | 337 | { | ||
969 | 338 | struct netreg_data *nd = ofono_netreg_get_data(netreg); | ||
970 | 339 | struct cb_data *cbd = cb_data_new(cb, data); | ||
971 | 340 | |||
972 | 341 | cbd->user = nd; | ||
973 | 342 | |||
974 | 343 | if (g_ril_send(nd->ril, RIL_REQUEST_QUERY_AVAILABLE_NETWORKS, NULL, | ||
975 | 344 | 0, ril_cops_list_cb, cbd, g_free) > 0) | ||
976 | 345 | return; | ||
977 | 346 | |||
978 | 347 | g_free(cbd); | ||
979 | 348 | |||
980 | 349 | CALLBACK_WITH_FAILURE(cb, 0, NULL, data); | ||
981 | 350 | } | ||
982 | 351 | |||
983 | 352 | static void ril_register_cb(struct ril_msg *message, gpointer user_data) | ||
984 | 353 | { | ||
985 | 354 | struct cb_data *cbd = user_data; | ||
986 | 355 | ofono_netreg_register_cb_t cb = cbd->cb; | ||
987 | 356 | struct ofono_error error; | ||
988 | 357 | |||
989 | 358 | if (message->error == RIL_E_SUCCESS) { | ||
990 | 359 | decode_ril_error(&error, "OK"); | ||
991 | 360 | } else { | ||
992 | 361 | decode_ril_error(&error, "FAIL"); | ||
993 | 362 | } | ||
994 | 363 | |||
995 | 364 | cb(&error, cbd->data); | ||
996 | 365 | } | ||
997 | 366 | |||
998 | 367 | static void ril_register_auto(struct ofono_netreg *netreg, | ||
999 | 368 | ofono_netreg_register_cb_t cb, void *data) | ||
1000 | 369 | { | ||
1001 | 370 | struct netreg_data *nd = ofono_netreg_get_data(netreg); | ||
1002 | 371 | struct cb_data *cbd = cb_data_new(cb, data); | ||
1003 | 372 | |||
1004 | 373 | if (g_ril_send(nd->ril, RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, | ||
1005 | 374 | NULL, 0, ril_register_cb, cbd, g_free) > 0) | ||
1006 | 375 | return; | ||
1007 | 376 | |||
1008 | 377 | g_free(cbd); | ||
1009 | 378 | |||
1010 | 379 | CALLBACK_WITH_FAILURE(cb, data); | ||
1011 | 380 | } | ||
1012 | 381 | |||
1013 | 382 | static void ril_register_manual(struct ofono_netreg *netreg, | ||
1014 | 383 | const char *mcc, const char *mnc, | ||
1015 | 384 | ofono_netreg_register_cb_t cb, void *data) | ||
1016 | 385 | { | ||
1017 | 386 | struct netreg_data *nd = ofono_netreg_get_data(netreg); | ||
1018 | 387 | struct cb_data *cbd = cb_data_new(cb, data); | ||
1019 | 388 | char buf[OFONO_MAX_MCC_LENGTH + OFONO_MAX_MNC_LENGTH + 1]; | ||
1020 | 389 | struct parcel rilp; | ||
1021 | 390 | int ret; | ||
1022 | 391 | |||
1023 | 392 | parcel_init(&rilp); | ||
1024 | 393 | |||
1025 | 394 | /* RIL expects a char * specifying MCCMNC of network to select */ | ||
1026 | 395 | snprintf(buf, sizeof(buf), "%s%s", mcc, mnc); | ||
1027 | 396 | parcel_w_string(&rilp, buf); | ||
1028 | 397 | |||
1029 | 398 | ret = g_ril_send(nd->ril, RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL, | ||
1030 | 399 | rilp.data, rilp.size, ril_register_cb, | ||
1031 | 400 | cbd, g_free); | ||
1032 | 401 | parcel_free(&rilp); | ||
1033 | 402 | |||
1034 | 403 | /* In case of error free cbd and return the cb with failure */ | ||
1035 | 404 | if (ret <= 0) { | ||
1036 | 405 | g_free(cbd); | ||
1037 | 406 | CALLBACK_WITH_FAILURE(cb, data); | ||
1038 | 407 | } | ||
1039 | 408 | } | ||
1040 | 409 | |||
1041 | 410 | static void ril_strength_notify(struct ril_msg *message, gpointer user_data) | ||
1042 | 411 | { | ||
1043 | 412 | struct ofono_netreg *netreg = user_data; | ||
1044 | 413 | int strength; | ||
1045 | 414 | |||
1046 | 415 | g_assert(message->req == RIL_UNSOL_SIGNAL_STRENGTH); | ||
1047 | 416 | |||
1048 | 417 | strength = ril_util_get_signal(message); | ||
1049 | 418 | ofono_netreg_strength_notify(netreg, strength); | ||
1050 | 419 | |||
1051 | 420 | return; | ||
1052 | 421 | } | ||
1053 | 422 | |||
1054 | 423 | static void ril_strength_cb(struct ril_msg *message, gpointer user_data) | ||
1055 | 424 | { | ||
1056 | 425 | struct cb_data *cbd = user_data; | ||
1057 | 426 | ofono_netreg_strength_cb_t cb = cbd->cb; | ||
1058 | 427 | struct ofono_error error; | ||
1059 | 428 | int strength; | ||
1060 | 429 | |||
1061 | 430 | if (message->error == RIL_E_SUCCESS) { | ||
1062 | 431 | decode_ril_error(&error, "OK"); | ||
1063 | 432 | } else { | ||
1064 | 433 | ofono_error("Failed to retrive the signal strength"); | ||
1065 | 434 | goto error; | ||
1066 | 435 | } | ||
1067 | 436 | |||
1068 | 437 | strength = ril_util_get_signal(message); | ||
1069 | 438 | cb(&error, strength, cbd->data); | ||
1070 | 439 | |||
1071 | 440 | return; | ||
1072 | 441 | |||
1073 | 442 | error: | ||
1074 | 443 | CALLBACK_WITH_FAILURE(cb, -1, cbd->data); | ||
1075 | 444 | } | ||
1076 | 445 | |||
1077 | 446 | static void ril_signal_strength(struct ofono_netreg *netreg, | ||
1078 | 447 | ofono_netreg_strength_cb_t cb, void *data) | ||
1079 | 448 | { | ||
1080 | 449 | struct netreg_data *nd = ofono_netreg_get_data(netreg); | ||
1081 | 450 | struct cb_data *cbd = cb_data_new(cb, data); | ||
1082 | 451 | |||
1083 | 452 | cbd->user = nd; | ||
1084 | 453 | |||
1085 | 454 | if (g_ril_send(nd->ril, RIL_REQUEST_SIGNAL_STRENGTH, | ||
1086 | 455 | NULL, 0, ril_strength_cb, cbd, g_free) > 0) | ||
1087 | 456 | return; | ||
1088 | 457 | |||
1089 | 458 | g_free(cbd); | ||
1090 | 459 | |||
1091 | 460 | CALLBACK_WITH_FAILURE(cb, -1, data); | ||
1092 | 461 | } | ||
1093 | 462 | |||
1094 | 463 | static void ril_nitz_notify(struct ril_msg *message, gpointer user_data) | ||
1095 | 464 | { | ||
1096 | 465 | struct ofono_netreg *netreg = user_data; | ||
1097 | 466 | struct netreg_data *nd = ofono_netreg_get_data(netreg); | ||
1098 | 467 | struct parcel rilp; | ||
1099 | 468 | int year, mon, mday, hour, min, sec, dst, tzi; | ||
1100 | 469 | char tzs, tz[4]; | ||
1101 | 470 | gchar *nitz; | ||
1102 | 471 | |||
1103 | 472 | if (message->req != RIL_UNSOL_NITZ_TIME_RECEIVED) | ||
1104 | 473 | goto error; | ||
1105 | 474 | |||
1106 | 475 | /* Set up Parcel struct for proper parsing */ | ||
1107 | 476 | rilp.data = message->buf; | ||
1108 | 477 | rilp.size = message->buf_len; | ||
1109 | 478 | rilp.capacity = message->buf_len; | ||
1110 | 479 | rilp.offset = 0; | ||
1111 | 480 | |||
1112 | 481 | nitz = parcel_r_string(&rilp); | ||
1113 | 482 | |||
1114 | 483 | DBG("RIL NITZ: %s", nitz); | ||
1115 | 484 | |||
1116 | 485 | sscanf(nitz, "%u/%u/%u,%u:%u:%u%c%u,%u", &year, &mon, &mday, | ||
1117 | 486 | &hour, &min, &sec, &tzs, &tzi, &dst); | ||
1118 | 487 | sprintf(tz, "%c%d", tzs, tzi); | ||
1119 | 488 | |||
1120 | 489 | nd->time.utcoff = atoi(tz) * 15 * 60; | ||
1121 | 490 | nd->time.dst = dst; | ||
1122 | 491 | nd->time.sec = sec; | ||
1123 | 492 | nd->time.min = min; | ||
1124 | 493 | nd->time.hour = hour; | ||
1125 | 494 | nd->time.mday = mday; | ||
1126 | 495 | nd->time.mon = mon; | ||
1127 | 496 | nd->time.year = 2000 + year; | ||
1128 | 497 | |||
1129 | 498 | ofono_netreg_time_notify(netreg, &nd->time); | ||
1130 | 499 | |||
1131 | 500 | g_free(nitz); | ||
1132 | 501 | |||
1133 | 502 | return; | ||
1134 | 503 | |||
1135 | 504 | error: | ||
1136 | 505 | ofono_error("Unable to notify ofono about nitz"); | ||
1137 | 506 | } | ||
1138 | 507 | |||
1139 | 508 | static gboolean ril_delayed_register(gpointer user_data) | ||
1140 | 509 | { | ||
1141 | 510 | struct ofono_netreg *netreg = user_data; | ||
1142 | 511 | struct netreg_data *nd = ofono_netreg_get_data(netreg); | ||
1143 | 512 | ofono_netreg_register(netreg); | ||
1144 | 513 | |||
1145 | 514 | /* Register for network state changes */ | ||
1146 | 515 | g_ril_register(nd->ril, RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, | ||
1147 | 516 | ril_network_state_change, netreg); | ||
1148 | 517 | |||
1149 | 518 | /* Register for network time update reports */ | ||
1150 | 519 | g_ril_register(nd->ril, RIL_UNSOL_NITZ_TIME_RECEIVED, | ||
1151 | 520 | ril_nitz_notify, netreg); | ||
1152 | 521 | |||
1153 | 522 | /* Register for signal strength changes */ | ||
1154 | 523 | g_ril_register(nd->ril, RIL_UNSOL_SIGNAL_STRENGTH, | ||
1155 | 524 | ril_strength_notify, netreg); | ||
1156 | 525 | |||
1157 | 526 | /* This makes the timeout a single-shot */ | ||
1158 | 527 | return FALSE; | ||
1159 | 528 | } | ||
1160 | 529 | |||
1161 | 530 | static int ril_netreg_probe(struct ofono_netreg *netreg, unsigned int vendor, | ||
1162 | 531 | void *data) | ||
1163 | 532 | { | ||
1164 | 533 | GRil *ril = data; | ||
1165 | 534 | struct netreg_data *nd; | ||
1166 | 535 | |||
1167 | 536 | nd = g_new0(struct netreg_data, 1); | ||
1168 | 537 | |||
1169 | 538 | nd->ril = g_ril_clone(ril); | ||
1170 | 539 | nd->vendor = vendor; | ||
1171 | 540 | nd->tech = -1; | ||
1172 | 541 | nd->time.sec = -1; | ||
1173 | 542 | nd->time.min = -1; | ||
1174 | 543 | nd->time.hour = -1; | ||
1175 | 544 | nd->time.mday = -1; | ||
1176 | 545 | nd->time.mon = -1; | ||
1177 | 546 | nd->time.year = -1; | ||
1178 | 547 | nd->time.dst = 0; | ||
1179 | 548 | nd->time.utcoff = 0; | ||
1180 | 549 | ofono_netreg_set_data(netreg, nd); | ||
1181 | 550 | |||
1182 | 551 | /* ofono_netreg_register() needs to be called after | ||
1183 | 552 | * the driver has been set in devinfo_create() which | ||
1184 | 553 | * calls this function. Most other drivers use a | ||
1185 | 554 | * callback after getting some return from the modem | ||
1186 | 555 | * itself... | ||
1187 | 556 | */ | ||
1188 | 557 | g_timeout_add_seconds(1, ril_delayed_register, netreg); | ||
1189 | 558 | |||
1190 | 559 | return 0; | ||
1191 | 560 | } | ||
1192 | 561 | |||
1193 | 562 | static void ril_netreg_remove(struct ofono_netreg *netreg) | ||
1194 | 563 | { | ||
1195 | 564 | struct netreg_data *nd = ofono_netreg_get_data(netreg); | ||
1196 | 565 | |||
1197 | 566 | if (nd->nitz_timeout) | ||
1198 | 567 | g_source_remove(nd->nitz_timeout); | ||
1199 | 568 | |||
1200 | 569 | ofono_netreg_set_data(netreg, NULL); | ||
1201 | 570 | |||
1202 | 571 | g_ril_unref(nd->ril); | ||
1203 | 572 | g_free(nd); | ||
1204 | 573 | } | ||
1205 | 574 | |||
1206 | 575 | static struct ofono_netreg_driver driver = { | ||
1207 | 576 | .name = "rilmodem", | ||
1208 | 577 | .probe = ril_netreg_probe, | ||
1209 | 578 | .remove = ril_netreg_remove, | ||
1210 | 579 | .registration_status = ril_registration_status, | ||
1211 | 580 | .current_operator = ril_current_operator, | ||
1212 | 581 | .list_operators = ril_list_operators, | ||
1213 | 582 | .register_auto = ril_register_auto, | ||
1214 | 583 | .register_manual = ril_register_manual, | ||
1215 | 584 | .strength = ril_signal_strength, | ||
1216 | 585 | }; | ||
1217 | 586 | |||
1218 | 587 | void ril_netreg_init(void) | ||
1219 | 588 | { | ||
1220 | 589 | ofono_netreg_driver_register(&driver); | ||
1221 | 590 | } | ||
1222 | 591 | |||
1223 | 592 | void ril_netreg_exit(void) | ||
1224 | 593 | { | ||
1225 | 594 | ofono_netreg_driver_unregister(&driver); | ||
1226 | 595 | } | ||
1227 | 0 | 596 | ||
1228 | === added file 'drivers/rilmodem/rilmodem.c' | |||
1229 | --- drivers/rilmodem/rilmodem.c 1970-01-01 00:00:00 +0000 | |||
1230 | +++ drivers/rilmodem/rilmodem.c 2013-04-09 20:01:20 +0000 | |||
1231 | @@ -0,0 +1,61 @@ | |||
1232 | 1 | /* | ||
1233 | 2 | * | ||
1234 | 3 | * oFono - Open Source Telephony - RIL Modem Support | ||
1235 | 4 | * | ||
1236 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
1237 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
1238 | 7 | * | ||
1239 | 8 | * This program is free software; you can redistribute it and/or modify | ||
1240 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
1241 | 10 | * published by the Free Software Foundation. | ||
1242 | 11 | * | ||
1243 | 12 | * This program is distributed in the hope that it will be useful, | ||
1244 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1245 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1246 | 15 | * GNU General Public License for more details. | ||
1247 | 16 | * | ||
1248 | 17 | * You should have received a copy of the GNU General Public License | ||
1249 | 18 | * along with this program; if not, write to the Free Software | ||
1250 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
1251 | 20 | * | ||
1252 | 21 | */ | ||
1253 | 22 | |||
1254 | 23 | #ifdef HAVE_CONFIG_H | ||
1255 | 24 | #include <config.h> | ||
1256 | 25 | #endif | ||
1257 | 26 | |||
1258 | 27 | #include <glib.h> | ||
1259 | 28 | #include <gril.h> | ||
1260 | 29 | |||
1261 | 30 | #define OFONO_API_SUBJECT_TO_CHANGE | ||
1262 | 31 | #include <ofono/plugin.h> | ||
1263 | 32 | #include <ofono/log.h> | ||
1264 | 33 | |||
1265 | 34 | #include "rilmodem.h" | ||
1266 | 35 | |||
1267 | 36 | static int rilmodem_init(void) | ||
1268 | 37 | { | ||
1269 | 38 | DBG(""); | ||
1270 | 39 | |||
1271 | 40 | ril_devinfo_init(); | ||
1272 | 41 | ril_voicecall_init(); | ||
1273 | 42 | ril_sms_init(); | ||
1274 | 43 | ril_netreg_init(); | ||
1275 | 44 | ril_call_volume_init(); | ||
1276 | 45 | |||
1277 | 46 | return 0; | ||
1278 | 47 | } | ||
1279 | 48 | |||
1280 | 49 | static void rilmodem_exit(void) | ||
1281 | 50 | { | ||
1282 | 51 | DBG(""); | ||
1283 | 52 | |||
1284 | 53 | ril_devinfo_exit(); | ||
1285 | 54 | ril_voicecall_exit(); | ||
1286 | 55 | ril_sms_exit(); | ||
1287 | 56 | ril_netreg_exit(); | ||
1288 | 57 | ril_call_volume_exit(); | ||
1289 | 58 | } | ||
1290 | 59 | |||
1291 | 60 | OFONO_PLUGIN_DEFINE(rilmodem, "RIL modem driver", VERSION, | ||
1292 | 61 | OFONO_PLUGIN_PRIORITY_DEFAULT, rilmodem_init, rilmodem_exit) | ||
1293 | 0 | 62 | ||
1294 | === added file 'drivers/rilmodem/rilmodem.h' | |||
1295 | --- drivers/rilmodem/rilmodem.h 1970-01-01 00:00:00 +0000 | |||
1296 | +++ drivers/rilmodem/rilmodem.h 2013-04-09 20:01:20 +0000 | |||
1297 | @@ -0,0 +1,38 @@ | |||
1298 | 1 | /* | ||
1299 | 2 | * | ||
1300 | 3 | * oFono - Open Source Telephony - RIL Modem Support | ||
1301 | 4 | * | ||
1302 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
1303 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
1304 | 7 | * | ||
1305 | 8 | * This program is free software; you can redistribute it and/or modify | ||
1306 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
1307 | 10 | * published by the Free Software Foundation. | ||
1308 | 11 | * | ||
1309 | 12 | * This program is distributed in the hope that it will be useful, | ||
1310 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1311 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1312 | 15 | * GNU General Public License for more details. | ||
1313 | 16 | * | ||
1314 | 17 | * You should have received a copy of the GNU General Public License | ||
1315 | 18 | * along with this program; if not, write to the Free Software | ||
1316 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
1317 | 20 | * | ||
1318 | 21 | */ | ||
1319 | 22 | |||
1320 | 23 | #include "rilutil.h" | ||
1321 | 24 | |||
1322 | 25 | extern void ril_devinfo_init(void); | ||
1323 | 26 | extern void ril_devinfo_exit(void); | ||
1324 | 27 | |||
1325 | 28 | extern void ril_call_volume_init(void); | ||
1326 | 29 | extern void ril_call_volume_exit(void); | ||
1327 | 30 | |||
1328 | 31 | extern void ril_voicecall_init(void); | ||
1329 | 32 | extern void ril_voicecall_exit(void); | ||
1330 | 33 | |||
1331 | 34 | extern void ril_sms_init(void); | ||
1332 | 35 | extern void ril_sms_exit(void); | ||
1333 | 36 | |||
1334 | 37 | extern void ril_netreg_init(void); | ||
1335 | 38 | extern void ril_netreg_exit(void); | ||
1336 | 0 | 39 | ||
1337 | === added file 'drivers/rilmodem/rilutil.c' | |||
1338 | --- drivers/rilmodem/rilutil.c 1970-01-01 00:00:00 +0000 | |||
1339 | +++ drivers/rilmodem/rilutil.c 2013-04-09 20:01:20 +0000 | |||
1340 | @@ -0,0 +1,372 @@ | |||
1341 | 1 | /* | ||
1342 | 2 | * | ||
1343 | 3 | * oFono - Open Source Telephony | ||
1344 | 4 | * | ||
1345 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
1346 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
1347 | 7 | * | ||
1348 | 8 | * This program is free software; you can redistribute it and/or modify | ||
1349 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
1350 | 10 | * published by the Free Software Foundation. | ||
1351 | 11 | * | ||
1352 | 12 | * This program is distributed in the hope that it will be useful, | ||
1353 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1354 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1355 | 15 | * GNU General Public License for more details. | ||
1356 | 16 | * | ||
1357 | 17 | * You should have received a copy of the GNU General Public License | ||
1358 | 18 | * along with this program; if not, write to the Free Software | ||
1359 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
1360 | 20 | * | ||
1361 | 21 | */ | ||
1362 | 22 | |||
1363 | 23 | #ifdef HAVE_CONFIG_H | ||
1364 | 24 | #include <config.h> | ||
1365 | 25 | #endif | ||
1366 | 26 | |||
1367 | 27 | #include <glib.h> | ||
1368 | 28 | #include <gril.h> | ||
1369 | 29 | #include <string.h> | ||
1370 | 30 | #include <stdlib.h> | ||
1371 | 31 | |||
1372 | 32 | #define OFONO_API_SUBJECT_TO_CHANGE | ||
1373 | 33 | #include <ofono/log.h> | ||
1374 | 34 | #include <ofono/types.h> | ||
1375 | 35 | |||
1376 | 36 | #include "common.h" | ||
1377 | 37 | #include "rilutil.h" | ||
1378 | 38 | #include "parcel.h" | ||
1379 | 39 | |||
1380 | 40 | struct ril_util_sim_state_query { | ||
1381 | 41 | GRil *ril; | ||
1382 | 42 | guint cpin_poll_source; | ||
1383 | 43 | guint cpin_poll_count; | ||
1384 | 44 | guint interval; | ||
1385 | 45 | guint num_times; | ||
1386 | 46 | ril_util_sim_inserted_cb_t cb; | ||
1387 | 47 | void *userdata; | ||
1388 | 48 | GDestroyNotify destroy; | ||
1389 | 49 | }; | ||
1390 | 50 | |||
1391 | 51 | static gboolean cpin_check(gpointer userdata); | ||
1392 | 52 | |||
1393 | 53 | void decode_ril_error(struct ofono_error *error, const char *final) | ||
1394 | 54 | { | ||
1395 | 55 | if (!strcmp(final, "OK")) { | ||
1396 | 56 | error->type = OFONO_ERROR_TYPE_NO_ERROR; | ||
1397 | 57 | error->error = 0; | ||
1398 | 58 | } else { | ||
1399 | 59 | error->type = OFONO_ERROR_TYPE_FAILURE; | ||
1400 | 60 | error->error = 0; | ||
1401 | 61 | } | ||
1402 | 62 | } | ||
1403 | 63 | |||
1404 | 64 | gint ril_util_call_compare_by_status(gconstpointer a, gconstpointer b) | ||
1405 | 65 | { | ||
1406 | 66 | const struct ofono_call *call = a; | ||
1407 | 67 | int status = GPOINTER_TO_INT(b); | ||
1408 | 68 | |||
1409 | 69 | if (status != call->status) | ||
1410 | 70 | return 1; | ||
1411 | 71 | |||
1412 | 72 | return 0; | ||
1413 | 73 | } | ||
1414 | 74 | |||
1415 | 75 | gint ril_util_call_compare_by_phone_number(gconstpointer a, gconstpointer b) | ||
1416 | 76 | { | ||
1417 | 77 | const struct ofono_call *call = a; | ||
1418 | 78 | const struct ofono_phone_number *pb = b; | ||
1419 | 79 | |||
1420 | 80 | return memcmp(&call->phone_number, pb, | ||
1421 | 81 | sizeof(struct ofono_phone_number)); | ||
1422 | 82 | } | ||
1423 | 83 | |||
1424 | 84 | gint ril_util_call_compare_by_id(gconstpointer a, gconstpointer b) | ||
1425 | 85 | { | ||
1426 | 86 | const struct ofono_call *call = a; | ||
1427 | 87 | unsigned int id = GPOINTER_TO_UINT(b); | ||
1428 | 88 | |||
1429 | 89 | if (id < call->id) | ||
1430 | 90 | return -1; | ||
1431 | 91 | |||
1432 | 92 | if (id > call->id) | ||
1433 | 93 | return 1; | ||
1434 | 94 | |||
1435 | 95 | return 0; | ||
1436 | 96 | } | ||
1437 | 97 | |||
1438 | 98 | gint ril_util_call_compare(gconstpointer a, gconstpointer b) | ||
1439 | 99 | { | ||
1440 | 100 | const struct ofono_call *ca = a; | ||
1441 | 101 | const struct ofono_call *cb = b; | ||
1442 | 102 | |||
1443 | 103 | if (ca->id < cb->id) | ||
1444 | 104 | return -1; | ||
1445 | 105 | |||
1446 | 106 | if (ca->id > cb->id) | ||
1447 | 107 | return 1; | ||
1448 | 108 | |||
1449 | 109 | return 0; | ||
1450 | 110 | } | ||
1451 | 111 | |||
1452 | 112 | static gboolean cpin_check(gpointer userdata) | ||
1453 | 113 | { | ||
1454 | 114 | struct ril_util_sim_state_query *req = userdata; | ||
1455 | 115 | |||
1456 | 116 | req->cpin_poll_source = 0; | ||
1457 | 117 | |||
1458 | 118 | return FALSE; | ||
1459 | 119 | } | ||
1460 | 120 | |||
1461 | 121 | struct ril_util_sim_state_query *ril_util_sim_state_query_new(GRil *ril, | ||
1462 | 122 | guint interval, guint num_times, | ||
1463 | 123 | ril_util_sim_inserted_cb_t cb, | ||
1464 | 124 | void *userdata, | ||
1465 | 125 | GDestroyNotify destroy) | ||
1466 | 126 | { | ||
1467 | 127 | struct ril_util_sim_state_query *req; | ||
1468 | 128 | |||
1469 | 129 | req = g_new0(struct ril_util_sim_state_query, 1); | ||
1470 | 130 | |||
1471 | 131 | req->ril = ril; | ||
1472 | 132 | req->interval = interval; | ||
1473 | 133 | req->num_times = num_times; | ||
1474 | 134 | req->cb = cb; | ||
1475 | 135 | req->userdata = userdata; | ||
1476 | 136 | req->destroy = destroy; | ||
1477 | 137 | |||
1478 | 138 | cpin_check(req); | ||
1479 | 139 | |||
1480 | 140 | return req; | ||
1481 | 141 | } | ||
1482 | 142 | |||
1483 | 143 | void ril_util_sim_state_query_free(struct ril_util_sim_state_query *req) | ||
1484 | 144 | { | ||
1485 | 145 | if (req == NULL) | ||
1486 | 146 | return; | ||
1487 | 147 | |||
1488 | 148 | if (req->cpin_poll_source > 0) | ||
1489 | 149 | g_source_remove(req->cpin_poll_source); | ||
1490 | 150 | |||
1491 | 151 | if (req->destroy) | ||
1492 | 152 | req->destroy(req->userdata); | ||
1493 | 153 | |||
1494 | 154 | g_free(req); | ||
1495 | 155 | } | ||
1496 | 156 | |||
1497 | 157 | GSList *ril_util_parse_clcc(struct ril_msg *message) | ||
1498 | 158 | { | ||
1499 | 159 | struct ofono_call *call; | ||
1500 | 160 | struct parcel rilp; | ||
1501 | 161 | GSList *l = NULL; | ||
1502 | 162 | int num, i; | ||
1503 | 163 | gchar *number, *name; | ||
1504 | 164 | |||
1505 | 165 | /* Set up Parcel struct for proper parsing */ | ||
1506 | 166 | rilp.data = message->buf; | ||
1507 | 167 | rilp.size = message->buf_len; | ||
1508 | 168 | rilp.capacity = message->buf_len; | ||
1509 | 169 | rilp.offset = 0; | ||
1510 | 170 | |||
1511 | 171 | /* Number of RIL_Call structs */ | ||
1512 | 172 | num = parcel_r_int32(&rilp); | ||
1513 | 173 | for (i = 0; i < num; i++) { | ||
1514 | 174 | call = g_try_new(struct ofono_call, 1); | ||
1515 | 175 | if (call == NULL) | ||
1516 | 176 | break; | ||
1517 | 177 | |||
1518 | 178 | ofono_call_init(call); | ||
1519 | 179 | call->status = parcel_r_int32(&rilp); | ||
1520 | 180 | call->id = parcel_r_int32(&rilp); | ||
1521 | 181 | call->phone_number.type = parcel_r_int32(&rilp); | ||
1522 | 182 | parcel_r_int32(&rilp); /* isMpty */ | ||
1523 | 183 | parcel_r_int32(&rilp); /* isMT */ | ||
1524 | 184 | parcel_r_int32(&rilp); /* als */ | ||
1525 | 185 | call->type = parcel_r_int32(&rilp); /* isVoice */ | ||
1526 | 186 | parcel_r_int32(&rilp); /* isVoicePrivacy */ | ||
1527 | 187 | number = parcel_r_string(&rilp); | ||
1528 | 188 | if (number) { | ||
1529 | 189 | strncpy(call->phone_number.number, number, | ||
1530 | 190 | OFONO_MAX_PHONE_NUMBER_LENGTH); | ||
1531 | 191 | g_free(number); | ||
1532 | 192 | } | ||
1533 | 193 | parcel_r_int32(&rilp); /* numberPresentation */ | ||
1534 | 194 | name = parcel_r_string(&rilp); | ||
1535 | 195 | if (name) { | ||
1536 | 196 | strncpy(call->name, name, | ||
1537 | 197 | OFONO_MAX_CALLER_NAME_LENGTH); | ||
1538 | 198 | g_free(name); | ||
1539 | 199 | } | ||
1540 | 200 | parcel_r_int32(&rilp); /* namePresentation */ | ||
1541 | 201 | parcel_r_int32(&rilp); /* uusInfo */ | ||
1542 | 202 | |||
1543 | 203 | if (strlen(call->phone_number.number) > 0) | ||
1544 | 204 | call->clip_validity = 0; | ||
1545 | 205 | else | ||
1546 | 206 | call->clip_validity = 2; | ||
1547 | 207 | |||
1548 | 208 | DBG("Adding call - id: %d, status: %d, type: %d, number: %s, name: %s", | ||
1549 | 209 | call->id, call->status, call->type, | ||
1550 | 210 | call->phone_number.number, call->name); | ||
1551 | 211 | |||
1552 | 212 | l = g_slist_insert_sorted(l, call, ril_util_call_compare); | ||
1553 | 213 | } | ||
1554 | 214 | |||
1555 | 215 | return l; | ||
1556 | 216 | } | ||
1557 | 217 | |||
1558 | 218 | gboolean ril_util_parse_reg(struct ril_msg *message, int *status, | ||
1559 | 219 | int *lac, int *ci, int *tech) | ||
1560 | 220 | { | ||
1561 | 221 | struct parcel rilp; | ||
1562 | 222 | gchar *sstatus, *slac, *sci, *stech; | ||
1563 | 223 | |||
1564 | 224 | /* Set up Parcel struct for proper parsing */ | ||
1565 | 225 | rilp.data = message->buf; | ||
1566 | 226 | rilp.size = message->buf_len; | ||
1567 | 227 | rilp.capacity = message->buf_len; | ||
1568 | 228 | rilp.offset = 0; | ||
1569 | 229 | |||
1570 | 230 | /* Size of char ** */ | ||
1571 | 231 | if (parcel_r_int32(&rilp) == 0) | ||
1572 | 232 | return FALSE; | ||
1573 | 233 | |||
1574 | 234 | sstatus = parcel_r_string(&rilp); | ||
1575 | 235 | slac = parcel_r_string(&rilp); | ||
1576 | 236 | sci = parcel_r_string(&rilp); | ||
1577 | 237 | stech = parcel_r_string(&rilp); | ||
1578 | 238 | |||
1579 | 239 | DBG("RIL reg - status: %s, lac: %s, ci: %s, radio tech: %s", | ||
1580 | 240 | sstatus, slac, sci, stech); | ||
1581 | 241 | |||
1582 | 242 | if (status) | ||
1583 | 243 | *status = atoi(sstatus); | ||
1584 | 244 | if (lac) { | ||
1585 | 245 | if (slac) | ||
1586 | 246 | *lac = strtol(slac, NULL, 16); | ||
1587 | 247 | else | ||
1588 | 248 | *lac = -1; | ||
1589 | 249 | } | ||
1590 | 250 | if (ci) { | ||
1591 | 251 | if (sci) | ||
1592 | 252 | *ci = strtol(sci, NULL, 16); | ||
1593 | 253 | else | ||
1594 | 254 | *ci = -1; | ||
1595 | 255 | } | ||
1596 | 256 | if (tech) { | ||
1597 | 257 | switch(atoi(stech)) { | ||
1598 | 258 | case RADIO_TECH_UNKNOWN: | ||
1599 | 259 | *tech = -1; | ||
1600 | 260 | break; | ||
1601 | 261 | case RADIO_TECH_GPRS: | ||
1602 | 262 | *tech = ACCESS_TECHNOLOGY_GSM; | ||
1603 | 263 | break; | ||
1604 | 264 | case RADIO_TECH_EDGE: | ||
1605 | 265 | *tech = ACCESS_TECHNOLOGY_GSM_EGPRS; | ||
1606 | 266 | break; | ||
1607 | 267 | case RADIO_TECH_UMTS: | ||
1608 | 268 | *tech = ACCESS_TECHNOLOGY_UTRAN; | ||
1609 | 269 | break; | ||
1610 | 270 | case RADIO_TECH_HSDPA: | ||
1611 | 271 | *tech = ACCESS_TECHNOLOGY_UTRAN_HSDPA; | ||
1612 | 272 | break; | ||
1613 | 273 | case RADIO_TECH_HSUPA: | ||
1614 | 274 | *tech = ACCESS_TECHNOLOGY_UTRAN_HSUPA; | ||
1615 | 275 | break; | ||
1616 | 276 | case RADIO_TECH_HSPA: | ||
1617 | 277 | *tech = ACCESS_TECHNOLOGY_UTRAN_HSDPA_HSUPA; | ||
1618 | 278 | break; | ||
1619 | 279 | default: | ||
1620 | 280 | *tech = -1; | ||
1621 | 281 | } | ||
1622 | 282 | } | ||
1623 | 283 | |||
1624 | 284 | /* Free our parcel handlers */ | ||
1625 | 285 | g_free(sstatus); | ||
1626 | 286 | g_free(slac); | ||
1627 | 287 | g_free(sci); | ||
1628 | 288 | g_free(stech); | ||
1629 | 289 | |||
1630 | 290 | return TRUE; | ||
1631 | 291 | } | ||
1632 | 292 | |||
1633 | 293 | gint ril_util_parse_sms_response(struct ril_msg *message) | ||
1634 | 294 | { | ||
1635 | 295 | struct parcel rilp; | ||
1636 | 296 | int error, mr; | ||
1637 | 297 | char *ack_pdu; | ||
1638 | 298 | |||
1639 | 299 | /* Set up Parcel struct for proper parsing */ | ||
1640 | 300 | rilp.data = message->buf; | ||
1641 | 301 | rilp.size = message->buf_len; | ||
1642 | 302 | rilp.capacity = message->buf_len; | ||
1643 | 303 | rilp.offset = 0; | ||
1644 | 304 | |||
1645 | 305 | /* TP-Message-Reference for GSM/ | ||
1646 | 306 | * BearerData MessageId for CDMA | ||
1647 | 307 | */ | ||
1648 | 308 | mr = parcel_r_int32(&rilp); | ||
1649 | 309 | ack_pdu = parcel_r_int32(&rilp); | ||
1650 | 310 | error = parcel_r_int32(&rilp); | ||
1651 | 311 | |||
1652 | 312 | DBG("SMS_Response mr: %d, ackPDU: %d, error: %d", | ||
1653 | 313 | mr, ack_pdu, error); | ||
1654 | 314 | |||
1655 | 315 | return mr; | ||
1656 | 316 | } | ||
1657 | 317 | |||
1658 | 318 | gint ril_util_get_signal(struct ril_msg *message) | ||
1659 | 319 | { | ||
1660 | 320 | struct parcel rilp; | ||
1661 | 321 | int gw_signal, cdma_dbm, evdo_dbm, lte_signal; | ||
1662 | 322 | |||
1663 | 323 | /* Set up Parcel struct for proper parsing */ | ||
1664 | 324 | rilp.data = message->buf; | ||
1665 | 325 | rilp.size = message->buf_len; | ||
1666 | 326 | rilp.capacity = message->buf_len; | ||
1667 | 327 | rilp.offset = 0; | ||
1668 | 328 | |||
1669 | 329 | /* RIL_SignalStrength_v6 */ | ||
1670 | 330 | /* GW_SignalStrength */ | ||
1671 | 331 | gw_signal = parcel_r_int32(&rilp); | ||
1672 | 332 | parcel_r_int32(&rilp); /* bitErrorRate */ | ||
1673 | 333 | |||
1674 | 334 | /* CDMA_SignalStrength */ | ||
1675 | 335 | cdma_dbm = parcel_r_int32(&rilp); | ||
1676 | 336 | parcel_r_int32(&rilp); /* ecio */ | ||
1677 | 337 | |||
1678 | 338 | /* EVDO_SignalStrength */ | ||
1679 | 339 | evdo_dbm = parcel_r_int32(&rilp); | ||
1680 | 340 | parcel_r_int32(&rilp); /* ecio */ | ||
1681 | 341 | parcel_r_int32(&rilp); /* signalNoiseRatio */ | ||
1682 | 342 | |||
1683 | 343 | /* LTE_SignalStrength */ | ||
1684 | 344 | lte_signal = parcel_r_int32(&rilp); | ||
1685 | 345 | parcel_r_int32(&rilp); /* rsrp */ | ||
1686 | 346 | parcel_r_int32(&rilp); /* rsrq */ | ||
1687 | 347 | parcel_r_int32(&rilp); /* rssnr */ | ||
1688 | 348 | parcel_r_int32(&rilp); /* cqi */ | ||
1689 | 349 | |||
1690 | 350 | DBG("RIL SignalStrength - gw: %d, cdma: %d, evdo: %d, lte: %d", | ||
1691 | 351 | gw_signal, cdma_dbm, evdo_dbm, lte_signal); | ||
1692 | 352 | |||
1693 | 353 | /* Return the first valid one */ | ||
1694 | 354 | if ((gw_signal != 99) && (gw_signal != -1)) | ||
1695 | 355 | return (gw_signal * 100) / 31; | ||
1696 | 356 | if ((lte_signal != 99) && (lte_signal != -1)) | ||
1697 | 357 | return (lte_signal * 100) / 31; | ||
1698 | 358 | |||
1699 | 359 | /* In case of dbm, return the value directly */ | ||
1700 | 360 | if (cdma_dbm != -1) { | ||
1701 | 361 | if (cdma_dbm > 100) | ||
1702 | 362 | cdma_dbm = 100; | ||
1703 | 363 | return cdma_dbm; | ||
1704 | 364 | } | ||
1705 | 365 | if (evdo_dbm != -1) { | ||
1706 | 366 | if (evdo_dbm > 100) | ||
1707 | 367 | evdo_dbm = 100; | ||
1708 | 368 | return evdo_dbm; | ||
1709 | 369 | } | ||
1710 | 370 | |||
1711 | 371 | return -1; | ||
1712 | 372 | } | ||
1713 | 0 | 373 | ||
1714 | === added file 'drivers/rilmodem/rilutil.h' | |||
1715 | --- drivers/rilmodem/rilutil.h 1970-01-01 00:00:00 +0000 | |||
1716 | +++ drivers/rilmodem/rilutil.h 2013-04-09 20:01:20 +0000 | |||
1717 | @@ -0,0 +1,125 @@ | |||
1718 | 1 | /* | ||
1719 | 2 | * | ||
1720 | 3 | * oFono - Open Source Telephony | ||
1721 | 4 | * | ||
1722 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
1723 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
1724 | 7 | * | ||
1725 | 8 | * This program is free software; you can redistribute it and/or modify | ||
1726 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
1727 | 10 | * published by the Free Software Foundation. | ||
1728 | 11 | * | ||
1729 | 12 | * This program is distributed in the hope that it will be useful, | ||
1730 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1731 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1732 | 15 | * GNU General Public License for more details. | ||
1733 | 16 | * | ||
1734 | 17 | * You should have received a copy of the GNU General Public License | ||
1735 | 18 | * along with this program; if not, write to the Free Software | ||
1736 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
1737 | 20 | * | ||
1738 | 21 | */ | ||
1739 | 22 | |||
1740 | 23 | enum ril_util_sms_store { | ||
1741 | 24 | RIL_UTIL_SMS_STORE_SM = 0, | ||
1742 | 25 | RIL_UTIL_SMS_STORE_ME = 1, | ||
1743 | 26 | RIL_UTIL_SMS_STORE_MT = 2, | ||
1744 | 27 | RIL_UTIL_SMS_STORE_SR = 3, | ||
1745 | 28 | RIL_UTIL_SMS_STORE_BM = 4, | ||
1746 | 29 | }; | ||
1747 | 30 | |||
1748 | 31 | /* 3GPP TS 27.007 Release 8 Section 5.5 */ | ||
1749 | 32 | enum at_util_charset { | ||
1750 | 33 | RIL_UTIL_CHARSET_GSM = 0x1, | ||
1751 | 34 | RIL_UTIL_CHARSET_HEX = 0x2, | ||
1752 | 35 | RIL_UTIL_CHARSET_IRA = 0x4, | ||
1753 | 36 | RIL_UTIL_CHARSET_PCCP437 = 0x8, | ||
1754 | 37 | RIL_UTIL_CHARSET_PCDN = 0x10, | ||
1755 | 38 | RIL_UTIL_CHARSET_UCS2 = 0x20, | ||
1756 | 39 | RIL_UTIL_CHARSET_UTF8 = 0x40, | ||
1757 | 40 | RIL_UTIL_CHARSET_8859_1 = 0x80, | ||
1758 | 41 | RIL_UTIL_CHARSET_8859_2 = 0x100, | ||
1759 | 42 | RIL_UTIL_CHARSET_8859_3 = 0x200, | ||
1760 | 43 | RIL_UTIL_CHARSET_8859_4 = 0x400, | ||
1761 | 44 | RIL_UTIL_CHARSET_8859_5 = 0x800, | ||
1762 | 45 | RIL_UTIL_CHARSET_8859_6 = 0x1000, | ||
1763 | 46 | RIL_UTIL_CHARSET_8859_C = 0x2000, | ||
1764 | 47 | RIL_UTIL_CHARSET_8859_A = 0x4000, | ||
1765 | 48 | RIL_UTIL_CHARSET_8859_G = 0x8000, | ||
1766 | 49 | RIL_UTIL_CHARSET_8859_H = 0x10000, | ||
1767 | 50 | }; | ||
1768 | 51 | |||
1769 | 52 | typedef void (*ril_util_sim_inserted_cb_t)(gboolean present, void *userdata); | ||
1770 | 53 | |||
1771 | 54 | void decode_ril_error(struct ofono_error *error, const char *final); | ||
1772 | 55 | gint ril_util_call_compare_by_status(gconstpointer a, gconstpointer b); | ||
1773 | 56 | gint ril_util_call_compare_by_phone_number(gconstpointer a, gconstpointer b); | ||
1774 | 57 | gint ril_util_call_compare_by_id(gconstpointer a, gconstpointer b); | ||
1775 | 58 | gint ril_util_call_compare(gconstpointer a, gconstpointer b); | ||
1776 | 59 | |||
1777 | 60 | struct ril_util_sim_state_query *ril_util_sim_state_query_new(GRil *ril, | ||
1778 | 61 | guint interval, guint num_times, | ||
1779 | 62 | ril_util_sim_inserted_cb_t cb, | ||
1780 | 63 | void *userdata, | ||
1781 | 64 | GDestroyNotify destroy); | ||
1782 | 65 | void ril_util_sim_state_query_free(struct ril_util_sim_state_query *req); | ||
1783 | 66 | |||
1784 | 67 | GSList *ril_util_parse_clcc(struct ril_msg *message); | ||
1785 | 68 | |||
1786 | 69 | gboolean ril_util_parse_reg(struct ril_msg *message, int *status, | ||
1787 | 70 | int *lac, int *ci, int *tech); | ||
1788 | 71 | |||
1789 | 72 | gint ril_util_parse_sms_response(struct ril_msg *message); | ||
1790 | 73 | |||
1791 | 74 | gint ril_util_get_signal(struct ril_msg *message); | ||
1792 | 75 | |||
1793 | 76 | struct cb_data { | ||
1794 | 77 | void *cb; | ||
1795 | 78 | void *data; | ||
1796 | 79 | void *user; | ||
1797 | 80 | }; | ||
1798 | 81 | |||
1799 | 82 | static inline struct cb_data *cb_data_new(void *cb, void *data) | ||
1800 | 83 | { | ||
1801 | 84 | struct cb_data *ret; | ||
1802 | 85 | |||
1803 | 86 | ret = g_new0(struct cb_data, 1); | ||
1804 | 87 | ret->cb = cb; | ||
1805 | 88 | ret->data = data; | ||
1806 | 89 | |||
1807 | 90 | return ret; | ||
1808 | 91 | } | ||
1809 | 92 | |||
1810 | 93 | static inline int ril_util_convert_signal_strength(int strength) | ||
1811 | 94 | { | ||
1812 | 95 | int result; | ||
1813 | 96 | |||
1814 | 97 | if (strength == 99) | ||
1815 | 98 | result = -1; | ||
1816 | 99 | else | ||
1817 | 100 | result = (strength * 100) / 31; | ||
1818 | 101 | |||
1819 | 102 | return result; | ||
1820 | 103 | } | ||
1821 | 104 | |||
1822 | 105 | #define DECLARE_FAILURE(e) \ | ||
1823 | 106 | struct ofono_error e; \ | ||
1824 | 107 | e.type = OFONO_ERROR_TYPE_FAILURE; \ | ||
1825 | 108 | e.error = 0 \ | ||
1826 | 109 | |||
1827 | 110 | #define CALLBACK_WITH_FAILURE(cb, args...) \ | ||
1828 | 111 | do { \ | ||
1829 | 112 | struct ofono_error cb_e; \ | ||
1830 | 113 | cb_e.type = OFONO_ERROR_TYPE_FAILURE; \ | ||
1831 | 114 | cb_e.error = 0; \ | ||
1832 | 115 | \ | ||
1833 | 116 | cb(&cb_e, ##args); \ | ||
1834 | 117 | } while (0) \ | ||
1835 | 118 | |||
1836 | 119 | #define CALLBACK_WITH_SUCCESS(f, args...) \ | ||
1837 | 120 | do { \ | ||
1838 | 121 | struct ofono_error e; \ | ||
1839 | 122 | e.type = OFONO_ERROR_TYPE_NO_ERROR; \ | ||
1840 | 123 | e.error = 0; \ | ||
1841 | 124 | f(&e, ##args); \ | ||
1842 | 125 | } while (0) | ||
1843 | 0 | 126 | ||
1844 | === added file 'drivers/rilmodem/sms.c' | |||
1845 | --- drivers/rilmodem/sms.c 1970-01-01 00:00:00 +0000 | |||
1846 | +++ drivers/rilmodem/sms.c 2013-04-09 20:01:20 +0000 | |||
1847 | @@ -0,0 +1,357 @@ | |||
1848 | 1 | /* | ||
1849 | 2 | * | ||
1850 | 3 | * oFono - Open Source Telephony - RIL Modem Support | ||
1851 | 4 | * | ||
1852 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
1853 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
1854 | 7 | * | ||
1855 | 8 | * This program is free software; you can redistribute it and/or modify | ||
1856 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
1857 | 10 | * published by the Free Software Foundation. | ||
1858 | 11 | * | ||
1859 | 12 | * This program is distributed in the hope that it will be useful, | ||
1860 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1861 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1862 | 15 | * GNU General Public License for more details. | ||
1863 | 16 | * | ||
1864 | 17 | * You should have received a copy of the GNU General Public License | ||
1865 | 18 | * along with this program; if not, write to the Free Software | ||
1866 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
1867 | 20 | * | ||
1868 | 21 | */ | ||
1869 | 22 | |||
1870 | 23 | #ifdef HAVE_CONFIG_H | ||
1871 | 24 | #include <config.h> | ||
1872 | 25 | #endif | ||
1873 | 26 | |||
1874 | 27 | #define _GNU_SOURCE | ||
1875 | 28 | #include <ctype.h> | ||
1876 | 29 | #include <string.h> | ||
1877 | 30 | #include <stdlib.h> | ||
1878 | 31 | #include <stdio.h> | ||
1879 | 32 | |||
1880 | 33 | #include <glib.h> | ||
1881 | 34 | #include <gril.h> | ||
1882 | 35 | #include <parcel.h> | ||
1883 | 36 | |||
1884 | 37 | #include <ofono/log.h> | ||
1885 | 38 | #include <ofono/modem.h> | ||
1886 | 39 | #include <ofono/sms.h> | ||
1887 | 40 | #include "smsutil.h" | ||
1888 | 41 | #include "util.h" | ||
1889 | 42 | |||
1890 | 43 | #include "rilmodem.h" | ||
1891 | 44 | |||
1892 | 45 | struct sms_data { | ||
1893 | 46 | GRil *ril; | ||
1894 | 47 | unsigned int vendor; | ||
1895 | 48 | }; | ||
1896 | 49 | |||
1897 | 50 | static void sms_debug(const gchar *str, gpointer user_data) | ||
1898 | 51 | { | ||
1899 | 52 | const char *prefix = user_data; | ||
1900 | 53 | |||
1901 | 54 | ofono_info("%s%s", prefix, str); | ||
1902 | 55 | } | ||
1903 | 56 | |||
1904 | 57 | static void ril_csca_set(struct ofono_sms *sms, | ||
1905 | 58 | const struct ofono_phone_number *sca, | ||
1906 | 59 | ofono_sms_sca_set_cb_t cb, void *user_data) | ||
1907 | 60 | { | ||
1908 | 61 | /* TODO: | ||
1909 | 62 | * | ||
1910 | 63 | * (1) Need to determine if RIL supports setting the | ||
1911 | 64 | * SMSC number. | ||
1912 | 65 | * | ||
1913 | 66 | * (2) In the short term, this function should return | ||
1914 | 67 | * a 'not-supported' error. | ||
1915 | 68 | */ | ||
1916 | 69 | |||
1917 | 70 | DBG(""); | ||
1918 | 71 | |||
1919 | 72 | CALLBACK_WITH_FAILURE(cb, user_data); | ||
1920 | 73 | } | ||
1921 | 74 | |||
1922 | 75 | static void ril_csca_query_cb(gboolean ok, gpointer user_data) | ||
1923 | 76 | { | ||
1924 | 77 | struct cb_data *cbd = user_data; | ||
1925 | 78 | ofono_sms_sca_query_cb_t cb = cbd->cb; | ||
1926 | 79 | struct ofono_error error; | ||
1927 | 80 | struct ofono_phone_number sca; | ||
1928 | 81 | |||
1929 | 82 | /* For now setup dummy number */ | ||
1930 | 83 | const char *number = "6176666666"; | ||
1931 | 84 | |||
1932 | 85 | if (number[0] == '+') { | ||
1933 | 86 | number = number + 1; | ||
1934 | 87 | sca.type = 145; | ||
1935 | 88 | } else { | ||
1936 | 89 | sca.type = 129; | ||
1937 | 90 | } | ||
1938 | 91 | |||
1939 | 92 | strncpy(sca.number, number, OFONO_MAX_PHONE_NUMBER_LENGTH); | ||
1940 | 93 | sca.number[OFONO_MAX_PHONE_NUMBER_LENGTH] = '\0'; | ||
1941 | 94 | |||
1942 | 95 | DBG("csca_query_cb: %s, %d", sca.number, sca.type); | ||
1943 | 96 | |||
1944 | 97 | cb(&error, &sca, cbd->data); | ||
1945 | 98 | |||
1946 | 99 | return; | ||
1947 | 100 | } | ||
1948 | 101 | |||
1949 | 102 | static void ril_csca_query(struct ofono_sms *sms, ofono_sms_sca_query_cb_t cb, | ||
1950 | 103 | void *user_data) | ||
1951 | 104 | { | ||
1952 | 105 | /* TODO: | ||
1953 | 106 | * | ||
1954 | 107 | * (1) Need to determine if RIL supports querying the | ||
1955 | 108 | * SMSC number. | ||
1956 | 109 | * | ||
1957 | 110 | * (2) In the short term, this function should return | ||
1958 | 111 | * a 'not-supported' error. | ||
1959 | 112 | */ | ||
1960 | 113 | |||
1961 | 114 | CALLBACK_WITH_FAILURE(cb, NULL, user_data); | ||
1962 | 115 | } | ||
1963 | 116 | |||
1964 | 117 | static void submit_sms_cb(struct ril_msg *message, gpointer user_data) | ||
1965 | 118 | { | ||
1966 | 119 | struct cb_data *cbd = user_data; | ||
1967 | 120 | struct ofono_error error; | ||
1968 | 121 | ofono_sms_submit_cb_t cb = cbd->cb; | ||
1969 | 122 | int mr; | ||
1970 | 123 | |||
1971 | 124 | if (message->error == RIL_E_SUCCESS) { | ||
1972 | 125 | decode_ril_error(&error, "OK"); | ||
1973 | 126 | } else { | ||
1974 | 127 | decode_ril_error(&error, "FAIL"); | ||
1975 | 128 | } | ||
1976 | 129 | |||
1977 | 130 | mr = ril_util_parse_sms_response(message); | ||
1978 | 131 | |||
1979 | 132 | cb(&error, mr, cbd->data); | ||
1980 | 133 | } | ||
1981 | 134 | |||
1982 | 135 | static void ril_cmgs(struct ofono_sms *sms, const unsigned char *pdu, | ||
1983 | 136 | int pdu_len, int tpdu_len, int mms, | ||
1984 | 137 | ofono_sms_submit_cb_t cb, void *user_data) | ||
1985 | 138 | { | ||
1986 | 139 | struct sms_data *data = ofono_sms_get_data(sms); | ||
1987 | 140 | struct cb_data *cbd = cb_data_new(cb, user_data); | ||
1988 | 141 | struct parcel rilp; | ||
1989 | 142 | char *tpdu; | ||
1990 | 143 | int ret, smsc_len; | ||
1991 | 144 | |||
1992 | 145 | DBG("pdu_len: %d, tpdu_len: %d mms: %d", pdu_len, tpdu_len, mms); | ||
1993 | 146 | g_ril_util_debug_hexdump(FALSE, pdu, pdu_len, sms_debug, "sms-pdu: "); | ||
1994 | 147 | |||
1995 | 148 | /* TODO: if (mms) { ... } */ | ||
1996 | 149 | |||
1997 | 150 | parcel_init(&rilp); | ||
1998 | 151 | parcel_w_int32(&rilp, 2); /* Number of strings */ | ||
1999 | 152 | |||
2000 | 153 | /* SMSC address: | ||
2001 | 154 | * | ||
2002 | 155 | * smsc_len == 1, then zero-length SMSC was spec'd | ||
2003 | 156 | * RILD expects a NULL string in this case instead | ||
2004 | 157 | * of a zero-length string. | ||
2005 | 158 | */ | ||
2006 | 159 | smsc_len = pdu_len - tpdu_len; | ||
2007 | 160 | if (smsc_len > 1) { | ||
2008 | 161 | /* TODO: encode SMSC & write to parcel */ | ||
2009 | 162 | DBG("SMSC address specified (smsc_len %d); NOT-IMPLEMENTED", smsc_len); | ||
2010 | 163 | } | ||
2011 | 164 | |||
2012 | 165 | parcel_w_string(&rilp, NULL); /* SMSC address; NULL == default */ | ||
2013 | 166 | |||
2014 | 167 | /* TPDU: | ||
2015 | 168 | * | ||
2016 | 169 | * 'pdu' is a raw hexadecimal string | ||
2017 | 170 | * encode_hex() turns it into an ASCII/hex UTF8 buffer | ||
2018 | 171 | * parcel_w_string() encodes utf8 -> utf16 | ||
2019 | 172 | */ | ||
2020 | 173 | tpdu = encode_hex(pdu + smsc_len, tpdu_len, 0); | ||
2021 | 174 | g_ril_util_debug_hexdump(FALSE, (guchar *) tpdu, (tpdu_len * 2), | ||
2022 | 175 | sms_debug, "tpdu: "); | ||
2023 | 176 | |||
2024 | 177 | parcel_w_string(&rilp, tpdu); | ||
2025 | 178 | |||
2026 | 179 | /* Dump the entire parcel */ | ||
2027 | 180 | g_ril_util_debug_hexdump(FALSE, (guchar *) rilp.data, rilp.size, | ||
2028 | 181 | sms_debug, "sms-encoded-buf: "); | ||
2029 | 182 | ret = g_ril_send(data->ril, | ||
2030 | 183 | RIL_REQUEST_SEND_SMS, | ||
2031 | 184 | rilp.data, | ||
2032 | 185 | rilp.size, | ||
2033 | 186 | submit_sms_cb, cbd, g_free); | ||
2034 | 187 | |||
2035 | 188 | parcel_free(&rilp); | ||
2036 | 189 | |||
2037 | 190 | if (ret <= 0) { | ||
2038 | 191 | g_free(cbd); | ||
2039 | 192 | CALLBACK_WITH_FAILURE(cb, -1, data); | ||
2040 | 193 | } | ||
2041 | 194 | } | ||
2042 | 195 | |||
2043 | 196 | static void ril_cgsms_set(struct ofono_sms *sms, int bearer, | ||
2044 | 197 | ofono_sms_bearer_set_cb_t cb, void *user_data) | ||
2045 | 198 | { | ||
2046 | 199 | /* TODO: same as csca_set */ | ||
2047 | 200 | DBG(""); | ||
2048 | 201 | |||
2049 | 202 | CALLBACK_WITH_FAILURE(cb, user_data); | ||
2050 | 203 | } | ||
2051 | 204 | |||
2052 | 205 | static void ril_cgsms_query(struct ofono_sms *sms, | ||
2053 | 206 | ofono_sms_bearer_query_cb_t cb, void *user_data) | ||
2054 | 207 | { | ||
2055 | 208 | /* TODO: same as csca_query */ | ||
2056 | 209 | DBG(""); | ||
2057 | 210 | |||
2058 | 211 | CALLBACK_WITH_FAILURE(cb, -1, user_data); | ||
2059 | 212 | } | ||
2060 | 213 | |||
2061 | 214 | static void ril_sms_notify(struct ril_msg *message, gpointer user_data) | ||
2062 | 215 | { | ||
2063 | 216 | struct ofono_sms *sms = user_data; | ||
2064 | 217 | struct sms_data *data = ofono_sms_get_data(sms); | ||
2065 | 218 | struct parcel rilp; | ||
2066 | 219 | char *ril_pdu; | ||
2067 | 220 | int ril_pdu_len; | ||
2068 | 221 | long ril_buf_len; | ||
2069 | 222 | guchar *ril_data; | ||
2070 | 223 | |||
2071 | 224 | DBG("req: %d; data_len: %d", message->req, message->buf_len); | ||
2072 | 225 | |||
2073 | 226 | if (message->req != RIL_UNSOL_RESPONSE_NEW_SMS) | ||
2074 | 227 | goto error; | ||
2075 | 228 | |||
2076 | 229 | /* Set up Parcel struct for proper parsing */ | ||
2077 | 230 | rilp.data = message->buf; | ||
2078 | 231 | rilp.size = message->buf_len; | ||
2079 | 232 | rilp.capacity = message->buf_len; | ||
2080 | 233 | rilp.offset = 0; | ||
2081 | 234 | |||
2082 | 235 | g_ril_util_debug_hexdump(FALSE, (guchar *) message->buf, | ||
2083 | 236 | message->buf_len, sms_debug, "sms-notify: "); | ||
2084 | 237 | |||
2085 | 238 | ril_pdu = parcel_r_string(&rilp); | ||
2086 | 239 | if (ril_pdu == NULL) | ||
2087 | 240 | goto error; | ||
2088 | 241 | |||
2089 | 242 | ril_pdu_len = strlen(ril_pdu); | ||
2090 | 243 | |||
2091 | 244 | DBG("ril_pdu_len is %d", ril_pdu_len); | ||
2092 | 245 | ril_data = decode_hex(ril_pdu, ril_pdu_len, &ril_buf_len, -1); | ||
2093 | 246 | if (ril_data == NULL) | ||
2094 | 247 | goto error; | ||
2095 | 248 | |||
2096 | 249 | g_ril_util_debug_hexdump(FALSE, ril_data, | ||
2097 | 250 | ril_buf_len, | ||
2098 | 251 | sms_debug, | ||
2099 | 252 | "sms-notify-decoded: "); | ||
2100 | 253 | |||
2101 | 254 | /* Last parameter is 'tpdu_len' ( substract SMSC length ) */ | ||
2102 | 255 | ofono_sms_deliver_notify(sms, ril_data, | ||
2103 | 256 | ril_buf_len, | ||
2104 | 257 | ril_buf_len - 8); | ||
2105 | 258 | |||
2106 | 259 | /* Re-use rilp, so initilize */ | ||
2107 | 260 | parcel_init(&rilp); | ||
2108 | 261 | parcel_w_int32(&rilp, 2); /* Number of int32 values in array */ | ||
2109 | 262 | parcel_w_int32(&rilp, 1); /* Successful receipt */ | ||
2110 | 263 | parcel_w_int32(&rilp, 0); /* error code */ | ||
2111 | 264 | |||
2112 | 265 | /* TODO: should ACK be sent for either of the error cases? */ | ||
2113 | 266 | |||
2114 | 267 | /* ACK the incoming NEW_SMS; ignore response so no cb needed */ | ||
2115 | 268 | g_ril_send(data->ril, RIL_REQUEST_SMS_ACKNOWLEDGE, | ||
2116 | 269 | rilp.data, | ||
2117 | 270 | rilp.size, | ||
2118 | 271 | NULL, NULL, NULL); | ||
2119 | 272 | |||
2120 | 273 | parcel_free(&rilp); | ||
2121 | 274 | return; | ||
2122 | 275 | |||
2123 | 276 | error: | ||
2124 | 277 | ofono_error("Unable to parse NEW_SMS notification"); | ||
2125 | 278 | } | ||
2126 | 279 | |||
2127 | 280 | static gboolean ril_delayed_register(gpointer user_data) | ||
2128 | 281 | { | ||
2129 | 282 | struct ofono_sms *sms = user_data; | ||
2130 | 283 | struct sms_data *data = ofono_sms_get_data(sms); | ||
2131 | 284 | |||
2132 | 285 | DBG(""); | ||
2133 | 286 | ofono_sms_register(sms); | ||
2134 | 287 | |||
2135 | 288 | /* register to receive INCOMING_SMS */ | ||
2136 | 289 | g_ril_register(data->ril, RIL_UNSOL_RESPONSE_NEW_SMS, | ||
2137 | 290 | ril_sms_notify, sms); | ||
2138 | 291 | |||
2139 | 292 | DBG("registered NEW_SMS callback"); | ||
2140 | 293 | |||
2141 | 294 | /* This makes the timeout a single-shot */ | ||
2142 | 295 | return FALSE; | ||
2143 | 296 | } | ||
2144 | 297 | |||
2145 | 298 | static int ril_sms_probe(struct ofono_sms *sms, unsigned int vendor, | ||
2146 | 299 | void *user) | ||
2147 | 300 | { | ||
2148 | 301 | GRil *ril = user; | ||
2149 | 302 | struct sms_data *data; | ||
2150 | 303 | |||
2151 | 304 | DBG(""); | ||
2152 | 305 | |||
2153 | 306 | data = g_new0(struct sms_data, 1); | ||
2154 | 307 | data->ril = g_ril_clone(ril); | ||
2155 | 308 | data->vendor = vendor; | ||
2156 | 309 | |||
2157 | 310 | ofono_sms_set_data(sms, data); | ||
2158 | 311 | |||
2159 | 312 | /* ofono_devinfo_register() needs to be called after | ||
2160 | 313 | * the driver has been set in devinfo_create() which | ||
2161 | 314 | * calls this function. Most other drivers use a | ||
2162 | 315 | * callback after getting some return from the modem | ||
2163 | 316 | * itself... | ||
2164 | 317 | */ | ||
2165 | 318 | g_timeout_add_seconds(2, ril_delayed_register, sms); | ||
2166 | 319 | |||
2167 | 320 | return 0; | ||
2168 | 321 | } | ||
2169 | 322 | |||
2170 | 323 | static void ril_sms_remove(struct ofono_sms *sms) | ||
2171 | 324 | { | ||
2172 | 325 | struct sms_data *data = ofono_sms_get_data(sms); | ||
2173 | 326 | |||
2174 | 327 | DBG(""); | ||
2175 | 328 | |||
2176 | 329 | g_ril_unref(data->ril); | ||
2177 | 330 | g_free(data); | ||
2178 | 331 | |||
2179 | 332 | ofono_sms_set_data(sms, NULL); | ||
2180 | 333 | } | ||
2181 | 334 | |||
2182 | 335 | static struct ofono_sms_driver driver = { | ||
2183 | 336 | .name = "rilmodem", | ||
2184 | 337 | .probe = ril_sms_probe, | ||
2185 | 338 | .remove = ril_sms_remove, | ||
2186 | 339 | .sca_query = ril_csca_query, | ||
2187 | 340 | .sca_set = ril_csca_set, | ||
2188 | 341 | .submit = ril_cmgs, | ||
2189 | 342 | .bearer_query = NULL, /* FIXME: needs investigation. */ | ||
2190 | 343 | .bearer_set = NULL, | ||
2191 | 344 | }; | ||
2192 | 345 | |||
2193 | 346 | void ril_sms_init(void) | ||
2194 | 347 | { | ||
2195 | 348 | DBG(""); | ||
2196 | 349 | if (ofono_sms_driver_register(&driver)) | ||
2197 | 350 | DBG("ofono_sms_driver_register failed!"); | ||
2198 | 351 | } | ||
2199 | 352 | |||
2200 | 353 | void ril_sms_exit(void) | ||
2201 | 354 | { | ||
2202 | 355 | DBG(""); | ||
2203 | 356 | ofono_sms_driver_unregister(&driver); | ||
2204 | 357 | } | ||
2205 | 0 | 358 | ||
2206 | === added file 'drivers/rilmodem/voicecall.c' | |||
2207 | --- drivers/rilmodem/voicecall.c 1970-01-01 00:00:00 +0000 | |||
2208 | +++ drivers/rilmodem/voicecall.c 2013-04-09 20:01:20 +0000 | |||
2209 | @@ -0,0 +1,537 @@ | |||
2210 | 1 | /* | ||
2211 | 2 | * | ||
2212 | 3 | * oFono - Open Source Telephony | ||
2213 | 4 | * | ||
2214 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
2215 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
2216 | 7 | * | ||
2217 | 8 | * This program is free software; you can redistribute it and/or modify | ||
2218 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
2219 | 10 | * published by the Free Software Foundation. | ||
2220 | 11 | * | ||
2221 | 12 | * This program is distributed in the hope that it will be useful, | ||
2222 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2223 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2224 | 15 | * GNU General Public License for more details. | ||
2225 | 16 | * | ||
2226 | 17 | * You should have received a copy of the GNU General Public License | ||
2227 | 18 | * along with this program; if not, write to the Free Software | ||
2228 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
2229 | 20 | * | ||
2230 | 21 | */ | ||
2231 | 22 | |||
2232 | 23 | #ifdef HAVE_CONFIG_H | ||
2233 | 24 | #include <config.h> | ||
2234 | 25 | #endif | ||
2235 | 26 | |||
2236 | 27 | #define _GNU_SOURCE | ||
2237 | 28 | #include <string.h> | ||
2238 | 29 | #include <stdlib.h> | ||
2239 | 30 | #include <stdio.h> | ||
2240 | 31 | #include <errno.h> | ||
2241 | 32 | |||
2242 | 33 | #include <glib.h> | ||
2243 | 34 | |||
2244 | 35 | /* For AudioFlinger settings */ | ||
2245 | 36 | #include <waudio.h> | ||
2246 | 37 | |||
2247 | 38 | #include <ofono/log.h> | ||
2248 | 39 | #include <ofono/modem.h> | ||
2249 | 40 | #include <ofono/voicecall.h> | ||
2250 | 41 | |||
2251 | 42 | #include "gril.h" | ||
2252 | 43 | #include "grilutil.h" | ||
2253 | 44 | |||
2254 | 45 | #include "common.h" | ||
2255 | 46 | |||
2256 | 47 | #include "rilmodem.h" | ||
2257 | 48 | #include "parcel.h" | ||
2258 | 49 | |||
2259 | 50 | /* Amount of ms we wait between CLCC calls */ | ||
2260 | 51 | #define POLL_CLCC_INTERVAL 300 | ||
2261 | 52 | |||
2262 | 53 | /* When +VTD returns 0, an unspecified manufacturer-specific delay is used */ | ||
2263 | 54 | #define TONE_DURATION 1000 | ||
2264 | 55 | |||
2265 | 56 | #define FLAG_NEED_CLIP 1 | ||
2266 | 57 | |||
2267 | 58 | struct voicecall_data { | ||
2268 | 59 | GSList *calls; | ||
2269 | 60 | unsigned int local_release; | ||
2270 | 61 | unsigned int clcc_source; | ||
2271 | 62 | GRil *ril; | ||
2272 | 63 | unsigned int vendor; | ||
2273 | 64 | unsigned int tone_duration; | ||
2274 | 65 | guint vts_source; | ||
2275 | 66 | unsigned int vts_delay; | ||
2276 | 67 | unsigned char flags; | ||
2277 | 68 | }; | ||
2278 | 69 | |||
2279 | 70 | struct release_id_req { | ||
2280 | 71 | struct ofono_voicecall *vc; | ||
2281 | 72 | ofono_voicecall_cb_t cb; | ||
2282 | 73 | void *data; | ||
2283 | 74 | int id; | ||
2284 | 75 | }; | ||
2285 | 76 | |||
2286 | 77 | struct change_state_req { | ||
2287 | 78 | struct ofono_voicecall *vc; | ||
2288 | 79 | ofono_voicecall_cb_t cb; | ||
2289 | 80 | void *data; | ||
2290 | 81 | int affected_types; | ||
2291 | 82 | }; | ||
2292 | 83 | |||
2293 | 84 | static void audioflinger_set_call_mode() | ||
2294 | 85 | { | ||
2295 | 86 | char parameter[20]; | ||
2296 | 87 | int i; | ||
2297 | 88 | |||
2298 | 89 | /* Set the call mode in AudioFlinger */ | ||
2299 | 90 | DBG("Setting AudioFlinger to call state"); | ||
2300 | 91 | AudioSystem_setMode(AUDIO_MODE_IN_CALL); | ||
2301 | 92 | |||
2302 | 93 | DBG("Setting sound route to earpiece"); | ||
2303 | 94 | sprintf(parameter, "routing=%d", AUDIO_DEVICE_OUT_EARPIECE); | ||
2304 | 95 | |||
2305 | 96 | /* Try the first 3 threads, as this is not fixed and there's no easy | ||
2306 | 97 | * way to retrieve the default thread/output from Android */ | ||
2307 | 98 | for (i = 1; i <= 3; i++) { | ||
2308 | 99 | if (AudioSystem_setParameters(i, parameter) >= 0) | ||
2309 | 100 | break; | ||
2310 | 101 | } | ||
2311 | 102 | } | ||
2312 | 103 | |||
2313 | 104 | static void audioflinger_set_normal_mode() | ||
2314 | 105 | { | ||
2315 | 106 | char parameter[20]; | ||
2316 | 107 | int i; | ||
2317 | 108 | |||
2318 | 109 | DBG("Setting AudioFlinger to normal mode"); | ||
2319 | 110 | AudioSystem_setMode(AUDIO_MODE_NORMAL); | ||
2320 | 111 | |||
2321 | 112 | DBG("Setting sound route back to speaker"); | ||
2322 | 113 | |||
2323 | 114 | /* Get device back to speaker mode, as by default in_call | ||
2324 | 115 | * mode sets up device out to earpiece */ | ||
2325 | 116 | sprintf(parameter, "routing=%d", AUDIO_DEVICE_OUT_SPEAKER); | ||
2326 | 117 | |||
2327 | 118 | /* Try the first 3 threads, as this is not fixed and there's no easy | ||
2328 | 119 | * way to retrieve the default thread/output from Android */ | ||
2329 | 120 | for (i = 1; i <= 3; i++) { | ||
2330 | 121 | if (AudioSystem_setParameters(i, parameter) >= 0) | ||
2331 | 122 | break; | ||
2332 | 123 | } | ||
2333 | 124 | } | ||
2334 | 125 | |||
2335 | 126 | static void clcc_poll_cb(struct ril_msg *message, gpointer user_data) | ||
2336 | 127 | { | ||
2337 | 128 | struct ofono_voicecall *vc = user_data; | ||
2338 | 129 | struct voicecall_data *vd = ofono_voicecall_get_data(vc); | ||
2339 | 130 | GSList *calls; | ||
2340 | 131 | GSList *n, *o; | ||
2341 | 132 | struct ofono_call *nc, *oc; | ||
2342 | 133 | |||
2343 | 134 | if (message->error != RIL_E_SUCCESS) { | ||
2344 | 135 | ofono_error("We are polling CLCC and received an error"); | ||
2345 | 136 | ofono_error("All bets are off for call management"); | ||
2346 | 137 | return; | ||
2347 | 138 | } | ||
2348 | 139 | |||
2349 | 140 | calls = ril_util_parse_clcc(message); | ||
2350 | 141 | |||
2351 | 142 | n = calls; | ||
2352 | 143 | o = vd->calls; | ||
2353 | 144 | |||
2354 | 145 | while (n || o) { | ||
2355 | 146 | nc = n ? n->data : NULL; | ||
2356 | 147 | oc = o ? o->data : NULL; | ||
2357 | 148 | |||
2358 | 149 | if (oc && (nc == NULL || (nc->id > oc->id))) { | ||
2359 | 150 | enum ofono_disconnect_reason reason; | ||
2360 | 151 | |||
2361 | 152 | if (vd->local_release & (1 << oc->id)) | ||
2362 | 153 | reason = OFONO_DISCONNECT_REASON_LOCAL_HANGUP; | ||
2363 | 154 | else | ||
2364 | 155 | reason = OFONO_DISCONNECT_REASON_REMOTE_HANGUP; | ||
2365 | 156 | |||
2366 | 157 | if (oc->type) | ||
2367 | 158 | ofono_voicecall_disconnected(vc, oc->id, | ||
2368 | 159 | reason, NULL); | ||
2369 | 160 | |||
2370 | 161 | o = o->next; | ||
2371 | 162 | } else if (nc && (oc == NULL || (nc->id < oc->id))) { | ||
2372 | 163 | /* new call, signal it */ | ||
2373 | 164 | if (nc->type) | ||
2374 | 165 | ofono_voicecall_notify(vc, nc); | ||
2375 | 166 | |||
2376 | 167 | n = n->next; | ||
2377 | 168 | } else { | ||
2378 | 169 | /* | ||
2379 | 170 | * Always use the clip_validity from old call | ||
2380 | 171 | * the only place this is truly told to us is | ||
2381 | 172 | * in the CLIP notify, the rest are fudged | ||
2382 | 173 | * anyway. Useful when RING, CLIP is used, | ||
2383 | 174 | * and we're forced to use CLCC and clip_validity | ||
2384 | 175 | * is 1 | ||
2385 | 176 | */ | ||
2386 | 177 | if (oc->clip_validity == 1) | ||
2387 | 178 | nc->clip_validity = oc->clip_validity; | ||
2388 | 179 | |||
2389 | 180 | nc->cnap_validity = oc->cnap_validity; | ||
2390 | 181 | |||
2391 | 182 | /* | ||
2392 | 183 | * CDIP doesn't arrive as part of CLCC, always | ||
2393 | 184 | * re-use from the old call | ||
2394 | 185 | */ | ||
2395 | 186 | memcpy(&nc->called_number, &oc->called_number, | ||
2396 | 187 | sizeof(oc->called_number)); | ||
2397 | 188 | |||
2398 | 189 | /* | ||
2399 | 190 | * If the CLIP is not provided and the CLIP never | ||
2400 | 191 | * arrives, or RING is used, then signal the call | ||
2401 | 192 | * here | ||
2402 | 193 | */ | ||
2403 | 194 | if (nc->status == CALL_STATUS_INCOMING && | ||
2404 | 195 | (vd->flags & FLAG_NEED_CLIP)) { | ||
2405 | 196 | if (nc->type) | ||
2406 | 197 | ofono_voicecall_notify(vc, nc); | ||
2407 | 198 | |||
2408 | 199 | vd->flags &= ~FLAG_NEED_CLIP; | ||
2409 | 200 | } else if (memcmp(nc, oc, sizeof(*nc)) && nc->type) | ||
2410 | 201 | ofono_voicecall_notify(vc, nc); | ||
2411 | 202 | |||
2412 | 203 | n = n->next; | ||
2413 | 204 | o = o->next; | ||
2414 | 205 | } | ||
2415 | 206 | } | ||
2416 | 207 | |||
2417 | 208 | /* No other calls, get audioflinger into normal state */ | ||
2418 | 209 | if (vd->calls && !calls) { | ||
2419 | 210 | audioflinger_set_normal_mode(); | ||
2420 | 211 | } | ||
2421 | 212 | |||
2422 | 213 | g_slist_foreach(vd->calls, (GFunc) g_free, NULL); | ||
2423 | 214 | g_slist_free(vd->calls); | ||
2424 | 215 | |||
2425 | 216 | vd->calls = calls; | ||
2426 | 217 | vd->local_release = 0; | ||
2427 | 218 | } | ||
2428 | 219 | |||
2429 | 220 | static gboolean poll_clcc(gpointer user_data) | ||
2430 | 221 | { | ||
2431 | 222 | struct ofono_voicecall *vc = user_data; | ||
2432 | 223 | struct voicecall_data *vd = ofono_voicecall_get_data(vc); | ||
2433 | 224 | |||
2434 | 225 | g_ril_send(vd->ril, RIL_REQUEST_GET_CURRENT_CALLS, NULL, | ||
2435 | 226 | 0, clcc_poll_cb, vc, NULL); | ||
2436 | 227 | |||
2437 | 228 | vd->clcc_source = 0; | ||
2438 | 229 | |||
2439 | 230 | return FALSE; | ||
2440 | 231 | } | ||
2441 | 232 | |||
2442 | 233 | static void generic_cb(struct ril_msg *message, gpointer user_data) | ||
2443 | 234 | { | ||
2444 | 235 | struct change_state_req *req = user_data; | ||
2445 | 236 | struct voicecall_data *vd = ofono_voicecall_get_data(req->vc); | ||
2446 | 237 | struct ofono_error error; | ||
2447 | 238 | |||
2448 | 239 | if (message->error == RIL_E_SUCCESS) { | ||
2449 | 240 | decode_ril_error(&error, "OK"); | ||
2450 | 241 | } else { | ||
2451 | 242 | decode_ril_error(&error, "FAIL"); | ||
2452 | 243 | goto out; | ||
2453 | 244 | } | ||
2454 | 245 | |||
2455 | 246 | if (req->affected_types) { | ||
2456 | 247 | GSList *l; | ||
2457 | 248 | struct ofono_call *call; | ||
2458 | 249 | |||
2459 | 250 | for (l = vd->calls; l; l = l->next) { | ||
2460 | 251 | call = l->data; | ||
2461 | 252 | |||
2462 | 253 | if (req->affected_types & (1 << call->status)) | ||
2463 | 254 | vd->local_release |= (1 << call->id); | ||
2464 | 255 | } | ||
2465 | 256 | } | ||
2466 | 257 | |||
2467 | 258 | out: | ||
2468 | 259 | g_ril_send(vd->ril, RIL_REQUEST_GET_CURRENT_CALLS, NULL, | ||
2469 | 260 | 0, clcc_poll_cb, req->vc, NULL); | ||
2470 | 261 | |||
2471 | 262 | /* We have to callback after we schedule a poll if required */ | ||
2472 | 263 | if (req->cb) | ||
2473 | 264 | req->cb(&error, req->data); | ||
2474 | 265 | } | ||
2475 | 266 | |||
2476 | 267 | static void ril_template(const guint rreq, struct ofono_voicecall *vc, | ||
2477 | 268 | GRilResponseFunc func, unsigned int affected_types, | ||
2478 | 269 | gpointer pdata, const gsize psize, | ||
2479 | 270 | ofono_voicecall_cb_t cb, void *data) | ||
2480 | 271 | { | ||
2481 | 272 | struct voicecall_data *vd = ofono_voicecall_get_data(vc); | ||
2482 | 273 | struct change_state_req *req = g_try_new0(struct change_state_req, 1); | ||
2483 | 274 | |||
2484 | 275 | if (req == NULL) | ||
2485 | 276 | goto error; | ||
2486 | 277 | |||
2487 | 278 | req->vc = vc; | ||
2488 | 279 | req->cb = cb; | ||
2489 | 280 | req->data = data; | ||
2490 | 281 | req->affected_types = affected_types; | ||
2491 | 282 | |||
2492 | 283 | if (g_ril_send(vd->ril, rreq, pdata, psize, func, req, g_free) > 0) | ||
2493 | 284 | return; | ||
2494 | 285 | |||
2495 | 286 | error: | ||
2496 | 287 | g_free(req); | ||
2497 | 288 | |||
2498 | 289 | if (cb) | ||
2499 | 290 | CALLBACK_WITH_FAILURE(cb, data); | ||
2500 | 291 | } | ||
2501 | 292 | |||
2502 | 293 | static void rild_cb(struct ril_msg *message, gpointer user_data) | ||
2503 | 294 | { | ||
2504 | 295 | struct cb_data *cbd = user_data; | ||
2505 | 296 | struct ofono_voicecall *vc = cbd->user; | ||
2506 | 297 | struct voicecall_data *vd = ofono_voicecall_get_data(vc); | ||
2507 | 298 | ofono_voicecall_cb_t cb = cbd->cb; | ||
2508 | 299 | struct ofono_error error; | ||
2509 | 300 | struct ofono_call *call; | ||
2510 | 301 | GSList *l; | ||
2511 | 302 | |||
2512 | 303 | if (message->error == RIL_E_SUCCESS) { | ||
2513 | 304 | decode_ril_error(&error, "OK"); | ||
2514 | 305 | } else { | ||
2515 | 306 | decode_ril_error(&error, "FAIL"); | ||
2516 | 307 | goto out; | ||
2517 | 308 | } | ||
2518 | 309 | |||
2519 | 310 | /* On a success, make sure to put all active calls on hold */ | ||
2520 | 311 | for (l = vd->calls; l; l = l->next) { | ||
2521 | 312 | call = l->data; | ||
2522 | 313 | |||
2523 | 314 | if (call->status != CALL_STATUS_ACTIVE) | ||
2524 | 315 | continue; | ||
2525 | 316 | |||
2526 | 317 | call->status = CALL_STATUS_HELD; | ||
2527 | 318 | ofono_voicecall_notify(vc, call); | ||
2528 | 319 | } | ||
2529 | 320 | |||
2530 | 321 | /* CLCC will update the oFono call list with proper ids */ | ||
2531 | 322 | if (!vd->clcc_source) | ||
2532 | 323 | vd->clcc_source = g_timeout_add(POLL_CLCC_INTERVAL, | ||
2533 | 324 | poll_clcc, vc); | ||
2534 | 325 | |||
2535 | 326 | audioflinger_set_call_mode(); | ||
2536 | 327 | |||
2537 | 328 | out: | ||
2538 | 329 | cb(&error, cbd->data); | ||
2539 | 330 | } | ||
2540 | 331 | |||
2541 | 332 | static void ril_dial(struct ofono_voicecall *vc, | ||
2542 | 333 | const struct ofono_phone_number *ph, | ||
2543 | 334 | enum ofono_clir_option clir, ofono_voicecall_cb_t cb, | ||
2544 | 335 | void *data) | ||
2545 | 336 | { | ||
2546 | 337 | struct voicecall_data *vd = ofono_voicecall_get_data(vc); | ||
2547 | 338 | struct cb_data *cbd = cb_data_new(cb, data); | ||
2548 | 339 | struct parcel rilp; | ||
2549 | 340 | int ret; | ||
2550 | 341 | |||
2551 | 342 | cbd->user = vc; | ||
2552 | 343 | |||
2553 | 344 | parcel_init(&rilp); | ||
2554 | 345 | |||
2555 | 346 | /* Number to dial */ | ||
2556 | 347 | parcel_w_string(&rilp, phone_number_to_string(ph)); | ||
2557 | 348 | /* CLIR mode */ | ||
2558 | 349 | parcel_w_int32(&rilp, clir); | ||
2559 | 350 | /* USS, need it twice for absent */ | ||
2560 | 351 | /* TODO: Deal with USS properly */ | ||
2561 | 352 | parcel_w_int32(&rilp, 0); | ||
2562 | 353 | parcel_w_int32(&rilp, 0); | ||
2563 | 354 | |||
2564 | 355 | /* Send request to RIL */ | ||
2565 | 356 | ret = g_ril_send(vd->ril, RIL_REQUEST_DIAL, rilp.data, | ||
2566 | 357 | rilp.size, rild_cb, cbd, g_free); | ||
2567 | 358 | parcel_free(&rilp); | ||
2568 | 359 | |||
2569 | 360 | /* In case of error free cbd and return the cb with failure */ | ||
2570 | 361 | if (ret <= 0) { | ||
2571 | 362 | g_free(cbd); | ||
2572 | 363 | CALLBACK_WITH_FAILURE(cb, data); | ||
2573 | 364 | } | ||
2574 | 365 | } | ||
2575 | 366 | |||
2576 | 367 | static void ril_hangup_all(struct ofono_voicecall *vc, | ||
2577 | 368 | ofono_voicecall_cb_t cb, void *data) | ||
2578 | 369 | { | ||
2579 | 370 | struct voicecall_data *vd = ofono_voicecall_get_data(vc); | ||
2580 | 371 | struct parcel rilp; | ||
2581 | 372 | struct ofono_error error; | ||
2582 | 373 | struct ofono_call *call; | ||
2583 | 374 | GSList *l; | ||
2584 | 375 | |||
2585 | 376 | for (l = vd->calls; l; l = l->next) { | ||
2586 | 377 | call = l->data; | ||
2587 | 378 | /* TODO: Hangup just the active ones once we have call | ||
2588 | 379 | * state tracking (otherwise it can't handle ringing) */ | ||
2589 | 380 | DBG("Hanging up call with id %d", call->id); | ||
2590 | 381 | parcel_init(&rilp); | ||
2591 | 382 | parcel_w_int32(&rilp, 1); /* Always 1 - AT+CHLD=1x */ | ||
2592 | 383 | parcel_w_int32(&rilp, call->id); | ||
2593 | 384 | |||
2594 | 385 | /* Send request to RIL */ | ||
2595 | 386 | ril_template(RIL_REQUEST_HANGUP, vc, generic_cb, 0x3f, | ||
2596 | 387 | rilp.data, rilp.size, NULL, NULL); | ||
2597 | 388 | parcel_free(&rilp); | ||
2598 | 389 | } | ||
2599 | 390 | |||
2600 | 391 | /* TODO: Deal in case of an error at hungup */ | ||
2601 | 392 | decode_ril_error(&error, "OK"); | ||
2602 | 393 | cb(&error, data); | ||
2603 | 394 | } | ||
2604 | 395 | |||
2605 | 396 | static void ril_call_state_notify(struct ril_msg *message, gpointer user_data) | ||
2606 | 397 | { | ||
2607 | 398 | struct ofono_voicecall *vc = user_data; | ||
2608 | 399 | |||
2609 | 400 | if (message->req != RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED) | ||
2610 | 401 | goto error; | ||
2611 | 402 | |||
2612 | 403 | /* Just need to request the call list again */ | ||
2613 | 404 | poll_clcc(vc); | ||
2614 | 405 | |||
2615 | 406 | return; | ||
2616 | 407 | |||
2617 | 408 | error: | ||
2618 | 409 | ofono_error("Unable to notify about call state changes"); | ||
2619 | 410 | } | ||
2620 | 411 | |||
2621 | 412 | static void ril_answer(struct ofono_voicecall *vc, | ||
2622 | 413 | ofono_voicecall_cb_t cb, void *data) | ||
2623 | 414 | { | ||
2624 | 415 | DBG("Answering current call"); | ||
2625 | 416 | |||
2626 | 417 | /* Send request to RIL */ | ||
2627 | 418 | ril_template(RIL_REQUEST_ANSWER, vc, generic_cb, 0, | ||
2628 | 419 | NULL, 0, cb, data); | ||
2629 | 420 | |||
2630 | 421 | audioflinger_set_call_mode(); | ||
2631 | 422 | } | ||
2632 | 423 | |||
2633 | 424 | static void ril_send_dtmf(struct ofono_voicecall *vc, const char *dtmf, | ||
2634 | 425 | ofono_voicecall_cb_t cb, void *data) | ||
2635 | 426 | { | ||
2636 | 427 | struct voicecall_data *vd = ofono_voicecall_get_data(vc); | ||
2637 | 428 | int len = strlen(dtmf); | ||
2638 | 429 | struct parcel rilp; | ||
2639 | 430 | struct ofono_error error; | ||
2640 | 431 | char *ril_dtmf = g_try_malloc(sizeof(char) * 2); | ||
2641 | 432 | int i; | ||
2642 | 433 | |||
2643 | 434 | DBG(""); | ||
2644 | 435 | |||
2645 | 436 | /* Ril wants just one character, but we need to send as string */ | ||
2646 | 437 | ril_dtmf[1] = '\0'; | ||
2647 | 438 | |||
2648 | 439 | for (i = 0; i < len; i++) { | ||
2649 | 440 | parcel_init(&rilp); | ||
2650 | 441 | ril_dtmf[0] = dtmf[i]; | ||
2651 | 442 | parcel_w_string(&rilp, ril_dtmf); | ||
2652 | 443 | DBG("DTMF: Sending %s", ril_dtmf); | ||
2653 | 444 | g_ril_send(vd->ril, RIL_REQUEST_DTMF, rilp.data, | ||
2654 | 445 | rilp.size, NULL, NULL, NULL); | ||
2655 | 446 | parcel_free(&rilp); | ||
2656 | 447 | } | ||
2657 | 448 | |||
2658 | 449 | free(ril_dtmf); | ||
2659 | 450 | |||
2660 | 451 | /* We don't really care about errors here */ | ||
2661 | 452 | decode_ril_error(&error, "OK"); | ||
2662 | 453 | cb(&error, data); | ||
2663 | 454 | } | ||
2664 | 455 | |||
2665 | 456 | static gboolean ril_delayed_register(gpointer user_data) | ||
2666 | 457 | { | ||
2667 | 458 | struct ofono_voicecall *vc = user_data; | ||
2668 | 459 | struct voicecall_data *vd = ofono_voicecall_get_data(vc); | ||
2669 | 460 | ofono_voicecall_register(vc); | ||
2670 | 461 | |||
2671 | 462 | /* Initialize call list */ | ||
2672 | 463 | poll_clcc(vc); | ||
2673 | 464 | |||
2674 | 465 | /* Unsol when call state changes */ | ||
2675 | 466 | g_ril_register(vd->ril, RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, | ||
2676 | 467 | ril_call_state_notify, vc); | ||
2677 | 468 | |||
2678 | 469 | /* This makes the timeout a single-shot */ | ||
2679 | 470 | return FALSE; | ||
2680 | 471 | } | ||
2681 | 472 | |||
2682 | 473 | static int ril_voicecall_probe(struct ofono_voicecall *vc, unsigned int vendor, | ||
2683 | 474 | void *data) | ||
2684 | 475 | { | ||
2685 | 476 | GRil *ril = data; | ||
2686 | 477 | struct voicecall_data *vd; | ||
2687 | 478 | |||
2688 | 479 | vd = g_try_new0(struct voicecall_data, 1); | ||
2689 | 480 | if (vd == NULL) | ||
2690 | 481 | return -ENOMEM; | ||
2691 | 482 | |||
2692 | 483 | vd->ril = g_ril_clone(ril); | ||
2693 | 484 | vd->vendor = vendor; | ||
2694 | 485 | vd->tone_duration = TONE_DURATION; | ||
2695 | 486 | |||
2696 | 487 | ofono_voicecall_set_data(vc, vd); | ||
2697 | 488 | |||
2698 | 489 | /* ofono_devinfo_register() needs to be called after | ||
2699 | 490 | * the driver has been set in devinfo_create() which | ||
2700 | 491 | * calls this function. Most other drivers use a | ||
2701 | 492 | * callback after getting some return from the modem | ||
2702 | 493 | * itself... | ||
2703 | 494 | */ | ||
2704 | 495 | g_timeout_add_seconds(2, ril_delayed_register, vc); | ||
2705 | 496 | |||
2706 | 497 | return 0; | ||
2707 | 498 | } | ||
2708 | 499 | |||
2709 | 500 | static void ril_voicecall_remove(struct ofono_voicecall *vc) | ||
2710 | 501 | { | ||
2711 | 502 | struct voicecall_data *vd = ofono_voicecall_get_data(vc); | ||
2712 | 503 | |||
2713 | 504 | if (vd->clcc_source) | ||
2714 | 505 | g_source_remove(vd->clcc_source); | ||
2715 | 506 | |||
2716 | 507 | if (vd->vts_source) | ||
2717 | 508 | g_source_remove(vd->vts_source); | ||
2718 | 509 | |||
2719 | 510 | g_slist_foreach(vd->calls, (GFunc) g_free, NULL); | ||
2720 | 511 | g_slist_free(vd->calls); | ||
2721 | 512 | |||
2722 | 513 | ofono_voicecall_set_data(vc, NULL); | ||
2723 | 514 | |||
2724 | 515 | g_ril_unref(vd->ril); | ||
2725 | 516 | g_free(vd); | ||
2726 | 517 | } | ||
2727 | 518 | |||
2728 | 519 | static struct ofono_voicecall_driver driver = { | ||
2729 | 520 | .name = "rilmodem", | ||
2730 | 521 | .probe = ril_voicecall_probe, | ||
2731 | 522 | .remove = ril_voicecall_remove, | ||
2732 | 523 | .dial = ril_dial, | ||
2733 | 524 | .answer = ril_answer, | ||
2734 | 525 | .hangup_all = ril_hangup_all, | ||
2735 | 526 | .send_tones = ril_send_dtmf | ||
2736 | 527 | }; | ||
2737 | 528 | |||
2738 | 529 | void ril_voicecall_init(void) | ||
2739 | 530 | { | ||
2740 | 531 | ofono_voicecall_driver_register(&driver); | ||
2741 | 532 | } | ||
2742 | 533 | |||
2743 | 534 | void ril_voicecall_exit(void) | ||
2744 | 535 | { | ||
2745 | 536 | ofono_voicecall_driver_unregister(&driver); | ||
2746 | 537 | } | ||
2747 | 0 | 538 | ||
2748 | === added directory 'gril' | |||
2749 | === added file 'gril/gfunc.h' | |||
2750 | --- gril/gfunc.h 1970-01-01 00:00:00 +0000 | |||
2751 | +++ gril/gfunc.h 2013-04-09 20:01:20 +0000 | |||
2752 | @@ -0,0 +1,42 @@ | |||
2753 | 1 | /* | ||
2754 | 2 | * | ||
2755 | 3 | * RIL library with GLib integration | ||
2756 | 4 | * | ||
2757 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
2758 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
2759 | 7 | * | ||
2760 | 8 | * This program is free software; you can redistribute it and/or modify | ||
2761 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
2762 | 10 | * published by the Free Software Foundation. | ||
2763 | 11 | * | ||
2764 | 12 | * This program is distributed in the hope that it will be useful, | ||
2765 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2766 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2767 | 15 | * GNU General Public License for more details. | ||
2768 | 16 | * | ||
2769 | 17 | * You should have received a copy of the GNU General Public License | ||
2770 | 18 | * along with this program; if not, write to the Free Software | ||
2771 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
2772 | 20 | * | ||
2773 | 21 | */ | ||
2774 | 22 | |||
2775 | 23 | #ifndef __GFUNC_H | ||
2776 | 24 | #define __GFUNC_H | ||
2777 | 25 | |||
2778 | 26 | #include <glib.h> | ||
2779 | 27 | |||
2780 | 28 | #ifdef __cplusplus | ||
2781 | 29 | extern "C" { | ||
2782 | 30 | #endif | ||
2783 | 31 | |||
2784 | 32 | typedef void (*GRilDisconnectFunc)(gpointer user_data); | ||
2785 | 33 | typedef void (*GRilReceiveFunc)(const unsigned char *data, gsize size, | ||
2786 | 34 | gpointer user_data); | ||
2787 | 35 | typedef void (*GRilDebugFunc)(const char *str, gpointer user_data); | ||
2788 | 36 | typedef void (*GRilSuspendFunc)(gpointer user_data); | ||
2789 | 37 | |||
2790 | 38 | #ifdef __cplusplus | ||
2791 | 39 | } | ||
2792 | 40 | #endif | ||
2793 | 41 | |||
2794 | 42 | #endif /* __GFUNC_H */ | ||
2795 | 0 | 43 | ||
2796 | === added file 'gril/gril.c' | |||
2797 | --- gril/gril.c 1970-01-01 00:00:00 +0000 | |||
2798 | +++ gril/gril.c 2013-04-09 20:01:20 +0000 | |||
2799 | @@ -0,0 +1,1160 @@ | |||
2800 | 1 | /* | ||
2801 | 2 | * | ||
2802 | 3 | * RIL library with GLib integration | ||
2803 | 4 | * | ||
2804 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
2805 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
2806 | 7 | * | ||
2807 | 8 | * This program is free software; you can redistribute it and/or modify | ||
2808 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
2809 | 10 | * published by the Free Software Foundation. | ||
2810 | 11 | * | ||
2811 | 12 | * This program is distributed in the hope that it will be useful, | ||
2812 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2813 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2814 | 15 | * GNU General Public License for more details. | ||
2815 | 16 | * | ||
2816 | 17 | * You should have received a copy of the GNU General Public License | ||
2817 | 18 | * along with this program; if not, write to the Free Software | ||
2818 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
2819 | 20 | * | ||
2820 | 21 | */ | ||
2821 | 22 | |||
2822 | 23 | #ifdef HAVE_CONFIG_H | ||
2823 | 24 | #include <config.h> | ||
2824 | 25 | #endif | ||
2825 | 26 | |||
2826 | 27 | #include <stdio.h> | ||
2827 | 28 | #include <unistd.h> | ||
2828 | 29 | #include <string.h> | ||
2829 | 30 | #include <assert.h> | ||
2830 | 31 | #include <ctype.h> | ||
2831 | 32 | #include <errno.h> | ||
2832 | 33 | #include <sys/socket.h> | ||
2833 | 34 | #include <sys/un.h> | ||
2834 | 35 | #include <netinet/in.h> | ||
2835 | 36 | |||
2836 | 37 | #include <glib.h> | ||
2837 | 38 | |||
2838 | 39 | #include "log.h" | ||
2839 | 40 | #include "ringbuffer.h" | ||
2840 | 41 | #include "gril.h" | ||
2841 | 42 | |||
2842 | 43 | #define COMMAND_FLAG_EXPECT_PDU 0x1 | ||
2843 | 44 | #define COMMAND_FLAG_EXPECT_SHORT_PROMPT 0x2 | ||
2844 | 45 | |||
2845 | 46 | #define RILD_CMD_SOCKET "/dev/socket/rild" | ||
2846 | 47 | #define RILD_DBG_SOCKET "/dev/socket/rild-debug" | ||
2847 | 48 | |||
2848 | 49 | struct ril_request { | ||
2849 | 50 | gchar *req; | ||
2850 | 51 | guint req_len; | ||
2851 | 52 | guint id; | ||
2852 | 53 | guint gid; | ||
2853 | 54 | GRilResponseFunc callback; | ||
2854 | 55 | gpointer user_data; | ||
2855 | 56 | GDestroyNotify notify; | ||
2856 | 57 | }; | ||
2857 | 58 | |||
2858 | 59 | struct ril_notify_node { | ||
2859 | 60 | guint id; | ||
2860 | 61 | guint gid; | ||
2861 | 62 | GRilNotifyFunc callback; | ||
2862 | 63 | gpointer user_data; | ||
2863 | 64 | gboolean destroyed; | ||
2864 | 65 | }; | ||
2865 | 66 | |||
2866 | 67 | typedef gboolean (*node_remove_func)(struct ril_notify_node *node, | ||
2867 | 68 | gpointer user_data); | ||
2868 | 69 | |||
2869 | 70 | struct ril_notify { | ||
2870 | 71 | GSList *nodes; | ||
2871 | 72 | }; | ||
2872 | 73 | |||
2873 | 74 | struct ril_s { | ||
2874 | 75 | gint ref_count; /* Ref count */ | ||
2875 | 76 | guint next_cmd_id; /* Next command id */ | ||
2876 | 77 | guint next_notify_id; /* Next notify id */ | ||
2877 | 78 | guint next_gid; /* Next group id */ | ||
2878 | 79 | GRilIO *io; /* GRil IO */ | ||
2879 | 80 | GQueue *command_queue; /* Command queue */ | ||
2880 | 81 | guint req_bytes_written; /* bytes written from req */ | ||
2881 | 82 | GHashTable *notify_list; /* List of notification reg */ | ||
2882 | 83 | GRilDisconnectFunc user_disconnect; /* user disconnect func */ | ||
2883 | 84 | gpointer user_disconnect_data; /* user disconnect data */ | ||
2884 | 85 | guint read_so_far; /* Number of bytes processed */ | ||
2885 | 86 | gboolean suspended; /* Are we suspended? */ | ||
2886 | 87 | GRilDebugFunc debugf; /* debugging output function */ | ||
2887 | 88 | gpointer debug_data; /* Data to pass to debug func */ | ||
2888 | 89 | GSList *response_lines; /* char * lines of the response */ | ||
2889 | 90 | gint timeout_source; | ||
2890 | 91 | gboolean destroyed; /* Re-entrancy guard */ | ||
2891 | 92 | gboolean in_read_handler; /* Re-entrancy guard */ | ||
2892 | 93 | gboolean in_notify; | ||
2893 | 94 | }; | ||
2894 | 95 | |||
2895 | 96 | struct _GRil { | ||
2896 | 97 | gint ref_count; | ||
2897 | 98 | struct ril_s *parent; | ||
2898 | 99 | guint group; | ||
2899 | 100 | }; | ||
2900 | 101 | |||
2901 | 102 | /* | ||
2902 | 103 | * This struct represents the header of a RIL reply. | ||
2903 | 104 | * It does not include the Big Endian UINT32 length prefix. | ||
2904 | 105 | */ | ||
2905 | 106 | struct ril_reply { | ||
2906 | 107 | guint32 reply; /* LE: should be 0 */ | ||
2907 | 108 | guint32 serial_no; /* LE: used to match requests */ | ||
2908 | 109 | guint32 error_code; /* LE: */ | ||
2909 | 110 | }; | ||
2910 | 111 | |||
2911 | 112 | static void ril_wakeup_writer(struct ril_s *ril); | ||
2912 | 113 | |||
2913 | 114 | static void ril_notify_node_destroy(gpointer data, gpointer user_data) | ||
2914 | 115 | { | ||
2915 | 116 | struct ril_notify_node *node = data; | ||
2916 | 117 | g_free(node); | ||
2917 | 118 | } | ||
2918 | 119 | |||
2919 | 120 | static void ril_notify_destroy(gpointer user_data) | ||
2920 | 121 | { | ||
2921 | 122 | struct ril_notify *notify = user_data; | ||
2922 | 123 | |||
2923 | 124 | g_slist_foreach(notify->nodes, ril_notify_node_destroy, NULL); | ||
2924 | 125 | g_slist_free(notify->nodes); | ||
2925 | 126 | g_free(notify); | ||
2926 | 127 | } | ||
2927 | 128 | |||
2928 | 129 | static gint ril_notify_node_compare_by_id(gconstpointer a, gconstpointer b) | ||
2929 | 130 | { | ||
2930 | 131 | const struct ril_notify_node *node = a; | ||
2931 | 132 | guint id = GPOINTER_TO_UINT(b); | ||
2932 | 133 | |||
2933 | 134 | if (node->id < id) | ||
2934 | 135 | return -1; | ||
2935 | 136 | |||
2936 | 137 | if (node->id > id) | ||
2937 | 138 | return 1; | ||
2938 | 139 | |||
2939 | 140 | return 0; | ||
2940 | 141 | } | ||
2941 | 142 | |||
2942 | 143 | static gboolean ril_unregister_all(struct ril_s *ril, | ||
2943 | 144 | gboolean mark_only, | ||
2944 | 145 | node_remove_func func, | ||
2945 | 146 | gpointer userdata) | ||
2946 | 147 | { | ||
2947 | 148 | GHashTableIter iter; | ||
2948 | 149 | struct ril_notify *notify; | ||
2949 | 150 | struct ril_notify_node *node; | ||
2950 | 151 | gpointer key, value; | ||
2951 | 152 | GSList *p; | ||
2952 | 153 | GSList *c; | ||
2953 | 154 | GSList *t; | ||
2954 | 155 | |||
2955 | 156 | if (ril->notify_list == NULL) | ||
2956 | 157 | return FALSE; | ||
2957 | 158 | |||
2958 | 159 | g_hash_table_iter_init(&iter, ril->notify_list); | ||
2959 | 160 | |||
2960 | 161 | while (g_hash_table_iter_next(&iter, &key, &value)) { | ||
2961 | 162 | notify = value; | ||
2962 | 163 | |||
2963 | 164 | p = NULL; | ||
2964 | 165 | c = notify->nodes; | ||
2965 | 166 | |||
2966 | 167 | while (c) { | ||
2967 | 168 | node = c->data; | ||
2968 | 169 | |||
2969 | 170 | if (func(node, userdata) != TRUE) { | ||
2970 | 171 | p = c; | ||
2971 | 172 | c = c->next; | ||
2972 | 173 | continue; | ||
2973 | 174 | } | ||
2974 | 175 | |||
2975 | 176 | if (mark_only) { | ||
2976 | 177 | node->destroyed = TRUE; | ||
2977 | 178 | p = c; | ||
2978 | 179 | c = c->next; | ||
2979 | 180 | continue; | ||
2980 | 181 | } | ||
2981 | 182 | |||
2982 | 183 | if (p) | ||
2983 | 184 | p->next = c->next; | ||
2984 | 185 | else | ||
2985 | 186 | notify->nodes = c->next; | ||
2986 | 187 | |||
2987 | 188 | ril_notify_node_destroy(node, NULL); | ||
2988 | 189 | |||
2989 | 190 | t = c; | ||
2990 | 191 | c = c->next; | ||
2991 | 192 | g_slist_free_1(t); | ||
2992 | 193 | } | ||
2993 | 194 | |||
2994 | 195 | if (notify->nodes == NULL) | ||
2995 | 196 | g_hash_table_iter_remove(&iter); | ||
2996 | 197 | } | ||
2997 | 198 | |||
2998 | 199 | return TRUE; | ||
2999 | 200 | } | ||
3000 | 201 | |||
3001 | 202 | /* TODO: move to grilutil.h */ | ||
3002 | 203 | static const char *err_name(int error) | ||
3003 | 204 | { | ||
3004 | 205 | switch(error) { | ||
3005 | 206 | case RIL_E_SUCCESS: return "SUCCESS"; | ||
3006 | 207 | case RIL_E_RADIO_NOT_AVAILABLE: return "RADIO_NOT_AVAILABLE"; | ||
3007 | 208 | case RIL_E_GENERIC_FAILURE: return "GENERIC_FAILURE"; | ||
3008 | 209 | case RIL_E_PASSWORD_INCORRECT: return "PASSWORD_INCORRECT"; | ||
3009 | 210 | case RIL_E_SIM_PIN2: return "SIM_PIN2"; | ||
3010 | 211 | case RIL_E_SIM_PUK2: return "SIM_PUK2"; | ||
3011 | 212 | case RIL_E_REQUEST_NOT_SUPPORTED: return "REQUEST_NOT_SUPPORTED"; | ||
3012 | 213 | case RIL_E_CANCELLED: return "CANCELLED"; | ||
3013 | 214 | case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "OP_NOT_ALLOWED_DURING_VOICE_CALL"; | ||
3014 | 215 | case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "OP_NOT_ALLOWED_BEFORE_REG_TO_NW"; | ||
3015 | 216 | case RIL_E_SMS_SEND_FAIL_RETRY: return "SMS_SEND_FAIL_RETRY"; | ||
3016 | 217 | case RIL_E_SIM_ABSENT: return "SIM_ABSENT"; | ||
3017 | 218 | case RIL_E_SUBSCRIPTION_NOT_AVAILABLE: return "SUBSCRIPTION_NOT_AVAILABLE"; | ||
3018 | 219 | case RIL_E_MODE_NOT_SUPPORTED: return "MODE_NOT_SUPPORTED"; | ||
3019 | 220 | case RIL_E_FDN_CHECK_FAILURE: return "FDN_CHECK_FAILURE"; | ||
3020 | 221 | case RIL_E_ILLEGAL_SIM_OR_ME: return "ILLEGAL_SIM_OR_ME"; | ||
3021 | 222 | default: return "<unknown errno>"; | ||
3022 | 223 | } | ||
3023 | 224 | } | ||
3024 | 225 | |||
3025 | 226 | /* TODO: move to grilutil.h */ | ||
3026 | 227 | static const char *unsol_request_name(int request) | ||
3027 | 228 | { | ||
3028 | 229 | switch(request) { | ||
3029 | 230 | case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED"; | ||
3030 | 231 | case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED"; | ||
3031 | 232 | case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED"; | ||
3032 | 233 | case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS"; | ||
3033 | 234 | case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT"; | ||
3034 | 235 | case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM"; | ||
3035 | 236 | case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD"; | ||
3036 | 237 | case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)"; | ||
3037 | 238 | case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED"; | ||
3038 | 239 | case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH"; | ||
3039 | 240 | case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END"; | ||
3040 | 241 | case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND"; | ||
3041 | 242 | case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY"; | ||
3042 | 243 | case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP"; | ||
3043 | 244 | case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL"; | ||
3044 | 245 | case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH"; | ||
3045 | 246 | case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED"; | ||
3046 | 247 | case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING"; | ||
3047 | 248 | case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED"; | ||
3048 | 249 | case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS"; | ||
3049 | 250 | case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS"; | ||
3050 | 251 | case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL"; | ||
3051 | 252 | case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED"; | ||
3052 | 253 | case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE"; | ||
3053 | 254 | case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING"; | ||
3054 | 255 | case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS"; | ||
3055 | 256 | case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC"; | ||
3056 | 257 | case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW"; | ||
3057 | 258 | case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE"; | ||
3058 | 259 | case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE"; | ||
3059 | 260 | case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED"; | ||
3060 | 261 | case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED"; | ||
3061 | 262 | case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE"; | ||
3062 | 263 | case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED"; | ||
3063 | 264 | default: | ||
3064 | 265 | DBG("Got unknown request number %d", request); | ||
3065 | 266 | return "<unknown request>"; | ||
3066 | 267 | } | ||
3067 | 268 | } | ||
3068 | 269 | |||
3069 | 270 | /* | ||
3070 | 271 | * This function creates a RIL request. For a good reference on | ||
3071 | 272 | * the layout of RIL requests, responses, and unsolicited requests | ||
3072 | 273 | * see: | ||
3073 | 274 | * | ||
3074 | 275 | * https://wiki.mozilla.org/B2G/RIL | ||
3075 | 276 | * | ||
3076 | 277 | */ | ||
3077 | 278 | static struct ril_request *ril_request_create(struct ril_s *ril, | ||
3078 | 279 | guint gid, | ||
3079 | 280 | const guint req, | ||
3080 | 281 | const guint id, | ||
3081 | 282 | const char *data, | ||
3082 | 283 | const gsize data_len, | ||
3083 | 284 | GRilResponseFunc func, | ||
3084 | 285 | gpointer user_data, | ||
3085 | 286 | GDestroyNotify notify, | ||
3086 | 287 | gboolean wakeup) | ||
3087 | 288 | { | ||
3088 | 289 | struct ril_request *r; | ||
3089 | 290 | gsize len; | ||
3090 | 291 | gchar *cur_bufp; | ||
3091 | 292 | guint32 *net_length, *request, *serial_no; | ||
3092 | 293 | |||
3093 | 294 | r = g_try_new0(struct ril_request, 1); | ||
3094 | 295 | if (r == NULL) | ||
3095 | 296 | return 0; | ||
3096 | 297 | |||
3097 | 298 | DBG("req: %s, id: %d, data_len: %d", | ||
3098 | 299 | ril_request_id_to_string(req), id, data_len); | ||
3099 | 300 | |||
3100 | 301 | /* RIL request: 8 byte header + data */ | ||
3101 | 302 | len = 8 + data_len; | ||
3102 | 303 | |||
3103 | 304 | /* Add 4 bytes to buffer length to include length prefix */ | ||
3104 | 305 | r->req_len = len + 4; | ||
3105 | 306 | |||
3106 | 307 | r->req = g_try_new(char, r->req_len); | ||
3107 | 308 | if (r->req == NULL) { | ||
3108 | 309 | ofono_error("ril_request: can't allocate new request."); | ||
3109 | 310 | g_free(r); | ||
3110 | 311 | return 0; | ||
3111 | 312 | } | ||
3112 | 313 | |||
3113 | 314 | /* convert length to network byte order (Big Endian) */ | ||
3114 | 315 | net_length = (guint32 *) r->req; | ||
3115 | 316 | *net_length = htonl(len); | ||
3116 | 317 | |||
3117 | 318 | /* advance past initial length */ | ||
3118 | 319 | cur_bufp = r->req + 4; | ||
3119 | 320 | |||
3120 | 321 | /* write request code */ | ||
3121 | 322 | request = (guint32 *) cur_bufp; | ||
3122 | 323 | *request = req; | ||
3123 | 324 | cur_bufp += 4; | ||
3124 | 325 | |||
3125 | 326 | /* write serial number */ | ||
3126 | 327 | serial_no = (guint32 *) cur_bufp; | ||
3127 | 328 | *serial_no = id; | ||
3128 | 329 | cur_bufp += 4; | ||
3129 | 330 | |||
3130 | 331 | /* copy request data */ | ||
3131 | 332 | memcpy(cur_bufp, (const void *) data, data_len); | ||
3132 | 333 | |||
3133 | 334 | r->gid = gid; | ||
3134 | 335 | r->id = id; | ||
3135 | 336 | r->callback = func; | ||
3136 | 337 | r->user_data = user_data; | ||
3137 | 338 | r->notify = notify; | ||
3138 | 339 | |||
3139 | 340 | return r; | ||
3140 | 341 | } | ||
3141 | 342 | |||
3142 | 343 | static void ril_request_destroy(struct ril_request *req) | ||
3143 | 344 | { | ||
3144 | 345 | if (req->notify) | ||
3145 | 346 | req->notify(req->user_data); | ||
3146 | 347 | |||
3147 | 348 | g_free(req->req); | ||
3148 | 349 | g_free(req); | ||
3149 | 350 | } | ||
3150 | 351 | |||
3151 | 352 | static void ril_cleanup(struct ril_s *p) | ||
3152 | 353 | { | ||
3153 | 354 | /* Cleanup pending commands */ | ||
3154 | 355 | |||
3155 | 356 | g_queue_free(p->command_queue); | ||
3156 | 357 | p->command_queue = NULL; | ||
3157 | 358 | |||
3158 | 359 | /* Cleanup any response lines we have pending */ | ||
3159 | 360 | g_slist_foreach(p->response_lines, (GFunc)g_free, NULL); | ||
3160 | 361 | g_slist_free(p->response_lines); | ||
3161 | 362 | p->response_lines = NULL; | ||
3162 | 363 | |||
3163 | 364 | /* Cleanup registered notifications */ | ||
3164 | 365 | |||
3165 | 366 | if (p->notify_list) | ||
3166 | 367 | g_hash_table_destroy(p->notify_list); | ||
3167 | 368 | |||
3168 | 369 | p->notify_list = NULL; | ||
3169 | 370 | |||
3170 | 371 | if (p->timeout_source) { | ||
3171 | 372 | g_source_remove(p->timeout_source); | ||
3172 | 373 | p->timeout_source = 0; | ||
3173 | 374 | } | ||
3174 | 375 | } | ||
3175 | 376 | |||
3176 | 377 | static void io_disconnect(gpointer user_data) | ||
3177 | 378 | { | ||
3178 | 379 | struct ril_s *ril = user_data; | ||
3179 | 380 | |||
3180 | 381 | ril_cleanup(ril); | ||
3181 | 382 | g_ril_io_unref(ril->io); | ||
3182 | 383 | ril->io = NULL; | ||
3183 | 384 | |||
3184 | 385 | if (ril->user_disconnect) | ||
3185 | 386 | ril->user_disconnect(ril->user_disconnect_data); | ||
3186 | 387 | } | ||
3187 | 388 | |||
3188 | 389 | static void handle_response(struct ril_s *p, struct ril_msg *message) | ||
3189 | 390 | { | ||
3190 | 391 | gsize count = g_queue_get_length(p->command_queue); | ||
3191 | 392 | struct ril_request *req; | ||
3192 | 393 | int i; | ||
3193 | 394 | |||
3194 | 395 | g_assert(count > 0); | ||
3195 | 396 | |||
3196 | 397 | for (i = 0; i < count; i++) { | ||
3197 | 398 | req = g_queue_peek_nth(p->command_queue, i); | ||
3198 | 399 | DBG("comparing req->id: %d to message->serial_no: %d", | ||
3199 | 400 | req->id, message->serial_no); | ||
3200 | 401 | |||
3201 | 402 | if (req->id == message->serial_no) { | ||
3202 | 403 | req = g_queue_pop_nth(p->command_queue, i); | ||
3203 | 404 | |||
3204 | 405 | if (req->callback) | ||
3205 | 406 | req->callback(message, req->user_data); | ||
3206 | 407 | |||
3207 | 408 | ril_request_destroy(req); | ||
3208 | 409 | |||
3209 | 410 | if (g_queue_peek_head(p->command_queue)) | ||
3210 | 411 | ril_wakeup_writer(p); | ||
3211 | 412 | /* | ||
3212 | 413 | * TODO: there's a flaw in the current logic. | ||
3213 | 414 | * If a matching response isn't received, | ||
3214 | 415 | * req_bytes_written doesn't get reset. | ||
3215 | 416 | * gatchat has the concept of modem wakeup, | ||
3216 | 417 | * which is a failsafe way of making sure | ||
3217 | 418 | * cmd_bytes_written gets reset, however if | ||
3218 | 419 | * the modem isn't configured for wakeup, | ||
3219 | 420 | * it may have the same problem. Perhaps | ||
3220 | 421 | * we should consider adding a timer? | ||
3221 | 422 | */ | ||
3222 | 423 | p->req_bytes_written = 0; | ||
3223 | 424 | |||
3224 | 425 | /* Found our matching one */ | ||
3225 | 426 | break; | ||
3226 | 427 | } | ||
3227 | 428 | } | ||
3228 | 429 | } | ||
3229 | 430 | |||
3230 | 431 | static void handle_unsol_req(struct ril_s *p, struct ril_msg *message) | ||
3231 | 432 | { | ||
3232 | 433 | GHashTableIter iter; | ||
3233 | 434 | struct ril_notify *notify; | ||
3234 | 435 | int req_key; | ||
3235 | 436 | gpointer key, value; | ||
3236 | 437 | GList *list_item; | ||
3237 | 438 | struct ril_notify_node *node; | ||
3238 | 439 | |||
3239 | 440 | if (p->notify_list == NULL) | ||
3240 | 441 | return; | ||
3241 | 442 | |||
3242 | 443 | p->in_notify = TRUE; | ||
3243 | 444 | |||
3244 | 445 | g_hash_table_iter_init(&iter, p->notify_list); | ||
3245 | 446 | |||
3246 | 447 | while (g_hash_table_iter_next(&iter, &key, &value)) { | ||
3247 | 448 | req_key = *((int *)key); | ||
3248 | 449 | notify = value; | ||
3249 | 450 | |||
3250 | 451 | DBG("checking req_key: %d to req: %d", req_key, message->req); | ||
3251 | 452 | |||
3252 | 453 | if (req_key != message->req) | ||
3253 | 454 | continue; | ||
3254 | 455 | |||
3255 | 456 | list_item = notify->nodes; | ||
3256 | 457 | |||
3257 | 458 | while (list_item != NULL) { | ||
3258 | 459 | node = list_item->data; | ||
3259 | 460 | |||
3260 | 461 | DBG("about to callback: notify: %x, node: %x, notify->nodes: %x, callback: %x", | ||
3261 | 462 | notify, node, notify->nodes, node->callback); | ||
3262 | 463 | |||
3263 | 464 | node->callback(message, node->user_data); | ||
3264 | 465 | |||
3265 | 466 | list_item = g_slist_next(list_item); | ||
3266 | 467 | } | ||
3267 | 468 | } | ||
3268 | 469 | |||
3269 | 470 | p->in_notify = FALSE; | ||
3270 | 471 | } | ||
3271 | 472 | |||
3272 | 473 | static void dispatch(struct ril_s *p, struct ril_msg *message) | ||
3273 | 474 | { | ||
3274 | 475 | guint32 *unsolicited_field, *id_num_field; | ||
3275 | 476 | gchar *bufp = message->buf; | ||
3276 | 477 | gchar *datap; | ||
3277 | 478 | gsize data_len; | ||
3278 | 479 | |||
3279 | 480 | /* This could be done with a struct/union... */ | ||
3280 | 481 | unsolicited_field = (guint32 *) bufp; | ||
3281 | 482 | if (*unsolicited_field) | ||
3282 | 483 | message->unsolicited = TRUE; | ||
3283 | 484 | else | ||
3284 | 485 | message->unsolicited = FALSE; | ||
3285 | 486 | |||
3286 | 487 | bufp += 4; | ||
3287 | 488 | |||
3288 | 489 | id_num_field = (guint32 *) bufp; | ||
3289 | 490 | if (message->unsolicited) { | ||
3290 | 491 | message->req = (int) *id_num_field; | ||
3291 | 492 | |||
3292 | 493 | /* | ||
3293 | 494 | * A RIL Unsolicited Event is two UINT32 fields ( unsolicited, and req/ev ), | ||
3294 | 495 | * so subtract the length of the header from the overall length to calculate | ||
3295 | 496 | * the length of the Event Data. | ||
3296 | 497 | */ | ||
3297 | 498 | data_len = message->buf_len - 8; | ||
3298 | 499 | } else { | ||
3299 | 500 | message->serial_no = (int) *id_num_field; | ||
3300 | 501 | |||
3301 | 502 | bufp += 4; | ||
3302 | 503 | message->error = *((guint32 *) bufp); | ||
3303 | 504 | |||
3304 | 505 | /* | ||
3305 | 506 | * A RIL Solicited Response is three UINT32 fields ( unsolicied, serial_no | ||
3306 | 507 | * and error ), so subtract the length of the header from the overall length | ||
3307 | 508 | * to calculate the length of the Event Data. | ||
3308 | 509 | */ | ||
3309 | 510 | data_len = message->buf_len - 12; | ||
3310 | 511 | } | ||
3311 | 512 | |||
3312 | 513 | /* advance to start of data.. */ | ||
3313 | 514 | bufp += 4; | ||
3314 | 515 | |||
3315 | 516 | /* Now, allocate new buffer for data only, copy from | ||
3316 | 517 | * original, and free the original... | ||
3317 | 518 | */ | ||
3318 | 519 | if (data_len) { | ||
3319 | 520 | datap = g_try_malloc(data_len); | ||
3320 | 521 | if (datap == NULL) | ||
3321 | 522 | goto error; | ||
3322 | 523 | |||
3323 | 524 | /* Copy bytes into new buffer */ | ||
3324 | 525 | memmove(datap, (const void *) bufp, data_len); | ||
3325 | 526 | |||
3326 | 527 | /* Free old buffer */ | ||
3327 | 528 | g_free(message->buf); | ||
3328 | 529 | |||
3329 | 530 | /* ...and replace with new buffer */ | ||
3330 | 531 | message->buf = datap; | ||
3331 | 532 | message->buf_len = data_len; | ||
3332 | 533 | } | ||
3333 | 534 | |||
3334 | 535 | if (message->unsolicited == TRUE) { | ||
3335 | 536 | DBG("RIL Event: %s\n", unsol_request_name(message->req)); | ||
3336 | 537 | |||
3337 | 538 | handle_unsol_req(p, message); | ||
3338 | 539 | } else { | ||
3339 | 540 | DBG("RIL Reply: serial-no: %d errno: %s\n", | ||
3340 | 541 | message->serial_no, | ||
3341 | 542 | err_name(message->error)); | ||
3342 | 543 | |||
3343 | 544 | handle_response(p, message); | ||
3344 | 545 | } | ||
3345 | 546 | error: | ||
3346 | 547 | g_free(message->buf); | ||
3347 | 548 | g_free(message); | ||
3348 | 549 | } | ||
3349 | 550 | |||
3350 | 551 | static struct ril_msg *read_fixed_record(struct ril_s *p, | ||
3351 | 552 | const guchar *bytes, gsize *len) | ||
3352 | 553 | { | ||
3353 | 554 | struct ril_msg *message; | ||
3354 | 555 | int message_len, plen; | ||
3355 | 556 | |||
3356 | 557 | /* First four bytes are length in TCP byte order (Big Endian) */ | ||
3357 | 558 | plen = ntohl(*((uint32_t *) bytes)); | ||
3358 | 559 | bytes += 4; | ||
3359 | 560 | |||
3360 | 561 | /* TODO: Verify that 4k is the max message size from rild. | ||
3361 | 562 | * | ||
3362 | 563 | * These conditions shouldn't happen. If it does | ||
3363 | 564 | * there are three options: | ||
3364 | 565 | * | ||
3365 | 566 | * 1) ASSERT; ofono will restart via DBus | ||
3366 | 567 | * 2) Consume the bytes & continue | ||
3367 | 568 | * 3) force a disconnect | ||
3368 | 569 | */ | ||
3369 | 570 | g_assert(plen >= 8 && plen <= 4092); | ||
3370 | 571 | |||
3371 | 572 | /* If we don't have the whole fixed record in the ringbuffer | ||
3372 | 573 | * then return NULL & leave ringbuffer as is. | ||
3373 | 574 | */ | ||
3374 | 575 | |||
3375 | 576 | message_len = *len - 4; | ||
3376 | 577 | if (message_len < plen) { | ||
3377 | 578 | return NULL; | ||
3378 | 579 | } | ||
3379 | 580 | |||
3380 | 581 | /* FIXME: add check for message_len = 0? */ | ||
3381 | 582 | |||
3382 | 583 | message = g_try_malloc(sizeof(struct ril_msg)); | ||
3383 | 584 | g_assert(message != NULL); | ||
3384 | 585 | |||
3385 | 586 | /* allocate ril_msg->buffer */ | ||
3386 | 587 | message->buf_len = plen; | ||
3387 | 588 | message->buf = g_try_malloc(plen); | ||
3388 | 589 | g_assert(message->buf != NULL); | ||
3389 | 590 | |||
3390 | 591 | /* Copy bytes into message buffer */ | ||
3391 | 592 | memmove(message->buf, (const void *) bytes, plen); | ||
3392 | 593 | |||
3393 | 594 | /* Indicate to caller size of record we extracted */ | ||
3394 | 595 | *len = plen + 4; | ||
3395 | 596 | return message; | ||
3396 | 597 | } | ||
3397 | 598 | |||
3398 | 599 | static void new_bytes(struct ring_buffer *rbuf, gpointer user_data) | ||
3399 | 600 | { | ||
3400 | 601 | struct ril_msg *message; | ||
3401 | 602 | struct ril_s *p = user_data; | ||
3402 | 603 | unsigned int len = ring_buffer_len(rbuf); | ||
3403 | 604 | unsigned int wrap = ring_buffer_len_no_wrap(rbuf); | ||
3404 | 605 | guchar *buf = ring_buffer_read_ptr(rbuf, p->read_so_far); | ||
3405 | 606 | |||
3406 | 607 | p->in_read_handler = TRUE; | ||
3407 | 608 | |||
3408 | 609 | DBG("len: %d, wrap: %d", len, wrap); | ||
3409 | 610 | |||
3410 | 611 | while (p->suspended == FALSE && (p->read_so_far < len)) { | ||
3411 | 612 | gsize rbytes = MIN(len - p->read_so_far, wrap - p->read_so_far); | ||
3412 | 613 | |||
3413 | 614 | if (rbytes < 4) { | ||
3414 | 615 | DBG("Not enough bytes for header length: len: %d", len); | ||
3415 | 616 | return; | ||
3416 | 617 | } | ||
3417 | 618 | |||
3418 | 619 | /* this function attempts to read the next full length | ||
3419 | 620 | * fixed message from the stream. if not all bytes are | ||
3420 | 621 | * available, it returns NULL. otherwise it allocates | ||
3421 | 622 | * and returns a ril_message with the copied bytes, and | ||
3422 | 623 | * drains those bytes from the ring_buffer | ||
3423 | 624 | */ | ||
3424 | 625 | message = read_fixed_record(p, buf, &rbytes); | ||
3425 | 626 | |||
3426 | 627 | /* wait for the rest of the record... */ | ||
3427 | 628 | if (message == NULL) { | ||
3428 | 629 | DBG("Not enough bytes for fixed record"); | ||
3429 | 630 | break; | ||
3430 | 631 | } | ||
3431 | 632 | |||
3432 | 633 | buf += rbytes; | ||
3433 | 634 | p->read_so_far += rbytes; | ||
3434 | 635 | |||
3435 | 636 | /* TODO: need to better understand how wrap works! */ | ||
3436 | 637 | if (p->read_so_far == wrap) { | ||
3437 | 638 | buf = ring_buffer_read_ptr(rbuf, p->read_so_far); | ||
3438 | 639 | wrap = len; | ||
3439 | 640 | } | ||
3440 | 641 | |||
3441 | 642 | dispatch(p, message); | ||
3442 | 643 | |||
3443 | 644 | ring_buffer_drain(rbuf, p->read_so_far); | ||
3444 | 645 | |||
3445 | 646 | len -= p->read_so_far; | ||
3446 | 647 | wrap -= p->read_so_far; | ||
3447 | 648 | p->read_so_far = 0; | ||
3448 | 649 | } | ||
3449 | 650 | |||
3450 | 651 | p->in_read_handler = FALSE; | ||
3451 | 652 | |||
3452 | 653 | if (p->destroyed) | ||
3453 | 654 | g_free(p); | ||
3454 | 655 | } | ||
3455 | 656 | |||
3456 | 657 | static gboolean can_write_data(gpointer data) | ||
3457 | 658 | { | ||
3458 | 659 | struct ril_s *ril = data; | ||
3459 | 660 | struct ril_request *req; | ||
3460 | 661 | gsize bytes_written; | ||
3461 | 662 | gsize towrite; | ||
3462 | 663 | gsize len; | ||
3463 | 664 | |||
3464 | 665 | /* Grab the first command off the queue and write as | ||
3465 | 666 | * much of it as we can | ||
3466 | 667 | */ | ||
3467 | 668 | req = g_queue_peek_head(ril->command_queue); | ||
3468 | 669 | |||
3469 | 670 | /* For some reason command queue is empty, cancel write watcher */ | ||
3470 | 671 | if (req == NULL) | ||
3471 | 672 | return FALSE; | ||
3472 | 673 | |||
3473 | 674 | len = req->req_len; | ||
3474 | 675 | DBG("len: %d, req_bytes_written: %d", len, ril->req_bytes_written); | ||
3475 | 676 | |||
3476 | 677 | /* For some reason write watcher fired, but we've already | ||
3477 | 678 | * written the entire command out to the io channel, | ||
3478 | 679 | * cancel write watcher | ||
3479 | 680 | */ | ||
3480 | 681 | if (ril->req_bytes_written >= len) | ||
3481 | 682 | return FALSE; | ||
3482 | 683 | |||
3483 | 684 | /* | ||
3484 | 685 | * AT modems need to be woken up via a command set by the | ||
3485 | 686 | * upper layers. RIL has no such concept, hence wakeup needed | ||
3486 | 687 | * NOTE - I'm keeping the if statement here commented out, just | ||
3487 | 688 | * in case this concept needs to be added back in... | ||
3488 | 689 | * | ||
3489 | 690 | * if (ril->req_bytes_written == 0 && wakeup_first == TRUE) { | ||
3490 | 691 | * cmd = at_command_create(0, chat->wakeup, none_prefix, 0, | ||
3491 | 692 | * NULL, wakeup_cb, chat, NULL, TRUE); | ||
3492 | 693 | * g_queue_push_head(chat->command_queue, cmd); | ||
3493 | 694 | * len = strlen(chat->wakeup); | ||
3494 | 695 | * chat->timeout_source = g_timeout_add(chat->wakeup_timeout, | ||
3495 | 696 | * wakeup_no_response, chat); | ||
3496 | 697 | * } | ||
3497 | 698 | */ | ||
3498 | 699 | |||
3499 | 700 | towrite = len - ril->req_bytes_written; | ||
3500 | 701 | |||
3501 | 702 | #ifdef WRITE_SCHEDULER_DEBUG | ||
3502 | 703 | if (towrite > 5) | ||
3503 | 704 | towrite = 5; | ||
3504 | 705 | #endif | ||
3505 | 706 | |||
3506 | 707 | bytes_written = g_ril_io_write(ril->io, | ||
3507 | 708 | req->req + ril->req_bytes_written, | ||
3508 | 709 | towrite); | ||
3509 | 710 | |||
3510 | 711 | DBG("bytes_written: %d", bytes_written); | ||
3511 | 712 | |||
3512 | 713 | if (bytes_written == 0) | ||
3513 | 714 | return FALSE; | ||
3514 | 715 | |||
3515 | 716 | ril->req_bytes_written += bytes_written; | ||
3516 | 717 | if (bytes_written < towrite) | ||
3517 | 718 | return TRUE; | ||
3518 | 719 | |||
3519 | 720 | return FALSE; | ||
3520 | 721 | } | ||
3521 | 722 | |||
3522 | 723 | static void ril_wakeup_writer(struct ril_s *ril) | ||
3523 | 724 | { | ||
3524 | 725 | g_ril_io_set_write_handler(ril->io, can_write_data, ril); | ||
3525 | 726 | } | ||
3526 | 727 | |||
3527 | 728 | static void ril_suspend(struct ril_s *ril) | ||
3528 | 729 | { | ||
3529 | 730 | ril->suspended = TRUE; | ||
3530 | 731 | |||
3531 | 732 | g_ril_io_set_write_handler(ril->io, NULL, NULL); | ||
3532 | 733 | g_ril_io_set_read_handler(ril->io, NULL, NULL); | ||
3533 | 734 | g_ril_io_set_debug(ril->io, NULL, NULL); | ||
3534 | 735 | } | ||
3535 | 736 | |||
3536 | 737 | /* | ||
3537 | 738 | * TODO: need to determine when ril_resume/suspend are called. | ||
3538 | 739 | * | ||
3539 | 740 | * Most likely, this is in response to DBUS messages sent to | ||
3540 | 741 | * oFono to tell it the system is suspending/resuming. | ||
3541 | 742 | */ | ||
3542 | 743 | static void ril_resume(struct ril_s *ril) | ||
3543 | 744 | { | ||
3544 | 745 | ril->suspended = FALSE; | ||
3545 | 746 | |||
3546 | 747 | if (g_ril_io_get_channel(ril->io) == NULL) { | ||
3547 | 748 | io_disconnect(ril); | ||
3548 | 749 | return; | ||
3549 | 750 | } | ||
3550 | 751 | |||
3551 | 752 | g_ril_io_set_disconnect_function(ril->io, io_disconnect, ril); | ||
3552 | 753 | |||
3553 | 754 | g_ril_io_set_debug(ril->io, ril->debugf, ril->debug_data); | ||
3554 | 755 | |||
3555 | 756 | g_ril_io_set_read_handler(ril->io, new_bytes, ril); | ||
3556 | 757 | |||
3557 | 758 | if (g_queue_get_length(ril->command_queue) > 0) | ||
3558 | 759 | ril_wakeup_writer(ril); | ||
3559 | 760 | } | ||
3560 | 761 | |||
3561 | 762 | static gboolean ril_set_debug(struct ril_s *ril, | ||
3562 | 763 | GRilDebugFunc func, gpointer user_data) | ||
3563 | 764 | { | ||
3564 | 765 | |||
3565 | 766 | ril->debugf = func; | ||
3566 | 767 | ril->debug_data = user_data; | ||
3567 | 768 | |||
3568 | 769 | if (ril->io) | ||
3569 | 770 | g_ril_io_set_debug(ril->io, func, user_data); | ||
3570 | 771 | |||
3571 | 772 | return TRUE; | ||
3572 | 773 | } | ||
3573 | 774 | |||
3574 | 775 | static void ril_unref(struct ril_s *ril) | ||
3575 | 776 | { | ||
3576 | 777 | gboolean is_zero; | ||
3577 | 778 | |||
3578 | 779 | is_zero = g_atomic_int_dec_and_test(&ril->ref_count); | ||
3579 | 780 | |||
3580 | 781 | if (is_zero == FALSE) | ||
3581 | 782 | return; | ||
3582 | 783 | |||
3583 | 784 | if (ril->io) { | ||
3584 | 785 | ril_suspend(ril); | ||
3585 | 786 | g_ril_io_unref(ril->io); | ||
3586 | 787 | ril->io = NULL; | ||
3587 | 788 | ril_cleanup(ril); | ||
3588 | 789 | } | ||
3589 | 790 | |||
3590 | 791 | if (ril->in_read_handler) | ||
3591 | 792 | ril->destroyed = TRUE; | ||
3592 | 793 | else | ||
3593 | 794 | g_free(ril); | ||
3594 | 795 | } | ||
3595 | 796 | |||
3596 | 797 | static gboolean node_compare_by_group(struct ril_notify_node *node, | ||
3597 | 798 | gpointer userdata) | ||
3598 | 799 | { | ||
3599 | 800 | guint group = GPOINTER_TO_UINT(userdata); | ||
3600 | 801 | |||
3601 | 802 | if (node->gid == group) | ||
3602 | 803 | return TRUE; | ||
3603 | 804 | |||
3604 | 805 | return FALSE; | ||
3605 | 806 | } | ||
3606 | 807 | |||
3607 | 808 | static struct ril_s *create_ril() | ||
3608 | 809 | |||
3609 | 810 | { | ||
3610 | 811 | struct ril_s *ril; | ||
3611 | 812 | struct sockaddr_un addr; | ||
3612 | 813 | int sk; | ||
3613 | 814 | GIOChannel *io; | ||
3614 | 815 | |||
3615 | 816 | ril = g_try_new0(struct ril_s, 1); | ||
3616 | 817 | if (ril == NULL) | ||
3617 | 818 | return ril; | ||
3618 | 819 | |||
3619 | 820 | ril->ref_count = 1; | ||
3620 | 821 | ril->next_cmd_id = 1; | ||
3621 | 822 | ril->next_notify_id = 1; | ||
3622 | 823 | ril->next_gid = 0; | ||
3623 | 824 | ril->debugf = NULL; | ||
3624 | 825 | ril->req_bytes_written = 0; | ||
3625 | 826 | |||
3626 | 827 | sk = socket(AF_UNIX, SOCK_STREAM, 0); | ||
3627 | 828 | if (sk < 0) { | ||
3628 | 829 | ofono_error("create_ril: can't create unix socket: %s (%d)\n", | ||
3629 | 830 | strerror(errno), errno); | ||
3630 | 831 | goto error; | ||
3631 | 832 | } | ||
3632 | 833 | |||
3633 | 834 | memset(&addr, 0, sizeof(addr)); | ||
3634 | 835 | addr.sun_family = AF_UNIX; | ||
3635 | 836 | strncpy(addr.sun_path, RILD_CMD_SOCKET, sizeof(addr.sun_path) - 1); | ||
3636 | 837 | |||
3637 | 838 | if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { | ||
3638 | 839 | ofono_error("create_ril: can't connect to RILD: %s (%d)\n", | ||
3639 | 840 | strerror(errno), errno); | ||
3640 | 841 | goto error; | ||
3641 | 842 | } | ||
3642 | 843 | |||
3643 | 844 | io = g_io_channel_unix_new(sk); | ||
3644 | 845 | if (io == NULL) { | ||
3645 | 846 | ofono_error("create_ril: can't connect to RILD: %s (%d)\n", | ||
3646 | 847 | strerror(errno), errno); | ||
3647 | 848 | return NULL; | ||
3648 | 849 | } | ||
3649 | 850 | |||
3650 | 851 | g_io_channel_set_buffered(io, FALSE); | ||
3651 | 852 | g_io_channel_set_encoding(io, NULL, NULL); | ||
3652 | 853 | g_io_channel_set_close_on_unref(io, TRUE); | ||
3653 | 854 | g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL); | ||
3654 | 855 | |||
3655 | 856 | ril->io = g_ril_io_new(io); | ||
3656 | 857 | if (ril->io == NULL) { | ||
3657 | 858 | ofono_error("create_ril: can't create ril->io"); | ||
3658 | 859 | goto error; | ||
3659 | 860 | } | ||
3660 | 861 | |||
3661 | 862 | g_ril_io_set_disconnect_function(ril->io, io_disconnect, ril); | ||
3662 | 863 | |||
3663 | 864 | ril->command_queue = g_queue_new(); | ||
3664 | 865 | if (ril->command_queue == NULL) { | ||
3665 | 866 | ofono_error("create_ril: Couldn't create command_queue."); | ||
3666 | 867 | goto error; | ||
3667 | 868 | } | ||
3668 | 869 | |||
3669 | 870 | ril->notify_list = g_hash_table_new_full(g_int_hash, g_int_equal, | ||
3670 | 871 | g_free, ril_notify_destroy); | ||
3671 | 872 | |||
3672 | 873 | g_ril_io_set_read_handler(ril->io, new_bytes, ril); | ||
3673 | 874 | |||
3674 | 875 | return ril; | ||
3675 | 876 | |||
3676 | 877 | error: | ||
3677 | 878 | g_ril_io_unref(ril->io); | ||
3678 | 879 | |||
3679 | 880 | if (ril->command_queue) | ||
3680 | 881 | g_queue_free(ril->command_queue); | ||
3681 | 882 | |||
3682 | 883 | if (ril->notify_list) | ||
3683 | 884 | g_hash_table_destroy(ril->notify_list); | ||
3684 | 885 | |||
3685 | 886 | g_free(ril); | ||
3686 | 887 | return NULL; | ||
3687 | 888 | } | ||
3688 | 889 | |||
3689 | 890 | static struct ril_notify *ril_notify_create(struct ril_s *ril, | ||
3690 | 891 | const int req) | ||
3691 | 892 | { | ||
3692 | 893 | struct ril_notify *notify; | ||
3693 | 894 | int *key; | ||
3694 | 895 | |||
3695 | 896 | notify = g_try_new0(struct ril_notify, 1); | ||
3696 | 897 | if (notify == NULL) | ||
3697 | 898 | return 0; | ||
3698 | 899 | |||
3699 | 900 | key = g_try_new0(int, 1); | ||
3700 | 901 | if (key == NULL) | ||
3701 | 902 | return 0; | ||
3702 | 903 | |||
3703 | 904 | *key = req; | ||
3704 | 905 | |||
3705 | 906 | g_hash_table_insert(ril->notify_list, key, notify); | ||
3706 | 907 | |||
3707 | 908 | return notify; | ||
3708 | 909 | } | ||
3709 | 910 | |||
3710 | 911 | static guint ril_register(struct ril_s *ril, guint group, | ||
3711 | 912 | const int req, GRilNotifyFunc func, | ||
3712 | 913 | gpointer user_data) | ||
3713 | 914 | { | ||
3714 | 915 | struct ril_notify *notify; | ||
3715 | 916 | struct ril_notify_node *node; | ||
3716 | 917 | |||
3717 | 918 | if (ril->notify_list == NULL) | ||
3718 | 919 | return 0; | ||
3719 | 920 | |||
3720 | 921 | if (func == NULL) | ||
3721 | 922 | return 0; | ||
3722 | 923 | |||
3723 | 924 | notify = g_hash_table_lookup(ril->notify_list, &req); | ||
3724 | 925 | |||
3725 | 926 | if (notify == NULL) | ||
3726 | 927 | notify = ril_notify_create(ril, req); | ||
3727 | 928 | |||
3728 | 929 | if (notify == NULL) | ||
3729 | 930 | return 0; | ||
3730 | 931 | |||
3731 | 932 | node = g_try_new0(struct ril_notify_node, 1); | ||
3732 | 933 | if (node == NULL) | ||
3733 | 934 | return 0; | ||
3734 | 935 | |||
3735 | 936 | node->id = ril->next_notify_id++; | ||
3736 | 937 | node->gid = group; | ||
3737 | 938 | node->callback = func; | ||
3738 | 939 | node->user_data = user_data; | ||
3739 | 940 | |||
3740 | 941 | notify->nodes = g_slist_prepend(notify->nodes, node); | ||
3741 | 942 | DBG("after pre-pend; notify: %x, node %x, notify->nodes: %x, callback: %x", | ||
3742 | 943 | notify, node, notify->nodes, node->callback); | ||
3743 | 944 | |||
3744 | 945 | return node->id; | ||
3745 | 946 | } | ||
3746 | 947 | |||
3747 | 948 | static gboolean ril_unregister(struct ril_s *ril, gboolean mark_only, | ||
3748 | 949 | guint group, guint id) | ||
3749 | 950 | { | ||
3750 | 951 | GHashTableIter iter; | ||
3751 | 952 | struct ril_notify *notify; | ||
3752 | 953 | struct ril_notify_node *node; | ||
3753 | 954 | gpointer key, value; | ||
3754 | 955 | GSList *l; | ||
3755 | 956 | |||
3756 | 957 | if (ril->notify_list == NULL) | ||
3757 | 958 | return FALSE; | ||
3758 | 959 | |||
3759 | 960 | g_hash_table_iter_init(&iter, ril->notify_list); | ||
3760 | 961 | |||
3761 | 962 | while (g_hash_table_iter_next(&iter, &key, &value)) { | ||
3762 | 963 | notify = value; | ||
3763 | 964 | |||
3764 | 965 | l = g_slist_find_custom(notify->nodes, GUINT_TO_POINTER(id), | ||
3765 | 966 | ril_notify_node_compare_by_id); | ||
3766 | 967 | |||
3767 | 968 | if (l == NULL) | ||
3768 | 969 | continue; | ||
3769 | 970 | |||
3770 | 971 | node = l->data; | ||
3771 | 972 | |||
3772 | 973 | if (node->gid != group) | ||
3773 | 974 | return FALSE; | ||
3774 | 975 | |||
3775 | 976 | if (mark_only) { | ||
3776 | 977 | node->destroyed = TRUE; | ||
3777 | 978 | return TRUE; | ||
3778 | 979 | } | ||
3779 | 980 | |||
3780 | 981 | ril_notify_node_destroy(node, NULL); | ||
3781 | 982 | notify->nodes = g_slist_remove(notify->nodes, node); | ||
3782 | 983 | |||
3783 | 984 | if (notify->nodes == NULL) | ||
3784 | 985 | g_hash_table_iter_remove(&iter); | ||
3785 | 986 | |||
3786 | 987 | return TRUE; | ||
3787 | 988 | } | ||
3788 | 989 | |||
3789 | 990 | return FALSE; | ||
3790 | 991 | } | ||
3791 | 992 | |||
3792 | 993 | GRil *g_ril_new() | ||
3793 | 994 | { | ||
3794 | 995 | GRil *ril; | ||
3795 | 996 | |||
3796 | 997 | ril = g_try_new0(GRil, 1); | ||
3797 | 998 | if (ril == NULL) | ||
3798 | 999 | return NULL; | ||
3799 | 1000 | |||
3800 | 1001 | ril->parent = create_ril(); | ||
3801 | 1002 | if (ril->parent == NULL) { | ||
3802 | 1003 | g_free(ril); | ||
3803 | 1004 | return NULL; | ||
3804 | 1005 | } | ||
3805 | 1006 | |||
3806 | 1007 | ril->group = ril->parent->next_gid++; | ||
3807 | 1008 | ril->ref_count = 1; | ||
3808 | 1009 | |||
3809 | 1010 | return ril; | ||
3810 | 1011 | } | ||
3811 | 1012 | |||
3812 | 1013 | GRil *g_ril_clone(GRil *clone) | ||
3813 | 1014 | { | ||
3814 | 1015 | GRil *ril; | ||
3815 | 1016 | |||
3816 | 1017 | if (clone == NULL) | ||
3817 | 1018 | return NULL; | ||
3818 | 1019 | |||
3819 | 1020 | ril = g_try_new0(GRil, 1); | ||
3820 | 1021 | if (ril == NULL) | ||
3821 | 1022 | return NULL; | ||
3822 | 1023 | |||
3823 | 1024 | ril->parent = clone->parent; | ||
3824 | 1025 | ril->group = ril->parent->next_gid++; | ||
3825 | 1026 | ril->ref_count = 1; | ||
3826 | 1027 | g_atomic_int_inc(&ril->parent->ref_count); | ||
3827 | 1028 | |||
3828 | 1029 | return ril; | ||
3829 | 1030 | } | ||
3830 | 1031 | |||
3831 | 1032 | GIOChannel *g_ril_get_channel(GRil *ril) | ||
3832 | 1033 | { | ||
3833 | 1034 | if (ril == NULL || ril->parent->io == NULL) | ||
3834 | 1035 | return NULL; | ||
3835 | 1036 | |||
3836 | 1037 | return g_ril_io_get_channel(ril->parent->io); | ||
3837 | 1038 | |||
3838 | 1039 | } | ||
3839 | 1040 | |||
3840 | 1041 | GRilIO *g_ril_get_io(GRil *ril) | ||
3841 | 1042 | { | ||
3842 | 1043 | if (ril == NULL) | ||
3843 | 1044 | return NULL; | ||
3844 | 1045 | |||
3845 | 1046 | return ril->parent->io; | ||
3846 | 1047 | } | ||
3847 | 1048 | |||
3848 | 1049 | GRil *g_ril_ref(GRil *ril) | ||
3849 | 1050 | { | ||
3850 | 1051 | if (ril == NULL) | ||
3851 | 1052 | return NULL; | ||
3852 | 1053 | |||
3853 | 1054 | g_atomic_int_inc(&ril->ref_count); | ||
3854 | 1055 | |||
3855 | 1056 | return ril; | ||
3856 | 1057 | } | ||
3857 | 1058 | |||
3858 | 1059 | guint g_ril_send(GRil *ril, const guint req, const char *data, | ||
3859 | 1060 | const gsize data_len, GRilResponseFunc func, | ||
3860 | 1061 | gpointer user_data, GDestroyNotify notify) | ||
3861 | 1062 | { | ||
3862 | 1063 | struct ril_request *r; | ||
3863 | 1064 | struct ril_s *p; | ||
3864 | 1065 | |||
3865 | 1066 | if (ril == NULL || ril->parent == NULL || ril->parent->command_queue == NULL) | ||
3866 | 1067 | return 0; | ||
3867 | 1068 | |||
3868 | 1069 | p = ril->parent; | ||
3869 | 1070 | |||
3870 | 1071 | r = ril_request_create(p, ril->group, req, p->next_cmd_id, | ||
3871 | 1072 | data, data_len, func, | ||
3872 | 1073 | user_data, notify, FALSE); | ||
3873 | 1074 | if (r == NULL) | ||
3874 | 1075 | return 0; | ||
3875 | 1076 | |||
3876 | 1077 | p->next_cmd_id++; | ||
3877 | 1078 | |||
3878 | 1079 | g_queue_push_tail(p->command_queue, r); | ||
3879 | 1080 | |||
3880 | 1081 | if (g_queue_get_length(p->command_queue) == 1) { | ||
3881 | 1082 | DBG("calling wakeup_writer: qlen: %d", g_queue_get_length(p->command_queue)); | ||
3882 | 1083 | ril_wakeup_writer(p); | ||
3883 | 1084 | } | ||
3884 | 1085 | |||
3885 | 1086 | return r->id; | ||
3886 | 1087 | } | ||
3887 | 1088 | |||
3888 | 1089 | void g_ril_suspend(GRil *ril) | ||
3889 | 1090 | { | ||
3890 | 1091 | if (ril == NULL) | ||
3891 | 1092 | return; | ||
3892 | 1093 | |||
3893 | 1094 | ril_suspend(ril->parent); | ||
3894 | 1095 | } | ||
3895 | 1096 | |||
3896 | 1097 | void g_ril_resume(GRil *ril) | ||
3897 | 1098 | { | ||
3898 | 1099 | if (ril == NULL) | ||
3899 | 1100 | return; | ||
3900 | 1101 | |||
3901 | 1102 | ril_resume(ril->parent); | ||
3902 | 1103 | } | ||
3903 | 1104 | |||
3904 | 1105 | void g_ril_unref(GRil *ril) | ||
3905 | 1106 | { | ||
3906 | 1107 | gboolean is_zero; | ||
3907 | 1108 | |||
3908 | 1109 | if (ril == NULL) | ||
3909 | 1110 | return; | ||
3910 | 1111 | |||
3911 | 1112 | is_zero = g_atomic_int_dec_and_test(&ril->ref_count); | ||
3912 | 1113 | |||
3913 | 1114 | if (is_zero == FALSE) | ||
3914 | 1115 | return; | ||
3915 | 1116 | |||
3916 | 1117 | ril_unref(ril->parent); | ||
3917 | 1118 | |||
3918 | 1119 | g_free(ril); | ||
3919 | 1120 | } | ||
3920 | 1121 | |||
3921 | 1122 | gboolean g_ril_set_debug(GRil *ril, | ||
3922 | 1123 | GRilDebugFunc func, gpointer user_data) | ||
3923 | 1124 | { | ||
3924 | 1125 | |||
3925 | 1126 | if (ril == NULL || ril->group != 0) | ||
3926 | 1127 | return FALSE; | ||
3927 | 1128 | |||
3928 | 1129 | return ril_set_debug(ril->parent, func, user_data); | ||
3929 | 1130 | } | ||
3930 | 1131 | |||
3931 | 1132 | guint g_ril_register(GRil *ril, const int req, | ||
3932 | 1133 | GRilNotifyFunc func, gpointer user_data) | ||
3933 | 1134 | { | ||
3934 | 1135 | if (ril == NULL) | ||
3935 | 1136 | return 0; | ||
3936 | 1137 | |||
3937 | 1138 | return ril_register(ril->parent, ril->group, req, | ||
3938 | 1139 | func, user_data); | ||
3939 | 1140 | } | ||
3940 | 1141 | |||
3941 | 1142 | gboolean g_ril_unregister(GRil *ril, guint id) | ||
3942 | 1143 | { | ||
3943 | 1144 | if (ril == NULL) | ||
3944 | 1145 | return FALSE; | ||
3945 | 1146 | |||
3946 | 1147 | return ril_unregister(ril->parent, ril->parent->in_notify, | ||
3947 | 1148 | ril->group, id); | ||
3948 | 1149 | } | ||
3949 | 1150 | |||
3950 | 1151 | gboolean g_ril_unregister_all(GRil *ril) | ||
3951 | 1152 | { | ||
3952 | 1153 | if (ril == NULL) | ||
3953 | 1154 | return FALSE; | ||
3954 | 1155 | |||
3955 | 1156 | return ril_unregister_all(ril->parent, | ||
3956 | 1157 | ril->parent->in_notify, | ||
3957 | 1158 | node_compare_by_group, | ||
3958 | 1159 | GUINT_TO_POINTER(ril->group)); | ||
3959 | 1160 | } | ||
3960 | 0 | 1161 | ||
3961 | === added file 'gril/gril.h' | |||
3962 | --- gril/gril.h 1970-01-01 00:00:00 +0000 | |||
3963 | +++ gril/gril.h 2013-04-09 20:01:20 +0000 | |||
3964 | @@ -0,0 +1,102 @@ | |||
3965 | 1 | /* | ||
3966 | 2 | * | ||
3967 | 3 | * RIL library with GLib integration | ||
3968 | 4 | * | ||
3969 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
3970 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
3971 | 7 | * | ||
3972 | 8 | * This program is free software; you can redistribute it and/or modify | ||
3973 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
3974 | 10 | * published by the Free Software Foundation. | ||
3975 | 11 | * | ||
3976 | 12 | * This program is distributed in the hope that it will be useful, | ||
3977 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3978 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3979 | 15 | * GNU General Public License for more details. | ||
3980 | 16 | * | ||
3981 | 17 | * You should have received a copy of the GNU General Public License | ||
3982 | 18 | * along with this program; if not, write to the Free Software | ||
3983 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
3984 | 20 | * | ||
3985 | 21 | */ | ||
3986 | 22 | |||
3987 | 23 | #ifndef __GRIL_H | ||
3988 | 24 | #define __GRIL_H | ||
3989 | 25 | |||
3990 | 26 | #ifdef __cplusplus | ||
3991 | 27 | extern "C" { | ||
3992 | 28 | #endif | ||
3993 | 29 | |||
3994 | 30 | #include "grilresponse.h" | ||
3995 | 31 | #include "grilutil.h" | ||
3996 | 32 | #include "grilio.h" | ||
3997 | 33 | #include "ril_constants.h" | ||
3998 | 34 | |||
3999 | 35 | struct _GRil; | ||
4000 | 36 | |||
4001 | 37 | typedef struct _GRil GRil; | ||
4002 | 38 | |||
4003 | 39 | /* | ||
4004 | 40 | * This struct represents an entire RIL message read | ||
4005 | 41 | * from the command socket. It can hold responses or | ||
4006 | 42 | * unsolicited requests from RILD. | ||
4007 | 43 | */ | ||
4008 | 44 | struct ril_msg { | ||
4009 | 45 | gchar *buf; | ||
4010 | 46 | gsize buf_len; | ||
4011 | 47 | gboolean unsolicited; | ||
4012 | 48 | int req; | ||
4013 | 49 | int serial_no; | ||
4014 | 50 | int error; | ||
4015 | 51 | }; | ||
4016 | 52 | |||
4017 | 53 | typedef void (*GRilResponseFunc)(struct ril_msg *message, gpointer user_data); | ||
4018 | 54 | |||
4019 | 55 | typedef void (*GRilNotifyFunc)(struct ril_msg *message, gpointer user_data); | ||
4020 | 56 | |||
4021 | 57 | GRil *g_ril_new(); | ||
4022 | 58 | |||
4023 | 59 | GIOChannel *g_ril_get_channel(GRil *ril); | ||
4024 | 60 | GRilIO *g_ril_get_io(GRil *ril); | ||
4025 | 61 | |||
4026 | 62 | GRil *g_ril_ref(GRil *ril); | ||
4027 | 63 | void g_ril_unref(GRil *ril); | ||
4028 | 64 | |||
4029 | 65 | GRil *g_ril_clone(GRil *ril); | ||
4030 | 66 | |||
4031 | 67 | void g_ril_suspend(GRil *ril); | ||
4032 | 68 | void g_ril_resume(GRil *ril); | ||
4033 | 69 | |||
4034 | 70 | gboolean g_ril_set_disconnect_function(GRil *ril, GRilDisconnectFunc disconnect, | ||
4035 | 71 | gpointer user_data); | ||
4036 | 72 | |||
4037 | 73 | /*! | ||
4038 | 74 | * If the function is not NULL, then on every read/write from the GIOChannel | ||
4039 | 75 | * provided to GRil the logging function will be called with the | ||
4040 | 76 | * input/output string and user data | ||
4041 | 77 | */ | ||
4042 | 78 | gboolean g_ril_set_debug(GRil *ril, GRilDebugFunc func, gpointer user_data); | ||
4043 | 79 | |||
4044 | 80 | /*! | ||
4045 | 81 | * Queue an RIL request for execution. The request contents are given | ||
4046 | 82 | * in data. Once the command executes, the callback function given by | ||
4047 | 83 | * func is called with user provided data in user_data. | ||
4048 | 84 | * | ||
4049 | 85 | * Returns an id of the queued command which can be canceled using | ||
4050 | 86 | * g_ril_cancel. If an error occurred, an id of 0 is returned. | ||
4051 | 87 | * | ||
4052 | 88 | */ | ||
4053 | 89 | guint g_ril_send(GRil *ril, const guint req, const char *data, const gsize data_len, | ||
4054 | 90 | GRilResponseFunc func, gpointer user_data, GDestroyNotify notify); | ||
4055 | 91 | |||
4056 | 92 | guint g_ril_register(GRil *ril, const int req, | ||
4057 | 93 | GRilNotifyFunc func, gpointer user_data); | ||
4058 | 94 | |||
4059 | 95 | gboolean g_ril_unregister(GRil *ril, guint id); | ||
4060 | 96 | gboolean g_ril_unregister_all(GRil *ril); | ||
4061 | 97 | |||
4062 | 98 | #ifdef __cplusplus | ||
4063 | 99 | } | ||
4064 | 100 | #endif | ||
4065 | 101 | |||
4066 | 102 | #endif /* __GRIL_H */ | ||
4067 | 0 | 103 | ||
4068 | === added file 'gril/grilio.c' | |||
4069 | --- gril/grilio.c 1970-01-01 00:00:00 +0000 | |||
4070 | +++ gril/grilio.c 2013-04-09 20:01:20 +0000 | |||
4071 | @@ -0,0 +1,396 @@ | |||
4072 | 1 | /* | ||
4073 | 2 | * | ||
4074 | 3 | * RIL chat library with GLib integration | ||
4075 | 4 | * | ||
4076 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
4077 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
4078 | 7 | * | ||
4079 | 8 | * This program is free software; you can redistribute it and/or modify | ||
4080 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
4081 | 10 | * published by the Free Software Foundation. | ||
4082 | 11 | * | ||
4083 | 12 | * This program is distributed in the hope that it will be useful, | ||
4084 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4085 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4086 | 15 | * GNU General Public License for more details. | ||
4087 | 16 | * | ||
4088 | 17 | * You should have received a copy of the GNU General Public License | ||
4089 | 18 | * along with this program; if not, write to the Free Software | ||
4090 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
4091 | 20 | * | ||
4092 | 21 | */ | ||
4093 | 22 | |||
4094 | 23 | #ifdef HAVE_CONFIG_H | ||
4095 | 24 | #include <config.h> | ||
4096 | 25 | #endif | ||
4097 | 26 | |||
4098 | 27 | #include <stdio.h> | ||
4099 | 28 | #include <unistd.h> | ||
4100 | 29 | #include <string.h> | ||
4101 | 30 | #include <assert.h> | ||
4102 | 31 | #include <ctype.h> | ||
4103 | 32 | #include <errno.h> | ||
4104 | 33 | |||
4105 | 34 | #include <glib.h> | ||
4106 | 35 | |||
4107 | 36 | #include "ringbuffer.h" | ||
4108 | 37 | #include "grilio.h" | ||
4109 | 38 | #include "grilutil.h" | ||
4110 | 39 | |||
4111 | 40 | struct _GRilIO { | ||
4112 | 41 | gint ref_count; /* Ref count */ | ||
4113 | 42 | guint read_watch; /* GSource read id, 0 if no */ | ||
4114 | 43 | guint write_watch; /* GSource write id, 0 if no */ | ||
4115 | 44 | GIOChannel *channel; /* comms channel */ | ||
4116 | 45 | GRilDisconnectFunc user_disconnect; /* user disconnect func */ | ||
4117 | 46 | gpointer user_disconnect_data; /* user disconnect data */ | ||
4118 | 47 | struct ring_buffer *buf; /* Current read buffer */ | ||
4119 | 48 | guint max_read_attempts; /* max reads / select */ | ||
4120 | 49 | GRilIOReadFunc read_handler; /* Read callback */ | ||
4121 | 50 | gpointer read_data; /* Read callback userdata */ | ||
4122 | 51 | gboolean use_write_watch; /* Use write select */ | ||
4123 | 52 | GRilIOWriteFunc write_handler; /* Write callback */ | ||
4124 | 53 | gpointer write_data; /* Write callback userdata */ | ||
4125 | 54 | GRilDebugFunc debugf; /* debugging output function */ | ||
4126 | 55 | gpointer debug_data; /* Data to pass to debug func */ | ||
4127 | 56 | GRilDisconnectFunc write_done_func; /* tx empty notifier */ | ||
4128 | 57 | gpointer write_done_data; /* tx empty data */ | ||
4129 | 58 | gboolean destroyed; /* Re-entrancy guard */ | ||
4130 | 59 | }; | ||
4131 | 60 | |||
4132 | 61 | static void read_watcher_destroy_notify(gpointer user_data) | ||
4133 | 62 | { | ||
4134 | 63 | GRilIO *io = user_data; | ||
4135 | 64 | |||
4136 | 65 | ring_buffer_free(io->buf); | ||
4137 | 66 | io->buf = NULL; | ||
4138 | 67 | |||
4139 | 68 | io->debugf = NULL; | ||
4140 | 69 | io->debug_data = NULL; | ||
4141 | 70 | |||
4142 | 71 | io->read_watch = 0; | ||
4143 | 72 | io->read_handler = NULL; | ||
4144 | 73 | io->read_data = NULL; | ||
4145 | 74 | |||
4146 | 75 | io->channel = NULL; | ||
4147 | 76 | |||
4148 | 77 | if (io->destroyed) | ||
4149 | 78 | g_free(io); | ||
4150 | 79 | else if (io->user_disconnect) | ||
4151 | 80 | io->user_disconnect(io->user_disconnect_data); | ||
4152 | 81 | } | ||
4153 | 82 | |||
4154 | 83 | static gboolean received_data(GIOChannel *channel, GIOCondition cond, | ||
4155 | 84 | gpointer data) | ||
4156 | 85 | { | ||
4157 | 86 | unsigned char *buf; | ||
4158 | 87 | GRilIO *io = data; | ||
4159 | 88 | GIOStatus status; | ||
4160 | 89 | gsize rbytes; | ||
4161 | 90 | gsize toread; | ||
4162 | 91 | gsize total_read = 0; | ||
4163 | 92 | guint read_count = 0; | ||
4164 | 93 | |||
4165 | 94 | if (cond & G_IO_NVAL) | ||
4166 | 95 | return FALSE; | ||
4167 | 96 | |||
4168 | 97 | /* Regardless of condition, try to read all the data available */ | ||
4169 | 98 | do { | ||
4170 | 99 | toread = ring_buffer_avail_no_wrap(io->buf); | ||
4171 | 100 | |||
4172 | 101 | if (toread == 0) | ||
4173 | 102 | break; | ||
4174 | 103 | |||
4175 | 104 | rbytes = 0; | ||
4176 | 105 | buf = ring_buffer_write_ptr(io->buf, 0); | ||
4177 | 106 | |||
4178 | 107 | status = g_io_channel_read_chars(channel, (char *) buf, | ||
4179 | 108 | toread, &rbytes, NULL); | ||
4180 | 109 | |||
4181 | 110 | g_ril_util_debug_hexdump(TRUE, (char *)buf, rbytes, | ||
4182 | 111 | io->debugf, io->debug_data); | ||
4183 | 112 | |||
4184 | 113 | read_count++; | ||
4185 | 114 | |||
4186 | 115 | total_read += rbytes; | ||
4187 | 116 | |||
4188 | 117 | if (rbytes > 0) | ||
4189 | 118 | ring_buffer_write_advance(io->buf, rbytes); | ||
4190 | 119 | |||
4191 | 120 | } while (status == G_IO_STATUS_NORMAL && rbytes > 0 && | ||
4192 | 121 | read_count < io->max_read_attempts); | ||
4193 | 122 | |||
4194 | 123 | if (total_read > 0 && io->read_handler) | ||
4195 | 124 | io->read_handler(io->buf, io->read_data); | ||
4196 | 125 | |||
4197 | 126 | if (cond & (G_IO_HUP | G_IO_ERR)) | ||
4198 | 127 | return FALSE; | ||
4199 | 128 | |||
4200 | 129 | if (read_count > 0 && rbytes == 0 && status != G_IO_STATUS_AGAIN) | ||
4201 | 130 | return FALSE; | ||
4202 | 131 | |||
4203 | 132 | /* We're overflowing the buffer, shutdown the socket */ | ||
4204 | 133 | if (ring_buffer_avail(io->buf) == 0) | ||
4205 | 134 | return FALSE; | ||
4206 | 135 | |||
4207 | 136 | return TRUE; | ||
4208 | 137 | } | ||
4209 | 138 | |||
4210 | 139 | gsize g_ril_io_write(GRilIO *io, const gchar *data, gsize count) | ||
4211 | 140 | { | ||
4212 | 141 | GIOStatus status; | ||
4213 | 142 | gsize bytes_written; | ||
4214 | 143 | |||
4215 | 144 | status = g_io_channel_write_chars(io->channel, data, | ||
4216 | 145 | count, &bytes_written, NULL); | ||
4217 | 146 | |||
4218 | 147 | if (status != G_IO_STATUS_NORMAL) { | ||
4219 | 148 | g_source_remove(io->read_watch); | ||
4220 | 149 | return 0; | ||
4221 | 150 | } | ||
4222 | 151 | |||
4223 | 152 | g_ril_util_debug_hexdump(FALSE, data, bytes_written, | ||
4224 | 153 | io->debugf, io->debug_data); | ||
4225 | 154 | |||
4226 | 155 | return bytes_written; | ||
4227 | 156 | } | ||
4228 | 157 | |||
4229 | 158 | static void write_watcher_destroy_notify(gpointer user_data) | ||
4230 | 159 | { | ||
4231 | 160 | GRilIO *io = user_data; | ||
4232 | 161 | |||
4233 | 162 | io->write_watch = 0; | ||
4234 | 163 | io->write_handler = NULL; | ||
4235 | 164 | io->write_data = NULL; | ||
4236 | 165 | |||
4237 | 166 | if (io->write_done_func) { | ||
4238 | 167 | io->write_done_func(io->write_done_data); | ||
4239 | 168 | io->write_done_func = NULL; | ||
4240 | 169 | io->write_done_data = NULL; | ||
4241 | 170 | } | ||
4242 | 171 | } | ||
4243 | 172 | |||
4244 | 173 | static gboolean can_write_data(GIOChannel *channel, GIOCondition cond, | ||
4245 | 174 | gpointer data) | ||
4246 | 175 | { | ||
4247 | 176 | GRilIO *io = data; | ||
4248 | 177 | |||
4249 | 178 | if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) | ||
4250 | 179 | return FALSE; | ||
4251 | 180 | |||
4252 | 181 | if (io->write_handler == NULL) | ||
4253 | 182 | return FALSE; | ||
4254 | 183 | |||
4255 | 184 | return io->write_handler(io->write_data); | ||
4256 | 185 | } | ||
4257 | 186 | |||
4258 | 187 | static GRilIO *create_io(GIOChannel *channel, GIOFlags flags) | ||
4259 | 188 | { | ||
4260 | 189 | GRilIO *io; | ||
4261 | 190 | |||
4262 | 191 | if (channel == NULL) | ||
4263 | 192 | return NULL; | ||
4264 | 193 | |||
4265 | 194 | io = g_try_new0(GRilIO, 1); | ||
4266 | 195 | if (io == NULL) | ||
4267 | 196 | return io; | ||
4268 | 197 | |||
4269 | 198 | io->ref_count = 1; | ||
4270 | 199 | io->debugf = NULL; | ||
4271 | 200 | |||
4272 | 201 | if (flags & G_IO_FLAG_NONBLOCK) { | ||
4273 | 202 | io->max_read_attempts = 3; | ||
4274 | 203 | io->use_write_watch = TRUE; | ||
4275 | 204 | } else { | ||
4276 | 205 | io->max_read_attempts = 1; | ||
4277 | 206 | io->use_write_watch = FALSE; | ||
4278 | 207 | } | ||
4279 | 208 | |||
4280 | 209 | io->buf = ring_buffer_new(8192); | ||
4281 | 210 | |||
4282 | 211 | if (!io->buf) | ||
4283 | 212 | goto error; | ||
4284 | 213 | |||
4285 | 214 | if (!g_ril_util_setup_io(channel, flags)) | ||
4286 | 215 | goto error; | ||
4287 | 216 | |||
4288 | 217 | io->channel = channel; | ||
4289 | 218 | io->read_watch = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, | ||
4290 | 219 | G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, | ||
4291 | 220 | received_data, io, | ||
4292 | 221 | read_watcher_destroy_notify); | ||
4293 | 222 | |||
4294 | 223 | return io; | ||
4295 | 224 | |||
4296 | 225 | error: | ||
4297 | 226 | if (io->buf) | ||
4298 | 227 | ring_buffer_free(io->buf); | ||
4299 | 228 | |||
4300 | 229 | g_free(io); | ||
4301 | 230 | |||
4302 | 231 | return NULL; | ||
4303 | 232 | } | ||
4304 | 233 | |||
4305 | 234 | GRilIO *g_ril_io_new(GIOChannel *channel) | ||
4306 | 235 | { | ||
4307 | 236 | return create_io(channel, G_IO_FLAG_NONBLOCK); | ||
4308 | 237 | } | ||
4309 | 238 | |||
4310 | 239 | GRilIO *g_ril_io_new_blocking(GIOChannel *channel) | ||
4311 | 240 | { | ||
4312 | 241 | return create_io(channel, 0); | ||
4313 | 242 | } | ||
4314 | 243 | |||
4315 | 244 | GIOChannel *g_ril_io_get_channel(GRilIO *io) | ||
4316 | 245 | { | ||
4317 | 246 | if (io == NULL) | ||
4318 | 247 | return NULL; | ||
4319 | 248 | |||
4320 | 249 | return io->channel; | ||
4321 | 250 | } | ||
4322 | 251 | |||
4323 | 252 | gboolean g_ril_io_set_read_handler(GRilIO *io, GRilIOReadFunc read_handler, | ||
4324 | 253 | gpointer user_data) | ||
4325 | 254 | { | ||
4326 | 255 | if (io == NULL) | ||
4327 | 256 | return FALSE; | ||
4328 | 257 | |||
4329 | 258 | io->read_handler = read_handler; | ||
4330 | 259 | io->read_data = user_data; | ||
4331 | 260 | |||
4332 | 261 | if (read_handler && ring_buffer_len(io->buf) > 0) | ||
4333 | 262 | read_handler(io->buf, user_data); | ||
4334 | 263 | |||
4335 | 264 | return TRUE; | ||
4336 | 265 | } | ||
4337 | 266 | |||
4338 | 267 | static gboolean call_blocking_read(gpointer user_data) | ||
4339 | 268 | { | ||
4340 | 269 | GRilIO *io = user_data; | ||
4341 | 270 | |||
4342 | 271 | while (can_write_data(io->channel, G_IO_OUT, io) == TRUE); | ||
4343 | 272 | write_watcher_destroy_notify(io); | ||
4344 | 273 | |||
4345 | 274 | return FALSE; | ||
4346 | 275 | } | ||
4347 | 276 | |||
4348 | 277 | gboolean g_ril_io_set_write_handler(GRilIO *io, GRilIOWriteFunc write_handler, | ||
4349 | 278 | gpointer user_data) | ||
4350 | 279 | { | ||
4351 | 280 | if (io == NULL) | ||
4352 | 281 | return FALSE; | ||
4353 | 282 | |||
4354 | 283 | if (io->write_watch > 0) { | ||
4355 | 284 | if (write_handler == NULL) { | ||
4356 | 285 | g_source_remove(io->write_watch); | ||
4357 | 286 | return TRUE; | ||
4358 | 287 | } | ||
4359 | 288 | |||
4360 | 289 | return FALSE; | ||
4361 | 290 | } | ||
4362 | 291 | |||
4363 | 292 | if (write_handler == NULL) | ||
4364 | 293 | return FALSE; | ||
4365 | 294 | |||
4366 | 295 | io->write_handler = write_handler; | ||
4367 | 296 | io->write_data = user_data; | ||
4368 | 297 | |||
4369 | 298 | if (io->use_write_watch == TRUE) | ||
4370 | 299 | io->write_watch = g_io_add_watch_full(io->channel, | ||
4371 | 300 | G_PRIORITY_HIGH, | ||
4372 | 301 | G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL, | ||
4373 | 302 | can_write_data, io, | ||
4374 | 303 | write_watcher_destroy_notify); | ||
4375 | 304 | else | ||
4376 | 305 | io->write_watch = g_idle_add(call_blocking_read, io); | ||
4377 | 306 | |||
4378 | 307 | return TRUE; | ||
4379 | 308 | } | ||
4380 | 309 | |||
4381 | 310 | GRilIO *g_ril_io_ref(GRilIO *io) | ||
4382 | 311 | { | ||
4383 | 312 | if (io == NULL) | ||
4384 | 313 | return NULL; | ||
4385 | 314 | |||
4386 | 315 | g_atomic_int_inc(&io->ref_count); | ||
4387 | 316 | |||
4388 | 317 | return io; | ||
4389 | 318 | } | ||
4390 | 319 | |||
4391 | 320 | static gboolean io_shutdown(GRilIO *io) | ||
4392 | 321 | { | ||
4393 | 322 | /* Don't trigger user disconnect on shutdown */ | ||
4394 | 323 | io->user_disconnect = NULL; | ||
4395 | 324 | io->user_disconnect_data = NULL; | ||
4396 | 325 | |||
4397 | 326 | if (io->read_watch > 0) | ||
4398 | 327 | g_source_remove(io->read_watch); | ||
4399 | 328 | |||
4400 | 329 | if (io->write_watch > 0) | ||
4401 | 330 | g_source_remove(io->write_watch); | ||
4402 | 331 | |||
4403 | 332 | return TRUE; | ||
4404 | 333 | } | ||
4405 | 334 | |||
4406 | 335 | void g_ril_io_unref(GRilIO *io) | ||
4407 | 336 | { | ||
4408 | 337 | gboolean is_zero; | ||
4409 | 338 | |||
4410 | 339 | if (io == NULL) | ||
4411 | 340 | return; | ||
4412 | 341 | |||
4413 | 342 | is_zero = g_atomic_int_dec_and_test(&io->ref_count); | ||
4414 | 343 | |||
4415 | 344 | if (is_zero == FALSE) | ||
4416 | 345 | return; | ||
4417 | 346 | |||
4418 | 347 | io_shutdown(io); | ||
4419 | 348 | |||
4420 | 349 | /* glib delays the destruction of the watcher until it exits, this | ||
4421 | 350 | * means we can't free the data just yet, even though we've been | ||
4422 | 351 | * destroyed already. We have to wait until the read_watcher | ||
4423 | 352 | * destroy function gets called | ||
4424 | 353 | */ | ||
4425 | 354 | if (io->read_watch > 0) | ||
4426 | 355 | io->destroyed = TRUE; | ||
4427 | 356 | else | ||
4428 | 357 | g_free(io); | ||
4429 | 358 | } | ||
4430 | 359 | |||
4431 | 360 | gboolean g_ril_io_set_disconnect_function(GRilIO *io, | ||
4432 | 361 | GRilDisconnectFunc disconnect, gpointer user_data) | ||
4433 | 362 | { | ||
4434 | 363 | if (io == NULL) | ||
4435 | 364 | return FALSE; | ||
4436 | 365 | |||
4437 | 366 | io->user_disconnect = disconnect; | ||
4438 | 367 | io->user_disconnect_data = user_data; | ||
4439 | 368 | |||
4440 | 369 | return TRUE; | ||
4441 | 370 | } | ||
4442 | 371 | |||
4443 | 372 | gboolean g_ril_io_set_debug(GRilIO *io, GRilDebugFunc func, gpointer user_data) | ||
4444 | 373 | { | ||
4445 | 374 | if (io == NULL) | ||
4446 | 375 | return FALSE; | ||
4447 | 376 | |||
4448 | 377 | io->debugf = func; | ||
4449 | 378 | io->debug_data = user_data; | ||
4450 | 379 | |||
4451 | 380 | return TRUE; | ||
4452 | 381 | } | ||
4453 | 382 | |||
4454 | 383 | void g_ril_io_set_write_done(GRilIO *io, GRilDisconnectFunc func, | ||
4455 | 384 | gpointer user_data) | ||
4456 | 385 | { | ||
4457 | 386 | if (io == NULL) | ||
4458 | 387 | return; | ||
4459 | 388 | |||
4460 | 389 | io->write_done_func = func; | ||
4461 | 390 | io->write_done_data = user_data; | ||
4462 | 391 | } | ||
4463 | 392 | |||
4464 | 393 | void g_ril_io_drain_ring_buffer(GRilIO *io, guint len) | ||
4465 | 394 | { | ||
4466 | 395 | ring_buffer_drain(io->buf, len); | ||
4467 | 396 | } | ||
4468 | 0 | 397 | ||
4469 | === added file 'gril/grilio.h' | |||
4470 | --- gril/grilio.h 1970-01-01 00:00:00 +0000 | |||
4471 | +++ gril/grilio.h 2013-04-09 20:01:20 +0000 | |||
4472 | @@ -0,0 +1,69 @@ | |||
4473 | 1 | /* | ||
4474 | 2 | * | ||
4475 | 3 | * RIL chat library with GLib integration | ||
4476 | 4 | * | ||
4477 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
4478 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
4479 | 7 | * | ||
4480 | 8 | * This program is free software; you can redistribute it and/or modify | ||
4481 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
4482 | 10 | * published by the Free Software Foundation. | ||
4483 | 11 | * | ||
4484 | 12 | * This program is distributed in the hope that it will be useful, | ||
4485 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4486 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4487 | 15 | * GNU General Public License for more details. | ||
4488 | 16 | * | ||
4489 | 17 | * You should have received a copy of the GNU General Public License | ||
4490 | 18 | * along with this program; if not, write to the Free Software | ||
4491 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
4492 | 20 | * | ||
4493 | 21 | */ | ||
4494 | 22 | |||
4495 | 23 | #ifndef __GRILIO_H | ||
4496 | 24 | #define __GRILIO_H | ||
4497 | 25 | |||
4498 | 26 | #ifdef __cplusplus | ||
4499 | 27 | extern "C" { | ||
4500 | 28 | #endif | ||
4501 | 29 | |||
4502 | 30 | #include "gfunc.h" | ||
4503 | 31 | |||
4504 | 32 | struct _GRilIO; | ||
4505 | 33 | |||
4506 | 34 | typedef struct _GRilIO GRilIO; | ||
4507 | 35 | |||
4508 | 36 | struct ring_buffer; | ||
4509 | 37 | |||
4510 | 38 | typedef void (*GRilIOReadFunc)(struct ring_buffer *buffer, gpointer user_data); | ||
4511 | 39 | typedef gboolean (*GRilIOWriteFunc)(gpointer user_data); | ||
4512 | 40 | |||
4513 | 41 | GRilIO *g_ril_io_new(GIOChannel *channel); | ||
4514 | 42 | GRilIO *g_ril_io_new_blocking(GIOChannel *channel); | ||
4515 | 43 | |||
4516 | 44 | GIOChannel *g_ril_io_get_channel(GRilIO *io); | ||
4517 | 45 | |||
4518 | 46 | GRilIO *g_ril_io_ref(GRilIO *io); | ||
4519 | 47 | void g_ril_io_unref(GRilIO *io); | ||
4520 | 48 | |||
4521 | 49 | gboolean g_ril_io_set_read_handler(GRilIO *io, GRilIOReadFunc read_handler, | ||
4522 | 50 | gpointer user_data); | ||
4523 | 51 | gboolean g_ril_io_set_write_handler(GRilIO *io, GRilIOWriteFunc write_handler, | ||
4524 | 52 | gpointer user_data); | ||
4525 | 53 | void g_ril_io_set_write_done(GRilIO *io, GRilDisconnectFunc func, | ||
4526 | 54 | gpointer user_data); | ||
4527 | 55 | |||
4528 | 56 | void g_ril_io_drain_ring_buffer(GRilIO *io, guint len); | ||
4529 | 57 | |||
4530 | 58 | gsize g_ril_io_write(GRilIO *io, const gchar *data, gsize count); | ||
4531 | 59 | |||
4532 | 60 | gboolean g_ril_io_set_disconnect_function(GRilIO *io, | ||
4533 | 61 | GRilDisconnectFunc disconnect, gpointer user_data); | ||
4534 | 62 | |||
4535 | 63 | gboolean g_ril_io_set_debug(GRilIO *io, GRilDebugFunc func, gpointer user_data); | ||
4536 | 64 | |||
4537 | 65 | #ifdef __cplusplus | ||
4538 | 66 | } | ||
4539 | 67 | #endif | ||
4540 | 68 | |||
4541 | 69 | #endif /* __GRILIO_H */ | ||
4542 | 0 | 70 | ||
4543 | === added file 'gril/grilresponse.h' | |||
4544 | --- gril/grilresponse.h 1970-01-01 00:00:00 +0000 | |||
4545 | +++ gril/grilresponse.h 2013-04-09 20:01:20 +0000 | |||
4546 | @@ -0,0 +1,46 @@ | |||
4547 | 1 | /* | ||
4548 | 2 | * | ||
4549 | 3 | * RIL chat library with GLib integration | ||
4550 | 4 | * | ||
4551 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
4552 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
4553 | 7 | * | ||
4554 | 8 | * This program is free software; you can redistribute it and/or modify | ||
4555 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
4556 | 10 | * published by the Free Software Foundation. | ||
4557 | 11 | * | ||
4558 | 12 | * This program is distributed in the hope that it will be useful, | ||
4559 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4560 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4561 | 15 | * GNU General Public License for more details. | ||
4562 | 16 | * | ||
4563 | 17 | * You should have received a copy of the GNU General Public License | ||
4564 | 18 | * along with this program; if not, write to the Free Software | ||
4565 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
4566 | 20 | * | ||
4567 | 21 | */ | ||
4568 | 22 | |||
4569 | 23 | #ifndef __GRIL_RESPONSE_H | ||
4570 | 24 | #define __GRIL_RESPONSE_H | ||
4571 | 25 | |||
4572 | 26 | #ifdef __cplusplus | ||
4573 | 27 | extern "C" { | ||
4574 | 28 | #endif | ||
4575 | 29 | |||
4576 | 30 | struct _GRilResponse { | ||
4577 | 31 | GSList *lines; | ||
4578 | 32 | char *final_or_pdu; | ||
4579 | 33 | }; | ||
4580 | 34 | |||
4581 | 35 | typedef struct _GRilResponse GRilResponse; | ||
4582 | 36 | |||
4583 | 37 | #define G_RIL_RESPONSE_LINE_LENGTH_MAX 2048 | ||
4584 | 38 | |||
4585 | 39 | const char *g_ril_final_response(GRilResponse *response); | ||
4586 | 40 | const char *g_ril_response_pdu(GRilResponse *response); | ||
4587 | 41 | |||
4588 | 42 | #ifdef __cplusplus | ||
4589 | 43 | } | ||
4590 | 44 | #endif | ||
4591 | 45 | |||
4592 | 46 | #endif /* __GRIL_RESPONSE_H */ | ||
4593 | 0 | 47 | ||
4594 | === added file 'gril/grilutil.c' | |||
4595 | --- gril/grilutil.c 1970-01-01 00:00:00 +0000 | |||
4596 | +++ gril/grilutil.c 2013-04-09 20:01:20 +0000 | |||
4597 | @@ -0,0 +1,499 @@ | |||
4598 | 1 | /* | ||
4599 | 2 | * | ||
4600 | 3 | * RIL library with GLib integration | ||
4601 | 4 | * | ||
4602 | 5 | * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. | ||
4603 | 6 | * Copyright (C) 2012 Canonical Ltd. | ||
4604 | 7 | * | ||
4605 | 8 | * This program is free software; you can redistribute it and/or modify | ||
4606 | 9 | * it under the terms of the GNU General Public License version 2 as | ||
4607 | 10 | * published by the Free Software Foundation. | ||
4608 | 11 | * | ||
4609 | 12 | * This program is distributed in the hope that it will be useful, | ||
4610 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4611 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4612 | 15 | * GNU General Public License for more details. | ||
4613 | 16 | * | ||
4614 | 17 | * You should have received a copy of the GNU General Public License | ||
4615 | 18 | * along with this program; if not, write to the Free Software | ||
4616 | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
4617 | 20 | * | ||
4618 | 21 | */ | ||
4619 | 22 | |||
4620 | 23 | #ifdef HAVE_CONFIG_H | ||
4621 | 24 | #include <config.h> | ||
4622 | 25 | #endif | ||
4623 | 26 | |||
4624 | 27 | #include <stdio.h> | ||
4625 | 28 | #include <ctype.h> | ||
4626 | 29 | #include <string.h> | ||
4627 | 30 | |||
4628 | 31 | #include <glib.h> | ||
4629 | 32 | |||
4630 | 33 | #include "grilutil.h" | ||
4631 | 34 | #include "ril_constants.h" | ||
4632 | 35 | |||
4633 | 36 | const char *ril_appstate_to_string(int app_state) | ||
4634 | 37 | { | ||
4635 | 38 | switch (app_state) { | ||
4636 | 39 | case RIL_APPSTATE_UNKNOWN: | ||
4637 | 40 | return "UNKNOWN"; | ||
4638 | 41 | case RIL_APPSTATE_DETECTED: | ||
4639 | 42 | return "DETECTED"; | ||
4640 | 43 | case RIL_APPSTATE_PIN: | ||
4641 | 44 | return "PIN"; | ||
4642 | 45 | case RIL_APPSTATE_PUK: | ||
4643 | 46 | return "PUK"; | ||
4644 | 47 | case RIL_APPSTATE_SUBSCRIPTION_PERSO: | ||
4645 | 48 | return ""; | ||
4646 | 49 | case RIL_APPSTATE_READY: | ||
4647 | 50 | return "READY"; | ||
4648 | 51 | default: | ||
4649 | 52 | return "<INVALID>"; | ||
4650 | 53 | } | ||
4651 | 54 | } | ||
4652 | 55 | |||
4653 | 56 | const char *ril_apptype_to_string(int app_type) | ||
4654 | 57 | { | ||
4655 | 58 | |||
4656 | 59 | switch (app_type) { | ||
4657 | 60 | case RIL_APPTYPE_UNKNOWN: | ||
4658 | 61 | return "UNKNOWN"; | ||
4659 | 62 | case RIL_APPTYPE_SIM: | ||
4660 | 63 | return "SIM"; | ||
4661 | 64 | case RIL_APPTYPE_USIM: | ||
4662 | 65 | return "USIM"; | ||
4663 | 66 | case RIL_APPTYPE_RUIM: | ||
4664 | 67 | return "RUIM"; | ||
4665 | 68 | case RIL_APPTYPE_CSIM: | ||
4666 | 69 | return "CSIM"; | ||
4667 | 70 | case RIL_APPTYPE_ISIM: | ||
4668 | 71 | return "ISIM"; | ||
4669 | 72 | default: | ||
4670 | 73 | return "<INVALID>"; | ||
4671 | 74 | } | ||
4672 | 75 | } | ||
4673 | 76 | |||
4674 | 77 | const char *ril_cardstate_to_string(int card_state) | ||
4675 | 78 | { | ||
4676 | 79 | switch (card_state) { | ||
4677 | 80 | case RIL_CARDSTATE_ABSENT: | ||
4678 | 81 | return "ABSENT"; | ||
4679 | 82 | case RIL_CARDSTATE_PRESENT: | ||
4680 | 83 | return "PRESENT"; | ||
4681 | 84 | case RIL_CARDSTATE_ERROR: | ||
4682 | 85 | return "ERROR"; | ||
4683 | 86 | default: | ||
4684 | 87 | return "<INVALID>"; | ||
4685 | 88 | } | ||
4686 | 89 | } | ||
4687 | 90 | |||
4688 | 91 | const char *ril_pinstate_to_string(int pin_state) | ||
4689 | 92 | { | ||
4690 | 93 | switch (pin_state) { | ||
4691 | 94 | case RIL_PINSTATE_UNKNOWN: | ||
4692 | 95 | return "UNKNOWN"; | ||
4693 | 96 | case RIL_PINSTATE_ENABLED_NOT_VERIFIED: | ||
4694 | 97 | return "ENABLED_NOT_VERIFIED"; | ||
4695 | 98 | case RIL_PINSTATE_ENABLED_VERIFIED: | ||
4696 | 99 | return "ENABLED_VERIFIED"; | ||
4697 | 100 | case RIL_PINSTATE_DISABLED: | ||
4698 | 101 | return "DISABLED"; | ||
4699 | 102 | case RIL_PINSTATE_ENABLED_BLOCKED: | ||
4700 | 103 | return "ENABLED_BLOCKED"; | ||
4701 | 104 | case RIL_PINSTATE_ENABLED_PERM_BLOCKED: | ||
4702 | 105 | return "ENABLED_PERM_BLOCKED"; | ||
4703 | 106 | default: | ||
4704 | 107 | return "<INVALID>"; | ||
4705 | 108 | } | ||
4706 | 109 | } | ||
4707 | 110 | |||
4708 | 111 | const char *ril_request_id_to_string(int req) | ||
4709 | 112 | { | ||
4710 | 113 | switch (req) { | ||
4711 | 114 | case RIL_REQUEST_GET_SIM_STATUS: | ||
4712 | 115 | return "RIL_REQUEST_GET_SIM_STATUS"; | ||
4713 | 116 | case RIL_REQUEST_ENTER_SIM_PIN: | ||
4714 | 117 | return "RIL_REQUEST_ENTER_SIM_PIN"; | ||
4715 | 118 | case RIL_REQUEST_ENTER_SIM_PUK: | ||
4716 | 119 | return "RIL_REQUEST_ENTER_SIM_PUK"; | ||
4717 | 120 | case RIL_REQUEST_ENTER_SIM_PIN2: | ||
4718 | 121 | return "RIL_REQUEST_ENTER_SIM_PIN2"; | ||
4719 | 122 | case RIL_REQUEST_ENTER_SIM_PUK2: | ||
4720 | 123 | return "RIL_REQUEST_ENTER_SIM_PUK2"; | ||
4721 | 124 | case RIL_REQUEST_CHANGE_SIM_PIN: | ||
4722 | 125 | return "RIL_REQUEST_CHANGE_SIM_PIN"; | ||
4723 | 126 | case RIL_REQUEST_CHANGE_SIM_PIN2: | ||
4724 | 127 | return "RIL_REQUEST_CHANGE_SIM_PIN2"; | ||
4725 | 128 | case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: | ||
4726 | 129 | return "RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION"; | ||
4727 | 130 | case RIL_REQUEST_GET_CURRENT_CALLS: | ||
4728 | 131 | return "RIL_REQUEST_GET_CURRENT_CALLS"; | ||
4729 | 132 | case RIL_REQUEST_DIAL: | ||
4730 | 133 | return "RIL_REQUEST_DIAL"; | ||
4731 | 134 | case RIL_REQUEST_GET_IMSI: | ||
4732 | 135 | return "RIL_REQUEST_GET_IMSI"; | ||
4733 | 136 | case RIL_REQUEST_HANGUP: | ||
4734 | 137 | return "RIL_REQUEST_HANGUP"; | ||
4735 | 138 | case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: | ||
4736 | 139 | return "RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND"; | ||
4737 | 140 | case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: | ||
4738 | 141 | return "RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND"; | ||
4739 | 142 | case RIL_REQUEST_SWITCH_HOLDING_AND_ACTIVE: | ||
4740 | 143 | return "RIL_REQUEST_SWITCH_HOLDING_AND_ACTIVE"; | ||
4741 | 144 | case RIL_REQUEST_CONFERENCE: | ||
4742 | 145 | return "RIL_REQUEST_CONFERENCE"; | ||
4743 | 146 | case RIL_REQUEST_UDUB: | ||
4744 | 147 | return "RIL_REQUEST_UDUB"; | ||
4745 | 148 | case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: | ||
4746 | 149 | return "RIL_REQUEST_LAST_CALL_FAIL_CAUSE"; | ||
4747 | 150 | case RIL_REQUEST_SIGNAL_STRENGTH: | ||
4748 | 151 | return "RIL_REQUEST_SIGNAL_STRENGTH"; | ||
4749 | 152 | case RIL_REQUEST_VOICE_REGISTRATION_STATE: | ||
4750 | 153 | return "RIL_REQUEST_VOICE_REGISTRATION_STATE"; | ||
4751 | 154 | case RIL_REQUEST_DATA_REGISTRATION_STATE: | ||
4752 | 155 | return "RIL_REQUEST_DATA_REGISTRATION_STATE"; | ||
4753 | 156 | case RIL_REQUEST_OPERATOR: | ||
4754 | 157 | return "RIL_REQUEST_OPERATOR"; | ||
4755 | 158 | case RIL_REQUEST_RADIO_POWER: | ||
4756 | 159 | return "RIL_REQUEST_RADIO_POWER"; | ||
4757 | 160 | case RIL_REQUEST_DTMF: | ||
4758 | 161 | return "RIL_REQUEST_DTMF"; | ||
4759 | 162 | case RIL_REQUEST_SEND_SMS: | ||
4760 | 163 | return "RIL_REQUEST_SEND_SMS"; | ||
4761 | 164 | case RIL_REQUEST_SEND_SMS_EXPECT_MORE: | ||
4762 | 165 | return "RIL_REQUEST_SEND_SMS_EXPECT_MORE"; | ||
4763 | 166 | case RIL_REQUEST_SETUP_DATA_CALL: | ||
4764 | 167 | return "RIL_REQUEST_SETUP_DATA_CALL"; | ||
4765 | 168 | case RIL_REQUEST_SIM_IO: | ||
4766 | 169 | return "RIL_REQUEST_SIM_IO"; | ||
4767 | 170 | case RIL_REQUEST_SEND_USSD: | ||
4768 | 171 | return "RIL_REQUEST_SEND_USSD"; | ||
4769 | 172 | case RIL_REQUEST_CANCEL_USSD: | ||
4770 | 173 | return "RIL_REQUEST_CANCEL_USSD"; | ||
4771 | 174 | case RIL_REQUEST_GET_CLIR: | ||
4772 | 175 | return "RIL_REQUEST_GET_CLIR"; | ||
4773 | 176 | case RIL_REQUEST_SET_CLIR: | ||
4774 | 177 | return "RIL_REQUEST_SET_CLIR"; | ||
4775 | 178 | case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: | ||
4776 | 179 | return "RIL_REQUEST_QUERY_CALL_FORWARD_STATUS"; | ||
4777 | 180 | case RIL_REQUEST_SET_CALL_FORWARD: | ||
4778 | 181 | return "RIL_REQUEST_SET_CALL_FORWARD"; | ||
4779 | 182 | case RIL_REQUEST_QUERY_CALL_WAITING: | ||
4780 | 183 | return "RIL_REQUEST_QUERY_CALL_WAITING"; | ||
4781 | 184 | case RIL_REQUEST_SET_CALL_WAITING: | ||
4782 | 185 | return "RIL_REQUEST_SET_CALL_WAITING"; | ||
4783 | 186 | case RIL_REQUEST_SMS_ACKNOWLEDGE : | ||
4784 | 187 | return "RIL_REQUEST_SMS_ACKNOWLEDGE "; | ||
4785 | 188 | case RIL_REQUEST_GET_IMEI: | ||
4786 | 189 | return "RIL_REQUEST_GET_IMEI"; | ||
4787 | 190 | case RIL_REQUEST_GET_IMEISV: | ||
4788 | 191 | return "RIL_REQUEST_GET_IMEISV"; | ||
4789 | 192 | case RIL_REQUEST_ANSWER: | ||
4790 | 193 | return "RIL_REQUEST_ANSWER"; | ||
4791 | 194 | case RIL_REQUEST_DEACTIVATE_DATA_CALL: | ||
4792 | 195 | return "RIL_REQUEST_DEACTIVATE_DATA_CALL"; | ||
4793 | 196 | case RIL_REQUEST_QUERY_FACILITY_LOCK: | ||
4794 | 197 | return "RIL_REQUEST_QUERY_FACILITY_LOCK"; | ||
4795 | 198 | case RIL_REQUEST_SET_FACILITY_LOCK: | ||
4796 | 199 | return "RIL_REQUEST_SET_FACILITY_LOCK"; | ||
4797 | 200 | case RIL_REQUEST_CHANGE_BARRING_PASSWORD: | ||
4798 | 201 | return "RIL_REQUEST_CHANGE_BARRING_PASSWORD"; | ||
4799 | 202 | case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: | ||
4800 | 203 | return "RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE"; | ||
4801 | 204 | case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: | ||
4802 | 205 | return "RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC"; | ||
4803 | 206 | case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: | ||
4804 | 207 | return "RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL"; | ||
4805 | 208 | case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: | ||
4806 | 209 | return "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS"; | ||
4807 | 210 | case RIL_REQUEST_DTMF_START: | ||
4808 | 211 | return "RIL_REQUEST_DTMF_START"; | ||
4809 | 212 | case RIL_REQUEST_DTMF_STOP: | ||
4810 | 213 | return "RIL_REQUEST_DTMF_STOP"; | ||
4811 | 214 | case RIL_REQUEST_BASEBAND_VERSION: | ||
4812 | 215 | return "RIL_REQUEST_BASEBAND_VERSION"; | ||
4813 | 216 | case RIL_REQUEST_SEPARATE_CONNECTION: | ||
4814 | 217 | return "RIL_REQUEST_SEPARATE_CONNECTION"; | ||
4815 | 218 | case RIL_REQUEST_SET_MUTE: | ||
4816 | 219 | return "RIL_REQUEST_SET_MUTE"; | ||
4817 | 220 | case RIL_REQUEST_GET_MUTE: | ||
4818 | 221 | return "RIL_REQUEST_GET_MUTE"; | ||
4819 | 222 | case RIL_REQUEST_QUERY_CLIP: | ||
4820 | 223 | return "RIL_REQUEST_QUERY_CLIP"; | ||
4821 | 224 | case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: | ||
4822 | 225 | return "RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE"; | ||
4823 | 226 | case RIL_REQUEST_DATA_CALL_LIST: | ||
4824 | 227 | return "RIL_REQUEST_DATA_CALL_LIST"; | ||
4825 | 228 | case RIL_REQUEST_RESET_RADIO: | ||
4826 | 229 | return "RIL_REQUEST_RESET_RADIO"; | ||
4827 | 230 | case RIL_REQUEST_OEM_HOOK_RAW: | ||
4828 | 231 | return "RIL_REQUEST_OEM_HOOK_RAW"; | ||
4829 | 232 | case RIL_REQUEST_OEM_HOOK_STRINGS: | ||
4830 | 233 | return "RIL_REQUEST_OEM_HOOK_STRINGS"; | ||
4831 | 234 | case RIL_REQUEST_SCREEN_STATE: | ||
4832 | 235 | return "RIL_REQUEST_SCREEN_STATE"; | ||
4833 | 236 | case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: | ||
4834 | 237 | return "RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION"; | ||
4835 | 238 | case RIL_REQUEST_WRITE_SMS_TO_SIM: | ||
4836 | 239 | return "RIL_REQUEST_WRITE_SMS_TO_SIM"; | ||
4837 | 240 | case RIL_REQUEST_DELETE_SMS_ON_SIM: | ||
4838 | 241 | return "RIL_REQUEST_DELETE_SMS_ON_SIM"; | ||
4839 | 242 | case RIL_REQUEST_SET_BAND_MODE: | ||
4840 | 243 | return "RIL_REQUEST_SET_BAND_MODE"; | ||
4841 | 244 | case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: | ||
4842 | 245 | return "RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE"; | ||
4843 | 246 | case RIL_REQUEST_STK_GET_PROFILE: | ||
4844 | 247 | return "RIL_REQUEST_STK_GET_PROFILE"; | ||
4845 | 248 | case RIL_REQUEST_STK_SET_PROFILE: | ||
4846 | 249 | return "RIL_REQUEST_STK_SET_PROFILE"; | ||
4847 | 250 | case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: | ||
4848 | 251 | return "RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND"; | ||
4849 | 252 | case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: | ||
4850 | 253 | return "RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE"; | ||
4851 | 254 | case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: | ||
4852 | 255 | return "RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM"; | ||
4853 | 256 | case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: | ||
4854 | 257 | return "RIL_REQUEST_EXPLICIT_CALL_TRANSFER"; | ||
4855 | 258 | case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: | ||
4856 | 259 | return "RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE"; | ||
4857 | 260 | case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: | ||
4858 | 261 | return "RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE"; | ||
4859 | 262 | case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: | ||
4860 | 263 | return "RIL_REQUEST_GET_NEIGHBORING_CELL_IDS"; | ||
4861 | 264 | case RIL_REQUEST_SET_LOCATION_UPDATES: | ||
4862 | 265 | return "RIL_REQUEST_SET_LOCATION_UPDATES"; | ||
4863 | 266 | case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: | ||
4864 | 267 | return "RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE"; | ||
4865 | 268 | case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: | ||
4866 | 269 | return "RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE"; | ||
4867 | 270 | case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: | ||
4868 | 271 | return "RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE"; | ||
4869 | 272 | case RIL_REQUEST_SET_TTY_MODE: | ||
4870 | 273 | return "RIL_REQUEST_SET_TTY_MODE"; | ||
4871 | 274 | case RIL_REQUEST_QUERY_TTY_MODE: | ||
4872 | 275 | return "RIL_REQUEST_QUERY_TTY_MODE"; | ||
4873 | 276 | case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: | ||
4874 | 277 | return "RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE"; | ||
4875 | 278 | case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: | ||
4876 | 279 | return "RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE"; | ||
4877 | 280 | case RIL_REQUEST_CDMA_FLASH: | ||
4878 | 281 | return "RIL_REQUEST_CDMA_FLASH"; | ||
4879 | 282 | case RIL_REQUEST_CDMA_BURST_DTMF: | ||
4880 | 283 | return "RIL_REQUEST_CDMA_BURST_DTMF"; | ||
4881 | 284 | case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: | ||
4882 | 285 | return "RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY"; | ||
4883 | 286 | case RIL_REQUEST_CDMA_SEND_SMS: | ||
4884 | 287 | return "RIL_REQUEST_CDMA_SEND_SMS"; | ||
4885 | 288 | case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: | ||
4886 | 289 | return "RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE"; | ||
4887 | 290 | case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG: | ||
4888 | 291 | return "RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG"; | ||
4889 | 292 | case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG: | ||
4890 | 293 | return "RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG"; | ||
4891 | 294 | case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION: | ||
4892 | 295 | return "RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION"; | ||
4893 | 296 | case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG: | ||
4894 | 297 | return "RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG"; | ||
4895 | 298 | case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG: | ||
4896 | 299 | return "RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG"; | ||
4897 | 300 | case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION: | ||
4898 | 301 | return "RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION"; | ||
4899 | 302 | case RIL_REQUEST_CDMA_SUBSCRIPTION: | ||
4900 | 303 | return "RIL_REQUEST_CDMA_SUBSCRIPTION"; | ||
4901 | 304 | case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: | ||
4902 | 305 | return "RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM"; | ||
4903 | 306 | case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: | ||
4904 | 307 | return "RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM"; | ||
4905 | 308 | case RIL_REQUEST_DEVICE_IDENTITY: | ||
4906 | 309 | return "RIL_REQUEST_DEVICE_IDENTITY"; | ||
4907 | 310 | case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: | ||
4908 | 311 | return "RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE"; | ||
4909 | 312 | case RIL_REQUEST_GET_SMSC_ADDRESS: | ||
4910 | 313 | return "RIL_REQUEST_GET_SMSC_ADDRESS"; | ||
4911 | 314 | case RIL_REQUEST_SET_SMSC_ADDRESS: | ||
4912 | 315 | return "RIL_REQUEST_SET_SMSC_ADDRESS"; | ||
4913 | 316 | case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: | ||
4914 | 317 | return "RIL_REQUEST_REPORT_SMS_MEMORY_STATUS"; | ||
4915 | 318 | case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: | ||
4916 | 319 | return "RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING"; | ||
4917 | 320 | case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: | ||
4918 | 321 | return "RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE"; | ||
4919 | 322 | case RIL_REQUEST_ISIM_AUTHENTICATION: | ||
4920 | 323 | return "RIL_REQUEST_ISIM_AUTHENTICATION"; | ||
4921 | 324 | case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: | ||
4922 | 325 | return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU"; | ||
4923 | 326 | case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: | ||
4924 | 327 | return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS"; | ||
4925 | 328 | default: | ||
4926 | 329 | return "<INVALID>"; | ||
4927 | 330 | } | ||
4928 | 331 | } | ||
4929 | 332 | |||
4930 | 333 | void g_ril_util_debug_chat(gboolean in, const char *str, gsize len, | ||
4931 | 334 | GRilDebugFunc debugf, gpointer user_data) | ||
4932 | 335 | { | ||
4933 | 336 | char type = in ? '<' : '>'; | ||
4934 | 337 | gsize escaped = 2; /* Enough for '<', ' ' */ | ||
4935 | 338 | char *escaped_str; | ||
4936 | 339 | const char *esc = "<ESC>"; | ||
4937 | 340 | gsize esc_size = strlen(esc); | ||
4938 | 341 | const char *ctrlz = "<CtrlZ>"; | ||
4939 | 342 | gsize ctrlz_size = strlen(ctrlz); | ||
4940 | 343 | gsize i; | ||
4941 | 344 | |||
4942 | 345 | if (debugf == NULL || !len) | ||
4943 | 346 | return; | ||
4944 | 347 | |||
4945 | 348 | for (i = 0; i < len; i++) { | ||
4946 | 349 | char c = str[i]; | ||
4947 | 350 | |||
4948 | 351 | if (g_ascii_isprint(c)) | ||
4949 | 352 | escaped += 1; | ||
4950 | 353 | else if (c == '\r' || c == '\t' || c == '\n') | ||
4951 | 354 | escaped += 2; | ||
4952 | 355 | else if (c == 26) | ||
4953 | 356 | escaped += ctrlz_size; | ||
4954 | 357 | else if (c == 25) | ||
4955 | 358 | escaped += esc_size; | ||
4956 | 359 | else | ||
4957 | 360 | escaped += 4; | ||
4958 | 361 | } | ||
4959 | 362 | |||
4960 | 363 | escaped_str = g_try_malloc(escaped + 1); | ||
4961 | 364 | if (escaped_str == NULL) | ||
4962 | 365 | return; | ||
4963 | 366 | |||
4964 | 367 | escaped_str[0] = type; | ||
4965 | 368 | escaped_str[1] = ' '; | ||
4966 | 369 | escaped_str[2] = '\0'; | ||
4967 | 370 | escaped_str[escaped] = '\0'; | ||
4968 | 371 | |||
4969 | 372 | for (escaped = 2, i = 0; i < len; i++) { | ||
4970 | 373 | unsigned char c = str[i]; | ||
4971 | 374 | |||
4972 | 375 | switch (c) { | ||
4973 | 376 | case '\r': | ||
4974 | 377 | escaped_str[escaped++] = '\\'; | ||
4975 | 378 | escaped_str[escaped++] = 'r'; | ||
4976 | 379 | break; | ||
4977 | 380 | case '\t': | ||
4978 | 381 | escaped_str[escaped++] = '\\'; | ||
4979 | 382 | escaped_str[escaped++] = 't'; | ||
4980 | 383 | break; | ||
4981 | 384 | case '\n': | ||
4982 | 385 | escaped_str[escaped++] = '\\'; | ||
4983 | 386 | escaped_str[escaped++] = 'n'; | ||
4984 | 387 | break; | ||
4985 | 388 | case 26: | ||
4986 | 389 | strncpy(&escaped_str[escaped], ctrlz, ctrlz_size); | ||
4987 | 390 | escaped += ctrlz_size; | ||
4988 | 391 | break; | ||
4989 | 392 | case 25: | ||
4990 | 393 | strncpy(&escaped_str[escaped], esc, esc_size); | ||
4991 | 394 | escaped += esc_size; | ||
4992 | 395 | break; | ||
4993 | 396 | default: | ||
4994 | 397 | if (g_ascii_isprint(c)) | ||
4995 | 398 | escaped_str[escaped++] = c; | ||
4996 | 399 | else { | ||
4997 | 400 | escaped_str[escaped++] = '\\'; | ||
4998 | 401 | escaped_str[escaped++] = '0' + ((c >> 6) & 07); | ||
4999 | 402 | escaped_str[escaped++] = '0' + ((c >> 3) & 07); | ||
5000 | 403 | escaped_str[escaped++] = '0' + (c & 07); |
PASSED: Continuous integration, rev:31 jenkins. qa.ubuntu. com/job/ phablet- extras- ofono-ci/ 2/ jenkins. qa.ubuntu. com/job/ phablet- extras- ofono-raring- armhf-ci/ 2 jenkins. qa.ubuntu. com/job/ phablet- extras- ofono-raring- armhf-ci/ 2/artifact/ work/output/ *zip*/output. zip
http://
Executed test runs:
SUCCESS: http://
deb: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ phablet- extras- ofono-ci/ 2/rebuild
http://