Compare commits

...

216 Commits

Author SHA1 Message Date
Slava Monich
12ffd8acf9 Merge branch 'post-1.17-picks' into 'master'
Cherry-picked useful post-1.17 commits + a simple bug fix on top of it.

See merge request !25
2016-01-20 13:47:17 +00:00
Slava Monich
df9b35b440 [ril] Set correct status for the current operator. Fixes JB#33922 2016-01-20 11:33:27 +02:00
John Ernberg
76e991d3da network: Fix crash caused by empty Scan() results
When issuing a Scan() in poor reception while attached to an operator it's
fully possible to get no results, which causes the attached operator to be
cleaned up. In certain scenarios this would cause a use-after-free as there
are still references to this operator.
Transfer the attached operator to the new list regardless of removal caused
by the Scan() results.
2016-01-20 11:33:27 +02:00
John Ernberg
90803904be gprs: Fix the ContextAdded() signal Introspection
This matches the behavior described by the documentation the signal
value returned by the code. This was causing a headache when using
stricter D-Bus wrappers like dbus-c++.
2016-01-20 11:33:27 +02:00
John Ernberg
84e547c2ed cbs: Resolve a use-after-free
In situations where location changes rapidly, a use-after-free condition
can occur.  What happens is that the timeout leaks and then the cbs
struct with the callback is cleaned up, resulting in a SIGSEGV when the
callback occurs from the glib loop.
2016-01-20 11:33:27 +02:00
Denis Kenzior
652798d592 modem: Don't move to pre-sim state in case of failure
In ofono_modem_reset, if the enable() callback fails, do not
proceed to the pre-sim state
2016-01-20 11:33:27 +02:00
Denis Kenzior
979a3bcef3 gprs: Implement ofono_gprs_context_get_type 2016-01-20 11:33:27 +02:00
Denis Kenzior
69178c8ecb include: Add ofono_gprs_context_get_type 2016-01-20 11:33:27 +02:00
Slava Monich
1ac1c9268d [gprs] Remove redundant ofono_gprs_get_modem declarations
Upstream now has those too.
2016-01-20 11:33:27 +02:00
Denis Kenzior
5483a8ecc0 gprs: Implement ofono_gprs_get_modem 2016-01-20 11:33:27 +02:00
Denis Kenzior
95dacebb0c gprs: Add ofono_gprs_get_modem() 2016-01-20 11:33:27 +02:00
Simon Fels
b92b1ce13f voicecall: don't dereference a supplied null value
When the voicecall atom is unregistered we remove all HFP support as
well but were supplying a zero as value to the emulator status
callbacks which caused the process to crash as we were dereferencing
the supplied value always and not respecting a zero as indicator to
reset.
2016-01-20 11:33:27 +02:00
Denis Kenzior
70ab2175a0 gprs: Allow synchronous callbacks for set_attached 2016-01-20 11:33:27 +02:00
Denis Kenzior
9810a258a1 radio-settings: Implement get_modem() 2016-01-20 11:33:27 +02:00
Denis Kenzior
760c17052f include: Add ofono_radio_settings_get_modem() 2016-01-20 11:33:27 +02:00
Denis Kenzior
e77b62a91e doc: Add Item M17 to coding-style.txt 2016-01-20 11:33:27 +02:00
Alfonso Sanchez-Beato
7103c81a77 include: Add definitions for phone number types 2016-01-20 11:33:27 +02:00
Slava Monich
2bc610353d [ril] Removed redundant declaration of enum operator_status
It has become public
2016-01-20 11:33:27 +02:00
Tony Espy
dd04ac248d src: make bearer/operator enums public
Move enums for operator_status and packet_bearer to common.h to avoid
duplication in drivers.
2016-01-20 11:33:27 +02:00
Slava Monich
c5b3357000 Merge branch 'merge-1.17' into 'master'
Upgrade to ofono 1.17

Some of the commits look quite useful and yet the whole thing doesn't seem to be particularly destructive (unlike what started happening after 1.17).

See merge request !24
2016-01-20 09:19:42 +00:00
Slava Monich
ddbdf9f649 Merge tag '63f6a75a61e7e07cc773929acb4c13acaf8a4b00' into merge-1.17
Release 1.17

Conflicts:
	ofono/src/gprs.c
	ofono/src/log.c
	ofono/src/main.c
	ofono/src/sim.c
2016-01-19 14:30:45 +02:00
Slava Monich
7b5be51527 [ofono] Update to upstream 1.17 2016-01-19 14:26:00 +02:00
Alfonso Sanchez-Beato
5aef6a8356 sms: Add trace when datagram is not delivered 2016-01-19 14:19:33 +02:00
Alfonso Sanchez-Beato
b99cd4f8ca smsutil: Do not check the origin port
Do not check if the origin port is reserved, as some operators use that
range of values.
2016-01-19 14:18:23 +02:00
Alfonso Sanchez-Beato
47ee85e955 push-notification: Accept push from any origin
Accept push notifications regardless of the origin port, as some
operators do not insert there the WAP connectionless session service
port, and use random values instead.
2016-01-19 14:17:39 +02:00
Denis Kenzior
b500f4fa65 voicecall: Don't accept USSD strings in Dial() 2016-01-19 14:16:01 +02:00
Denis Kenzior
c2c048dc05 gprs: Try re-attaching when we switch cells 2016-01-19 14:15:09 +02:00
Alfonso Sanchez-Beato
df923b481f message-waiting: Fix reading EF_MWIS records 2016-01-19 14:14:13 +02:00
Alfonso Sanchez-Beato
ed0c1f94f6 message-waiting: Update properly EF_MWIS SIM file 2016-01-19 14:13:44 +02:00
Marko Sulejic
6d2852cdaf configure.ac: fix typo 2016-01-19 14:13:00 +02:00
Denis Kenzior
72a1ecf5d0 sim: Fix up whitespace issues 2016-01-19 14:12:14 +02:00
Alfonso Sanchez-Beato
2fa10fb265 gprs: Add comment to gprs_reset_contexts 2016-01-19 14:10:53 +02:00
Denis Kenzior
f907c3a85d test: Fix file mode for reset-contexts 2016-01-19 14:10:28 +02:00
Alfonso Sanchez-Beato
4a7b325191 gprs: Refactor to remove forward declaration 2016-01-19 14:09:58 +02:00
Alfonso Sanchez-Beato
a8103a39fa test: Add script for resetting contexts 2016-01-19 14:07:35 +02:00
Alfonso Sanchez-Beato
4076502017 doc: Add description for ResetContexts method 2016-01-19 14:07:28 +02:00
Alfonso Sanchez-Beato
7ed41beadd gprs: Add DBus method to reset contexts
Add DBus method that removes the current contexts and re-provisions
using the APN database.

Conflicts:
	ofono/src/gprs.c
2016-01-19 14:06:26 +02:00
Luiz Augusto von Dentz
e45389cf84 gdbus: Close private connection if setup fails
Private connection should be properly closed with dbus_connection_close
otherwise libdbus exits with the following error:

  'The last reference on a connection was dropped without closing the
   connection. This is a bug in an application. See
   dbus_connection_unref() documentation for details. Most likely, the
   application was supposed to call dbus_connection_close(), since this
   is a private connection.'
2016-01-19 14:01:44 +02:00
Szymon Janc
4bae61c83e gdbus: Fix crash in g_dbus_create_error_valist
Passing NULL format parameter to vsnprintf results in invalid argument
error on glibc. But with some other libc libraries (musl and uClibc)
this results in dereferencing NULL pointer and crash due to
segmentation fault.
2016-01-19 14:01:37 +02:00
Szymon Janc
11d6e76f0a gdbus: Use g_dbus_create_error_valist internally
There is no need to duplicate code in g_dbus_send_error_valist.
2016-01-19 14:01:27 +02:00
Michael Janssen
4cfa5cdf36 gdbus: Add g_dbus_get_flags function
The g_dbus_get_flags function enables detection of when the
G_DBUS_FLAG_ENABLE_EXPERIMENTAL is set.
2016-01-19 14:01:17 +02:00
Luiz Augusto von Dentz
135923532c gdbus: Make GDBusClient work without ObjectManager
This makes GDBusClient work normally without ObjectManager.
2016-01-19 14:01:11 +02:00
Arman Uguray
d112c042e3 gdbus/client: Allow specifying ObjectManager path
GDBusClient currently hard-codes "/" as the remote ObjectManager path.
This is generally incorrect, as an application can choose to expose an
ObjectManager at any well-known path. This patch fixes this by allowing
the user to pass in the ObjectManager path by introducing a new
conctructor "g_dbus_client_new_full".
2016-01-19 14:01:02 +02:00
Arman Uguray
b9407ff65f gdbus/client: Don't GetManagedObjects w/o handlers
The client code currently issues GetManagedObjects if new handlers are
set via g_dbus_client_set_proxy_handlers. An application may set these
to NULL before unref'ing a client or to simply prevent further events.
Hence, there is no need to refresh objects or properties if all handlers
are NULL.
2016-01-19 14:00:55 +02:00
Szymon Janc
5a92625c9f gdbus: Fix not calling disconnect function
If daemon gets disconnected from D-Bus sender is NULL. Watches that
was explicitly added with NULL sender (ie disconnected_signal in
g_dbus_set_disconnect_function) should be called anyway.
2016-01-19 14:00:40 +02:00
Arman Uguray
c684033671 gdbus: Don't refresh objects/props if disconnected
If g_dbus_client_set_proxy_handlers gets called from within a
proxy_removed callback, the code may end up refreshing the proxy's
properties and incorrectly access the client's proxy_list as it gets
freed. This patch fixes this, so that get_managed_objects does nothing
if it gets called during a service disconnect.
2016-01-19 13:53:41 +02:00
Slava Monich
59cb9c39b9 Merge branch 'jb33872' into 'master'
Fix eternal loop loop with roaming SIM

When ofono core is asking gprs driver to detach (because data roaming is disabled), it's expecting data registration status to change. If that doesn't happen, it starts all over again.

See merge request !22
2016-01-18 15:26:47 +00:00
Slava Monich
0831fd803a [ril] Tweaking mobile data management
Mobile data availability for all slots is now managed by the single
component called ril_data_manager.
2016-01-18 12:28:18 +02:00
Slava Monich
1b6c20759c [ril] Fix eternal loop with roaming sim. Fixes JB#33872
When ofono core is asking gprs driver to detach (because data
roaming is disabled), it's expecting data registration status
to change. If that doesn't happen, it starts all over again.
2016-01-18 12:28:18 +02:00
Slava Monich
3681eb63b1 Merge branch 'voicereg' into 'master'
Allow 3 values for registration state response

This was seen by one of the porters:
```
RIL< [0000000a] VOICE_REGISTRATION_STATE
RIL> [0000000a] OK
RIL> 0000: 00 00 00 00 0a 00 00 00  00 00 00 00 03 00 00 00    ........ ........
RIL  0010: 01 00 00 00 30 00 00 00  04 00 00 00 30 00 30 00    ....0... ....0.0.
RIL  0020: 30 00 30 00 00 00 00 00  08 00 00 00 30 00 30 00    0.0..... ....0.0.
RIL  0030: 30 00 30 00 30 00 30 00  30 00 30 00 00 00 00 00    0.0.0.0. 0.0.....
ofonod[953]: drivers/ril/ril_network.c:ril_network_parse_response() broken response
```

See merge request !23
2016-01-18 10:26:50 +00:00
Slava Monich
5303f766a9 [ril] Provide reasonable default for max_calls
Some older RILs don't provide max calls, in that case let's supply
some reasonable default. We don't need more than 2 simultaneous data
calls anyway.
2016-01-18 00:13:41 +02:00
Slava Monich
2f68eeea6c [ril] Allow 3 values for registration state response 2016-01-17 17:08:42 +02:00
Slava Monich
7a7744781a Merge branch 'imei' into 'master'
Return cached IMEI values from query_serial

Those are always queried at startup and they never change. There's no reason to perform RIL query for IMEI more than once.

See merge request !21
2016-01-14 21:15:23 +00:00
Slava Monich
fc1491c634 [ril] Return cached IMEI values from query_serial
Those are always queried at startup and they never change.
There's no reason to perform RIL query for IMEI more than once.
2016-01-14 16:48:38 +02:00
Slava Monich
c631a48c41 [ril] Set gprs cid range when registering gprs driver. Fixes JB#33861
There is no need to wait for the network state status, the network
may already be operational. Without cid range, attempts to activate
connection context will fail with org.ofono.Error.NotImplemented
2016-01-13 18:08:15 +02:00
Slava Monich
21e90e5abd Housekeeping 2016-01-13 16:52:36 +02:00
Slava Monich
bfcf8b726b Merge branch 'reg_state' into 'master'
Fixed a few issues mostly affecting startup and slowing down sim initialization

1. Don't submit the initial network state request if RIL says that radio is off. I have the impression that RIL doesn't like it; besides it won't work anyway. Instead, wait for radio on or for the network state change event, whichever comes first.
2. When the network state or sim status event occurs and the corresponding query is scheduled to be retried after a failure, retry it right away (i.e. don't wait for the retry timeout to expire).

Requires libgrilio 1.0.6 (already merged) which includes the bug fix for retries happening 1000 times too often (which rild might not like too).

See merge request !19
2016-01-13 14:49:20 +00:00
Slava Monich
3b69c9843b Merge branch 'lastcause' into 'master'
Handle more cause values for call control.

Quite many normal disconnect causes defined in 3GPP TS 24.008 Annex H
are not handled and are thus treated as errors. telepathy-ring would
then play "network out of order" tone, when "busy" tone would be more
appropriate. Add all the call control cause values not defined in ril.h
(but defined in Annex H) here and handle them appropriately.

See merge request !20
2016-01-13 13:58:48 +00:00
Juho Hämäläinen
f24252e2c6 Handle more cause values for call control. Fixes MER#1461
Quite many normal disconnect causes defined in 3GPP TS 24.008 Annex H
are not handled and are thus treated as errors. telepathy-ring would
then play "network out of order" tone, when "busy" tone would be more
appropriate. Add all the call control cause values not defined in ril.h
(but defined in Annex H) here and handle them appropriately.
2016-01-13 15:08:44 +02:00
Slava Monich
4be4cb4f57 [ril] Poke enabled modems with RADIO_POWER request after any modem gets powered off. Fixes JB#33830
If we don't do it, bad things may happen (like the enabled and
apparently powered on modem never registering on the network).
This may have something to do with certain pieces of radio
circuitry being shared by all modems.
2016-01-13 14:38:33 +02:00
Slava Monich
9d4f682b14 [ril] Fixed GET_SIM_STATUS retry 2016-01-13 00:01:02 +02:00
Slava Monich
bd736f7aa6 [ril] Only query the initial network state only if radio is on
Otherwise wait for the network state change event
2016-01-13 00:00:39 +02:00
Slava Monich
ff328c2a73 [systemd] Add $OFONO_DEBUG to the service command line
This allows to put a conf file to /var/lib/environment/ofono/ which
defines OFONO_DEBUG and avoid modifying ofono.service after each update.
2016-01-12 16:29:38 +02:00
Slava Monich
10e908fa96 Merge branch 'ril_subscription' into 'master'
Updated sample ril_subscription.conf

The comments in gril/ril_subscription.conf are not relevant to ril plugin in drivers/ril

See merge request !18
2016-01-11 12:45:56 +00:00
Slava Monich
4aa59c7274 Merge branch 'uicc_sub' into 'master'
Use different SET_UICC_SUBSCRIPTION codes for different RIL versions

RIL_REQUEST_SET_UICC_SUBSCRIPTION is 115 in RIL version 9 (or earlier) and 122 in RIL version 10 and later. Since we don't know in advance which RIL version we are dealing with, we need to make the decision at runtime.

See merge request !17
2016-01-11 12:45:29 +00:00
Slava Monich
d61be44bb4 [ril] Updated sample ril_subscription.conf 2016-01-11 13:16:10 +02:00
Slava Monich
0ed1ef1e4c [ril] Use different SET_UICC_SUBSCRIPTION codes for different RIL versions. Fixes MER#1446
RIL_REQUEST_SET_UICC_SUBSCRIPTION is 115 in RIL version 9 (or earlier)
and 122 in RIL version 10 and later. Since we don't know in advance which
RIL version we are dealing with, we need to make the decision at runtime.
2016-01-11 12:59:58 +02:00
Slava Monich
2fa193ad5b Merge branch 'sim_card' into 'master'
Refactoring of SIM card, network and radio power management

Major refactoring aimed at improving predictability, reliability and reducing RIL socket traffic. For instance, SIM card, radio and network states are now represented at the ofono side by dedicated per-socket objects and state changes are indicated to the interested parties using glib signalling mechanism (as opposed to independently listening to RIL events and performing redundant queries).

Requires libgrilio 1.0.4 (already merged)

See merge request !16
2016-01-11 08:46:48 +00:00
Slava Monich
e686240eeb [ril] Allow to control libgrilio logging with ofono -d option
It can be turned on with -d grilio or via D-Bus
2016-01-10 16:05:58 +02:00
Slava Monich
18bc7a3ad8 [ril] Use libgrilio built-in retry mechanism 2016-01-08 23:20:34 +02:00
Slava Monich
6624066917 [ril] Let gprs driver control "allow data" setting
Also added ril_network object that keeps track of the network state and
reduces the number of RIL requests.
2016-01-07 16:56:12 +02:00
Slava Monich
6015490d41 [ril] Indicate SIM card presence in appropriate radio state. Contributes to JB#33805
This also reduces the number of GET_SIM_STATUS requests. Only one object
per RIL instance makes these requests, the results are shared by all
other objects involved.

In addition to that, radio power on request is retried if radio power
unexpectedly switches off which does happen on multi-sim hardware.
2016-01-07 15:54:14 +02:00
Slava Monich
a135d0ea52 [ril] Sync constants with the latest Android ril.h 2016-01-07 15:47:30 +02:00
Slava Monich
f86159c180 [ril] Reset data modem pointer after default data SIM is gone 2015-12-15 12:38:53 +03:00
Slava Monich
de2b622f3b Merge branch 'radio-settings' into 'master'
Radio settings

Fixes `org.ofono.RadioSettings.GetProperties` failures after switching SIM cards and adds support for `"AvailableTechnologies"` property.

See merge request !13
2015-12-15 09:33:36 +00:00
Slava Monich
077f3f2e1e [ril] radio_settings: Implemented query_available_rats, removed obsolete code 2015-12-09 16:49:20 +03:00
Slava Monich
acbd40f9ad [ofono] radio-settings: Queue GetProperties requests
Just after the modem is added and org.ofono.RadioSettings interface
is registered, ofono may receive a number of GetProperties calls for
this interface. The first one would wait for initial queries to
complete while others may fail.

I guess it was expected that clients would retry the call later
but in practice pretty much all clients treat any D-Bus error as
a permanent failure.

This commit introduces the list of pending GetProperties requests
which all get completed after the initial query is done.
2015-12-09 14:03:24 +03:00
Slava Monich
26398c769f Merge branch 'PrefixLength' into 'master'
Provide PrefixLength for IPv6 address

`PrefixLength` property was absent from ConnectionContext IPv6.Settings even if it's provided by RIL.

See merge request !12
2015-12-02 15:33:27 +00:00
Slava Monich
60c53428f0 [ril] Provide PrefixLength for IPv6 address. Contributes to JB#31859 2015-12-02 15:05:21 +02:00
Slava Monich
90824a8906 Merge branch 'jb33531' into 'master'
Queue org.ofono.MessageManager.GetProperties requests while waiting for sca_query

Just after the modem is added and `org.ofono.MessageManager` interface is registered, ofono receives a bunch of `GetProperties` calls for this interface. The first one would wait for `driver->sca_query` completion and all others would fail until `driver->sca_query` completes. I guess it was expected that clients would retry the call later but in practice pretty much all clients treat any D-Bus error as a permanent failure.

This commit introduces the list of pending `GetProperties` requests which all get completed when `driver->sca_query` is done.

See merge request !11
2015-11-30 14:16:47 +00:00
Slava Monich
b85b8f0019 [ofono] sms: Queue GetProperties requests while waiting for sca_query. Fixes JB#33531
Just after the modem is added and org.ofono.MessageManager interface
is registered, ofono receives a bunch of GetProperties calls for this
interface. The first one would wait for driver->sca_query completion
and all others would fail until driver->sca_query completes.

I guess it was expected that clients would retry the call later
but in practice pretty much all clients treat any D-Bus error as
a permanent failure.

This commit introduces the list of pending GetProperties requests
which all get completed when driver->sca_query is done.
2015-11-30 16:11:54 +02:00
Slava Monich
29069fd152 Merge branch 'imei' into 'master'
Add GetIMEI method to ModemManager

This allows to query IMEI of all available modems without having to register them with ofono.

See merge request !10
2015-11-13 16:09:28 +00:00
Slava Monich
8e4e88e4fc [ril] Added GetIMEI method to ModemManager. Contributes to JB#33484
This allows to query IMEI of all available modems without having
to register them with ofono.
2015-11-12 17:59:05 +02:00
Slava Monich
40f148c134 [ril] Fixed memory leak on ofono_modem_register() failure 2015-11-12 17:51:35 +02:00
Slava Monich
730d5ff9b5 [ofono] modem: Destroy modem->properties in ofono_modem_remove()
Since it's created in ofono_modem_create(), it has to be destroyed
in ofono_modem_remove() to avoid memory leaks if ofono_modem_register()
fails.
2015-11-12 17:49:13 +02:00
Slava Monich
c6000fd909 Merge branch 'jb33441' into 'master'
Fix double free on self-deactivation of GPRS context



See merge request !9
2015-11-12 08:12:01 +00:00
Slava Monich
f2edab4ed8 Merge branch 'jb33265' into 'master'
Add GetPresentSims to ModemManager interface

Only a simple boolean (presence/absence) is reported. `PresentSimsChanged` signal is emitted when SIM is inserted or removed (if RIL supports it).

See merge request !8
2015-11-12 08:11:38 +00:00
Slava Monich
9915ccb3ba [ril] Fixed double free on self-deactivation of GPRS context. Fixes JB#33441 2015-11-11 19:20:24 +02:00
Slava Monich
b5be8420ab [ril] Add GetPresentSims to ModemManager interface. Contributes to JB#33265
Only a simple boolean (presence/absence) is reported. PresentSimsChanged
signal is emitted when SIM is inserted or removed (if RIL supports it).
2015-11-11 17:14:32 +02:00
Slava Monich
5498e22839 Merge branch 'jb33299' into 'master'
Fix manual operator selection for L500D

Seems to work on both Jolla1 and L500D

See merge request !7
2015-11-10 09:43:10 +00:00
Slava Monich
802d351ab0 Merge branch 'mer1394' into 'master'
Fix memory leaks

Memory was leaking every time a new SIM is inserted or "Reset to default" is done from AP settings page. Also refactored `provision_normalize_apn_list()` to eliminate duplicate code and clearly separate AP selection criteria into the sorting callback function.

See merge request !6
2015-11-10 09:42:52 +00:00
Slava Monich
3d62d57d20 [ril] Append +0 to MCCMNC in network selection request. Fixes JB#33299
Some RILs report MCCMNC in MCCMNC+TECH format and seem to expect it
in a similar way in SET_NETWORK_SELECTION_MANUAL request. Older RILs
don't require it but don't have a problem with that sort of syntax
either, at least one particular QCRIL vesion 6 that I tried. So the
solution seems to be quite portable.
2015-11-09 16:29:12 +02:00
Slava Monich
3b1b272967 [ril] Eliminated unnecessary debug print 2015-11-09 16:28:44 +02:00
Slava Monich
5e2a7afabd [ril] Fixed conversion of RIL to ofono registration status 2015-11-09 16:25:14 +02:00
Slava Monich
f7fa1c81f3 [provision] Fixed memory leak. Contributes to MER#1394
According to valgrind:

543 (8 direct, 535 indirect) bytes in 1 blocks are definitely lost in loss record 413 of 428
   at 0x483F380: malloc (vg_replace_malloc.c:296)
   by 0x4AB6083: g_malloc (gmem.c:104)
   by 0x4ACC9B5: g_slice_alloc (gslice.c:1016)
   by 0x4ACD8A3: g_slist_append (gslist.c:224)
   by 0xCE6BF: gsm_end (mbpi.c:423)
   by 0x4AB470D: g_markup_parse_context_parse (gmarkup.c:1602)
   by 0xCEE03: mbpi_parse (mbpi.c:646)
   by 0xCEEF3: mbpi_lookup_apn (mbpi.c:669)
   by 0xCF453: provision_get_settings (provision.c:184)
   by 0x145E87: __ofono_gprs_provision_get_settings (gprs-provision.c:68)
   by 0x12A983: provision_contexts (gprs.c:3327)
   by 0x12AD1B: spn_read_cb (gprs.c:3413)
2015-11-04 16:41:44 +03:00
Slava Monich
62a0b3518b [provision] Fixed memory leak. Contributes to MER#1394
According to valgrind:

14 bytes in 2 blocks are definitely lost in loss record 155 of 428
   at 0x483F380: malloc (vg_replace_malloc.c:296)
   by 0x4AB6083: g_malloc (gmem.c:104)
   by 0x4ACDAA9: g_strdup (gstrfuncs.c:364)
   by 0xCE383: apn_handler (mbpi.c:329)
   by 0xCE5B3: gsm_start (mbpi.c:386)
   by 0x4AB333B: emit_start_element (gmarkup.c:1029)
   by 0x4AB4685: g_markup_parse_context_parse (gmarkup.c:1366)
   by 0xCEE03: mbpi_parse (mbpi.c:646)
   by 0xCEEF3: mbpi_lookup_apn (mbpi.c:669)
   by 0xCF453: provision_get_settings (provision.c:184)
   by 0x145E87: __ofono_gprs_provision_get_settings (gprs-provision.c:68)
   by 0x12A983: provision_contexts (gprs.c:3327)
2015-11-04 10:58:34 +03:00
Slava Monich
d7cbedc0e9 Merge branch 'jb32969' into 'master'
Don't rely on DATA_CALL_LIST_CHANGED too much

Some RILs don't send `RIL_UNSOL_DATA_CALL_LIST_CHANGED` event after data call gets deactivated, only after activation. Some RILs send it in either case.

Ofono RIL plugin should consider data call disconnected after either `RIL_REQUEST_DEACTIVATE_DATA_CALL` successfully completes or data call disappears from the list reported by `RIL_UNSOL_DATA_CALL_LIST_CHANGED`, whichever happens first. That would work with both kinds of RILs.

See merge request !5
2015-11-04 07:41:21 +00:00
Slava Monich
1e75448127 Merge branch 'addremove' into 'master'
Always fire ModemRemoved first then ModemAdded

When switching from `/ril_1` to `/ril_0` we used to fire `ModemAdded("/ril_0")` followed by `ModemRemoved("/ril_1")` which may confuse D-Bus clients that are not so good at handling multiple modems. To well-behaved clients the order doesn't matter.

See merge request !4
2015-11-04 07:41:03 +00:00
Slava Monich
7ab4da0c91 [ril] Don't rely on DATA_CALL_LIST_CHANGED too much. Fixes JB#32969
Some RILs don't send RIL_UNSOL_DATA_CALL_LIST_CHANGED event after
data call gets deactivated, only after activation. Some RILs send
it in either case.

Ofono RIL plugin should consider data call disconnected after either
RIL_REQUEST_DEACTIVATE_DATA_CALL successfully completes or data call
disappears from the list reported by RIL_UNSOL_DATA_CALL_LIST_CHANGED,
whichever happens first. That would work with both kinds of RILs.
2015-11-03 19:06:48 +03:00
Slava Monich
f13991d04e [ril] Always fire ModemRemoved first then ModemAdded. Contributes to MER#1110
When switching from /ril_1 to /ril_0 we used to fire ModemAdded("/ril_0")
followed by ModemRemoved("/ril_1") which may confuse D-Bus clients that are
not so good at handling multiple modems. To well-bahaved clients the order
doesn't matter.
2015-11-03 16:06:52 +03:00
Slava Monich
c451110c39 [ril] Elimitated dependency on mce-headers. MER#1110
It's just a few defines, not worth the trouble.
2015-11-02 12:08:23 +03:00
Slava Monich
cb9183f3ff Merge branch 'multisim' into 'master'
New RIL plugin supporting multiple modems

Enabled by --enable-jolla-rilmodem configure option. Old plugin is preserved as a reference and for debugging regressions on Jolla1.

See merge request !2
2015-11-02 08:53:27 +00:00
Slava Monich
c1a9d7a578 [ril] New RIL plugin supporting multiple modems. Fixes MER#1110
Enabled by --enable-jolla-rilmodem configure option.
2015-10-30 18:01:37 +03:00
Slava Monich
9aee7ccadd [ofono] Added ofono_gprs_get_roaming_allowed() function
It's required by the RIL modem.
2015-10-25 19:12:17 +03:00
Slava Monich
0777b2853a Merge branch 'log' into 'master'
Allow to specify a function to be called when debug flags change

This allows to pass log level modifications to the external libraries that don't use ofono DBG mechanism.

See merge request !1
2015-10-25 16:09:11 +00:00
Slava Monich
b7bd9ca425 [ofono] Allow to specify a function to be called when debug flags change
This allows to pass log level modifications to the external libraries that
don't use ofono's DBG mechanism.
2015-10-25 18:47:10 +03:00
Marcel Holtmann
8929d131a3 Release 1.17 2015-09-13 17:08:07 +02:00
Slava Monich
97e34cc851 Merge pull request #302 from monich/nettime
Updated nettime plugin to support more than one modem
2015-09-11 17:03:28 +03:00
Slava Monich
e558d48b6f [ofono] Updated nettime plugin to support more than one modem. MER#1110 2015-09-08 22:23:20 +03:00
Alfonso Sanchez-Beato
51fc828c5e sms: Add trace when datagram is not delivered 2015-09-08 09:14:03 -05:00
Alfonso Sanchez-Beato
ac14de37ca smsutil: Do not check the origin port
Do not check if the origin port is reserved, as some operators use that
range of values.
2015-09-08 09:14:03 -05:00
Alfonso Sanchez-Beato
665c053803 push-notification: Accept push from any origin
Accept push notifications regardless of the origin port, as some
operators do not insert there the WAP connectionless session service
port, and use random values instead.
2015-09-08 09:14:03 -05:00
Slava Monich
aca873a5c4 [spec] Fixed configure option. MER#531
Configure option that enables org.ofono.DebugLog interface was misspelled.
2015-08-27 20:59:38 +03:00
Slava Monich
a12e10e36f Merge pull request #301 from monich/uicc_subscription
SET_UICC_SUBSCRIPTION
2015-08-26 12:50:58 +03:00
Slava Monich
7cd3fb74d4 [rilmodem] Simplified RIL initialization code
Requesting SIM status from RIL_REQUEST_SET_UICC_SUBSCRIPTION error handler
smells like a potential infinite loop. And it doesn't seem to be necessary.
Without that, the whole RIL_REQUEST_SET_UICC_SUBSCRIPTION completion
callback becomes unnecessary.

Simplified the algorithm of finding GSM/UMTS app index. It was a bit strange.
2015-08-25 16:37:30 +03:00
Slava Monich
84289d83fd [rilmodem] If error or request code is unknown, print the number
Also added string for RIL_REQUEST_SET_UICC_SUBSCRIPTION
2015-08-25 16:37:02 +03:00
Carsten Munk
f826abdbc7 Implement SET_UICC_SUBSCRIPTION. Fixes MER#1263
This is based on bd4677ee20
and 6b757515bf by Ratchanan Srirattanamet.
Any missing credit, let us know.
2015-08-25 11:28:31 +02:00
Kuba Pawlak
4e9cbcdb89 hfp: Handle extra CCWA event
When a call is waitng, CCWA event is sent and call object
in state WAITING is created. on ReleaseAndAnswer it is
promoted to INCOMING and later to ACTIVE.
iPhones send an extra CCWA event when active call is ended.
This extra event is creating a second call object in state
WAITING. It is not possible to have two WAITING calls, but
previously waiting call was already promoted to INCOMING.
For a brief time we have two calls from the same number,
one INCOMING and one WAITING. Later WAITING one is removed.
As we cannot have a waiting and incoming call at the same
time, ignore CCWA when there is already an INCOMING call.

< \r\n+CIEV: 3,3\r\n
< \r\n+CIEV: 2,1\r\n
< \r\n+CIEV: 3,0\r\n
< \r\n+CCWA: "01234567890",129,1,"Me"\r\n
< \r\n+CIEV: 3,1\r\n
> AT+CLCC\r
< \r\n+CLCC: 1,0,0,0,0,"09876543210",129,"Me"\r\n
< \r\n+CLCC: 2,1,5,0,0,"01234567890",129,"Me"\r\n
< \r\nOK\r\n
< \r\n+CIEV: 2,0\r\n
< \r\n+CCWA: "01234567890",129,1,"Me"\r\n
< \r\n+CIEV: 2,1\r\n
< \r\n+CIEV: 3,0\r\n
> AT+CLCC\r
< \r\n+CLCC: 2,1,0,0,0,"01234567890",129,"Me"\r\n
< \r\nOK\r\n
2015-08-24 16:29:29 -05:00
Slava Monich
f6ac328110 Merge pull request #298 from monich/debuglog
Add org.ofono.DebugLog interface
2015-08-24 14:36:14 +03:00
Slava Monich
8d46ababee [ofono] Added org.ofono.DebugLog interface. MER#531
It provides the following methods:

  array(string,boolean) List()
  void Enable(string pattern)
  void Disable(string pattern)

Enable and Disable methods allow to modify ofono logging settings
without restarting it. The List method returns the list of modules
for which logging can be changed at runtime and their current settings.
2015-08-19 16:33:07 +03:00
Denis Kenzior
9ec8d03c7c voicecall: Don't accept USSD strings in Dial() 2015-08-06 17:16:03 -05:00
Kuba Pawlak
3e6bbc676f hfp: Synchronize call state in case of +CHUP error
It is possible for the phone to accept Dial request
but not actually dial. This leaves a voicecall object
in state 'dialling' that cannot be removed.
Proposed workaround is to trigger AT+CLCC when an error
is returned for Hangup. As the call is not on the list,
this would remove this hanging object and signal CallRemoved.

Windows Phone trace with this fix:
ofonod[273]: > ATD1;\r
ofonod[273]: < \r\nOK\r\n
ofonod[273]: src/voicecall.c:dial_handle_result() Registering new call: 1
ofonod[273]: < \r\n+CIEV: 5,4\r\n
ofonod[273]: src/network.c:ofono_netreg_strength_notify() strength 80
ofonod[273]: > AT+CHUP\r
ofonod[273]: < \r\nERROR\r\n
ofonod[273]: src/voicecall.c:generic_callback() command failed with error: Unknown error type
ofonod[273]: > AT+CLCC\r
ofonod[273]: < \r\nOK\r\n
ofonod[273]: src/voicecall.c:ofono_voicecall_disconnected() Got disconnection event for id: 1, reason: 2
2015-08-05 11:15:33 -05:00
Denis Kenzior
8be0245664 cdma-connman: Make static analysis tools happy
The kernel simply puts a null terminator at index 15 prior to ifr_name
processing.  So we do the same.

Original report by:
Sabas Rosales, Blanca E <blanca.e.sabas.rosales@intel.com>

 Buffer not null terminated (BUFFER_SIZE_WARNING) buffer_size_warning:
 Calling strncpy with a maximum size argument of 16 bytes on destination
 array ifr.ifr_ifrn.ifrn_name of size 16 bytes might leave the
 destination string unterminated.

  92        strncpy(ifr.ifr_name, interface, IFNAMSIZ);
2015-07-28 10:18:26 -05:00
Denis Kenzior
ca105f7040 ppp_net: Make static analysis tools happy
The kernel simply puts a null terminator at index 15 prior to ifr_name
processing.  So we do the same.

Original report by:
Sabas Rosales, Blanca E <blanca.e.sabas.rosales@intel.com>

 Buffer not null terminated (BUFFER_SIZE_WARNING) buffer_size_warning:
 Calling strncpy with a maximum size argument of 16 bytes on destination
 array ifr.ifr_ifrn.ifrn_name of size 16 bytes might leave the
 destination string unterminated.

  67        strncpy(ifr.ifr_name, net->if_name, sizeof(ifr.ifr_name));
2015-07-28 10:16:16 -05:00
Denis Kenzior
dbb3ec13e5 gprs: Try re-attaching when we switch cells 2015-07-20 13:51:29 -05:00
Alfonso Sanchez-Beato
1b3302322a message-waiting: Fix reading EF_MWIS records 2015-07-16 20:22:38 -05:00
Alfonso Sanchez-Beato
cd76f913f0 message-waiting: Update properly EF_MWIS SIM file 2015-07-16 20:17:27 -05:00
Denis Kenzior
8dc220bc11 AUTHORS: Mention Johannes' contributions 2015-07-16 14:11:14 -05:00
Johannes 'josch' Schauer
b04fabcda3 udevng: add support for Ericsson N5321 gw 2015-07-16 14:10:41 -05:00
Kuba Pawlak
71df8bb15e hfp_hf_bluez5: Fix crash on re-pairing a Device
It may happen that a Device object is unpaired an paired again
without being removed from DBus. This in turn triggers second
modem object to be created, but not fully initialized.
If this modem object is used, oFono will crash.
2015-07-12 21:19:31 -05:00
Denis Kenzior
35ebbf4c97 handsfree: Mark GetProperties method ASYNC 2015-07-06 04:06:45 -05:00
Marcel Holtmann
a2acb227fd u8500: Fix compiler warning with logical expression
CC       plugins/u8500.o
plugins/u8500.c: In function ‘reachable_cb’:
plugins/u8500.c:235:28: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
  if (!g_isi_msg_error(msg) < 0)
                            ^
2015-07-07 11:35:54 +02:00
Marcel Holtmann
def77f7653 n900: Fix compiler warning with logical expression
CC       plugins/n900.o
plugins/n900.c: In function ‘mtc_reachable_cb’:
plugins/n900.c:241:28: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
  if (!g_isi_msg_error(msg) < 0)
                            ^
2015-07-07 11:35:54 +02:00
Marcel Holtmann
c3af639874 isiusb: Fix compiler warning with logical expression
CC       plugins/isiusb.o
plugins/isiusb.c: In function ‘reachable_cb’:
plugins/isiusb.c:207:28: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
  if (!g_isi_msg_error(msg) < 0)
                            ^
2015-07-07 11:35:54 +02:00
Marcel Holtmann
b2b67fa74e gatchat: Fix compiler warning with logical expression
CC       gatchat/gatchat.o
gatchat/gatchat.c: In function ‘have_line’:
gatchat/gatchat.c:586:28: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
  if (!strncmp(str, "AT", 2) == TRUE)
                            ^
2015-07-07 11:35:54 +02:00
Denis Kenzior
96754c0dfc AUTHORS: Mention Marko's contributions 2015-07-05 05:44:46 -05:00
Marko Sulejic
f2c474c55a configure.ac: fix typo 2015-07-05 05:43:56 -05:00
Slava Monich
07144c2dd5 Merge pull request #294 from monich/mer1137
Don't drop SMS datagrams with unknown ports
2015-07-02 00:57:27 +03:00
Denis Kenzior
58076d9a00 AUTHORS: Mention Sergey's contributions 2015-07-01 08:10:39 -05:00
Sergey Alirzaev
4a937b96aa build: make ofono build against musl
ifdef away GNU libc extensions and use a POSIXly correct pointer type
2015-07-01 08:09:53 -05:00
Denis Kenzior
fceb5a41c2 handsfree: Fix potential buffer overflow
Function: ag_features_list
 static const char *list[10];  (Out of bounds write, line 75)
  Incrementing i the value is now 10, for “hf-indicators”

Reported by: blanca.e.sabas.rosales@intel.com
2015-06-30 16:58:36 -05:00
Slava Monich
0073dc7bfc [sms] Don't drop SMS datagrams with unknown ports. Fixes MER#1137 2015-06-26 15:52:35 +03:00
Tommi Kenakkala
297bdaba0f Merge pull request #293 from tkenakka/cherrypick-pin-upstr
[sim] Improve Emit LockedPins after pin_type is queried. MER#1082
2015-06-23 15:12:46 +03:00
Tommi Kenakkala
f14db3b2a6 Merge pull request #292 from tkenakka/sockpath
Read RILD command socket path from a conf file. MER#1107
2015-06-23 14:44:31 +03:00
Tommi Kenakkala
4a0182616d [ril] Read RILD socket path from a file at startup. MER#1107
This allows configuring at startup the socket path to which ril plugin
will connect to.
2015-06-23 11:44:48 +03:00
Tommi Kenakkala
bbdfc8f46d [sim] Improve Emit LockedPins after pin_type is queried. MER#1082
Merge additional upstreaming changes from upstream commit eebe2f3
to previous nemomobile ofono commit 10328e6
2015-06-23 11:38:10 +03:00
Tommi Kenakkala
fbd59a8dc9 [gril] Change oFono gril to take a socket path. MER#1107
This allows configuring at startup the socket path to which gril
will connect to.
2015-06-22 11:16:00 +03:00
Denis Kenzior
48da783732 sim: Fix up whitespace issues 2015-06-18 14:59:06 -05:00
Tommi Kenakkala
eebe2f3ac2 Emit LockedPins after pin_type is queried
Fixes property change not being emited when hot-swapping a
PIN-enabled card.
2015-06-18 14:56:05 -05:00
Tommi Kenakkala
7eb6d5559a Merge pull request #291 from tkenakka/pin
[sim] Reset ofono pin state to none when card removed
2015-06-18 12:14:18 +03:00
Tommi Kenakkala
9a47510eb5 [sim] Coding conventions improvements for sim.c
Improves 10328e626d
2015-06-18 12:11:03 +03:00
Tommi Kenakkala
8fc7ae836f [sim] Reset pin state to none when card removed
Improves d88af05dc3
sim_get_properties would have problems with OFONO_SIM_PASSWORD_INVALID.
2015-06-18 12:11:03 +03:00
Tommi Kenakkala
4677729502 sim: Reset pin_type on card remove
Fixes PinRequired not being emitted when a card is inserted
2015-06-17 23:09:03 -05:00
Tommi Kenakkala
8c0f4f27eb Merge pull request #290 from tkenakka/pin
Refactor rilmodem SIM PIN handling
2015-06-10 15:09:53 +03:00
Tommi Kenakkala
b932bed519 Merge pull request #288 from monich/features
Don't unnecessarily emit "Features" PropertyChanged signal
2015-06-10 15:08:34 +03:00
Tommi Kenakkala
db83ac369b Merge pull request #287 from monich/leak
Fix memory leak
2015-06-10 15:02:54 +03:00
Tommi Kenakkala
e26df8a645 [rilmodem] Minor sim related logging updates 2015-06-09 16:19:01 +03:00
Tommi Kenakkala
5144f3fa14 [rilmodem] Remove ofono_set_pin_lock_state. Contributes MER#1082
Core sets LockedPins when driver returns that a PIN query is
required.
2015-06-09 16:17:55 +03:00
Tommi Kenakkala
0d6459b9b0 [sim] Remove ofono_set_pin_lock_state. Contributes MER#1082 2015-06-09 16:17:44 +03:00
Tommi Kenakkala
10328e626d [sim] Emit LockedPins changed. Contributes MER#1082
org.ofono.SimManager "Present" is signalled by ofono_sim_inserted_notify,
but LockedPins and PinRequired are updated later by sim_pin_query_cb.
Without signalling a client does not know when LockedPins
becomes available.
2015-06-09 16:05:43 +03:00
Tommi Kenakkala
5b407d654a [rilmodem] Reset retry count on PIN state change
After this rilmodem driver reports retries only for the required PIN type
and does not remember counts for previous password types.
2015-06-09 16:05:43 +03:00
Tommi Kenakkala
d88af05dc3 [sim] Reset pin_type on card removal. Contributes MER#1083
With this the variable behind org.ofono.SimManager "PinRequired"
is reset when card is removed, allowing signalling property change
in sim_pin_query_cb when card is inserted back.
2015-06-09 16:05:43 +03:00
Tommi Kenakkala
99cae6876f [rilmodem] Reset rilmodem driver's PIN type on card removal. Contributes MER#1083
Getting the PIN state for a freshly inserted card takes a while,
without this change driver uses the old state until the new state
is known.
2015-06-09 16:05:43 +03:00
Tommi Kenakkala
89e6593f9c [rilmodem] Delay signalling SIM inserted until PIN state available
Delay ofono_sim_inserted_notify call to core until PIN state is parsed
from gsmumts application by rilmodem driver.
2015-06-09 16:05:43 +03:00
Kuba Pawlak
93ccb84761 hfpmodem: Fix connecting to AG with existing mpty
If there is more then one active or held call, we are in mpty calls.
We won't get indicator update if any of them is released by CHLD=1x.
So we have to poll it.
2015-06-04 16:18:08 -05:00
Alfonso Sanchez-Beato
e70afdd9dc gprs: Add comment to gprs_reset_contexts 2015-05-18 12:13:04 -05:00
Denis Kenzior
1edb6eec9b test: Fix file mode for reset-contexts 2015-05-18 10:02:10 -05:00
Alfonso Sanchez-Beato
946b568f43 gprs: Refactor to remove forward declaration 2015-05-18 09:08:33 -05:00
Alfonso Sanchez-Beato
f3f3dabfac test: Add script for resetting contexts 2015-05-18 09:08:28 -05:00
Alfonso Sanchez-Beato
4c0f783f5c doc: Add description for ResetContexts method 2015-05-18 09:08:20 -05:00
Alfonso Sanchez-Beato
444611c086 gprs: Add DBus method to reset contexts
Add DBus method that removes the current contexts and re-provisions
using the APN database.
2015-05-18 09:08:13 -05:00
Tommi Kenakkala
8e9085f5ab Merge pull request #289 from tkenakka/simmgr
[rilmodem] Fix simmanager removal handling. Contributes to MER#928
2015-05-15 12:47:15 +03:00
Tommi Kenakkala
c33a48ea0c [rilmodem] Fix simmanager removal handling. Contributes to MER#928
Improves 7d0d72a.
2015-05-15 11:38:21 +03:00
Alex J Lennon
f8d9485dc2 cinterion: Correct use of freed structure
On error struct cb_data *cbd was used after in cinterion_set_online
after already being freed.
2015-05-13 15:56:34 -05:00
Denis Kenzior
23c45abd57 ste: Fix out-of-order free
CALLBACK_WITH_FAILURE used data structure freed just beforehand
2015-05-13 15:55:00 -05:00
Denis Kenzior
a371f46735 dundee: Fix out-of-order free
CALLBACK_WITH_FAILURE used data structure freed just beforehand
2015-05-13 15:44:39 -05:00
Denis Kenzior
ce0529fcf6 AUTHORS: Mention Alex's contributions 2015-05-13 09:57:53 -05:00
Alex J Lennon
fc3f937a67 udev: Add support for ehs6 name
As with tc65, ehs6 makes use of cinterion plugin
2015-05-13 09:57:53 -05:00
Alex J Lennon
7d4a19b114 cinterion: Register as OFONO_VENDOR_CINTERION
This enables us to take advantage of vendor specific quirks
(e.g. signal strength handling specifics for tc65)
2015-05-13 09:57:53 -05:00
Alex J Lennon
4242f6ee72 atmodem: Add Cinterion quirk for signal strength
Implement OFONO_VENDOR_CINTERION specific vendor support to register
textual +CIEV indications for signal strength using AT^SIND command.
2015-05-13 09:57:53 -05:00
Alex J Lennon
b31a3c2390 tc65: Replace tc65 plugin with cinterion plugin
On the basis that tc6x and other Cinterion devices will likely
have similar firmware requirements, provide a generic Cinterion
plugin which is functionally identical to the replaced tc65 plugin.

The udev implementation retains support for "tc65" name for
backwards compatibility, and adds support for the new "cinterion"
name.
2015-05-13 09:57:53 -05:00
Denis Kenzior
8d47f97106 hfp_hf_bluez5: Implement sco_connected_hint 2015-05-13 09:57:53 -05:00
Denis Kenzior
fdba39b8ed handsfree-audio: Call sco_connected_hint 2015-05-13 09:57:52 -05:00
Denis Kenzior
288364295c include: Add sco_connected_hint to handsfree-audio 2015-05-13 09:57:52 -05:00
Denis Kenzior
bce5d9579c gatchat: Introduce g_at_chat_get_userdata 2015-05-13 09:57:52 -05:00
Denis Kenzior
1c2987670d handsfree-audio: Add additional debugs 2015-05-13 09:57:52 -05:00
Tommi Kenakkala
44585697c3 Merge pull request #286 from tkenakka/simmgr
Register SimManager interface always and simplify logic
2015-05-06 10:06:29 +03:00
Slava Monich
3860230644 [modem] Don't unnecessarily emit "Features" PropertyChanged signal
Not all interfaces have corresponding features, meaning that not every
interface addition or removal actually updates the feature list.
If nothing else, this reduces the number of D-Bus signals emitted.
2015-05-05 16:11:06 +03:00
Tommi Kenakkala
07da2f3fa7 [rilmodem] Minor updates to error debug logging
Added function name prefix printing.
2015-05-05 15:52:35 +03:00
Tommi Kenakkala
7d0d72a4a9 [rilmodem] Register SimManager always and simplify logic. MER#928
Register org.ofono.SimManager always, without this the dbus
interface does not exist when starting without a SIM card.
Simplified rilmodem SIM status handling.
Moved some debug logging from sim.c to rilutil.c.
2015-05-05 15:52:35 +03:00
Tommi Kenakkala
f9ee2ae9b8 [rilmodem] Remove rilplugin sim inserted notification. MER#928
Functionality combined in rilmodem/sim.c.
No need to notify from both ril.c and sim.c.
2015-05-05 15:52:35 +03:00
Slava Monich
063234a433 [rilmodem] Fixed memory leak in handle_sne() 2015-05-05 15:51:12 +03:00
Tommi Kenakkala
c006d822f1 [rilmodem] Improve rilutil debug logging
Move some logs from rilmodem/sim.c to rilmodem/rilutil.c
and do some additional improvements.
2015-04-30 16:17:12 +03:00
Luiz Augusto von Dentz
a5b040b781 gdbus: Close private connection if setup fails
Private connection should be properly closed with dbus_connection_close
otherwise libdbus exits with the following error:

  'The last reference on a connection was dropped without closing the
   connection. This is a bug in an application. See
   dbus_connection_unref() documentation for details. Most likely, the
   application was supposed to call dbus_connection_close(), since this
   is a private connection.'
2015-04-20 09:04:39 +02:00
Szymon Janc
97abe1751d gdbus: Fix crash in g_dbus_create_error_valist
Passing NULL format parameter to vsnprintf results in invalid argument
error on glibc. But with some other libc libraries (musl and uClibc)
this results in dereferencing NULL pointer and crash due to
segmentation fault.
2015-04-09 16:59:08 +02:00
Szymon Janc
2f75b13ecd gdbus: Use g_dbus_create_error_valist internally
There is no need to duplicate code in g_dbus_send_error_valist.
2015-04-09 16:59:08 +02:00
Michael Janssen
73e517bcca gdbus: Add g_dbus_get_flags function
The g_dbus_get_flags function enables detection of when the
G_DBUS_FLAG_ENABLE_EXPERIMENTAL is set.
2015-04-07 19:00:45 +02:00
Luiz Augusto von Dentz
dae225a0d6 gdbus: Make GDBusClient work without ObjectManager
This makes GDBusClient work normally without ObjectManager.
2015-03-26 10:02:05 +01:00
Arman Uguray
97ac3f7c76 gdbus/client: Allow specifying ObjectManager path
GDBusClient currently hard-codes "/" as the remote ObjectManager path.
This is generally incorrect, as an application can choose to expose an
ObjectManager at any well-known path. This patch fixes this by allowing
the user to pass in the ObjectManager path by introducing a new
conctructor "g_dbus_client_new_full".
2015-03-26 10:02:05 +01:00
Arman Uguray
26a00f2f31 gdbus/client: Don't GetManagedObjects w/o handlers
The client code currently issues GetManagedObjects if new handlers are
set via g_dbus_client_set_proxy_handlers. An application may set these
to NULL before unref'ing a client or to simply prevent further events.
Hence, there is no need to refresh objects or properties if all handlers
are NULL.
2015-03-26 10:02:05 +01:00
Kuba Pawlak
cede3700f7 hfpmodem: slc.c: make sure to use none_prefix 2015-03-24 11:05:03 -05:00
Kuba Pawlak
318d313fc9 hfpmodem: hfpmodem.c make sure to use none_prefix 2015-03-24 11:04:48 -05:00
Kuba Pawlak
8e6ebab83b hfp_ag_bluez5: use none prefix for AT+BCC.
iPhone 5s with iOS8.2 sometimes failes to acknowledge AT+BCC
with OK. This means +CIEV events get consumed by this command
and call ended notification is not parsed.

Nov 30 00:00:19 ofonod[938]: > AT+BCC\r
Nov 30 00:00:28 ofonod[938]: < \r\n+CIEV: 2,0\r\n
2015-03-24 09:12:58 -05:00
Szymon Janc
d8edd49535 gdbus: Fix not calling disconnect function
If daemon gets disconnected from D-Bus sender is NULL. Watches that
was explicitly added with NULL sender (ie disconnected_signal in
g_dbus_set_disconnect_function) should be called anyway.
2015-02-24 18:24:42 +01:00
Arman Uguray
8660527b11 gdbus: Don't refresh objects/props if disconnected
If g_dbus_client_set_proxy_handlers gets called from within a
proxy_removed callback, the code may end up refreshing the proxy's
properties and incorrectly access the client's proxy_list as it gets
freed. This patch fixes this, so that get_managed_objects does nothing
if it gets called during a service disconnect.
2015-02-22 19:42:25 +01:00
Denis Kenzior
d6bc91ebfc hfpmodem: Make sure to use none_prefix
ofonod[253]: > AT+CCWA=1\r
ofonod[253]: < \r\n+BCS:2\r\n
ofonod[253]: < \r\nOK\r\n
2015-02-20 10:30:21 -06:00
Denis Kenzior
3d592d7d46 hfpmodem: Make sure to set the prefix properly
ofonod[1239]: > AT+COPS=3,0\r
ofonod[1239]: < \r\n+BCS:2\r\n
ofonod[1239]: < \r\nOK\r\n
2015-02-20 10:28:24 -06:00
Denis Kenzior
e2398b4dfa smsutil: Add additional sanity check
We make sure that after performing the UTF8 -> GSM conversion, the
number of GSM bytes is not greater than 11, which is the maximum
payload.
2015-02-13 09:59:59 -06:00
Tommi Kenakkala
42deee76a1 unit: Add test to encode / decode 11 char TP-OA 2015-02-13 09:55:16 -06:00
Tommi Kenakkala
2af3c733b7 sms: Fix alphanumeric TP-OA handling
TP-OA max length comparisons were incorrect because TP-OA's 7-bit
coded octets transport eleven 8-bit chars.  The current code assumed
only 10 chars were possible.

The patch
- increases the array size to 23, (maximum of 22 bytes for UTF8
  encoding + null terminator)
- Updates the sanity check to account for the correct maximum
- For encoding, checks the maximum length in UTF8 characters instead of
  bytes
2015-02-13 09:49:39 -06:00
Denis Kenzior
604fa223f4 AUTHORS: Mention Tommi's contributions 2015-02-02 09:29:46 -06:00
Tommi Kenakkala
04218d3a86 handsfree-audio: Refactor manager init / cleanup 2015-02-02 09:28:34 -06:00
Tommi Kenakkala
41fadd3787 main: Remove handsfree_audio_manager init/cleanup
Init allocates a SCO audio socket always. oFono should do that
with bluez5 but not with bluez4.  This patch starts the refactoring of
the handsfree_audio_manager init/cleanup functionality.
2015-02-02 09:26:58 -06:00
Cedric Jehasse
d539ed19f3 atmodem: fix retries reporting from AT+CPINR
The retries array was not correctly filled in.
2015-02-02 09:22:21 -06:00
Cedric Jehasse
25f926c733 atmodem: Sierra modems should be polled after CPIN
Sierra modem will return "CME ERROR: 14" when polled right after pin has
been entered. Use the existing vendor quirk to handle this.
2015-02-02 09:21:10 -06:00
Cedric Jehasse
151b837428 sierra: add sim state polling after CFUN enable
When pin is queried shortly after a Siera dongle is plugged in,
"AT+CPIN?" responds with "CME ERROR 14: SIM".
Poll the sim, as already done by several other vendor plugins.
2015-01-31 10:20:18 -06:00
113 changed files with 15554 additions and 685 deletions

View File

@@ -99,3 +99,8 @@ Jussi Pakkanen <jussi.pakkanen@canonical.com>
Sergio Checa Blanco <sergio.checa@bmw-carit.de>
Philip Paeps <philip@paeps.cx>
Kuba Pawlak <kubax.t.pawlak@intel.com>
Tommi Kenakkala <tommi.kenakkala@tieto.com>
Alex J Lennon <ajlennon@dynamicdevices.co.uk>
Sergey Alirzaev <zl29ah@gmail.com>
Marko Sulejic <marko.sulejic@hale.at>
Johannes 'josch' Schauer <josch@mister-muffin.de>

View File

@@ -1,3 +1,13 @@
ver 1.17:
Fix issue with alphanumeric TP-OA handling.
Fix issue with push notification origin port.
Fix issue with reading of EF_MWIS records.
Fix issue with handling AT+CPINR results.
Fix issue with SIM state polling for Sierra modems.
Fix issue with HFP handling and AT command prefixes.
Fix issue with HFP and extra CCWA event handling.
Fix issue with HFP call state and +CHUP errors.
ver 1.16:
Fix issue with PIN retry handling.
Fix issue with HFP and multiple calls.

View File

@@ -119,6 +119,41 @@ builtin_sources += plugins/udevng.c
endif
if RILMODEM
if JOLLA_RILMODEM
builtin_modules += ril
builtin_sources += drivers/ril/ril_call_barring.c \
drivers/ril/ril_call_forward.c \
drivers/ril/ril_call_settings.c \
drivers/ril/ril_call_volume.c \
drivers/ril/ril_cbs.c \
drivers/ril/ril_data.c \
drivers/ril/ril_devinfo.c \
drivers/ril/ril_gprs.c \
drivers/ril/ril_gprs_context.c \
drivers/ril/ril_mce.c \
drivers/ril/ril_modem.c \
drivers/ril/ril_netreg.c \
drivers/ril/ril_network.c \
drivers/ril/ril_oem_raw.c \
drivers/ril/ril_phonebook.c \
drivers/ril/ril_plugin.c \
drivers/ril/ril_plugin_dbus.c \
drivers/ril/ril_radio.c \
drivers/ril/ril_radio_settings.c \
drivers/ril/ril_sim.c \
drivers/ril/ril_sim_card.c \
drivers/ril/ril_sim_dbus.c \
drivers/ril/ril_sms.c \
drivers/ril/ril_stk.c \
drivers/ril/ril_ussd.c \
drivers/ril/ril_util.c \
drivers/ril/ril_voicecall.c
if DATAFILES
dist_conf_DATA += drivers/ril/ril_subscription.conf
endif
else
builtin_sources += $(gril_sources)
builtin_modules += rildev
@@ -150,6 +185,11 @@ builtin_sources += drivers/rilmodem/rilmodem.h \
drivers/rilmodem/call-barring.c \
drivers/rilmodem/stk.c
if DATAFILES
dist_conf_DATA += gril/ril_subscription.conf
endif
endif
endif
if ISIMODEM
@@ -381,9 +421,6 @@ builtin_sources += plugins/phonesim.c
if DATAFILES
dist_conf_DATA += plugins/phonesim.conf
if RILMODEM
dist_conf_DATA += gril/ril_subscription.conf
endif
endif
endif
@@ -439,8 +476,8 @@ builtin_sources += plugins/stemgr.c
builtin_modules += caif
builtin_sources += plugins/caif.c
builtin_modules += tc65
builtin_sources += plugins/tc65.c
builtin_modules += cinterion
builtin_sources += plugins/cinterion.c
builtin_modules += nokia
builtin_sources += plugins/nokia.c
@@ -575,6 +612,11 @@ builtin_cflags += @WSPCODEC_CFLAGS@
builtin_libadd += @WSPCODEC_LIBS@
endif
if LOGCONTROL
builtin_modules += debuglog
builtin_sources += plugins/debuglog.c
endif
builtin_modules += sms_history
builtin_sources += plugins/smshistory.c

View File

@@ -1,5 +1,5 @@
AC_PREREQ(2.60)
AC_INIT(ofono, 1.16)
AC_INIT(ofono, 1.17)
AM_INIT_AUTOMAKE([foreign subdir-objects color-tests])
AC_CONFIG_HEADERS(config.h)
@@ -42,6 +42,7 @@ AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug],
if (test "${enableval}" = "yes" &&
test "${ac_cv_prog_cc_g}" = "yes"); then
CFLAGS="$CFLAGS -g"
CPPFLAGS="$CPPFLAGS -DDEBUG"
fi
])
@@ -166,6 +167,20 @@ AC_ARG_ENABLE(rilmodem, AC_HELP_STRING([--disable-rilmodem],
[enable_rilmodem=${enableval}])
AM_CONDITIONAL(RILMODEM, test "${enable_rilmodem}" != "no")
AC_ARG_ENABLE(jolla-rilmodem,
AC_HELP_STRING([--enable-jolla-rilmodem], [enable Jolla RIL modem]),
[enable_jolla_rilmodem=${enableval}], [enable_jolla_rilmodem="no"])
AM_CONDITIONAL(JOLLA_RILMODEM, test "${enable_jolla_rilmodem}" != "no")
if (test "${enable_jolla_rilmodem}" = "yes"); then
PKG_CHECK_MODULES(GRILIO, libgrilio >= 1.0.6, dummy=yes,
AC_MSG_ERROR(libgrilio >= 1.0.6 is required))
PKG_CHECK_MODULES(GLIBUTIL, libglibutil, dummy=yes,
AC_MSG_ERROR(libglibutil is required))
CFLAGS="$CFLAGS $GRILIO_CFLAGS $GLIBUTIL_CFLAGS"
LIBS="$LIBS $GRILIO_LIBS $GLIBUTIL_LIBS"
fi
AC_ARG_ENABLE(qmimodem, AC_HELP_STRING([--disable-qmimodem],
[disable Qualcomm QMI modem support]),
[enable_qmimodem=${enableval}])
@@ -201,7 +216,7 @@ AC_ARG_WITH([provisiondb], AC_HELP_STRING([--with-provisiondb=FILE],
[location of provision database]), [path_provisiondb=${withval}])
AC_ARG_ENABLE(provision, AC_HELP_STRING([--disable-provision],
[disable provisioning suport]),
[disable provisioning support]),
[enable_provision=${enableval}])
if (test "${enable_provision}" != "no"); then
if (test -n "${path_provisiondb}"); then
@@ -237,6 +252,11 @@ if (test "${enable_pushforwarder}" != "no"); then
AC_SUBST(WSPCODEC_LIBS)
fi
AC_ARG_ENABLE(logcontrol,
AC_HELP_STRING([--enable-logcontrol], [enable log control plugin]),
[enable_logcontrol=${enableval}], [enable_logcontrol="no"])
AM_CONDITIONAL(LOGCONTROL, test "${enable_logcontrol}" != "no")
if (test "${prefix}" = "NONE"); then
dnl no prefix and no localstatedir, so default to /var
if (test "$localstatedir" = '${prefix}/var'); then

View File

@@ -306,6 +306,13 @@ Example:
2)
0x1 << y // Wrong
M17: Avoid forward-declaration of static functions
==================================================
Functions that are static should not be forward-declared. The only exception
to this rule is if a circular dependency condition exists, and the forward
declaration cannot be avoided.
O1: Shorten the name
====================
Better to use abbreviation, rather than full name, to name a variable,

View File

@@ -60,6 +60,16 @@ Methods dict GetProperties()
[service].Error.NotFound
[service].Error.Failed
void ResetContexts()
Removes all contexts and re-provisions from the APN
database. Contexts must all be deactivated for this
method to work, and the atom must not be powered.
Possible Errors: [service].Error.InProgress
[service].Error.InvalidArguments
[service].Error.NotAllowed
Signals PropertyChanged(string property, variant value)
This signal indicates a changed value of the given

View File

@@ -0,0 +1,28 @@
Debug log control
=================
Service org.ofono
Interface org.ofono.DebugLog
Object path /
Methods void Enable(string pattern)
Enables all logs that match the pattern.
void Disable(string pattern)
Disables all logs that match the pattern.
array(string,boolean) List()
Returns all available log names and their current
states.
In order for Enable or Disable call to have any
effect, the pattern must match one or more of
these strings.
Signals Changed(string name, boolean enabled)
This signal indicates a changed log status of the
given log module.

View File

@@ -838,6 +838,39 @@ static void telit_ciev_notify(GAtResult *result, gpointer user_data)
ofono_netreg_strength_notify(netreg, strength);
}
static void cinterion_ciev_notify(GAtResult *result, gpointer user_data)
{
struct ofono_netreg *netreg = user_data;
struct netreg_data *nd = ofono_netreg_get_data(netreg);
const char *signal_identifier = "rssi";
const char *ind_str;
int strength;
GAtResultIter iter;
g_at_result_iter_init(&iter, result);
if (!g_at_result_iter_next(&iter, "+CIEV:"))
return;
if (!g_at_result_iter_next_unquoted_string(&iter, &ind_str))
return;
if (!g_str_equal(signal_identifier, ind_str))
return;
if (!g_at_result_iter_next_number(&iter, &strength))
return;
DBG("rssi %d", strength);
if (strength == nd->signal_invalid)
strength = -1;
else
strength = (strength * 100) / (nd->signal_max - nd->signal_min);
ofono_netreg_strength_notify(netreg, strength);
}
static void ctzv_notify(GAtResult *result, gpointer user_data)
{
struct ofono_netreg *netreg = user_data;
@@ -1915,6 +1948,27 @@ static void at_creg_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
g_at_chat_send(nd->chat, "AT*TLTS=1", none_prefix,
NULL, NULL, NULL);
break;
case OFONO_VENDOR_CINTERION:
/*
* We can't set rssi bounds from Cinterion responses
* so set them up to specified values here
*
* Cinterion rssi signal strength specified as:
* 0 <= -112dBm
* 1 - 4 signal strengh in 15 dB steps
* 5 >= -51 dBm
* 99 not known or undetectable
*/
nd->signal_min = 0;
nd->signal_max = 5;
nd->signal_invalid = 99;
/* Register for specific signal strength reports */
g_at_chat_send(nd->chat, "AT^SIND=\"rssi\",1", none_prefix,
NULL, NULL, NULL);
g_at_chat_register(nd->chat, "+CIEV:",
cinterion_ciev_notify, FALSE, netreg, NULL);
break;
case OFONO_VENDOR_NOKIA:
case OFONO_VENDOR_SAMSUNG:
/* Signal strength reporting via CIND is not supported */

View File

@@ -827,7 +827,7 @@ static void at_cpinr_cb(gboolean ok, GAtResult *result, gpointer user_data)
for (i = 1; i < len; i++) {
if (!strcmp(name, at_sim_name[i].name)) {
retries[i] = val;
retries[at_sim_name[i].type] = val;
break;
}
}
@@ -1350,6 +1350,7 @@ static void at_pin_send_cb(gboolean ok, GAtResult *result,
case OFONO_VENDOR_ALCATEL:
case OFONO_VENDOR_HUAWEI:
case OFONO_VENDOR_SIMCOM:
case OFONO_VENDOR_SIERRA:
/*
* On ZTE modems, after pin is entered, SIM state is checked
* by polling CPIN as their modem doesn't provide unsolicited

View File

@@ -45,4 +45,5 @@ enum ofono_vendor {
OFONO_VENDOR_ALCATEL,
OFONO_VENDOR_QUECTEL,
OFONO_VENDOR_UBLOX,
OFONO_VENDOR_CINTERION,
};

View File

@@ -45,6 +45,7 @@
static const char *binp_prefix[] = { "+BINP:", NULL };
static const char *bvra_prefix[] = { "+BVRA:", NULL };
static const char *none_prefix[] = { NULL };
struct hf_data {
GAtChat *chat;
@@ -197,7 +198,7 @@ static void hfp_cnum_query(struct ofono_handsfree *hf,
struct hf_data *hd = ofono_handsfree_get_data(hf);
struct cb_data *cbd = cb_data_new(cb, data);
if (g_at_chat_send(hd->chat, "AT+CNUM", NULL,
if (g_at_chat_send(hd->chat, "AT+CNUM", none_prefix,
cnum_query_cb, cbd, g_free) > 0)
return;
@@ -382,8 +383,8 @@ static void hfp_disable_nrec(struct ofono_handsfree *hf,
struct cb_data *cbd = cb_data_new(cb, data);
const char *buf = "AT+NREC=0";
if (g_at_chat_send(hd->chat, buf, NULL, hf_generic_set_cb,
cbd, g_free) > 0)
if (g_at_chat_send(hd->chat, buf, none_prefix,
hf_generic_set_cb, cbd, g_free) > 0)
return;
g_free(cbd);
@@ -401,8 +402,8 @@ static void hfp_hf_indicator(struct ofono_handsfree *hf,
snprintf(buf, sizeof(buf), "AT+BIEV=%u,%u", indicator, value);
if (g_at_chat_send(hd->chat, buf, NULL, hf_generic_set_cb,
cbd, g_free) > 0)
if (g_at_chat_send(hd->chat, buf, none_prefix,
hf_generic_set_cb, cbd, g_free) > 0)
return;
g_free(cbd);

View File

@@ -46,6 +46,7 @@
static const char *cops_prefix[] = { "+COPS:", NULL };
static const char *cind_prefix[] = { "+CIND:", NULL };
static const char *none_prefix[] = { NULL };
struct netreg_data {
GAtChat *chat;
@@ -263,7 +264,7 @@ static void hfp_current_operator(struct ofono_netreg *netreg,
cbd->user = netreg;
ok = g_at_chat_send(nd->chat, "AT+COPS=3,0", NULL,
ok = g_at_chat_send(nd->chat, "AT+COPS=3,0", none_prefix,
NULL, cbd, NULL);
if (ok)

View File

@@ -113,7 +113,8 @@ static void slc_established(struct slc_establish_data *sed)
{
struct hfp_slc_info *info = sed->info;
g_at_chat_send(info->chat, "AT+CMEE=1", NULL, NULL, NULL, NULL);
g_at_chat_send(info->chat, "AT+CMEE=1", none_prefix,
NULL, NULL, NULL);
sed->connect_cb(sed->userdata);
}
@@ -434,8 +435,8 @@ static void brsf_cb(gboolean ok, GAtResult *result, gpointer user_data)
sprintf(str, "AT+BAC=%d", HFP_CODEC_CVSD);
slc_establish_data_ref(sed);
g_at_chat_send(info->chat, str, NULL, bac_cb, sed,
slc_establish_data_unref);
g_at_chat_send(info->chat, str, none_prefix, bac_cb,
sed, slc_establish_data_unref);
return;
}

View File

@@ -333,6 +333,10 @@ static void generic_cb(gboolean ok, GAtResult *result, gpointer user_data)
}
}
if (!ok && vd->calls)
g_at_chat_send(vd->chat, "AT+CLCC", clcc_prefix,
clcc_poll_cb, req->vc, NULL);
req->cb(&error, req->data);
}
@@ -711,6 +715,16 @@ static void ccwa_notify(GAtResult *result, gpointer user_data)
at_util_call_compare_by_status))
return;
/* some phones may send extra CCWA after active call is ended
* this would trigger creation of second call in state 'WAITING'
* as our previous WAITING call has been promoted to INCOMING
*/
if (g_slist_find_custom(vd->calls,
GINT_TO_POINTER(CALL_STATUS_INCOMING),
at_util_call_compare_by_status))
return;
g_at_result_iter_init(&iter, result);
if (!g_at_result_iter_next(&iter, "+CCWA:"))
@@ -1134,6 +1148,10 @@ static void hfp_clcc_cb(gboolean ok, GAtResult *result, gpointer user_data)
struct ofono_voicecall *vc = user_data;
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
unsigned int mpty_ids;
GSList *n;
struct ofono_call *nc;
unsigned int num_active = 0;
unsigned int num_held = 0;
if (!ok)
return;
@@ -1142,6 +1160,22 @@ static void hfp_clcc_cb(gboolean ok, GAtResult *result, gpointer user_data)
g_slist_foreach(vd->calls, voicecall_notify, vc);
ofono_voicecall_mpty_hint(vc, mpty_ids);
n = vd->calls;
while (n) {
nc = n->data;
if (nc->status == CALL_STATUS_ACTIVE)
num_active++;
else if (nc->status == CALL_STATUS_HELD)
num_held++;
n = n->next;
}
if ((num_active > 1 || num_held > 1) && !vd->clcc_source)
vd->clcc_source = g_timeout_add(POLL_CLCC_INTERVAL, poll_clcc, vc);
}
static void hfp_voicecall_initialized(gboolean ok, GAtResult *result,
@@ -1183,8 +1217,8 @@ static int hfp_voicecall_probe(struct ofono_voicecall *vc, unsigned int vendor,
ofono_voicecall_set_data(vc, vd);
g_at_chat_send(vd->chat, "AT+CLIP=1", NULL, NULL, NULL, NULL);
g_at_chat_send(vd->chat, "AT+CCWA=1", NULL,
g_at_chat_send(vd->chat, "AT+CLIP=1", none_prefix, NULL, NULL, NULL);
g_at_chat_send(vd->chat, "AT+CCWA=1", none_prefix,
hfp_voicecall_initialized, vc, NULL);
return 0;
}

View File

@@ -0,0 +1,284 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_util.h"
#include "ril_log.h"
#include "ril_constants.h"
#include "common.h"
/* See 3GPP 27.007 7.4 for possible values */
#define RIL_MAX_SERVICE_LENGTH 3
/*
* ril.h does not state that string count must be given, but that is
* still expected by the modem
*/
#define RIL_QUERY_STRING_COUNT 4
#define RIL_SET_STRING_COUNT 5
#define RIL_SET_PW_STRING_COUNT 3
struct ril_call_barring {
GRilIoQueue *q;
guint timer_id;
};
struct ril_call_barring_cbd {
struct ril_call_barring *bd;
union _ofono_call_barring_cb {
ofono_call_barring_query_cb_t query;
ofono_call_barring_set_cb_t set;
gpointer ptr;
} cb;
gpointer data;
};
#define ril_call_barring_cbd_free g_free
static inline struct ril_call_barring *ril_call_barring_get_data(
struct ofono_call_barring *b)
{
return ofono_call_barring_get_data(b);
}
static struct ril_call_barring_cbd *ril_call_barring_cbd_new(
struct ril_call_barring *bd, void *cb, void *data)
{
struct ril_call_barring_cbd *cbd;
cbd = g_new0(struct ril_call_barring_cbd, 1);
cbd->bd = bd;
cbd->cb.ptr = cb;
cbd->data = data;
return cbd;
}
static inline void ril_call_barring_submit_request(struct ril_call_barring *bd,
GRilIoRequest* req, guint code, GRilIoChannelResponseFunc response,
void *cb, void *data)
{
grilio_queue_send_request_full(bd->q, req, code, response,
ril_call_barring_cbd_free,
ril_call_barring_cbd_new(bd, cb, data));
}
static void ril_call_barring_query_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_call_barring_cbd *cbd = user_data;
ofono_call_barring_query_cb_t cb = cbd->cb.query;
if (status == RIL_E_SUCCESS) {
int bearer_class = 0;
GRilIoParser rilp;
/*
* Services for which the specified barring facility is active.
* "0" means "disabled for all, -1 if unknown"
*/
grilio_parser_init(&rilp, data, len);
grilio_parser_get_int32(&rilp, NULL); /* count */
grilio_parser_get_int32(&rilp, &bearer_class);
DBG("Active services: %d", bearer_class);
cb(ril_error_ok(&error), bearer_class, cbd->data);
} else {
ofono_error("Call Barring query error %d", status);
cb(ril_error_failure(&error), 0, cbd->data);
}
}
static void ril_call_barring_query(struct ofono_call_barring *b,
const char *lock, int cls,
ofono_call_barring_query_cb_t cb, void *data)
{
struct ril_call_barring *bd = ofono_call_barring_get_data(b);
char cls_textual[RIL_MAX_SERVICE_LENGTH];
GRilIoRequest *req = grilio_request_new();
DBG("lock: %s, services to query: %d", lock, cls);
/*
* RIL modems do not support 7 as default bearer class. According to
* the 22.030 Annex C: When service code is not given it corresponds to
* "All tele and bearer services"
*/
if (cls == BEARER_CLASS_DEFAULT) {
cls = SERVICE_CLASS_NONE;
}
sprintf(cls_textual, "%d", cls);
/*
* See 3GPP 27.007 7.4 for parameter descriptions.
* According to ril.h password should be empty string "" when not
* needed, but in reality we only need to give string length as 0
*/
grilio_request_append_int32(req, RIL_QUERY_STRING_COUNT);
grilio_request_append_utf8(req, lock); /* Facility code */
grilio_request_append_int32(req, 0); /* Password length */
grilio_request_append_utf8(req, cls_textual);
grilio_request_append_utf8(req, NULL); /* AID (not yet supported) */
ril_call_barring_submit_request(bd, req,
RIL_REQUEST_QUERY_FACILITY_LOCK,
ril_call_barring_query_cb, cb, data);
grilio_request_unref(req);
}
static void ril_call_barring_set_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_call_barring_cbd *cbd = user_data;
ofono_call_barring_set_cb_t cb = cbd->cb.set;
if (status == RIL_E_SUCCESS) {
cb(ril_error_ok(&error), cbd->data);
} else {
ofono_error("Call Barring Set error %d", status);
cb(ril_error_failure(&error), cbd->data);
}
}
static void ril_call_barring_set(struct ofono_call_barring *b,
const char *lock, int enable, const char *passwd, int cls,
ofono_call_barring_set_cb_t cb, void *data)
{
struct ril_call_barring *bd = ofono_call_barring_get_data(b);
char cls_textual[RIL_MAX_SERVICE_LENGTH];
GRilIoRequest *req = grilio_request_new();
DBG("lock: %s, enable: %i, bearer class: %i", lock, enable, cls);
/*
* RIL modem does not support 7 as default bearer class. According to
* the 22.030 Annex C: When service code is not given it corresponds to
* "All tele and bearer services"
*/
if (cls == BEARER_CLASS_DEFAULT) {
cls = SERVICE_CLASS_NONE;
}
sprintf(cls_textual, "%d", cls);
/* See 3GPP 27.007 7.4 for parameter descriptions */
grilio_request_append_int32(req, RIL_SET_STRING_COUNT);
grilio_request_append_utf8(req, lock); /* Facility code */
grilio_request_append_utf8(req, enable ?
RIL_FACILITY_LOCK :
RIL_FACILITY_UNLOCK);
grilio_request_append_utf8(req, passwd);
grilio_request_append_utf8(req, cls_textual);
grilio_request_append_utf8(req, NULL); /* AID (not yet supported) */
ril_call_barring_submit_request(bd, req,
RIL_REQUEST_SET_FACILITY_LOCK,
ril_call_barring_set_cb, cb, data);
grilio_request_unref(req);
}
static void ril_call_barring_set_passwd_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_call_barring_cbd *cbd = user_data;
ofono_call_barring_set_cb_t cb = cbd->cb.set;
if (status == RIL_E_SUCCESS) {
cb(ril_error_ok(&error), cbd->data);
} else {
ofono_error("Call Barring Set PW error %d", status);
cb(ril_error_failure(&error), cbd->data);
}
}
static void ril_call_barring_set_passwd(struct ofono_call_barring *b,
const char *lock, const char *old_passwd,
const char *new_passwd, ofono_call_barring_set_cb_t cb,
void *data)
{
struct ril_call_barring *bd = ofono_call_barring_get_data(b);
GRilIoRequest *req = grilio_request_new();
DBG("");
grilio_request_append_int32(req, RIL_SET_PW_STRING_COUNT);
grilio_request_append_utf8(req, lock); /* Facility code */
grilio_request_append_utf8(req, old_passwd);
grilio_request_append_utf8(req, new_passwd);
ril_call_barring_submit_request(bd, req,
RIL_REQUEST_CHANGE_BARRING_PASSWORD,
ril_call_barring_set_passwd_cb, cb, data);
grilio_request_unref(req);
}
static gboolean ril_call_barring_register(gpointer user_data)
{
struct ofono_call_barring *b = user_data;
struct ril_call_barring *bd = ril_call_barring_get_data(b);
GASSERT(bd->timer_id);
bd->timer_id = 0;
ofono_call_barring_register(b);
return FALSE;
}
static int ril_call_barring_probe(struct ofono_call_barring *b,
unsigned int vendor, void *data)
{
struct ril_modem *modem = data;
struct ril_call_barring *bd = g_new0(struct ril_call_barring, 1);
DBG("");
bd->q = grilio_queue_new(ril_modem_io(modem));
bd->timer_id = g_idle_add(ril_call_barring_register, b);
ofono_call_barring_set_data(b, bd);
return 0;
}
static void ril_call_barring_remove(struct ofono_call_barring *b)
{
struct ril_call_barring *bd = ril_call_barring_get_data(b);
DBG("");
ofono_call_barring_set_data(b, NULL);
if (bd->timer_id > 0) {
g_source_remove(bd->timer_id);
}
grilio_queue_cancel_all(bd->q, FALSE);
grilio_queue_unref(bd->q);
g_free(bd);
}
const struct ofono_call_barring_driver ril_call_barring_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_call_barring_probe,
.remove = ril_call_barring_remove,
.query = ril_call_barring_query,
.set = ril_call_barring_set,
.set_passwd = ril_call_barring_set_passwd
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,315 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_util.h"
#include "ril_log.h"
#include "ril_constants.h"
#include "common.h"
struct ril_call_forward {
GRilIoQueue *q;
guint timer_id;
};
enum ril_call_forward_cmd {
CF_ACTION_DISABLE,
CF_ACTION_ENABLE,
CF_ACTION_UNUSED,
CF_ACTION_REGISTRATION,
CF_ACTION_ERASURE
};
struct ril_call_forward_cbd {
struct ril_call_forward *fd;
union _ofono_call_forward_cb {
ofono_call_forwarding_query_cb_t query;
ofono_call_forwarding_set_cb_t set;
gpointer ptr;
} cb;
gpointer data;
};
#define ril_call_forward_cbd_free g_free
static inline struct ril_call_forward *ril_call_forward_get_data(
struct ofono_call_forwarding *cf)
{
return ofono_call_forwarding_get_data(cf);
}
static struct ril_call_forward_cbd *ril_call_forward_cbd_new(void *cb,
void *data)
{
struct ril_call_forward_cbd *cbd;
cbd = g_new0(struct ril_call_forward_cbd, 1);
cbd->cb.ptr = cb;
cbd->data = data;
return cbd;
}
static inline void ril_call_forward_submit_request(struct ril_call_forward *fd,
GRilIoRequest* req, guint code, GRilIoChannelResponseFunc response,
void *cb, void *data)
{
grilio_queue_send_request_full(fd->q, req, code, response,
ril_call_forward_cbd_free,
ril_call_forward_cbd_new(cb, data));
}
static void ril_forward_set_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_call_forward_cbd *cbd = user_data;
ofono_call_forwarding_set_cb_t cb = cbd->cb.set;
if (status == RIL_E_SUCCESS) {
cb(ril_error_ok(&error), cbd->data);
} else {
ofono_error("CF setting failed");
cb(ril_error_failure(&error), cbd->data);
}
}
static void ril_call_forward_registration(struct ofono_call_forwarding *cf,
int type, int cls, const struct ofono_phone_number *number,
int time, ofono_call_forwarding_set_cb_t cb, void *data)
{
struct ril_call_forward *fd = ril_call_forward_get_data(cf);
GRilIoRequest *req = grilio_request_new();
ofono_info("cf registration");
grilio_request_append_int32(req, CF_ACTION_REGISTRATION);
grilio_request_append_int32(req, type);
/*
* Modem seems to respond with error to all queries
* or settings made with bearer class
* BEARER_CLASS_DEFAULT. Design decision: If given
* class is BEARER_CLASS_DEFAULT let's map it to
* BEARER_CLASS_VOICE as per RIL design.
*/
if (cls == BEARER_CLASS_DEFAULT) {
cls = BEARER_CLASS_VOICE;
}
grilio_request_append_int32(req, cls);
grilio_request_append_int32(req, number->type);
grilio_request_append_utf8(req, number->number);
grilio_request_append_int32(req, time);
ril_call_forward_submit_request(fd, req, RIL_REQUEST_SET_CALL_FORWARD,
ril_forward_set_cb, cb, data);
grilio_request_unref(req);
}
static void ril_call_forward_send_cmd(struct ofono_call_forwarding *cf,
int type, int cls, ofono_call_forwarding_set_cb_t cb,
void *data, int action)
{
struct ril_call_forward *fd = ril_call_forward_get_data(cf);
GRilIoRequest *req = grilio_request_new();
grilio_request_append_int32(req, action);
grilio_request_append_int32(req, type);
/*
* Modem seems to respond with error to all queries
* or settings made with bearer class
* BEARER_CLASS_DEFAULT. Design decision: If given
* class is BEARER_CLASS_DEFAULT let's map it to
* BEARER_CLASS_VOICE as per RIL design.
*/
if (cls == BEARER_CLASS_DEFAULT) {
cls = BEARER_CLASS_VOICE;
}
grilio_request_append_int32(req, cls); /* Service class */
/* Following 3 values have no real meaning in erasure
* but apparently RIL expects them so fields need to
* be filled. Otherwise there is no response
*/
grilio_request_append_int32(req, 0x81); /* TOA unknown */
grilio_request_append_utf8(req, "1234567890");
grilio_request_append_int32(req, 60);
ril_call_forward_submit_request(fd, req, RIL_REQUEST_SET_CALL_FORWARD,
ril_forward_set_cb, cb, data);
grilio_request_unref(req);
}
static void ril_call_forward_erasure(struct ofono_call_forwarding *cf,
int type, int cls, ofono_call_forwarding_set_cb_t cb, void *data)
{
ofono_info("CF_ACTION_ERASURE");
ril_call_forward_send_cmd(cf, type, cls, cb, data, CF_ACTION_ERASURE);
}
static void ril_call_forward_deactivate(struct ofono_call_forwarding *cf,
int type, int cls, ofono_call_forwarding_set_cb_t cb, void *data)
{
ofono_info("CF_ACTION_DISABLE");
ril_call_forward_send_cmd(cf, type, cls, cb, data, CF_ACTION_DISABLE);
}
static void ril_call_forward_activate(struct ofono_call_forwarding *cf,
int type, int cls, ofono_call_forwarding_set_cb_t cb, void *data)
{
ofono_info("CF_ACTION_ENABLE");
ril_call_forward_send_cmd(cf, type, cls, cb, data, CF_ACTION_ENABLE);
}
static void ril_call_forward_query_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_call_forward_cbd *cbd = user_data;
ofono_call_forwarding_query_cb_t cb = cbd->cb.query;
if (status == RIL_E_SUCCESS) {
struct ofono_call_forwarding_condition *list = NULL;
GRilIoParser rilp;
int count = 0;
int i;
grilio_parser_init(&rilp, data, len);
grilio_parser_get_int32(&rilp, &count);
list = g_new0(struct ofono_call_forwarding_condition, count);
for (i = 0; i < count; i++) {
struct ofono_call_forwarding_condition *fw = list + i;
char *str;
grilio_parser_get_int32(&rilp, &fw->status);
grilio_parser_get_int32(&rilp, NULL);
grilio_parser_get_int32(&rilp, &fw->cls);
grilio_parser_get_int32(&rilp, &fw->phone_number.type);
str = grilio_parser_get_utf8(&rilp);
if (str) {
strncpy(fw->phone_number.number, str,
OFONO_MAX_PHONE_NUMBER_LENGTH);
fw->phone_number.number[
OFONO_MAX_PHONE_NUMBER_LENGTH] = 0;
g_free(str);
}
grilio_parser_get_int32(&rilp, &fw->time);
}
cb(ril_error_ok(&error), count, list, cbd->data);
g_free(list);
} else {
ofono_error("CF query failed");
cb(ril_error_failure(&error), 0, NULL, cbd->data);
}
}
static void ril_call_forward_query(struct ofono_call_forwarding *cf, int type,
int cls, ofono_call_forwarding_query_cb_t cb, void *data)
{
struct ril_call_forward *fd = ril_call_forward_get_data(cf);
GRilIoRequest *req = grilio_request_new();
ofono_info("cf query");
grilio_request_append_int32(req, 2);
grilio_request_append_int32(req, type);
/*
* Modem seems to respond with error to all queries
* or settings made with bearer class
* BEARER_CLASS_DEFAULT. Design decision: If given
* class is BEARER_CLASS_DEFAULT let's map it to
* SERVICE_CLASS_NONE as per RIL design.
*/
if (cls == BEARER_CLASS_DEFAULT) {
cls = SERVICE_CLASS_NONE;
}
grilio_request_append_int32(req, cls);
/* Following 3 values have no real meaning in query
* but apparently RIL expects them so fields need to
* be filled. Otherwise there is no response
*/
grilio_request_append_int32(req, 0x81); /* TOA unknown */
grilio_request_append_utf8(req, "1234567890");
grilio_request_append_int32(req, 0);
ril_call_forward_submit_request(fd, req,
RIL_REQUEST_QUERY_CALL_FORWARD_STATUS,
ril_call_forward_query_cb, cb, data);
grilio_request_unref(req);
}
static gboolean ril_call_forward_register(gpointer user_data)
{
struct ofono_call_forwarding *cf = user_data;
struct ril_call_forward *fd = ril_call_forward_get_data(cf);
fd->timer_id = 0;
ofono_call_forwarding_register(cf);
return FALSE;
}
static int ril_call_forward_probe(struct ofono_call_forwarding *cf,
unsigned int vendor, void *data)
{
struct ril_modem *modem = data;
struct ril_call_forward *fd = g_try_new0(struct ril_call_forward, 1);
DBG("");
fd->q = grilio_queue_new(ril_modem_io(modem));
fd->timer_id = g_idle_add(ril_call_forward_register, cf);
ofono_call_forwarding_set_data(cf, fd);
return 0;
}
static void ril_call_forward_remove(struct ofono_call_forwarding *cf)
{
struct ril_call_forward *fd = ril_call_forward_get_data(cf);
DBG("");
ofono_call_forwarding_set_data(cf, NULL);
if (fd->timer_id > 0) {
g_source_remove(fd->timer_id);
}
grilio_queue_cancel_all(fd->q, FALSE);
grilio_queue_unref(fd->q);
g_free(fd);
}
const struct ofono_call_forwarding_driver ril_call_forwarding_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_call_forward_probe,
.remove = ril_call_forward_remove,
.erasure = ril_call_forward_erasure,
.deactivation = ril_call_forward_deactivate,
.query = ril_call_forward_query,
.registration = ril_call_forward_registration,
.activation = ril_call_forward_activate
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,309 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_util.h"
#include "ril_log.h"
#include "ril_constants.h"
#include "common.h"
struct ril_call_settings {
GRilIoQueue *q;
guint timer_id;
};
struct ril_call_settings_cbd {
union _ofono_call_settings_cb {
ofono_call_settings_status_cb_t status;
ofono_call_settings_set_cb_t set;
ofono_call_settings_clir_cb_t clir;
gpointer ptr;
} cb;
gpointer data;
};
#define ril_call_settings_cbd_free g_free
static inline struct ril_call_settings *ril_call_settings_get_data(
struct ofono_call_settings *b)
{
return ofono_call_settings_get_data(b);
}
static struct ril_call_settings_cbd *ril_call_settings_cbd_new(void *cb,
void *data)
{
struct ril_call_settings_cbd *cbd;
cbd = g_new0(struct ril_call_settings_cbd, 1);
cbd->cb.ptr = cb;
cbd->data = data;
return cbd;
}
static inline void ril_call_settings_submit_req(struct ril_call_settings *sd,
GRilIoRequest* req, guint code, GRilIoChannelResponseFunc response,
void *cb, void *data)
{
grilio_queue_send_request_full(sd->q, req, code, response,
ril_call_settings_cbd_free,
ril_call_settings_cbd_new(cb, data));
}
static void ril_call_settings_clip_query_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_call_settings_cbd *cbd = user_data;
ofono_call_settings_status_cb_t cb = cbd->cb.status;
if (status == RIL_E_SUCCESS) {
GRilIoParser rilp;
int res = 0;
/* data length of the response */
grilio_parser_init(&rilp, data, len);
if (grilio_parser_get_int32(&rilp, &res) && res > 0) {
grilio_parser_get_int32(&rilp, &res);
}
cb(ril_error_ok(&error), res, cbd->data);
} else {
cb(ril_error_failure(&error), -1, cbd->data);
}
}
static void ril_call_settings_set_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_call_settings_cbd *cbd = user_data;
ofono_call_settings_set_cb_t cb = cbd->cb.set;
if (status == RIL_E_SUCCESS) {
cb(ril_error_ok(&error), cbd->data);
} else {
cb(ril_error_failure(&error), cbd->data);
}
}
static void ril_call_settings_cw_set(struct ofono_call_settings *cs, int mode,
int cls, ofono_call_settings_set_cb_t cb, void *data)
{
struct ril_call_settings *sd = ril_call_settings_get_data(cs);
GRilIoRequest *req = grilio_request_sized_new(12);
grilio_request_append_int32(req, 2); /* Number of params */
grilio_request_append_int32(req, mode); /* on/off */
/* Modem seems to respond with error to all queries
* or settings made with bearer class
* BEARER_CLASS_DEFAULT. Design decision: If given
* class is BEARER_CLASS_DEFAULT let's map it to
* SERVICE_CLASS_VOICE effectively making it the
* default bearer. This in line with API which is
* contains only voice anyways.
*/
if (cls == BEARER_CLASS_DEFAULT) {
cls = BEARER_CLASS_VOICE;
}
grilio_request_append_int32(req, cls); /* Service class */
ril_call_settings_submit_req(sd, req, RIL_REQUEST_SET_CALL_WAITING,
ril_call_settings_set_cb, cb, data);
grilio_request_unref(req);
}
static void ril_call_settings_cw_query_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_call_settings_cbd *cbd = user_data;
ofono_call_settings_status_cb_t cb = cbd->cb.status;
if (status == RIL_E_SUCCESS) {
GRilIoParser rilp;
int res = 0;
int sv = 0;
grilio_parser_init(&rilp, data, len);
/* first value in int[] is len so let's skip that */
grilio_parser_get_int32(&rilp, NULL);
/* status of call waiting service, disabled is returned only if
* service is not active for any service class */
grilio_parser_get_int32(&rilp, &res);
DBG("CW enabled/disabled: %d", res);
if (res > 0) {
/* services for which call waiting is enabled,
27.007 7.12 */
grilio_parser_get_int32(&rilp, &sv);
DBG("CW enabled for: %d", sv);
}
cb(ril_error_ok(&error), sv, cbd->data);
} else {
cb(ril_error_failure(&error), -1, cbd->data);
}
}
static void ril_call_settings_cw_query(struct ofono_call_settings *cs, int cls,
ofono_call_settings_status_cb_t cb, void *data)
{
struct ril_call_settings *sd = ril_call_settings_get_data(cs);
GRilIoRequest *req = grilio_request_sized_new(8);
grilio_request_append_int32(req, 1); /* Number of params */
/*
* RILD expects service class to be 0 as certain carriers can reject
* the query with specific service class
*/
grilio_request_append_int32(req, 0);
ril_call_settings_submit_req(sd, req, RIL_REQUEST_QUERY_CALL_WAITING,
ril_call_settings_cw_query_cb, cb, data);
grilio_request_unref(req);
}
static void ril_call_settings_clip_query(struct ofono_call_settings *cs,
ofono_call_settings_status_cb_t cb, void *data)
{
struct ril_call_settings *sd = ril_call_settings_get_data(cs);
ril_call_settings_submit_req(sd, NULL, RIL_REQUEST_QUERY_CLIP,
ril_call_settings_clip_query_cb, cb, data);
}
static void ril_call_settings_clir_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_call_settings_cbd *cbd = user_data;
ofono_call_settings_clir_cb_t cb = cbd->cb.clir;
if (status == RIL_E_SUCCESS) {
GRilIoParser rilp;
int override = -1, network = -1;
grilio_parser_init(&rilp, data, len);
/*first value in int[] is len so let's skip that*/
grilio_parser_get_int32(&rilp, NULL);
/* Set HideCallerId property from network */
grilio_parser_get_int32(&rilp, &override);
/* CallingLineRestriction indicates the state of
the CLIR supplementary service in the network */
grilio_parser_get_int32(&rilp, &network);
cb(ril_error_ok(&error), override, network, cbd->data);
} else {
cb(ril_error_failure(&error), -1, -1, cbd->data);
}
}
static void ril_call_settings_clir_query(struct ofono_call_settings *cs,
ofono_call_settings_clir_cb_t cb, void *data)
{
struct ril_call_settings *sd = ril_call_settings_get_data(cs);
ril_call_settings_submit_req(sd, NULL, RIL_REQUEST_GET_CLIR,
ril_call_settings_clir_cb, cb, data);
}
static void ril_call_settings_clir_set(struct ofono_call_settings *cs,
int mode, ofono_call_settings_set_cb_t cb, void *data)
{
struct ril_call_settings *sd = ril_call_settings_get_data(cs);
GRilIoRequest *req = grilio_request_sized_new(8);
grilio_request_append_int32(req, 1); /* Number of params */
grilio_request_append_int32(req, mode); /* for outgoing calls */
ril_call_settings_submit_req(sd, req, RIL_REQUEST_SET_CLIR,
ril_call_settings_set_cb, cb, data);
grilio_request_unref(req);
}
static gboolean ril_call_settings_register(gpointer user_data)
{
struct ofono_call_settings *cs = user_data;
struct ril_call_settings *sd = ril_call_settings_get_data(cs);
DBG("");
GASSERT(sd->timer_id);
sd->timer_id = 0;
ofono_call_settings_register(cs);
/* Single-shot */
return FALSE;
}
static int ril_call_settings_probe(struct ofono_call_settings *cs,
unsigned int vendor, void *data)
{
struct ril_modem *modem = data;
struct ril_call_settings *sd = g_try_new0(struct ril_call_settings, 1);
DBG("");
sd->q = grilio_queue_new(ril_modem_io(modem));
sd->timer_id = g_idle_add(ril_call_settings_register, cs);
ofono_call_settings_set_data(cs, sd);
return 0;
}
static void ril_call_settings_remove(struct ofono_call_settings *cs)
{
struct ril_call_settings *sd = ril_call_settings_get_data(cs);
DBG("");
ofono_call_settings_set_data(cs, NULL);
if (sd->timer_id > 0) {
g_source_remove(sd->timer_id);
}
grilio_queue_cancel_all(sd->q, FALSE);
grilio_queue_unref(sd->q);
g_free(sd);
}
const struct ofono_call_settings_driver ril_call_settings_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_call_settings_probe,
.remove = ril_call_settings_remove,
.clip_query = ril_call_settings_clip_query,
.cw_query = ril_call_settings_cw_query,
.cw_set = ril_call_settings_cw_set,
.clir_query = ril_call_settings_clir_query,
.clir_set = ril_call_settings_clir_set
/*
* Not supported in RIL API
* .colp_query = ril_call_settings_colp_query,
* .colr_query = ril_call_settings_colr_query
*/
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,151 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_util.h"
#include "ril_log.h"
#include "ril_constants.h"
struct ril_call_volume {
struct ofono_call_volume *v;
GRilIoQueue *q;
guint timer_id;
};
struct ril_call_volume_req {
ofono_call_volume_cb_t cb;
gpointer data;
};
static inline struct ril_call_volume *ril_call_volume_get_data(
struct ofono_call_volume *v)
{
return ofono_call_volume_get_data(v);
}
static void ril_call_volume_mute_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_call_volume_req *cbd = user_data;
ofono_call_volume_cb_t cb = cbd->cb;
if (status == RIL_E_SUCCESS) {
cb(ril_error_ok(&error), cbd->data);
} else {
ofono_error("Could not set the ril mute state");
cb(ril_error_failure(&error), cbd->data);
}
}
static void ril_call_volume_mute(struct ofono_call_volume *v, int muted,
ofono_call_volume_cb_t cb, void *data)
{
struct ril_call_volume *vd = ril_call_volume_get_data(v);
struct ril_call_volume_req *cbd;
GRilIoRequest *req = grilio_request_sized_new(8);
cbd = g_new(struct ril_call_volume_req, 1);
cbd->cb = cb;
cbd->data = data;
DBG("%d", muted);
grilio_request_append_int32(req, 1);
grilio_request_append_int32(req, muted);
grilio_queue_send_request_full(vd->q, req, RIL_REQUEST_SET_MUTE,
ril_call_volume_mute_cb, g_free, cbd);
grilio_request_unref(req);
}
static void ril_call_volume_query_mute_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ril_call_volume *vd = user_data;
if (status == RIL_E_SUCCESS) {
int muted = 0;
GRilIoParser rilp;
grilio_parser_init(&rilp, data, len);
grilio_parser_get_int32(&rilp, NULL); /* Array length */
grilio_parser_get_int32(&rilp, &muted);
DBG("{%d}", muted);
ofono_call_volume_set_muted(vd->v, muted);
} else {
ofono_error("Could not retrive the ril mute state");
}
}
static gboolean ril_call_volume_register(gpointer user_data)
{
struct ril_call_volume *vd = user_data;
DBG("");
GASSERT(vd->timer_id);
vd->timer_id = 0;
ofono_call_volume_register(vd->v);
/* Probe the mute state */
grilio_queue_send_request_full(vd->q, NULL,
RIL_REQUEST_GET_MUTE, ril_call_volume_query_mute_cb, NULL, vd);
/* This makes the timeout a single-shot */
return FALSE;
}
static int ril_call_volume_probe(struct ofono_call_volume *v,
unsigned int vendor, void *data)
{
struct ril_modem *modem = data;
struct ril_call_volume *vd = g_new0(struct ril_call_volume, 1);
DBG("");
vd->v = v;
vd->q = grilio_queue_new(ril_modem_io(modem));
vd->timer_id = g_idle_add(ril_call_volume_register, vd);
ofono_call_volume_set_data(v, vd);
return 0;
}
static void ril_call_volume_remove(struct ofono_call_volume *v)
{
struct ril_call_volume *vd = ril_call_volume_get_data(v);
DBG("");
ofono_call_volume_set_data(v, NULL);
if (vd->timer_id) {
g_source_remove(vd->timer_id);
}
grilio_queue_cancel_all(vd->q, FALSE);
grilio_queue_unref(vd->q);
g_free(vd);
}
const struct ofono_call_volume_driver ril_call_volume_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_call_volume_probe,
.remove = ril_call_volume_remove,
.mute = ril_call_volume_mute,
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

119
ofono/drivers/ril/ril_cbs.c Normal file
View File

@@ -0,0 +1,119 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_util.h"
#include "ril_log.h"
#include "ril_constants.h"
struct ril_cbs {
struct ofono_cbs *cbs;
GRilIoChannel *io;
guint timer_id;
gulong event_id;
};
static void ril_set_topics(struct ofono_cbs *cbs, const char *topics,
ofono_cbs_set_cb_t cb, void *data)
{
struct ofono_error error;
cb(ril_error_ok(&error), data);
}
static void ril_clear_topics(struct ofono_cbs *cbs,
ofono_cbs_set_cb_t cb, void *data)
{
struct ofono_error error;
cb(ril_error_ok(&error), data);
}
static void ril_cbs_notify(GRilIoChannel *io, guint code,
const void *data, guint len, void *user_data)
{
struct ril_cbs *cd = user_data;
GRilIoParser rilp;
char* pdu;
GASSERT(code == RIL_UNSOL_ON_USSD);
grilio_parser_init(&rilp, data, len);
pdu = grilio_parser_get_utf8(&rilp);
DBG("%s", pdu);
if (pdu) {
ofono_cbs_notify(cd->cbs, (const guchar *)pdu, strlen(pdu));
g_free(pdu);
}
}
static gboolean ril_cbs_register(gpointer user_data)
{
struct ril_cbs *cd = user_data;
DBG("");
GASSERT(cd->timer_id);
cd->timer_id = 0;
ofono_cbs_register(cd->cbs);
cd->event_id = grilio_channel_add_unsol_event_handler(cd->io,
ril_cbs_notify, RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS, cd);
/* Single-shot */
return FALSE;
}
static int ril_cbs_probe(struct ofono_cbs *cbs, unsigned int vendor,
void *data)
{
struct ril_modem *modem = data;
struct ril_cbs *cd = g_try_new0(struct ril_cbs, 1);
DBG("");
cd->cbs = cbs;
cd->io = grilio_channel_ref(ril_modem_io(modem));
cd->timer_id = g_idle_add(ril_cbs_register, cd);
ofono_cbs_set_data(cbs, cd);
return 0;
}
static void ril_cbs_remove(struct ofono_cbs *cbs)
{
struct ril_cbs *cd = ofono_cbs_get_data(cbs);
DBG("");
ofono_cbs_set_data(cbs, NULL);
if (cd->timer_id > 0) {
g_source_remove(cd->timer_id);
}
grilio_channel_remove_handler(cd->io, cd->event_id);
grilio_channel_unref(cd->io);
g_free(cd);
}
const struct ofono_cbs_driver ril_cbs_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_cbs_probe,
.remove = ril_cbs_remove,
.set_topics = ril_set_topics,
.clear_topics = ril_clear_topics
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,447 @@
/*
*
* RIL constants adopted from AOSP's header:
*
* /hardware/ril/reference_ril/ril.h
*
* Copyright (C) 2013 Canonical Ltd.
* Copyright (C) 2013-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef __RIL_CONSTANTS_H
#define __RIL_CONSTANTS_H 1
/* Error Codes */
#define RIL_E_SUCCESS 0
#define RIL_E_RADIO_NOT_AVAILABLE 1
#define RIL_E_GENERIC_FAILURE 2
#define RIL_E_PASSWORD_INCORRECT 3
#define RIL_E_SIM_PIN2 4
#define RIL_E_SIM_PUK2 5
#define RIL_E_REQUEST_NOT_SUPPORTED 6
#define RIL_E_CANCELLED 7
#define RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL 8
#define RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW 9
#define RIL_E_SMS_SEND_FAIL_RETRY 10
#define RIL_E_SIM_ABSENT 11
#define RIL_E_SUBSCRIPTION_NOT_AVAILABLE 12
#define RIL_E_MODE_NOT_SUPPORTED 13
#define RIL_E_FDN_CHECK_FAILURE 14
#define RIL_E_ILLEGAL_SIM_OR_ME 15
#define RIL_E_UNUSED 16
#define RIL_E_DIAL_MODIFIED_TO_USSD 17
#define RIL_E_DIAL_MODIFIED_TO_SS 18
#define RIL_E_DIAL_MODIFIED_TO_DIAL 19
#define RIL_E_USSD_MODIFIED_TO_DIAL 20
#define RIL_E_USSD_MODIFIED_TO_SS 21
#define RIL_E_USSD_MODIFIED_TO_USSD 22
#define RIL_E_SS_MODIFIED_TO_DIAL 23
#define RIL_E_SS_MODIFIED_TO_USSD 24
#define RIL_E_SS_MODIFIED_TO_SS 25
#define RIL_E_SUBSCRIPTION_NOT_SUPPORTED 26
#define RIL_E_MISSING_RESOURCE 27
#define RIL_E_NO_SUCH_ELEMENT 28
#define RIL_E_INVALID_PARAMETER 29
/* call states */
enum ril_call_state {
RIL_CALL_ACTIVE = 0,
RIL_CALL_HOLDING = 1,
RIL_CALL_DIALING = 2,
RIL_CALL_ALERTING = 3,
RIL_CALL_INCOMING = 4,
RIL_CALL_WAITING = 5
};
/* Radio state */
enum ril_radio_state {
RADIO_STATE_OFF = 0,
RADIO_STATE_UNAVAILABLE = 1,
RADIO_STATE_SIM_NOT_READY = 2,
RADIO_STATE_SIM_LOCKED_OR_ABSENT = 3,
RADIO_STATE_SIM_READY = 4,
RADIO_STATE_RUIM_NOT_READY = 5,
RADIO_STATE_RUIM_READY = 6,
RADIO_STATE_RUIM_LOCKED_OR_ABSENT = 7,
RADIO_STATE_NV_NOT_READY = 8,
RADIO_STATE_NV_READY = 9,
RADIO_STATE_ON = 10
};
/* Preferred network types */
enum ril_pref_net_type {
PREF_NET_TYPE_GSM_WCDMA = 0,
PREF_NET_TYPE_GSM_ONLY = 1,
PREF_NET_TYPE_WCDMA = 2,
PREF_NET_TYPE_GSM_WCDMA_AUTO = 3,
PREF_NET_TYPE_CDMA_EVDO_AUTO = 4,
PREF_NET_TYPE_CDMA_ONLY = 5,
PREF_NET_TYPE_EVDO_ONLY = 6,
PREF_NET_TYPE_GSM_WCDMA_CDMA_EVDO_AUTO = 7,
PREF_NET_TYPE_LTE_CDMA_EVDO = 8,
PREF_NET_TYPE_LTE_GSM_WCDMA = 9,
PREF_NET_TYPE_LTE_CMDA_EVDO_GSM_WCDMA = 10,
PREF_NET_TYPE_LTE_ONLY = 11,
PREF_NET_TYPE_LTE_WCDMA = 12
};
/* Radio technologies */
enum ril_radio_tech {
RADIO_TECH_UNKNOWN = 0,
RADIO_TECH_GPRS = 1,
RADIO_TECH_EDGE = 2,
RADIO_TECH_UMTS = 3,
RADIO_TECH_IS95A = 4,
RADIO_TECH_IS95B = 5,
RADIO_TECH_1xRTT = 6,
RADIO_TECH_EVDO_0 = 7,
RADIO_TECH_EVDO_A = 8,
RADIO_TECH_HSDPA = 9,
RADIO_TECH_HSUPA = 10,
RADIO_TECH_HSPA = 11,
RADIO_TECH_EVDO_B = 12,
RADIO_TECH_EHRPD = 13,
RADIO_TECH_LTE = 14,
RADIO_TECH_HSPAP = 15,
RADIO_TECH_GSM = 16,
RADIO_TECH_TD_SCDMA = 17,
RADIO_TECH_IWLAN = 18
};
/* See RIL_REQUEST_LAST_CALL_FAIL_CAUSE */
#define CALL_FAIL_UNOBTAINABLE_NUMBER 1
#define CALL_FAIL_NORMAL 16
#define CALL_FAIL_BUSY 17
#define CALL_FAIL_CONGESTION 34
#define CALL_FAIL_ACM_LIMIT_EXCEEDED 68
#define CALL_FAIL_CALL_BARRED 240
#define CALL_FAIL_FDN_BLOCKED 241
#define CALL_FAIL_IMSI_UNKNOWN_IN_VLR 242
#define CALL_FAIL_IMEI_NOT_ACCEPTED 243
#define CALL_FAIL_DIAL_MODIFIED_TO_USSD 244
#define CALL_FAIL_DIAL_MODIFIED_TO_SS 245
#define CALL_FAIL_DIAL_MODIFIED_TO_DIAL 246
#define CALL_FAIL_CDMA_LOCKED_UNTIL_POWER_CYCLE 1000
#define CALL_FAIL_CDMA_DROP 1001
#define CALL_FAIL_CDMA_INTERCEPT 1002
#define CALL_FAIL_CDMA_REORDER 1003
#define CALL_FAIL_CDMA_SO_REJECT 1004
#define CALL_FAIL_CDMA_RETRY_ORDER 1005
#define CALL_FAIL_CDMA_ACCESS_FAILURE 1006
#define CALL_FAIL_CDMA_PREEMPTED 1007
#define CALL_FAIL_CDMA_NOT_EMERGENCY 1008
#define CALL_FAIL_CDMA_ACCESS_BLOCKED 1009
#define CALL_FAIL_ERROR_UNSPECIFIED 0xffff
/* Not defined in ril.h but valid 3GPP specific cause values
* for call control. See 3GPP TS 24.008 Annex H. */
#define CALL_FAIL_NO_ROUTE_TO_DESTINATION 3
#define CALL_FAIL_CHANNEL_UNACCEPTABLE 6
#define CALL_FAIL_OPERATOR_DETERMINED_BARRING 8
#define CALL_FAIL_NO_USER_RESPONDING 18
#define CALL_FAIL_USER_ALERTING_NO_ANSWER 19
#define CALL_FAIL_CALL_REJECTED 21
#define CALL_FAIL_NUMBER_CHANGED 22
#define CALL_FAIL_ANONYMOUS_CALL_REJECTION 24
#define CALL_FAIL_PRE_EMPTION 25
#define CALL_FAIL_DESTINATION_OUT_OF_ORDER 27
#define CALL_FAIL_INCOMPLETE_NUMBER 28
#define CALL_FAIL_FACILITY_REJECTED 29
#define CALL_FAIL_NORMAL_UNSPECIFIED 31
/* see RIL_REQUEST_DEACTIVATE_DATA_CALL parameter */
#define RIL_DEACTIVATE_DATA_CALL_NO_REASON 0
#define RIL_DEACTIVATE_DATA_CALL_RADIO_SHUTDOWN 1
/* See RIL_REQUEST_SETUP_DATA_CALL */
#define RIL_DATA_PROFILE_DEFAULT 0
#define RIL_DATA_PROFILE_TETHERED 1
#define RIL_DATA_PROFILE_IMS 2
#define RIL_DATA_PROFILE_FOTA 3 /* FOTA = Firmware Over the Air */
#define RIL_DATA_PROFILE_CBS 4
#define RIL_DATA_PROFILE_OEM_BASE 1000 /* Start of OEM-specific profiles */
#define RIL_AUTH_NONE 0
#define RIL_AUTH_PAP 1
#define RIL_AUTH_CHAP 2
#define RIL_AUTH_BOTH 3
#define RIL_CARD_MAX_APPS 8
/* SIM card states */
enum ril_card_state {
RIL_CARDSTATE_UNKNOWN = -1,
RIL_CARDSTATE_ABSENT = 0,
RIL_CARDSTATE_PRESENT = 1,
RIL_CARDSTATE_ERROR = 2
};
/* SIM personalization substates */
enum ril_perso_substate {
RIL_PERSOSUBSTATE_UNKNOWN = 0,
RIL_PERSOSUBSTATE_IN_PROGRESS = 1,
RIL_PERSOSUBSTATE_READY = 2,
RIL_PERSOSUBSTATE_SIM_NETWORK = 3,
RIL_PERSOSUBSTATE_SIM_NETWORK_SUBSET = 4,
RIL_PERSOSUBSTATE_SIM_CORPORATE = 5,
RIL_PERSOSUBSTATE_SIM_SERVICE_PROVIDER = 6,
RIL_PERSOSUBSTATE_SIM_SIM = 7,
RIL_PERSOSUBSTATE_SIM_NETWORK_PUK = 8,
RIL_PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK = 9,
RIL_PERSOSUBSTATE_SIM_CORPORATE_PUK = 10,
RIL_PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK = 11,
RIL_PERSOSUBSTATE_SIM_SIM_PUK = 12,
RIL_PERSOSUBSTATE_RUIM_NETWORK1 = 13,
RIL_PERSOSUBSTATE_RUIM_NETWORK2 = 14,
RIL_PERSOSUBSTATE_RUIM_HRPD = 15,
RIL_PERSOSUBSTATE_RUIM_CORPORATE = 16,
RIL_PERSOSUBSTATE_RUIM_SERVICE_PROVIDER = 17,
RIL_PERSOSUBSTATE_RUIM_RUIM = 18,
RIL_PERSOSUBSTATE_RUIM_NETWORK1_PUK = 19,
RIL_PERSOSUBSTATE_RUIM_NETWORK2_PUK = 20,
RIL_PERSOSUBSTATE_RUIM_HRPD_PUK = 21,
RIL_PERSOSUBSTATE_RUIM_CORPORATE_PUK = 22,
RIL_PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK = 23,
RIL_PERSOSUBSTATE_RUIM_RUIM_PUK = 24
};
/* SIM - App states */
enum ril_app_state {
RIL_APPSTATE_ILLEGAL = -1,
RIL_APPSTATE_UNKNOWN = 0,
RIL_APPSTATE_DETECTED = 1,
RIL_APPSTATE_PIN = 2,
RIL_APPSTATE_PUK = 3,
RIL_APPSTATE_SUBSCRIPTION_PERSO = 4,
RIL_APPSTATE_READY = 5
};
/* SIM - PIN states */
enum ril_pin_state {
RIL_PINSTATE_UNKNOWN = 0,
RIL_PINSTATE_ENABLED_NOT_VERIFIED = 1,
RIL_PINSTATE_ENABLED_VERIFIED = 2,
RIL_PINSTATE_DISABLED = 3,
RIL_PINSTATE_ENABLED_BLOCKED = 4,
RIL_PINSTATE_ENABLED_PERM_BLOCKED = 5
};
/* SIM - App types */
enum ril_app_type {
RIL_APPTYPE_UNKNOWN = 0,
RIL_APPTYPE_SIM = 1,
RIL_APPTYPE_USIM = 2,
RIL_APPTYPE_RUIM = 3,
RIL_APPTYPE_CSIM = 4,
RIL_APPTYPE_ISIM = 5
};
/* RIL Request Messages */
#define RIL_REQUEST_GET_SIM_STATUS 1
#define RIL_REQUEST_ENTER_SIM_PIN 2
#define RIL_REQUEST_ENTER_SIM_PUK 3
#define RIL_REQUEST_ENTER_SIM_PIN2 4
#define RIL_REQUEST_ENTER_SIM_PUK2 5
#define RIL_REQUEST_CHANGE_SIM_PIN 6
#define RIL_REQUEST_CHANGE_SIM_PIN2 7
#define RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION 8
#define RIL_REQUEST_GET_CURRENT_CALLS 9
#define RIL_REQUEST_DIAL 10
#define RIL_REQUEST_GET_IMSI 11
#define RIL_REQUEST_HANGUP 12
#define RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND 13
#define RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND 14
#define RIL_REQUEST_SWITCH_HOLDING_AND_ACTIVE 15
#define RIL_REQUEST_CONFERENCE 16
#define RIL_REQUEST_UDUB 17
#define RIL_REQUEST_LAST_CALL_FAIL_CAUSE 18
#define RIL_REQUEST_SIGNAL_STRENGTH 19
#define RIL_REQUEST_VOICE_REGISTRATION_STATE 20
#define RIL_REQUEST_DATA_REGISTRATION_STATE 21
#define RIL_REQUEST_OPERATOR 22
#define RIL_REQUEST_RADIO_POWER 23
#define RIL_REQUEST_DTMF 24
#define RIL_REQUEST_SEND_SMS 25
#define RIL_REQUEST_SEND_SMS_EXPECT_MORE 26
#define RIL_REQUEST_SETUP_DATA_CALL 27
#define RIL_REQUEST_SIM_IO 28
#define RIL_REQUEST_SEND_USSD 29
#define RIL_REQUEST_CANCEL_USSD 30
#define RIL_REQUEST_GET_CLIR 31
#define RIL_REQUEST_SET_CLIR 32
#define RIL_REQUEST_QUERY_CALL_FORWARD_STATUS 33
#define RIL_REQUEST_SET_CALL_FORWARD 34
#define RIL_REQUEST_QUERY_CALL_WAITING 35
#define RIL_REQUEST_SET_CALL_WAITING 36
#define RIL_REQUEST_SMS_ACKNOWLEDGE 37
#define RIL_REQUEST_GET_IMEI 38
#define RIL_REQUEST_GET_IMEISV 39
#define RIL_REQUEST_ANSWER 40
#define RIL_REQUEST_DEACTIVATE_DATA_CALL 41
#define RIL_REQUEST_QUERY_FACILITY_LOCK 42
#define RIL_REQUEST_SET_FACILITY_LOCK 43
#define RIL_REQUEST_CHANGE_BARRING_PASSWORD 44
#define RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE 45
#define RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC 46
#define RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL 47
#define RIL_REQUEST_QUERY_AVAILABLE_NETWORKS 48
#define RIL_REQUEST_DTMF_START 49
#define RIL_REQUEST_DTMF_STOP 50
#define RIL_REQUEST_BASEBAND_VERSION 51
#define RIL_REQUEST_SEPARATE_CONNECTION 52
#define RIL_REQUEST_SET_MUTE 53
#define RIL_REQUEST_GET_MUTE 54
#define RIL_REQUEST_QUERY_CLIP 55
#define RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE 56
#define RIL_REQUEST_DATA_CALL_LIST 57
#define RIL_REQUEST_RESET_RADIO 58
#define RIL_REQUEST_OEM_HOOK_RAW 59
#define RIL_REQUEST_OEM_HOOK_STRINGS 60
#define RIL_REQUEST_SCREEN_STATE 61
#define RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION 62
#define RIL_REQUEST_WRITE_SMS_TO_SIM 63
#define RIL_REQUEST_DELETE_SMS_ON_SIM 64
#define RIL_REQUEST_SET_BAND_MODE 65
#define RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE 66
#define RIL_REQUEST_STK_GET_PROFILE 67
#define RIL_REQUEST_STK_SET_PROFILE 68
#define RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND 69
#define RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE 70
#define RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM 71
#define RIL_REQUEST_EXPLICIT_CALL_TRANSFER 72
#define RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE 73
#define RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE 74
#define RIL_REQUEST_GET_NEIGHBORING_CELL_IDS 75
#define RIL_REQUEST_SET_LOCATION_UPDATES 76
#define RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE 77
#define RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE 78
#define RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE 79
#define RIL_REQUEST_SET_TTY_MODE 80
#define RIL_REQUEST_QUERY_TTY_MODE 81
#define RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE 82
#define RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE 83
#define RIL_REQUEST_CDMA_FLASH 84
#define RIL_REQUEST_CDMA_BURST_DTMF 85
#define RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY 86
#define RIL_REQUEST_CDMA_SEND_SMS 87
#define RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE 88
#define RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG 89
#define RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG 90
#define RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION 91
#define RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG 92
#define RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG 93
#define RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION 94
#define RIL_REQUEST_CDMA_SUBSCRIPTION 95
#define RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM 96
#define RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM 97
#define RIL_REQUEST_DEVICE_IDENTITY 98
#define RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE 99
#define RIL_REQUEST_GET_SMSC_ADDRESS 100
#define RIL_REQUEST_SET_SMSC_ADDRESS 101
#define RIL_REQUEST_REPORT_SMS_MEMORY_STATUS 102
#define RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING 103
#define RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE 104
#define RIL_REQUEST_ISIM_AUTHENTICATION 105
#define RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU 106
#define RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS 107
#define RIL_REQUEST_VOICE_RADIO_TECH 108
#define RIL_REQUEST_GET_CELL_INFO_LIST 109
#define RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE 110
#define RIL_REQUEST_SET_INITIAL_ATTACH_APN 111
#define RIL_REQUEST_IMS_REGISTRATION_STATE 112
#define RIL_REQUEST_IMS_SEND_SMS 113
#define RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC 114
#define RIL_REQUEST_SIM_OPEN_CHANNEL 115
#define RIL_REQUEST_SIM_CLOSE_CHANNEL 116
#define RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL 117
#define RIL_REQUEST_NV_READ_ITEM 118
#define RIL_REQUEST_NV_WRITE_ITEM 119
#define RIL_REQUEST_NV_WRITE_CDMA_PRL 120
#define RIL_REQUEST_NV_RESET_CONFIG 121
/* SET_UICC_SUBSCRIPTION was 115 in v9 and 122 in v10 and later */
#define RIL_REQUEST_V9_SET_UICC_SUBSCRIPTION 115
#define RIL_REQUEST_SET_UICC_SUBSCRIPTION 122
#define RIL_REQUEST_ALLOW_DATA 123
#define RIL_REQUEST_GET_HARDWARE_CONFIG 124
#define RIL_REQUEST_SIM_AUTHENTICATION 125
#define RIL_REQUEST_GET_DC_RT_INFO 126
#define RIL_REQUEST_SET_DC_RT_INFO_RATE 127
#define RIL_REQUEST_SET_DATA_PROFILE 128
#define RIL_REQUEST_SHUTDOWN 129
#define RIL_REQUEST_GET_RADIO_CAPABILITY 130
#define RIL_REQUEST_SET_RADIO_CAPABILITY 131
/* RIL Unsolicited Messages */
#define RIL_UNSOL_RESPONSE_BASE 1000
#define RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED 1000
#define RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED 1001
#define RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED 1002
#define RIL_UNSOL_RESPONSE_NEW_SMS 1003
#define RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT 1004
#define RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM 1005
#define RIL_UNSOL_ON_USSD 1006
#define RIL_UNSOL_ON_USSD_REQUEST 1007
#define RIL_UNSOL_NITZ_TIME_RECEIVED 1008
#define RIL_UNSOL_SIGNAL_STRENGTH 1009
#define RIL_UNSOL_DATA_CALL_LIST_CHANGED 1010
#define RIL_UNSOL_SUPP_SVC_NOTIFICATION 1011
#define RIL_UNSOL_STK_SESSION_END 1012
#define RIL_UNSOL_STK_PROACTIVE_COMMAND 1013
#define RIL_UNSOL_STK_EVENT_NOTIFY 1014
#define RIL_UNSOL_STK_CALL_SETUP 1015
#define RIL_UNSOL_SIM_SMS_STORAGE_FULL 1016
#define RIL_UNSOL_SIM_REFRESH 1017
#define RIL_UNSOL_CALL_RING 1018
#define RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED 1019
#define RIL_UNSOL_RESPONSE_CDMA_NEW_SMS 1020
#define RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS 1021
#define RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL 1022
#define RIL_UNSOL_RESTRICTED_STATE_CHANGED 1023
#define RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE 1024
#define RIL_UNSOL_CDMA_CALL_WAITING 1025
#define RIL_UNSOL_CDMA_OTA_PROVISION_STATUS 1026
#define RIL_UNSOL_CDMA_INFO_REC 1027
#define RIL_UNSOL_OEM_HOOK_RAW 1028
#define RIL_UNSOL_RINGBACK_TONE 1029
#define RIL_UNSOL_RESEND_INCALL_MUTE 1030
#define RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED 1031
#define RIL_UNSOL_CDMA_PRL_CHANGED 1032
#define RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE 1033
#define RIL_UNSOL_RIL_CONNECTED 1034
#define RIL_UNSOL_VOICE_RADIO_TECH_CHANGED 1035
#define RIL_UNSOL_CELL_INFO_LIST 1036
#define RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED 1037
#define RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED 1038
#define RIL_UNSOL_SRVCC_STATE_NOTIFY 1039
#define RIL_UNSOL_HARDWARE_CONFIG_CHANGED 1040
#define RIL_UNSOL_DC_RT_INFO_CHANGED 1041
#define RIL_UNSOL_RADIO_CAPABILITY 1042
#define RIL_UNSOL_ON_SS 1043
#define RIL_UNSOL_STK_CC_ALPHA_NOTIFY 1044
/* Suplementary services Service class*/
#define SERVICE_CLASS_NONE 0
/* RIL_FACILITY_LOCK parameters */
#define RIL_FACILITY_UNLOCK "0"
#define RIL_FACILITY_LOCK "1"
#endif /*__RIL_CONSTANTS_H */
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,313 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_data.h"
#include "ril_log.h"
#include <grilio_queue.h>
#include <grilio_request.h>
typedef GObjectClass RilDataClass;
typedef struct ril_data RilData;
struct ril_data_manager {
gint ref_count;
struct ril_data *selected;
guint pending_id;
GSList *data_list;
};
struct ril_data {
GObject object;
GRilIoQueue *q;
const char *log_prefix;
char *custom_log_prefix;
struct ril_data_manager *dm;
gboolean allowed;
};
enum ril_data_signal {
SIGNAL_ALLOW_CHANGED,
SIGNAL_COUNT
};
#define SIGNAL_ALLOW_CHANGED_NAME "ril-data-allow-changed"
static guint ril_data_signals[SIGNAL_COUNT] = { 0 };
G_DEFINE_TYPE(RilData, ril_data, G_TYPE_OBJECT)
#define RIL_DATA_TYPE (ril_data_get_type())
#define RIL_DATA(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, RIL_DATA_TYPE,RilData))
static void ril_data_manager_check(struct ril_data_manager *self);
/*==========================================================================*
* ril_data
*==========================================================================*/
gulong ril_data_add_allow_changed_handler(struct ril_data *self,
ril_data_cb_t cb, void *arg)
{
return (G_LIKELY(self) && G_LIKELY(cb)) ? g_signal_connect(self,
SIGNAL_ALLOW_CHANGED_NAME, G_CALLBACK(cb), arg) : 0;
}
void ril_data_remove_handler(struct ril_data *self, gulong id)
{
if (G_LIKELY(self) && G_LIKELY(id)) {
g_signal_handler_disconnect(self, id);
}
}
struct ril_data *ril_data_new(struct ril_data_manager *dm, GRilIoChannel *io)
{
GASSERT(dm);
if (G_LIKELY(dm)) {
struct ril_data *self = g_object_new(RIL_DATA_TYPE, NULL);
self->q = grilio_queue_new(io);
self->dm = ril_data_manager_ref(dm);
dm->data_list = g_slist_append(dm->data_list, self);
return self;
}
return NULL;
}
struct ril_data *ril_data_ref(struct ril_data *self)
{
if (G_LIKELY(self)) {
g_object_ref(RIL_DATA(self));
return self;
} else {
return NULL;
}
}
void ril_data_unref(struct ril_data *self)
{
if (G_LIKELY(self)) {
g_object_unref(RIL_DATA(self));
}
}
G_INLINE_FUNC void ril_data_signal(struct ril_data *self)
{
g_signal_emit(self, ril_data_signals[SIGNAL_ALLOW_CHANGED], 0);
}
void ril_data_allow(struct ril_data *self, gboolean allow)
{
if (G_LIKELY(self)) {
struct ril_data_manager *dm = self->dm;
DBG("%s%s", self->log_prefix, allow ? "yes" : "no");
if (allow) {
if (!self->allowed) {
self->allowed = TRUE;
ril_data_manager_check(dm);
}
} else {
if (self->allowed) {
self->allowed = FALSE;
if (dm->selected == self) {
ril_data_manager_check(dm);
}
}
}
}
}
gboolean ril_data_allowed(struct ril_data *self)
{
return G_LIKELY(self) && self->allowed && self->dm->selected == self;
}
void ril_data_set_name(struct ril_data *self, const char *name)
{
if (G_LIKELY(self)) {
g_free(self->custom_log_prefix);
if (name) {
self->custom_log_prefix = g_strconcat(name, " ", NULL);
self->log_prefix = self->custom_log_prefix;
} else {
self->custom_log_prefix = NULL;
self->log_prefix = "";
}
}
}
static void ril_data_init(struct ril_data *self)
{
self->log_prefix = "";
}
static void ril_data_dispose(GObject *object)
{
struct ril_data *self = RIL_DATA(object);
struct ril_data_manager *dm = self->dm;
dm->data_list = g_slist_remove(dm->data_list, self);
grilio_queue_cancel_all(self->q, FALSE);
ril_data_manager_check(dm);
G_OBJECT_CLASS(ril_data_parent_class)->dispose(object);
}
static void ril_data_finalize(GObject *object)
{
struct ril_data *self = RIL_DATA(object);
g_free(self->custom_log_prefix);
grilio_queue_unref(self->q);
ril_data_manager_unref(self->dm);
G_OBJECT_CLASS(ril_data_parent_class)->finalize(object);
}
static void ril_data_class_init(RilDataClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->dispose = ril_data_dispose;
object_class->finalize = ril_data_finalize;
ril_data_signals[SIGNAL_ALLOW_CHANGED] =
g_signal_new(SIGNAL_ALLOW_CHANGED_NAME,
G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL, G_TYPE_NONE, 0);
}
/*==========================================================================*
* ril_data_manager
*==========================================================================*/
struct ril_data_manager *ril_data_manager_new()
{
struct ril_data_manager *self = g_new0(struct ril_data_manager, 1);
self->ref_count = 1;
return self;
}
struct ril_data_manager *ril_data_manager_ref(struct ril_data_manager *self)
{
if (self) {
GASSERT(self->ref_count > 0);
g_atomic_int_inc(&self->ref_count);
}
return self;
}
void ril_data_manager_unref(struct ril_data_manager *self)
{
if (self) {
GASSERT(self->ref_count > 0);
if (g_atomic_int_dec_and_test(&self->ref_count)) {
GASSERT(!self->selected);
g_free(self);
}
}
}
static void ril_data_manager_allow_data_cb(GRilIoChannel *io, int ril_status,
const void *data, guint len, void *user_data)
{
struct ril_data_manager *self = user_data;
GASSERT(self->selected);
GASSERT(self->pending_id);
self->pending_id = 0;
if (ril_status == RIL_E_SUCCESS) {
DBG("%sselected", self->selected->log_prefix);
} else {
DBG("%srequest failed", self->selected->log_prefix);
}
}
static struct ril_data *ril_data_manager_pick(struct ril_data_manager *self)
{
GSList *list = self->data_list;
while (list) {
struct ril_data *data = list->data;
if (data->allowed) {
return data;
}
list = list->next;
}
return NULL;
}
static GRilIoRequest *ril_data_allow_req(gboolean allow)
{
GRilIoRequest *req = grilio_request_sized_new(8);
grilio_request_append_int32(req, 1);
grilio_request_append_int32(req, allow != FALSE);
return req;
}
static void ril_data_manager_check(struct ril_data_manager *self)
{
struct ril_data *data = ril_data_manager_pick(self);
if (data) {
if (self->selected != data) {
GRilIoRequest *req = ril_data_allow_req(TRUE);
struct ril_data *prev = self->selected;
/* Cancel pending request, if any */
GASSERT(prev || !self->pending_id);
if (prev) {
grilio_queue_cancel_request(prev->q,
self->pending_id, FALSE);
}
/*
* Submit the RIL request. Note that with
* some older RILs this request will never
* get completed (no reply from rild will
* ever come).
*/
grilio_request_set_retry(req, RIL_RETRY_MS, -1);
self->pending_id =
grilio_queue_send_request_full(data->q, req,
RIL_REQUEST_ALLOW_DATA,
ril_data_manager_allow_data_cb,
NULL, self);
grilio_request_unref(req);
DBG("%srequested", data->log_prefix);
self->selected = data;
if (prev) {
ril_data_signal(prev);
}
ril_data_signal(data);
}
} else {
if (self->selected) {
struct ril_data *prev = self->selected;
if (self->pending_id) {
grilio_queue_cancel_request(prev->q,
self->pending_id, FALSE);
self->pending_id = 0;
}
self->selected = NULL;
ril_data_signal(prev);
}
}
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,46 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef RIL_DATA_H
#define RIL_DATA_H
#include "ril_types.h"
struct ril_data_manager;
struct ril_data_manager *ril_data_manager_new(void);
struct ril_data_manager *ril_data_manager_ref(struct ril_data_manager *dm);
void ril_data_manager_unref(struct ril_data_manager *dm);
struct ril_data *ril_data_new(struct ril_data_manager *dm, GRilIoChannel *io);
struct ril_data *ril_data_ref(struct ril_data *data);
void ril_data_unref(struct ril_data *data);
void ril_data_set_name(struct ril_data *data, const char *name);
void ril_data_allow(struct ril_data *data, gboolean allow);
gboolean ril_data_allowed(struct ril_data *data);
typedef void (*ril_data_cb_t)(struct ril_data *data, void *arg);
gulong ril_data_add_allow_changed_handler(struct ril_data *data,
ril_data_cb_t cb, void *arg);
void ril_data_remove_handler(struct ril_data *data, gulong id);
#endif /* RIL_DATA_H */
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,193 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_util.h"
#include "ril_log.h"
/*
* TODO: No public RIL api to query manufacturer or model.
* Check where to get, could /system/build.prop be updated to have good values?
*/
struct ril_devinfo {
struct ofono_devinfo *info;
GRilIoQueue *q;
guint register_id;
guint imei_id;
char *imei;
};
struct ril_devinfo_cbd {
struct ril_devinfo *di;
ofono_devinfo_query_cb_t cb;
gpointer data;
};
#define ril_devinfo_cbd_free g_free
static inline struct ril_devinfo *ril_devinfo_get_data(
struct ofono_devinfo *info)
{
return ofono_devinfo_get_data(info);
}
struct ril_devinfo_cbd *ril_devinfo_cbd_new(struct ril_devinfo *di,
ofono_devinfo_query_cb_t cb, void *data)
{
struct ril_devinfo_cbd *cbd = g_new0(struct ril_devinfo_cbd, 1);
cbd->di = di;
cbd->cb = cb;
cbd->data = data;
return cbd;
}
static void ril_devinfo_query_unsupported(struct ofono_devinfo *info,
ofono_devinfo_query_cb_t cb, void *data)
{
struct ofono_error error;
cb(ril_error_failure(&error), "", data);
}
static void ril_devinfo_query_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_devinfo_cbd *cbd = user_data;
if (status == RIL_E_SUCCESS) {
char *res;
GRilIoParser rilp;
grilio_parser_init(&rilp, data, len);
res = grilio_parser_get_utf8(&rilp);
DBG("%s", res);
cbd->cb(ril_error_ok(&error), res ? res : "", cbd->data);
g_free(res);
} else {
cbd->cb(ril_error_failure(&error), NULL, cbd->data);
}
}
static void ril_devinfo_query_revision(struct ofono_devinfo *info,
ofono_devinfo_query_cb_t cb, void *data)
{
struct ril_devinfo *di = ril_devinfo_get_data(info);
DBG("");
grilio_queue_send_request_full(di->q, NULL, RIL_REQUEST_BASEBAND_VERSION,
ril_devinfo_query_cb, ril_devinfo_cbd_free,
ril_devinfo_cbd_new(di, cb, data));
}
static gboolean ril_devinfo_query_serial_cb(void *user_data)
{
struct ril_devinfo_cbd *cbd = user_data;
struct ril_devinfo *di = cbd->di;
struct ofono_error error;
GASSERT(di->imei_id);
di->imei_id = 0;
cbd->cb(ril_error_ok(&error), di->imei, cbd->data);
return FALSE;
}
static void ril_devinfo_query_serial(struct ofono_devinfo *info,
ofono_devinfo_query_cb_t cb,
void *data)
{
struct ril_devinfo *di = ril_devinfo_get_data(info);
GASSERT(!di->imei_id);
if (di->imei_id) {
g_source_remove(di->imei_id);
di->imei_id = 0;
}
DBG("%s", di->imei);
di->imei_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
ril_devinfo_query_serial_cb,
ril_devinfo_cbd_new(di, cb, data),
ril_devinfo_cbd_free);
}
static gboolean ril_devinfo_register(gpointer user_data)
{
struct ril_devinfo *di = user_data;
DBG("");
di->register_id = 0;
ofono_devinfo_register(di->info);
/* This makes the timeout a single-shot */
return FALSE;
}
static int ril_devinfo_probe(struct ofono_devinfo *info, unsigned int vendor,
void *data)
{
struct ril_modem *modem = data;
struct ril_devinfo *di = g_new0(struct ril_devinfo, 1);
DBG("%s %s %p", ril_modem_get_path(modem), modem->imei, di);
GASSERT(modem->imei);
di->q = grilio_queue_new(ril_modem_io(modem));
di->info = info;
di->imei = g_strdup(modem->imei);
di->register_id = g_idle_add(ril_devinfo_register, di);
ofono_devinfo_set_data(info, di);
return 0;
}
static void ril_devinfo_remove(struct ofono_devinfo *info)
{
struct ril_devinfo *di = ril_devinfo_get_data(info);
DBG("%p", di);
ofono_devinfo_set_data(info, NULL);
if (di->register_id > 0) {
g_source_remove(di->register_id);
}
if (di->imei_id > 0) {
g_source_remove(di->imei_id);
}
grilio_queue_cancel_all(di->q, FALSE);
grilio_queue_unref(di->q);
g_free(di->imei);
g_free(di);
}
const struct ofono_devinfo_driver ril_devinfo_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_devinfo_probe,
.remove = ril_devinfo_remove,
.query_manufacturer = ril_devinfo_query_unsupported,
.query_model = ril_devinfo_query_unsupported,
.query_revision = ril_devinfo_query_revision,
.query_serial = ril_devinfo_query_serial
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,283 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_network.h"
#include "ril_data.h"
#include "ril_util.h"
#include "ril_log.h"
#include "common.h"
/*
* This module is the ofono_gprs_driver implementation for rilmodem.
*
* Notes:
*
* 1. ofono_gprs_suspend/resume() are not used by this module, as
* the concept of suspended GPRS is not exposed by RILD.
*
* 2. ofono_gprs_bearer_notify() is never called as RILD does not
* expose an unsolicited event equivalent to +CPSB ( see 27.007
* 7.29 ), and the tech values returned by REQUEST_DATA/VOICE
* _REGISTRATION requests do not match the values defined for
* <AcT> in the +CPSB definition. Note, the values returned by
* the *REGISTRATION commands are aligned with those defined by
* +CREG ( see 27.003 7.2 ).
*/
struct ril_gprs {
struct ofono_gprs *gprs;
struct ril_modem *md;
struct ril_data *data;
struct ril_network *network;
GRilIoChannel *io;
GRilIoQueue *q;
gboolean attached;
int max_cids;
enum network_registration_status registration_status;
guint register_id;
gulong network_event_id;
gulong data_event_id;
guint set_attached_id;
};
struct ril_gprs_cbd {
struct ril_gprs *gd;
ofono_gprs_cb_t cb;
gpointer data;
};
#define ril_gprs_cbd_free g_free
static struct ril_gprs *ril_gprs_get_data(struct ofono_gprs *ofono)
{
return ofono ? ofono_gprs_get_data(ofono) : NULL;
}
static struct ril_gprs_cbd *ril_gprs_cbd_new(struct ril_gprs *gd,
ofono_gprs_cb_t cb, void *data)
{
struct ril_gprs_cbd *cbd = g_new0(struct ril_gprs_cbd, 1);
cbd->gd = gd;
cbd->cb = cb;
cbd->data = data;
return cbd;
}
static enum network_registration_status ril_gprs_fix_registration_status(
struct ril_gprs *gd, enum network_registration_status status)
{
if (!ril_data_allowed(gd->data)) {
return NETWORK_REGISTRATION_STATUS_NOT_REGISTERED;
} else {
/* TODO: need a way to make sure that SPDI information has
* already been read from the SIM (i.e. sim_spdi_read_cb in
* network.c has been called) */
struct ofono_netreg *netreg = ril_modem_ofono_netreg(gd->md);
return ril_netreg_check_if_really_roaming(netreg, status);
}
}
static void ril_gprs_data_update_registration_state(struct ril_gprs *gd)
{
const enum network_registration_status status =
ril_gprs_fix_registration_status(gd, gd->network->data.status);
if (gd->registration_status != status) {
ofono_info("data reg changed %d -> %d (%s), attached %d",
gd->registration_status, status,
registration_status_to_string(status),
gd->attached);
gd->registration_status = status;
ofono_gprs_status_notify(gd->gprs, gd->registration_status);
}
}
static void ril_gprs_check_data_allowed(struct ril_gprs *gd)
{
DBG("%s %d %d", ril_modem_get_path(gd->md), ril_data_allowed(gd->data),
gd->attached);
if (!ril_data_allowed(gd->data) && gd->attached) {
gd->attached = FALSE;
if (gd->gprs) {
ofono_gprs_detached_notify(gd->gprs);
}
}
ril_gprs_data_update_registration_state(gd);
}
static gboolean ril_gprs_set_attached_cb(gpointer user_data)
{
struct ofono_error error;
struct ril_gprs_cbd *cbd = user_data;
struct ril_gprs *gd = cbd->gd;
GASSERT(gd->set_attached_id);
gd->set_attached_id = 0;
ril_gprs_check_data_allowed(gd);
cbd->cb(ril_error_ok(&error), cbd->data);
return FALSE;
}
static void ril_gprs_set_attached(struct ofono_gprs *gprs, int attached,
ofono_gprs_cb_t cb, void *data)
{
struct ril_gprs *gd = ril_gprs_get_data(gprs);
if (ril_data_allowed(gd->data) || !attached) {
DBG("%s attached: %d", ril_modem_get_path(gd->md), attached);
if (gd->set_attached_id) {
g_source_remove(gd->set_attached_id);
}
gd->attached = attached;
gd->set_attached_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
ril_gprs_set_attached_cb,
ril_gprs_cbd_new(gd, cb, data),
ril_gprs_cbd_free);
} else {
struct ofono_error error;
DBG("%s not allowed to attach", ril_modem_get_path(gd->md));
cb(ril_error_failure(&error), data);
}
}
static void ril_gprs_allow_data_changed(struct ril_data *data, void *user_data)
{
struct ril_gprs *gd = user_data;
GASSERT(gd->data == data);
DBG("%s %d", ril_modem_get_path(gd->md), ril_data_allowed(data));
if (!gd->set_attached_id) {
ril_gprs_check_data_allowed(gd);
}
}
static void ril_gprs_data_registration_state_changed(struct ril_network *net,
void *user_data)
{
struct ril_gprs *gd = user_data;
const struct ril_registration_state *data = &net->data;
GASSERT(gd->network == net);
if (data->max_calls > gd->max_cids) {
DBG("Setting max cids to %d", data->max_calls);
gd->max_cids = data->max_calls;
ofono_gprs_set_cid_range(gd->gprs, 1, gd->max_cids);
}
ril_gprs_data_update_registration_state(gd);
}
static void ril_gprs_registration_status(struct ofono_gprs *gprs,
ofono_gprs_status_cb_t cb, void *data)
{
struct ril_gprs *gd = ril_gprs_get_data(gprs);
struct ofono_error error;
const enum network_registration_status status = gd->attached ?
gd->registration_status :
NETWORK_REGISTRATION_STATUS_NOT_REGISTERED;
DBG("%d (%s)", status, registration_status_to_string(status));
cb(ril_error_ok(&error), status, data);
}
static gboolean ril_gprs_register(gpointer user_data)
{
struct ril_gprs *gd = user_data;
gd->register_id = 0;
gd->network_event_id = ril_network_add_data_state_changed_handler(
gd->network, ril_gprs_data_registration_state_changed, gd);
gd->data_event_id = ril_data_add_allow_changed_handler(gd->data,
ril_gprs_allow_data_changed, gd);
gd->registration_status = ril_gprs_fix_registration_status(gd,
gd->network->data.status);
gd->max_cids = gd->network->data.max_calls;
if (gd->max_cids > 0) {
DBG("Setting max cids to %d", gd->max_cids);
ofono_gprs_set_cid_range(gd->gprs, 1, gd->max_cids);
}
ofono_gprs_register(gd->gprs);
return FALSE;
}
static int ril_gprs_probe(struct ofono_gprs *gprs, unsigned int vendor,
void *data)
{
struct ril_modem *modem = data;
struct ril_gprs *gd = g_new0(struct ril_gprs, 1);
DBG("%s", ril_modem_get_path(modem));
gd->md = modem;
gd->io = grilio_channel_ref(ril_modem_io(modem));
gd->q = grilio_queue_new(gd->io);
gd->data = ril_data_ref(modem->data);
gd->network = ril_network_ref(modem->network);
gd->gprs = gprs;
ofono_gprs_set_data(gprs, gd);
/* ofono crashes if we register right away */
gd->register_id = g_idle_add(ril_gprs_register, gd);
return 0;
}
static void ril_gprs_remove(struct ofono_gprs *gprs)
{
struct ril_gprs *gd = ril_gprs_get_data(gprs);
DBG("%s", ril_modem_get_path(gd->md));
ofono_gprs_set_data(gprs, NULL);
if (gd->set_attached_id) {
g_source_remove(gd->set_attached_id);
}
if (gd->register_id) {
g_source_remove(gd->register_id);
}
ril_network_remove_handler(gd->network, gd->network_event_id);
ril_network_unref(gd->network);
ril_data_remove_handler(gd->data, gd->data_event_id);
ril_data_unref(gd->data);
grilio_channel_unref(gd->io);
grilio_queue_cancel_all(gd->q, FALSE);
grilio_queue_unref(gd->q);
g_free(gd);
}
const struct ofono_gprs_driver ril_gprs_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_gprs_probe,
.remove = ril_gprs_remove,
.set_attached = ril_gprs_set_attached,
.attached_status = ril_gprs_registration_status,
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,972 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_network.h"
#include "ril_util.h"
#include "ril_log.h"
#include <gutil_strv.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "common.h"
#define PROTO_IP_STR "IP"
#define PROTO_IPV6_STR "IPV6"
#define PROTO_IPV4V6_STR "IPV4V6"
#define MIN_DATA_CALL_LIST_SIZE 8
#define MIN_DATA_CALL_REPLY_SIZE 36
#define SETUP_DATA_CALL_PARAMS 7
#define DATA_PROFILE_DEFAULT_STR "0"
#define DEACTIVATE_DATA_CALL_PARAMS 2
#define CTX_ID_NONE ((unsigned int)(-1))
enum data_call_state {
DATA_CALL_INACTIVE,
DATA_CALL_LINK_DOWN,
DATA_CALL_ACTIVE,
};
enum ril_gprs_context_state {
STATE_IDLE,
STATE_ACTIVATING,
STATE_DEACTIVATING,
STATE_ACTIVE,
};
struct ril_gprs_context {
struct ofono_gprs_context *gc;
struct ril_modem *modem;
struct ril_network *network;
GRilIoChannel *io;
GRilIoQueue *q;
guint active_ctx_cid;
enum ril_gprs_context_state state;
gulong regid;
struct ril_gprs_context_data_call *active_call;
struct ril_gprs_context_deactivate_req *deactivate_req;
};
struct ril_gprs_context_data_call {
guint status;
gint cid;
guint active;
int retry_time;
int prot;
gint mtu;
gchar *ifname;
gchar **dnses;
gchar **gateways;
gchar **addresses;
};
struct ril_gprs_context_data_call_list {
guint version;
guint num;
GSList *calls;
};
struct ril_gprs_context_cbd {
struct ril_gprs_context *gcd;
ofono_gprs_context_cb_t cb;
gpointer data;
};
struct ril_gprs_context_deactivate_req {
struct ril_gprs_context_cbd cbd;
gint cid;
};
#define ril_gprs_context_cbd_free g_free
#define ril_gprs_context_deactivate_req_free g_free
static inline struct ril_gprs_context *ril_gprs_context_get_data(
struct ofono_gprs_context *gprs)
{
return ofono_gprs_context_get_data(gprs);
}
static struct ril_gprs_context_cbd *ril_gprs_context_cbd_new(
struct ril_gprs_context *gcd, ofono_gprs_context_cb_t cb, void *data)
{
struct ril_gprs_context_cbd *cbd =
g_new0(struct ril_gprs_context_cbd, 1);
cbd->gcd = gcd;
cbd->cb = cb;
cbd->data = data;
return cbd;
}
static struct ril_gprs_context_deactivate_req *
ril_gprs_context_deactivate_req_new(struct ril_gprs_context *gcd,
ofono_gprs_context_cb_t cb, void *data)
{
struct ril_gprs_context_deactivate_req *req =
g_new0(struct ril_gprs_context_deactivate_req, 1);
req->cbd.gcd = gcd;
req->cbd.cb = cb;
req->cbd.data = data;
req->cid = gcd->active_call->cid;
return req;
}
static char *ril_gprs_context_netmask(const char *address)
{
if (address) {
const char *suffix = strchr(address, '/');
if (suffix) {
int nbits = atoi(suffix + 1);
if (nbits > 0 && nbits < 33) {
const char* str;
struct in_addr in;
in.s_addr = htonl((nbits == 32) ? 0xffffffff :
((1 << nbits)-1) << (32-nbits));
str = inet_ntoa(in);
if (str) {
return g_strdup(str);
}
}
}
}
return g_strdup("255.255.255.0");
}
static const char *ril_gprs_ofono_protocol_to_ril(guint protocol)
{
switch (protocol) {
case OFONO_GPRS_PROTO_IPV6:
return PROTO_IPV6_STR;
case OFONO_GPRS_PROTO_IPV4V6:
return PROTO_IPV4V6_STR;
case OFONO_GPRS_PROTO_IP:
return PROTO_IP_STR;
default:
return NULL;
}
}
static int ril_gprs_protocol_to_ofono(gchar *protocol_str)
{
if (protocol_str) {
if (!strcmp(protocol_str, PROTO_IPV6_STR)) {
return OFONO_GPRS_PROTO_IPV6;
} else if (!strcmp(protocol_str, PROTO_IPV4V6_STR)) {
return OFONO_GPRS_PROTO_IPV4V6;
} else if (!strcmp(protocol_str, PROTO_IP_STR)) {
return OFONO_GPRS_PROTO_IP;
}
}
return -1;
}
static void ril_gprs_context_set_ipv4(struct ofono_gprs_context *gc,
char * const *ip_addr)
{
const guint n = gutil_strv_length(ip_addr);
if (n > 0) {
ofono_gprs_context_set_ipv4_address(gc, ip_addr[0], TRUE);
if (n > 1) {
ofono_gprs_context_set_ipv4_netmask(gc, ip_addr[1]);
}
}
}
static void ril_gprs_context_set_ipv6(struct ofono_gprs_context *gc,
char * const *ipv6_addr)
{
const guint n = gutil_strv_length(ipv6_addr);
if (n > 0) {
ofono_gprs_context_set_ipv6_address(gc, ipv6_addr[0]);
if (n > 1) {
const int p = atoi(ipv6_addr[1]);
if (p > 0 && p <= 128) {
ofono_gprs_context_set_ipv6_prefix_length(gc, p);
}
}
}
}
static void ril_gprs_context_data_call_free(
struct ril_gprs_context_data_call *call)
{
if (call) {
g_free(call->ifname);
g_strfreev(call->dnses);
g_strfreev(call->addresses);
g_strfreev(call->gateways);
g_free(call);
}
}
static void ril_gprs_context_set_disconnected(struct ril_gprs_context *gcd)
{
gcd->state = STATE_IDLE;
if (gcd->active_call) {
if (gcd->deactivate_req &&
gcd->deactivate_req->cid == gcd->active_call->cid) {
/* Mark this request as done */
gcd->deactivate_req->cbd.gcd = NULL;
gcd->deactivate_req = NULL;
}
ril_gprs_context_data_call_free(gcd->active_call);
gcd->active_call = NULL;
}
if (gcd->active_ctx_cid != CTX_ID_NONE) {
guint id = gcd->active_ctx_cid;
gcd->active_ctx_cid = CTX_ID_NONE;
ofono_gprs_context_deactivated(gcd->gc, id);
}
}
static void ril_gprs_split_ip_by_protocol(char **ip_array,
char ***split_ip_addr,
char ***split_ipv6_addr)
{
const int n = gutil_strv_length(ip_array);
int i;
*split_ipv6_addr = *split_ip_addr = NULL;
for (i = 0; i < n && (!*split_ipv6_addr || !*split_ip_addr); i++) {
const char *addr = ip_array[i];
switch (ril_address_family(addr)) {
case AF_INET:
if (!*split_ip_addr) {
char *mask = ril_gprs_context_netmask(addr);
*split_ip_addr = g_strsplit(addr, "/", 2);
if (gutil_strv_length(*split_ip_addr) == 2) {
g_free((*split_ip_addr)[1]);
(*split_ip_addr)[1] = mask;
} else {
/* This is rather unlikely to happen */
*split_ip_addr =
gutil_strv_add(*split_ip_addr,
mask);
g_free(mask);
}
}
break;
case AF_INET6:
if (!*split_ipv6_addr) {
*split_ipv6_addr = g_strsplit(addr, "/", 2);
}
}
}
}
static void ril_gprs_split_gw_by_protocol(char **gw_array, char **ip_gw,
char **ipv6_gw)
{
const int n = gutil_strv_length(gw_array);
int i;
*ip_gw = *ipv6_gw = NULL;
for (i = 0; i < n && (!*ipv6_gw || !*ip_gw); i++) {
const char *gw_addr = gw_array[i];
switch (ril_address_family(gw_addr)) {
case AF_INET:
if (!*ip_gw) *ip_gw = g_strdup(gw_addr);
break;
case AF_INET6:
if (!*ipv6_gw) *ipv6_gw = g_strdup(gw_addr);
break;
}
}
}
static void ril_gprs_split_dns_by_protocol(char **dns_array, char ***dns_addr,
char ***dns_ipv6_addr)
{
const int n = gutil_strv_length(dns_array);
int i;
*dns_ipv6_addr = *dns_addr = 0;
for (i = 0; i < n; i++) {
const char *addr = dns_array[i];
switch (ril_address_family(addr)) {
case AF_INET:
*dns_addr = gutil_strv_add(*dns_addr, addr);
break;
case AF_INET6:
*dns_ipv6_addr = gutil_strv_add(*dns_ipv6_addr, addr);
break;
}
}
}
static gint ril_gprs_context_parse_data_call_compare(gconstpointer a,
gconstpointer b)
{
const struct ril_gprs_context_data_call *ca = a;
const struct ril_gprs_context_data_call *cb = b;
if (ca->cid < cb->cid) {
return -1;
} else if (ca->cid > cb->cid) {
return 1;
} else {
return 0;
}
}
static void ril_gprs_context_data_call_free1(gpointer data)
{
ril_gprs_context_data_call_free(data);
}
static void ril_gprs_context_data_call_list_free(
struct ril_gprs_context_data_call_list *list)
{
if (list) {
g_slist_free_full(list->calls, ril_gprs_context_data_call_free1);
g_free(list);
}
}
static struct ril_gprs_context_data_call *ril_gprs_context_data_call_find(
struct ril_gprs_context_data_call_list *list, gint cid)
{
if (list) {
GSList *entry;
for (entry = list->calls; entry; entry = entry->next) {
struct ril_gprs_context_data_call *call = entry->data;
if (call->cid == cid) {
return call;
}
}
}
return NULL;
}
/* Only compares the stuff that's important to us */
static gboolean ril_gprs_context_data_call_equal(
const struct ril_gprs_context_data_call *c1,
const struct ril_gprs_context_data_call *c2)
{
if (!c1 && !c2) {
return TRUE;
} else if (c1 && c2) {
return c1->cid == c2->cid &&
c1->active == c2->active && c1->prot == c2->prot &&
!g_strcmp0(c1->ifname, c2->ifname) &&
gutil_strv_equal(c1->dnses, c2->dnses) &&
gutil_strv_equal(c1->gateways, c2->gateways) &&
gutil_strv_equal(c1->addresses, c2->addresses);
} else {
return FALSE;
}
}
static struct ril_gprs_context_data_call *
ril_gprs_context_parse_data_call(int version, GRilIoParser *rilp)
{
char *prot;
struct ril_gprs_context_data_call *call =
g_new0(struct ril_gprs_context_data_call, 1);
grilio_parser_get_uint32(rilp, &call->status);
grilio_parser_get_int32(rilp, &call->retry_time);
grilio_parser_get_int32(rilp, &call->cid);
grilio_parser_get_uint32(rilp, &call->active);
prot = grilio_parser_get_utf8(rilp);
call->ifname = grilio_parser_get_utf8(rilp);
call->addresses = grilio_parser_split_utf8(rilp, " ");
call->dnses = grilio_parser_split_utf8(rilp, " ");
call->gateways = grilio_parser_split_utf8(rilp, " ");
call->prot = ril_gprs_protocol_to_ofono(prot);
if (call->prot < 0) {
ofono_error("Invalid type(protocol) specified: %s", prot);
}
g_free(prot);
if (version >= 9) {
/* PCSCF */
grilio_parser_skip_string(rilp);
if (version >= 11) {
/* MTU */
grilio_parser_get_int32(rilp, &call->mtu);
}
}
return call;
}
static struct ril_gprs_context_data_call_list *
ril_gprs_context_parse_data_call_list(const void *data, guint len)
{
struct ril_gprs_context_data_call_list *reply =
g_new0(struct ril_gprs_context_data_call_list, 1);
GRilIoParser rilp;
unsigned int i, n;
grilio_parser_init(&rilp, data, len);
grilio_parser_get_uint32(&rilp, &reply->version);
grilio_parser_get_uint32(&rilp, &n);
DBG("version=%d,num=%d", reply->version, n);
for (i = 0; i < n && !grilio_parser_at_end(&rilp); i++) {
struct ril_gprs_context_data_call *call =
ril_gprs_context_parse_data_call(reply->version, &rilp);
DBG("%d [status=%d,retry=%d,cid=%d,"
"active=%d,type=%s,ifname=%s,mtu=%d,"
"address=%s, dns=%s %s,gateways=%s]",
i, call->status, call->retry_time,
call->cid, call->active,
ril_gprs_ofono_protocol_to_ril(call->prot),
call->ifname, call->mtu, call->addresses[0],
call->dnses[0],
(call->dnses[0] && call->dnses[1]) ?
call->dnses[1] : "",
call->gateways[0]);
reply->num++;
reply->calls = g_slist_insert_sorted(reply->calls, call,
ril_gprs_context_parse_data_call_compare);
}
return reply;
}
static void ril_gprs_context_call_list_changed(GRilIoChannel *io, guint event,
const void *data, guint len, void *user_data)
{
struct ril_gprs_context *gcd = user_data;
struct ofono_gprs_context *gc = gcd->gc;
struct ril_gprs_context_data_call *call = NULL;
struct ril_gprs_context_data_call *prev_call;
struct ril_gprs_context_data_call_list *unsol =
ril_gprs_context_parse_data_call_list(data, len);
if (gcd->active_call) {
/* Find our call */
call = ril_gprs_context_data_call_find(unsol,
gcd->active_call->cid);
if (call) {
/* Check if the call have been disconnected */
if (call->active == DATA_CALL_INACTIVE) {
ofono_error("Clearing active context");
ril_gprs_context_set_disconnected(gcd);
call = NULL;
/* Compare it agains the last known state */
} else if (ril_gprs_context_data_call_equal(call,
gcd->active_call)) {
DBG("call %u didn't change", call->cid);
call = NULL;
} else {
/* Steal it from the list */
DBG("call %u changed", call->cid);
unsol->calls = g_slist_remove(unsol->calls,
call);
}
} else {
ofono_error("Clearing active context");
ril_gprs_context_set_disconnected(gcd);
}
}
/* We don't need the rest of the list anymore */
ril_gprs_context_data_call_list_free(unsol);
if (!call) {
/* We are not interested */
return;
}
/* Store the updated call data */
prev_call = gcd->active_call;
gcd->active_call = call;
if (call->status != 0) {
ofono_info("data call status: %d", call->status);
}
if (call->active == DATA_CALL_ACTIVE) {
gboolean signal = FALSE;
if (call->ifname && g_strcmp0(call->ifname, prev_call->ifname)) {
DBG("interface changed");
signal = TRUE;
ofono_gprs_context_set_interface(gc, call->ifname);
}
if (!gutil_strv_equal(call->addresses, prev_call->addresses)) {
char **split_ip_addr = NULL;
char **split_ipv6_addr = NULL;
DBG("address changed");
signal = TRUE;
/* Pick 1 address of each protocol */
ril_gprs_split_ip_by_protocol(call->addresses,
&split_ip_addr, &split_ipv6_addr);
if ((call->prot == OFONO_GPRS_PROTO_IPV4V6 ||
call->prot == OFONO_GPRS_PROTO_IPV6) &&
split_ipv6_addr) {
ril_gprs_context_set_ipv6(gc, split_ipv6_addr);
}
if ((call->prot == OFONO_GPRS_PROTO_IPV4V6 ||
call->prot == OFONO_GPRS_PROTO_IP) &&
split_ip_addr) {
ril_gprs_context_set_ipv4(gc, split_ip_addr);
}
g_strfreev(split_ip_addr);
g_strfreev(split_ipv6_addr);
}
if (!gutil_strv_equal(call->gateways, prev_call->gateways)){
char *ip_gw = NULL;
char *ipv6_gw = NULL;
DBG("gateway changed");
signal = TRUE;
/* Pick 1 gw for each protocol*/
ril_gprs_split_gw_by_protocol(call->gateways,
&ip_gw, &ipv6_gw);
if ((call->prot == OFONO_GPRS_PROTO_IPV4V6 ||
call->prot == OFONO_GPRS_PROTO_IPV6) &&
ipv6_gw) {
ofono_gprs_context_set_ipv6_gateway(gc, ipv6_gw);
}
if ((call->prot == OFONO_GPRS_PROTO_IPV4V6 ||
call->prot == OFONO_GPRS_PROTO_IP) &&
ip_gw) {
ofono_gprs_context_set_ipv4_gateway(gc, ip_gw);
}
g_free(ip_gw);
g_free(ipv6_gw);
}
if (!gutil_strv_equal(call->dnses, prev_call->dnses)){
char **dns_ip = NULL;
char **dns_ipv6 = NULL;
DBG("name server(s) changed");
signal = TRUE;
/* split based on protocol*/
ril_gprs_split_dns_by_protocol(call->dnses,
&dns_ip, &dns_ipv6);
if ((call->prot == OFONO_GPRS_PROTO_IPV4V6 ||
call->prot == OFONO_GPRS_PROTO_IPV6) &&
dns_ipv6) {
ofono_gprs_context_set_ipv6_dns_servers(gc,
(const char **) dns_ipv6);
}
if ((call->prot == OFONO_GPRS_PROTO_IPV4V6 ||
call->prot == OFONO_GPRS_PROTO_IP) && dns_ip) {
ofono_gprs_context_set_ipv4_dns_servers(gc,
(const char**)dns_ip);
}
g_strfreev(dns_ip);
g_strfreev(dns_ipv6);
}
if (signal) {
ofono_gprs_context_signal_change(gc, call->cid);
}
}
ril_gprs_context_data_call_free(prev_call);
}
static void ril_gprs_context_activate_primary_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ril_gprs_context_cbd *cbd = user_data;
ofono_gprs_context_cb_t cb = cbd->cb;
struct ril_gprs_context *gcd = cbd->gcd;
struct ofono_gprs_context *gc = gcd->gc;
struct ofono_error error;
struct ril_gprs_context_data_call_list *reply = NULL;
struct ril_gprs_context_data_call *call;
char **split_ip_addr = NULL;
char **split_ipv6_addr = NULL;
char* ip_gw = NULL;
char* ipv6_gw = NULL;
char** dns_addr = NULL;
char** dns_ipv6_addr = NULL;
ofono_info("setting up data call");
ril_error_init_ok(&error);
if (status != RIL_E_SUCCESS) {
ofono_error("GPRS context: Reply failure: %s",
ril_error_to_string(status));
error.type = OFONO_ERROR_TYPE_FAILURE;
error.error = status;
ril_gprs_context_set_disconnected(gcd);
goto done;
}
reply = ril_gprs_context_parse_data_call_list(data, len);
if (reply->num != 1) {
ofono_error("Number of data calls: %u", reply->num);
ril_error_init_failure(&error);
ril_gprs_context_set_disconnected(gcd);
goto done;
}
call = reply->calls->data;
if (call->status != 0) {
ofono_error("Unexpected data call status %d", call->status);
error.type = OFONO_ERROR_TYPE_FAILURE;
error.error = call->status;
goto done;
}
/* Must have interface */
if (!call->ifname) {
ofono_error("GPRS context: No interface");
error.type = OFONO_ERROR_TYPE_FAILURE;
error.error = EINVAL;
ril_gprs_context_set_disconnected(gcd);
goto done;
}
/* Check the ip address */
ril_gprs_split_ip_by_protocol(call->addresses, &split_ip_addr,
&split_ipv6_addr);
if (!split_ip_addr && !split_ipv6_addr) {
ofono_error("GPRS context: No IP address");
error.type = OFONO_ERROR_TYPE_FAILURE;
error.error = EINVAL;
ril_gprs_context_set_disconnected(gcd);
goto done;
}
/* Steal the call data from the list */
g_slist_free(reply->calls);
reply->calls = NULL;
ril_gprs_context_data_call_free(gcd->active_call);
gcd->active_call = call;
gcd->state = STATE_ACTIVE;
ofono_gprs_context_set_interface(gc, call->ifname);
ril_gprs_split_gw_by_protocol(call->gateways, &ip_gw, &ipv6_gw);
ril_gprs_split_dns_by_protocol(call->dnses, &dns_addr, &dns_ipv6_addr);
/* TODO:
* RILD can return multiple addresses; oFono only supports setting
* a single IPv4 and single IPV6 address. At this time, we only use
* the first address. It's possible that a RIL may just specify
* the end-points of the point-to-point connection, in which case this
* code will need to changed to handle such a device.
*/
if (split_ipv6_addr &&
(call->prot == OFONO_GPRS_PROTO_IPV6 ||
call->prot == OFONO_GPRS_PROTO_IPV4V6)) {
ril_gprs_context_set_ipv6(gc, split_ipv6_addr);
ofono_gprs_context_set_ipv6_gateway(gc, ipv6_gw);
ofono_gprs_context_set_ipv6_dns_servers(gc,
(const char **) dns_ipv6_addr);
}
if (split_ip_addr &&
(call->prot == OFONO_GPRS_PROTO_IP ||
call->prot == OFONO_GPRS_PROTO_IPV4V6)) {
ril_gprs_context_set_ipv4(gc, split_ip_addr);
ofono_gprs_context_set_ipv4_gateway(gc, ip_gw);
ofono_gprs_context_set_ipv4_dns_servers(gc,
(const char **) dns_addr);
}
done:
ril_gprs_context_data_call_list_free(reply);
g_strfreev(split_ip_addr);
g_strfreev(split_ipv6_addr);
g_strfreev(dns_addr);
g_strfreev(dns_ipv6_addr);
g_free(ip_gw);
g_free(ipv6_gw);
cb(&error, cbd->data);
}
static void ril_gprs_context_activate_primary(struct ofono_gprs_context *gc,
const struct ofono_gprs_primary_context *ctx,
ofono_gprs_context_cb_t cb, void *data)
{
struct ril_gprs_context *gcd = ril_gprs_context_get_data(gc);
struct ofono_netreg *netreg = ril_modem_ofono_netreg(gcd->modem);
struct ofono_gprs *gprs = ril_modem_ofono_gprs(gcd->modem);
const int rs = ofono_netreg_get_status(netreg);
const gchar *protocol_str;
GRilIoRequest* req;
int tech, auth;
/* Let's make sure that we aren't connecting when roaming not allowed */
if (rs == NETWORK_REGISTRATION_STATUS_ROAMING) {
if (!ofono_gprs_get_roaming_allowed(gprs) &&
ril_netreg_check_if_really_roaming(netreg, rs) ==
NETWORK_REGISTRATION_STATUS_ROAMING) {
struct ofono_error error;
ofono_info("Can't activate context %d (roaming)",
ctx->cid);
cb(ril_error_failure(&error), data);
return;
}
}
ofono_info("Activating context: %d", ctx->cid);
protocol_str = ril_gprs_ofono_protocol_to_ril(ctx->proto);
GASSERT(protocol_str);
/* ril.h has this to say about the radio tech parameter:
*
* ((const char **)data)[0] Radio technology to use: 0-CDMA,
* 1-GSM/UMTS, 2... for values above 2
* this is RIL_RadioTechnology + 2.
*
* Makes little sense but it is what it is.
*/
tech = gcd->network->data.ril_tech;
if (tech > 2) {
tech += 2;
} else {
/*
* This value used to be hardcoded, let's keep using it
* as the default.
*/
tech = RADIO_TECH_HSPA;
}
/*
* We do the same as in $AOSP/frameworks/opt/telephony/src/java/com/
* android/internal/telephony/dataconnection/DataConnection.java,
* onConnect(), and use authentication or not depending on whether
* the user field is empty or not.
*/
auth = (ctx->username && ctx->username[0]) ?
RIL_AUTH_BOTH : RIL_AUTH_NONE;
/*
* TODO: add comments about tethering, other non-public
* profiles...
*/
req = grilio_request_new();
grilio_request_append_int32(req, SETUP_DATA_CALL_PARAMS);
grilio_request_append_format(req, "%d", tech);
grilio_request_append_utf8(req, DATA_PROFILE_DEFAULT_STR);
grilio_request_append_utf8(req, ctx->apn);
grilio_request_append_utf8(req, ctx->username);
grilio_request_append_utf8(req, ctx->password);
grilio_request_append_format(req, "%d", auth);
grilio_request_append_utf8(req, protocol_str);
GASSERT(ctx->cid != CTX_ID_NONE);
gcd->active_ctx_cid = ctx->cid;
gcd->state = STATE_ACTIVATING;
grilio_queue_send_request_full(gcd->q, req, RIL_REQUEST_SETUP_DATA_CALL,
ril_gprs_context_activate_primary_cb, ril_gprs_context_cbd_free,
ril_gprs_context_cbd_new(gcd, cb, data));
grilio_request_unref(req);
}
static void ril_gprs_context_deactivate_data_call_cb(GRilIoChannel *io, int err,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_gprs_context_deactivate_req *req = user_data;
struct ril_gprs_context *gcd = req->cbd.gcd;
if (!gcd) {
/*
* ril_gprs_context_remove() zeroes gcd pointer for the
* pending ril_gprs_context_deactivate_req. Or we may have
* received RIL_UNSOL_DATA_CALL_LIST_CHANGED event before
* RIL_REQUEST_DEACTIVATE_DATA_CALL completes, in which
* case gcd will also be NULL. In any case, it means that
* there's nothing left for us to do here. Just ignore it.
*/
DBG("late completion, cid: %d err: %d", req->cid, err);
} else {
ofono_gprs_context_cb_t cb = req->cbd.cb;
/* Mark it as done */
if (gcd->deactivate_req == req) {
gcd->deactivate_req = NULL;
}
if (err == RIL_E_SUCCESS) {
GASSERT(gcd->active_call &&
gcd->active_call->cid == req->cid);
ril_gprs_context_set_disconnected(gcd);
ofono_info("Deactivated data call");
if (cb) {
cb(ril_error_ok(&error), req->cbd.data);
}
} else {
ofono_error("Deactivate failure: %s",
ril_error_to_string(err));
if (cb) {
cb(ril_error_failure(&error), req->cbd.data);
}
}
}
}
static void ril_gprs_context_deactivate_data_call(struct ril_gprs_context *gcd,
ofono_gprs_context_cb_t cb, void *data)
{
GRilIoRequest *req = grilio_request_new();
/* Overlapping deactivate requests make no sense */
GASSERT(!gcd->deactivate_req);
if (gcd->deactivate_req) {
gcd->deactivate_req->cbd.gcd = NULL;
}
gcd->deactivate_req =
ril_gprs_context_deactivate_req_new(gcd, cb, data);
/* Caller is responsible for checking gcd->active_call */
GASSERT(gcd->active_call);
grilio_request_append_int32(req, DEACTIVATE_DATA_CALL_PARAMS);
grilio_request_append_format(req, "%d", gcd->active_call->cid);
grilio_request_append_format(req, "%d",
RIL_DEACTIVATE_DATA_CALL_NO_REASON);
/*
* Send it to GRilIoChannel so that it doesn't get cancelled
* by ril_gprs_context_remove()
*/
grilio_channel_send_request_full(gcd->io, req,
RIL_REQUEST_DEACTIVATE_DATA_CALL,
ril_gprs_context_deactivate_data_call_cb,
ril_gprs_context_deactivate_req_free,
gcd->deactivate_req);
grilio_request_unref(req);
gcd->state = STATE_DEACTIVATING;
}
static void ril_gprs_context_deactivate_primary(struct ofono_gprs_context *gc,
unsigned int id, ofono_gprs_context_cb_t cb, void *data)
{
struct ril_gprs_context *gcd = ril_gprs_context_get_data(gc);
GASSERT(cb);
GASSERT(gcd->active_call && gcd->active_ctx_cid == id);
ofono_info("Deactivate primary");
if (gcd->active_call && gcd->active_ctx_cid == id) {
ril_gprs_context_deactivate_data_call(gcd, cb, data);
} else {
struct ofono_error error;
cb(ril_error_ok(&error), data);
}
}
static void ril_gprs_context_detach_shutdown(struct ofono_gprs_context *gc,
unsigned int id)
{
struct ril_gprs_context *gcd = ril_gprs_context_get_data(gc);
DBG("%d", id);
GASSERT(gcd->active_ctx_cid == id);
if (gcd->active_call && !gcd->deactivate_req) {
ril_gprs_context_deactivate_data_call(gcd, NULL, NULL);
}
}
static int ril_gprs_context_probe(struct ofono_gprs_context *gc,
unsigned int vendor, void *data)
{
struct ril_modem *modem = data;
struct ril_gprs_context *gcd = g_new0(struct ril_gprs_context, 1);
DBG("");
gcd->gc = gc;
gcd->modem = modem;
gcd->network = ril_network_ref(modem->network);
gcd->io = grilio_channel_ref(ril_modem_io(modem));
gcd->q = grilio_queue_new(gcd->io);
gcd->regid = grilio_channel_add_unsol_event_handler(gcd->io,
ril_gprs_context_call_list_changed,
RIL_UNSOL_DATA_CALL_LIST_CHANGED, gcd);
ril_gprs_context_set_disconnected(gcd);
ofono_gprs_context_set_data(gc, gcd);
return 0;
}
static void ril_gprs_context_remove(struct ofono_gprs_context *gc)
{
struct ril_gprs_context *gcd = ril_gprs_context_get_data(gc);
DBG("");
ofono_gprs_context_set_data(gc, NULL);
if (gcd->active_call && !gcd->deactivate_req) {
ril_gprs_context_deactivate_data_call(gcd, NULL, NULL);
}
if (gcd->deactivate_req) {
gcd->deactivate_req->cbd.gcd = NULL;
}
ril_network_unref(gcd->network);
grilio_channel_remove_handler(gcd->io, gcd->regid);
grilio_channel_unref(gcd->io);
grilio_queue_cancel_all(gcd->q, FALSE);
grilio_queue_unref(gcd->q);
ril_gprs_context_data_call_free(gcd->active_call);
g_free(gcd);
}
const struct ofono_gprs_context_driver ril_gprs_context_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_gprs_context_probe,
.remove = ril_gprs_context_remove,
.activate_primary = ril_gprs_context_activate_primary,
.deactivate_primary = ril_gprs_context_deactivate_primary,
.detach_shutdown = ril_gprs_context_detach_shutdown,
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,31 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef RIL_LOG_H
#define RIL_LOG_H
#define GLOG_MODULE_NAME ril_log
#include <gutil_log.h>
#include <ofono/log.h>
#endif /* RIL_LOG_H */
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

135
ofono/drivers/ril/ril_mce.c Normal file
View File

@@ -0,0 +1,135 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_mce.h"
#include "ril_constants.h"
#include <grilio_channel.h>
#include <grilio_request.h>
#include <ofono/log.h>
#include <ofono/dbus.h>
#include <gdbus.h>
#define MCE_SERVICE "com.nokia.mce"
#define MCE_SIGNAL_IF "com.nokia.mce.signal"
#define MCE_DISPLAY_SIG "display_status_ind"
#define MCE_DISPLAY_OFF_STRING "off"
struct ril_mce {
GRilIoChannel *io;
DBusConnection *conn;
int screen_state;
guint daemon_watch;
guint signal_watch;
};
static void ril_mce_send_screen_state(struct ril_mce *mce, gboolean on)
{
GRilIoRequest *req = grilio_request_sized_new(8);
grilio_request_append_int32(req, 1); /* Number of params */
grilio_request_append_int32(req, on); /* screen on/off */
grilio_channel_send_request(mce->io, req, RIL_REQUEST_SCREEN_STATE);
grilio_request_unref(req);
}
static gboolean ril_mce_display_changed(DBusConnection *conn,
DBusMessage *message, void *user_data)
{
DBusMessageIter iter;
if (dbus_message_iter_init(message, &iter) &&
dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) {
struct ril_mce *mce = user_data;
const char *value = NULL;
int state;
dbus_message_iter_get_basic(&iter, &value);
DBG(" %s", value);
/* It is on if it's not off */
state = (g_strcmp0(value, MCE_DISPLAY_OFF_STRING) != 0);
if (mce->screen_state != state) {
mce->screen_state = state;
ril_mce_send_screen_state(mce, state);
}
} else {
DBG("");
}
return TRUE;
}
static void ril_mce_connect(DBusConnection *conn, void *user_data)
{
struct ril_mce *mce = user_data;
DBG("");
if (!mce->signal_watch) {
mce->signal_watch = g_dbus_add_signal_watch(conn,
MCE_SERVICE, NULL, MCE_SIGNAL_IF, MCE_DISPLAY_SIG,
ril_mce_display_changed, mce, NULL);
}
}
static void ril_mce_disconnect(DBusConnection *conn, void *user_data)
{
struct ril_mce *mce = user_data;
DBG("");
if (mce->signal_watch) {
g_dbus_remove_watch(conn, mce->signal_watch);
mce->signal_watch = 0;
}
}
struct ril_mce *ril_mce_new(GRilIoChannel *io)
{
struct ril_mce *mce = g_new0(struct ril_mce, 1);
mce->conn = dbus_connection_ref(ofono_dbus_get_connection());
mce->io = grilio_channel_ref(io);
mce->screen_state = -1;
mce->daemon_watch = g_dbus_add_service_watch(mce->conn, MCE_SERVICE,
ril_mce_connect, ril_mce_disconnect, mce, NULL);
return mce;
}
void ril_mce_free(struct ril_mce *mce)
{
if (mce) {
if (mce->signal_watch) {
g_dbus_remove_watch(mce->conn, mce->signal_watch);
}
if (mce->daemon_watch) {
g_dbus_remove_watch(mce->conn, mce->daemon_watch);
}
dbus_connection_unref(mce->conn);
grilio_channel_unref(mce->io);
g_free(mce);
}
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,32 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef RIL_MCE_H
#define RIL_MCE_H
#include "ril_types.h"
struct ril_mce *ril_mce_new(GRilIoChannel *io);
void ril_mce_free(struct ril_mce *mce);
#endif /* RIL_MCE_H */
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,499 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_network.h"
#include "ril_radio.h"
#include "ril_sim_card.h"
#include "ril_data.h"
#include "ril_util.h"
#include "ril_log.h"
#include "ofono.h"
#define MAX_PDP_CONTEXTS (2)
#define ONLINE_TIMEOUT_SECS (15) /* 20 sec is hardcoded in ofono core */
enum ril_modem_power_state {
POWERED_OFF,
POWERED_ON,
POWERING_OFF
};
enum ril_modem_online_state {
OFFLINE,
GOING_ONLINE,
ONLINE,
GOING_OFFLINE
};
struct ril_modem_online_request {
ofono_modem_online_cb_t cb;
struct ril_modem_data *md;
void *data;
guint timeout_id;
};
struct ril_modem_data {
struct ril_modem modem;
GRilIoQueue *q;
struct ofono_radio_settings *radio_settings;
char *default_name;
char *imei;
gboolean pre_sim_done;
gboolean devinfo_created;
gboolean allow_data;
guint online_check_id;
enum ril_modem_power_state power_state;
gulong radio_state_event_id;
ril_modem_cb_t removed_cb;
void *removed_cb_data;
struct ril_modem_online_request set_online;
struct ril_modem_online_request set_offline;
};
#define RADIO_POWER_TAG(md) (md)
static struct ril_modem_data *ril_modem_data_from_ofono(struct ofono_modem *o)
{
struct ril_modem_data *md = ofono_modem_get_data(o);
GASSERT(md->modem.ofono == o);
return md;
}
static struct ril_modem_data *ril_modem_data_from_modem(struct ril_modem *m)
{
return m ? G_CAST(m, struct ril_modem_data, modem) : NULL;
}
static void *ril_modem_get_atom_data(struct ril_modem *modem,
enum ofono_atom_type type)
{
if (modem && modem->ofono) {
struct ofono_atom *atom =
__ofono_modem_find_atom(modem->ofono, type);
if (atom) {
return __ofono_atom_get_data(atom);
}
}
return NULL;
}
struct ofono_sim *ril_modem_ofono_sim(struct ril_modem *modem)
{
return ril_modem_get_atom_data(modem, OFONO_ATOM_TYPE_SIM);
}
struct ofono_gprs *ril_modem_ofono_gprs(struct ril_modem *modem)
{
return ril_modem_get_atom_data(modem, OFONO_ATOM_TYPE_GPRS);
}
struct ofono_netreg *ril_modem_ofono_netreg(struct ril_modem *modem)
{
return ril_modem_get_atom_data(modem, OFONO_ATOM_TYPE_NETREG);
}
void ril_modem_delete(struct ril_modem *md)
{
if (md && md->ofono) {
ofono_modem_remove(md->ofono);
}
}
void ril_modem_set_removed_cb(struct ril_modem *modem, ril_modem_cb_t cb,
void *data)
{
struct ril_modem_data *md = ril_modem_data_from_modem(modem);
md->removed_cb = cb;
md->removed_cb_data = data;
}
static void ril_modem_check_devinfo(struct ril_modem_data *md)
{
/* devinfo driver assumes that IMEI is known */
if (md->imei && md->pre_sim_done && !md->devinfo_created &&
md->modem.ofono) {
md->devinfo_created = TRUE;
ofono_devinfo_create(md->modem.ofono, 0, RILMODEM_DRIVER, md);
}
}
void ril_modem_set_imei(struct ril_modem *modem, const char *imei)
{
struct ril_modem_data *md = ril_modem_data_from_modem(modem);
if (md) {
g_free(md->imei);
modem->imei = md->imei = g_strdup(imei);
ril_modem_check_devinfo(md);
}
}
static void ril_modem_online_request_ok(struct ril_modem_online_request *req)
{
if (req->timeout_id) {
g_source_remove(req->timeout_id);
req->timeout_id = 0;
}
if (req->cb) {
struct ofono_error error;
ofono_modem_online_cb_t cb = req->cb;
void *data = req->data;
req->cb = NULL;
req->data = NULL;
cb(ril_error_ok(&error), data);
}
}
static void ril_modem_update_online_state(struct ril_modem_data *md)
{
switch (md->modem.radio->state) {
case RADIO_STATE_ON:
DBG("online");
ril_modem_online_request_ok(&md->set_online);
break;
case RADIO_STATE_OFF:
case RADIO_STATE_UNAVAILABLE:
DBG("offline");
ril_modem_online_request_ok(&md->set_offline);
break;
default:
break;
}
if (!md->set_offline.timeout_id && !md->set_online.timeout_id &&
md->power_state == POWERING_OFF) {
md->power_state = POWERED_OFF;
if (md->modem.ofono) {
ofono_modem_set_powered(md->modem.ofono, FALSE);
}
}
}
static gboolean ril_modem_online_request_timeout(gpointer data)
{
struct ril_modem_online_request *req = data;
struct ofono_error error;
ofono_modem_online_cb_t cb = req->cb;
void *cb_data = req->data;
GASSERT(req->timeout_id);
GASSERT(cb);
req->timeout_id = 0;
req->cb = NULL;
req->data = NULL;
cb(ril_error_failure(&error), cb_data);
ril_modem_update_online_state(req->md);
return FALSE;
}
static gboolean ril_modem_online_check(gpointer data)
{
struct ril_modem_data *md = data;
GASSERT(md->online_check_id);
md->online_check_id = 0;
ril_modem_update_online_state(md);
return FALSE;
}
static void ril_modem_schedule_online_check(struct ril_modem_data *md)
{
if (!md->online_check_id) {
md->online_check_id = g_idle_add(ril_modem_online_check, md);
}
}
static void ril_modem_update_radio_settings(struct ril_modem_data *md)
{
if (md->modem.radio->state == RADIO_STATE_ON) {
if (!md->radio_settings) {
DBG("Initializing radio settings interface");
md->radio_settings =
ofono_radio_settings_create(md->modem.ofono, 0,
RILMODEM_DRIVER, md);
}
} else if (md->radio_settings) {
DBG("Removing radio settings interface");
ofono_radio_settings_remove(md->radio_settings);
md->radio_settings = NULL;
}
}
static void ril_modem_radio_state_cb(struct ril_radio *radio, void *data)
{
struct ril_modem_data *md = data;
GASSERT(md->modem.radio == radio);
ril_modem_update_radio_settings(md);
ril_modem_update_online_state(md);
};
static void ril_modem_pre_sim(struct ofono_modem *modem)
{
struct ril_modem_data *md = ril_modem_data_from_ofono(modem);
DBG("%s", ofono_modem_get_path(modem));
md->pre_sim_done = TRUE;
ril_modem_check_devinfo(md);
ofono_sim_create(modem, 0, RILMODEM_DRIVER, md);
ofono_voicecall_create(modem, 0, RILMODEM_DRIVER, md);
ril_modem_update_radio_settings(md);
if (!md->radio_state_event_id) {
md->radio_state_event_id =
ril_radio_add_state_changed_handler(md->modem.radio,
ril_modem_radio_state_cb, md);
}
}
static void ril_modem_post_sim(struct ofono_modem *modem)
{
struct ril_modem_data *md = ril_modem_data_from_ofono(modem);
struct ofono_gprs *gprs;
DBG("%s", ofono_modem_get_path(modem));
ofono_sms_create(modem, 0, RILMODEM_DRIVER, md);
gprs = ofono_gprs_create(modem, 0, RILMODEM_DRIVER, md);
if (gprs) {
int i;
for (i = 0; i < MAX_PDP_CONTEXTS; i++) {
struct ofono_gprs_context *gc =
ofono_gprs_context_create(modem, 0,
RILMODEM_DRIVER, md);
if (gc == NULL)
break;
ofono_gprs_add_context(gprs, gc);
}
}
ofono_phonebook_create(modem, 0, RILMODEM_DRIVER, md);
ofono_call_forwarding_create(modem, 0, RILMODEM_DRIVER, md);
ofono_call_barring_create(modem, 0, RILMODEM_DRIVER, md);
ofono_stk_create(modem, 0, RILMODEM_DRIVER, md);
ofono_message_waiting_register(ofono_message_waiting_create(modem));
}
static void ril_modem_post_online(struct ofono_modem *modem)
{
struct ril_modem_data *md = ril_modem_data_from_ofono(modem);
DBG("%s", ofono_modem_get_path(modem));
ofono_call_volume_create(modem, 0, RILMODEM_DRIVER, md);
ofono_netreg_create(modem, 0, RILMODEM_DRIVER, md);
ofono_ussd_create(modem, 0, RILMODEM_DRIVER, md);
ofono_call_settings_create(modem, 0, RILMODEM_DRIVER, md);
ofono_oem_raw_create(modem, 0, RILMODEM_DRIVER, md);
}
static void ril_modem_set_online(struct ofono_modem *modem, ofono_bool_t online,
ofono_modem_online_cb_t cb, void *data)
{
struct ril_modem_data *md = ril_modem_data_from_ofono(modem);
struct ril_modem_online_request *req;
DBG("%s going %sline", ofono_modem_get_path(modem),
online ? "on" : "off");
if (online) {
ril_radio_power_on(md->modem.radio, RADIO_POWER_TAG(md));
req = &md->set_online;
} else {
ril_radio_power_off(md->modem.radio, RADIO_POWER_TAG(md));
req = &md->set_offline;
}
req->cb = cb;
req->data = data;
if (req->timeout_id) {
g_source_remove(req->timeout_id);
}
req->timeout_id = g_timeout_add_seconds(ONLINE_TIMEOUT_SECS,
ril_modem_online_request_timeout, req);
ril_modem_schedule_online_check(md);
}
static int ril_modem_enable(struct ofono_modem *modem)
{
struct ril_modem_data *md = ril_modem_data_from_ofono(modem);
DBG("%s", ofono_modem_get_path(modem));
md->power_state = POWERED_ON;
return 0;
}
static int ril_modem_disable(struct ofono_modem *modem)
{
struct ril_modem_data *md = ril_modem_data_from_ofono(modem);
DBG("%s", ofono_modem_get_path(modem));
if (md->set_online.timeout_id || md->set_offline.timeout_id) {
md->power_state = POWERING_OFF;
return -EINPROGRESS;
} else {
md->power_state = POWERED_OFF;
return 0;
}
}
static int ril_modem_probe(struct ofono_modem *modem)
{
DBG("%s", ofono_modem_get_path(modem));
return 0;
}
static void ril_modem_remove(struct ofono_modem *ofono)
{
struct ril_modem_data *md = ril_modem_data_from_ofono(ofono);
struct ril_modem *modem = &md->modem;
DBG("%s", ril_modem_get_path(modem));
if (md->removed_cb) {
ril_modem_cb_t cb = md->removed_cb;
void *data = md->removed_cb_data;
md->removed_cb = NULL;
md->removed_cb_data = NULL;
cb(modem, data);
}
ofono_modem_set_data(ofono, NULL);
ril_radio_remove_handler(modem->radio, md->radio_state_event_id);
ril_radio_power_off(modem->radio, RADIO_POWER_TAG(md));
ril_radio_unref(modem->radio);
if (md->online_check_id) {
g_source_remove(md->online_check_id);
}
if (md->set_online.timeout_id) {
g_source_remove(md->set_online.timeout_id);
}
if (md->set_offline.timeout_id) {
g_source_remove(md->set_offline.timeout_id);
}
ril_network_unref(modem->network);
ril_sim_card_unref(modem->sim_card);
ril_data_unref(modem->data);
grilio_channel_unref(modem->io);
grilio_queue_cancel_all(md->q, FALSE);
grilio_queue_unref(md->q);
g_free(md->default_name);
g_free(md->imei);
g_free(md);
}
struct ril_modem *ril_modem_create(GRilIoChannel *io,
const struct ril_slot_info *slot, struct ril_radio *radio,
struct ril_network *network, struct ril_sim_card *card,
struct ril_data *data)
{
/* Skip the slash from the path, it looks like "/ril_0" */
struct ofono_modem *ofono = ofono_modem_create(slot->path + 1,
RILMODEM_DRIVER);
if (ofono) {
int err;
struct ril_modem_data *md = g_new0(struct ril_modem_data, 1);
struct ril_modem *modem = &md->modem;
/* Copy config */
modem->config = *slot->config;
modem->imei = md->imei = g_strdup(slot->imei);
if (slot->config->default_name &&
slot->config->default_name[0]) {
md->default_name = g_strdup(slot->config->default_name);
} else {
md->default_name = g_strdup_printf("SIM%u",
slot->config->slot + 1);
}
modem->config.default_name = md->default_name;
modem->ofono = ofono;
modem->radio = ril_radio_ref(radio);
modem->network = ril_network_ref(network);
modem->sim_card = ril_sim_card_ref(card);
modem->data = ril_data_ref(data);
modem->io = grilio_channel_ref(io);
md->q = grilio_queue_new(io);
md->set_online.md = md;
md->set_offline.md = md;
ofono_modem_set_data(ofono, md);
err = ofono_modem_register(ofono);
if (!err) {
ril_radio_power_cycle(modem->radio);
ril_radio_power_on(modem->radio, RADIO_POWER_TAG(md));
GASSERT(io->connected);
/*
* ofono_modem_reset sets Powered to TRUE without
* issuing PropertyChange signal.
*/
ofono_modem_set_powered(modem->ofono, FALSE);
ofono_modem_set_powered(modem->ofono, TRUE);
md->power_state = POWERED_ON;
return modem;
} else {
ofono_error("Error %d registering %s",
err, RILMODEM_DRIVER);
/*
* If ofono_modem_register() failed, then
* ofono_modem_remove() won't invoke
* ril_modem_remove() callback.
*/
ril_modem_remove(ofono);
}
ofono_modem_remove(ofono);
}
return NULL;
}
const struct ofono_modem_driver ril_modem_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_modem_probe,
.remove = ril_modem_remove,
.enable = ril_modem_enable,
.disable = ril_modem_disable,
.pre_sim = ril_modem_pre_sim,
.post_sim = ril_modem_post_sim,
.post_online = ril_modem_post_online,
.set_online = ril_modem_set_online
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,543 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_network.h"
#include "ril_util.h"
#include "ril_log.h"
#include "common.h"
#include "simutil.h"
enum ril_netreg_events {
NETREG_RIL_EVENT_NITZ_TIME_RECEIVED,
NETREG_RIL_EVENT_SIGNAL_STRENGTH,
NETREG_RIL_EVENT_COUNT
};
enum ril_netreg_network_events {
NETREG_NETWORK_EVENT_OPERATOR_CHANGED,
NETREG_NETWORK_EVENT_VOICE_STATE_CHANGED,
NETREG_NETWORK_EVENT_COUNT
};
struct ril_netreg {
GRilIoChannel *io;
GRilIoQueue *q;
struct ofono_netreg *netreg;
struct ril_network *network;
char *log_prefix;
guint timer_id;
guint notify_id;
guint current_operator_id;
gulong ril_event_id[NETREG_RIL_EVENT_COUNT];
gulong network_event_id[NETREG_NETWORK_EVENT_COUNT];
};
struct ril_netreg_cbd {
struct ril_netreg *nd;
union {
ofono_netreg_status_cb_t status;
ofono_netreg_operator_cb_t operator;
ofono_netreg_operator_list_cb_t operator_list;
ofono_netreg_register_cb_t reg;
ofono_netreg_strength_cb_t strength;
gpointer ptr;
} cb;
gpointer data;
};
#define ril_netreg_cbd_free g_free
static inline struct ril_netreg *ril_netreg_get_data(struct ofono_netreg *ofono)
{
return ofono ? ofono_netreg_get_data(ofono) : NULL;
}
static struct ril_netreg_cbd *ril_netreg_cbd_new(struct ril_netreg *nd,
void *cb, void *data)
{
struct ril_netreg_cbd *cbd = g_new0(struct ril_netreg_cbd, 1);
cbd->nd = nd;
cbd->cb.ptr = cb;
cbd->data = data;
return cbd;
}
int ril_netreg_check_if_really_roaming(struct ofono_netreg *netreg,
gint status)
{
if (status == NETWORK_REGISTRATION_STATUS_ROAMING) {
/* These functions tolerate NULL argument */
const char *net_mcc = ofono_netreg_get_mcc(netreg);
const char *net_mnc = ofono_netreg_get_mnc(netreg);
struct sim_spdi *spdi = ofono_netreg_get_spdi(netreg);
if (spdi && net_mcc && net_mnc) {
if (sim_spdi_lookup(spdi, net_mcc, net_mnc)) {
ofono_info("not roaming based on spdi");
return NETWORK_REGISTRATION_STATUS_REGISTERED;
}
}
}
return status;
}
static int ril_netreg_check_status(struct ril_netreg *nd, int status)
{
return (nd && nd->netreg) ?
ril_netreg_check_if_really_roaming(nd->netreg, status) :
status;
}
static gboolean ril_netreg_status_notify_cb(gpointer user_data)
{
struct ril_netreg *nd = user_data;
const struct ril_registration_state *reg = &nd->network->voice;
DBG("%s", nd->log_prefix);
GASSERT(nd->notify_id);
nd->notify_id = 0;
ofono_netreg_status_notify(nd->netreg,
ril_netreg_check_status(nd, reg->status),
reg->lac, reg->ci, reg->access_tech);
return FALSE;
}
static void ril_netreg_status_notify(struct ril_network *net, void *user_data)
{
struct ril_netreg *nd = user_data;
/* Coalesce multiple notifications into one */
if (nd->notify_id) {
DBG("%snotification aready queued", nd->log_prefix);
} else {
DBG("%squeuing notification", nd->log_prefix);
nd->notify_id = g_idle_add(ril_netreg_status_notify_cb, nd);
}
}
static void ril_netreg_registration_status(struct ofono_netreg *netreg,
ofono_netreg_status_cb_t cb, void *data)
{
struct ril_netreg *nd = ril_netreg_get_data(netreg);
const struct ril_registration_state *reg = &nd->network->voice;
struct ofono_error error;
DBG("%s", nd->log_prefix);
cb(ril_error_ok(&error),
ril_netreg_check_status(nd, reg->status),
reg->lac, reg->ci, reg->access_tech, data);
}
static gboolean ril_netreg_current_operator_cb(void *user_data)
{
struct ril_netreg_cbd *cbd = user_data;
struct ril_netreg *nd = cbd->nd;
ofono_netreg_operator_cb_t cb = cbd->cb.operator;
struct ofono_error error;
DBG("%s", nd->log_prefix);
GASSERT(nd->current_operator_id);
nd->current_operator_id = 0;
cb(ril_error_ok(&error), nd->network->operator, cbd->data);
return FALSE;
}
static void ril_netreg_current_operator(struct ofono_netreg *netreg,
ofono_netreg_operator_cb_t cb, void *data)
{
struct ril_netreg *nd = ril_netreg_get_data(netreg);
GASSERT(!nd->current_operator_id);
if (nd->current_operator_id) {
g_source_remove(nd->current_operator_id);
}
nd->current_operator_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
ril_netreg_current_operator_cb,
ril_netreg_cbd_new(nd, cb, data),
ril_netreg_cbd_free);
}
static void ril_netreg_list_operators_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ril_netreg_cbd *cbd = user_data;
ofono_netreg_operator_list_cb_t cb = cbd->cb.operator_list;
struct ofono_network_operator *list;
struct ofono_error error;
int noperators = 0, i;
GRilIoParser rilp;
gboolean ok = TRUE;
if (status != RIL_E_SUCCESS) {
ofono_error("Failed to retrive the list of operators: %s",
ril_error_to_string(status));
cb(ril_error_failure(&error), 0, NULL, cbd->data);
return;
}
grilio_parser_init(&rilp, data, len);
/* Number of operators at the list (4 strings for every operator) */
grilio_parser_get_int32(&rilp, &noperators);
GASSERT(!(noperators % 4));
noperators /= 4;
ofono_info("noperators = %d", noperators);
list = g_new0(struct ofono_network_operator, noperators);
for (i = 0; i < noperators && ok; i++) {
struct ofono_network_operator *op = list + i;
char *lalpha = grilio_parser_get_utf8(&rilp);
char *salpha = grilio_parser_get_utf8(&rilp);
char *numeric = grilio_parser_get_utf8(&rilp);
char *status = grilio_parser_get_utf8(&rilp);
/* Try to use long by default */
if (lalpha) {
strncpy(op->name, lalpha,
OFONO_MAX_OPERATOR_NAME_LENGTH);
} else if (salpha) {
strncpy(op->name, salpha,
OFONO_MAX_OPERATOR_NAME_LENGTH);
} else {
op->name[0] = 0;
}
/* Set the proper status */
if (!strcmp(status, "available")) {
list[i].status = OPERATOR_STATUS_AVAILABLE;
} else if (!strcmp(status, "current")) {
list[i].status = OPERATOR_STATUS_CURRENT;
} else if (!strcmp(status, "forbidden")) {
list[i].status = OPERATOR_STATUS_FORBIDDEN;
} else {
list[i].status = OPERATOR_STATUS_UNKNOWN;
}
op->tech = -1;
ok = ril_parse_mcc_mnc(numeric, op);
if (ok) {
if (op->tech < 0) {
op->tech = cbd->nd->network->voice.access_tech;
}
DBG("[operator=%s, %s, %s, status: %s]", op->name,
op->mcc, op->mnc, status);
} else {
DBG("failed to parse operator list");
}
g_free(lalpha);
g_free(salpha);
g_free(numeric);
g_free(status);
}
if (ok) {
cb(ril_error_ok(&error), noperators, list, cbd->data);
} else {
cb(ril_error_failure(&error), 0, NULL, cbd->data);
}
g_free(list);
}
static void ril_netreg_list_operators(struct ofono_netreg *netreg,
ofono_netreg_operator_list_cb_t cb, void *data)
{
struct ril_netreg *nd = ril_netreg_get_data(netreg);
grilio_queue_send_request_full(nd->q, NULL,
RIL_REQUEST_QUERY_AVAILABLE_NETWORKS,
ril_netreg_list_operators_cb, ril_netreg_cbd_free,
ril_netreg_cbd_new(nd, cb, data));
}
static void ril_netreg_register_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ril_netreg_cbd *cbd = user_data;
ofono_netreg_register_cb_t cb = cbd->cb.reg;
struct ofono_error error;
if (status == RIL_E_SUCCESS) {
cb(ril_error_ok(&error), cbd->data);
} else {
ofono_error("registration failed, ril result %d", status);
cb(ril_error_failure(&error), cbd->data);
}
}
static void ril_netreg_register_auto(struct ofono_netreg *netreg,
ofono_netreg_register_cb_t cb, void *data)
{
struct ril_netreg *nd = ril_netreg_get_data(netreg);
ofono_info("nw select automatic");
grilio_queue_send_request_full(nd->q, NULL,
RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC,
ril_netreg_register_cb, ril_netreg_cbd_free,
ril_netreg_cbd_new(nd, cb, data));
}
static void ril_netreg_register_manual(struct ofono_netreg *netreg,
const char *mcc, const char *mnc,
ofono_netreg_register_cb_t cb, void *data)
{
struct ril_netreg *nd = ril_netreg_get_data(netreg);
GRilIoRequest *req = grilio_request_new();
ofono_info("nw select manual: %s%s", mcc, mnc);
grilio_request_append_format(req, "%s%s+0", mcc, mnc);
grilio_queue_send_request_full(nd->q, req,
RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL,
ril_netreg_register_cb, ril_netreg_cbd_free,
ril_netreg_cbd_new(nd, cb, data));
grilio_request_unref(req);
}
static int ril_netreg_get_signal_strength(const void *data, guint len)
{
GRilIoParser rilp;
int gw_signal = 0, cdma_dbm = 0, evdo_dbm = 0, lte_signal = 0;
grilio_parser_init(&rilp, data, len);
/* RIL_SignalStrength_v6 */
/* GW_SignalStrength */
grilio_parser_get_int32(&rilp, &gw_signal);
grilio_parser_get_int32(&rilp, NULL); /* bitErrorRate */
/* CDMA_SignalStrength */
grilio_parser_get_int32(&rilp, &cdma_dbm);
grilio_parser_get_int32(&rilp, NULL); /* ecio */
/* EVDO_SignalStrength */
grilio_parser_get_int32(&rilp, &evdo_dbm);
grilio_parser_get_int32(&rilp, NULL); /* ecio */
grilio_parser_get_int32(&rilp, NULL); /* signalNoiseRatio */
/* LTE_SignalStrength */
grilio_parser_get_int32(&rilp, &lte_signal);
grilio_parser_get_int32(&rilp, NULL); /* rsrp */
grilio_parser_get_int32(&rilp, NULL); /* rsrq */
grilio_parser_get_int32(&rilp, NULL); /* rssnr */
grilio_parser_get_int32(&rilp, NULL); /* cqi */
DBG("gw: %d, cdma: %d, evdo: %d, lte: %d", gw_signal, cdma_dbm,
evdo_dbm, lte_signal);
/* Return the first valid one */
if (gw_signal != 99 && gw_signal != -1) {
return (gw_signal * 100) / 31;
}
if (lte_signal != 99 && lte_signal != -1) {
return (lte_signal * 100) / 31;
}
/* In case of dbm, return the value directly */
if (cdma_dbm != -1) {
return MIN(cdma_dbm, 100);
}
if (evdo_dbm != -1) {
return MIN(evdo_dbm, 100);
}
return -1;
}
static void ril_netreg_strength_notify(GRilIoChannel *io, guint ril_event,
const void *data, guint len, void *user_data)
{
struct ril_netreg *nd = user_data;
int strength;
GASSERT(ril_event == RIL_UNSOL_SIGNAL_STRENGTH);
strength = ril_netreg_get_signal_strength(data, len);
DBG("%d", strength);
ofono_netreg_strength_notify(nd->netreg, strength);
}
static void ril_netreg_strength_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ril_netreg_cbd *cbd = user_data;
ofono_netreg_strength_cb_t cb = cbd->cb.strength;
struct ofono_error error;
if (status == RIL_E_SUCCESS) {
int strength = ril_netreg_get_signal_strength(data, len);
cb(ril_error_ok(&error), strength, cbd->data);
} else {
ofono_error("Failed to retrive the signal strength: %s",
ril_error_to_string(status));
cb(ril_error_failure(&error), -1, cbd->data);
}
}
static void ril_netreg_strength(struct ofono_netreg *netreg,
ofono_netreg_strength_cb_t cb, void *data)
{
struct ril_netreg *nd = ril_netreg_get_data(netreg);
grilio_queue_send_request_full(nd->q, NULL,
RIL_REQUEST_SIGNAL_STRENGTH, ril_netreg_strength_cb,
ril_netreg_cbd_free, ril_netreg_cbd_new(nd, cb, data));
}
static void ril_netreg_nitz_notify(GRilIoChannel *io, guint ril_event,
const void *data, guint len, void *user_data)
{
struct ril_netreg *nd = user_data;
GRilIoParser rilp;
struct ofono_network_time time;
int year, mon, mday, hour, min, sec, dst, tzi;
char tzs, tz[4];
gchar *nitz;
GASSERT(ril_event == RIL_UNSOL_NITZ_TIME_RECEIVED);
grilio_parser_init(&rilp, data, len);
nitz = grilio_parser_get_utf8(&rilp);
DBG("%s", nitz);
sscanf(nitz, "%u/%u/%u,%u:%u:%u%c%u,%u", &year, &mon, &mday,
&hour, &min, &sec, &tzs, &tzi, &dst);
snprintf(tz, sizeof(tz), "%c%d", tzs, tzi);
time.utcoff = atoi(tz) * 15 * 60;
time.dst = dst;
time.sec = sec;
time.min = min;
time.hour = hour;
time.mday = mday;
time.mon = mon;
time.year = 2000 + year;
ofono_netreg_time_notify(nd->netreg, &time);
g_free(nitz);
}
static gboolean ril_netreg_register(gpointer user_data)
{
struct ril_netreg *nd = user_data;
GASSERT(nd->timer_id);
nd->timer_id = 0;
ofono_netreg_register(nd->netreg);
/* Register for network state changes */
nd->network_event_id[NETREG_NETWORK_EVENT_OPERATOR_CHANGED] =
ril_network_add_operator_changed_handler(nd->network,
ril_netreg_status_notify, nd);
nd->network_event_id[NETREG_NETWORK_EVENT_VOICE_STATE_CHANGED] =
ril_network_add_voice_state_changed_handler(nd->network,
ril_netreg_status_notify, nd);
/* Register for network time updates */
nd->ril_event_id[NETREG_RIL_EVENT_NITZ_TIME_RECEIVED] =
grilio_channel_add_unsol_event_handler(nd->io,
ril_netreg_nitz_notify,
RIL_UNSOL_NITZ_TIME_RECEIVED, nd);
/* Register for signal strength changes */
nd->ril_event_id[NETREG_RIL_EVENT_SIGNAL_STRENGTH] =
grilio_channel_add_unsol_event_handler(nd->io,
ril_netreg_strength_notify,
RIL_UNSOL_SIGNAL_STRENGTH, nd);
/* This makes the timeout a single-shot */
return FALSE;
}
static int ril_netreg_probe(struct ofono_netreg *netreg, unsigned int vendor,
void *data)
{
struct ril_modem *modem = data;
struct ril_netreg *nd = g_new0(struct ril_netreg, 1);
guint slot = ril_modem_slot(modem);
DBG("[%u] %p", slot, netreg);
nd->log_prefix = g_strdup_printf("%s_%u ", RILMODEM_DRIVER, slot);
nd->io = grilio_channel_ref(ril_modem_io(modem));
nd->q = grilio_queue_new(nd->io);
nd->network = ril_network_ref(modem->network);
nd->netreg = netreg;
ofono_netreg_set_data(netreg, nd);
nd->timer_id = g_idle_add(ril_netreg_register, nd);
return 0;
}
static void ril_netreg_remove(struct ofono_netreg *netreg)
{
struct ril_netreg *nd = ril_netreg_get_data(netreg);
int i;
DBG("%p", netreg);
grilio_queue_cancel_all(nd->q, FALSE);
ofono_netreg_set_data(netreg, NULL);
if (nd->timer_id > 0) {
g_source_remove(nd->timer_id);
}
if (nd->notify_id) {
g_source_remove(nd->notify_id);
}
if (nd->current_operator_id) {
g_source_remove(nd->current_operator_id);
}
for (i=0; i<G_N_ELEMENTS(nd->network_event_id); i++) {
ril_network_remove_handler(nd->network, nd->network_event_id[i]);
}
ril_network_unref(nd->network);
grilio_channel_remove_handlers(nd->io, nd->ril_event_id,
G_N_ELEMENTS(nd->ril_event_id));
grilio_channel_unref(nd->io);
grilio_queue_unref(nd->q);
g_free(nd->log_prefix);
g_free(nd);
}
const struct ofono_netreg_driver ril_netreg_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_netreg_probe,
.remove = ril_netreg_remove,
.registration_status = ril_netreg_registration_status,
.current_operator = ril_netreg_current_operator,
.list_operators = ril_netreg_list_operators,
.register_auto = ril_netreg_register_auto,
.register_manual = ril_netreg_register_manual,
.strength = ril_netreg_strength
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,501 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_network.h"
#include "ril_radio.h"
#include "ril_util.h"
#include "ril_log.h"
#include <grilio_queue.h>
#include <grilio_request.h>
#include <grilio_parser.h>
#include <ofono/netreg.h>
#include "common.h"
typedef GObjectClass RilNetworkClass;
typedef struct ril_network RilNetwork;
struct ril_network_priv {
GRilIoChannel *io;
GRilIoQueue *q;
struct ril_radio *radio;
char *log_prefix;
gulong event_id;
guint operator_poll_id;
guint voice_poll_id;
guint data_poll_id;
gulong radio_event_id;
struct ofono_network_operator operator;
};
enum ril_network_signal {
SIGNAL_OPERATOR_CHANGED,
SIGNAL_VOICE_STATE_CHANGED,
SIGNAL_DATA_STATE_CHANGED,
SIGNAL_COUNT
};
#define SIGNAL_OPERATOR_CHANGED_NAME "ril-network-operator-changed"
#define SIGNAL_VOICE_STATE_CHANGED_NAME "ril-network-voice-state-changed"
#define SIGNAL_DATA_STATE_CHANGED_NAME "ril-network-data-state-changed"
static guint ril_network_signals[SIGNAL_COUNT] = { 0 };
G_DEFINE_TYPE(RilNetwork, ril_network, G_TYPE_OBJECT)
#define RIL_NETWORK_TYPE (ril_network_get_type())
#define RIL_NETWORK(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj,\
RIL_NETWORK_TYPE,RilNetwork))
static void ril_network_reset_state(struct ril_registration_state *reg)
{
memset(reg, 0, sizeof(*reg));
reg->status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
reg->access_tech = -1;
reg->ril_tech = -1;
reg->lac = -1;
reg->ci = -1;
}
static gboolean ril_network_parse_response(struct ril_network *self,
const void *data, guint len, struct ril_registration_state *reg)
{
struct ril_network_priv *priv = self->priv;
int nparams, ril_status;
gchar *sstatus = NULL, *slac = NULL, *sci = NULL;
gchar *stech = NULL, *sreason = NULL, *smax = NULL;
GRilIoParser rilp;
ril_network_reset_state(reg);
/* Size of response string array. The minimum seen in the wild is 3 */
grilio_parser_init(&rilp, data, len);
if (!grilio_parser_get_int32(&rilp, &nparams) || nparams < 3) {
DBG("%sbroken response", priv->log_prefix);
return FALSE;
}
sstatus = grilio_parser_get_utf8(&rilp); /* response[0] */
if (!sstatus) {
DBG("%sNo sstatus value returned!", priv->log_prefix);
return FALSE;
}
slac = grilio_parser_get_utf8(&rilp); /* response[1] */
sci = grilio_parser_get_utf8(&rilp); /* response[2] */
if (nparams > 3) {
stech = grilio_parser_get_utf8(&rilp); /* response[3] */
}
ril_status = atoi(sstatus);
if (ril_status > 10) {
reg->status = ril_status - 10;
} else {
reg->status = ril_status;
}
/* FIXME: need to review VOICE_REGISTRATION response
* as it returns up to 15 parameters ( vs. 6 for DATA ).
*
* The first four parameters are the same for both
* responses ( although status includes values for
* emergency calls for VOICE response ).
*
* Parameters 5 & 6 have different meanings for
* voice & data response.
*/
if (nparams > 4) {
/* TODO: different use for CDMA */
sreason = grilio_parser_get_utf8(&rilp); /* response[4] */
if (nparams > 5) {
/* TODO: different use for CDMA */
smax = grilio_parser_get_utf8(&rilp); /* response[5] */
if (smax) {
reg->max_calls = atoi(smax);
}
}
}
/*
* Some older RILs don't provide max calls, in that case let's
* supply some reasonable default. We don't need more than 2
* simultaneous data calls anyway.
*/
if (nparams <= 5) {
reg->max_calls = 2;
}
reg->lac = slac ? strtol(slac, NULL, 16) : -1;
reg->ci = sci ? strtol(sci, NULL, 16) : -1;
reg->access_tech = ril_parse_tech(stech, &reg->ril_tech);
DBG("%s%s,%s,%s,%d,%s,%s,%s", priv->log_prefix,
registration_status_to_string(reg->status),
slac, sci, reg->ril_tech,
registration_tech_to_string(reg->access_tech),
sreason, smax);
g_free(sstatus);
g_free(slac);
g_free(sci);
g_free(stech);
g_free(sreason);
g_free(smax);
return TRUE;
}
static void ril_network_op_copy(struct ofono_network_operator *dest,
const struct ofono_network_operator *src)
{
strncpy(dest->mcc, src->mcc, sizeof(dest->mcc));
strncpy(dest->mnc, src->mnc, sizeof(dest->mnc));
strncpy(dest->name, src->name, sizeof(dest->name));
dest->mcc[sizeof(dest->mcc)-1] = 0;
dest->mnc[sizeof(dest->mnc)-1] = 0;
dest->name[sizeof(dest->name)-1] = 0;
dest->status = src->status;
dest->tech = src->tech;
}
static gboolean ril_network_op_equal(const struct ofono_network_operator *op1,
const struct ofono_network_operator *op2)
{
if (op1 == op2) {
return TRUE;
} else if (!op1 || !op2) {
return FALSE;
} else {
return op1->status == op2->status &&
op1->tech == op2->tech &&
!strncmp(op1->mcc, op2->mcc, sizeof(op2->mcc)) &&
!strncmp(op1->mnc, op2->mnc, sizeof(op2->mnc)) &&
!strncmp(op1->name, op2->name, sizeof(op2->name));
}
}
static void ril_network_poll_operator_cb(GRilIoChannel *io, int req_status,
const void *data, guint len, void *user_data)
{
struct ril_network *self = RIL_NETWORK(user_data);
struct ril_network_priv *priv = self->priv;
GASSERT(priv->operator_poll_id);
priv->operator_poll_id = 0;
if (req_status == RIL_E_SUCCESS) {
struct ofono_network_operator op;
gboolean changed = FALSE;
gchar *lalpha;
char *salpha;
char *numeric;
GRilIoParser rilp;
grilio_parser_init(&rilp, data, len);
grilio_parser_get_int32(&rilp, NULL);
lalpha = grilio_parser_get_utf8(&rilp);
salpha = grilio_parser_get_utf8(&rilp);
numeric = grilio_parser_get_utf8(&rilp);
op.tech = -1;
if (ril_parse_mcc_mnc(numeric, &op)) {
if (op.tech < 0) op.tech = self->voice.access_tech;
op.status = OPERATOR_STATUS_CURRENT;
op.name[0] = 0;
if (lalpha) {
strncpy(op.name, lalpha, sizeof(op.name));
} else if (salpha) {
strncpy(op.name, salpha, sizeof(op.name));
} else {
strncpy(op.name, numeric, sizeof(op.name));
}
op.name[sizeof(op.name)-1] = 0;
if (!self->operator) {
self->operator = &priv->operator;
ril_network_op_copy(&priv->operator, &op);
changed = TRUE;
} else if (!ril_network_op_equal(&op, &priv->operator)) {
ril_network_op_copy(&priv->operator, &op);
changed = TRUE;
}
} else if (self->operator) {
self->operator = NULL;
changed = TRUE;
}
if (changed) {
if (self->operator) {
DBG("%slalpha=%s, salpha=%s, numeric=%s, %s, "
"mcc=%s, mnc=%s, %s", priv->log_prefix,
lalpha, salpha, numeric,
op.name, op.mcc, op.mnc,
registration_tech_to_string(op.tech));
} else {
DBG("%sno operator", priv->log_prefix);
}
g_signal_emit(self, ril_network_signals[
SIGNAL_OPERATOR_CHANGED], 0);
}
g_free(lalpha);
g_free(salpha);
g_free(numeric);
}
}
static void ril_network_poll_voice_state_cb(GRilIoChannel *io, int req_status,
const void *data, guint len, void *user_data)
{
struct ril_network *self = RIL_NETWORK(user_data);
struct ril_network_priv *priv = self->priv;
GASSERT(priv->voice_poll_id);
priv->voice_poll_id = 0;
if (req_status == RIL_E_SUCCESS) {
struct ril_registration_state state;
ril_network_parse_response(self, data, len, &state);
if (memcmp(&state, &self->voice, sizeof(state))) {
DBG("%svoice registration changed", priv->log_prefix);
self->voice = state;
g_signal_emit(self, ril_network_signals[
SIGNAL_VOICE_STATE_CHANGED], 0);
}
}
}
static void ril_network_poll_data_state_cb(GRilIoChannel *io, int req_status,
const void *data, guint len, void *user_data)
{
struct ril_network *self = RIL_NETWORK(user_data);
struct ril_network_priv *priv = self->priv;
GASSERT(priv->data_poll_id);
priv->data_poll_id = 0;
if (req_status == RIL_E_SUCCESS) {
struct ril_registration_state state;
ril_network_parse_response(self, data, len, &state);
if (memcmp(&state, &self->data, sizeof(state))) {
DBG("%sdata registration changed", priv->log_prefix);
self->data = state;
g_signal_emit(self, ril_network_signals[
SIGNAL_DATA_STATE_CHANGED], 0);
}
}
}
static guint ril_network_poll_and_retry(struct ril_network *self, guint id,
int code, GRilIoChannelResponseFunc fn)
{
struct ril_network_priv *priv = self->priv;
if (id) {
/* Retry right away, don't wait for retry timeout to expire */
grilio_channel_retry_request(priv->io, id);
} else {
GRilIoRequest *req = grilio_request_new();
grilio_request_set_retry(req, RIL_RETRY_SECS*1000, -1);
id = grilio_queue_send_request_full(priv->q, req, code, fn,
NULL, self);
grilio_request_unref(req);
}
return id;
}
static void ril_network_poll_state(struct ril_network *self)
{
struct ril_network_priv *priv = self->priv;
DBG("%s", priv->log_prefix);
priv->operator_poll_id = ril_network_poll_and_retry(self,
priv->operator_poll_id, RIL_REQUEST_OPERATOR,
ril_network_poll_operator_cb);
priv->voice_poll_id = ril_network_poll_and_retry(self,
priv->voice_poll_id, RIL_REQUEST_VOICE_REGISTRATION_STATE,
ril_network_poll_voice_state_cb);
priv->data_poll_id = ril_network_poll_and_retry(self,
priv->data_poll_id, RIL_REQUEST_DATA_REGISTRATION_STATE,
ril_network_poll_data_state_cb);
}
gulong ril_network_add_operator_changed_handler(struct ril_network *self,
ril_network_cb_t cb, void *arg)
{
return (G_LIKELY(self) && G_LIKELY(cb)) ? g_signal_connect(self,
SIGNAL_OPERATOR_CHANGED_NAME, G_CALLBACK(cb), arg) : 0;
}
gulong ril_network_add_voice_state_changed_handler(struct ril_network *self,
ril_network_cb_t cb, void *arg)
{
return (G_LIKELY(self) && G_LIKELY(cb)) ? g_signal_connect(self,
SIGNAL_VOICE_STATE_CHANGED_NAME, G_CALLBACK(cb), arg) : 0;
}
gulong ril_network_add_data_state_changed_handler(struct ril_network *self,
ril_network_cb_t cb, void *arg)
{
return (G_LIKELY(self) && G_LIKELY(cb)) ? g_signal_connect(self,
SIGNAL_DATA_STATE_CHANGED_NAME, G_CALLBACK(cb), arg) : 0;
}
void ril_network_remove_handler(struct ril_network *self, gulong id)
{
if (G_LIKELY(self) && G_LIKELY(id)) {
g_signal_handler_disconnect(self, id);
}
}
static void ril_network_voice_state_changed_cb(GRilIoChannel *io, guint code,
const void *data, guint len, void *user_data)
{
struct ril_network *self = RIL_NETWORK(user_data);
struct ril_network_priv *priv = self->priv;
DBG("%s", priv->log_prefix);
GASSERT(code == RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED);
ril_network_poll_state(self);
}
static void ril_network_radio_state_cb(struct ril_radio *radio, void *user_data)
{
struct ril_network *self = RIL_NETWORK(user_data);
if (radio->state == RADIO_STATE_ON) {
ril_network_poll_state(self);
}
}
struct ril_network *ril_network_new(GRilIoChannel *io, struct ril_radio *radio)
{
struct ril_network *self = g_object_new(RIL_NETWORK_TYPE, NULL);
struct ril_network_priv *priv = self->priv;
priv->io = grilio_channel_ref(io);
priv->q = grilio_queue_new(priv->io);
priv->radio = ril_radio_ref(radio);
priv->log_prefix =
(io && io->name && io->name[0] && strcmp(io->name, "RIL")) ?
g_strconcat(io->name, " ", NULL) : g_strdup("");
DBG("%s", priv->log_prefix);
priv->event_id = grilio_channel_add_unsol_event_handler(priv->io,
ril_network_voice_state_changed_cb,
RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, self);
priv->radio_event_id = ril_radio_add_state_changed_handler(priv->radio,
ril_network_radio_state_cb, self);
/*
* Query the initial state. Querying network state before the radio
* has been turned on makes RIL unhappy.
*/
if (radio->state == RADIO_STATE_ON) {
ril_network_poll_state(self);
}
return self;
}
struct ril_network *ril_network_ref(struct ril_network *self)
{
if (G_LIKELY(self)) {
g_object_ref(RIL_NETWORK(self));
return self;
} else {
return NULL;
}
}
void ril_network_unref(struct ril_network *self)
{
if (G_LIKELY(self)) {
g_object_unref(RIL_NETWORK(self));
}
}
static void ril_network_init(struct ril_network *self)
{
struct ril_network_priv *priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
RIL_NETWORK_TYPE, struct ril_network_priv);
self->priv = priv;
ril_network_reset_state(&self->voice);
ril_network_reset_state(&self->data);
}
static void ril_network_dispose(GObject *object)
{
struct ril_network *self = RIL_NETWORK(object);
struct ril_network_priv *priv = self->priv;
if (priv->event_id) {
grilio_channel_remove_handler(priv->io, priv->event_id);
priv->event_id = 0;
}
if (priv->radio_event_id) {
ril_radio_remove_handler(priv->radio, priv->radio_event_id);
priv->radio_event_id = 0;
}
grilio_queue_cancel_all(priv->q, FALSE);
G_OBJECT_CLASS(ril_network_parent_class)->dispose(object);
}
static void ril_network_finalize(GObject *object)
{
struct ril_network *self = RIL_NETWORK(object);
struct ril_network_priv *priv = self->priv;
DBG("%s", priv->log_prefix);
g_free(priv->log_prefix);
grilio_channel_unref(priv->io);
grilio_queue_unref(priv->q);
ril_radio_unref(priv->radio);
G_OBJECT_CLASS(ril_network_parent_class)->finalize(object);
}
static void ril_network_class_init(RilNetworkClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->dispose = ril_network_dispose;
object_class->finalize = ril_network_finalize;
g_type_class_add_private(klass, sizeof(struct ril_network_priv));
ril_network_signals[SIGNAL_OPERATOR_CHANGED] =
g_signal_new(SIGNAL_OPERATOR_CHANGED_NAME,
G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL, G_TYPE_NONE, 0);
ril_network_signals[SIGNAL_VOICE_STATE_CHANGED] =
g_signal_new(SIGNAL_VOICE_STATE_CHANGED_NAME,
G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL, G_TYPE_NONE, 0);
ril_network_signals[SIGNAL_DATA_STATE_CHANGED] =
g_signal_new(SIGNAL_DATA_STATE_CHANGED_NAME,
G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL, G_TYPE_NONE, 0);
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,62 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef RIL_NETWORK_H
#define RIL_NETWORK_H
#include "ril_types.h"
struct ofono_network_operator;
struct ril_registration_state {
int status; /* enum network_registration_status */
int access_tech; /* enum access_technology or -1 if none */
int ril_tech;
int max_calls;
int lac;
int ci;
};
struct ril_network {
GObject object;
struct ril_network_priv *priv;
struct ril_registration_state voice;
struct ril_registration_state data;
const struct ofono_network_operator *operator;
};
typedef void (*ril_network_cb_t)(struct ril_network *net, void *arg);
struct ril_network *ril_network_new(GRilIoChannel *io, struct ril_radio *radio);
struct ril_network *ril_network_ref(struct ril_network *net);
void ril_network_unref(struct ril_network *net);
gulong ril_network_add_operator_changed_handler(struct ril_network *net,
ril_network_cb_t cb, void *arg);
gulong ril_network_add_voice_state_changed_handler(struct ril_network *net,
ril_network_cb_t cb, void *arg);
gulong ril_network_add_data_state_changed_handler(struct ril_network *net,
ril_network_cb_t cb, void *arg);
void ril_network_remove_handler(struct ril_network *net, gulong id);
#endif /* RIL_NETWORK */
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,137 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_util.h"
#include "ril_log.h"
#include "ril_constants.h"
struct ril_oem_raw {
GRilIoQueue *q;
guint timer_id;
};
struct ril_oem_raw_cbd {
ofono_oem_raw_query_cb_t cb;
gpointer data;
};
#define ril_oem_raw_cbd_free g_free
static inline struct ril_oem_raw *ril_oem_raw_get_data(
struct ofono_oem_raw *raw)
{
return ofono_oem_raw_get_data(raw);
}
static struct ril_oem_raw_cbd *ril_oem_raw_cbd_new(ofono_oem_raw_query_cb_t cb,
void *data)
{
struct ril_oem_raw_cbd *cbd = g_new0(struct ril_oem_raw_cbd, 1);
cbd->cb = cb;
cbd->data = data;
return cbd;
}
static void ril_oem_raw_request_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_oem_raw_cbd *cbd = user_data;
if (status == RIL_E_SUCCESS) {
struct ofono_oem_raw_results result;
result.data = (void *)data;
result.length = len;
cbd->cb(ril_error_ok(&error), &result, cbd->data);
} else {
DBG("error:%d len:%d ", status, len);
cbd->cb(ril_error_failure(&error), NULL, cbd->data);
}
}
static void ril_oem_raw_request(struct ofono_oem_raw *raw,
const struct ofono_oem_raw_request *request,
ofono_oem_raw_query_cb_t cb, void *data)
{
struct ril_oem_raw *od = ril_oem_raw_get_data(raw);
GRilIoRequest *req = grilio_request_sized_new(request->length);
grilio_request_append_bytes(req, request->data, request->length);
grilio_queue_send_request_full(od->q, req, RIL_REQUEST_OEM_HOOK_RAW,
ril_oem_raw_request_cb, ril_oem_raw_cbd_free,
ril_oem_raw_cbd_new(cb, data));
grilio_request_unref(req);
}
static gboolean ril_oem_raw_register(gpointer user_data)
{
struct ofono_oem_raw *raw = user_data;
struct ril_oem_raw *od = ril_oem_raw_get_data(raw);
DBG("");
GASSERT(od->timer_id);
od->timer_id = 0;
ofono_oem_raw_dbus_register(raw);
/* Single-shot */
return FALSE;
}
static int ril_oem_raw_probe(struct ofono_oem_raw *raw, unsigned int vendor,
void *data)
{
struct ril_modem *modem = data;
struct ril_oem_raw *od = g_new0(struct ril_oem_raw, 1);
DBG("");
od->q = grilio_queue_new(ril_modem_io(modem));
od->timer_id = g_idle_add(ril_oem_raw_register, raw);
ofono_oem_raw_set_data(raw, od);
return 0;
}
static void ril_oem_raw_remove(struct ofono_oem_raw *raw)
{
struct ril_oem_raw *od = ril_oem_raw_get_data(raw);
DBG("");
grilio_queue_cancel_all(od->q, TRUE);
ofono_oem_raw_set_data(raw, NULL);
if (od->timer_id) {
g_source_remove(od->timer_id);
}
grilio_queue_unref(od->q);
g_free(od);
}
/* const */ struct ofono_oem_raw_driver ril_oem_raw_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_oem_raw_probe,
.remove = ril_oem_raw_remove,
.request = ril_oem_raw_request,
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,167 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef RIL_PLUGIN_H
#define RIL_PLUGIN_H
#include "ril_types.h"
#include <ofono/modem.h>
#include <ofono/call-barring.h>
#include <ofono/call-forwarding.h>
#include <ofono/call-settings.h>
#include <ofono/call-volume.h>
#include <ofono/cbs.h>
#include <ofono/devinfo.h>
#include <ofono/gprs-context.h>
#include <ofono/gprs.h>
#include <ofono/netreg.h>
#include <ofono/oemraw.h>
#include <ofono/phonebook.h>
#include <ofono/radio-settings.h>
#include <ofono/sim.h>
#include <ofono/sms.h>
#include <ofono/stk.h>
#include <ofono/ussd.h>
#include <ofono/voicecall.h>
#include <grilio_queue.h>
#include <grilio_request.h>
#include <grilio_parser.h>
#define RILMODEM_DRIVER "ril"
typedef struct ril_slot_info const *ril_slot_info_ptr;
struct ril_slot_config {
guint slot;
gboolean enable_4g;
const char *default_name;
};
struct ril_slot_info {
const char *path;
const char *imei;
gboolean enabled;
gboolean sim_present;
const struct ril_slot_config *config;
};
struct ril_plugin {
const char *default_voice_imsi;
const char *default_data_imsi;
const char *default_voice_path;
const char *default_data_path;
const ril_slot_info_ptr *slots;
};
struct ril_modem {
GRilIoChannel *io;
const char *imei;
struct ofono_modem *ofono;
struct ril_radio *radio;
struct ril_data *data;
struct ril_network *network;
struct ril_sim_card *sim_card;
struct ril_slot_config config;
};
#define RIL_PLUGIN_SIGNAL_VOICE_IMSI (0x01)
#define RIL_PLUGIN_SIGNAL_DATA_IMSI (0x02)
#define RIL_PLUGIN_SIGNAL_VOICE_PATH (0x04)
#define RIL_PLUGIN_SIGNAL_DATA_PATH (0x10)
#define RIL_PLUGIN_SIGNAL_ENABLED_SLOTS (0x20)
typedef void (*ril_modem_cb_t)(struct ril_modem *modem, void *data);
void ril_plugin_set_enabled_slots(struct ril_plugin *plugin, char **slots);
void ril_plugin_set_default_voice_imsi(struct ril_plugin *plugin,
const char *imsi);
void ril_plugin_set_default_data_imsi(struct ril_plugin *plugin,
const char *imsi);
struct ril_sim_dbus *ril_sim_dbus_new(struct ril_modem *modem);
const char *ril_sim_dbus_imsi(struct ril_sim_dbus *dbus);
void ril_sim_dbus_free(struct ril_sim_dbus *dbus);
struct ril_plugin_dbus *ril_plugin_dbus_new(struct ril_plugin *plugin);
void ril_plugin_dbus_free(struct ril_plugin_dbus *dbus);
void ril_plugin_dbus_block_imei_requests(struct ril_plugin_dbus *dbus,
gboolean clock);
void ril_plugin_dbus_signal(struct ril_plugin_dbus *dbus, int mask);
void ril_plugin_dbus_signal_sim(struct ril_plugin_dbus *dbus, int index,
gboolean present);
struct ril_modem *ril_modem_create(GRilIoChannel *io,
const struct ril_slot_info *slot, struct ril_radio *radio,
struct ril_network *network, struct ril_sim_card *card,
struct ril_data *data);
void ril_modem_delete(struct ril_modem *modem);
void ril_modem_set_imei(struct ril_modem *modem, const char *imei);
struct ofono_sim *ril_modem_ofono_sim(struct ril_modem *modem);
struct ofono_gprs *ril_modem_ofono_gprs(struct ril_modem *modem);
struct ofono_netreg *ril_modem_ofono_netreg(struct ril_modem *modem);
void ril_modem_set_removed_cb(struct ril_modem *modem, ril_modem_cb_t cb,
void *data);
#define ril_modem_get_path(modem) ofono_modem_get_path((modem)->ofono)
#define ril_modem_4g_enabled(modem) ((modem)->config.enable_4g)
#define ril_modem_slot(modem) ((modem)->config.slot)
#define ril_modem_io(modem) ((modem)->io)
void ril_sim_read_file_linear(struct ofono_sim *sim, int fileid,
int record, int length, const unsigned char *path,
unsigned int path_len, ofono_sim_read_cb_t cb, void *data);
void ril_sim_read_file_cyclic(struct ofono_sim *sim, int fileid,
int record, int length, const unsigned char *path,
unsigned int path_len, ofono_sim_read_cb_t cb, void *data);
void ril_sim_read_file_transparent(struct ofono_sim *sim, int fileid,
int start, int length, const unsigned char *path,
unsigned int path_len, ofono_sim_read_cb_t cb, void *data);
void ril_sim_read_file_info(struct ofono_sim *sim, int fileid,
const unsigned char *path, unsigned int path_len,
ofono_sim_file_info_cb_t cb, void *data);
int ril_sim_app_type(struct ofono_sim *sim);
int ril_netreg_check_if_really_roaming(struct ofono_netreg *netreg, gint status);
extern const struct ofono_call_barring_driver ril_call_barring_driver;
extern const struct ofono_call_forwarding_driver ril_call_forwarding_driver;
extern const struct ofono_call_settings_driver ril_call_settings_driver;
extern const struct ofono_call_volume_driver ril_call_volume_driver;
extern const struct ofono_cbs_driver ril_cbs_driver;
extern const struct ofono_devinfo_driver ril_devinfo_driver;
extern const struct ofono_gprs_context_driver ril_gprs_context_driver;
extern const struct ofono_gprs_driver ril_gprs_driver;
extern const struct ofono_modem_driver ril_modem_driver;
extern const struct ofono_netreg_driver ril_netreg_driver;
extern /* const */ struct ofono_oem_raw_driver ril_oem_raw_driver;
extern const struct ofono_phonebook_driver ril_phonebook_driver;
extern const struct ofono_radio_settings_driver ril_radio_settings_driver;
extern const struct ofono_sim_driver ril_sim_driver;
extern const struct ofono_sms_driver ril_sms_driver;
extern const struct ofono_stk_driver ril_stk_driver;
extern const struct ofono_ussd_driver ril_ussd_driver;
extern const struct ofono_voicecall_driver ril_voicecall_driver;
#endif /* RIL_PLUGIN_H */
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,644 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include <ofono/log.h>
#include <ofono/dbus.h>
#include <gutil_strv.h>
#include <gutil_log.h>
#include <gdbus.h>
#include "ofono.h"
typedef void (*ril_plugin_dbus_append_fn)(DBusMessageIter *it,
struct ril_plugin_dbus *dbus);
typedef gboolean (*ril_plugin_dbus_slot_select_fn)
(const struct ril_slot_info *slot);
typedef const char *(*ril_plugin_dbus_slot_string_fn)
(const struct ril_slot_info *slot);
struct ril_plugin_dbus_request {
DBusMessage *msg;
ril_plugin_dbus_append_fn fn;
};
struct ril_plugin_dbus {
struct ril_plugin *plugin;
DBusConnection *conn;
gboolean block_imei_req;
GSList *blocked_imei_req;
};
#define RIL_DBUS_PATH "/"
#define RIL_DBUS_INTERFACE "org.nemomobile.ofono.ModemManager"
#define RIL_DBUS_INTERFACE_VERSION (3)
#define RIL_DBUS_ENABLED_MODEMS_CHANGED_SIGNAL "EnabledModemsChanged"
#define RIL_DBUS_PRESENT_SIMS_CHANGED_SIGNAL "PresentSimsChanged"
#define RIL_DBUS_DEFAULT_VOICE_SIM_CHANGED_SIGNAL "DefaultVoiceSimChanged"
#define RIL_DBUS_DEFAULT_DATA_SIM_CHANGED_SIGNAL "DefaultDataSimChanged"
#define RIL_DBUS_DEFAULT_VOICE_MODEM_CHANGED_SIGNAL "DefaultVoiceModemChanged"
#define RIL_DBUS_DEFAULT_DATA_MODEM_CHANGED_SIGNAL "DefaultDataModemChanged"
#define RIL_DBUS_IMSI_AUTO "auto"
static gboolean ril_plugin_dbus_enabled(const struct ril_slot_info *slot)
{
return slot->enabled;
}
static gboolean ril_plugin_dbus_present(const struct ril_slot_info *slot)
{
return slot->sim_present;
}
static const char *ril_plugin_dbus_imei(const struct ril_slot_info *slot)
{
return slot->imei;
}
static void ril_plugin_dbus_append_path_array(DBusMessageIter *it,
struct ril_plugin_dbus *dbus, ril_plugin_dbus_slot_select_fn selector)
{
DBusMessageIter array;
const struct ril_slot_info *const *ptr = dbus->plugin->slots;
dbus_message_iter_open_container(it, DBUS_TYPE_ARRAY,
DBUS_TYPE_OBJECT_PATH_AS_STRING, &array);
while (*ptr) {
const struct ril_slot_info *slot = *ptr++;
if (!selector || selector(slot)) {
const char *path = slot->path;
dbus_message_iter_append_basic(&array,
DBUS_TYPE_OBJECT_PATH, &path);
}
}
dbus_message_iter_close_container(it, &array);
}
static void ril_plugin_dbus_append_string_array(DBusMessageIter *it,
struct ril_plugin_dbus *dbus, ril_plugin_dbus_slot_string_fn fn)
{
DBusMessageIter array;
const struct ril_slot_info *const *ptr = dbus->plugin->slots;
dbus_message_iter_open_container(it, DBUS_TYPE_ARRAY,
DBUS_TYPE_STRING_AS_STRING, &array);
while (*ptr) {
const struct ril_slot_info *slot = *ptr++;
const char *str = fn(slot);
if (!str) str = "";
dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING, &str);
}
dbus_message_iter_close_container(it, &array);
}
static void ril_plugin_dbus_append_boolean_array(DBusMessageIter *it,
struct ril_plugin_dbus *dbus, ril_plugin_dbus_slot_select_fn value)
{
DBusMessageIter array;
const struct ril_slot_info *const *ptr = dbus->plugin->slots;
dbus_message_iter_open_container(it, DBUS_TYPE_ARRAY,
DBUS_TYPE_BOOLEAN_AS_STRING, &array);
while (*ptr) {
const struct ril_slot_info *slot = *ptr++;
dbus_bool_t b = value(slot);
dbus_message_iter_append_basic(&array, DBUS_TYPE_BOOLEAN, &b);
}
dbus_message_iter_close_container(it, &array);
}
static void ril_plugin_dbus_append_imsi(DBusMessageIter *it, const char *imsi)
{
if (!imsi) imsi = RIL_DBUS_IMSI_AUTO;
dbus_message_iter_append_basic(it, DBUS_TYPE_STRING, &imsi);
}
static void ril_plugin_dbus_append_path(DBusMessageIter *it, const char *path)
{
if (!path) path = "";
/* It's DBUS_TYPE_STRING because DBUS_TYPE_OBJECT_PATH can't be empty */
dbus_message_iter_append_basic(it, DBUS_TYPE_STRING, &path);
}
static void ril_plugin_dbus_message_append_path_array(DBusMessage *msg,
struct ril_plugin_dbus *dbus, ril_plugin_dbus_slot_select_fn fn)
{
DBusMessageIter iter;
dbus_message_iter_init_append(msg, &iter);
ril_plugin_dbus_append_path_array(&iter, dbus, fn);
}
static void ril_plugin_dbus_signal_path_array(struct ril_plugin_dbus *dbus,
const char *name, ril_plugin_dbus_slot_select_fn fn)
{
DBusMessage *signal = dbus_message_new_signal(RIL_DBUS_PATH,
RIL_DBUS_INTERFACE, name);
ril_plugin_dbus_message_append_path_array(signal, dbus, fn);
g_dbus_send_message(dbus->conn, signal);
}
static inline void ril_plugin_dbus_signal_imsi(struct ril_plugin_dbus *dbus,
const char *name, const char *imsi)
{
if (!imsi) imsi = RIL_DBUS_IMSI_AUTO;
g_dbus_emit_signal(dbus->conn, RIL_DBUS_PATH, RIL_DBUS_INTERFACE,
name, DBUS_TYPE_STRING, &imsi, DBUS_TYPE_INVALID);
}
static inline void ril_plugin_dbus_signal_path(struct ril_plugin_dbus *dbus,
const char *name, const char *path)
{
if (!path) path = "";
g_dbus_emit_signal(dbus->conn, RIL_DBUS_PATH, RIL_DBUS_INTERFACE,
name, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID);
}
void ril_plugin_dbus_signal(struct ril_plugin_dbus *dbus, int mask)
{
if (dbus) {
if (mask & RIL_PLUGIN_SIGNAL_VOICE_IMSI) {
ril_plugin_dbus_signal_imsi(dbus,
RIL_DBUS_DEFAULT_VOICE_SIM_CHANGED_SIGNAL,
dbus->plugin->default_voice_imsi);
}
if (mask & RIL_PLUGIN_SIGNAL_DATA_IMSI) {
ril_plugin_dbus_signal_imsi(dbus,
RIL_DBUS_DEFAULT_DATA_SIM_CHANGED_SIGNAL,
dbus->plugin->default_data_imsi);
}
if (mask & RIL_PLUGIN_SIGNAL_ENABLED_SLOTS) {
ril_plugin_dbus_signal_path_array(dbus,
RIL_DBUS_ENABLED_MODEMS_CHANGED_SIGNAL,
ril_plugin_dbus_enabled);
}
if (mask & RIL_PLUGIN_SIGNAL_VOICE_PATH) {
ril_plugin_dbus_signal_path(dbus,
RIL_DBUS_DEFAULT_VOICE_MODEM_CHANGED_SIGNAL,
dbus->plugin->default_voice_path);
}
if (mask & RIL_PLUGIN_SIGNAL_DATA_PATH) {
ril_plugin_dbus_signal_path(dbus,
RIL_DBUS_DEFAULT_DATA_MODEM_CHANGED_SIGNAL,
dbus->plugin->default_data_path);
}
}
}
void ril_plugin_dbus_signal_sim(struct ril_plugin_dbus *dbus, int index,
gboolean present)
{
dbus_bool_t value = present;
g_dbus_emit_signal(dbus->conn, RIL_DBUS_PATH, RIL_DBUS_INTERFACE,
RIL_DBUS_PRESENT_SIMS_CHANGED_SIGNAL,
DBUS_TYPE_INT32, &index,
DBUS_TYPE_BOOLEAN, &value,
DBUS_TYPE_INVALID);
}
static DBusMessage *ril_plugin_dbus_reply_with_path_array(DBusMessage *msg,
struct ril_plugin_dbus *dbus, ril_plugin_dbus_slot_select_fn fn)
{
DBusMessage *reply = dbus_message_new_method_return(msg);
ril_plugin_dbus_message_append_path_array(reply, dbus, fn);
return reply;
}
static DBusMessage *ril_plugin_dbus_reply(DBusMessage *msg,
struct ril_plugin_dbus *dbus, ril_plugin_dbus_append_fn append)
{
DBusMessage *reply = dbus_message_new_method_return(msg);
DBusMessageIter iter;
dbus_message_iter_init_append(reply, &iter);
append(&iter, dbus);
return reply;
}
static void ril_plugin_dbus_unblock_request(gpointer data, gpointer user_data)
{
struct ril_plugin_dbus_request *req = data;
DBG("unblocking IMEI request %p", req);
__ofono_dbus_pending_reply(&req->msg, ril_plugin_dbus_reply(req->msg,
(struct ril_plugin_dbus *)user_data, req->fn));
g_free(req);
}
static void ril_plugin_dbus_cancel_request(gpointer data)
{
struct ril_plugin_dbus_request *req = data;
DBG("canceling IMEI request %p", req);
__ofono_dbus_pending_reply(&req->msg, __ofono_error_canceled(req->msg));
g_free(req);
}
void ril_plugin_dbus_block_imei_requests(struct ril_plugin_dbus *dbus,
gboolean block)
{
dbus->block_imei_req = block;
if (!block && dbus->blocked_imei_req) {
g_slist_foreach(dbus->blocked_imei_req,
ril_plugin_dbus_unblock_request, dbus);
g_slist_free(dbus->blocked_imei_req);
dbus->blocked_imei_req = NULL;
}
}
static DBusMessage *ril_plugin_dbus_imei_reply(DBusMessage *msg,
struct ril_plugin_dbus *dbus, ril_plugin_dbus_append_fn fn)
{
if (dbus->block_imei_req) {
struct ril_plugin_dbus_request *req =
g_new(struct ril_plugin_dbus_request, 1);
req->msg = dbus_message_ref(msg);
req->fn = fn;
dbus->blocked_imei_req = g_slist_append(dbus->blocked_imei_req,
req);
DBG("blocking IMEI request %p", req);
return NULL;
} else {
return ril_plugin_dbus_reply(msg, dbus, fn);
}
}
static void ril_plugin_dbus_append_version(DBusMessageIter *it,
struct ril_plugin_dbus *dbus)
{
dbus_int32_t version = RIL_DBUS_INTERFACE_VERSION;
dbus_message_iter_append_basic(it, DBUS_TYPE_INT32, &version);
}
static void ril_plugin_dbus_append_all(DBusMessageIter *it,
struct ril_plugin_dbus *dbus)
{
ril_plugin_dbus_append_version(it, dbus);
ril_plugin_dbus_append_path_array(it, dbus, NULL);
ril_plugin_dbus_append_path_array(it, dbus, ril_plugin_dbus_enabled);
ril_plugin_dbus_append_imsi(it, dbus->plugin->default_data_imsi);
ril_plugin_dbus_append_imsi(it, dbus->plugin->default_voice_imsi);
ril_plugin_dbus_append_path(it, dbus->plugin->default_data_path);
ril_plugin_dbus_append_path(it, dbus->plugin->default_voice_path);
}
static void ril_plugin_dbus_append_all2(DBusMessageIter *it,
struct ril_plugin_dbus *dbus)
{
ril_plugin_dbus_append_all(it, dbus);
ril_plugin_dbus_append_boolean_array(it, dbus, ril_plugin_dbus_present);
}
static void ril_plugin_dbus_append_all3(DBusMessageIter *it,
struct ril_plugin_dbus *dbus)
{
ril_plugin_dbus_append_all2(it, dbus);
ril_plugin_dbus_append_string_array(it, dbus, ril_plugin_dbus_imei);
}
static DBusMessage *ril_plugin_dbus_get_all(DBusConnection *conn,
DBusMessage *msg, void *data)
{
return ril_plugin_dbus_reply(msg, (struct ril_plugin_dbus *)data,
ril_plugin_dbus_append_all);
}
static DBusMessage *ril_plugin_dbus_get_all2(DBusConnection *conn,
DBusMessage *msg, void *data)
{
return ril_plugin_dbus_reply(msg, (struct ril_plugin_dbus *)data,
ril_plugin_dbus_append_all2);
}
static DBusMessage *ril_plugin_dbus_get_all3(DBusConnection *conn,
DBusMessage *msg, void *data)
{
return ril_plugin_dbus_imei_reply(msg, (struct ril_plugin_dbus *)data,
ril_plugin_dbus_append_all3);
}
static DBusMessage *ril_plugin_dbus_get_interface_version(DBusConnection *conn,
DBusMessage *msg, void *data)
{
return ril_plugin_dbus_reply(msg, (struct ril_plugin_dbus *)data,
ril_plugin_dbus_append_version);
}
static DBusMessage *ril_plugin_dbus_get_available_modems(DBusConnection *conn,
DBusMessage *msg, void *data)
{
return ril_plugin_dbus_reply_with_path_array(msg,
(struct ril_plugin_dbus *)data, NULL);
}
static DBusMessage *ril_plugin_dbus_get_enabled_modems(DBusConnection *conn,
DBusMessage *msg, void *data)
{
return ril_plugin_dbus_reply_with_path_array(msg,
(struct ril_plugin_dbus *)data, ril_plugin_dbus_enabled);
}
static void ril_plugin_dbus_append_present_sims(DBusMessageIter *it,
struct ril_plugin_dbus *dbus)
{
ril_plugin_dbus_append_boolean_array(it, dbus, ril_plugin_dbus_present);
}
static DBusMessage *ril_plugin_dbus_get_present_sims(DBusConnection *conn,
DBusMessage *msg, void *data)
{
return ril_plugin_dbus_reply(msg, (struct ril_plugin_dbus *)data,
ril_plugin_dbus_append_present_sims);
}
static void ril_plugin_dbus_append_imei_array(DBusMessageIter *it,
struct ril_plugin_dbus *dbus)
{
ril_plugin_dbus_append_string_array(it, dbus, ril_plugin_dbus_imei);
}
static DBusMessage *ril_plugin_dbus_get_imei(DBusConnection *conn,
DBusMessage *msg, void *data)
{
return ril_plugin_dbus_imei_reply(msg, (struct ril_plugin_dbus *)data,
ril_plugin_dbus_append_imei_array);
}
static DBusMessage *ril_plugin_dbus_reply_with_imsi(DBusMessage *msg,
const char *imsi)
{
DBusMessage *reply = dbus_message_new_method_return(msg);
DBusMessageIter iter;
dbus_message_iter_init_append(reply, &iter);
ril_plugin_dbus_append_imsi(&iter, imsi);
return reply;
}
static DBusMessage *ril_plugin_dbus_get_default_data_sim(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ril_plugin_dbus *dbus = data;
return ril_plugin_dbus_reply_with_imsi(msg,
dbus->plugin->default_data_imsi);
}
static DBusMessage *ril_plugin_dbus_get_default_voice_sim(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ril_plugin_dbus *dbus = data;
return ril_plugin_dbus_reply_with_imsi(msg,
dbus->plugin->default_voice_imsi);
}
static DBusMessage *ril_plugin_dbus_reply_with_path(DBusMessage *msg,
const char *path)
{
DBusMessage *reply = dbus_message_new_method_return(msg);
DBusMessageIter iter;
dbus_message_iter_init_append(reply, &iter);
ril_plugin_dbus_append_path(&iter, path);
return reply;
}
static DBusMessage *ril_plugin_dbus_get_default_data_modem(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ril_plugin_dbus *dbus = data;
return ril_plugin_dbus_reply_with_path(msg,
dbus->plugin->default_data_path);
}
static DBusMessage *ril_plugin_dbus_get_default_voice_modem(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ril_plugin_dbus *dbus = data;
return ril_plugin_dbus_reply_with_path(msg,
dbus->plugin->default_voice_path);
}
static DBusMessage *ril_plugin_dbus_set_enabled_modems(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ril_plugin_dbus *dbus = data;
DBusMessageIter iter;
dbus_message_iter_init(msg, &iter);
if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_ARRAY) {
char **paths = NULL;
DBusMessageIter array;
dbus_message_iter_recurse(&iter, &array);
while (dbus_message_iter_get_arg_type(&array) ==
DBUS_TYPE_OBJECT_PATH) {
DBusBasicValue value;
dbus_message_iter_get_basic(&array, &value);
paths = gutil_strv_add(paths, value.str);
dbus_message_iter_next(&array);
}
ril_plugin_set_enabled_slots(dbus->plugin, paths);
g_strfreev(paths);
return dbus_message_new_method_return(msg);
} else {
return __ofono_error_invalid_args(msg);
}
}
static DBusMessage *ril_plugin_dbus_set_imsi(struct ril_plugin_dbus *dbus,
DBusMessage *msg, void (*apply)(struct ril_plugin *plugin,
const char *imsi))
{
DBusMessageIter iter;
dbus_message_iter_init(msg, &iter);
if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) {
DBusBasicValue value;
const char *imsi;
dbus_message_iter_get_basic(&iter, &value);
imsi = value.str;
if (!g_strcmp0(imsi, RIL_DBUS_IMSI_AUTO)) imsi = NULL;
apply(dbus->plugin, imsi);
return dbus_message_new_method_return(msg);
} else {
return __ofono_error_invalid_args(msg);
}
}
static DBusMessage *ril_plugin_dbus_set_default_voice_sim(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ril_plugin_dbus *dbus = data;
GASSERT(conn == dbus->conn);
return ril_plugin_dbus_set_imsi(dbus, msg,
ril_plugin_set_default_voice_imsi);
}
static DBusMessage *ril_plugin_dbus_set_default_data_sim(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ril_plugin_dbus *dbus = data;
GASSERT(conn == dbus->conn);
return ril_plugin_dbus_set_imsi(dbus, msg,
ril_plugin_set_default_data_imsi);
}
static const GDBusMethodTable ril_plugin_dbus_methods[] = {
{ GDBUS_METHOD("GetAll", NULL,
GDBUS_ARGS({"version", "i" },
{"availableModems", "ao" },
{"enabledModems", "ao" },
{"defaultDataSim", "s" },
{"defaultVoiceSim", "s" },
{"defaultDataModem", "s" },
{"defaultVoiceModem" , "s"}),
ril_plugin_dbus_get_all) },
{ GDBUS_METHOD("GetAll2", NULL,
GDBUS_ARGS({"version", "i" },
{"availableModems", "ao" },
{"enabledModems", "ao" },
{"defaultDataSim", "s" },
{"defaultVoiceSim", "s" },
{"defaultDataModem", "s" },
{"defaultVoiceModem" , "s"},
{"presentSims" , "ab"}),
ril_plugin_dbus_get_all2) },
{ GDBUS_ASYNC_METHOD("GetAll3", NULL,
GDBUS_ARGS({"version", "i" },
{"availableModems", "ao" },
{"enabledModems", "ao" },
{"defaultDataSim", "s" },
{"defaultVoiceSim", "s" },
{"defaultDataModem", "s" },
{"defaultVoiceModem" , "s"},
{"presentSims" , "ab"},
{"imei" , "as"}),
ril_plugin_dbus_get_all3) },
{ GDBUS_METHOD("GetInterfaceVersion",
NULL, GDBUS_ARGS({ "version", "i" }),
ril_plugin_dbus_get_interface_version) },
{ GDBUS_METHOD("GetAvailableModems",
NULL, GDBUS_ARGS({ "modems", "ao" }),
ril_plugin_dbus_get_available_modems) },
{ GDBUS_METHOD("GetEnabledModems",
NULL, GDBUS_ARGS({ "modems", "ao" }),
ril_plugin_dbus_get_enabled_modems) },
{ GDBUS_METHOD("GetPresentSims",
NULL, GDBUS_ARGS({ "presentSims", "ab" }),
ril_plugin_dbus_get_present_sims) },
{ GDBUS_ASYNC_METHOD("GetIMEI",
NULL, GDBUS_ARGS({ "imei", "as" }),
ril_plugin_dbus_get_imei) },
{ GDBUS_METHOD("GetDefaultDataSim",
NULL, GDBUS_ARGS({ "imsi", "s" }),
ril_plugin_dbus_get_default_data_sim) },
{ GDBUS_METHOD("GetDefaultVoiceSim",
NULL, GDBUS_ARGS({ "imsi", "s" }),
ril_plugin_dbus_get_default_voice_sim) },
{ GDBUS_METHOD("GetDefaultDataModem",
NULL, GDBUS_ARGS({ "path", "s" }),
ril_plugin_dbus_get_default_data_modem) },
{ GDBUS_METHOD("GetDefaultVoiceModem",
NULL, GDBUS_ARGS({ "path", "s" }),
ril_plugin_dbus_get_default_voice_modem) },
{ GDBUS_METHOD("SetEnabledModems",
GDBUS_ARGS({ "modems", "ao" }), NULL,
ril_plugin_dbus_set_enabled_modems) },
{ GDBUS_METHOD("SetDefaultDataSim",
GDBUS_ARGS({ "imsi", "s" }), NULL,
ril_plugin_dbus_set_default_data_sim) },
{ GDBUS_METHOD("SetDefaultVoiceSim",
GDBUS_ARGS({ "imsi", "s" }), NULL,
ril_plugin_dbus_set_default_voice_sim) },
{ }
};
static const GDBusSignalTable ril_plugin_dbus_signals[] = {
{ GDBUS_SIGNAL(RIL_DBUS_ENABLED_MODEMS_CHANGED_SIGNAL,
GDBUS_ARGS({ "modems", "ao" })) },
{ GDBUS_SIGNAL(RIL_DBUS_PRESENT_SIMS_CHANGED_SIGNAL,
GDBUS_ARGS({"index", "i" },
{"present" , "b"})) },
{ GDBUS_SIGNAL(RIL_DBUS_DEFAULT_DATA_SIM_CHANGED_SIGNAL,
GDBUS_ARGS({ "imsi", "s" })) },
{ GDBUS_SIGNAL(RIL_DBUS_DEFAULT_VOICE_SIM_CHANGED_SIGNAL,
GDBUS_ARGS({ "imsi", "s" })) },
{ GDBUS_SIGNAL(RIL_DBUS_DEFAULT_DATA_MODEM_CHANGED_SIGNAL,
GDBUS_ARGS({ "path", "s" })) },
{ GDBUS_SIGNAL(RIL_DBUS_DEFAULT_VOICE_MODEM_CHANGED_SIGNAL,
GDBUS_ARGS({ "path", "s" })) },
{ }
};
struct ril_plugin_dbus *ril_plugin_dbus_new(struct ril_plugin *plugin)
{
struct ril_plugin_dbus *dbus = g_new0(struct ril_plugin_dbus, 1);
dbus->conn = dbus_connection_ref(ofono_dbus_get_connection());
dbus->plugin = plugin;
if (g_dbus_register_interface(dbus->conn, RIL_DBUS_PATH,
RIL_DBUS_INTERFACE, ril_plugin_dbus_methods,
ril_plugin_dbus_signals, NULL, dbus, NULL)) {
return dbus;
} else {
ofono_error("RIL D-Bus register failed");
ril_plugin_dbus_free(dbus);
return NULL;
}
}
void ril_plugin_dbus_free(struct ril_plugin_dbus *dbus)
{
if (dbus) {
g_slist_free_full(dbus->blocked_imei_req,
ril_plugin_dbus_cancel_request);
g_dbus_unregister_interface(dbus->conn, RIL_DBUS_PATH,
RIL_DBUS_INTERFACE);
dbus_connection_unref(dbus->conn);
g_free(dbus);
}
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,405 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_radio.h"
#include "ril_util.h"
#include "ril_log.h"
#include <grilio_queue.h>
#include <grilio_request.h>
#include <grilio_parser.h>
typedef GObjectClass RilRadioClass;
typedef struct ril_radio RilRadio;
/*
* Object states:
*
* 1. Idle (!pending && !retry)
* 2. Power on/off request pending (pending)
* 3. Power on retry has been scheduled (retry)
*/
struct ril_radio_priv {
GRilIoChannel *io;
GRilIoQueue *q;
gulong state_event_id;
char *log_prefix;
GHashTable *req_table;
guint pending_id;
guint retry_id;
guint state_changed_while_request_pending;
enum ril_radio_state last_known_state;
gboolean power_cycle;
gboolean next_state_valid;
gboolean next_state;
};
enum ril_radio_signal {
SIGNAL_STATE_CHANGED,
SIGNAL_COUNT
};
#define POWER_RETRY_SECS (1)
#define SIGNAL_STATE_CHANGED_NAME "ril-radio-state-changed"
static guint ril_radio_signals[SIGNAL_COUNT] = { 0 };
G_DEFINE_TYPE(RilRadio, ril_radio, G_TYPE_OBJECT)
#define RIL_RADIO_TYPE (ril_radio_get_type())
#define RIL_RADIO(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj,RIL_RADIO_TYPE,RilRadio))
static void ril_radio_submit_power_request(struct ril_radio *self, gboolean on);
G_INLINE_FUNC gboolean ril_radio_power_should_be_on(struct ril_radio *self)
{
struct ril_radio_priv *priv = self->priv;
return g_hash_table_size(priv->req_table) && !priv->power_cycle;
}
G_INLINE_FUNC gboolean ril_radio_state_off(enum ril_radio_state radio_state)
{
return radio_state == RADIO_STATE_OFF;
}
G_INLINE_FUNC gboolean ril_radio_state_on(enum ril_radio_state radio_state)
{
return !ril_radio_state_off(radio_state);
}
static gboolean ril_radio_power_request_retry_cb(gpointer user_data)
{
struct ril_radio *self = user_data;
struct ril_radio_priv *priv = self->priv;
DBG("%s", priv->log_prefix);
GASSERT(priv->retry_id);
priv->retry_id = 0;
ril_radio_submit_power_request(self, ril_radio_power_should_be_on(self));
return FALSE;
}
static void ril_radio_cancel_retry(struct ril_radio *self)
{
struct ril_radio_priv *priv = self->priv;
if (priv->retry_id) {
DBG("%sretry cancelled", priv->log_prefix);
g_source_remove(priv->retry_id);
priv->retry_id = 0;
}
}
static void ril_radio_check_state(struct ril_radio *self)
{
struct ril_radio_priv *priv = self->priv;
if (!priv->pending_id) {
const gboolean should_be_on = ril_radio_power_should_be_on(self);
if (ril_radio_state_on(self->priv->last_known_state) ==
should_be_on) {
/* All is good, cancel pending retry if there is one */
ril_radio_cancel_retry(self);
} else if (priv->state_changed_while_request_pending) {
/* Hmm... RIL's reaction was inadequate, repeat */
ril_radio_submit_power_request(self, should_be_on);
} else if (!priv->retry_id) {
/* There has been no reaction so far, wait a bit */
DBG("%sretry scheduled", priv->log_prefix);
priv->retry_id = g_timeout_add_seconds(POWER_RETRY_SECS,
ril_radio_power_request_retry_cb, self);
}
}
/* Don't update public state while something is pending */
if (!priv->pending_id && !priv->retry_id &&
self->state != priv->last_known_state) {
DBG("%s%s -> %s", priv->log_prefix,
ril_radio_state_to_string(self->state),
ril_radio_state_to_string(priv->last_known_state));
self->state = priv->last_known_state;
g_signal_emit(self, ril_radio_signals[SIGNAL_STATE_CHANGED], 0);
}
}
static void ril_radio_power_request_cb(GRilIoChannel *channel, int ril_status,
const void *data, guint len, void *user_data)
{
struct ril_radio *self = user_data;
struct ril_radio_priv *priv = self->priv;
GASSERT(priv->pending_id);
priv->pending_id = 0;
if (ril_status != RIL_E_SUCCESS) {
ofono_error("Power request failed: %s",
ril_error_to_string(ril_status));
}
if (priv->next_state_valid) {
ril_radio_submit_power_request(self, priv->next_state);
} else {
ril_radio_check_state(self);
}
}
static void ril_radio_submit_power_request(struct ril_radio *self, gboolean on)
{
struct ril_radio_priv *priv = self->priv;
GRilIoRequest *req = grilio_request_sized_new(8);
grilio_request_append_int32(req, 1);
grilio_request_append_int32(req, on); /* Radio ON=1, OFF=0 */
priv->next_state_valid = FALSE;
priv->next_state = on;
priv->state_changed_while_request_pending = 0;
ril_radio_cancel_retry(self);
GASSERT(!priv->pending_id);
priv->pending_id = grilio_queue_send_request_full(priv->q, req,
RIL_REQUEST_RADIO_POWER, ril_radio_power_request_cb, NULL, self);
grilio_request_unref(req);
}
static void ril_radio_power_request(struct ril_radio *self, gboolean on,
gboolean allow_repeat)
{
struct ril_radio_priv *priv = self->priv;
const char *on_off = on ? "on" : "off";
if (priv->pending_id) {
if (allow_repeat || priv->next_state != on) {
/* Wait for the pending request to complete */
priv->next_state_valid = TRUE;
priv->next_state = on;
DBG("%s%s (queued)", priv->log_prefix, on_off);
} else {
DBG("%s%s (ignored)", priv->log_prefix, on_off);
}
} else {
DBG("%s%s", priv->log_prefix, on_off);
ril_radio_submit_power_request(self, on);
}
}
void ril_radio_confirm_power_on(struct ril_radio *self)
{
if (G_LIKELY(self) && ril_radio_power_should_be_on(self)) {
ril_radio_power_request(self, TRUE, TRUE);
}
}
void ril_radio_power_cycle(struct ril_radio *self)
{
if (G_LIKELY(self)) {
struct ril_radio_priv *priv = self->priv;
if (ril_radio_state_off(priv->last_known_state)) {
DBG("%spower is already off", priv->log_prefix);
GASSERT(!priv->power_cycle);
} else if (priv->power_cycle) {
DBG("%salready in progress", priv->log_prefix);
} else {
DBG("%sinitiated", priv->log_prefix);
priv->power_cycle = TRUE;
if (!priv->pending_id) {
ril_radio_submit_power_request(self, FALSE);
}
}
}
}
void ril_radio_power_on(struct ril_radio *self, gpointer tag)
{
if (G_LIKELY(self)) {
struct ril_radio_priv *priv = self->priv;
const gboolean was_on = ril_radio_power_should_be_on(self);
DBG("%s%p", priv->log_prefix, tag);
g_hash_table_insert(priv->req_table, tag, tag);
if (!was_on) {
ril_radio_power_request(self, TRUE, FALSE);
}
}
}
void ril_radio_power_off(struct ril_radio *self, gpointer tag)
{
if (G_LIKELY(self)) {
struct ril_radio_priv *priv = self->priv;
DBG("%s%p", priv->log_prefix, tag);
if (g_hash_table_remove(priv->req_table, tag) &&
!ril_radio_power_should_be_on(self)) {
/* The last one turns the lights off */
ril_radio_power_request(self, FALSE, FALSE);
}
}
}
gulong ril_radio_add_state_changed_handler(struct ril_radio *self,
ril_radio_cb_t cb, void *arg)
{
return (G_LIKELY(self) && G_LIKELY(cb)) ? g_signal_connect(self,
SIGNAL_STATE_CHANGED_NAME, G_CALLBACK(cb), arg) : 0;
}
void ril_radio_remove_handler(struct ril_radio *self, gulong id)
{
if (G_LIKELY(self) && G_LIKELY(id)) {
g_signal_handler_disconnect(self, id);
}
}
enum ril_radio_state ril_radio_state_parse(const void *data, guint len)
{
GRilIoParser rilp;
int radio_state;
grilio_parser_init(&rilp, data, len);
if (grilio_parser_get_int32(&rilp, &radio_state)) {
return radio_state;
} else {
ofono_error("Error parsing radio state");
return RADIO_STATE_UNAVAILABLE;
}
}
static void ril_radio_state_changed(GRilIoChannel *io, guint code,
const void *data, guint len, void *user_data)
{
struct ril_radio *self = user_data;
enum ril_radio_state radio_state = ril_radio_state_parse(data, len);
GASSERT(code == RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED);
if (radio_state != RADIO_STATE_UNAVAILABLE) {
struct ril_radio_priv *priv = self->priv;
DBG("%s%s", priv->log_prefix,
ril_radio_state_to_string(radio_state));
GASSERT(!priv->pending_id || !priv->retry_id);
if (priv->power_cycle && ril_radio_state_off(radio_state)) {
DBG("%sswitched off for power cycle", priv->log_prefix);
priv->power_cycle = FALSE;
}
if (priv->pending_id) {
priv->state_changed_while_request_pending++;
}
priv->last_known_state = radio_state;
ril_radio_check_state(self);
}
}
struct ril_radio *ril_radio_new(GRilIoChannel *io)
{
struct ril_radio *self = g_object_new(RIL_RADIO_TYPE, NULL);
struct ril_radio_priv *priv = self->priv;
priv->io = grilio_channel_ref(io);
priv->q = grilio_queue_new(priv->io);
priv->log_prefix =
(io && io->name && io->name[0] && strcmp(io->name, "RIL")) ?
g_strconcat(io->name, " ", NULL) : g_strdup("");
DBG("%s", priv->log_prefix);
priv->state_event_id = grilio_channel_add_unsol_event_handler(priv->io,
ril_radio_state_changed,
RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, self);
return self;
}
struct ril_radio *ril_radio_ref(struct ril_radio *self)
{
if (G_LIKELY(self)) {
g_object_ref(RIL_RADIO(self));
return self;
} else {
return NULL;
}
}
void ril_radio_unref(struct ril_radio *self)
{
if (G_LIKELY(self)) {
g_object_unref(RIL_RADIO(self));
}
}
static void ril_radio_init(struct ril_radio *self)
{
struct ril_radio_priv *priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
RIL_RADIO_TYPE, struct ril_radio_priv);
self->priv = priv;
priv->req_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
NULL, NULL);
}
static void ril_radio_dispose(GObject *object)
{
struct ril_radio *self = RIL_RADIO(object);
struct ril_radio_priv *priv = self->priv;
if (priv->state_event_id) {
grilio_channel_remove_handler(priv->io, priv->state_event_id);
priv->state_event_id = 0;
}
if (priv->pending_id) {
grilio_queue_cancel_request(priv->q, priv->pending_id, FALSE);
priv->pending_id = 0;
}
priv->next_state_valid = FALSE;
ril_radio_cancel_retry(self);
grilio_queue_cancel_all(priv->q, FALSE);
G_OBJECT_CLASS(ril_radio_parent_class)->dispose(object);
}
static void ril_radio_finalize(GObject *object)
{
struct ril_radio *self = RIL_RADIO(object);
struct ril_radio_priv *priv = self->priv;
DBG("%s", priv->log_prefix);
g_free(priv->log_prefix);
grilio_channel_unref(priv->io);
grilio_queue_unref(priv->q);
g_hash_table_unref(priv->req_table);
G_OBJECT_CLASS(ril_radio_parent_class)->finalize(object);
}
static void ril_radio_class_init(RilRadioClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->dispose = ril_radio_dispose;
object_class->finalize = ril_radio_finalize;
g_type_class_add_private(klass, sizeof(struct ril_radio_priv));
ril_radio_signals[SIGNAL_STATE_CHANGED] =
g_signal_new(SIGNAL_STATE_CHANGED_NAME,
G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL, G_TYPE_NONE, 0);
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,50 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef RIL_RADIO_H
#define RIL_RADIO_H
#include "ril_types.h"
struct ril_radio {
GObject object;
struct ril_radio_priv *priv;
enum ril_radio_state state;
};
typedef void (*ril_radio_cb_t)(struct ril_radio *radio, void *arg);
struct ril_radio *ril_radio_new(GRilIoChannel *io);
struct ril_radio *ril_radio_ref(struct ril_radio *radio);
void ril_radio_unref(struct ril_radio *radio);
void ril_radio_power_on(struct ril_radio *radio, gpointer tag);
void ril_radio_power_off(struct ril_radio *radio, gpointer tag);
void ril_radio_confirm_power_on(struct ril_radio *radio);
void ril_radio_power_cycle(struct ril_radio *radio);
gulong ril_radio_add_state_changed_handler(struct ril_radio *radio,
ril_radio_cb_t cb, void *arg);
void ril_radio_remove_handler(struct ril_radio *radio, gulong id);
enum ril_radio_state ril_radio_state_parse(const void *data, guint len);
#endif /* RIL_RADIO */
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,316 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_util.h"
#include "ril_log.h"
#include "ril_constants.h"
struct ril_radio_settings {
GRilIoQueue *q;
struct ofono_radio_settings *rs;
enum ofono_radio_access_mode access_mode;
gboolean enable_4g;
int ratmode;
guint query_rats_id;
};
struct ril_radio_settings_cbd {
struct ril_radio_settings *rsd;
union _ofono_radio_settings_cb {
ofono_radio_settings_rat_mode_set_cb_t rat_mode_set;
ofono_radio_settings_rat_mode_query_cb_t rat_mode_query;
ofono_radio_settings_available_rats_query_cb_t available_rats;
gpointer ptr;
} cb;
gpointer data;
};
#define ril_radio_settings_cbd_free g_free
static inline struct ril_radio_settings *ril_radio_settings_get_data(
struct ofono_radio_settings *rs)
{
return ofono_radio_settings_get_data(rs);
}
static struct ril_radio_settings_cbd *ril_radio_settings_cbd_new(
struct ril_radio_settings *rsd, void *cb, void *data)
{
struct ril_radio_settings_cbd *cbd;
cbd = g_new0(struct ril_radio_settings_cbd, 1);
cbd->rsd = rsd;
cbd->cb.ptr = cb;
cbd->data = data;
return cbd;
}
static enum ofono_radio_access_mode ril_radio_settings_pref_to_mode(int pref)
{
switch (pref) {
case PREF_NET_TYPE_LTE_CDMA_EVDO:
case PREF_NET_TYPE_LTE_GSM_WCDMA:
case PREF_NET_TYPE_LTE_CMDA_EVDO_GSM_WCDMA:
case PREF_NET_TYPE_LTE_ONLY:
case PREF_NET_TYPE_LTE_WCDMA:
return OFONO_RADIO_ACCESS_MODE_LTE;
case PREF_NET_TYPE_GSM_ONLY:
return OFONO_RADIO_ACCESS_MODE_GSM;
case PREF_NET_TYPE_GSM_WCDMA_AUTO:
case PREF_NET_TYPE_WCDMA:
case PREF_NET_TYPE_GSM_WCDMA:
return OFONO_RADIO_ACCESS_MODE_UMTS;
default:
return OFONO_RADIO_ACCESS_MODE_ANY;
}
}
static int ril_radio_settings_mode_to_pref(struct ril_radio_settings *rsd,
enum ofono_radio_access_mode mode)
{
switch (mode) {
case OFONO_RADIO_ACCESS_MODE_ANY:
case OFONO_RADIO_ACCESS_MODE_LTE:
if (rsd->enable_4g) {
return PREF_NET_TYPE_LTE_WCDMA;
}
/* no break */
case OFONO_RADIO_ACCESS_MODE_UMTS:
return PREF_NET_TYPE_GSM_WCDMA_AUTO;
case OFONO_RADIO_ACCESS_MODE_GSM:
return PREF_NET_TYPE_GSM_ONLY;
default:
return -1;
}
}
static void ril_radio_settings_submit_request(struct ril_radio_settings *rsd,
GRilIoRequest* req, guint code, GRilIoChannelResponseFunc response,
void *cb, void *data)
{
grilio_queue_send_request_full(rsd->q, req, code, response,
ril_radio_settings_cbd_free,
ril_radio_settings_cbd_new(rsd, cb, data));
}
static void ril_radio_settings_set_rat_mode_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_radio_settings_cbd *cbd = user_data;
ofono_radio_settings_rat_mode_set_cb_t cb = cbd->cb.rat_mode_set;
if (status == RIL_E_SUCCESS) {
cb(ril_error_ok(&error), cbd->data);
} else {
ofono_error("failed to set rat mode");
cb(ril_error_failure(&error), cbd->data);
}
}
static GRilIoRequest *ril_radio_settings_set_pref_req(int pref)
{
GRilIoRequest *req = grilio_request_sized_new(8);
grilio_request_append_int32(req, 1); /* Number of params */
grilio_request_append_int32(req, pref);
return req;
}
static int ril_radio_settings_parse_pref_resp(const void *data, guint len)
{
GRilIoParser rilp;
int pref = -1;
grilio_parser_init(&rilp, data, len);
grilio_parser_get_int32(&rilp, NULL);
grilio_parser_get_int32(&rilp, &pref);
return pref;
}
static void ril_radio_settings_set_rat_mode(struct ofono_radio_settings *rs,
enum ofono_radio_access_mode mode,
ofono_radio_settings_rat_mode_set_cb_t cb, void *data)
{
struct ril_radio_settings *rsd = ril_radio_settings_get_data(rs);
int pref = ril_radio_settings_mode_to_pref(rsd, mode);
GRilIoRequest *req;
if (pref < 0) pref = rsd->ratmode;
DBG("rat mode set %d (ril %d)", mode, pref);
req = ril_radio_settings_set_pref_req(pref);
ril_radio_settings_submit_request(rsd, req,
RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE,
ril_radio_settings_set_rat_mode_cb, cb, data);
grilio_request_unref(req);
}
static void ril_radio_settings_query_rat_mode_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_radio_settings_cbd *cbd = user_data;
struct ril_radio_settings *rsd = cbd->rsd;
ofono_radio_settings_rat_mode_query_cb_t cb = cbd->cb.rat_mode_query;
if (status == RIL_E_SUCCESS) {
rsd->ratmode = ril_radio_settings_parse_pref_resp(data, len);
DBG("rat mode %d (ril %d)",
ril_radio_settings_pref_to_mode(rsd->ratmode),
rsd->ratmode);
} else {
/*
* With certain versions of RIL, preferred network type
* queries don't work even though setting preferred network
* type does actually work. In this case, assume that our
* cached network type is the right one.
*/
ofono_error("rat mode query failed, assuming %d (ril %d)",
ril_radio_settings_pref_to_mode(rsd->ratmode),
rsd->ratmode);
}
cb(ril_error_ok(&error), ril_radio_settings_pref_to_mode(rsd->ratmode),
cbd->data);
}
static void ril_radio_settings_query_rat_mode(struct ofono_radio_settings *rs,
ofono_radio_settings_rat_mode_query_cb_t cb, void *data)
{
struct ril_radio_settings *rsd = ril_radio_settings_get_data(rs);
DBG("rat mode query");
ril_radio_settings_submit_request(rsd, NULL,
RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE,
ril_radio_settings_query_rat_mode_cb, cb, data);
}
static gboolean ril_radio_settings_query_available_rats_cb(gpointer data)
{
struct ofono_error error;
struct ril_radio_settings_cbd *cbd = data;
guint rats = OFONO_RADIO_ACCESS_MODE_GSM | OFONO_RADIO_ACCESS_MODE_UMTS;
if (cbd->rsd->enable_4g) {
rats |= OFONO_RADIO_ACCESS_MODE_LTE;
}
GASSERT(cbd->rsd->query_rats_id);
cbd->rsd->query_rats_id = 0;
cbd->cb.available_rats(ril_error_ok(&error), rats, cbd->data);
return FALSE;
}
static void ril_radio_settings_query_available_rats(
struct ofono_radio_settings *rs,
ofono_radio_settings_available_rats_query_cb_t cb, void *data)
{
struct ril_radio_settings *rsd = ril_radio_settings_get_data(rs);
DBG("");
GASSERT(!rsd->query_rats_id);
rsd->query_rats_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
ril_radio_settings_query_available_rats_cb,
ril_radio_settings_cbd_new(rsd, cb, data),
ril_radio_settings_cbd_free);
}
static void ril_radio_settings_init_query_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
int pref;
struct ril_radio_settings *rsd = user_data;
enum ofono_radio_access_mode mode;
if (status == RIL_E_SUCCESS) {
pref = ril_radio_settings_parse_pref_resp(data, len);
DBG("rat mode %d", pref);
} else {
ofono_error("initial rat mode query failed");
pref = ril_radio_settings_mode_to_pref(rsd,
OFONO_RADIO_ACCESS_MODE_ANY);
}
mode = ril_radio_settings_pref_to_mode(pref);
if (!rsd->enable_4g && mode == OFONO_RADIO_ACCESS_MODE_LTE) {
rsd->ratmode = ril_radio_settings_mode_to_pref(rsd,
OFONO_RADIO_ACCESS_MODE_UMTS);
} else {
rsd->ratmode = pref;
}
if (rsd->ratmode != pref || status != RIL_E_SUCCESS) {
GRilIoRequest *req;
DBG("forcing rat mode %d", rsd->ratmode);
req = ril_radio_settings_set_pref_req(rsd->ratmode);
grilio_queue_send_request(rsd->q, req,
RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE);
grilio_request_unref(req);
}
ofono_radio_settings_register(rsd->rs);
}
static int ril_radio_settings_probe(struct ofono_radio_settings *rs,
unsigned int vendor, void *data)
{
struct ril_modem *modem = data;
struct ril_radio_settings *rsd = g_new0(struct ril_radio_settings, 1);
DBG("");
rsd->rs = rs;
rsd->q = grilio_queue_new(ril_modem_io(modem));
rsd->enable_4g = ril_modem_4g_enabled(modem);
grilio_queue_send_request_full(rsd->q, NULL,
RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE,
ril_radio_settings_init_query_cb, NULL, rsd);
ofono_radio_settings_set_data(rs, rsd);
return 0;
}
static void ril_radio_settings_remove(struct ofono_radio_settings *rs)
{
struct ril_radio_settings *rsd = ril_radio_settings_get_data(rs);
DBG("");
ofono_radio_settings_set_data(rs, NULL);
if (rsd->query_rats_id > 0) {
g_source_remove(rsd->query_rats_id);
}
grilio_queue_cancel_all(rsd->q, FALSE);
grilio_queue_unref(rsd->q);
g_free(rsd);
}
const struct ofono_radio_settings_driver ril_radio_settings_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_radio_settings_probe,
.remove = ril_radio_settings_remove,
.query_rat_mode = ril_radio_settings_query_rat_mode,
.set_rat_mode = ril_radio_settings_set_rat_mode,
.query_available_rats = ril_radio_settings_query_available_rats
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

1150
ofono/drivers/ril/ril_sim.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,532 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_sim_card.h"
#include "ril_radio.h"
#include "ril_util.h"
#include "ril_log.h"
#include <grilio_queue.h>
#include <grilio_request.h>
#include <grilio_parser.h>
typedef GObjectClass RilSimCardClass;
typedef struct ril_sim_card RilSimCard;
enum ril_sim_card_event {
EVENT_SIM_STATUS_CHANGED,
EVENT_UICC_SUBSCRIPTION_STATUS_CHANGED,
EVENT_COUNT
};
struct ril_sim_card_priv {
GRilIoChannel *io;
GRilIoQueue *q;
int flags;
guint status_req_id;
gulong event_id[EVENT_COUNT];
};
enum ril_sim_card_signal {
SIGNAL_STATUS_RECEIVED,
SIGNAL_STATUS_CHANGED,
SIGNAL_STATE_CHANGED,
SIGNAL_APP_CHANGED,
SIGNAL_COUNT
};
#define SIGNAL_STATUS_RECEIVED_NAME "ril-simcard-status-received"
#define SIGNAL_STATUS_CHANGED_NAME "ril-simcard-status-changed"
#define SIGNAL_STATE_CHANGED_NAME "ril-simcard-state-changed"
#define SIGNAL_APP_CHANGED_NAME "ril-simcard-app-changed"
static guint ril_sim_card_signals[SIGNAL_COUNT] = { 0 };
G_DEFINE_TYPE(RilSimCard, ril_sim_card, G_TYPE_OBJECT)
#define RIL_SIMCARD_TYPE (ril_sim_card_get_type())
#define RIL_SIMCARD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
RIL_SIMCARD_TYPE, RilSimCard))
#define RIL_SIMCARD_STATE_CHANGED (0x01)
#define RIL_SIMCARD_STATUS_CHANGED (0x02)
static void ril_sim_card_request_status(struct ril_sim_card *self);
static gboolean ril_sim_card_app_equal(const struct ril_sim_card_app *a1,
const struct ril_sim_card_app *a2)
{
if (a1 == a2) {
return TRUE;
} else if (!a1 || !a2) {
return FALSE;
} else {
return a1->app_type == a2->app_type &&
a1->app_state == a2->app_state &&
a1->perso_substate == a2->perso_substate &&
a1->pin_replaced == a2->pin_replaced &&
a1->pin1_state == a2->pin1_state &&
a1->pin2_state == a2->pin2_state &&
!g_strcmp0(a1->aid, a2->aid) &&
!g_strcmp0(a1->label, a2->label);
}
}
static int ril_sim_card_status_compare(const struct ril_sim_card_status *s1,
const struct ril_sim_card_status *s2)
{
if (s1 == s2) {
return 0;
} else if (!s1 || !s2) {
return RIL_SIMCARD_STATE_CHANGED | RIL_SIMCARD_STATUS_CHANGED;
} else {
int diff = 0;
if (s1->card_state != s2->card_state) {
diff |= RIL_SIMCARD_STATE_CHANGED;
}
if (s1->pin_state != s2->pin_state ||
s1->gsm_umts_index != s2->gsm_umts_index ||
s1->cdma_index != s2->cdma_index ||
s1->ims_index != s2->ims_index ||
s1->num_apps != s2->num_apps) {
diff |= RIL_SIMCARD_STATUS_CHANGED;
} else {
int i;
for (i = 0; i < s1->num_apps; i++) {
if (!ril_sim_card_app_equal(s1->apps + i,
s2->apps + i)) {
diff |= RIL_SIMCARD_STATUS_CHANGED;
break;
}
}
}
return diff;
}
}
static void ril_sim_card_status_free(struct ril_sim_card_status *status)
{
if (status) {
if (status->apps) {
int i;
for (i = 0; i < status->num_apps; i++) {
g_free(status->apps[i].aid);
g_free(status->apps[i].label);
}
g_free(status->apps);
}
g_free(status);
}
}
static void ril_sim_card_subscribe(struct ril_sim_card *self,
int app_index, int sub_status)
{
struct ril_sim_card_priv *priv = self->priv;
GRilIoRequest *req = grilio_request_sized_new(16);
const guint sub_id = self->slot;
DBG("%u,%d,%u,%d", self->slot, app_index, sub_id, sub_status);
grilio_request_append_int32(req, self->slot);
grilio_request_append_int32(req, app_index);
grilio_request_append_int32(req, sub_id);
grilio_request_append_int32(req, sub_status);
grilio_queue_send_request(priv->q, req, (priv->io->ril_version <= 9 &&
(priv->flags & RIL_SIM_CARD_V9_UICC_SUBSCRIPTION_WORKAROUND)) ?
RIL_REQUEST_V9_SET_UICC_SUBSCRIPTION :
RIL_REQUEST_SET_UICC_SUBSCRIPTION);
grilio_request_unref(req);
}
static int ril_sim_card_select_app(const struct ril_sim_card_status *status)
{
int selected_app = -1;
guint i;
for (i = 0; i < status->num_apps; i++) {
const int type = status->apps[i].app_type;
if (type == RIL_APPTYPE_USIM || type == RIL_APPTYPE_RUIM) {
selected_app = i;
break;
} else if (type != RIL_APPTYPE_UNKNOWN && selected_app == -1) {
selected_app = i;
}
}
DBG("%d", selected_app);
return selected_app;
}
static void ril_sim_card_update_app(struct ril_sim_card *self)
{
const struct ril_sim_card_app *old_app = self->app;
const struct ril_sim_card_status *status = self->status;
int app_index;
if (status->card_state == RIL_CARDSTATE_PRESENT) {
if (status->gsm_umts_index >= 0 &&
status->gsm_umts_index < status->num_apps) {
app_index = status->gsm_umts_index;
} else {
app_index = ril_sim_card_select_app(status);
if (app_index >= 0) {
ril_sim_card_subscribe(self, app_index, 1);
}
}
} else {
app_index = -1;
}
if (app_index >= 0 &&
status->apps[app_index].app_type != RIL_APPTYPE_UNKNOWN) {
self->app = status->apps + app_index;
} else {
self->app = NULL;
}
if (!ril_sim_card_app_equal(old_app, self->app)) {
g_signal_emit(self,
ril_sim_card_signals[SIGNAL_APP_CHANGED], 0);
}
}
static void ril_sim_card_update_status(struct ril_sim_card *self,
struct ril_sim_card_status *status)
{
const int diff = ril_sim_card_status_compare(self->status, status);
if (diff) {
struct ril_sim_card_status *old_status = self->status;
self->status = status;
ril_sim_card_update_app(self);
g_signal_emit(self, ril_sim_card_signals[
SIGNAL_STATUS_RECEIVED], 0);
if (diff & RIL_SIMCARD_STATUS_CHANGED) {
DBG("status changed");
g_signal_emit(self, ril_sim_card_signals[
SIGNAL_STATUS_CHANGED], 0);
}
if (diff & RIL_SIMCARD_STATE_CHANGED) {
DBG("state changed");
g_signal_emit(self, ril_sim_card_signals[
SIGNAL_STATE_CHANGED], 0);
}
ril_sim_card_status_free(old_status);
} else {
ril_sim_card_status_free(status);
g_signal_emit(self, ril_sim_card_signals[
SIGNAL_STATUS_RECEIVED], 0);
}
}
static gboolean ril_sim_card_app_parse(GRilIoParser *rilp,
struct ril_sim_card_app *app)
{
gint32 app_type, app_state, perso_substate;
gint32 pin_replaced, pin1_state, pin2_state;
grilio_parser_get_int32(rilp, &app_type);
grilio_parser_get_int32(rilp, &app_state);
/*
* Consider RIL_APPSTATE_ILLEGAL also READY. Even if app state is
* RIL_APPSTATE_ILLEGAL (-1), ICC operations must be permitted.
* Network access requests will anyway be rejected and ME will be
* in limited service.
*/
if (app_state == RIL_APPSTATE_ILLEGAL) {
DBG("RIL_APPSTATE_ILLEGAL => RIL_APPSTATE_READY");
app_state = RIL_APPSTATE_READY;
}
grilio_parser_get_int32(rilp, &perso_substate);
app->aid = grilio_parser_get_utf8(rilp);
app->label = grilio_parser_get_utf8(rilp);
if (grilio_parser_get_int32(rilp, &pin_replaced) &&
grilio_parser_get_int32(rilp, &pin1_state) &&
grilio_parser_get_int32(rilp, &pin2_state)) {
app->app_type = app_type;
app->app_state = app_state;
app->perso_substate = perso_substate;
app->pin_replaced = pin_replaced;
app->pin1_state = pin1_state;
app->pin2_state = pin2_state;
return TRUE;
}
return FALSE;
}
static struct ril_sim_card_status *ril_sim_card_status_parse(const void *data,
guint len)
{
GRilIoParser rilp;
gint32 card_state, pin_state, gsm_umts_index, cdma_index;
gint32 ims_index, num_apps;
grilio_parser_init(&rilp, data, len);
if (!grilio_parser_get_int32(&rilp, &card_state) ||
!grilio_parser_get_int32(&rilp, &pin_state) ||
!grilio_parser_get_int32(&rilp, &gsm_umts_index) ||
!grilio_parser_get_int32(&rilp, &cdma_index) ||
!grilio_parser_get_int32(&rilp, &ims_index) ||
!grilio_parser_get_int32(&rilp, &num_apps)) {
ofono_error("Failed to parse SIM card status request");
return NULL;
} else if (num_apps < 0 || num_apps > RIL_CARD_MAX_APPS) {
ofono_error("Invalid SIM app count %d", num_apps);
return NULL;
} else {
int i;
struct ril_sim_card_status *status =
g_new0(struct ril_sim_card_status, 1);
DBG("card_state=%d, universal_pin_state=%d, gsm_umts_index=%d, "
"cdma_index=%d, ims_index=%d, num_apps=%d",
card_state, pin_state, gsm_umts_index, cdma_index,
ims_index, num_apps);
status->card_state = card_state;
status->pin_state = pin_state;
status->gsm_umts_index = gsm_umts_index;
status->cdma_index = cdma_index;
status->ims_index = ims_index;
status->num_apps = num_apps;
if (num_apps > 0) {
status->apps = g_new0(struct ril_sim_card_app, num_apps);
}
for (i = 0; i < num_apps; i++) {
struct ril_sim_card_app *app = status->apps + i;
if (ril_sim_card_app_parse(&rilp, app)) {
DBG("app[%d]: type=%d, state=%d, "
"perso_substate=%d, aid_ptr=%s, "
"label=%s, pin1_replaced=%d, pin1=%d, "
"pin2=%d", i, app->app_type,
app->app_state, app->perso_substate,
app->aid, app->label,
app->pin_replaced, app->pin1_state,
app->pin2_state);
} else {
break;
}
}
if (i == num_apps) {
return status;
} else {
ril_sim_card_status_free(status);
return NULL;
}
}
}
static void ril_sim_card_status_cb(GRilIoChannel *io, int ril_status,
const void *data, guint len, void *user_data)
{
struct ril_sim_card *self = user_data;
struct ril_sim_card_priv *priv = self->priv;
GASSERT(priv->status_req_id);
priv->status_req_id = 0;
if (ril_status == RIL_E_SUCCESS) {
struct ril_sim_card_status *status =
ril_sim_card_status_parse(data, len);
if (status) {
ril_sim_card_update_status(self, status);
}
}
}
static void ril_sim_card_request_status(struct ril_sim_card *self)
{
struct ril_sim_card_priv *priv = self->priv;
if (priv->status_req_id) {
/* Retry right away, don't wait for retry timeout to expire */
grilio_channel_retry_request(priv->io, priv->status_req_id);
} else {
GRilIoRequest* req = grilio_request_new();
grilio_request_set_retry(req, RIL_RETRY_SECS*1000, -1);
priv->status_req_id = grilio_queue_send_request_full(priv->q,
req, RIL_REQUEST_GET_SIM_STATUS,
ril_sim_card_status_cb, NULL, self);
grilio_request_unref(req);
}
}
static void ril_sim_card_status_changed(GRilIoChannel *io, guint code,
const void *data, guint len, void *user_data)
{
struct ril_sim_card *self = user_data;
ril_sim_card_request_status(self);
}
struct ril_sim_card *ril_sim_card_new(GRilIoChannel *io, guint slot, int flags)
{
struct ril_sim_card *self = g_object_new(RIL_SIMCARD_TYPE, NULL);
struct ril_sim_card_priv *priv = self->priv;
/*
* We need to know the RIL version (for UICC subscription hack),
* so we must be connected. The caller is supposed to make sure
* that we get connected first.
*/
DBG("%u", slot);
GASSERT(io->connected);
self->slot = slot;
priv->io = grilio_channel_ref(io);
priv->q = grilio_queue_new(io);
priv->flags = flags;
priv->event_id[EVENT_SIM_STATUS_CHANGED] =
grilio_channel_add_unsol_event_handler(priv->io,
ril_sim_card_status_changed,
RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, self);
priv->event_id[EVENT_UICC_SUBSCRIPTION_STATUS_CHANGED] =
grilio_channel_add_unsol_event_handler(priv->io,
ril_sim_card_status_changed,
RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED, self);
ril_sim_card_request_status(self);
return self;
}
struct ril_sim_card *ril_sim_card_ref(struct ril_sim_card *self)
{
if (G_LIKELY(self)) {
g_object_ref(RIL_SIMCARD(self));
return self;
} else {
return NULL;
}
}
void ril_sim_card_unref(struct ril_sim_card *self)
{
if (G_LIKELY(self)) {
g_object_unref(RIL_SIMCARD(self));
}
}
gulong ril_sim_card_add_status_received_handler(struct ril_sim_card *self,
ril_sim_card_cb_t cb, void *arg)
{
return (G_LIKELY(self) && G_LIKELY(cb)) ? g_signal_connect(self,
SIGNAL_STATUS_RECEIVED_NAME, G_CALLBACK(cb), arg) : 0;
}
gulong ril_sim_card_add_status_changed_handler(struct ril_sim_card *self,
ril_sim_card_cb_t cb, void *arg)
{
return (G_LIKELY(self) && G_LIKELY(cb)) ? g_signal_connect(self,
SIGNAL_STATUS_CHANGED_NAME, G_CALLBACK(cb), arg) : 0;
}
gulong ril_sim_card_add_state_changed_handler(struct ril_sim_card *self,
ril_sim_card_cb_t cb, void *arg)
{
return (G_LIKELY(self) && G_LIKELY(cb)) ? g_signal_connect(self,
SIGNAL_STATE_CHANGED_NAME, G_CALLBACK(cb), arg) : 0;
}
gulong ril_sim_card_add_app_changed_handler(struct ril_sim_card *self,
ril_sim_card_cb_t cb, void *arg)
{
return (G_LIKELY(self) && G_LIKELY(cb)) ? g_signal_connect(self,
SIGNAL_APP_CHANGED_NAME, G_CALLBACK(cb), arg) : 0;
}
void ril_sim_card_remove_handler(struct ril_sim_card *self, gulong id)
{
if (G_LIKELY(self) && G_LIKELY(id)) {
g_signal_handler_disconnect(self, id);
}
}
static void ril_sim_card_init(struct ril_sim_card *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self, RIL_SIMCARD_TYPE,
struct ril_sim_card_priv);
}
static void ril_sim_card_dispose(GObject *object)
{
struct ril_sim_card *self = RIL_SIMCARD(object);
struct ril_sim_card_priv *priv = self->priv;
grilio_channel_remove_handlers(priv->io, priv->event_id, EVENT_COUNT);
grilio_queue_cancel_all(priv->q, TRUE);
G_OBJECT_CLASS(ril_sim_card_parent_class)->dispose(object);
}
static void ril_sim_card_finalize(GObject *object)
{
struct ril_sim_card *self = RIL_SIMCARD(object);
struct ril_sim_card_priv *priv = self->priv;
grilio_channel_unref(priv->io);
grilio_queue_unref(priv->q);
ril_sim_card_status_free(self->status);
G_OBJECT_CLASS(ril_sim_card_parent_class)->finalize(object);
}
static void ril_sim_card_class_init(RilSimCardClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->dispose = ril_sim_card_dispose;
object_class->finalize = ril_sim_card_finalize;
g_type_class_add_private(klass, sizeof(struct ril_sim_card_priv));
ril_sim_card_signals[SIGNAL_STATUS_RECEIVED] =
g_signal_new(SIGNAL_STATUS_RECEIVED_NAME,
G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL, G_TYPE_NONE, 0);
ril_sim_card_signals[SIGNAL_STATUS_CHANGED] =
g_signal_new(SIGNAL_STATUS_CHANGED_NAME,
G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL, G_TYPE_NONE, 0);
ril_sim_card_signals[SIGNAL_STATE_CHANGED] =
g_signal_new(SIGNAL_STATE_CHANGED_NAME,
G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL, G_TYPE_NONE, 0);
ril_sim_card_signals[SIGNAL_APP_CHANGED] =
g_signal_new(SIGNAL_APP_CHANGED_NAME,
G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL, G_TYPE_NONE, 0);
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,81 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef RIL_SIM_CARD_H
#define RIL_SIM_CARD_H
#include "ril_types.h"
struct ril_sim_card_app {
enum ril_app_type app_type;
enum ril_app_state app_state;
enum ril_perso_substate perso_substate;
char *aid;
char *label;
guint pin_replaced;
enum ril_pin_state pin1_state;
enum ril_pin_state pin2_state;
};
struct ril_sim_card_status {
enum ril_card_state card_state;
enum ril_pin_state pin_state;
int gsm_umts_index;
int cdma_index;
int ims_index;
int num_apps;
struct ril_sim_card_app *apps;
};
struct ril_sim_card {
GObject object;
struct ril_sim_card_priv *priv;
struct ril_sim_card_status *status;
const struct ril_sim_card_app *app;
guint slot;
};
typedef void (*ril_sim_card_cb_t)(struct ril_sim_card *sc, void *arg);
/* Flags for ril_sim_card_new */
#define RIL_SIM_CARD_V9_UICC_SUBSCRIPTION_WORKAROUND (0x01)
struct ril_sim_card *ril_sim_card_new(GRilIoChannel *io, guint slot, int flags);
struct ril_sim_card *ril_sim_card_ref(struct ril_sim_card *sc);
void ril_sim_card_unref(struct ril_sim_card *sc);
gulong ril_sim_card_add_status_received_handler(struct ril_sim_card *sc,
ril_sim_card_cb_t cb, void *arg);
gulong ril_sim_card_add_status_changed_handler(struct ril_sim_card *sc,
ril_sim_card_cb_t cb, void *arg);
gulong ril_sim_card_add_state_changed_handler(struct ril_sim_card *sc,
ril_sim_card_cb_t cb, void *arg);
gulong ril_sim_card_add_app_changed_handler(struct ril_sim_card *sc,
ril_sim_card_cb_t cb, void *arg);
void ril_sim_card_remove_handler(struct ril_sim_card *sc, gulong id);
/* Inline wrappers */
G_INLINE_FUNC enum ril_app_type
ril_sim_card_app_type(struct ril_sim_card *sc)
{ return (sc && sc->app) ? sc->app->app_type : RIL_APPTYPE_UNKNOWN; }
#endif /* RIL_SIM_CARD_H */
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,242 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_log.h"
#include <ofono/dbus.h>
#include <gdbus.h>
#include "ofono.h"
#include "storage.h"
struct ril_sim_dbus {
char *path;
char *imsi;
char *name;
char *default_name;
gboolean enable_4g;
GKeyFile *storage;
DBusConnection *conn;
struct ril_modem *md;
};
#define RIL_SIM_STORE "ril"
#define RIL_SIM_STORE_GROUP "Settings"
#define RIL_SIM_STORE_ENABLE_4G "Enable4G"
#define RIL_SIM_STORE_DISPLAY_NAME "DisplayName"
#define RIL_SIM_DBUS_INTERFACE "org.nemomobile.ofono.SimSettings"
#define RIL_SIM_DBUS_INTERFACE_VERSION (1)
#define RIL_SIM_DBUS_DISPLAY_NAME_CHANGED_SIGNAL "DisplayNameChanged"
#define RIL_SIM_DBUS_ENABLE_4G_CHANGED_SIGNAL "Enable4GChanged"
static DBusMessage *ril_sim_dbus_get_all(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ril_sim_dbus *dbus = data;
DBusMessage *reply = dbus_message_new_method_return(msg);
dbus_int32_t version = RIL_SIM_DBUS_INTERFACE_VERSION;
dbus_bool_t enable_4g = dbus->enable_4g;
DBusMessageIter iter;
dbus_message_iter_init_append(reply, &iter);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &version);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &enable_4g);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &dbus->name);
return reply;
}
static DBusMessage *ril_sim_dbus_get_interface_version(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply = dbus_message_new_method_return(msg);
dbus_int32_t version = RIL_SIM_DBUS_INTERFACE_VERSION;
DBusMessageIter iter;
dbus_message_iter_init_append(reply, &iter);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &version);
return reply;
}
static DBusMessage *ril_sim_dbus_get_enable_4g(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ril_sim_dbus *dbus = data;
DBusMessage *reply = dbus_message_new_method_return(msg);
dbus_bool_t enable_4g = dbus->enable_4g;
DBusMessageIter iter;
dbus_message_iter_init_append(reply, &iter);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &enable_4g);
return reply;
}
static DBusMessage *ril_sim_dbus_get_display_name(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ril_sim_dbus *dbus = data;
DBusMessage *reply = dbus_message_new_method_return(msg);
DBusMessageIter iter;
dbus_message_iter_init_append(reply, &iter);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &dbus->name);
return reply;
}
static void ril_sim_dbus_update_display_name(struct ril_sim_dbus *dbus,
const char *name)
{
if (g_strcmp0(dbus->name, name)) {
g_free(dbus->name);
dbus->name = g_strdup(name);
g_key_file_set_string(dbus->storage, RIL_SIM_STORE_GROUP,
RIL_SIM_STORE_DISPLAY_NAME, name);
storage_sync(dbus->imsi, RIL_SIM_STORE, dbus->storage);
g_dbus_emit_signal(dbus->conn, dbus->path,
RIL_SIM_DBUS_INTERFACE,
RIL_SIM_DBUS_DISPLAY_NAME_CHANGED_SIGNAL,
DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
}
}
static DBusMessage *ril_sim_dbus_set_display_name(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessageIter iter;
dbus_message_iter_init(msg, &iter);
if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) {
struct ril_sim_dbus *dbus = data;
DBusBasicValue value;
const char *name;
dbus_message_iter_get_basic(&iter, &value);
name = value.str;
if (!name || !name[0]) name = dbus->default_name;
ril_sim_dbus_update_display_name(dbus, name);
return dbus_message_new_method_return(msg);
} else {
return __ofono_error_invalid_args(msg);
}
}
static const GDBusMethodTable ril_sim_dbus_methods[] = {
{ GDBUS_METHOD("GetAll",
NULL, GDBUS_ARGS({ "settings", "ibs" }),
ril_sim_dbus_get_all) },
{ GDBUS_METHOD("GetInterfaceVersion",
NULL, GDBUS_ARGS({ "version", "i" }),
ril_sim_dbus_get_interface_version) },
{ GDBUS_METHOD("GetEnable4G",
NULL, GDBUS_ARGS({ "enable", "b" }),
ril_sim_dbus_get_enable_4g) },
{ GDBUS_METHOD("GetDisplayName",
NULL, GDBUS_ARGS({ "name", "s" }),
ril_sim_dbus_get_display_name) },
{ GDBUS_METHOD("SetDisplayName",
GDBUS_ARGS({ "name", "s" }), NULL,
ril_sim_dbus_set_display_name) },
{ }
};
static const GDBusSignalTable ril_sim_dbus_signals[] = {
{ GDBUS_SIGNAL(RIL_SIM_DBUS_DISPLAY_NAME_CHANGED_SIGNAL,
GDBUS_ARGS({ "name", "s" })) },
{ GDBUS_SIGNAL(RIL_SIM_DBUS_ENABLE_4G_CHANGED_SIGNAL,
GDBUS_ARGS({ "enabled", "b" })) },
{ }
};
const char *ril_sim_dbus_imsi(struct ril_sim_dbus *dbus)
{
return dbus ? dbus->imsi : NULL;
}
struct ril_sim_dbus *ril_sim_dbus_new(struct ril_modem *md)
{
const char *imsi = ofono_sim_get_imsi(ril_modem_ofono_sim(md));
if (imsi) {
GError *error = NULL;
const struct ril_slot_config *config = &md->config;
struct ril_sim_dbus *dbus = g_new0(struct ril_sim_dbus, 1);
DBG("%s", ril_modem_get_path(md));
dbus->md = md;
dbus->conn = dbus_connection_ref(ofono_dbus_get_connection());
dbus->path = g_strdup(ril_modem_get_path(md));
dbus->imsi = g_strdup(imsi);
dbus->default_name = g_strdup(config->default_name);
/* Load settings */
dbus->storage = storage_open(imsi, RIL_SIM_STORE);
dbus->enable_4g = g_key_file_get_boolean(dbus->storage,
RIL_SIM_STORE_GROUP, RIL_SIM_STORE_ENABLE_4G, &error);
if (error) {
dbus->enable_4g = config->enable_4g;
g_error_free(error);
error = NULL;
}
dbus->name = g_key_file_get_string(dbus->storage,
RIL_SIM_STORE_GROUP, RIL_SIM_STORE_DISPLAY_NAME, NULL);
if (!dbus->name) {
dbus->name = g_strdup(config->default_name);
GASSERT(dbus->name);
}
/* Register D-Bus interface */
if (g_dbus_register_interface(dbus->conn, dbus->path,
RIL_SIM_DBUS_INTERFACE, ril_sim_dbus_methods,
ril_sim_dbus_signals, NULL, dbus, NULL)) {
ofono_modem_add_interface(md->ofono,
RIL_SIM_DBUS_INTERFACE);
return dbus;
} else {
ofono_error("RIL D-Bus register failed");
ril_sim_dbus_free(dbus);
}
}
return NULL;
}
void ril_sim_dbus_free(struct ril_sim_dbus *dbus)
{
if (dbus) {
DBG("%s", dbus->path);
g_dbus_unregister_interface(dbus->conn, dbus->path,
RIL_SIM_DBUS_INTERFACE);
ofono_modem_remove_interface(dbus->md->ofono,
RIL_SIM_DBUS_INTERFACE);
dbus_connection_unref(dbus->conn);
g_key_file_free(dbus->storage);
g_free(dbus->path);
g_free(dbus->imsi);
g_free(dbus->name);
g_free(dbus->default_name);
g_free(dbus);
}
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

498
ofono/drivers/ril/ril_sms.c Normal file
View File

@@ -0,0 +1,498 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_constants.h"
#include "ril_util.h"
#include "ril_log.h"
#include "smsutil.h"
#include "util.h"
#include "simutil.h"
#define SIM_EFSMS_FILEID 0x6F3C
#define EFSMS_LENGTH 176
#define TYPE_LOCAL 129
#define TYPE_INTERNATIONAL 145
static unsigned char path[4] = {0x3F, 0x00, 0x7F, 0x10};
enum ril_sms_events {
SMS_EVENT_NEW_SMS,
SMS_EVENT_NEW_STATUS_REPORT,
SMS_EVENT_NEW_SMS_ON_SIM,
SMS_EVENT_COUNT
};
struct ril_sms {
GRilIoChannel *io;
GRilIoQueue *q;
struct ril_modem *modem;
struct ofono_sms *sms;
gulong event_id[SMS_EVENT_COUNT];
guint timer_id;
};
struct ril_sms_cbd {
union _ofono_sms_cb {
ofono_sms_sca_set_cb_t sca_set;
ofono_sms_sca_query_cb_t sca_query;
ofono_sms_submit_cb_t submit;
gpointer ptr;
} cb;
gpointer data;
};
struct ril_sms_on_sim_req {
struct ril_sms *sd;
int record;
};
#define ril_sms_cbd_free g_free
#define ril_sms_on_sim_req_free g_free
static inline struct ril_sms *ril_sms_get_data(struct ofono_sms *sms)
{
return ofono_sms_get_data(sms);
}
struct ril_sms_cbd *ril_sms_cbd_new(struct ril_sms *sd, void *cb, void *data)
{
struct ril_sms_cbd *cbd = g_new0(struct ril_sms_cbd, 1);
cbd->cb.ptr = cb;
cbd->data = data;
return cbd;
}
struct ril_sms_on_sim_req *ril_sms_on_sim_req_new(struct ril_sms *sd, int rec)
{
struct ril_sms_on_sim_req *cbd = g_new0(struct ril_sms_on_sim_req, 1);
cbd->sd = sd;
cbd->record = rec;
return cbd;
}
static void ril_sms_sca_set_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_sms_cbd *cbd = user_data;
ofono_sms_sca_set_cb_t cb = cbd->cb.sca_set;
if (status == RIL_E_SUCCESS) {
cb(ril_error_ok(&error), cbd->data);
} else {
ofono_error("csca setting failed");
cb(ril_error_failure(&error), cbd->data);
}
}
static void ril_sms_sca_set(struct ofono_sms *sms,
const struct ofono_phone_number *sca,
ofono_sms_sca_set_cb_t cb, void *data)
{
struct ril_sms *sd = ril_sms_get_data(sms);
GRilIoRequest *req = grilio_request_new();
char number[OFONO_MAX_PHONE_NUMBER_LENGTH + 4];
if (sca->type == TYPE_LOCAL) {
snprintf(number, sizeof(number), "\"%s\"", sca->number);
} else {
snprintf(number, sizeof(number), "\"+%s\"", sca->number);
}
DBG("Setting sca: %s", number);
grilio_request_append_utf8(req, number);
grilio_queue_send_request_full(sd->q, req,
RIL_REQUEST_SET_SMSC_ADDRESS, ril_sms_sca_set_cb,
ril_sms_cbd_free, ril_sms_cbd_new(sd, cb, data));
grilio_request_unref(req);
}
static void ril_sms_sca_query_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ril_sms_cbd *cbd = user_data;
ofono_sms_sca_query_cb_t cb = cbd->cb.sca_query;
struct ofono_error error;
GRilIoParser rilp;
gchar *temp_buf;
if (status != RIL_E_SUCCESS) {
ofono_error("csca query failed");
cb(ril_error_failure(&error), NULL, cbd->data);
return;
}
grilio_parser_init(&rilp, data, len);
temp_buf = grilio_parser_get_utf8(&rilp);
if (temp_buf) {
/* RIL gives address in quotes */
gchar *number = strtok(temp_buf, "\"");
struct ofono_phone_number sca;
strncpy(sca.number, number, OFONO_MAX_PHONE_NUMBER_LENGTH);
sca.number[OFONO_MAX_PHONE_NUMBER_LENGTH] = '\0';
if (sca.number[0] == '+') {
number = number + 1;
sca.type = TYPE_INTERNATIONAL;
} else {
sca.type = TYPE_LOCAL;
}
DBG("csca_query_cb: %s, %d", sca.number, sca.type);
cb(ril_error_ok(&error), &sca, cbd->data);
g_free(temp_buf);
} else {
ofono_error("return value invalid");
cb(ril_error_failure(&error), NULL, cbd->data);
}
}
static void ril_sms_sca_query(struct ofono_sms *sms,
ofono_sms_sca_query_cb_t cb, void *data)
{
struct ril_sms *sd = ril_sms_get_data(sms);
DBG("Sending csca_query");
grilio_queue_send_request_full(sd->q, NULL,
RIL_REQUEST_GET_SMSC_ADDRESS, ril_sms_sca_query_cb,
ril_sms_cbd_free, ril_sms_cbd_new(sd, cb, data));
}
static void ril_sms_submit_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ril_sms_cbd *cbd = user_data;
ofono_sms_submit_cb_t cb = cbd->cb.submit;
struct ofono_error error;
int mr = 0;
if (status == RIL_E_SUCCESS) {
GRilIoParser rilp;
int err = -1;
grilio_parser_init(&rilp, data, len);
/* TP-Message-Reference for GSM/
* BearerData MessageId for CDMA
*/
grilio_parser_get_int32(&rilp, &mr);
grilio_parser_skip_string(&rilp);
/* error: 3GPP 27.005, 3.2.5, -1 if unknown or not applicable */
grilio_parser_get_int32(&rilp, &err);
DBG("sms msg ref: %d, error: %d", mr, err);
ril_error_init_ok(&error);
} else if (status == RIL_E_GENERIC_FAILURE) {
ofono_info("not allowed by MO SMS control, do not retry");
error.type = OFONO_ERROR_TYPE_CMS;
error.error = 500;
} else {
ofono_error("sms sending failed, retry");
ril_error_init_failure(&error);
}
cb(&error, mr, cbd->data);
}
static void ril_sms_submit(struct ofono_sms *sms, const unsigned char *pdu,
int pdu_len, int tpdu_len, int mms,
ofono_sms_submit_cb_t cb, void *data)
{
struct ril_sms *sd = ril_sms_get_data(sms);
GRilIoRequest *req = grilio_request_new();
int smsc_len;
char *tpdu;
DBG("pdu_len: %d, tpdu_len: %d mms: %d", pdu_len, tpdu_len, mms);
grilio_request_append_int32(req, 2); /* Number of strings */
/* SMSC address:
*
* smsc_len == 1, then zero-length SMSC was spec'd
* RILD expects a NULL string in this case instead
* of a zero-length string.
*/
smsc_len = pdu_len - tpdu_len;
if (smsc_len > 1) {
/* TODO: encode SMSC & write to parcel */
DBG("SMSC address specified (smsc_len %d); NOT-IMPLEMENTED",
smsc_len);
}
grilio_request_append_utf8(req, NULL); /* default SMSC address */
/* TPDU:
*
* 'pdu' is a raw hexadecimal string
* encode_hex() turns it into an ASCII/hex UTF8 buffer
* grilio_request_append_utf8() encodes utf8 -> utf16
*/
tpdu = encode_hex(pdu + smsc_len, tpdu_len, 0);
grilio_request_append_utf8(req, tpdu);
DBG("%s", tpdu);
grilio_queue_send_request_full(sd->q, req,
RIL_REQUEST_SEND_SMS, ril_sms_submit_cb,
ril_sms_cbd_free, ril_sms_cbd_new(sd, cb, data));
grilio_request_unref(req);
g_free(tpdu);
}
static void ril_ack_delivery_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
if (status != RIL_E_SUCCESS) {
ofono_error("SMS acknowledgement failed: "
"Further SMS reception is not guaranteed");
}
}
static void ril_ack_delivery(struct ril_sms *sd, gboolean error)
{
GRilIoRequest *req = grilio_request_sized_new(12);
const int code = (error ? 0 : 0xff);
DBG("(%d,%d)", error, code);
grilio_request_append_int32(req, 2); /* Array size*/
grilio_request_append_int32(req, error); /* Success (1)/Failure (0) */
grilio_request_append_int32(req, code); /* error code */
/* ACK the incoming NEW_SMS */
grilio_queue_send_request_full(sd->q, req,
RIL_REQUEST_SMS_ACKNOWLEDGE, ril_ack_delivery_cb, NULL, NULL);
grilio_request_unref(req);
}
static void ril_sms_notify(GRilIoChannel *io, guint ril_event,
const void *data, guint len, void *user_data)
{
struct ril_sms *sd = user_data;
GRilIoParser rilp;
char *ril_pdu;
int ril_pdu_len;
unsigned int smsc_len;
long ril_buf_len;
guchar *ril_data;
ril_pdu = NULL;
ril_data = NULL;
DBG("event: %d; data_len: %d", ril_event, len);
grilio_parser_init(&rilp, data, len);
ril_pdu = grilio_parser_get_utf8(&rilp);
if (ril_pdu == NULL)
goto error;
ril_pdu_len = strlen(ril_pdu);
DBG("ril_pdu_len is %d", ril_pdu_len);
ril_data = decode_hex(ril_pdu, ril_pdu_len, &ril_buf_len, -1);
if (ril_data == NULL)
goto error;
/* The first octect in the pdu contains the SMSC address length
* which is the X following octects it reads. We add 1 octet to
* the read length to take into account this read octet in order
* to calculate the proper tpdu length.
*/
smsc_len = ril_data[0] + 1;
ofono_info("sms received, smsc_len is %d", smsc_len);
DBG("(%s)", ril_pdu);
if (ril_event == RIL_UNSOL_RESPONSE_NEW_SMS) {
/* Last parameter is 'tpdu_len' ( substract SMSC length ) */
ofono_sms_deliver_notify(sd->sms, ril_data, ril_buf_len,
ril_buf_len - smsc_len);
} else {
GASSERT(ril_event == RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT);
ofono_sms_status_notify(sd->sms, ril_data, ril_buf_len,
ril_buf_len - smsc_len);
}
g_free(ril_pdu);
g_free(ril_data);
ril_ack_delivery(sd, TRUE);
return;
error:
g_free(ril_pdu);
g_free(ril_data);
ril_ack_delivery(sd, FALSE);
ofono_error("Unable to parse NEW_SMS notification");
}
static void ril_new_sms_on_sim_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
DBG("%d", status);
if (status == RIL_E_SUCCESS) {
ofono_info("sms deleted from sim");
} else {
ofono_error("deleting sms from sim failed");
}
}
static void ril_request_delete_sms_om_sim(struct ril_sms *sd, int record)
{
GRilIoRequest *req = grilio_request_sized_new(8);
DBG("Deleting record: %d", record);
grilio_request_append_int32(req, 1); /* Array length */
grilio_request_append_int32(req, record);
grilio_queue_send_request_full(sd->q, req,
RIL_REQUEST_DELETE_SMS_ON_SIM,
ril_new_sms_on_sim_cb, NULL, NULL);
grilio_request_unref(req);
}
static void ril_sms_on_sim_cb(const struct ofono_error *error,
const unsigned char *sdata,
int length, void *data)
{
struct ril_sms_on_sim_req *cbd = data;
struct ril_sms *sd = cbd->sd;
/*
* It seems when reading EFsms RIL returns the whole record including
* the first status byte therefore we ignore that as we are only
* interested of the following pdu
*/
/* The first octect in the pdu contains the SMSC address length
* which is the X following octects it reads. We add 1 octet to
* the read length to take into account this read octet in order
* to calculate the proper tpdu length.
*/
if (error->type == OFONO_ERROR_TYPE_NO_ERROR) {
unsigned int smsc_len = sdata[1] + 1;
ofono_sms_deliver_notify(sd->sms, sdata + 1, length - 1,
length - smsc_len - 1);
ril_request_delete_sms_om_sim(sd, cbd->record);
} else {
ofono_error("cannot read sms from sim");
}
ril_sms_on_sim_req_free(cbd);
}
static void ril_sms_on_sim(GRilIoChannel *io, guint ril_event,
const void *data, guint len, void *user_data)
{
struct ril_sms *sd = user_data;
struct ofono_sim *sim = ril_modem_ofono_sim(sd->modem);
int data_len = 0, rec = 0;
GRilIoParser rilp;
ofono_info("new sms on sim");
grilio_parser_init(&rilp, data, len);
if (sim &&
grilio_parser_get_int32(&rilp, &data_len) && data_len > 0 &&
grilio_parser_get_int32(&rilp, &rec)) {
DBG("rec %d", rec);
ril_sim_read_file_linear(sim, SIM_EFSMS_FILEID, rec,
EFSMS_LENGTH, path, sizeof(path),
ril_sms_on_sim_cb,
ril_sms_on_sim_req_new(sd,rec));
}
}
static gboolean ril_sms_register(gpointer user_data)
{
struct ril_sms *sd = user_data;
DBG("");
GASSERT(sd->timer_id);
sd->timer_id = 0;
ofono_sms_register(sd->sms);
/* Register event handlers */
sd->event_id[SMS_EVENT_NEW_SMS] =
grilio_channel_add_unsol_event_handler(sd->io, ril_sms_notify,
RIL_UNSOL_RESPONSE_NEW_SMS, sd);
sd->event_id[SMS_EVENT_NEW_STATUS_REPORT] =
grilio_channel_add_unsol_event_handler(sd->io, ril_sms_notify,
RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT, sd);
sd->event_id[SMS_EVENT_NEW_SMS_ON_SIM] =
grilio_channel_add_unsol_event_handler(sd->io, ril_sms_on_sim,
RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM, sd);
/* Single-shot */
return FALSE;
}
static int ril_sms_probe(struct ofono_sms *sms, unsigned int vendor,
void *data)
{
struct ril_modem *modem = data;
struct ril_sms *sd = g_new0(struct ril_sms, 1);
sd->modem = modem;
sd->sms = sms;
sd->io = grilio_channel_ref(ril_modem_io(modem));
sd->q = grilio_queue_new(sd->io);
sd->timer_id = g_idle_add(ril_sms_register, sd);
ofono_sms_set_data(sms, sd);
return 0;
}
static void ril_sms_remove(struct ofono_sms *sms)
{
int i;
struct ril_sms *sd = ril_sms_get_data(sms);
DBG("");
ofono_sms_set_data(sms, NULL);
for (i=0; i<G_N_ELEMENTS(sd->event_id); i++) {
grilio_channel_remove_handler(sd->io, sd->event_id[i]);
}
if (sd->timer_id > 0) {
g_source_remove(sd->timer_id);
}
grilio_channel_unref(sd->io);
grilio_queue_cancel_all(sd->q, FALSE);
grilio_queue_unref(sd->q);
g_free(sd);
}
const struct ofono_sms_driver ril_sms_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_sms_probe,
.remove = ril_sms_remove,
.sca_query = ril_sms_sca_query,
.sca_set = ril_sms_sca_set,
.submit = ril_sms_submit,
.bearer_query = NULL, /* FIXME: needs investigation. */
.bearer_set = NULL
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

303
ofono/drivers/ril/ril_stk.c Normal file
View File

@@ -0,0 +1,303 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_util.h"
#include "ril_log.h"
#include "ril_constants.h"
#include "util.h"
#ifndef UI_LANG
# define UI_LANG "/var/lib/environment/nemo/locale.conf"
#endif
enum ril_stk_events {
STK_EVENT_PROACTIVE_COMMAND,
STK_EVENT_SESSION_END,
STK_EVENT_NOTIFY,
STK_EVENT_COUNT
};
struct ril_stk {
struct ofono_stk *stk;
GRilIoChannel *io;
GRilIoQueue *q;
gulong event_id[STK_EVENT_COUNT];
};
struct ril_stk_cbd {
union _ofono_stk_cb {
ofono_stk_envelope_cb_t envelope;
ofono_stk_generic_cb_t generic;
gpointer ptr;
} cb;
gpointer data;
};
#define ril_stk_cbd_free g_free
static inline struct ril_stk *ril_stk_get_data(struct ofono_stk *stk)
{
return ofono_stk_get_data(stk);
}
struct ril_stk_cbd *ril_stk_cbd_new(void *cb, void *data)
{
struct ril_stk_cbd *cbd = g_new0(struct ril_stk_cbd, 1);
cbd->cb.ptr = cb;
cbd->data = data;
return cbd;
}
static void ril_stk_envelope_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_stk_cbd *cbd = user_data;
ofono_stk_envelope_cb_t cb = cbd->cb.envelope;
if (status == RIL_E_SUCCESS) {
DBG("%u bytes(s)", len);
cb(ril_error_ok(&error), NULL, 0, cbd->data);
} else {
DBG("Envelope reply failure: %s", ril_error_to_string(status));
cb(ril_error_failure(&error), NULL, 0, cbd->data);
}
}
static void ril_stk_envelope(struct ofono_stk *stk, int length,
const unsigned char *cmd, ofono_stk_envelope_cb_t cb, void *data)
{
struct ril_stk *sd = ril_stk_get_data(stk);
GRilIoRequest *req = grilio_request_new();
char *hex_envelope = encode_hex(cmd, length, 0);
DBG("%s", hex_envelope);
grilio_request_append_utf8(req, hex_envelope);
g_free(hex_envelope);
grilio_queue_send_request_full(sd->q, req,
RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND,
ril_stk_envelope_cb, ril_stk_cbd_free,
ril_stk_cbd_new(cb, data));
grilio_request_unref(req);
}
static void ril_stk_terminal_response_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_stk_cbd *cbd = user_data;
ofono_stk_generic_cb_t cb = cbd->cb.generic;
DBG("");
if (status == RIL_E_SUCCESS) {
cb(ril_error_ok(&error), cbd->data);
} else {
ofono_error("Error in sending terminal response");
cb(ril_error_failure(&error), cbd->data);
}
}
static void ril_stk_terminal_response(struct ofono_stk *stk, int length,
const unsigned char *resp,
ofono_stk_generic_cb_t cb, void *data)
{
struct ril_stk *sd = ril_stk_get_data(stk);
GRilIoRequest *req = grilio_request_new();
char *hex_tr = encode_hex(resp, length, 0);
DBG("rilmodem terminal response: %s", hex_tr);
grilio_request_append_utf8(req, hex_tr);
g_free(hex_tr);
grilio_queue_send_request_full(sd->q, req,
RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE,
ril_stk_terminal_response_cb,
ril_stk_cbd_free, ril_stk_cbd_new(cb, data));
grilio_request_unref(req);
}
static void ril_stk_user_confirmation(struct ofono_stk *stk,
ofono_bool_t confirm)
{
struct ril_stk *sd = ril_stk_get_data(stk);
GRilIoRequest *req = grilio_request_sized_new(8);
DBG("%d", confirm);
grilio_request_append_int32(req, 1); /* size of array */
grilio_request_append_int32(req, confirm); /* yes/no */
grilio_queue_send_request(sd->q, req,
RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM);
grilio_request_unref(req);
}
static void ril_stk_pcmd_notify(GRilIoChannel *io, guint code,
const void *data, guint data_len, void *user_data)
{
struct ril_stk *sd = user_data;
GRilIoParser rilp;
char *pcmd;
guchar *pdu;
long len = 0;
GASSERT(code == RIL_UNSOL_STK_PROACTIVE_COMMAND);
grilio_parser_init(&rilp, data, data_len);
pcmd = grilio_parser_get_utf8(&rilp);
DBG("pcmd: %s", pcmd);
pdu = decode_hex(pcmd, strlen(pcmd), &len, -1);
g_free(pcmd);
ofono_stk_proactive_command_notify(sd->stk, len, pdu);
g_free(pdu);
}
static void ril_stk_event_notify(GRilIoChannel *io, guint code,
const void *data, guint data_len, void *user_data)
{
struct ril_stk *sd = user_data;
GRilIoParser rilp;
char *pcmd = NULL;
guchar *pdu = NULL;
long len;
/* Proactive command has been handled by the modem. */
GASSERT(code == RIL_UNSOL_STK_EVENT_NOTIFY);
grilio_parser_init(&rilp, data, data_len);
pcmd = grilio_parser_get_utf8(&rilp);
DBG("pcmd: %s", pcmd);
pdu = decode_hex(pcmd, strlen(pcmd), &len, -1);
g_free(pcmd);
ofono_stk_proactive_command_handled_notify(sd->stk, len, pdu);
g_free(pdu);
}
static void ril_stk_session_end_notify(GRilIoChannel *io, guint code,
const void *data, guint len, void *user_data)
{
struct ril_stk *sd = user_data;
DBG("");
GASSERT(code == RIL_UNSOL_STK_SESSION_END);
ofono_stk_proactive_session_end_notify(sd->stk);
}
static void ril_stk_agent_ready(struct ofono_stk *stk)
{
struct ril_stk *sd = ril_stk_get_data(stk);
DBG("");
if (!sd->event_id[STK_EVENT_PROACTIVE_COMMAND]) {
DBG("Subscribing notifications");
sd->event_id[STK_EVENT_PROACTIVE_COMMAND] =
grilio_channel_add_unsol_event_handler(sd->io,
ril_stk_pcmd_notify,
RIL_UNSOL_STK_PROACTIVE_COMMAND, sd);
GASSERT(!sd->event_id[STK_EVENT_SESSION_END]);
sd->event_id[STK_EVENT_SESSION_END] =
grilio_channel_add_unsol_event_handler(sd->io,
ril_stk_session_end_notify,
RIL_UNSOL_STK_SESSION_END, sd);
GASSERT(!sd->event_id[STK_EVENT_NOTIFY]);
sd->event_id[STK_EVENT_NOTIFY] =
grilio_channel_add_unsol_event_handler(sd->io,
ril_stk_event_notify,
RIL_UNSOL_STK_EVENT_NOTIFY, sd);
grilio_queue_send_request(sd->q, NULL,
RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING);
}
}
static void ril_stk_set_lang()
{
GError *error = NULL;
GIOChannel* chan = g_io_channel_new_file(UI_LANG, "r", &error);
if (chan) {
GString* buf = g_string_new(NULL);
gsize term;
while (g_io_channel_read_line_string(chan, buf, &term, NULL) ==
G_IO_STATUS_NORMAL) {
char* lang;
g_string_set_size(buf, term);
lang = strstr(buf->str, "LANG=");
if (lang) {
setenv("LANG", lang + 5, TRUE);
}
}
g_string_free(buf, TRUE);
g_io_channel_unref(chan);
} else {
DBG("%s: %s", UI_LANG, error->message);
g_error_free(error);
}
}
static int ril_stk_probe(struct ofono_stk *stk, unsigned int vendor, void *data)
{
struct ril_modem *modem = data;
struct ril_stk *sd = g_new0(struct ril_stk, 1);
DBG("");
sd->stk = stk;
sd->io = grilio_channel_ref(ril_modem_io(modem));
sd->q = grilio_queue_new(sd->io);
ofono_stk_set_data(stk, sd);
ofono_stk_register(stk);
ril_stk_set_lang();
return 0;
}
static void ril_stk_remove(struct ofono_stk *stk)
{
struct ril_stk *sd = ril_stk_get_data(stk);
int i;
DBG("");
ofono_stk_set_data(stk, NULL);
for (i=0; i<G_N_ELEMENTS(sd->event_id); i++) {
grilio_channel_remove_handler(sd->io, sd->event_id[i]);
}
grilio_channel_unref(sd->io);
grilio_queue_cancel_all(sd->q, FALSE);
grilio_queue_unref(sd->q);
g_free(sd);
}
const struct ofono_stk_driver ril_stk_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_stk_probe,
.remove = ril_stk_remove,
.envelope = ril_stk_envelope,
.terminal_response = ril_stk_terminal_response,
.user_confirmation = ril_stk_user_confirmation,
.ready = ril_stk_agent_ready
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,55 @@
# This is a sample configuration file for the ril driver
#
# This file is expected to be installed in /etc/ofono
#
# Configuration for each modem is defined in its own [ril_x] section.
# Only the sections that start with the "ril_" prefix define the modems,
# other sections are currently ignored.
#
[ril_0]
# Required entry, defines the RIL socket path
socket=/dev/socket/rild
# Subscription string. Some (mostly, older) RILs require that 4 bytes
# (usually SUB1 or SUB2) are written to the socket before rild starts
# talking to us.
#
# Not sent by default.
#
#sub=SUB1
# RIL logging prefix, to tell one socket from another in the log.
# Makes sense if you have more than one modem configured.
#
# No prefix by default.
#
#name=RIL1
# Slot id for SET_UICC_SUBSCRIPTION request.
#
# By default the first modem becomes slot 0, the next one slot 1 and so on.
#
#slot=0
# RIL request timeout, in milliseconds.
#
# The default is zero (no timeout)
#
#timeout=0
# Setting this one to false would disable 4G technology selection.
#
# By default 4G is enabled
#
#enable4G=true
# RIL_REQUEST_SET_UICC_SUBSCRIPTION is 115 in RIL version 9 (or earlier)
# and 122 in RIL version 10 and later. Since ofono doesn't know in advance
# which RIL version it's dealing with, it makes the decision at runtime.
# Settings it to false disables the workaround and always sends 122.
#
# Default is true (select SET_UICC_SUBSCRIPTION based on the RIL version)
#
#uiccWorkaround=true

View File

@@ -0,0 +1,56 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef RIL_TYPES_H
#define RIL_TYPES_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <grilio_types.h>
#include <gutil_macros.h>
#include <ofono/types.h>
struct ofono_modem;
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "ril_constants.h"
#define RIL_RETRY_SECS (2)
#define RIL_RETRY_MS (RIL_RETRY_SECS*1000)
struct ril_data;
struct ril_modem;
struct ril_radio;
struct ril_network;
struct ril_sim_card;
struct ril_plugin_dbus;
#endif /* RIL_TYPES_H */
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,224 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_util.h"
#include "ril_log.h"
#include "ril_constants.h"
#include "smsutil.h"
#include "util.h"
struct ril_ussd {
struct ofono_ussd *ussd;
GRilIoChannel *io;
GRilIoQueue *q;
guint timer_id;
gulong event_id;
};
struct ril_ussd_cbd {
ofono_ussd_cb_t cb;
gpointer data;
};
#define ril_ussd_cbd_free g_free
static inline struct ril_ussd *ril_ussd_get_data(struct ofono_ussd *ussd)
{
return ofono_ussd_get_data(ussd);
}
static struct ril_ussd_cbd *ril_ussd_cbd_new(ofono_ussd_cb_t cb, void *data)
{
struct ril_ussd_cbd *cbd = g_new0(struct ril_ussd_cbd, 1);
cbd->cb = cb;
cbd->data = data;
return cbd;
}
static void ril_ussd_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ofono_error error;
struct ril_ussd_cbd *cbd = user_data;
if (status == RIL_E_SUCCESS) {
cbd->cb(ril_error_ok(&error), cbd->data);
} else {
cbd->cb(ril_error_failure(&error), cbd->data);
}
}
static void ril_ussd_request(struct ofono_ussd *ussd, int dcs,
const unsigned char *pdu, int len, ofono_ussd_cb_t cb, void *data)
{
struct ofono_error error;
enum sms_charset charset;
struct ril_ussd *ud = ril_ussd_get_data(ussd);
ofono_info("send ussd, len:%d", len);
if (cbs_dcs_decode(dcs, NULL, NULL, &charset, NULL, NULL, NULL)) {
if (charset == SMS_CHARSET_7BIT) {
unsigned char unpacked_buf[182];
long written = 0;
unpack_7bit_own_buf(pdu, len, 0, TRUE,
sizeof(unpacked_buf)-1, &written, 0,
unpacked_buf);
unpacked_buf[written] = 0;
if (written >= 1) {
/*
* When USSD was packed, additional CR
* might have been added (according to
* 23.038 6.1.2.3.1). So if the last
* character is CR, it should be removed
* here.
*
* Over 2 characters long USSD string must
* end with # (checked in valid_ussd_string),
* so it should be safe to remove extra CR.
*/
GRilIoRequest *req = grilio_request_new();
int length = strlen((char *)unpacked_buf);
while (length > 2 &&
unpacked_buf[length-1] == '\r') {
unpacked_buf[--length] = 0;
}
grilio_request_append_utf8_chars(req, (char*)
unpacked_buf, length);
grilio_queue_send_request_full(ud->q, req,
RIL_REQUEST_SEND_USSD, ril_ussd_cb,
ril_ussd_cbd_free,
ril_ussd_cbd_new(cb, data));
grilio_request_unref(req);
return;
}
}
}
cb(ril_error_failure(&error), data);
}
static void ril_ussd_cancel(struct ofono_ussd *ussd,
ofono_ussd_cb_t cb, void *data)
{
struct ril_ussd *ud = ril_ussd_get_data(ussd);
ofono_info("send ussd cancel");
grilio_queue_send_request_full(ud->q, NULL, RIL_REQUEST_CANCEL_USSD,
ril_ussd_cb, ril_ussd_cbd_free, ril_ussd_cbd_new(cb, data));
}
static void ril_ussd_notify(GRilIoChannel *io, guint code,
const void *data, guint len, void *user_data)
{
struct ril_ussd *ud = user_data;
GRilIoParser rilp;
char *ussd_from_network = NULL;
char *type = NULL;
int ussdtype = 0;
ofono_info("ussd_received");
GASSERT(code == RIL_UNSOL_ON_USSD);
grilio_parser_init(&rilp, data, len);
grilio_parser_get_uint32(&rilp, NULL);
type = grilio_parser_get_utf8(&rilp);
ussd_from_network = grilio_parser_get_utf8(&rilp);
ussdtype = g_ascii_xdigit_value(*type);
if (ussd_from_network) {
const int data_len = strlen(ussd_from_network);
DBG("ussd_received, length %d", data_len);
ofono_ussd_notify(ud->ussd, ussdtype, 0xFF,
(const unsigned char *) ussd_from_network, data_len);
} else {
ofono_ussd_notify(ud->ussd, ussdtype, 0, NULL, 0);
}
/* ussd_from_network not freed because core does that if dcs is 0xFF */
g_free(type);
return;
}
static gboolean ril_ussd_register(gpointer user_data)
{
struct ril_ussd *ud = user_data;
DBG("");
GASSERT(ud->timer_id);
ud->timer_id = 0;
ofono_ussd_register(ud->ussd);
/* Register for USSD events */
ud->event_id = grilio_channel_add_unsol_event_handler(ud->io,
ril_ussd_notify, RIL_UNSOL_ON_USSD, ud);
/* Single-shot */
return FALSE;
}
static int ril_ussd_probe(struct ofono_ussd *ussd, unsigned int vendor,
void *data)
{
struct ril_modem *modem = data;
struct ril_ussd *ud = g_try_new0(struct ril_ussd, 1);
DBG("");
ud->ussd = ussd;
ud->io = grilio_channel_ref(ril_modem_io(modem));
ud->q = grilio_queue_new(ud->io);
ud->timer_id = g_idle_add(ril_ussd_register, ud);
ofono_ussd_set_data(ussd, ud);
return 0;
}
static void ril_ussd_remove(struct ofono_ussd *ussd)
{
struct ril_ussd *ud = ril_ussd_get_data(ussd);
DBG("");
ofono_ussd_set_data(ussd, NULL);
if (ud->timer_id > 0) {
g_source_remove(ud->timer_id);
}
grilio_channel_remove_handler(ud->io, ud->event_id);
grilio_channel_unref(ud->io);
grilio_queue_cancel_all(ud->q, FALSE);
grilio_queue_unref(ud->q);
g_free(ud);
}
const struct ofono_ussd_driver ril_ussd_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_ussd_probe,
.remove = ril_ussd_remove,
.request = ril_ussd_request,
.cancel = ril_ussd_cancel
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,399 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_util.h"
#include "ril_log.h"
#include <grilio_channel.h>
#include <sys/socket.h>
#include <ctype.h>
#include "common.h"
#include "netreg.h"
const char *ril_error_to_string(int error)
{
#define RIL_E_(name) case RIL_E_##name: return #name
#define GRILIO_E_(name) case GRILIO_STATUS_##name: return "GRILIO_" #name
static char unknown[12];
switch (error) {
case RIL_E_SUCCESS: return "OK";
GRILIO_E_(TIMEOUT);
GRILIO_E_(CANCELLED);
RIL_E_(RADIO_NOT_AVAILABLE);
RIL_E_(GENERIC_FAILURE);
RIL_E_(PASSWORD_INCORRECT);
RIL_E_(SIM_PIN2);
RIL_E_(SIM_PUK2);
RIL_E_(REQUEST_NOT_SUPPORTED);
RIL_E_(CANCELLED);
RIL_E_(OP_NOT_ALLOWED_DURING_VOICE_CALL);
RIL_E_(OP_NOT_ALLOWED_BEFORE_REG_TO_NW);
RIL_E_(SMS_SEND_FAIL_RETRY);
RIL_E_(SIM_ABSENT);
RIL_E_(SUBSCRIPTION_NOT_AVAILABLE);
RIL_E_(MODE_NOT_SUPPORTED);
RIL_E_(FDN_CHECK_FAILURE);
RIL_E_(ILLEGAL_SIM_OR_ME);
RIL_E_(UNUSED);
RIL_E_(DIAL_MODIFIED_TO_USSD);
RIL_E_(DIAL_MODIFIED_TO_SS);
RIL_E_(DIAL_MODIFIED_TO_DIAL);
RIL_E_(USSD_MODIFIED_TO_DIAL);
RIL_E_(USSD_MODIFIED_TO_SS);
RIL_E_(USSD_MODIFIED_TO_USSD);
RIL_E_(SS_MODIFIED_TO_DIAL);
RIL_E_(SS_MODIFIED_TO_USSD);
RIL_E_(SS_MODIFIED_TO_SS);
RIL_E_(SUBSCRIPTION_NOT_SUPPORTED);
RIL_E_(MISSING_RESOURCE);
RIL_E_(NO_SUCH_ELEMENT);
RIL_E_(INVALID_PARAMETER);
default:
snprintf(unknown, sizeof(unknown), "%d", error);
return unknown;
}
}
const char *ril_request_to_string(guint request)
{
#define RIL_REQUEST_(name) case RIL_REQUEST_##name: return #name
static char unknown[24];
switch (request) {
RIL_REQUEST_(GET_SIM_STATUS);
RIL_REQUEST_(ENTER_SIM_PIN);
RIL_REQUEST_(ENTER_SIM_PUK);
RIL_REQUEST_(ENTER_SIM_PIN2);
RIL_REQUEST_(ENTER_SIM_PUK2);
RIL_REQUEST_(CHANGE_SIM_PIN);
RIL_REQUEST_(CHANGE_SIM_PIN2);
RIL_REQUEST_(ENTER_NETWORK_DEPERSONALIZATION);
RIL_REQUEST_(GET_CURRENT_CALLS);
RIL_REQUEST_(DIAL);
RIL_REQUEST_(GET_IMSI);
RIL_REQUEST_(HANGUP);
RIL_REQUEST_(HANGUP_WAITING_OR_BACKGROUND);
RIL_REQUEST_(HANGUP_FOREGROUND_RESUME_BACKGROUND);
RIL_REQUEST_(SWITCH_HOLDING_AND_ACTIVE);
RIL_REQUEST_(CONFERENCE);
RIL_REQUEST_(UDUB);
RIL_REQUEST_(LAST_CALL_FAIL_CAUSE);
RIL_REQUEST_(SIGNAL_STRENGTH);
RIL_REQUEST_(VOICE_REGISTRATION_STATE);
RIL_REQUEST_(DATA_REGISTRATION_STATE);
RIL_REQUEST_(OPERATOR);
RIL_REQUEST_(RADIO_POWER);
RIL_REQUEST_(DTMF);
RIL_REQUEST_(SEND_SMS);
RIL_REQUEST_(SEND_SMS_EXPECT_MORE);
RIL_REQUEST_(SETUP_DATA_CALL);
RIL_REQUEST_(SIM_IO);
RIL_REQUEST_(SEND_USSD);
RIL_REQUEST_(CANCEL_USSD);
RIL_REQUEST_(GET_CLIR);
RIL_REQUEST_(SET_CLIR);
RIL_REQUEST_(QUERY_CALL_FORWARD_STATUS);
RIL_REQUEST_(SET_CALL_FORWARD);
RIL_REQUEST_(QUERY_CALL_WAITING);
RIL_REQUEST_(SET_CALL_WAITING);
RIL_REQUEST_(SMS_ACKNOWLEDGE);
RIL_REQUEST_(GET_IMEI);
RIL_REQUEST_(GET_IMEISV);
RIL_REQUEST_(ANSWER);
RIL_REQUEST_(DEACTIVATE_DATA_CALL);
RIL_REQUEST_(QUERY_FACILITY_LOCK);
RIL_REQUEST_(SET_FACILITY_LOCK);
RIL_REQUEST_(CHANGE_BARRING_PASSWORD);
RIL_REQUEST_(QUERY_NETWORK_SELECTION_MODE);
RIL_REQUEST_(SET_NETWORK_SELECTION_AUTOMATIC);
RIL_REQUEST_(SET_NETWORK_SELECTION_MANUAL);
RIL_REQUEST_(QUERY_AVAILABLE_NETWORKS);
RIL_REQUEST_(DTMF_START);
RIL_REQUEST_(DTMF_STOP);
RIL_REQUEST_(BASEBAND_VERSION);
RIL_REQUEST_(SEPARATE_CONNECTION);
RIL_REQUEST_(SET_MUTE);
RIL_REQUEST_(GET_MUTE);
RIL_REQUEST_(QUERY_CLIP);
RIL_REQUEST_(LAST_DATA_CALL_FAIL_CAUSE);
RIL_REQUEST_(DATA_CALL_LIST);
RIL_REQUEST_(RESET_RADIO);
RIL_REQUEST_(OEM_HOOK_RAW);
RIL_REQUEST_(OEM_HOOK_STRINGS);
RIL_REQUEST_(SCREEN_STATE);
RIL_REQUEST_(SET_SUPP_SVC_NOTIFICATION);
RIL_REQUEST_(WRITE_SMS_TO_SIM);
RIL_REQUEST_(DELETE_SMS_ON_SIM);
RIL_REQUEST_(SET_BAND_MODE);
RIL_REQUEST_(QUERY_AVAILABLE_BAND_MODE);
RIL_REQUEST_(STK_GET_PROFILE);
RIL_REQUEST_(STK_SET_PROFILE);
RIL_REQUEST_(STK_SEND_ENVELOPE_COMMAND);
RIL_REQUEST_(STK_SEND_TERMINAL_RESPONSE);
RIL_REQUEST_(STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM);
RIL_REQUEST_(EXPLICIT_CALL_TRANSFER);
RIL_REQUEST_(SET_PREFERRED_NETWORK_TYPE);
RIL_REQUEST_(GET_PREFERRED_NETWORK_TYPE);
RIL_REQUEST_(GET_NEIGHBORING_CELL_IDS);
RIL_REQUEST_(SET_LOCATION_UPDATES);
RIL_REQUEST_(CDMA_SET_SUBSCRIPTION_SOURCE);
RIL_REQUEST_(CDMA_SET_ROAMING_PREFERENCE);
RIL_REQUEST_(CDMA_QUERY_ROAMING_PREFERENCE);
RIL_REQUEST_(SET_TTY_MODE);
RIL_REQUEST_(QUERY_TTY_MODE);
RIL_REQUEST_(CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE);
RIL_REQUEST_(CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE);
RIL_REQUEST_(CDMA_FLASH);
RIL_REQUEST_(CDMA_BURST_DTMF);
RIL_REQUEST_(CDMA_VALIDATE_AND_WRITE_AKEY);
RIL_REQUEST_(CDMA_SEND_SMS);
RIL_REQUEST_(CDMA_SMS_ACKNOWLEDGE);
RIL_REQUEST_(GSM_GET_BROADCAST_SMS_CONFIG);
RIL_REQUEST_(GSM_SET_BROADCAST_SMS_CONFIG);
RIL_REQUEST_(GSM_SMS_BROADCAST_ACTIVATION);
RIL_REQUEST_(CDMA_GET_BROADCAST_SMS_CONFIG);
RIL_REQUEST_(CDMA_SET_BROADCAST_SMS_CONFIG);
RIL_REQUEST_(CDMA_SMS_BROADCAST_ACTIVATION);
RIL_REQUEST_(CDMA_SUBSCRIPTION);
RIL_REQUEST_(CDMA_WRITE_SMS_TO_RUIM);
RIL_REQUEST_(CDMA_DELETE_SMS_ON_RUIM);
RIL_REQUEST_(DEVICE_IDENTITY);
RIL_REQUEST_(EXIT_EMERGENCY_CALLBACK_MODE);
RIL_REQUEST_(GET_SMSC_ADDRESS);
RIL_REQUEST_(SET_SMSC_ADDRESS);
RIL_REQUEST_(REPORT_SMS_MEMORY_STATUS);
RIL_REQUEST_(REPORT_STK_SERVICE_IS_RUNNING);
RIL_REQUEST_(CDMA_GET_SUBSCRIPTION_SOURCE);
RIL_REQUEST_(ISIM_AUTHENTICATION);
RIL_REQUEST_(ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU);
RIL_REQUEST_(STK_SEND_ENVELOPE_WITH_STATUS);
RIL_REQUEST_(VOICE_RADIO_TECH);
RIL_REQUEST_(GET_CELL_INFO_LIST);
RIL_REQUEST_(SET_UNSOL_CELL_INFO_LIST_RATE);
RIL_REQUEST_(SET_INITIAL_ATTACH_APN);
RIL_REQUEST_(IMS_REGISTRATION_STATE);
RIL_REQUEST_(IMS_SEND_SMS);
RIL_REQUEST_(SIM_TRANSMIT_APDU_BASIC);
RIL_REQUEST_(SIM_OPEN_CHANNEL);
RIL_REQUEST_(SIM_CLOSE_CHANNEL);
RIL_REQUEST_(SIM_TRANSMIT_APDU_CHANNEL);
RIL_REQUEST_(NV_READ_ITEM);
RIL_REQUEST_(NV_WRITE_ITEM);
RIL_REQUEST_(NV_WRITE_CDMA_PRL);
RIL_REQUEST_(NV_RESET_CONFIG);
RIL_REQUEST_(SET_UICC_SUBSCRIPTION);
RIL_REQUEST_(ALLOW_DATA);
RIL_REQUEST_(GET_HARDWARE_CONFIG);
RIL_REQUEST_(SIM_AUTHENTICATION);
RIL_REQUEST_(GET_DC_RT_INFO);
RIL_REQUEST_(SET_DC_RT_INFO_RATE);
RIL_REQUEST_(SET_DATA_PROFILE);
RIL_REQUEST_(SHUTDOWN);
RIL_REQUEST_(GET_RADIO_CAPABILITY);
RIL_REQUEST_(SET_RADIO_CAPABILITY);
default:
snprintf(unknown, sizeof(unknown), "RIL_REQUEST_%d", request);
return unknown;
}
}
const char *ril_unsol_event_to_string(guint event)
{
#define RIL_UNSOL_(name) case RIL_UNSOL_##name: return #name
static char unknown[24];
switch (event) {
RIL_UNSOL_(RESPONSE_RADIO_STATE_CHANGED);
RIL_UNSOL_(RESPONSE_CALL_STATE_CHANGED);
RIL_UNSOL_(RESPONSE_VOICE_NETWORK_STATE_CHANGED);
RIL_UNSOL_(RESPONSE_NEW_SMS);
RIL_UNSOL_(RESPONSE_NEW_SMS_STATUS_REPORT);
RIL_UNSOL_(RESPONSE_NEW_SMS_ON_SIM);
RIL_UNSOL_(ON_USSD);
RIL_UNSOL_(ON_USSD_REQUEST);
RIL_UNSOL_(NITZ_TIME_RECEIVED);
RIL_UNSOL_(SIGNAL_STRENGTH);
RIL_UNSOL_(DATA_CALL_LIST_CHANGED);
RIL_UNSOL_(SUPP_SVC_NOTIFICATION);
RIL_UNSOL_(STK_SESSION_END);
RIL_UNSOL_(STK_PROACTIVE_COMMAND);
RIL_UNSOL_(STK_EVENT_NOTIFY);
RIL_UNSOL_(STK_CALL_SETUP);
RIL_UNSOL_(SIM_SMS_STORAGE_FULL);
RIL_UNSOL_(SIM_REFRESH);
RIL_UNSOL_(CALL_RING);
RIL_UNSOL_(RESPONSE_SIM_STATUS_CHANGED);
RIL_UNSOL_(RESPONSE_CDMA_NEW_SMS);
RIL_UNSOL_(RESPONSE_NEW_BROADCAST_SMS);
RIL_UNSOL_(CDMA_RUIM_SMS_STORAGE_FULL);
RIL_UNSOL_(RESTRICTED_STATE_CHANGED);
RIL_UNSOL_(ENTER_EMERGENCY_CALLBACK_MODE);
RIL_UNSOL_(CDMA_CALL_WAITING);
RIL_UNSOL_(CDMA_OTA_PROVISION_STATUS);
RIL_UNSOL_(CDMA_INFO_REC);
RIL_UNSOL_(OEM_HOOK_RAW);
RIL_UNSOL_(RINGBACK_TONE);
RIL_UNSOL_(RESEND_INCALL_MUTE);
RIL_UNSOL_(CDMA_SUBSCRIPTION_SOURCE_CHANGED);
RIL_UNSOL_(CDMA_PRL_CHANGED);
RIL_UNSOL_(EXIT_EMERGENCY_CALLBACK_MODE);
RIL_UNSOL_(RIL_CONNECTED);
RIL_UNSOL_(VOICE_RADIO_TECH_CHANGED);
RIL_UNSOL_(CELL_INFO_LIST);
RIL_UNSOL_(RESPONSE_IMS_NETWORK_STATE_CHANGED);
RIL_UNSOL_(UICC_SUBSCRIPTION_STATUS_CHANGED);
RIL_UNSOL_(SRVCC_STATE_NOTIFY);
RIL_UNSOL_(HARDWARE_CONFIG_CHANGED);
RIL_UNSOL_(DC_RT_INFO_CHANGED);
RIL_UNSOL_(RADIO_CAPABILITY);
RIL_UNSOL_(ON_SS);
RIL_UNSOL_(STK_CC_ALPHA_NOTIFY);
default:
snprintf(unknown, sizeof(unknown), "RIL_UNSOL_%d", event);
return unknown;
}
}
const char *ril_radio_state_to_string(int radio_state)
{
#define RADIO_STATE_(name) case RADIO_STATE_##name: return #name
static char unknown[16];
switch (radio_state) {
RADIO_STATE_(OFF);
RADIO_STATE_(UNAVAILABLE);
RADIO_STATE_(SIM_NOT_READY);
RADIO_STATE_(SIM_LOCKED_OR_ABSENT);
RADIO_STATE_(SIM_READY);
RADIO_STATE_(RUIM_NOT_READY);
RADIO_STATE_(RUIM_READY);
RADIO_STATE_(RUIM_LOCKED_OR_ABSENT);
RADIO_STATE_(NV_NOT_READY);
RADIO_STATE_(NV_READY);
RADIO_STATE_(ON);
default:
snprintf(unknown, sizeof(unknown), "%d (?)", radio_state);
return unknown;
}
}
int ril_address_family(const char *addr)
{
if (strchr(addr, ':')) {
return AF_INET6;
} else if (strchr(addr, '.')) {
return AF_INET;
} else {
return AF_UNSPEC;
}
}
/* Returns enum access_technology or -1 on failure. */
int ril_parse_tech(const char *stech, int *ril_tech)
{
int access_tech = -1;
int tech = -1;
if (stech && stech[0]) {
tech = atoi(stech);
switch (tech) {
case RADIO_TECH_GPRS:
case RADIO_TECH_GSM:
access_tech = ACCESS_TECHNOLOGY_GSM;
break;
case RADIO_TECH_EDGE:
access_tech = ACCESS_TECHNOLOGY_GSM_EGPRS;
break;
case RADIO_TECH_UMTS:
access_tech = ACCESS_TECHNOLOGY_UTRAN;
break;
case RADIO_TECH_HSDPA:
access_tech = ACCESS_TECHNOLOGY_UTRAN_HSDPA;
break;
case RADIO_TECH_HSUPA:
access_tech = ACCESS_TECHNOLOGY_UTRAN_HSUPA;
break;
case RADIO_TECH_HSPA:
case RADIO_TECH_HSPAP:
access_tech = ACCESS_TECHNOLOGY_UTRAN_HSDPA_HSUPA;
break;
case RADIO_TECH_LTE:
access_tech = ACCESS_TECHNOLOGY_EUTRAN;
break;
default:
DBG("Unknown RIL tech %s", stech);
/* no break */
case RADIO_TECH_IWLAN:
case RADIO_TECH_UNKNOWN:
tech = -1;
break;
}
}
if (ril_tech) {
*ril_tech = tech;
}
return access_tech;
}
gboolean ril_parse_mcc_mnc(const char *str, struct ofono_network_operator *op)
{
if (str) {
int i;
const char *ptr = str;
/* Three digit country code */
for (i = 0;
i < OFONO_MAX_MCC_LENGTH && *ptr && isdigit(*ptr);
i++) {
op->mcc[i] = *ptr++;
}
op->mcc[i] = 0;
if (i == OFONO_MAX_MCC_LENGTH) {
/* Usually 2 but sometimes 3 digit network code */
for (i=0;
i<OFONO_MAX_MNC_LENGTH && *ptr && isdigit(*ptr);
i++) {
op->mnc[i] = *ptr++;
}
op->mnc[i] = 0;
if (i > 0) {
/*
* Sometimes MCC/MNC are followed by + and
* what looks like the technology code. This
* is of course completely undocumented.
*/
if (*ptr == '+') {
int tech = ril_parse_tech(ptr+1, NULL);
if (tech >= 0) {
op->tech = tech;
}
}
return TRUE;
}
}
}
return FALSE;
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,47 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef RIL_UTIL_H
#define RIL_UTIL_H
#include "ril_types.h"
struct ofono_network_operator;
const char *ril_error_to_string(int error);
const char *ril_request_to_string(guint request);
const char *ril_unsol_event_to_string(guint event);
const char *ril_radio_state_to_string(int radio_state);
int ril_parse_tech(const char *stech, int *ril_tech);
int ril_address_family(const char *addr);
gboolean ril_parse_mcc_mnc(const char *str, struct ofono_network_operator *op);
#define ril_error_init_ok(err) \
((err)->error = 0, (err)->type = OFONO_ERROR_TYPE_NO_ERROR)
#define ril_error_init_failure(err) \
((err)->error = 0, (err)->type = OFONO_ERROR_TYPE_FAILURE)
#define ril_error_ok(err) (ril_error_init_ok(err), err)
#define ril_error_failure(err) (ril_error_init_failure(err), err)
#endif /* RIL_UTIL_H */
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -0,0 +1,865 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2016 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "ril_plugin.h"
#include "ril_constants.h"
#include "ril_util.h"
#include "ril_log.h"
#include "common.h"
/* Amount of ms we wait between CLCC calls */
#define FLAG_NEED_CLIP 1
#define MAX_DTMF_BUFFER 32
enum ril_voicecall_events {
VOICECALL_EVENT_CALL_STATE_CHANGED,
VOICECALL_EVENT_SUPP_SVC_NOTIFICATION,
VOICECALL_EVENT_RINGBACK_TONE,
VOICECALL_EVENT_COUNT,
};
struct ril_voicecall {
GSList *calls;
GRilIoChannel *io;
GRilIoQueue *q;
struct ofono_voicecall *vc;
unsigned int local_release;
unsigned char flags;
ofono_voicecall_cb_t cb;
void *data;
guint timer_id;
gchar *tone_queue;
guint send_dtmf_id;
guint clcc_poll_id;
gulong event_id[VOICECALL_EVENT_COUNT];
gulong supp_svc_notification_id;
gulong ringback_tone_event_id;
};
struct release_id_req {
struct ofono_voicecall *vc;
ofono_voicecall_cb_t cb;
gpointer data;
int id;
};
struct ril_voicecall_change_state_req {
struct ofono_voicecall *vc;
ofono_voicecall_cb_t cb;
gpointer data;
int affected_types;
};
struct lastcause_req {
struct ofono_voicecall *vc;
int id;
};
struct ril_voicecall_req {
struct ofono_voicecall *vc;
ofono_voicecall_cb_t cb;
gpointer data;
};
static void ril_voicecall_send_one_dtmf(struct ril_voicecall *vd);
static void ril_voicecall_clear_dtmf_queue(struct ril_voicecall *vd);
/*
* structs ofono_voicecall and voicecall are fully defined
* in src/voicecall.c; we need (read) access to the
* call objects, so partially redefine them here.
*/
struct ofono_voicecall {
GSList *call_list;
/* ... */
};
struct voicecall {
struct ofono_call *call;
/* ... */
};
static inline struct ril_voicecall *ril_voicecall_get_data(
struct ofono_voicecall *vc)
{
return ofono_voicecall_get_data(vc);
}
static gint ril_voicecall_compare(gconstpointer a, gconstpointer b)
{
const struct ofono_call *ca = a;
const struct ofono_call *cb = b;
if (ca->id < cb->id)
return -1;
if (ca->id > cb->id)
return 1;
return 0;
}
static GSList *ril_voicecall_parse_clcc(const void *data, guint len)
{
GRilIoParser rilp;
GSList *l = NULL;
int num = 0, i;
gchar *number, *name;
grilio_parser_init(&rilp, data, len);
/* Number of RIL_Call structs */
grilio_parser_get_int32(&rilp, &num);
for (i = 0; i < num; i++) {
struct ofono_call *call = g_new(struct ofono_call, 1);
gint tmp;
ofono_call_init(call);
grilio_parser_get_int32(&rilp, &call->status);
grilio_parser_get_uint32(&rilp, &call->id);
grilio_parser_get_int32(&rilp, &call->phone_number.type);
grilio_parser_get_int32(&rilp, NULL); /* isMpty */
tmp = 0;
grilio_parser_get_int32(&rilp, &tmp);
call->direction = (tmp ? /* isMT */
CALL_DIRECTION_MOBILE_TERMINATED :
CALL_DIRECTION_MOBILE_ORIGINATED);
grilio_parser_get_int32(&rilp, NULL); /* als */
grilio_parser_get_int32(&rilp, &call->type); /* isVoice */
grilio_parser_get_int32(&rilp, NULL); /* isVoicePrivacy */
number = grilio_parser_get_utf8(&rilp);
if (number) {
strncpy(call->phone_number.number, number,
OFONO_MAX_PHONE_NUMBER_LENGTH);
g_free(number);
}
grilio_parser_get_int32(&rilp, NULL); /* numberPresentation */
name = grilio_parser_get_utf8(&rilp);
if (name) {
strncpy(call->name, name, OFONO_MAX_CALLER_NAME_LENGTH);
g_free(name);
}
grilio_parser_get_int32(&rilp, NULL); /* namePresentation */
grilio_parser_get_int32(&rilp, &tmp); /* uusInfo */
GASSERT(!tmp);
if (strlen(call->phone_number.number) > 0) {
call->clip_validity = 0;
} else {
call->clip_validity = 2;
}
DBG("[id=%d,status=%d,type=%d,number=%s,name=%s]",
call->id, call->status, call->type,
call->phone_number.number, call->name);
l = g_slist_insert_sorted(l, call, ril_voicecall_compare);
}
return l;
}
/* Valid call statuses have value >= 0 */
static int call_status_with_id(struct ofono_voicecall *vc, int id)
{
GSList *l;
struct voicecall *v;
GASSERT(vc);
for (l = vc->call_list; l; l = l->next) {
v = l->data;
if (v->call->id == id) {
return v->call->status;
}
}
return -1;
}
static void ril_voicecall_lastcause_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct lastcause_req *reqdata = user_data;
struct ofono_voicecall *vc = reqdata->vc;
int tmp;
int id = reqdata->id;
int call_status;
enum ofono_disconnect_reason reason = OFONO_DISCONNECT_REASON_ERROR;
int last_cause = CALL_FAIL_ERROR_UNSPECIFIED;
GRilIoParser rilp;
grilio_parser_init(&rilp, data, len);
if (grilio_parser_get_int32(&rilp, &tmp) && tmp > 0) {
grilio_parser_get_int32(&rilp, &last_cause);
}
/*
* Not all call control cause values specified in 3GPP TS 24.008
* "Mobile radio interface Layer 3 specification; Core network
* protocols", Annex H, are properly reflected in the RIL API.
* For example, cause #21 "call rejected" is mapped to
* CALL_FAIL_ERROR_UNSPECIFIED, and thus indistinguishable
* from a network failure.
*/
switch (last_cause) {
case CALL_FAIL_UNOBTAINABLE_NUMBER:
case CALL_FAIL_NORMAL:
case CALL_FAIL_BUSY:
case CALL_FAIL_NO_ROUTE_TO_DESTINATION:
case CALL_FAIL_CHANNEL_UNACCEPTABLE:
case CALL_FAIL_OPERATOR_DETERMINED_BARRING:
case CALL_FAIL_NO_USER_RESPONDING:
case CALL_FAIL_USER_ALERTING_NO_ANSWER:
case CALL_FAIL_CALL_REJECTED:
case CALL_FAIL_NUMBER_CHANGED:
case CALL_FAIL_ANONYMOUS_CALL_REJECTION:
case CALL_FAIL_PRE_EMPTION:
case CALL_FAIL_DESTINATION_OUT_OF_ORDER:
case CALL_FAIL_INCOMPLETE_NUMBER:
case CALL_FAIL_FACILITY_REJECTED:
reason = OFONO_DISCONNECT_REASON_REMOTE_HANGUP;
break;
case CALL_FAIL_NORMAL_UNSPECIFIED:
call_status = call_status_with_id(vc, id);
if (call_status == CALL_STATUS_ACTIVE ||
call_status == CALL_STATUS_HELD ||
call_status == CALL_STATUS_DIALING ||
call_status == CALL_STATUS_ALERTING) {
reason = OFONO_DISCONNECT_REASON_REMOTE_HANGUP;
} else if (call_status == CALL_STATUS_INCOMING) {
reason = OFONO_DISCONNECT_REASON_LOCAL_HANGUP;
}
break;
case CALL_FAIL_ERROR_UNSPECIFIED:
call_status = call_status_with_id(vc, id);
if (call_status == CALL_STATUS_DIALING ||
call_status == CALL_STATUS_ALERTING) {
reason = OFONO_DISCONNECT_REASON_REMOTE_HANGUP;
}
break;
default:
reason = OFONO_DISCONNECT_REASON_ERROR;
break;
}
ofono_info("Call %d ended with RIL cause %d -> ofono reason %d",
id, last_cause, reason);
ofono_voicecall_disconnected(vc, id, reason, NULL);
}
static void ril_voicecall_clcc_poll_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ril_voicecall *vd = user_data;
GSList *calls;
GSList *n, *o;
struct ofono_error error;
GASSERT(vd->clcc_poll_id);
vd->clcc_poll_id = 0;
if (status != RIL_E_SUCCESS) {
ofono_error("We are polling CLCC and received an error");
ofono_error("All bets are off for call management");
return;
}
calls = ril_voicecall_parse_clcc(data, len);
n = calls;
o = vd->calls;
while (n || o) {
struct ofono_call *nc = n ? n->data : NULL;
struct ofono_call *oc = o ? o->data : NULL;
if (oc && (nc == NULL || (nc->id > oc->id))) {
if (vd->local_release & (1 << oc->id)) {
ofono_voicecall_disconnected(vd->vc, oc->id,
OFONO_DISCONNECT_REASON_LOCAL_HANGUP,
NULL);
} else {
/* Get disconnect cause before informing
* oFono core */
struct lastcause_req *reqdata =
g_new0(struct lastcause_req, 1);
reqdata->vc = vd->vc;
reqdata->id = oc->id;
grilio_queue_send_request_full(vd->q, NULL,
RIL_REQUEST_LAST_CALL_FAIL_CAUSE,
ril_voicecall_lastcause_cb,
g_free, reqdata);
}
ril_voicecall_clear_dtmf_queue(vd);
o = o->next;
} else if (nc && (oc == NULL || (nc->id < oc->id))) {
/* new call, signal it */
if (nc->type) {
ofono_voicecall_notify(vd->vc, nc);
if (vd->cb) {
ofono_voicecall_cb_t cb = vd->cb;
cb(ril_error_ok(&error), vd->data);
vd->cb = NULL;
vd->data = NULL;
}
}
n = n->next;
} else {
/*
* Always use the clip_validity from old call
* the only place this is truly told to us is
* in the CLIP notify, the rest are fudged
* anyway. Useful when RING, CLIP is used,
* and we're forced to use CLCC and clip_validity
* is 1
*/
if (oc->clip_validity == 1) {
nc->clip_validity = oc->clip_validity;
}
nc->cnap_validity = oc->cnap_validity;
/*
* CDIP doesn't arrive as part of CLCC, always
* re-use from the old call
*/
memcpy(&nc->called_number, &oc->called_number,
sizeof(oc->called_number));
/*
* If the CLIP is not provided and the CLIP never
* arrives, or RING is used, then signal the call
* here
*/
if (nc->status == CALL_STATUS_INCOMING &&
(vd->flags & FLAG_NEED_CLIP)) {
if (nc->type) {
ofono_voicecall_notify(vd->vc, nc);
}
vd->flags &= ~FLAG_NEED_CLIP;
} else if (memcmp(nc, oc, sizeof(*nc)) && nc->type) {
ofono_voicecall_notify(vd->vc, nc);
}
n = n->next;
o = o->next;
}
}
g_slist_free_full(vd->calls, g_free);
vd->calls = calls;
vd->local_release = 0;
}
static void ril_voicecall_clcc_poll(struct ril_voicecall *vd)
{
GASSERT(vd);
if (!vd->clcc_poll_id) {
vd->clcc_poll_id = grilio_queue_send_request_full(vd->q,
NULL, RIL_REQUEST_GET_CURRENT_CALLS,
ril_voicecall_clcc_poll_cb, NULL, vd);
}
}
static void ril_voicecall_request_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ril_voicecall_change_state_req *req = user_data;
struct ril_voicecall *vd = ril_voicecall_get_data(req->vc);
struct ofono_error error;
if (status == RIL_E_SUCCESS) {
GSList *l;
if (req->affected_types) {
for (l = vd->calls; l; l = l->next) {
struct ofono_call *call = l->data;
if (req->affected_types & (1 << call->status)) {
vd->local_release |= (1 << call->id);
}
}
}
ril_error_init_ok(&error);
} else {
ofono_error("generic fail");
ril_error_init_failure(&error);
}
ril_voicecall_clcc_poll(vd);
/* We have to callback after we schedule a poll if required */
if (req->cb) {
req->cb(&error, req->data);
}
}
static void ril_voicecall_request(const guint rreq, struct ofono_voicecall *vc,
unsigned int affected_types, GRilIoRequest *ioreq,
ofono_voicecall_cb_t cb, void *data)
{
struct ril_voicecall *vd = ril_voicecall_get_data(vc);
struct ril_voicecall_change_state_req *req;
req = g_new0(struct ril_voicecall_change_state_req, 1);
req->vc = vc;
req->cb = cb;
req->data = data;
req->affected_types = affected_types;
grilio_queue_send_request_full(vd->q, ioreq, rreq,
ril_voicecall_request_cb, g_free, req);
}
static void ril_voicecall_dial_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ril_voicecall_req *cbd = user_data;
struct ofono_voicecall *vc = cbd->vc;
struct ril_voicecall *vd = ril_voicecall_get_data(vc);
if (status == RIL_E_SUCCESS) {
if (vd->cb) {
/* CLCC will update the oFono call list with
* proper ids if it's not done yet */
ril_voicecall_clcc_poll(vd);
}
} else {
struct ofono_error error;
ofono_error("call failed.");
vd->cb = cbd->cb;
vd->data = cbd->data;
cbd->cb(ril_error_failure(&error), cbd->data);
}
}
static void ril_voicecall_dial(struct ofono_voicecall *vc,
const struct ofono_phone_number *ph,
enum ofono_clir_option clir, ofono_voicecall_cb_t cb,
void *data)
{
struct ril_voicecall *vd = ril_voicecall_get_data(vc);
struct ril_voicecall_req *cbd = g_new(struct ril_voicecall_req, 1);
const char *phstr = phone_number_to_string(ph);
GRilIoRequest *req = grilio_request_new();
ofono_info("dialing \"%s\"", phstr);
DBG("%s,%d,0", phstr, clir);
cbd->vc = vc;
cbd->cb = cb;
cbd->data = data;
GASSERT(!vd->cb);
vd->cb = cbd->cb;
vd->data = cbd->data;
grilio_request_append_utf8(req, phstr); /* Number to dial */
grilio_request_append_int32(req, clir); /* CLIR mode */
grilio_request_append_int32(req, 0); /* UUS information (absent) */
grilio_queue_send_request_full(vd->q, req, RIL_REQUEST_DIAL,
ril_voicecall_dial_cb, g_free, cbd);
grilio_request_unref(req);
}
static void ril_voicecall_hangup_all(struct ofono_voicecall *vc,
ofono_voicecall_cb_t cb, void *data)
{
struct ril_voicecall *vd = ril_voicecall_get_data(vc);
struct ofono_error error;
GSList *l;
for (l = vd->calls; l; l = l->next) {
struct ofono_call *call = l->data;
GRilIoRequest *req = grilio_request_sized_new(8);
/* TODO: Hangup just the active ones once we have call
* state tracking (otherwise it can't handle ringing) */
DBG("Hanging up call with id %d", call->id);
grilio_request_append_int32(req, 1); /* Always 1 - AT+CHLD=1x */
grilio_request_append_int32(req, call->id);
/* Send request to RIL */
ril_voicecall_request(RIL_REQUEST_HANGUP, vc, 0x3f, req,
NULL, NULL);
grilio_request_unref(req);
}
/* TODO: Deal in case of an error at hungup */
cb(ril_error_ok(&error), data);
}
static void ril_voicecall_hangup_specific(struct ofono_voicecall *vc,
int id, ofono_voicecall_cb_t cb, void *data)
{
GRilIoRequest *req = grilio_request_sized_new(8);
struct ofono_error error;
DBG("Hanging up call with id %d", id);
grilio_request_append_int32(req, 1); /* Always 1 - AT+CHLD=1x */
grilio_request_append_int32(req, id);
/* Send request to RIL */
ril_voicecall_request(RIL_REQUEST_HANGUP, vc, 0x3f, req, NULL, NULL);
grilio_request_unref(req);
cb(ril_error_ok(&error), data);
}
static void ril_voicecall_call_state_changed_event(GRilIoChannel *io,
guint ril_event, const void *data, guint len, void *user_data)
{
struct ril_voicecall *vd = user_data;
GASSERT(ril_event == RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED);
/* Just need to request the call list again */
ril_voicecall_clcc_poll(vd);
}
static void ril_voicecall_supp_svc_notification_event(GRilIoChannel *io,
guint ril_event, const void *data, guint len, void *user_data)
{
GRilIoParser rilp;
struct ril_voicecall *vd = user_data;
struct ofono_phone_number phone;
int type = 0, code = 0, index = 0;
char *tmp = NULL;
GASSERT(ril_event == RIL_UNSOL_SUPP_SVC_NOTIFICATION);
grilio_parser_init(&rilp, data, len);
grilio_parser_get_int32(&rilp, &type);
grilio_parser_get_int32(&rilp, &code);
grilio_parser_get_int32(&rilp, &index);
grilio_parser_get_int32(&rilp, NULL);
tmp = grilio_parser_get_utf8(&rilp);
if (tmp) {
strncpy(phone.number, tmp, OFONO_MAX_PHONE_NUMBER_LENGTH);
phone.number[OFONO_MAX_PHONE_NUMBER_LENGTH] = 0;
g_free(tmp);
} else {
phone.number[0] = 0;
}
DBG("RIL data: MT/MO: %i, code: %i, index: %i", type, code, index);
/* 0 stands for MO intermediate (support TBD), 1 for MT unsolicited */
if (type == 1) {
ofono_voicecall_ssn_mt_notify(vd->vc, 0, code, index, &phone);
} else {
ofono_error("Unknown SS notification");
}
}
static void ril_voicecall_answer(struct ofono_voicecall *vc,
ofono_voicecall_cb_t cb, void *data)
{
/* Send request to RIL */
DBG("Answering current call");
ril_voicecall_request(RIL_REQUEST_ANSWER, vc, 0, NULL, cb, data);
}
static void ril_voicecall_send_dtmf_cb(GRilIoChannel *io, int status,
const void *data, guint len, void *user_data)
{
struct ril_voicecall *vd = user_data;
GASSERT(vd->send_dtmf_id);
vd->send_dtmf_id = 0;
if (status == RIL_E_SUCCESS) {
/* Remove sent DTMF character from queue */
gchar *tmp = g_strdup(vd->tone_queue + 1);
g_free(vd->tone_queue);
vd->tone_queue = tmp;
/* Send the next one */
ril_voicecall_send_one_dtmf(vd);
} else {
DBG("error=%d", status);
ril_voicecall_clear_dtmf_queue(vd);
}
}
static void ril_voicecall_send_one_dtmf(struct ril_voicecall *vd)
{
if (!vd->send_dtmf_id && vd->tone_queue && vd->tone_queue[0]) {
GRilIoRequest *req = grilio_request_sized_new(4);
/* RIL wants just one character */
DBG("%c", vd->tone_queue[0]);
grilio_request_append_utf8_chars(req, vd->tone_queue, 1);
vd->send_dtmf_id = grilio_queue_send_request_full(vd->q, req,
RIL_REQUEST_DTMF, ril_voicecall_send_dtmf_cb, NULL, vd);
grilio_request_unref(req);
}
}
static void ril_voicecall_send_dtmf(struct ofono_voicecall *vc,
const char *dtmf, ofono_voicecall_cb_t cb, void *data)
{
struct ril_voicecall *vd = ril_voicecall_get_data(vc);
struct ofono_error error;
DBG("Queue '%s'",dtmf);
/*
* Queue any incoming DTMF (up to MAX_DTMF_BUFFER characters),
* send them to RIL one-by-one, immediately call back
* core with no error
*/
g_strlcat(vd->tone_queue, dtmf, MAX_DTMF_BUFFER);
ril_voicecall_send_one_dtmf(vd);
cb(ril_error_ok(&error), data);
}
static void ril_voicecall_clear_dtmf_queue(struct ril_voicecall *vd)
{
g_free(vd->tone_queue);
vd->tone_queue = g_strnfill(MAX_DTMF_BUFFER + 1, '\0');
if (vd->send_dtmf_id) {
grilio_channel_cancel_request(vd->io, vd->send_dtmf_id, FALSE);
vd->send_dtmf_id = 0;
}
}
static void ril_voicecall_clcc_poll_on_success(GRilIoChannel *io,
int status, const void *data, guint len, void *user_data)
{
if (status == RIL_E_SUCCESS) {
ril_voicecall_clcc_poll((struct ril_voicecall *)user_data);
}
}
static void ril_voicecall_create_multiparty(struct ofono_voicecall *vc,
ofono_voicecall_cb_t cb, void *data)
{
struct ril_voicecall *vd = ril_voicecall_get_data(vc);
grilio_queue_send_request_full(vd->q, NULL, RIL_REQUEST_CONFERENCE,
ril_voicecall_clcc_poll_on_success, NULL, vd);
}
static void ril_voicecall_transfer(struct ofono_voicecall *vc,
ofono_voicecall_cb_t cb, void *data)
{
ril_voicecall_request(RIL_REQUEST_EXPLICIT_CALL_TRANSFER,
vc, 0, NULL, cb, data);
}
static void ril_voicecall_private_chat(struct ofono_voicecall *vc, int id,
ofono_voicecall_cb_t cb, void *data)
{
struct ril_voicecall *vd = ril_voicecall_get_data(vc);
GRilIoRequest *req = grilio_request_sized_new(8);
grilio_request_append_int32(req, 1);
grilio_request_append_int32(req, id);
grilio_queue_send_request_full(vd->q, req,
RIL_REQUEST_SEPARATE_CONNECTION,
ril_voicecall_clcc_poll_on_success, NULL, vd);
grilio_request_unref(req);
}
static void ril_voicecall_swap_without_accept(struct ofono_voicecall *vc,
ofono_voicecall_cb_t cb, void *data)
{
ril_voicecall_request(RIL_REQUEST_SWITCH_HOLDING_AND_ACTIVE,
vc, 0, NULL, cb, data);
}
static void ril_voicecall_hold_all_active(struct ofono_voicecall *vc,
ofono_voicecall_cb_t cb, void *data)
{
ril_voicecall_request(RIL_REQUEST_SWITCH_HOLDING_AND_ACTIVE,
vc, 0, NULL, cb, data);
}
static void ril_voicecall_release_all_held(struct ofono_voicecall *vc,
ofono_voicecall_cb_t cb, void *data)
{
ril_voicecall_request(RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,
vc, 0, NULL, cb, data);
}
static void ril_voicecall_release_all_active(struct ofono_voicecall *vc,
ofono_voicecall_cb_t cb, void *data)
{
ril_voicecall_request(RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,
vc, 0, NULL, cb, data);
}
static void ril_voicecall_set_udub(struct ofono_voicecall *vc,
ofono_voicecall_cb_t cb, void *data)
{
ril_voicecall_request(RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,
vc, 0, NULL, cb, data);
}
static gboolean ril_voicecall_enable_supp_svc(struct ril_voicecall *vd)
{
GRilIoRequest *req = grilio_request_sized_new(8);
grilio_request_append_int32(req, 1); /* size of array */
grilio_request_append_int32(req, 1); /* notifications enabled */
grilio_queue_send_request(vd->q, req,
RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION);
grilio_request_unref(req);
/* Makes this a single shot */
return FALSE;
}
static void ril_voicecall_ringback_tone_event(GRilIoChannel *io,
guint code, const void *data, guint len, void *user_data)
{
struct ril_voicecall *vd = user_data;
GRilIoParser rilp;
guint32 playTone = FALSE;
int tmp;
GASSERT(code == RIL_UNSOL_RINGBACK_TONE);
grilio_parser_init(&rilp, data, len);
if (grilio_parser_get_int32(&rilp, &tmp) && tmp > 0) {
grilio_parser_get_uint32(&rilp, &playTone);
}
DBG("play ringback tone: %d", playTone);
ofono_voicecall_ringback_tone_notify(vd->vc, playTone);
}
static gboolean ril_delayed_register(gpointer user_data)
{
struct ril_voicecall *vd = user_data;
GASSERT(vd->timer_id);
vd->timer_id = 0;
ofono_voicecall_register(vd->vc);
/* Initialize call list */
ril_voicecall_clcc_poll(vd);
/* request supplementary service notifications*/
ril_voicecall_enable_supp_svc(vd);
/* Unsol when call state changes */
vd->event_id[VOICECALL_EVENT_CALL_STATE_CHANGED] =
grilio_channel_add_unsol_event_handler(vd->io,
ril_voicecall_call_state_changed_event,
RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, vd);
/* Unsol when call set in hold */
vd->event_id[VOICECALL_EVENT_SUPP_SVC_NOTIFICATION] =
grilio_channel_add_unsol_event_handler(vd->io,
ril_voicecall_supp_svc_notification_event,
RIL_UNSOL_SUPP_SVC_NOTIFICATION, vd);
/* Register for ringback tone notifications */
vd->event_id[VOICECALL_EVENT_RINGBACK_TONE] =
grilio_channel_add_unsol_event_handler(vd->io,
ril_voicecall_ringback_tone_event,
RIL_UNSOL_RINGBACK_TONE, vd);
/* This makes the timeout a single-shot */
return FALSE;
}
static int ril_voicecall_probe(struct ofono_voicecall *vc, unsigned int vendor,
void *data)
{
struct ril_modem *modem = data;
struct ril_voicecall *vd;
DBG("");
vd = g_new0(struct ril_voicecall, 1);
vd->io = grilio_channel_ref(ril_modem_io(modem));
vd->q = grilio_queue_new(vd->io);
vd->vc = vc;
vd->timer_id = g_idle_add(ril_delayed_register, vd);
ril_voicecall_clear_dtmf_queue(vd);
ofono_voicecall_set_data(vc, vd);
return 0;
}
static void ril_voicecall_remove(struct ofono_voicecall *vc)
{
int i;
struct ril_voicecall *vd = ril_voicecall_get_data(vc);
DBG("");
ofono_voicecall_set_data(vc, NULL);
g_slist_foreach(vd->calls, (GFunc) g_free, NULL);
g_slist_free(vd->calls);
for (i=0; i<G_N_ELEMENTS(vd->event_id); i++) {
grilio_channel_remove_handler(vd->io, vd->event_id[i]);
}
if (vd->timer_id > 0) {
g_source_remove(vd->timer_id);
}
grilio_channel_unref(vd->io);
grilio_queue_cancel_all(vd->q, FALSE);
grilio_queue_unref(vd->q);
g_free(vd->tone_queue);
g_free(vd);
}
const struct ofono_voicecall_driver ril_voicecall_driver = {
.name = RILMODEM_DRIVER,
.probe = ril_voicecall_probe,
.remove = ril_voicecall_remove,
.dial = ril_voicecall_dial,
.answer = ril_voicecall_answer,
.hangup_all = ril_voicecall_hangup_all,
.release_specific = ril_voicecall_hangup_specific,
.send_tones = ril_voicecall_send_dtmf,
.create_multiparty = ril_voicecall_create_multiparty,
.transfer = ril_voicecall_transfer,
.private_chat = ril_voicecall_private_chat,
.swap_without_accept = ril_voicecall_swap_without_accept,
.hold_all_active = ril_voicecall_hold_all_active,
.release_all_held = ril_voicecall_release_all_held,
.set_udub = ril_voicecall_set_udub,
.release_all_active = ril_voicecall_release_all_active
};
/*
* Local Variables:
* mode: C
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/

View File

@@ -292,22 +292,19 @@ void handle_sne(size_t len, const unsigned char *msg, char *sne)
list_entry->data;
if (entry) {
/* If one already exists,
delete it */
if (entry->sne)
g_free(entry->sne);
DBG("Adding SNE to entry %d",
phonebook_entry_nbr);
DBG("name %s", entry->name);
g_free(entry->sne);
entry->sne = sne;
} else {
return;
}
}
g_free(sne);
}
}
}
}
void handle_anr(size_t len,const unsigned char *msg,char *anr,
struct pb_file_info *next_file, struct pb_data *pbd)

View File

@@ -375,7 +375,14 @@ gboolean ril_util_parse_sim_status(GRil *gril,
* Do we just make a style-guide exception for PrintBuf operations?
*/
g_ril_append_print_buf(gril,
"(card_state=%d,universal_pin_state=%d,gsm_umts_index=%d,cdma_index=%d,ims_index=%d, ",
"card_state=%d,universal_pin_state=%d,gsm_umts_index=%d,cdma_index=%d,ims_index=%d, ",
status->card_state,
status->pin_state,
status->gsm_umts_index,
status->cdma_index,
status->ims_index);
DBG("card_state=%d, universal_pin_state=%d, gsm_umts_index=%d, cdma_index=%d, ims_index=%d",
status->card_state,
status->pin_state,
status->gsm_umts_index,
@@ -387,13 +394,13 @@ gboolean ril_util_parse_sim_status(GRil *gril,
else
goto done;
DBG("sim num_apps: %d", status->num_apps);
if (status->num_apps > MAX_UICC_APPS) {
ofono_error("SIM error; too many apps: %d", status->num_apps);
status->num_apps = MAX_UICC_APPS;
}
for (i = 0; i < status->num_apps; i++) {
DBG("processing app[%d]", i);
apps[i] = g_try_new0(struct sim_app, 1);
if (apps[i] == NULL) {
ofono_error("Can't allocate app_data");
@@ -437,6 +444,16 @@ gboolean ril_util_parse_sim_status(GRil *gril,
apps[i]->pin_replaced,
apps[i]->pin1_state,
apps[i]->pin2_state);
DBG("app[%d]: type=%d, state=%d, perso_substate=%d, aid_ptr=%s, app_label_ptr=%s, pin1_replaced=%d, pin1=%d, pin2=%d",
i, apps[i]->app_type,
apps[i]->app_state,
apps[i]->perso_substate,
apps[i]->aid_str,
apps[i]->app_str,
apps[i]->pin_replaced,
apps[i]->pin1_state,
apps[i]->pin2_state);
}
done:
@@ -606,8 +623,10 @@ gint ril_util_parse_sms_response(GRil *gril, struct ril_msg *message)
*/
mr = parcel_r_int32(&rilp);
ack_pdu = parcel_r_string(&rilp);
error = parcel_r_int32(&rilp);
/* error: 3GPP 27.005, 3.2.5, -1 if unknown or not applicable */
error = parcel_r_int32(&rilp);
DBG("sms msg ref: %d, error: %d, ack_pdu: %s", mr, error, ack_pdu);
g_ril_append_print_buf(gril, "{%d,%s,%d}",
mr, ack_pdu, error);

View File

@@ -43,6 +43,7 @@
#include "util.h"
#include "gril.h"
#include "grilrequest.h"
#include "grilutil.h"
#include "parcel.h"
#include "ril_constants.h"
@@ -97,11 +98,9 @@ struct sim_data {
guint app_type;
gchar *app_str;
guint app_index;
gboolean sim_registered;
enum ofono_sim_password_type passwd_type;
int retries[OFONO_SIM_PASSWORD_INVALID];
enum ofono_sim_password_type passwd_state;
guint card_state;
guint idle_id;
gboolean initialized;
gboolean removed;
@@ -128,7 +127,8 @@ static void set_path(struct sim_data *sd, struct parcel *rilp,
} else if (sd->app_type == RIL_APPTYPE_SIM) {
len = sim_ef_db_get_path_2g(fileid, db_path);
} else {
ofono_error("Unsupported app_type: 0%x", sd->app_type);
ofono_error("%s Unsupported app_type: 0%x", __func__,
sd->app_type);
}
if (len > 0) {
@@ -187,7 +187,7 @@ static void ril_file_info_cb(struct ril_msg *message, gpointer user_data)
* core will crash.
*/
if (sd->removed == TRUE) {
ofono_error("RIL_CARDSTATE_ABSENT");
ofono_error("%s RIL_CARDSTATE_ABSENT", __func__);
return;
}
@@ -205,14 +205,15 @@ static void ril_file_info_cb(struct ril_msg *message, gpointer user_data)
&sw1,
&sw2,
&response_len)) == NULL) {
ofono_error("Can't parse SIM IO response from RILD");
ofono_error("%s Can't parse SIM IO response", __func__);
decode_ril_error(&error, "FAIL");
goto error;
}
if ((sw1 != 0x90 && sw1 != 0x91 && sw1 != 0x92 && sw1 != 0x9f) ||
(sw1 == 0x90 && sw2 != 0x00)) {
ofono_error("invalid values: sw1: %02x sw2: %02x", sw1, sw2);
ofono_error("%s invalid values: sw1: %02x sw2: %02x", __func__,
sw1, sw2);
memset(&error, 0, sizeof(error));
/* TODO: fix decode_ril_error to take type & error */
@@ -235,7 +236,7 @@ static void ril_file_info_cb(struct ril_msg *message, gpointer user_data)
}
if (!ok) {
ofono_error("parse response failed");
ofono_error("%s parse response failed", __func__);
decode_ril_error(&error, "FAIL");
goto error;
}
@@ -325,7 +326,7 @@ static void ril_file_io_cb(struct ril_msg *message, gpointer user_data)
if (message->error == RIL_E_SUCCESS) {
decode_ril_error(&error, "OK");
} else {
ofono_error("RILD reply failure: %s",
ofono_error("%s RILD reply failure: %s", __func__,
ril_error_to_string(message->error));
goto error;
}
@@ -336,7 +337,7 @@ static void ril_file_io_cb(struct ril_msg *message, gpointer user_data)
&sw1,
&sw2,
&response_len)) == NULL) {
ofono_error("Error parsing IO response");
ofono_error("%s Error parsing IO response", __func__);
goto error;
}
@@ -470,7 +471,7 @@ static void ril_imsi_cb(struct ril_msg *message, gpointer user_data)
DBG("GET IMSI reply - OK");
decode_ril_error(&error, "OK");
} else {
ofono_error("Reply failure: %s",
ofono_error("%s Reply failure: %s", __func__,
ril_error_to_string(message->error));
decode_ril_error(&error, "FAIL");
cb(&error, NULL, cbd->data);
@@ -519,44 +520,6 @@ static void ril_read_imsi(struct ofono_sim *sim, ofono_sim_imsi_cb_t cb,
}
}
void set_pin_lock_state(struct ofono_sim *sim, struct sim_app *app)
{
DBG("pin1:%u,pin2:%u", app->pin1_state, app->pin2_state);
/*
* Updates only pin and pin2 state. Other locks are not dealt here. For
* that a RIL_REQUEST_QUERY_FACILITY_LOCK request should be used.
*/
switch (app->pin1_state) {
case RIL_PINSTATE_ENABLED_NOT_VERIFIED:
case RIL_PINSTATE_ENABLED_VERIFIED:
case RIL_PINSTATE_ENABLED_BLOCKED:
case RIL_PINSTATE_ENABLED_PERM_BLOCKED:
ofono_set_pin_lock_state(sim, OFONO_SIM_PASSWORD_SIM_PIN, TRUE);
break;
case RIL_PINSTATE_DISABLED:
ofono_set_pin_lock_state(
sim, OFONO_SIM_PASSWORD_SIM_PIN, FALSE);
break;
default:
break;
}
switch (app->pin2_state) {
case RIL_PINSTATE_ENABLED_NOT_VERIFIED:
case RIL_PINSTATE_ENABLED_VERIFIED:
case RIL_PINSTATE_ENABLED_BLOCKED:
case RIL_PINSTATE_ENABLED_PERM_BLOCKED:
ofono_set_pin_lock_state(
sim, OFONO_SIM_PASSWORD_SIM_PIN2, TRUE);
break;
case RIL_PINSTATE_DISABLED:
ofono_set_pin_lock_state(
sim, OFONO_SIM_PASSWORD_SIM_PIN2, FALSE);
break;
default:
break;
}
}
static void configure_active_app(struct sim_data *sd,
struct sim_app *app,
guint index)
@@ -627,14 +590,80 @@ static void configure_active_app(struct sim_data *sd,
}
}
static void free_sim_state(struct sim_data *sd)
{
guint i = 0;
sd->passwd_state = OFONO_SIM_PASSWORD_INVALID;
for (i = 0; i < OFONO_SIM_PASSWORD_INVALID; i++)
sd->retries[i] = -1;
sd->removed = TRUE;
sd->initialized = FALSE;
}
static void sim_send_set_uicc_subscription(struct sim_data *sd, int slot_id,
int app_index, int sub_id, int sub_status)
{
struct parcel rilp;
DBG("");
g_ril_request_set_uicc_subscription(sd->ril, slot_id, app_index,
sub_id, sub_status, &rilp);
g_ril_send(sd->ril, RIL_REQUEST_SET_UICC_SUBSCRIPTION, rilp.data,
rilp.size, NULL, NULL, NULL);
}
static int sim_select_uicc_subscription(struct sim_data *sim,
struct sim_status *status, struct sim_app **apps)
{
int slot_id = 0;
int selected_app = -1;
unsigned int i;
for (i = 0; i < status->num_apps; i++) {
switch (apps[i]->app_type) {
case RIL_APPTYPE_UNKNOWN:
continue;
case RIL_APPTYPE_USIM:
case RIL_APPTYPE_RUIM:
if (selected_app != -1) {
switch (apps[selected_app]->app_type) {
case RIL_APPTYPE_USIM:
case RIL_APPTYPE_RUIM:
break;
default:
selected_app = i;
}
} else {
selected_app = i;
}
break;
default:
if (selected_app == -1)
selected_app = i;
}
}
DBG("Select app %d for subscription.", selected_app);
if (selected_app != -1)
/* Number 1 means activates that app */
sim_send_set_uicc_subscription(sim, slot_id, selected_app,
slot_id, 1);
return selected_app;
}
static void sim_status_cb(struct ril_msg *message, gpointer user_data)
{
struct ofono_sim *sim = user_data;
struct sim_data *sd = ofono_sim_get_data(sim);
struct sim_app *apps[MAX_UICC_APPS];
struct sim_status status;
guint i = 0;
guint search_index = -1;
struct parcel rilp;
DBG("");
@@ -642,28 +671,32 @@ static void sim_status_cb(struct ril_msg *message, gpointer user_data)
if (ril_util_parse_sim_status(sd->ril, message, &status, apps) &&
status.num_apps) {
DBG("num_apps: %d gsm_umts_index: %d", status.num_apps,
status.gsm_umts_index);
/* TODO(CDMA): need some kind of logic to
* set the correct app_index,
*/
search_index = status.gsm_umts_index;
int app_index = status.gsm_umts_index;
for (i = 0; i < status.num_apps; i++) {
if (i == search_index &&
apps[i]->app_type != RIL_APPTYPE_UNKNOWN) {
current_active_app = apps[i]->app_type;
configure_active_app(sd, apps[i], i);
set_pin_lock_state(sim, apps[i]);
break;
if (app_index < 0) {
app_index = sim_select_uicc_subscription(sd,
&status, apps);
}
if (app_index >= 0 && app_index < (int)status.num_apps &&
apps[app_index]->app_type != RIL_APPTYPE_UNKNOWN) {
current_active_app = apps[app_index]->app_type;
configure_active_app(sd, apps[app_index], app_index);
}
if (sd->sim_registered == FALSE) {
ofono_sim_register(sim);
sd->sim_registered = TRUE;
} else {
sd->removed = FALSE;
if (sd->passwd_state != OFONO_SIM_PASSWORD_INVALID) {
/*
* ril_util_parse_sim_status returns true only when
* card status is RIL_CARDSTATE_PRESENT,
* ofono_sim_inserted_notify returns if status doesn't
* change. So can notify core always in this branch.
*/
ofono_sim_inserted_notify(sim, TRUE);
/* TODO: There doesn't seem to be any other
* way to force the core SIM code to
* recheck the PIN.
@@ -671,15 +704,8 @@ static void sim_status_cb(struct ril_msg *message, gpointer user_data)
* more appropriate call here??
* __ofono_sim_refresh(sim, NULL, TRUE, TRUE);
*/
DBG("sd->card_state:%u", sd->card_state);
if (sd->card_state != RIL_CARDSTATE_PRESENT) {
ofono_sim_inserted_notify(sim, TRUE);
sd->card_state = RIL_CARDSTATE_PRESENT;
sd->removed = FALSE;
}
}
__ofono_sim_recheck_pin(sim);
}
if (current_online_state == RIL_ONLINE_PREF) {
@@ -705,19 +731,13 @@ static void sim_status_cb(struct ril_msg *message, gpointer user_data)
current_online_state = RIL_ONLINE_PREF;
if (status.card_state == RIL_CARDSTATE_ABSENT) {
DBG("sd->card_state:%u,status.card_state:%u,",
sd->card_state, status.card_state);
ofono_info("RIL_CARDSTATE_ABSENT");
ofono_info("%s: RIL_CARDSTATE_ABSENT", __func__);
free_sim_state(sd);
ofono_sim_inserted_notify(sim, FALSE);
if (sd->card_state == RIL_CARDSTATE_PRESENT)
sd->removed = TRUE;
sd->card_state = RIL_CARDSTATE_ABSENT;
sd->initialized = FALSE;
}
}
/* TODO: if no SIM present, handle emergency calling. */
}
static int send_get_sim_status(struct ofono_sim *sim)
@@ -763,30 +783,22 @@ static void ril_query_passwd_state_cb(struct ril_msg *message, gpointer user_dat
void *data = cbd->data;
struct sim_app *apps[MAX_UICC_APPS];
struct sim_status status;
guint i = 0;
guint search_index = -1;
gint state = ofono_sim_get_state(sim);
if (ril_util_parse_sim_status(sd->ril, message, &status, apps) &&
status.num_apps) {
DBG("num_apps: %d gsm_umts_index: %d", status.num_apps,
status.gsm_umts_index);
/* TODO(CDMA): need some kind of logic to
* set the correct app_index,
*/
search_index = status.gsm_umts_index;
int app_index = status.gsm_umts_index;
for (i = 0; i < status.num_apps; i++) {
if (i == search_index &&
apps[i]->app_type != RIL_APPTYPE_UNKNOWN) {
current_active_app = apps[i]->app_type;
configure_active_app(sd, apps[i], i);
set_pin_lock_state(sim, apps[i]);
break;
}
if (app_index >= 0 && app_index < (int)status.num_apps &&
apps[app_index]->app_type != RIL_APPTYPE_UNKNOWN) {
current_active_app = apps[app_index]->app_type;
configure_active_app(sd, apps[app_index], app_index);
}
ril_util_free_sim_apps(apps, status.num_apps);
}
DBG("passwd_state %u", sd->passwd_state);
@@ -838,8 +850,9 @@ static void ril_pin_change_state_cb(struct ril_msg *message, gpointer user_data)
struct sim_data *sd = cbd->user;
struct parcel rilp;
int retry_count;
int retries[OFONO_SIM_PASSWORD_INVALID];
int passwd_type;
int i;
/* There is no reason to ask SIM status until
* unsolicited sim status change indication
* Looks like state does not change before that.
@@ -849,8 +862,11 @@ static void ril_pin_change_state_cb(struct ril_msg *message, gpointer user_data)
ril_util_init_parcel(message, &rilp);
parcel_r_int32(&rilp);
retry_count = parcel_r_int32(&rilp);
retries[passwd_type] = retry_count;
sd->retries[passwd_type] = retries[passwd_type];
for (i = 0; i < OFONO_SIM_PASSWORD_INVALID; i++)
sd->retries[i] = -1;
sd->retries[passwd_type] = retry_count;
DBG("result=%d passwd_type=%d retry_count=%d",
message->error, passwd_type, retry_count);
@@ -1117,15 +1133,14 @@ static gboolean ril_sim_register(gpointer user)
DBG("");
sd->idle_id = 0;
ofono_sim_register(sim);
send_get_sim_status(sim);
g_ril_register(sd->ril, RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED,
sd->idle_id = 0;
g_ril_register(sd->ril,
RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED,
(GRilNotifyFunc) ril_sim_status_changed, sim);
/* TODO: should we also register for RIL_UNSOL_SIM_REFRESH? */
return FALSE;
}
@@ -1166,12 +1181,15 @@ static int ril_sim_probe(struct ofono_sim *sim, unsigned int vendor,
static void ril_sim_remove(struct ofono_sim *sim)
{
DBG("");
struct sim_data *sd = ofono_sim_get_data(sim);
ofono_sim_set_data(sim, NULL);
if (sd->idle_id > 0)
if (sd->idle_id > 0) {
g_source_remove(sd->idle_id);
sd->idle_id = 0;
}
g_free(sd->aid_str);
g_free(sd->app_str);

View File

@@ -128,9 +128,8 @@ static void bt_connect(struct dundee_device *device,
if (status == 0)
return;
g_free(cbd);
CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
g_free(cbd);
}
struct dundee_device_driver bluetooth_driver = {

View File

@@ -583,7 +583,7 @@ static void have_line(struct at_chat *p, char *str)
return;
/* Check for echo, this should not happen, but lets be paranoid */
if (!strncmp(str, "AT", 2) == TRUE)
if (!strncmp(str, "AT", 2))
goto done;
cmd = g_queue_peek_head(p->command_queue);
@@ -1135,6 +1135,29 @@ static gboolean at_chat_cancel_group(struct at_chat *chat, guint group)
return TRUE;
}
static gpointer at_chat_get_userdata(struct at_chat *chat,
guint group, guint id)
{
GList *l;
struct at_command *c;
if (chat->command_queue == NULL)
return NULL;
l = g_queue_find_custom(chat->command_queue, GUINT_TO_POINTER(id),
at_command_compare_by_id);
if (l == NULL)
return NULL;
c = l->data;
if (c->gid != group)
return NULL;
return c->user_data;
}
static guint at_chat_register(struct at_chat *chat, guint group,
const char *prefix, GAtNotifyFunc func,
gboolean expect_pdu, gpointer user_data,
@@ -1540,6 +1563,14 @@ gboolean g_at_chat_cancel_all(GAtChat *chat)
return at_chat_cancel_group(chat->parent, chat->group);
}
gpointer g_at_chat_get_userdata(GAtChat *chat, guint id)
{
if (chat == NULL)
return NULL;
return at_chat_get_userdata(chat->parent, chat->group, id);
}
guint g_at_chat_register(GAtChat *chat, const char *prefix,
GAtNotifyFunc func, gboolean expect_pdu,
gpointer user_data,

View File

@@ -150,6 +150,8 @@ guint g_at_chat_send_and_expect_short_prompt(GAtChat *chat, const char *cmd,
gboolean g_at_chat_cancel(GAtChat *chat, guint id);
gboolean g_at_chat_cancel_all(GAtChat *chat);
gpointer g_at_chat_get_userdata(GAtChat *chat, guint id);
guint g_at_chat_register(GAtChat *chat, const char *prefix,
GAtNotifyFunc func, gboolean expect_pdu,
gpointer user_data, GDestroyNotify notify);

View File

@@ -64,10 +64,10 @@ gboolean ppp_net_set_mtu(struct ppp_net *net, guint16 mtu)
return FALSE;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, net->if_name, sizeof(ifr.ifr_name));
strncpy(ifr.ifr_name, net->if_name, IFNAMSIZ - 1);
ifr.ifr_mtu = mtu;
err = ioctl(sk, SIOCSIFMTU, (caddr_t) &ifr);
err = ioctl(sk, SIOCSIFMTU, (void *) &ifr);
close(sk);

View File

@@ -42,6 +42,7 @@ struct GDBusClient {
DBusConnection *dbus_conn;
char *service_name;
char *base_path;
char *root_path;
guint watch;
guint added_watch;
guint removed_watch;
@@ -1107,7 +1108,11 @@ static void get_managed_objects(GDBusClient *client)
{
DBusMessage *msg;
if (!client->proxy_added && !client->proxy_removed) {
if (!client->connected)
return;
if ((!client->proxy_added && !client->proxy_removed) ||
!client->root_path) {
refresh_properties(client);
return;
}
@@ -1115,8 +1120,9 @@ static void get_managed_objects(GDBusClient *client)
if (client->get_objects_call != NULL)
return;
msg = dbus_message_new_method_call(client->service_name, "/",
DBUS_INTERFACE_DBUS ".ObjectManager",
msg = dbus_message_new_method_call(client->service_name,
client->root_path,
DBUS_INTERFACE_OBJECT_MANAGER,
"GetManagedObjects");
if (msg == NULL)
return;
@@ -1142,13 +1148,13 @@ static void service_connect(DBusConnection *conn, void *user_data)
g_dbus_client_ref(client);
client->connected = TRUE;
if (client->connect_func)
client->connect_func(conn, client->connect_data);
get_managed_objects(client);
client->connected = TRUE;
g_dbus_client_unref(client);
}
@@ -1156,13 +1162,13 @@ static void service_disconnect(DBusConnection *conn, void *user_data)
{
GDBusClient *client = user_data;
client->connected = FALSE;
g_list_free_full(client->proxy_list, proxy_free);
client->proxy_list = NULL;
if (client->disconn_func) {
if (client->disconn_func)
client->disconn_func(conn, client->disconn_data);
client->connected = FALSE;
}
}
static DBusHandlerResult message_filter(DBusConnection *connection,
@@ -1195,11 +1201,19 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
GDBusClient *g_dbus_client_new(DBusConnection *connection,
const char *service, const char *path)
{
return g_dbus_client_new_full(connection, service, path, "/");
}
GDBusClient *g_dbus_client_new_full(DBusConnection *connection,
const char *service,
const char *path,
const char *root_path)
{
GDBusClient *client;
unsigned int i;
if (connection == NULL)
if (!connection || !service)
return NULL;
client = g_try_new0(GDBusClient, 1);
@@ -1215,6 +1229,7 @@ GDBusClient *g_dbus_client_new(DBusConnection *connection,
client->dbus_conn = dbus_connection_ref(connection);
client->service_name = g_strdup(service);
client->base_path = g_strdup(path);
client->root_path = g_strdup(root_path);
client->connected = FALSE;
client->match_rules = g_ptr_array_sized_new(1);
@@ -1224,14 +1239,18 @@ GDBusClient *g_dbus_client_new(DBusConnection *connection,
service_connect,
service_disconnect,
client, NULL);
if (!root_path)
return g_dbus_client_ref(client);
client->added_watch = g_dbus_add_signal_watch(connection, service,
"/",
client->root_path,
DBUS_INTERFACE_OBJECT_MANAGER,
"InterfacesAdded",
interfaces_added,
client, NULL);
client->removed_watch = g_dbus_add_signal_watch(connection, service,
"/",
client->root_path,
DBUS_INTERFACE_OBJECT_MANAGER,
"InterfacesRemoved",
interfaces_removed,
@@ -1305,6 +1324,7 @@ void g_dbus_client_unref(GDBusClient *client)
g_free(client->service_name);
g_free(client->base_path);
g_free(client->root_path);
g_free(client);
}
@@ -1371,6 +1391,7 @@ gboolean g_dbus_client_set_proxy_handlers(GDBusClient *client,
client->property_changed = property_changed;
client->user_data = user_data;
if (proxy_added || proxy_removed || property_changed)
get_managed_objects(client);
return TRUE;

View File

@@ -216,6 +216,7 @@ struct GDBusSecurityTable {
.flags = G_DBUS_SIGNAL_FLAG_EXPERIMENTAL
void g_dbus_set_flags(int flags);
int g_dbus_get_flags(void);
gboolean g_dbus_register_interface(DBusConnection *connection,
const char *path, const char *name,
@@ -355,6 +356,10 @@ gboolean g_dbus_proxy_set_removed_watch(GDBusProxy *proxy,
GDBusClient *g_dbus_client_new(DBusConnection *connection,
const char *service, const char *path);
GDBusClient *g_dbus_client_new_full(DBusConnection *connection,
const char *service,
const char *path,
const char *root_path);
GDBusClient *g_dbus_client_ref(GDBusClient *client);
void g_dbus_client_unref(GDBusClient *client);

View File

@@ -322,6 +322,7 @@ DBusConnection *g_dbus_setup_private(DBusBusType type, const char *name,
return NULL;
if (setup_bus(conn, name, error) == FALSE) {
dbus_connection_close(conn);
dbus_connection_unref(conn);
return NULL;
}

View File

@@ -1412,7 +1412,10 @@ DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
{
char str[1024];
if (format)
vsnprintf(str, sizeof(str), format, args);
else
str[0] = '\0';
return dbus_message_new_error(message, name, str);
}
@@ -1530,11 +1533,8 @@ gboolean g_dbus_send_error_valist(DBusConnection *connection,
const char *format, va_list args)
{
DBusMessage *error;
char str[1024];
vsnprintf(str, sizeof(str), format, args);
error = dbus_message_new_error(message, name, str);
error = g_dbus_create_error_valist(message, name, format, args);
if (error == NULL)
return FALSE;
@@ -1816,3 +1816,8 @@ void g_dbus_set_flags(int flags)
{
global_flags = flags;
}
int g_dbus_get_flags(void)
{
return global_flags;
}

View File

@@ -523,7 +523,7 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
member = dbus_message_get_member(message);
dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg, DBUS_TYPE_INVALID);
/* Sender is always the owner */
/* If sender != NULL it is always the owner */
for (current = listeners; current != NULL; current = current->next) {
data = current->data;
@@ -531,19 +531,24 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
if (connection != data->connection)
continue;
if (data->owner && g_strcmp0(sender, data->owner) != 0)
if (!sender && data->owner)
continue;
if (data->path && g_strcmp0(path, data->path) != 0)
if (data->owner && g_str_equal(sender, data->owner) == FALSE)
continue;
if (data->interface && g_strcmp0(iface, data->interface) != 0)
if (data->path && g_str_equal(path, data->path) == FALSE)
continue;
if (data->member && g_strcmp0(member, data->member) != 0)
if (data->interface && g_str_equal(iface,
data->interface) == FALSE)
continue;
if (data->argument && g_strcmp0(arg, data->argument) != 0)
if (data->member && g_str_equal(member, data->member) == FALSE)
continue;
if (data->argument && g_str_equal(arg,
data->argument) == FALSE)
continue;
if (data->handle_func) {

View File

@@ -51,9 +51,6 @@
#define COMMAND_FLAG_EXPECT_PDU 0x1
#define COMMAND_FLAG_EXPECT_SHORT_PROMPT 0x2
#define RILD_CMD_SOCKET "/dev/socket/rild"
#define RILD_DBG_SOCKET "/dev/socket/rild-debug"
struct ril_request {
gchar *data;
guint data_len;
@@ -807,7 +804,7 @@ static gboolean node_compare_by_group(struct ril_notify_node *node,
return FALSE;
}
static struct ril_s *create_ril()
static struct ril_s *create_ril(const char *sockpath)
{
struct ril_s *ril;
@@ -819,6 +816,10 @@ static struct ril_s *create_ril()
GError *err = NULL;
char *path = "/etc/ofono/ril_subscription.conf";
DBG("sockpath: %s", sockpath);
if (!sockpath)
return NULL;
ril = g_try_new0(struct ril_s, 1);
if (ril == NULL)
return ril;
@@ -841,7 +842,7 @@ static struct ril_s *create_ril()
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, RILD_CMD_SOCKET, sizeof(addr.sun_path) - 1);
strncpy(addr.sun_path, sockpath, sizeof(addr.sun_path) - 1);
if (connect(ril->sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
ofono_error("%s: can't connect to RILD: %s (%d)\n",
@@ -1074,15 +1075,16 @@ void g_ril_init_parcel(struct ril_msg *message, struct parcel *rilp)
rilp->offset = 0;
}
GRil *g_ril_new()
GRil *g_ril_new(const char *sockpath)
{
DBG("");
GRil *ril;
ril = g_try_new0(GRil, 1);
if (ril == NULL)
return NULL;
ril->parent = create_ril();
ril->parent = create_ril(sockpath);
if (ril->parent == NULL) {
g_free(ril);
return NULL;

View File

@@ -93,7 +93,7 @@ extern char print_buf[];
void g_ril_init_parcel(struct ril_msg *message, struct parcel *rilp);
GRil *g_ril_new();
GRil *g_ril_new(const char *sockpath);
GIOChannel *g_ril_get_channel(GRil *ril);
GRilIO *g_ril_get_io(GRil *ril);

View File

@@ -211,3 +211,24 @@ error:
OFONO_EINVAL(error);
return FALSE;
}
void g_ril_request_set_uicc_subscription(GRil *gril, int slot_id,
int app_index,
int sub_id,
int sub_status,
struct parcel *rilp)
{
parcel_init(rilp);
parcel_w_int32(rilp, slot_id);
parcel_w_int32(rilp, app_index);
parcel_w_int32(rilp, sub_id);
parcel_w_int32(rilp, sub_status);
g_ril_append_print_buf(gril, "(%d, %d, %d, %d(%s))",
slot_id,
app_index,
sub_id,
sub_status,
sub_status ? "ACTIVATE" : "DEACTIVATE");
}

View File

@@ -56,6 +56,12 @@ gboolean g_ril_request_setup_data_call(GRil *gril,
struct parcel *rilp,
struct ofono_error *error);
void g_ril_request_set_uicc_subscription(GRil *gril, int slot_id,
int app_index,
int sub_id,
int sub_status,
struct parcel *rilp);
#ifdef __cplusplus
}
#endif

View File

@@ -137,6 +137,7 @@ const char *ril_cardstate_to_string(int card_state)
const char *ril_error_to_string(int error)
{
static char unknown[24];
switch (error) {
case RIL_E_SUCCESS: return "SUCCESS";
case RIL_E_RADIO_NOT_AVAILABLE: return "RADIO_NOT_AVAILABLE";
@@ -157,7 +158,9 @@ const char *ril_error_to_string(int error)
case RIL_E_MODE_NOT_SUPPORTED: return "MODE_NOT_SUPPORTED";
case RIL_E_FDN_CHECK_FAILURE: return "FDN_CHECK_FAILURE";
case RIL_E_ILLEGAL_SIM_OR_ME: return "ILLEGAL_SIM_OR_ME";
default: return "<unknown errno>";
default:
snprintf(unknown, sizeof(unknown), "%d", error);
return unknown;
}
}
@@ -183,6 +186,7 @@ const char *ril_pinstate_to_string(int pin_state)
const char *ril_request_id_to_string(int req)
{
static char unknown[24];
switch (req) {
case RIL_REQUEST_GET_SIM_STATUS:
return "RIL_REQUEST_GET_SIM_STATUS";
@@ -398,13 +402,17 @@ const char *ril_request_id_to_string(int req)
return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS:
return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
case RIL_REQUEST_SET_UICC_SUBSCRIPTION:
return "RIL_REQUEST_SET_UICC_SUBSCRIPTION";
default:
return "<INVALID>";
snprintf(unknown, sizeof(unknown), "RIL_REQUEST_%d", req);
return unknown;
}
}
const char *ril_unsol_request_to_string(int request)
{
static char unknown[24];
switch (request) {
case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
@@ -477,7 +485,8 @@ const char *ril_unsol_request_to_string(int request)
case RIL_UNSOL_SUPP_SVC_NOTIFICATION:
return "UNSOL_SUPP_SVC_NOTIFICATION";
default:
return "<unknown request>";
snprintf(unknown, sizeof(unknown), "UNSOL_%d", request);
return unknown;
}
}

View File

@@ -334,7 +334,7 @@
#define RIL_REQUEST_MODIFY_QOS 115
#define RIL_REQUEST_SUSPEND_QOS 116
#define RIL_REQUEST_RESUME_QOS 117
#define RIL_REQUEST_SET_UICC_SUBSCRIPTION 118
#define RIL_REQUEST_SET_UICC_SUBSCRIPTION 122
#define RIL_REQUEST_SET_DATA_SUBSCRIPTION 119
#define RIL_REQUEST_GET_UICC_SUBSCRIPTION 120
#define RIL_REQUEST_GET_DATA_SUBSCRIPTION 121

View File

@@ -101,6 +101,8 @@ struct ofono_modem *ofono_gprs_context_get_modem(struct ofono_gprs_context *gc);
void ofono_gprs_context_set_type(struct ofono_gprs_context *gc,
enum ofono_gprs_context_type type);
enum ofono_gprs_context_type ofono_gprs_context_get_type(
struct ofono_gprs_context *gc);
void ofono_gprs_context_set_interface(struct ofono_gprs_context *gc,
const char *interface);

View File

@@ -61,6 +61,8 @@ void ofono_gprs_suspend_notify(struct ofono_gprs *gprs, int cause);
void ofono_gprs_resume_notify(struct ofono_gprs *gprs);
void ofono_gprs_bearer_notify(struct ofono_gprs *gprs, int bearer);
struct ofono_modem *ofono_gprs_get_modem(struct ofono_gprs *gprs);
int ofono_gprs_driver_register(const struct ofono_gprs_driver *d);
void ofono_gprs_driver_unregister(const struct ofono_gprs_driver *d);
@@ -78,7 +80,7 @@ void ofono_gprs_set_cid_range(struct ofono_gprs *gprs,
void ofono_gprs_add_context(struct ofono_gprs *gprs,
struct ofono_gprs_context *gc);
struct ofono_modem *ofono_gprs_get_modem(struct ofono_gprs *gprs);
ofono_bool_t ofono_gprs_get_roaming_allowed(struct ofono_gprs *gprs);
#ifdef __cplusplus
}

View File

@@ -41,6 +41,7 @@ struct ofono_handsfree_card_driver {
void (*connect)(struct ofono_handsfree_card *card,
ofono_handsfree_card_connect_cb_t cb,
void *data);
void (*sco_connected_hint)(struct ofono_handsfree_card *card);
};
struct ofono_handsfree_card *ofono_handsfree_card_create(unsigned int vendor,

View File

@@ -41,13 +41,18 @@ extern void ofono_error(const char *format, ...)
extern void ofono_debug(const char *format, ...)
__attribute__((format(printf, 1, 2)));
#define OFONO_DEBUG_ALIGN 8
#define OFONO_DEBUG_ATTR \
__attribute__((used, section("__debug"), aligned(OFONO_DEBUG_ALIGN)))
struct ofono_debug_desc {
const char *name;
const char *file;
#define OFONO_DEBUG_FLAG_DEFAULT (0)
#define OFONO_DEBUG_FLAG_PRINT (1 << 0)
unsigned int flags;
} __attribute__((aligned(8)));
void (*notify)(struct ofono_debug_desc* desc);
} __attribute__((aligned(OFONO_DEBUG_ALIGN)));
/**
* DBG:
@@ -58,8 +63,7 @@ struct ofono_debug_desc {
* name it is called in.
*/
#define DBG(fmt, arg...) do { \
static struct ofono_debug_desc __ofono_debug_desc \
__attribute__((used, section("__debug"), aligned(8))) = { \
static struct ofono_debug_desc __ofono_debug_desc OFONO_DEBUG_ATTR = { \
.file = __FILE__, .flags = OFONO_DEBUG_FLAG_DEFAULT, \
}; \
if (__ofono_debug_desc.flags & OFONO_DEBUG_FLAG_PRINT) \

View File

@@ -133,6 +133,9 @@ void ofono_radio_settings_remove(struct ofono_radio_settings *rs);
void ofono_radio_settings_set_data(struct ofono_radio_settings *rs, void *data);
void *ofono_radio_settings_get_data(struct ofono_radio_settings *rs);
struct ofono_modem *ofono_radio_settings_get_modem(
struct ofono_radio_settings *rs);
#ifdef __cplusplus
}
#endif

View File

@@ -199,10 +199,6 @@ const unsigned char *ofono_sim_get_cphs_service_table(struct ofono_sim *sim);
enum ofono_sim_password_type ofono_sim_get_password_type(struct ofono_sim *sim);
void ofono_set_pin_lock_state(struct ofono_sim *sim,
enum ofono_sim_password_type type,
ofono_bool_t state);
unsigned int ofono_sim_add_state_watch(struct ofono_sim *sim,
ofono_sim_state_event_cb_t cb,
void *data, ofono_destroy_func destroy);

View File

@@ -83,6 +83,12 @@ struct ofono_error {
#define OFONO_MAX_PHONE_NUMBER_LENGTH 80
#define OFONO_MAX_CALLER_NAME_LENGTH 80
/* Number types, 3GPP TS 24.008 subclause 10.5.4.7, octect 3 */
/* Unknown, ISDN numbering plan */
#define OFONO_NUMBER_TYPE_UNKNOWN 129
/* International, ISDN numbering plan */
#define OFONO_NUMBER_TYPE_INTERNATIONAL 145
struct ofono_phone_number {
char number[OFONO_MAX_PHONE_NUMBER_LENGTH + 1];
int type;

View File

@@ -52,23 +52,25 @@
#include <ofono/gprs.h>
#include <ofono/gprs-context.h>
static int tc65_probe(struct ofono_modem *modem)
#include <drivers/atmodem/vendor.h>
static int cinterion_probe(struct ofono_modem *modem)
{
return 0;
}
static void tc65_remove(struct ofono_modem *modem)
static void cinterion_remove(struct ofono_modem *modem)
{
}
static void tc65_debug(const char *str, void *user_data)
static void cinterion_debug(const char *str, void *user_data)
{
const char *prefix = user_data;
ofono_info("%s%s", prefix, str);
}
static int tc65_enable(struct ofono_modem *modem)
static int cinterion_enable(struct ofono_modem *modem)
{
GAtChat *chat;
GIOChannel *channel;
@@ -102,6 +104,9 @@ static int tc65_enable(struct ofono_modem *modem)
return -EIO;
/*
* (Cinterion plugin is based on tc65 plugin. Comment left in but may
* not be applicable in the general case)
*
* TC65 works almost as the 27.007 says. But for example after
* AT+CRSM the modem replies with the data in the queried EF and
* writes three pairs of <CR><LF> after the data and before OK.
@@ -116,14 +121,14 @@ static int tc65_enable(struct ofono_modem *modem)
return -ENOMEM;
if (getenv("OFONO_AT_DEBUG"))
g_at_chat_set_debug(chat, tc65_debug, "");
g_at_chat_set_debug(chat, cinterion_debug, "");
ofono_modem_set_data(modem, chat);
return 0;
}
static int tc65_disable(struct ofono_modem *modem)
static int cinterion_disable(struct ofono_modem *modem)
{
GAtChat *chat = ofono_modem_get_data(modem);
@@ -149,7 +154,7 @@ static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
cb(&error, cbd->data);
}
static void tc65_set_online(struct ofono_modem *modem, ofono_bool_t online,
static void cinterion_set_online(struct ofono_modem *modem, ofono_bool_t online,
ofono_modem_online_cb_t cb, void *user_data)
{
GAtChat *chat = ofono_modem_get_data(modem);
@@ -161,12 +166,12 @@ static void tc65_set_online(struct ofono_modem *modem, ofono_bool_t online,
if (g_at_chat_send(chat, command, NULL, set_online_cb, cbd, g_free))
return;
g_free(cbd);
CALLBACK_WITH_FAILURE(cb, cbd->data);
g_free(cbd);
}
static void tc65_pre_sim(struct ofono_modem *modem)
static void cinterion_pre_sim(struct ofono_modem *modem)
{
GAtChat *chat = ofono_modem_get_data(modem);
struct ofono_sim *sim;
@@ -181,7 +186,7 @@ static void tc65_pre_sim(struct ofono_modem *modem)
ofono_sim_inserted_notify(sim, TRUE);
}
static void tc65_post_sim(struct ofono_modem *modem)
static void cinterion_post_sim(struct ofono_modem *modem)
{
GAtChat *chat = ofono_modem_get_data(modem);
@@ -192,7 +197,7 @@ static void tc65_post_sim(struct ofono_modem *modem)
ofono_sms_create(modem, 0, "atmodem", chat);
}
static void tc65_post_online(struct ofono_modem *modem)
static void cinterion_post_online(struct ofono_modem *modem)
{
GAtChat *chat = ofono_modem_get_data(modem);
struct ofono_message_waiting *mw;
@@ -204,7 +209,7 @@ static void tc65_post_online(struct ofono_modem *modem)
ofono_ussd_create(modem, 0, "atmodem", chat);
ofono_call_forwarding_create(modem, 0, "atmodem", chat);
ofono_call_settings_create(modem, 0, "atmodem", chat);
ofono_netreg_create(modem, 0, "atmodem", chat);
ofono_netreg_create(modem, OFONO_VENDOR_CINTERION, "atmodem", chat);
ofono_call_meter_create(modem, 0, "atmodem", chat);
ofono_call_barring_create(modem, 0, "atmodem", chat);
@@ -219,27 +224,27 @@ static void tc65_post_online(struct ofono_modem *modem)
ofono_message_waiting_register(mw);
}
static struct ofono_modem_driver tc65_driver = {
.name = "tc65",
.probe = tc65_probe,
.remove = tc65_remove,
.enable = tc65_enable,
.disable = tc65_disable,
.set_online = tc65_set_online,
.pre_sim = tc65_pre_sim,
.post_sim = tc65_post_sim,
.post_online = tc65_post_online,
static struct ofono_modem_driver cinterion_driver = {
.name = "cinterion",
.probe = cinterion_probe,
.remove = cinterion_remove,
.enable = cinterion_enable,
.disable = cinterion_disable,
.set_online = cinterion_set_online,
.pre_sim = cinterion_pre_sim,
.post_sim = cinterion_post_sim,
.post_online = cinterion_post_online,
};
static int tc65_init(void)
static int cinterion_init(void)
{
return ofono_modem_driver_register(&tc65_driver);
return ofono_modem_driver_register(&cinterion_driver);
}
static void tc65_exit(void)
static void cinterion_exit(void)
{
ofono_modem_driver_unregister(&tc65_driver);
ofono_modem_driver_unregister(&cinterion_driver);
}
OFONO_PLUGIN_DEFINE(tc65, "Cinterion TC65 driver plugin", VERSION,
OFONO_PLUGIN_PRIORITY_DEFAULT, tc65_init, tc65_exit)
OFONO_PLUGIN_DEFINE(cinterion, "Cinterion driver plugin", VERSION,
OFONO_PLUGIN_PRIORITY_DEFAULT, cinterion_init, cinterion_exit)

273
ofono/plugins/debuglog.c Normal file
View File

@@ -0,0 +1,273 @@
/*
*
* oFono - Open Source Telephony
*
* Copyright (C) 2015 Jolla Ltd. All rights reserved.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gdbus.h>
#include <string.h>
#define OFONO_API_SUBJECT_TO_CHANGE
#include <ofono/plugin.h>
#include <ofono/log.h>
#include <ofono.h>
#define DEBUGLOG_INTERFACE OFONO_SERVICE ".DebugLog"
#define DEBUGLOG_PATH "/"
#define DEBUGLOG_CHANGED_SIGNAL "Changed"
static DBusConnection *connection = NULL;
extern struct ofono_debug_desc __start___debug[];
extern struct ofono_debug_desc __stop___debug[];
static void debuglog_signal(DBusConnection *conn, const char *name,
guint flags)
{
DBusMessage *signal = dbus_message_new_signal(DEBUGLOG_PATH,
DEBUGLOG_INTERFACE, DEBUGLOG_CHANGED_SIGNAL);
if (signal) {
DBusMessageIter iter;
const dbus_bool_t on = (flags & OFONO_DEBUG_FLAG_PRINT) != 0;
dbus_message_iter_init_append(signal, &iter);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &on);
g_dbus_send_message(conn, signal);
}
}
static GHashTable *debuglog_update_flags_hash(GHashTable *hash,
const char *name, guint flags)
{
if (name) {
gpointer key = (gpointer)name;
guint value;
if (!hash) {
hash = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, NULL);
}
value = GPOINTER_TO_INT(g_hash_table_lookup(hash, key));
value |= flags;
g_hash_table_insert(hash, key, GINT_TO_POINTER(value));
}
return hash;
}
static gboolean debuglog_match(const char* name, const char* pattern)
{
return name && g_pattern_match_simple(pattern, name);
}
static void debuglog_update(DBusConnection *conn, const char* pattern,
guint set_flags, guint clear_flags)
{
const guint flags = set_flags | clear_flags;
struct ofono_debug_desc *start = __start___debug;
struct ofono_debug_desc *stop = __stop___debug;
struct ofono_debug_desc *desc;
GHashTable *hash = NULL;
if (!start || !stop)
return;
for (desc = start; desc < stop; desc++) {
const char *matched = NULL;
if (debuglog_match(desc->file, pattern)) {
matched = desc->file;
} else if (debuglog_match(desc->name, pattern)) {
matched = desc->name;
}
if (matched) {
const guint old_flags = (desc->flags & flags);
desc->flags |= set_flags;
desc->flags &= ~clear_flags;
if ((desc->flags & flags) != old_flags) {
hash = debuglog_update_flags_hash(hash,
matched, desc->flags);
if (desc->notify) {
desc->notify(desc);
}
}
}
}
if (hash) {
GList *entry, *names = g_hash_table_get_keys(hash);
for (entry = names; entry; entry = entry->next) {
debuglog_signal(conn, entry->data,
GPOINTER_TO_INT(g_hash_table_lookup(
hash, entry->data)));
}
g_list_free(names);
g_hash_table_destroy(hash);
}
}
static DBusMessage *debuglog_handle(DBusConnection *conn, DBusMessage *msg,
guint set_flags, guint clear_flags)
{
const char *pattern;
if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern,
DBUS_TYPE_INVALID)) {
debuglog_update(conn, pattern, set_flags, clear_flags);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
} else {
return __ofono_error_invalid_args(msg);
}
}
static DBusMessage *debuglog_enable(DBusConnection *conn,
DBusMessage *msg, void *data)
{
return debuglog_handle(conn, msg, OFONO_DEBUG_FLAG_PRINT, 0);
}
static DBusMessage *debuglog_disable(DBusConnection *conn,
DBusMessage *msg, void *data)
{
return debuglog_handle(conn, msg, 0, OFONO_DEBUG_FLAG_PRINT);
}
static gint debuglog_list_compare(gconstpointer a, gconstpointer b)
{
return strcmp(a, b);
}
static void debuglog_list_append(DBusMessageIter *iter, const char *name,
guint flags)
{
DBusMessageIter entry;
dbus_bool_t enabled = (flags & OFONO_DEBUG_FLAG_PRINT) != 0;
dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &name);
dbus_message_iter_append_basic(&entry, DBUS_TYPE_BOOLEAN, &enabled);
dbus_message_iter_close_container(iter, &entry);
}
static DBusMessage *debuglog_list(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply = dbus_message_new_method_return(msg);
if (reply) {
struct ofono_debug_desc *start = __start___debug;
struct ofono_debug_desc *stop = __stop___debug;
DBusMessageIter iter, array;
dbus_message_iter_init_append(reply, &iter);
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
"(sb)", &array);
if (start && stop) {
struct ofono_debug_desc *desc;
GList *names, *entry;
GHashTable *hash = g_hash_table_new_full(g_str_hash,
g_str_equal, NULL, NULL);
for (desc = start; desc < stop; desc++) {
debuglog_update_flags_hash(hash, desc->file,
desc->flags);
debuglog_update_flags_hash(hash, desc->name,
desc->flags);
}
names = g_list_sort(g_hash_table_get_keys(hash),
debuglog_list_compare);
for (entry = names; entry; entry = entry->next) {
const char *name = entry->data;
debuglog_list_append(&array, name,
GPOINTER_TO_INT(g_hash_table_lookup(
hash, name)));
}
g_list_free(names);
g_hash_table_destroy(hash);
}
dbus_message_iter_close_container(&iter, &array);
}
return reply;
}
static const GDBusMethodTable debuglog_methods[] = {
{ GDBUS_METHOD("Enable", GDBUS_ARGS({ "pattern", "s" }), NULL,
debuglog_enable) },
{ GDBUS_METHOD("Disable", GDBUS_ARGS({ "pattern", "s" }), NULL,
debuglog_disable) },
{ GDBUS_METHOD("List", NULL, GDBUS_ARGS({ "list", "a(sb)" }),
debuglog_list) },
{ },
};
static const GDBusSignalTable debuglog_signals[] = {
{ GDBUS_SIGNAL(DEBUGLOG_CHANGED_SIGNAL,
GDBUS_ARGS({ "name", "s" }, { "enabled", "b" })) },
{ }
};
static int debuglog_init(void)
{
DBG("");
connection = ofono_dbus_get_connection();
if (!connection)
return -1;
if (!g_dbus_register_interface(connection, DEBUGLOG_PATH,
DEBUGLOG_INTERFACE, debuglog_methods, debuglog_signals,
NULL, NULL, NULL)) {
ofono_error("debuglog: failed to register "
DEBUGLOG_INTERFACE);
return -1;
}
return 0;
}
static void debuglog_exit(void)
{
DBG("");
if (connection) {
g_dbus_unregister_interface(connection, DEBUGLOG_PATH,
DEBUGLOG_INTERFACE);
dbus_connection_unref(connection);
connection = NULL;
}
}
OFONO_PLUGIN_DEFINE(debuglog, "Debug log control interface",
VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT,
debuglog_init, debuglog_exit)

View File

@@ -70,6 +70,7 @@ struct hfp {
struct hfp_slc_info info;
DBusMessage *msg;
struct ofono_handsfree_card *card;
unsigned int bcc_id;
};
static const char *none_prefix[] = { NULL };
@@ -373,8 +374,12 @@ static void bcc_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
struct cb_data *cbd = user_data;
ofono_handsfree_card_connect_cb_t cb = cbd->cb;
struct ofono_handsfree_card *card = cbd->user;
struct hfp *hfp = ofono_handsfree_card_get_data(card);
struct ofono_error error;
hfp->bcc_id = 0;
decode_at_error(&error, g_at_result_final_response(result));
cb(&error, cbd->data);
@@ -391,7 +396,10 @@ static void hfp16_card_connect(struct ofono_handsfree_card *card,
info->ag_features & HFP_AG_FEATURE_CODEC_NEGOTIATION) {
struct cb_data *cbd = cb_data_new(cb, data);
g_at_chat_send(info->chat, "AT+BCC", NULL, bcc_cb, cbd, g_free);
cbd->user = card;
hfp->bcc_id = g_at_chat_send(info->chat, "AT+BCC",
none_prefix, bcc_cb,
cbd, g_free);
return;
}
@@ -404,11 +412,40 @@ static void hfp16_card_connect(struct ofono_handsfree_card *card,
ofono_handsfree_card_connect_sco(card);
}
static void hfp16_sco_connected_hint(struct ofono_handsfree_card *card)
{
struct hfp *hfp = ofono_handsfree_card_get_data(card);
struct hfp_slc_info *info = &hfp->info;
struct cb_data *cbd;
ofono_handsfree_card_connect_cb_t cb;
/*
* SCO has just been connected, probably initiated by the AG.
* If we have any outstanding BCC requests, then lets cancel these
* as they're no longer needed
*/
if (hfp->bcc_id == 0)
return;
cbd = g_at_chat_get_userdata(info->chat, hfp->bcc_id);
if (cbd == NULL)
return;
cb = cbd->cb;
CALLBACK_WITH_SUCCESS(cb, cbd->data);
/* cbd will be freed once cancel is processed */
g_at_chat_cancel(info->chat, hfp->bcc_id);
hfp->bcc_id = 0;
}
static struct ofono_handsfree_card_driver hfp16_hf_driver = {
.name = HFP16_HF_DRIVER,
.probe = hfp16_card_probe,
.remove = hfp16_card_remove,
.connect = hfp16_card_connect,
.sco_connected_hint = hfp16_sco_connected_hint,
};
static ofono_bool_t device_path_compare(struct ofono_modem *modem,
@@ -702,8 +739,17 @@ static void modem_register_from_proxy(GDBusProxy *proxy, const char *path)
return;
dbus_message_iter_get_basic(&iter, &paired);
if (paired == FALSE)
if (paired == FALSE) {
modem = ofono_modem_find(device_path_compare, (void *) path);
if (modem != NULL) {
ofono_modem_remove(modem);
g_dbus_proxy_set_removed_watch(proxy, NULL, NULL);
g_dbus_proxy_set_property_watch(proxy, NULL, NULL);
}
return;
}
if (g_dbus_proxy_get_property(proxy, "UUIDs", &iter) == FALSE)
return;

View File

@@ -204,7 +204,7 @@ static void reachable_cb(const GIsiMessage *msg, void *data)
struct ofono_modem *om = data;
struct isi_data *isi = ofono_modem_get_data(om);
if (!g_isi_msg_error(msg) < 0)
if (g_isi_msg_error(msg) < 0)
return;
ISI_RESOURCE_DBG(msg);

View File

@@ -238,7 +238,7 @@ static void mtc_reachable_cb(const GIsiMessage *msg, void *data)
struct ofono_modem *modem = data;
struct isi_data *isi = ofono_modem_get_data(modem);
if (!g_isi_msg_error(msg) < 0)
if (g_isi_msg_error(msg) < 0)
return;
ISI_RESOURCE_DBG(msg);

View File

@@ -2,7 +2,7 @@
*
* oFono - Open Source Telephony
*
* Copyright (C) 2012-2013 Jolla Ltd.
* Copyright (C) 2012-2015 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -32,12 +32,9 @@
#include <ofono/plugin.h>
#include <ofono/log.h>
#include <ofono/nettime.h>
#include <ofono/types.h>
#include "ofono.h"
#include "common.h"
struct nt_data {
gboolean time_available;
gboolean time_pending;
@@ -48,26 +45,32 @@ struct nt_data {
int dst;
int time_zone;
const char *mcc;
const char *mnc;
const char *path;
char *mcc;
char *mnc;
char* path;
DBusConnection *conn;
};
static struct nt_data *ntd = NULL;
static void init_time(void)
static struct nt_data *nettime_new(const char *path)
{
ntd = g_new0(struct nt_data, 1);
struct nt_data *ntd = g_new0(struct nt_data, 1);
ntd->time_available = FALSE;
ntd->time_pending = FALSE;
ntd->dst = 0;
ntd->time_zone = 0;
ntd->path = g_strdup(path);
ntd->conn = dbus_connection_ref(ofono_dbus_get_connection());
return ntd;
}
static gboolean encode_time_format(const struct ofono_network_time *time,
struct tm *tm)
static void nettime_free(struct nt_data *ntd)
{
dbus_connection_unref(ntd->conn);
g_free(ntd->path);
g_free(ntd->mcc);
g_free(ntd->mnc);
g_free(ntd);
}
static gboolean nettime_encode_time_format(struct tm *tm,
const struct ofono_network_time *time)
{
if (time->year < 0)
return FALSE;
@@ -85,7 +88,7 @@ static gboolean encode_time_format(const struct ofono_network_time *time,
return TRUE;
}
static time_t get_monotonic_time()
static time_t nettime_get_monotonic_time()
{
struct timespec ts;
memset(&ts, 0, sizeof(struct timespec));
@@ -98,8 +101,7 @@ static time_t get_monotonic_time()
return ts.tv_sec;
}
static int fill_time_notification(DBusMessage *msg,
struct nt_data *ntd)
static int nettime_fill_time_notification(DBusMessage *msg, struct nt_data *ntd)
{
DBusMessageIter iter, iter_array;
dbus_int64_t utc_long, received;
@@ -150,22 +152,22 @@ static int fill_time_notification(DBusMessage *msg,
return 0;
}
static DBusMessage *get_network_time(DBusConnection *conn,
static DBusMessage *nettime_get_network_time(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
struct nt_data *ntd = data;
DBusMessage *reply = dbus_message_new_method_return(msg);
reply = dbus_message_new_method_return(msg);
if (reply == NULL)
return NULL;
fill_time_notification(reply, ntd);
if (reply) {
nettime_fill_time_notification(reply, ntd);
}
return reply;
}
static const GDBusMethodTable nettime_methods[] = {
{ GDBUS_METHOD("GetNetworkTime",
NULL, GDBUS_ARGS({ "time", "a{sv}" }),
get_network_time) },
nettime_get_network_time) },
{ }
};
@@ -177,84 +179,90 @@ static const GDBusSignalTable nettime_signals[] = {
static int nettime_probe(struct ofono_nettime_context *context)
{
DBusConnection *conn = ofono_dbus_get_connection();
const char *path = ofono_modem_get_path(context->modem);
DBG("Network time probe for modem: %p (%s)", context->modem, path);
init_time();
if (!g_dbus_register_interface(conn, path,
OFONO_NETWORK_TIME_INTERFACE, // name
nettime_methods, // methods
nettime_signals, // signals
NULL, // GDBusPropertyTable *properties
NULL, // user data
NULL)) { // GDBusDestroyFunction destroy
ofono_error("Network time: Could not register interface %s, path %s",
OFONO_NETWORK_TIME_INTERFACE, path);
return 1;
} else {
ofono_info("Network time: Registered interface %s, path %s",
OFONO_NETWORK_TIME_INTERFACE, path);
}
struct nt_data *ntd = nettime_new(ofono_modem_get_path(context->modem));
ofono_modem_add_interface(context->modem, OFONO_NETWORK_TIME_INTERFACE);
DBG("Network time probe for modem: %p (%s)", context->modem, ntd->path);
if (g_dbus_register_interface(ntd->conn, ntd->path,
OFONO_NETWORK_TIME_INTERFACE, nettime_methods,
nettime_signals, NULL, ntd, NULL)) {
context->data = ntd;
ofono_info("Registered interface %s, path %s",
OFONO_NETWORK_TIME_INTERFACE, ntd->path);
ofono_modem_add_interface(context->modem,
OFONO_NETWORK_TIME_INTERFACE);
return 0;
} else {
ofono_error("Could not register interface %s, path %s",
OFONO_NETWORK_TIME_INTERFACE, ntd->path);
nettime_free(ntd);
return 1;
}
}
static void nettime_remove(struct ofono_nettime_context *context)
{
DBusConnection *conn = ofono_dbus_get_connection();
const char *path = ofono_modem_get_path(context->modem);
DBG("Network time remove for modem: %p (%s)", context->modem, path);
if (!g_dbus_unregister_interface(conn, path, OFONO_NETWORK_TIME_INTERFACE)) {
ofono_error("Network time: could not unregister interface %s, path %s",
OFONO_NETWORK_TIME_INTERFACE, path);
struct nt_data *ntd = context->data;
DBG("Network time remove for modem: %p (%s)", context->modem,
ofono_modem_get_path(context->modem));
ofono_modem_remove_interface(context->modem,
OFONO_NETWORK_TIME_INTERFACE);
if (!g_dbus_unregister_interface(ntd->conn, ntd->path,
OFONO_NETWORK_TIME_INTERFACE)) {
ofono_error("Network time: could not unregister interface %s"
" for %s", OFONO_NETWORK_TIME_INTERFACE, ntd->path);
}
ofono_modem_remove_interface(context->modem, OFONO_NETWORK_TIME_INTERFACE);
g_free(ntd);
nettime_free(ntd);
}
static void send_signal(struct nt_data *ntd)
static void nettime_send_signal(struct nt_data *ntd)
{
DBusConnection *conn = ofono_dbus_get_connection();
DBusMessage *signal = dbus_message_new_signal(ntd->path,
OFONO_NETWORK_TIME_INTERFACE,
"NetworkTimeChanged");
fill_time_notification(signal, ntd);
g_dbus_send_message(conn, signal);
nettime_fill_time_notification(signal, ntd);
g_dbus_send_message(ntd->conn, signal);
}
static void nettime_info_received(struct ofono_nettime_context *context,
struct ofono_network_time *info)
{
struct nt_data *ntd = context->data;
struct ofono_netreg *netreg;
const char *mcc;
const char *mnc;
struct tm t;
if (info == NULL)
if (!ntd)
return;
netreg = __ofono_atom_get_data(__ofono_modem_find_atom(
context->modem, OFONO_ATOM_TYPE_NETREG));
mcc = ofono_netreg_get_mcc(netreg);
mnc = ofono_netreg_get_mnc(netreg);
if (!(ofono_netreg_get_mcc(netreg) && ofono_netreg_get_mnc(netreg))) {
if (!mcc || !mnc) {
DBG("Incomplete network time received, ignoring");
return;
}
ntd->path = ofono_modem_get_path(context->modem);
ntd->mcc = ofono_netreg_get_mcc(netreg);
ntd->mnc = ofono_netreg_get_mnc(netreg);
ntd->received = get_monotonic_time();
g_free(ntd->mcc);
g_free(ntd->mnc);
ntd->mcc = g_strdup(mcc);
ntd->mnc = g_strdup(mnc);
ntd->received = nettime_get_monotonic_time();
ntd->time_pending = TRUE;
ntd->dst = info->dst;
ntd->time_zone = info->utcoff;
ntd->time_available = encode_time_format(info, &t);
if (ntd->time_available == TRUE)
ntd->time_available = nettime_encode_time_format(&t, info);
if (ntd->time_available) {
ntd->nw_time_utc = timegm(&t);
}
send_signal(ntd);
DBG("modem: %p (%s)", context->modem, ofono_modem_get_path(context->modem));
nettime_send_signal(ntd);
DBG("modem: %p (%s)", context->modem, ntd->path);
DBG("time: %04d-%02d-%02d %02d:%02d:%02d%c%02d:%02d (DST=%d)",
info->year, info->mon, info->mday, info->hour,
info->min, info->sec, info->utcoff > 0 ? '+' : '-',

View File

@@ -40,128 +40,104 @@
#include "provision.h"
#include "mbpi.h"
struct provision_ap_defaults {
enum ofono_gprs_context_type type;
const char *name;
const char *apn;
};
static gboolean provision_match_name(const struct ofono_gprs_provision_data *ap,
const char* spn)
{
return (ap->provider_name && strcasestr(ap->provider_name, spn)) ||
(ap->name && strcasestr(ap->name, spn)) ||
(ap->apn && strcasestr(ap->apn, spn));
}
static void provision_free_ap(gpointer data)
{
mbpi_ap_free(data);
}
static gint provision_compare_ap(gconstpointer a, gconstpointer b, gpointer data)
{
const struct ofono_gprs_provision_data *ap1 = a;
const struct ofono_gprs_provision_data *ap2 = b;
const char* spn = data;
if (spn) {
const gboolean match1 = provision_match_name(ap1, spn);
const gboolean match2 = provision_match_name(ap2, spn);
if (match1 && !match2) {
return -1;
} else if (match2 && !match1) {
return 1;
}
}
if (ap1->provider_primary && !ap2->provider_primary) {
return -1;
} else if (ap2->provider_primary && !ap1->provider_primary) {
return 1;
} else {
return 0;
}
}
/* Picks best ap, deletes the rest. Creates one if necessary */
static GSList *provision_pick_best_ap(GSList *list, const char* spn,
const struct provision_ap_defaults *defaults)
{
/* Sort the list */
list = g_slist_sort_with_data(list, provision_compare_ap, (void*)spn);
if (list) {
/* Pick the best one, delete the rest */
GSList *best = list;
g_slist_free_full(g_slist_remove_link(list, best),
provision_free_ap);
return best;
} else {
/* or create one from the default data */
struct ofono_gprs_provision_data *ap =
g_new0(struct ofono_gprs_provision_data, 1);
ap->type = defaults->type;
ap->name = g_strdup(defaults->name);
ap->apn = g_strdup(defaults->apn);
return g_slist_append(NULL, ap);
}
}
/* Returns the list containing exactly one INTERNET and one MMS access point */
static GSList *provision_normalize_apn_list(GSList *apns, const char* spn)
{
struct ofono_gprs_provision_data *best_internet = NULL;
struct ofono_gprs_provision_data *best_mms = NULL;
struct ofono_gprs_provision_data *second_best_internet = NULL;
struct ofono_gprs_provision_data *second_best_mms = NULL;
GSList *best_apns = NULL;
GSList *l;
static const struct provision_ap_defaults internet_defaults =
{ OFONO_GPRS_CONTEXT_TYPE_INTERNET, "Internet", "internet" };
static const struct provision_ap_defaults mms_defaults =
{ OFONO_GPRS_CONTEXT_TYPE_MMS, "MMS", "mms" };
/* 1. save the first found internet APN and the first MMS APN */
l = apns;
while (l != NULL) {
GSList *next = l->next;
struct ofono_gprs_provision_data *ap = l->data;
GSList *internet_apns = NULL;
GSList *mms_apns = NULL;
if (ap->type == OFONO_GPRS_CONTEXT_TYPE_INTERNET
&& !best_internet) {
best_internet = ap;
} else if (ap->type == OFONO_GPRS_CONTEXT_TYPE_MMS
&& !best_mms) {
best_mms = ap;
}
l = next;
}
/* Split internet and mms apns, delete all others */
while (apns) {
GSList *link = apns;
struct ofono_gprs_provision_data *ap = link->data;
/*
* 2. look for a "primary" provider (i.e. an MNO, not
* an MVNO on the same radio network)
*/
second_best_internet = best_internet;
best_internet = NULL;
second_best_mms = best_mms;
best_mms = NULL;
l = apns;
while (l != NULL) {
GSList *next = l->next;
struct ofono_gprs_provision_data *ap = l->data;
if (ap->provider_primary) {
if (ap->type == OFONO_GPRS_CONTEXT_TYPE_INTERNET
&& !best_internet) {
best_internet = ap;
} else if (ap->type == OFONO_GPRS_CONTEXT_TYPE_MMS
&& !best_mms) {
best_mms = ap;
}
}
l = next;
}
/* no better match found */
if (!best_internet)
best_internet = second_best_internet;
if (!best_mms)
best_mms = second_best_mms;
/*
* 3. if there is an SPN given, save the first internet APN and the
* first MMS APN matching the SPN (partially, case-insensitively)
* */
if (spn) {
second_best_internet = best_internet;
best_internet = NULL;
second_best_mms = best_mms;
best_mms = NULL;
l = apns;
while (l != NULL) {
GSList *next = l->next;
struct ofono_gprs_provision_data *ap = l->data;
if ((ap->provider_name && strcasestr(ap->provider_name, spn))
|| (ap->name && strcasestr(ap->name, spn))
|| (ap->apn && strcasestr(ap->apn, spn))) {
if (ap->type == OFONO_GPRS_CONTEXT_TYPE_INTERNET
&& !best_internet) {
best_internet = ap;
} else if (ap->type == OFONO_GPRS_CONTEXT_TYPE_MMS
&& !best_mms) {
best_mms = ap;
}
}
l = next;
}
/* no better match found */
if (!best_internet)
best_internet = second_best_internet;
if (!best_mms)
best_mms = second_best_mms;
}
/* 4. if none found yet, create APNs with default values */
if (!best_internet) {
best_internet = g_try_new0(struct ofono_gprs_provision_data, 1);
if (best_internet) {
best_internet->type =
OFONO_GPRS_CONTEXT_TYPE_INTERNET;
best_internet->name =
g_strdup("Internet");
best_internet->apn =
g_strdup("internet");
apns = g_slist_remove_link(apns, link);
if (ap->type == OFONO_GPRS_CONTEXT_TYPE_INTERNET) {
internet_apns = g_slist_concat(internet_apns, link);
} else if (ap->type == OFONO_GPRS_CONTEXT_TYPE_MMS) {
mms_apns = g_slist_concat(mms_apns, link);
} else {
g_slist_free_full(link, provision_free_ap);
}
}
if (!best_mms) {
best_mms = g_try_new0(struct ofono_gprs_provision_data, 1);
if (best_mms) {
best_mms->type =
OFONO_GPRS_CONTEXT_TYPE_MMS;
best_mms->name =
g_strdup("MMS");
best_mms->apn =
g_strdup("mms");
}
}
best_apns = g_slist_append(best_apns, best_internet);
best_apns = g_slist_append(best_apns, best_mms);
return best_apns;
/* Pick the best ap of each type and concatenate them */
return g_slist_concat(
provision_pick_best_ap(internet_apns, spn, &internet_defaults),
provision_pick_best_ap(mms_apns, spn, &mms_defaults));
}
int provision_get_settings(const char *mcc, const char *mnc,

View File

@@ -41,7 +41,7 @@
#define PUSH_NOTIFICATION_INTERFACE "org.ofono.PushNotification"
#define AGENT_INTERFACE "org.ofono.PushNotificationAgent"
#define WAP_PUSH_SRC_PORT 9200
#define WAP_PUSH_SRC_PORT -1
#define WAP_PUSH_DST_PORT 2948
static unsigned int modemwatch_id;
@@ -50,21 +50,16 @@ struct push_notification {
struct ofono_modem *modem;
struct ofono_sms *sms;
struct sms_agent *agent;
unsigned int push_watch[2];
unsigned int push_watch;
};
static void agent_exited(void *userdata)
{
struct push_notification *pn = userdata;
if (pn->push_watch[0] > 0) {
__ofono_sms_datagram_watch_remove(pn->sms, pn->push_watch[0]);
pn->push_watch[0] = 0;
}
if (pn->push_watch[1] > 0) {
__ofono_sms_datagram_watch_remove(pn->sms, pn->push_watch[1]);
pn->push_watch[1] = 0;
if (pn->push_watch > 0) {
__ofono_sms_datagram_watch_remove(pn->sms, pn->push_watch);
pn->push_watch = 0;
}
pn->agent = NULL;
@@ -113,17 +108,12 @@ static DBusMessage *push_notification_register_agent(DBusConnection *conn,
sms_agent_set_removed_notify(pn->agent, agent_exited, pn);
pn->push_watch[0] = __ofono_sms_datagram_watch_add(pn->sms,
pn->push_watch = __ofono_sms_datagram_watch_add(pn->sms,
push_received,
WAP_PUSH_DST_PORT,
WAP_PUSH_SRC_PORT,
pn, NULL);
pn->push_watch[1] = __ofono_sms_datagram_watch_add(pn->sms,
push_received,
WAP_PUSH_DST_PORT,
0, pn, NULL);
return dbus_message_new_method_return(msg);
}
@@ -166,8 +156,7 @@ static void push_notification_cleanup(gpointer user)
DBG("%p", pn);
/* The push watch was already cleaned up */
pn->push_watch[0] = 0;
pn->push_watch[1] = 0;
pn->push_watch = 0;
pn->sms = NULL;
sms_agent_free(pn->agent);

View File

@@ -86,12 +86,16 @@
#define MCE_DISPLAY_DIM_STRING "dimmed"
#define MCE_DISPLAY_OFF_STRING "off"
#define RILMODEM_CONF_FILE "/etc/ofono/ril_subscription.conf"
#define RILSOCK_CONF_GROUP "cmdsocket"
#define RILSOCK_CONF_PATH "path"
#define DEFAULT_CMD_SOCK "/dev/socket/rild"
struct ril_data {
GRil *modem;
int power_on_retries;
int sim_status_retries;
ofono_bool_t connected;
ofono_bool_t have_sim;
ofono_bool_t online;
ofono_bool_t reported;
guint timer_id;
@@ -141,17 +145,12 @@ static void sim_status_cb(struct ril_msg *message, gpointer user_data)
else
ofono_error("Max retries for GET_SIM_STATUS exceeded!");
} else {
/* Returns TRUE if cardstate == PRESENT */
if (ril_util_parse_sim_status(ril->modem, message,
&status, apps)) {
DBG("have_sim = TRUE; num_apps: %d",
status.num_apps);
if (status.num_apps)
ril_util_free_sim_apps(apps, status.num_apps);
ril->have_sim = TRUE;
} else {
ofono_warn("No SIM card present.");
}
@@ -237,13 +236,8 @@ static void ril_pre_sim(struct ofono_modem *modem)
{
DBG("");
struct ril_data *ril = ofono_modem_get_data(modem);
struct ofono_sim *sim;
sim = ofono_sim_create(modem, 0, "rilmodem", ril->modem);
ofono_sim_create(modem, 0, "rilmodem", ril->modem);
ofono_voicecall_create(modem, 0, "rilmodem", ril->modem);
if (sim && ril->have_sim)
ofono_sim_inserted_notify(sim, TRUE);
}
static void ril_post_sim(struct ofono_modem *modem)
@@ -486,17 +480,57 @@ void ril_switchUser()
}
/* TODO: Reading RILD socket path by for now from rilmodem .conf file,
* but change this later to StateFs when plans are more concrete.
* return: Null-terminated path string. Ownership transferred.
* */
static char *ril_socket_path()
{
GError *err = NULL;
GKeyFile *keyfile = NULL;
char *res = NULL;
keyfile = g_key_file_new();
g_key_file_set_list_separator(keyfile, ',');
if (!g_key_file_load_from_file(keyfile, RILMODEM_CONF_FILE, 0, &err)) {
if (err) {
DBG("conf load result: %s", err->message);
g_error_free(err);
}
} else {
if (g_key_file_has_group(keyfile, RILSOCK_CONF_GROUP)) {
res = g_key_file_get_string(
keyfile, RILSOCK_CONF_GROUP, RILSOCK_CONF_PATH, &err);
if (err) {
DBG("conf get result: %s", err->message);
g_error_free(err);
}
}
}
g_key_file_free(keyfile);
if (!res) {
DBG("Falling back to default cmd sock path");
res = g_strdup(DEFAULT_CMD_SOCK);
}
return res;
}
static int create_gril(struct ofono_modem *modem)
{
DBG(" modem: %p", modem);
struct ril_data *ril = ofono_modem_get_data(modem);
ril->have_sim = FALSE;
/* RIL expects user radio */
ril_switchUser();
ril->modem = g_ril_new();
char *path = ril_socket_path();
ril->modem = g_ril_new(path);
g_free(path);
path = NULL;
g_ril_set_disconnect_function(ril->modem, gril_disconnected, modem);

View File

@@ -48,6 +48,8 @@ static const char *none_prefix[] = { NULL };
struct sierra_data {
GAtChat *modem;
gboolean have_sim;
struct at_util_sim_state_query *sim_state_query;
};
static void sierra_debug(const char *str, void *user_data)
@@ -80,6 +82,9 @@ static void sierra_remove(struct ofono_modem *modem)
ofono_modem_set_data(modem, NULL);
/* Cleanup potential SIM state polling */
at_util_sim_state_query_free(data->sim_state_query);
/* Cleanup after hot-unplug */
g_at_chat_unref(data->modem);
@@ -119,6 +124,21 @@ static GAtChat *open_device(struct ofono_modem *modem,
return chat;
}
static void sim_state_cb(gboolean present, gpointer user_data)
{
struct ofono_modem *modem = user_data;
struct sierra_data *data = ofono_modem_get_data(modem);
DBG("%p", modem);
at_util_sim_state_query_free(data->sim_state_query);
data->sim_state_query = NULL;
data->have_sim = present;
ofono_modem_set_powered(modem, TRUE);
}
static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
{
struct ofono_modem *modem = user_data;
@@ -131,7 +151,9 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
data->modem = NULL;
}
ofono_modem_set_powered(modem, ok);
data->sim_state_query = at_util_sim_state_query_new(data->modem,
2, 20, sim_state_cb, modem,
NULL);
}
static int sierra_enable(struct ofono_modem *modem)
@@ -222,7 +244,7 @@ static void sierra_pre_sim(struct ofono_modem *modem)
sim = ofono_sim_create(modem, OFONO_VENDOR_SIERRA,
"atmodem", data->modem);
if (sim)
if (sim && data->have_sim == TRUE)
ofono_sim_inserted_notify(sim, TRUE);
}

View File

@@ -423,9 +423,8 @@ static void ste_set_online(struct ofono_modem *modem, ofono_bool_t online,
if (g_at_chat_send(chat, command, NULL, set_online_cb, cbd, g_free))
return;
g_free(cbd);
CALLBACK_WITH_FAILURE(cb, cbd->data);
g_free(cbd);
}
static void ste_pre_sim(struct ofono_modem *modem)

View File

@@ -232,7 +232,7 @@ static void reachable_cb(const GIsiMessage *msg, void *data)
struct ofono_modem *om = data;
struct isi_data *isi = ofono_modem_get_data(om);
if (!g_isi_msg_error(msg) < 0)
if (g_isi_msg_error(msg) < 0)
return;
ISI_RESOURCE_DBG(msg);

View File

@@ -192,7 +192,7 @@ static void add_wavecom(struct ofono_modem *modem,
ofono_modem_register(modem);
}
static void add_tc65(struct ofono_modem *modem,
static void add_cinterion(struct ofono_modem *modem,
struct udev_device *udev_device)
{
const char *devnode;
@@ -243,6 +243,11 @@ static void add_modem(struct udev_device *udev_device)
if (devpath == NULL)
return;
if(g_strcmp0(driver, "tc65") == 0)
driver = "cinterion";
if(g_strcmp0(driver, "ehs6") == 0)
driver = "cinterion";
modem = ofono_modem_create(NULL, driver);
if (modem == NULL)
return;
@@ -305,8 +310,8 @@ done:
add_isi(modem, udev_device);
else if (g_strcmp0(driver, "calypso") == 0)
add_calypso(modem, udev_device);
else if (g_strcmp0(driver, "tc65") == 0)
add_tc65(modem, udev_device);
else if (g_strcmp0(driver, "cinterion") == 0)
add_cinterion(modem, udev_device);
else if (g_strcmp0(driver, "nokiacdma") == 0)
add_nokiacdma(modem, udev_device);
else if (g_strcmp0(driver, "sim900") == 0)

View File

@@ -117,6 +117,8 @@ static gboolean setup_mbm(struct modem_info *modem)
gps = info->devnode;
} else if (g_str_has_suffix(info->sysattr,
"Network Adapter") == TRUE ||
g_str_has_suffix(info->sysattr,
"gw") == TRUE ||
g_str_has_suffix(info->sysattr,
"NetworkAdapter") == TRUE) {
network = info->devnode;
@@ -1078,14 +1080,19 @@ static struct {
{ "icera", "cdc_ether", "0421", "0633" },
{ "mbm", "cdc_acm", "0bdb" },
{ "mbm", "cdc_ether", "0bdb" },
{ "mbm", "cdc_ncm", "0bdb" },
{ "mbm", "cdc_acm", "0fce" },
{ "mbm", "cdc_ether", "0fce" },
{ "mbm", "cdc_ncm", "0fce" },
{ "mbm", "cdc_acm", "413c" },
{ "mbm", "cdc_ether", "413c" },
{ "mbm", "cdc_ncm", "413c" },
{ "mbm", "cdc_acm", "03f0" },
{ "mbm", "cdc_ether", "03f0" },
{ "mbm", "cdc_ncm", "03f0" },
{ "mbm", "cdc_acm", "0930" },
{ "mbm", "cdc_ether", "0930" },
{ "mbm", "cdc_ncm", "0930" },
{ "hso", "hso" },
{ "gobi", "qmi_wwan" },
{ "gobi", "qcserial" },

View File

@@ -1029,11 +1029,14 @@ out:
/*
* In order to minimize signal transmissions we wait about X seconds
* before reseting the base station id. The hope is that we receive
* before resetting the base station id. The hope is that we receive
* another cell broadcast with the new base station name within
* that time
*/
if (lac_changed || ci_changed) {
if(cbs->reset_source)
g_source_remove(cbs->reset_source);
cbs->reset_source =
g_timeout_add_seconds(3, reset_base_station_name, cbs);
}

View File

@@ -89,7 +89,7 @@ static void cdma_connman_ifupdown(const char *interface, ofono_bool_t active)
return;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, interface, IFNAMSIZ);
strncpy(ifr.ifr_name, interface, IFNAMSIZ - 1);
if (ioctl(sk, SIOCGIFFLAGS, &ifr) < 0)
goto done;

View File

@@ -41,6 +41,14 @@ enum network_registration_status {
NETWORK_REGISTRATION_STATUS_ROAMING = 5,
};
/* 27.007 Section 7.3 <stat> */
enum operator_status {
OPERATOR_STATUS_UNKNOWN = 0,
OPERATOR_STATUS_AVAILABLE = 1,
OPERATOR_STATUS_CURRENT = 2,
OPERATOR_STATUS_FORBIDDEN = 3,
};
/* 27.007 Section 7.6 */
enum clip_validity {
CLIP_VALIDITY_VALID = 0,
@@ -48,6 +56,18 @@ enum clip_validity {
CLIP_VALIDITY_NOT_AVAILABLE = 2,
};
/* 27.007 Section 7.29 */
enum packet_bearer {
PACKET_BEARER_NONE = 0,
PACKET_BEARER_GPRS = 1,
PACKET_BEARER_EGPRS = 2,
PACKET_BEARER_UMTS = 3,
PACKET_BEARER_HSUPA = 4,
PACKET_BEARER_HSDPA = 5,
PACKET_BEARER_HSUPA_HSDPA = 6,
PACKET_BEARER_EPS = 7,
};
/* 27.007 Section 7.30 */
enum cnap_validity {
CNAP_VALIDITY_VALID = 0,

View File

@@ -36,6 +36,7 @@ void __ofono_gprs_provision_free_settings(
int i;
for (i = 0; i < count; i++) {
g_free(settings[i].provider_name);
g_free(settings[i].name);
g_free(settings[i].apn);
g_free(settings[i].username);

View File

@@ -60,18 +60,6 @@
#define MAX_MMS_MTU 1280
#define MAX_GPRS_MTU 1280
/* 27.007 Section 7.29 */
enum packet_bearer {
PACKET_BEARER_NONE = 0,
PACKET_BEARER_GPRS = 1,
PACKET_BEARER_EGPRS = 2,
PACKET_BEARER_UMTS = 3,
PACKET_BEARER_HSUPA = 4,
PACKET_BEARER_HSDPA = 5,
PACKET_BEARER_HSUPA_HSDPA = 6,
PACKET_BEARER_EPS = 7,
};
struct ofono_gprs {
GSList *contexts;
ofono_bool_t attached;
@@ -1889,6 +1877,8 @@ static void gprs_netreg_update(struct ofono_gprs *gprs)
attach = attach && gprs->powered;
DBG("attach: %u, driver_attached: %u", attach, gprs->driver_attached);
if (gprs->driver_attached == attach)
return;
@@ -1899,8 +1889,8 @@ static void gprs_netreg_update(struct ofono_gprs *gprs)
gprs->flags |= GPRS_FLAG_ATTACHING;
gprs->driver->set_attached(gprs, attach, gprs_attach_callback, gprs);
gprs->driver_attached = attach;
gprs->driver->set_attached(gprs, attach, gprs_attach_callback, gprs);
}
static void netreg_status_changed(int status, int lac, int ci, int tech,
@@ -1911,9 +1901,6 @@ static void netreg_status_changed(int status, int lac, int ci, int tech,
DBG("%d", status);
if (gprs->netreg_status == status)
return;
gprs->netreg_status = status;
gprs_netreg_update(gprs);
@@ -2123,6 +2110,36 @@ static struct pri_context *add_context(struct ofono_gprs *gprs,
return context;
}
static void send_context_added_signal(struct ofono_gprs *gprs,
struct pri_context *context,
DBusConnection *conn)
{
const char *path;
DBusMessage *signal;
DBusMessageIter iter;
DBusMessageIter dict;
path = __ofono_atom_get_path(gprs->atom);
signal = dbus_message_new_signal(path,
OFONO_CONNECTION_MANAGER_INTERFACE,
"ContextAdded");
if (!signal)
return;
dbus_message_iter_init_append(signal, &iter);
path = context->path;
dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
OFONO_PROPERTIES_ARRAY_SIGNATURE,
&dict);
append_context_properties(context, &dict);
dbus_message_iter_close_container(&iter, &dict);
g_dbus_send_message(conn, signal);
}
static DBusMessage *gprs_add_context(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -2132,7 +2149,6 @@ static DBusMessage *gprs_add_context(DBusConnection *conn,
const char *name;
const char *path;
enum ofono_gprs_context_type type;
DBusMessage *signal;
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &typestr,
DBUS_TYPE_INVALID))
@@ -2154,29 +2170,7 @@ static DBusMessage *gprs_add_context(DBusConnection *conn,
g_dbus_send_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
path = __ofono_atom_get_path(gprs->atom);
signal = dbus_message_new_signal(path,
OFONO_CONNECTION_MANAGER_INTERFACE,
"ContextAdded");
if (signal) {
DBusMessageIter iter;
DBusMessageIter dict;
dbus_message_iter_init_append(signal, &iter);
path = context->path;
dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
&path);
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
OFONO_PROPERTIES_ARRAY_SIGNATURE,
&dict);
append_context_properties(context, &dict);
dbus_message_iter_close_container(&iter, &dict);
g_dbus_send_message(conn, signal);
}
send_context_added_signal(gprs, context, conn);
return NULL;
}
@@ -2411,6 +2405,196 @@ static DBusMessage *gprs_get_contexts(DBusConnection *conn,
return reply;
}
static void provision_context(const struct ofono_gprs_provision_data *ap,
struct ofono_gprs *gprs)
{
unsigned int id;
struct pri_context *context = NULL;
/* Sanity check */
if (ap == NULL)
return;
if (ap->name && strlen(ap->name) > MAX_CONTEXT_NAME_LENGTH)
return;
if (ap->apn == NULL || strlen(ap->apn) > OFONO_GPRS_MAX_APN_LENGTH)
return;
if (is_valid_apn(ap->apn) == FALSE)
return;
if (ap->username &&
strlen(ap->username) > OFONO_GPRS_MAX_USERNAME_LENGTH)
return;
if (ap->password &&
strlen(ap->password) > OFONO_GPRS_MAX_PASSWORD_LENGTH)
return;
if (ap->message_proxy &&
strlen(ap->message_proxy) > MAX_MESSAGE_PROXY_LENGTH)
return;
if (ap->message_center &&
strlen(ap->message_center) > MAX_MESSAGE_CENTER_LENGTH)
return;
if (gprs->last_context_id)
id = idmap_alloc_next(gprs->pid_map, gprs->last_context_id);
else
id = idmap_alloc(gprs->pid_map);
if (id > idmap_get_max(gprs->pid_map))
return;
context = pri_context_create(gprs, ap->name, ap->type);
if (context == NULL) {
idmap_put(gprs->pid_map, id);
return;
}
context->id = id;
if (ap->username != NULL)
strcpy(context->context.username, ap->username);
if (ap->password != NULL)
strcpy(context->context.password, ap->password);
context->context.auth_method = ap->auth_method;
strcpy(context->context.apn, ap->apn);
context->context.proto = ap->proto;
if (ap->type == OFONO_GPRS_CONTEXT_TYPE_MMS) {
if (ap->message_proxy != NULL)
strcpy(context->message_proxy, ap->message_proxy);
if (ap->message_center != NULL)
strcpy(context->message_center, ap->message_center);
}
if (context_dbus_register(context) == FALSE)
return;
gprs->last_context_id = id;
if (gprs->settings) {
write_context_settings(gprs, context);
storage_sync(gprs->imsi, SETTINGS_STORE, gprs->settings);
}
gprs->contexts = g_slist_append(gprs->contexts, context);
}
static void provision_contexts(struct ofono_gprs *gprs, const char *mcc,
const char *mnc, const char *spn)
{
struct ofono_gprs_provision_data *settings;
int count;
int i;
if (__ofono_gprs_provision_get_settings(mcc, mnc, spn,
&settings, &count) == FALSE) {
ofono_warn("Provisioning failed");
return;
}
for (i = 0; i < count; i++)
provision_context(&settings[i], gprs);
__ofono_gprs_provision_free_settings(settings, count);
}
static void remove_non_active_context(struct ofono_gprs *gprs,
struct pri_context *ctx, DBusConnection *conn)
{
char *path;
const char *atompath;
if (gprs->settings) {
g_key_file_remove_group(gprs->settings, ctx->key, NULL);
storage_sync(gprs->imsi, SETTINGS_STORE, gprs->settings);
}
/* Make a backup copy of path for signal emission below */
path = g_strdup(ctx->path);
context_dbus_unregister(ctx);
gprs->contexts = g_slist_remove(gprs->contexts, ctx);
atompath = __ofono_atom_get_path(gprs->atom);
g_dbus_emit_signal(conn, atompath, OFONO_CONNECTION_MANAGER_INTERFACE,
"ContextRemoved", DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
g_free(path);
}
static DBusMessage *gprs_reset_contexts(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ofono_gprs *gprs = data;
struct ofono_modem *modem = __ofono_atom_get_modem(gprs->atom);
struct ofono_sim *sim = __ofono_atom_find(OFONO_ATOM_TYPE_SIM, modem);
DBusMessage *reply;
GSList *l;
if (gprs->pending)
return __ofono_error_busy(msg);
/*
* We want __ofono_error_busy to take precedence over
* __ofono_error_not_allowed errors, so we check it first.
*/
for (l = gprs->contexts; l; l = l->next) {
struct pri_context *ctx = l->data;
if (ctx->pending)
return __ofono_error_busy(msg);
}
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID))
return __ofono_error_invalid_args(msg);
if (gprs->powered)
return __ofono_error_not_allowed(msg);
for (l = gprs->contexts; l; l = l->next) {
struct pri_context *ctx = l->data;
if (ctx->active)
return __ofono_error_not_allowed(msg);
}
reply = dbus_message_new_method_return(msg);
if (reply == NULL)
return NULL;
/* Remove first the current contexts, re-provision after */
while (gprs->contexts != NULL) {
struct pri_context *ctx = gprs->contexts->data;
remove_non_active_context(gprs, ctx, conn);
}
gprs->last_context_id = 0;
provision_contexts(gprs, ofono_sim_get_mcc(sim),
ofono_sim_get_mnc(sim), ofono_sim_get_spn(sim));
if (gprs->contexts == NULL) /* Automatic provisioning failed */
add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
for (l = gprs->contexts; l; l = l->next) {
struct pri_context *ctx = l->data;
send_context_added_signal(gprs, ctx, conn);
}
return reply;
}
static const GDBusMethodTable manager_methods[] = {
{ GDBUS_METHOD("GetProperties",
NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
@@ -2430,6 +2614,8 @@ static const GDBusMethodTable manager_methods[] = {
{ GDBUS_METHOD("GetContexts", NULL,
GDBUS_ARGS({ "contexts_with_properties", "a(oa{sv})" }),
gprs_get_contexts) },
{ GDBUS_ASYNC_METHOD("ResetContexts", NULL, NULL,
gprs_reset_contexts) },
{ }
};
@@ -2437,7 +2623,7 @@ static const GDBusSignalTable manager_signals[] = {
{ GDBUS_SIGNAL("PropertyChanged",
GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
{ GDBUS_SIGNAL("ContextAdded",
GDBUS_ARGS({ "path", "o" }, { "properties", "v" })) },
GDBUS_ARGS({ "path", "o" }, { "properties", "a{sv}" })) },
{ GDBUS_SIGNAL("ContextRemoved", GDBUS_ARGS({ "path", "o" })) },
{ }
};
@@ -2725,6 +2911,12 @@ void ofono_gprs_context_set_type(struct ofono_gprs_context *gc,
gc->type = type;
}
enum ofono_gprs_context_type ofono_gprs_context_get_type(
struct ofono_gprs_context *gc)
{
return gc->type;
}
void ofono_gprs_context_set_interface(struct ofono_gprs_context *gc,
const char *interface)
{
@@ -3234,108 +3426,6 @@ remove:
storage_sync(imsi, SETTINGS_STORE, gprs->settings);
}
static void provision_context(const struct ofono_gprs_provision_data *ap,
struct ofono_gprs *gprs)
{
unsigned int id;
struct pri_context *context = NULL;
/* Sanity check */
if (ap == NULL)
return;
if (ap->name && strlen(ap->name) > MAX_CONTEXT_NAME_LENGTH)
return;
if (ap->apn == NULL || strlen(ap->apn) > OFONO_GPRS_MAX_APN_LENGTH)
return;
if (is_valid_apn(ap->apn) == FALSE)
return;
if (ap->username &&
strlen(ap->username) > OFONO_GPRS_MAX_USERNAME_LENGTH)
return;
if (ap->password &&
strlen(ap->password) > OFONO_GPRS_MAX_PASSWORD_LENGTH)
return;
if (ap->message_proxy &&
strlen(ap->message_proxy) > MAX_MESSAGE_PROXY_LENGTH)
return;
if (ap->message_center &&
strlen(ap->message_center) > MAX_MESSAGE_CENTER_LENGTH)
return;
if (gprs->last_context_id)
id = idmap_alloc_next(gprs->pid_map, gprs->last_context_id);
else
id = idmap_alloc(gprs->pid_map);
if (id > idmap_get_max(gprs->pid_map))
return;
context = pri_context_create(gprs, ap->name, ap->type);
if (context == NULL) {
idmap_put(gprs->pid_map, id);
return;
}
context->id = id;
if (ap->username != NULL)
strcpy(context->context.username, ap->username);
if (ap->password != NULL)
strcpy(context->context.password, ap->password);
context->context.auth_method = ap->auth_method;
strcpy(context->context.apn, ap->apn);
context->context.proto = ap->proto;
if (ap->type == OFONO_GPRS_CONTEXT_TYPE_MMS) {
if (ap->message_proxy != NULL)
strcpy(context->message_proxy, ap->message_proxy);
if (ap->message_center != NULL)
strcpy(context->message_center, ap->message_center);
}
if (context_dbus_register(context) == FALSE)
return;
gprs->last_context_id = id;
if (gprs->settings) {
write_context_settings(gprs, context);
storage_sync(gprs->imsi, SETTINGS_STORE, gprs->settings);
}
gprs->contexts = g_slist_append(gprs->contexts, context);
}
static void provision_contexts(struct ofono_gprs *gprs, const char *mcc,
const char *mnc, const char *spn)
{
struct ofono_gprs_provision_data *settings;
int count;
int i;
if (__ofono_gprs_provision_get_settings(mcc, mnc, spn,
&settings, &count) == FALSE) {
ofono_warn("Provisioning failed");
return;
}
for (i = 0; i < count; i++)
provision_context(&settings[i], gprs);
__ofono_gprs_provision_free_settings(settings, count);
}
static void ofono_gprs_finish_register(struct ofono_gprs *gprs)
{
DBusConnection *conn = ofono_dbus_get_connection();
@@ -3422,6 +3512,11 @@ static void spn_read_cb(const char *spn, const char *dc, void *data)
ofono_gprs_finish_register(gprs);
}
struct ofono_modem *ofono_gprs_get_modem(struct ofono_gprs *gprs)
{
return __ofono_atom_get_modem(gprs->atom);
}
void ofono_gprs_register(struct ofono_gprs *gprs)
{
struct ofono_modem *modem = __ofono_atom_get_modem(gprs->atom);
@@ -3457,7 +3552,7 @@ void *ofono_gprs_get_data(struct ofono_gprs *gprs)
return gprs->driver_data;
}
struct ofono_modem *ofono_gprs_get_modem(struct ofono_gprs *gprs)
ofono_bool_t ofono_gprs_get_roaming_allowed(struct ofono_gprs *gprs)
{
return __ofono_atom_get_modem(gprs->atom);
return gprs->roaming_allowed;
}

View File

@@ -101,6 +101,8 @@ static void send_new_connection(const char *card, int fd, uint8_t codec)
DBusMessage *msg;
DBusMessageIter iter;
DBG("%p, fd: %d, codec: %hu", card, fd, codec);
msg = dbus_message_new_method_call(agent->owner, agent->path,
HFP_AUDIO_AGENT_INTERFACE, "NewConnection");
if (msg == NULL)
@@ -183,9 +185,15 @@ static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
return TRUE;
}
DBG("SCO connection setup between local: %s and remote: %s",
local, remote);
send_new_connection(card->path, nsk, card->selected_codec);
close(nsk);
if (card->driver->sco_connected_hint)
card->driver->sco_connected_hint(card);
return TRUE;
}
@@ -845,6 +853,8 @@ void ofono_handsfree_audio_ref(void)
if (ref_count != 1)
return;
__ofono_handsfree_audio_manager_init();
if (!g_dbus_register_interface(ofono_dbus_get_connection(),
OFONO_MANAGER_PATH,
HFP_AUDIO_MANAGER_INTERFACE,
@@ -873,6 +883,8 @@ void ofono_handsfree_audio_unref(void)
agent_release(agent);
agent_free(agent);
}
__ofono_handsfree_audio_manager_cleanup();
}
int __ofono_handsfree_audio_manager_init(void)
@@ -882,15 +894,11 @@ int __ofono_handsfree_audio_manager_init(void)
void __ofono_handsfree_audio_manager_cleanup(void)
{
if (ref_count == 0)
if (ref_count != 0)
return;
ofono_error("Handsfree Audio manager not cleaned up properly,"
"fixing...");
ref_count = 1;
ofono_handsfree_audio_unref();
if (sco_watch > 0)
if (sco_watch > 0) {
g_source_remove(sco_watch);
sco_watch = 0;
}
}

View File

@@ -72,7 +72,11 @@ struct ofono_handsfree {
static const char **ag_features_list(unsigned int features,
unsigned int chld_features)
{
static const char *list[10];
/*
* BRSF response is a 32-bit unsigned int. Only 32 entries are posible,
* and we do not ever report the presence of bit 8.
*/
static const char *list[32];
unsigned int i = 0;
if (features & HFP_AG_FEATURE_3WAY)
@@ -602,7 +606,7 @@ static DBusMessage *handsfree_request_phone_number(DBusConnection *conn,
}
static const GDBusMethodTable handsfree_methods[] = {
{ GDBUS_METHOD("GetProperties",
{ GDBUS_ASYNC_METHOD("GetProperties",
NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
handsfree_get_properties) },
{ GDBUS_ASYNC_METHOD("SetProperty",

View File

@@ -30,7 +30,9 @@
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#ifdef __GLIBC__
#include <execinfo.h>
#endif
#include <dlfcn.h>
#include "ofono.h"
@@ -113,6 +115,7 @@ void ofono_debug(const char *format, ...)
va_end(ap);
}
#ifdef __GLIBC__
static void print_backtrace(unsigned int offset)
{
void *frames[99];
@@ -240,6 +243,7 @@ static void signal_setup(sighandler_t handler)
sigaction(SIGABRT, &sa, NULL);
sigaction(SIGPIPE, &sa, NULL);
}
#endif
extern struct ofono_debug_desc __start___debug[];
extern struct ofono_debug_desc __stop___debug[];
@@ -283,8 +287,13 @@ void __ofono_log_enable(struct ofono_debug_desc *start,
file = NULL;
}
if (is_enabled(desc) == TRUE)
if (is_enabled(desc) &&
!(desc->flags & OFONO_DEBUG_FLAG_PRINT)) {
desc->flags |= OFONO_DEBUG_FLAG_PRINT;
if (desc->notify) {
desc->notify(desc);
}
}
}
}
@@ -306,8 +315,10 @@ int __ofono_log_init(const char *program, const char *debug,
if (detach == FALSE)
option |= LOG_PERROR;
#ifdef __GLIBC__
if (backtrace == TRUE)
signal_setup(signal_handler);
#endif
openlog(basename(program), option, LOG_DAEMON);
@@ -322,8 +333,10 @@ void __ofono_log_cleanup(ofono_bool_t backtrace)
closelog();
#ifdef __GLIBC__
if (backtrace == TRUE)
signal_setup(SIG_DFL);
#endif
g_strfreev(enabled);
}

View File

@@ -244,12 +244,6 @@ int main(int argc, char **argv)
__ofono_manager_init();
/*
* BT HFP SCO socket creation moved to Bluez5 plugin.
* Bluez4 handles the SCO socket, it will conflict with oFono.
*/
//__ofono_handsfree_audio_manager_init();
__ofono_plugin_init(option_plugin, option_noplugin);
g_free(option_plugin);
@@ -259,8 +253,6 @@ int main(int argc, char **argv)
__ofono_plugin_cleanup();
//__ofono_handsfree_audio_manager_cleanup(); See comment above
__ofono_manager_cleanup();
__ofono_modemwatch_cleanup();

Some files were not shown because too many files have changed in this diff Show More