Merge lp:~phablet-team/ofono/ofono-ww51-update into lp:~phablet-team/ofono/utopic-rtm

Proposed by Tony Espy
Status: Merged
Approved by: Alfonso Sanchez-Beato
Approved revision: 6886
Merged at revision: 6886
Proposed branch: lp:~phablet-team/ofono/ofono-ww51-update
Merge into: lp:~phablet-team/ofono/utopic-rtm
Diff against target: 1485 lines (+768/-236)
19 files modified
Makefile.am (+2/-1)
debian/changelog (+10/-0)
doc/mtk-settings-api.txt (+49/-0)
drivers/mtkmodem/mtk_constants.h (+1/-0)
drivers/mtkmodem/mtkreply.c (+5/-6)
drivers/mtkmodem/mtkrequest.c (+11/-0)
drivers/mtkmodem/mtkrequest.h (+6/-0)
drivers/mtkmodem/mtksettings.c (+261/-0)
drivers/mtkmodem/mtksettings.h (+43/-0)
drivers/mtkmodem/mtkutil.c (+2/-0)
drivers/mtkmodem/mtkutil.h (+2/-0)
drivers/mtkmodem/radio-settings.c (+5/-3)
drivers/rilmodem/radio-settings.c (+8/-0)
drivers/rilmodem/sim.c (+73/-53)
plugins/mtk.c (+236/-107)
plugins/ril.c (+0/-62)
test/set-3g-slot (+20/-0)
unit/test-mtkreply.c (+4/-4)
unit/test-mtkrequest.c (+30/-0)
To merge this branch: bzr merge lp:~phablet-team/ofono/ofono-ww51-update
Reviewer Review Type Date Requested Status
Alfonso Sanchez-Beato Approve
Review via email: mp+243884@code.launchpad.net

Commit message

[ Alfonso Sanchez-Beato ]
  * rilmodem/sim.c, plugins/mtk.c, ril.c: fix SIM interface signals (LP: #1376250)

  * Makefile.am, doc/mtk-settings-api.txt, mtkmodem,
    plugins/mtk.c, test, unit: support krillin 3g slot switch (LP: #1373388)

Description of the change

This merge includes fixes for two ofono bugs:

- fix SIM interface signals ( lp: #1376250 )

This fix also is thought to have bearing on a dialer/messaging app bug ( lp: #1379836 ), although as this is conjecture, the fix isn't included in the changelog.

- support krillin 3g slot switch ( lp: #1373388 )

Only the second bug is slated for ww51-2014, however this change is dependent on the earlier bug fix for the SIM interface signals.

To post a comment you must log in.
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

LGTM

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

We decided to pull the Set3G code for RTM, and just land the auto-answer code, so I've marked this MP as "work-in-progress".

6884. By Alfonso Sanchez-Beato

[ Alfonso Sanchez-Beato ]
* rilmodem, mtkmodem, plugins/ril.c,mtk.c: Auto-answer calls when test SIM is present.
Approved by: Tony Espy

6885. By CI Train Bot Account

Releasing 1.12.bzr6884+15.04.20150121.1~rtm-0ubuntu1

6886. By Alfonso Sanchez-Beato

[ Alfonso Sanchez-Beato ]
* rilmodem/sim.c, plugins/mtk.c, ril.c: fix SIM interface signals (LP: #1376250)
* Makefile.am, doc/mtk-settings-api.txt, mtkmodem,
  plugins/mtk.c, test, unit: support krillin 3g slot switch (LP: #1373388)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile.am'
2--- Makefile.am 2014-07-29 21:21:56 +0000
3+++ Makefile.am 2015-02-06 15:08:43 +0000
4@@ -146,7 +146,8 @@
5 drivers/mtkmodem/mtkreply.c \
6 drivers/mtkmodem/voicecall.c \
7 drivers/mtkmodem/gprs.c \
8- drivers/mtkmodem/radio-settings.c
9+ drivers/mtkmodem/radio-settings.c \
10+ drivers/mtkmodem/mtksettings.c
11
12 builtin_modules += rilmodem
13 builtin_sources += drivers/rilmodem/rilmodem.h \
14
15=== modified file 'debian/changelog'
16--- debian/changelog 2015-01-21 18:07:49 +0000
17+++ debian/changelog 2015-02-06 15:08:43 +0000
18@@ -1,3 +1,13 @@
19+ofono (1.12.bzr6886+15.04.20150206~rtm-0ubuntu1) UNRELEASED; urgency=medium
20+
21+ [ Alfonso Sanchez-Beato ]
22+ * rilmodem/sim.c, plugins/mtk.c, ril.c: fix SIM interface signals (LP: #1376250)
23+
24+ * Makefile.am, doc/mtk-settings-api.txt, mtkmodem,
25+ plugins/mtk.c, test, unit: support krillin 3g slot switch (LP: #1373388)
26+
27+ -- Alfonso Sanchez-Beato (email Canonical) <alfonso.sanchez-beato@canonical.com> Fri, 06 Feb 2015 16:03:05 +0100
28+
29 ofono (1.12.bzr6884+15.04.20150121.1~rtm-0ubuntu1) 14.09; urgency=medium
30
31 [ Alfonso Sanchez-Beato ]
32
33=== added file 'doc/mtk-settings-api.txt'
34--- doc/mtk-settings-api.txt 1970-01-01 00:00:00 +0000
35+++ doc/mtk-settings-api.txt 2015-02-06 15:08:43 +0000
36@@ -0,0 +1,49 @@
37+MediaTek settings hierarchy
38+===========================
39+
40+Service org.ofono
41+Interface org.ofono.MtkSettings
42+Object path [variable prefix]/{modem0,modem1,...}
43+
44+Methods dict GetProperties()
45+
46+ Returns all MtkSettings properties. See the
47+ properties section for available properties.
48+
49+ Possible Errors: [service].Error.InProgress
50+ [service].Error.NotImplemented
51+ [service].Error.Failed
52+
53+ void SetProperty(string name, variant value)
54+
55+ Changes the value of the specified property. Only
56+ properties that are listed as readwrite are
57+ changeable. On success a PropertyChanged signal
58+ will be emitted.
59+
60+ Possible Errors: [service].Error.InProgress
61+ [service].Error.NotImplemented
62+ [service].Error.InvalidArguments
63+ [service].Error.Failed
64+
65+Signals PropertyChanged(string property, variant value)
66+
67+ This signal indicates a changed value of the given
68+ property.
69+
70+Properties boolean Has3G [readwrite]
71+
72+ If true, the modem has 3G capabilities, otherwise it is
73+ just 2G. Only one of the modems can have this set at a
74+ time (note that in fact the modem hardware is shared
75+ among all ofono MTK modems, and that each ofono MTK
76+ modem represents one physical slot in the phone).
77+
78+ When we set the property to TRUE, all MTK modems are
79+ reset, and after that this property will be false for
80+ all modems except for the one for which we set the
81+ property. Note that setting this property to FALSE is
82+ not allowed to avoid confusion, as one and only one of
83+ the modems must have it set to true and we can have
84+ the case of more than two modems.
85+
86
87=== modified file 'drivers/mtkmodem/mtk_constants.h'
88--- drivers/mtkmodem/mtk_constants.h 2014-07-28 07:12:26 +0000
89+++ drivers/mtkmodem/mtk_constants.h 2015-02-06 15:08:43 +0000
90@@ -30,6 +30,7 @@
91 #define MTK_RIL_REQUEST_RADIO_POWERON 2033
92 #define MTK_RIL_REQUEST_SET_CALL_INDICATION 2036
93 #define MTK_RIL_REQUEST_GET_3G_CAPABILITY 2038
94+#define MTK_RIL_REQUEST_SET_3G_CAPABILITY 2039
95 #define MTK_RIL_REQUEST_SET_FD_MODE 2073
96
97 /* RIL Unsolicited Messages */
98
99=== modified file 'drivers/mtkmodem/mtkreply.c'
100--- drivers/mtkmodem/mtkreply.c 2014-07-24 08:31:18 +0000
101+++ drivers/mtkmodem/mtkreply.c 2015-02-06 15:08:43 +0000
102@@ -35,7 +35,7 @@
103 const struct ril_msg *message)
104 {
105 struct parcel rilp;
106- int sim_3g, numint, slot;
107+ int slot_3g, numint;
108
109 g_ril_init_parcel(message, &rilp);
110
111@@ -49,19 +49,18 @@
112 * Bitmap with 3g capability per slot. Reply is the same regardless of
113 * the socket used to sent the request.
114 */
115- sim_3g = parcel_r_int32(&rilp);
116+ slot_3g = parcel_r_int32(&rilp);
117
118 if (rilp.malformed) {
119 ofono_error("%s: malformed parcel", __func__);
120 goto error;
121 }
122
123- g_ril_append_print_buf(gril, "{%d}", sim_3g);
124+ g_ril_append_print_buf(gril, "{%d}", slot_3g);
125 g_ril_print_response(gril, message);
126
127- slot = g_ril_get_slot(gril);
128-
129- return (sim_3g >> slot) & 0x01;
130+ /* Do it zero-based */
131+ return slot_3g - 1;
132
133 error:
134 return -1;
135
136=== modified file 'drivers/mtkmodem/mtkrequest.c'
137--- drivers/mtkmodem/mtkrequest.c 2014-06-12 10:49:29 +0000
138+++ drivers/mtkmodem/mtkrequest.c 2015-02-06 15:08:43 +0000
139@@ -122,3 +122,14 @@
140 g_ril_append_print_buf(gril, "%s)", print_buf);
141 }
142 }
143+
144+void g_mtk_request_set_3g_capability(GRil *gril, struct parcel *rilp)
145+{
146+ int mode = g_ril_get_slot(gril) + 1;
147+
148+ parcel_init(rilp);
149+ parcel_w_int32(rilp, 1);
150+ parcel_w_int32(rilp, mode);
151+
152+ g_ril_append_print_buf(gril, "(%d)", mode);
153+}
154
155=== modified file 'drivers/mtkmodem/mtkrequest.h'
156--- drivers/mtkmodem/mtkrequest.h 2014-06-12 10:49:29 +0000
157+++ drivers/mtkmodem/mtkrequest.h 2015-02-06 15:08:43 +0000
158@@ -102,6 +102,12 @@
159 void g_mtk_request_set_fd_mode(GRil *gril, int mode, int param1,
160 int param2, struct parcel *rilp);
161
162+/*
163+ * Sets the slot to which the GRil object is connected as the one with 3G
164+ * capabilities. This makes the other slot just 2G.
165+ */
166+void g_mtk_request_set_3g_capability(GRil *gril, struct parcel *rilp);
167+
168 #ifdef __cplusplus
169 }
170 #endif
171
172=== added file 'drivers/mtkmodem/mtksettings.c'
173--- drivers/mtkmodem/mtksettings.c 1970-01-01 00:00:00 +0000
174+++ drivers/mtkmodem/mtksettings.c 2015-02-06 15:08:43 +0000
175@@ -0,0 +1,261 @@
176+/*
177+ *
178+ * oFono - Open Source Telephony
179+ *
180+ * Copyright (C) 2014 Canonical Ltd.
181+ *
182+ * This program is free software; you can redistribute it and/or modify
183+ * it under the terms of the GNU General Public License version 2 as
184+ * published by the Free Software Foundation.
185+ *
186+ * This program is distributed in the hope that it will be useful,
187+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
188+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
189+ * GNU General Public License for more details.
190+ *
191+ * You should have received a copy of the GNU General Public License
192+ * along with this program; if not, write to the Free Software
193+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
194+ *
195+ */
196+
197+#ifdef HAVE_CONFIG_H
198+#include <config.h>
199+#endif
200+#include <string.h>
201+#include <stdlib.h>
202+#include <stdio.h>
203+#include <errno.h>
204+#include <glib.h>
205+#include <gdbus.h>
206+#include <ofono.h>
207+
208+#define OFONO_API_SUBJECT_TO_CHANGE
209+#include <ofono/plugin.h>
210+#include <ofono/log.h>
211+#include <ofono/modem.h>
212+#include <ofono/dbus.h>
213+
214+#include "drivers/mtkmodem/mtk_constants.h"
215+#include "drivers/mtkmodem/mtkrequest.h"
216+#include "drivers/mtkmodem/mtkutil.h"
217+#include "mtksettings.h"
218+
219+#define MTK_SETTINGS_INTERFACE "org.ofono.MtkSettings"
220+
221+struct mtk_settings_data {
222+ struct ofono_modem *modem;
223+ GRil *ril;
224+ ofono_bool_t has_3g;
225+ ofono_bool_t has_3g_pending;
226+ DBusMessage *pending;
227+};
228+
229+static void set_3g(struct mtk_settings_data *msd, ofono_bool_t has_3g)
230+{
231+ DBusConnection *conn = ofono_dbus_get_connection();
232+ const char *path = ofono_modem_get_path(msd->modem);
233+ dbus_bool_t value = has_3g;
234+
235+ if (msd->has_3g == has_3g)
236+ return;
237+
238+ ofono_dbus_signal_property_changed(conn, path, MTK_SETTINGS_INTERFACE,
239+ "Has3G", DBUS_TYPE_BOOLEAN,
240+ &value);
241+ msd->has_3g = has_3g;
242+}
243+
244+static void set_3g_cb(struct ril_msg *message, gpointer user_data)
245+{
246+ struct mtk_settings_data *msd = user_data;
247+ DBusMessage *reply;
248+
249+ if (message->error != RIL_E_SUCCESS) {
250+ ofono_error("%s: Error setting 3G", __func__);
251+
252+ msd->has_3g_pending = msd->has_3g;
253+
254+ reply = __ofono_error_failed(msd->pending);
255+ __ofono_dbus_pending_reply(&msd->pending, reply);
256+
257+ return;
258+ }
259+
260+ g_ril_print_response_no_args(msd->ril, message);
261+
262+ reply = dbus_message_new_method_return(msd->pending);
263+ __ofono_dbus_pending_reply(&msd->pending, reply);
264+
265+ set_3g(msd, msd->has_3g_pending);
266+
267+ mtk_reset_all_modems();
268+}
269+
270+static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg,
271+ void *data)
272+{
273+ struct mtk_settings_data *msd = data;
274+ DBusMessageIter iter;
275+ DBusMessageIter var;
276+ const char *property;
277+
278+ if (msd->pending)
279+ return __ofono_error_busy(msg);
280+
281+ if (!dbus_message_iter_init(msg, &iter))
282+ return __ofono_error_invalid_args(msg);
283+
284+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
285+ return __ofono_error_invalid_args(msg);
286+
287+ dbus_message_iter_get_basic(&iter, &property);
288+ dbus_message_iter_next(&iter);
289+
290+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
291+ return __ofono_error_invalid_args(msg);
292+
293+ dbus_message_iter_recurse(&iter, &var);
294+
295+ if (g_strcmp0(property, "Has3G") == 0) {
296+ dbus_bool_t value;
297+ struct parcel rilp;
298+
299+ if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN)
300+ return __ofono_error_invalid_args(msg);
301+
302+ dbus_message_iter_get_basic(&var, &value);
303+
304+ if (msd->has_3g_pending == (ofono_bool_t) value)
305+ return dbus_message_new_method_return(msg);
306+
307+ /*
308+ * We can only set to true, as setting to false could be
309+ * confusing in a multi-sim environment (>2 SIM)
310+ */
311+ if (value == FALSE)
312+ return __ofono_error_invalid_args(msg);
313+
314+ g_mtk_request_set_3g_capability(msd->ril, &rilp);
315+
316+ if (g_ril_send(msd->ril, MTK_RIL_REQUEST_SET_3G_CAPABILITY,
317+ &rilp, set_3g_cb, msd, NULL) == 0) {
318+ ofono_error("%s: unable to set 3G for slot", __func__);
319+ return __ofono_error_failed(msg);
320+ }
321+
322+ msd->pending = dbus_message_ref(msg);
323+ msd->has_3g_pending = value;
324+
325+ return NULL;
326+ }
327+
328+ return __ofono_error_invalid_args(msg);
329+}
330+
331+static DBusMessage *get_properties(DBusConnection *conn,
332+ DBusMessage *msg, void *data)
333+{
334+ struct mtk_settings_data *msd = data;
335+ DBusMessage *reply;
336+ DBusMessageIter iter;
337+ DBusMessageIter dict;
338+
339+ reply = dbus_message_new_method_return(msg);
340+ if (reply == NULL)
341+ return NULL;
342+
343+ dbus_message_iter_init_append(reply, &iter);
344+
345+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
346+ OFONO_PROPERTIES_ARRAY_SIGNATURE,
347+ &dict);
348+
349+ ofono_dbus_dict_append(&dict, "Has3G",
350+ DBUS_TYPE_BOOLEAN, &msd->has_3g);
351+
352+ dbus_message_iter_close_container(&iter, &dict);
353+
354+ return reply;
355+}
356+
357+static const GDBusMethodTable mtk_settings_methods[] = {
358+ { GDBUS_ASYNC_METHOD("GetProperties",
359+ NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
360+ get_properties) },
361+ { GDBUS_ASYNC_METHOD("SetProperty",
362+ GDBUS_ARGS({ "property", "s" }, { "value", "v" }),
363+ NULL, set_property) },
364+ { }
365+};
366+
367+static const GDBusSignalTable mtk_settings_signals[] = {
368+ { GDBUS_SIGNAL("PropertyChanged",
369+ GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
370+ { }
371+};
372+
373+
374+static void register_interface(struct mtk_settings_data *msd)
375+{
376+ DBusConnection *conn = ofono_dbus_get_connection();
377+
378+ if (!g_dbus_register_interface(conn, ofono_modem_get_path(msd->modem),
379+ MTK_SETTINGS_INTERFACE,
380+ mtk_settings_methods,
381+ mtk_settings_signals,
382+ NULL, msd, NULL)) {
383+ ofono_error("Could not create %s interface",
384+ MTK_SETTINGS_INTERFACE);
385+ return;
386+ }
387+
388+ ofono_modem_add_interface(msd->modem, MTK_SETTINGS_INTERFACE);
389+}
390+
391+static void unregister_interface(struct mtk_settings_data *msd)
392+{
393+ DBusConnection *conn = ofono_dbus_get_connection();
394+
395+ ofono_modem_remove_interface(msd->modem, MTK_SETTINGS_INTERFACE);
396+
397+ g_dbus_unregister_interface(conn,
398+ ofono_modem_get_path(msd->modem),
399+ MTK_SETTINGS_INTERFACE);
400+}
401+
402+struct mtk_settings_data *mtk_settings_create(struct ofono_modem *modem,
403+ GRil *ril, ofono_bool_t has_3g)
404+{
405+ struct mtk_settings_data *msd = g_try_malloc0(sizeof(*msd));
406+
407+ DBG("");
408+
409+ if (msd == NULL) {
410+ ofono_error("%s: Cannot allocate mtk_settings_data", __func__);
411+ return NULL;
412+ }
413+
414+ msd->modem = modem;
415+ msd->ril = g_ril_clone(ril);
416+
417+ msd->has_3g = has_3g;
418+ msd->has_3g_pending = has_3g;
419+
420+ register_interface(msd);
421+
422+ return msd;
423+}
424+
425+void mtk_settings_remove(struct mtk_settings_data *msd)
426+{
427+ DBG("");
428+
429+ if (msd == NULL)
430+ return;
431+
432+ unregister_interface(msd);
433+
434+ g_ril_unref(msd->ril);
435+ g_free(msd);
436+}
437
438=== added file 'drivers/mtkmodem/mtksettings.h'
439--- drivers/mtkmodem/mtksettings.h 1970-01-01 00:00:00 +0000
440+++ drivers/mtkmodem/mtksettings.h 2015-02-06 15:08:43 +0000
441@@ -0,0 +1,43 @@
442+/*
443+ *
444+ * MTK driver for ofono/rilmodem
445+ *
446+ * Copyright (C) 2014 Canonical Ltd.
447+ *
448+ * This program is free software; you can redistribute it and/or modify
449+ * it under the terms of the GNU General Public License version 2 as
450+ * published by the Free Software Foundation.
451+ *
452+ * This program is distributed in the hope that it will be useful,
453+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
454+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
455+ * GNU General Public License for more details.
456+ *
457+ * You should have received a copy of the GNU General Public License
458+ * along with this program; if not, write to the Free Software
459+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
460+ *
461+ */
462+
463+#ifndef MTKSETTINGS_H
464+#define MTKSETTINGS_H
465+
466+#include <ofono/types.h>
467+
468+#include "gril.h"
469+
470+#ifdef __cplusplus
471+extern "C" {
472+#endif
473+
474+struct mtk_settings_data;
475+
476+struct mtk_settings_data *mtk_settings_create(struct ofono_modem *modem,
477+ GRil *ril, ofono_bool_t has_3g);
478+void mtk_settings_remove(struct mtk_settings_data *msd);
479+
480+#ifdef __cplusplus
481+}
482+#endif
483+
484+#endif /* MTKSETTINGS_H */
485
486=== modified file 'drivers/mtkmodem/mtkutil.c'
487--- drivers/mtkmodem/mtkutil.c 2014-07-28 07:12:26 +0000
488+++ drivers/mtkmodem/mtkutil.c 2015-02-06 15:08:43 +0000
489@@ -41,6 +41,8 @@
490 return "MTK_RIL_REQUEST_SET_CALL_INDICATION";
491 case MTK_RIL_REQUEST_GET_3G_CAPABILITY:
492 return "MTK_RIL_REQUEST_GET_3G_CAPABILITY";
493+ case MTK_RIL_REQUEST_SET_3G_CAPABILITY:
494+ return "MTK_RIL_REQUEST_SET_3G_CAPABILITY";
495 case MTK_RIL_REQUEST_SET_FD_MODE:
496 return "MTK_RIL_REQUEST_SET_FD_MODE";
497 default:
498
499=== modified file 'drivers/mtkmodem/mtkutil.h'
500--- drivers/mtkmodem/mtkutil.h 2014-07-31 06:45:32 +0000
501+++ drivers/mtkmodem/mtkutil.h 2015-02-06 15:08:43 +0000
502@@ -34,6 +34,8 @@
503 void mtk_set_attach_state(struct ofono_modem *modem, ofono_bool_t attached);
504 void mtk_detach_received(struct ofono_modem *modem);
505
506+void mtk_reset_all_modems(void);
507+
508 struct mtk_gprs_data {
509 GRil *gril;
510 struct ofono_modem *modem;
511
512=== modified file 'drivers/mtkmodem/radio-settings.c'
513--- drivers/mtkmodem/radio-settings.c 2014-09-25 12:16:25 +0000
514+++ drivers/mtkmodem/radio-settings.c 2015-02-06 15:08:43 +0000
515@@ -132,7 +132,7 @@
516 struct radio_data *rd = ofono_radio_settings_get_data(rs);
517 ofono_radio_settings_modem_rats_query_cb_t cb = cbd->cb;
518 ofono_bool_t modem_rats[OFONO_RADIO_ACCESS_MODE_LAST] = { FALSE };
519- int is_3g;
520+ int slot_3g, is_3g;
521
522 if (message->error != RIL_E_SUCCESS) {
523 ofono_error("%s: error %s", __func__,
524@@ -141,13 +141,15 @@
525 return;
526 }
527
528- is_3g = g_mtk_reply_parse_get_3g_capability(rd->ril, message);
529- if (is_3g < 0) {
530+ slot_3g = g_mtk_reply_parse_get_3g_capability(rd->ril, message);
531+ if (slot_3g < 0) {
532 ofono_error("%s: parse error", __func__);
533 CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
534 return;
535 }
536
537+ is_3g = (g_ril_get_slot(rd->ril) == slot_3g);
538+
539 modem_rats[OFONO_RADIO_ACCESS_MODE_GSM] = TRUE;
540
541 if (is_3g) {
542
543=== modified file 'drivers/rilmodem/radio-settings.c'
544--- drivers/rilmodem/radio-settings.c 2014-07-24 08:31:18 +0000
545+++ drivers/rilmodem/radio-settings.c 2015-02-06 15:08:43 +0000
546@@ -118,8 +118,16 @@
547 return;
548 }
549
550+ /*
551+ * GSM_WCDMA_AUTO -> ril.h: GSM/WCDMA (auto mode, according to PRL)
552+ * PRL: preferred roaming list.
553+ * This value is returned when selecting the slot as having 3G
554+ * capabilities, so it is sort of the default for MTK modems.
555+ */
556+
557 switch (pref) {
558 case PREF_NET_TYPE_GSM_WCDMA:
559+ case PREF_NET_TYPE_GSM_WCDMA_AUTO:
560 mode = OFONO_RADIO_ACCESS_MODE_UMTS;
561 break;
562 case PREF_NET_TYPE_GSM_ONLY:
563
564=== modified file 'drivers/rilmodem/sim.c'
565--- drivers/rilmodem/sim.c 2014-10-10 02:10:48 +0000
566+++ drivers/rilmodem/sim.c 2015-02-06 15:08:43 +0000
567@@ -85,7 +85,6 @@
568 guint app_type;
569 gchar *app_str;
570 guint app_index;
571- gboolean sim_registered;
572 enum ofono_sim_password_type passwd_type;
573 int retries[OFONO_SIM_PASSWORD_INVALID];
574 enum ofono_sim_password_type passwd_state;
575@@ -646,55 +645,56 @@
576 struct ofono_sim *sim = user_data;
577 struct sim_data *sd = ofono_sim_get_data(sim);
578 struct reply_sim_status *status;
579- guint i = 0;
580- guint search_index = -1;
581-
582- if (sd->sim_registered == FALSE) {
583- /* First status request, after sim_probe() */
584- ofono_sim_register(sim);
585- sd->sim_registered = TRUE;
586-
587- if (sd->ril_state_watch != NULL &&
588- !ofono_sim_add_state_watch(sim,
589- sd->ril_state_watch,
590- sd->modem, NULL))
591- ofono_error("Error registering ril sim watch");
592+ guint search_index;
593+
594+ status = g_ril_reply_parse_sim_status(sd->ril, message);
595+ if (status == NULL) {
596+ ofono_error("%s: Cannot parse SIM status reply", __func__);
597+ return;
598 }
599
600- if ((status = g_ril_reply_parse_sim_status(sd->ril, message))
601- != NULL
602- && status->card_state == RIL_CARDSTATE_PRESENT
603- && status->num_apps) {
604-
605- DBG("num_apps: %d gsm_umts_index: %d", status->num_apps,
606- status->gsm_umts_index);
607-
608- /*
609- * TODO(CDMA): need some kind of logic to
610- * set the correct app_index,
611- */
612- search_index = status->gsm_umts_index;
613-
614- for (i = 0; i < status->num_apps; i++) {
615- struct reply_sim_app *app = status->apps[i];
616- if (i == search_index &&
617- app->app_type != RIL_APPTYPE_UNKNOWN) {
618- configure_active_app(sd, app, i);
619- break;
620- }
621- }
622-
623- /*
624- * Note: There doesn't seem to be any other way to
625- * force the core SIM code to recheck the PIN. This
626- * call causes the core to call the this atom's
627- * query_passwd() function.
628- */
629- __ofono_sim_recheck_pin(sim);
630-
631- } else if (status && status->card_state == RIL_CARDSTATE_ABSENT) {
632- ofono_info("SIM card absent");
633+ DBG("SIM status is %u", status->card_state);
634+
635+ if (status->card_state == RIL_CARDSTATE_PRESENT)
636+ ofono_sim_inserted_notify(sim, TRUE);
637+ else if (status && status->card_state == RIL_CARDSTATE_ABSENT)
638 ofono_sim_inserted_notify(sim, FALSE);
639+ else
640+ ofono_error("%s: bad SIM state (%u)",
641+ __func__, status->card_state);
642+
643+ /* TODO(CDMA): need some kind of logic to set the correct app_index */
644+ search_index = status->gsm_umts_index;
645+
646+ /*
647+ * We cache the current password state. Ideally this should be done by
648+ * issuing a GET_SIM_STATUS request from ril_query_passwd_state, which
649+ * is called by the core after sending a password, but unfortunately the
650+ * response to GET_SIM_STATUS is not reliable in mako when sent just
651+ * after sending the password. Some time is needed before the modem
652+ * refreshes its internal state, and when it does it sends a
653+ * SIM_STATUS_CHANGED event. In that moment we retrieve the status and
654+ * this function is executed. We call __ofono_sim_recheck_pin as it is
655+ * the only way to indicate the core to call query_passwd_state again.
656+ * An option that can be explored in the future is wait before invoking
657+ * core callback for send_passwd until we know the real password state.
658+ */
659+ if (status->card_state == RIL_CARDSTATE_PRESENT
660+ && search_index < status->num_apps) {
661+ struct reply_sim_app *app = status->apps[search_index];
662+
663+ if (app->app_type != RIL_APPTYPE_UNKNOWN) {
664+ configure_active_app(sd, app, search_index);
665+ DBG("passwd_state: %d", sd->passwd_state);
666+
667+ /*
668+ * Note: There doesn't seem to be any other way to force
669+ * the core SIM code to recheck the PIN. This call
670+ * causes the core to call the this atom's
671+ * query_passwd() function.
672+ */
673+ __ofono_sim_recheck_pin(sim);
674+ }
675 }
676
677 g_ril_reply_free_sim_status(status);
678@@ -823,7 +823,7 @@
679 g_free(retries);
680 }
681
682- /* TODO: re-bfactor to not use macro for FAILURE;
683+ /* TODO: re-factor to not use macro for FAILURE;
684 doesn't return error! */
685 if (message->error == RIL_E_SUCCESS) {
686 CALLBACK_WITH_SUCCESS(cb, cbd->data);
687@@ -992,19 +992,40 @@
688 }
689 }
690
691-static gboolean ril_sim_register(gpointer user)
692+static gboolean listen_and_get_sim_status(gpointer user)
693 {
694 struct ofono_sim *sim = user;
695 struct sim_data *sd = ofono_sim_get_data(sim);
696
697- DBG("");
698-
699- send_get_sim_status(sim);
700+ send_get_sim_status(sim);
701
702 g_ril_register(sd->ril, RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED,
703 (GRilNotifyFunc) ril_sim_status_changed, sim);
704
705 /* TODO: should we also register for RIL_UNSOL_SIM_REFRESH? */
706+ return FALSE;
707+}
708+
709+static gboolean ril_sim_register(gpointer user)
710+{
711+ struct ofono_sim *sim = user;
712+ struct sim_data *sd = ofono_sim_get_data(sim);
713+
714+ DBG("");
715+
716+ ofono_sim_register(sim);
717+
718+ if (sd->ril_state_watch != NULL &&
719+ !ofono_sim_add_state_watch(sim, sd->ril_state_watch,
720+ sd->modem, NULL))
721+ ofono_error("Error registering ril sim watch");
722+
723+ /*
724+ * We use g_idle_add here to make sure that the presence of the SIM
725+ * interface is signalled before signalling anything else from the said
726+ * interface, as ofono_sim_register also uses g_idle_add.
727+ */
728+ g_idle_add(listen_and_get_sim_status, sim);
729
730 return FALSE;
731 }
732@@ -1025,7 +1046,6 @@
733 sd->app_type = RIL_APPTYPE_UNKNOWN;
734 sd->passwd_state = OFONO_SIM_PASSWORD_NONE;
735 sd->passwd_type = OFONO_SIM_PASSWORD_NONE;
736- sd->sim_registered = FALSE;
737 sd->modem = ril_data->modem;
738 sd->ril_state_watch = ril_data->ril_state_watch;
739
740
741=== modified file 'plugins/mtk.c'
742--- plugins/mtk.c 2015-01-13 14:13:08 +0000
743+++ plugins/mtk.c 2015-02-06 15:08:43 +0000
744@@ -66,6 +66,8 @@
745 #include "drivers/mtkmodem/mtk_constants.h"
746 #include "drivers/mtkmodem/mtkutil.h"
747 #include "drivers/mtkmodem/mtkrequest.h"
748+#include "drivers/mtkmodem/mtkreply.h"
749+#include "drivers/mtkmodem/mtksettings.h"
750
751 #define MAX_SIM_STATUS_RETRIES 15
752
753@@ -76,18 +78,25 @@
754 #define SIM_2_ACTIVE 2
755 #define NO_SIM_ACTIVE 0
756
757+#define SOCKET_NUM_FOR_DBG_0 -1
758+#define SOCKET_NUM_FOR_DBG_1 -2
759+
760 /* this gives 30s for rild to initialize */
761 #define RILD_MAX_CONNECT_RETRIES 5
762 #define RILD_CONNECT_RETRY_TIME_S 5
763
764 #define T_WAIT_DISCONN_MS 1000
765
766+static const char hex_slot_0[] = "Slot 0: ";
767+static const char hex_slot_1[] = "Slot 1: ";
768+
769 typedef void (*pending_cb_t)(struct cb_data *cbd);
770
771 struct mtk_data {
772 GRil *modem;
773 int sim_status_retries;
774 ofono_bool_t ofono_online;
775+ ofono_bool_t ofono_online_target;
776 int radio_state;
777 struct ofono_sim *sim;
778 /* pending_* are used in case we are disconnected from the socket */
779@@ -110,6 +119,9 @@
780 struct ofono_call_barring *call_barring;
781 struct ofono_gprs *gprs;
782 struct ofono_message_waiting *message_waiting;
783+ struct ofono_modem *ofono_modem;
784+ ofono_bool_t has_3g;
785+ struct mtk_settings_data *mtk_settings;
786 };
787
788 /*
789@@ -125,11 +137,23 @@
790 static gboolean disconnect_expected;
791 static guint not_disconn_cb_id;
792
793-static void send_get_sim_status(struct ofono_modem *modem);
794+struct socket_data {
795+ GRil *gril;
796+ const char *path;
797+ int radio_state;
798+ guint radio_state_ev_id;
799+};
800+
801+static struct socket_data *sock_0, *sock_1;
802+
803 static int create_gril(struct ofono_modem *modem);
804 static gboolean mtk_connected(gpointer user_data);
805 static void mtk_set_online(struct ofono_modem *modem, ofono_bool_t online,
806 ofono_modem_online_cb_t callback, void *data);
807+static void query_3g_caps(struct socket_data *sock);
808+static void socket_disconnected(gpointer user_data);
809+static void start_slot(struct mtk_data *ril, struct socket_data *sock,
810+ const char *hex_prefix);
811
812 static void mtk_debug(const char *str, void *user_data)
813 {
814@@ -146,6 +170,14 @@
815 return mtk_0;
816 }
817
818+static struct socket_data *socket_complement(struct socket_data *sock)
819+{
820+ if (sock == sock_0)
821+ return sock_1;
822+ else
823+ return sock_0;
824+}
825+
826 /*
827 * mtk_set_attach_state and mtk_detach_received are called by mtkmodem's gprs
828 * driver. They are needed to solve an issue with data attachment: in case
829@@ -197,13 +229,34 @@
830 }
831 }
832
833-static gboolean sim_status_retry(gpointer user_data)
834+static void radio_state_changed(struct ril_msg *message, gpointer user_data)
835 {
836- struct ofono_modem *modem = user_data;
837- send_get_sim_status(modem);
838-
839- /* Makes this a single shot */
840- return FALSE;
841+ struct socket_data *sock = user_data;
842+ int radio_state = g_ril_unsol_parse_radio_state_changed(sock->gril,
843+ message);
844+
845+ if (radio_state != sock->radio_state) {
846+ struct socket_data *sock_c = socket_complement(sock);
847+
848+ ofono_info("%s, state: %s", __func__,
849+ ril_radio_state_to_string(radio_state));
850+
851+ /*
852+ * If there is just one slot, just start it. Otherwise, we ask
853+ * who owns the 3G capabilities in case both slots have already
854+ * radio state different from UNAVAILABLE.
855+ */
856+ if (mtk_1 == NULL) {
857+ mtk_0->has_3g = TRUE;
858+ start_slot(mtk_0, sock, hex_slot_0);
859+ } else if (sock->radio_state == RADIO_STATE_UNAVAILABLE &&
860+ sock_c != NULL && sock_c->radio_state !=
861+ RADIO_STATE_UNAVAILABLE) {
862+ query_3g_caps(sock);
863+ }
864+
865+ sock->radio_state = radio_state;
866+ }
867 }
868
869 static void mtk_radio_state_changed(struct ril_msg *message, gpointer user_data)
870@@ -220,9 +273,6 @@
871 ril_radio_state_to_string(radio_state),
872 ril->ofono_online);
873
874- if (ril->radio_state == RADIO_STATE_UNAVAILABLE)
875- mtk_connected(modem);
876-
877 ril->radio_state = radio_state;
878
879 switch (radio_state) {
880@@ -275,65 +325,6 @@
881 }
882 }
883
884-static void sim_status_cb(struct ril_msg *message, gpointer user_data)
885-{
886- struct ofono_modem *modem = user_data;
887- struct mtk_data *ril = ofono_modem_get_data(modem);
888- struct reply_sim_status *status;
889-
890- DBG("slot %d", ril->slot);
891-
892- if (message->error != RIL_E_SUCCESS) {
893- ril->sim_status_retries++;
894-
895- ofono_error("[slot %d] GET_SIM_STATUS request failed: "
896- "%s; retries: %d",
897- ril->slot, ril_error_to_string(message->error),
898- ril->sim_status_retries);
899-
900- if (ril->sim_status_retries < MAX_SIM_STATUS_RETRIES)
901- g_timeout_add_seconds(2, sim_status_retry, modem);
902- else
903- ofono_error("[slot %d] Max retries for GET_SIM_STATUS"
904- " exceeded!", ril->slot);
905- } else {
906-
907- /* Register for changes in SIM insertion */
908- g_ril_register(ril->modem, MTK_RIL_UNSOL_SIM_PLUG_OUT,
909- sim_removed, modem);
910- g_ril_register(ril->modem, MTK_RIL_UNSOL_SIM_PLUG_IN,
911- sim_inserted, modem);
912-
913- if ((status = g_ril_reply_parse_sim_status(ril->modem, message))
914- != NULL) {
915-
916- if (status->card_state == RIL_CARDSTATE_PRESENT) {
917- DBG("Card PRESENT; num_apps: %d",
918- status->num_apps);
919-
920- ofono_sim_inserted_notify(ril->sim, TRUE);
921- } else {
922- ofono_warn("[slot %d] Card NOT_PRESENT",
923- ril->slot);
924-
925- ofono_sim_inserted_notify(ril->sim, FALSE);
926- }
927- g_ril_reply_free_sim_status(status);
928- }
929- }
930-}
931-
932-static void send_get_sim_status(struct ofono_modem *modem)
933-{
934- struct mtk_data *ril = ofono_modem_get_data(modem);
935-
936- DBG("slot %d", ril->slot);
937-
938- if (g_ril_send(ril->modem, RIL_REQUEST_GET_SIM_STATUS, NULL,
939- sim_status_cb, modem, NULL) == 0)
940- ofono_error("%s: failure sending request", __func__);
941-}
942-
943 static int mtk_probe(struct ofono_modem *modem)
944 {
945 struct mtk_data *ril = g_try_new0(struct mtk_data, 1);
946@@ -355,6 +346,8 @@
947
948 DBG("slot %d", ril->slot);
949
950+ ril->ofono_modem = modem;
951+
952 ofono_modem_set_data(modem, ril);
953
954 return 0;
955@@ -521,9 +514,11 @@
956 ofono_radio_settings_create(modem, OFONO_RIL_VENDOR_MTK,
957 MTKMODEM, ril->modem);
958
959- /* Ask sim status */
960- ril->sim_status_retries = 0;
961- send_get_sim_status(modem);
962+ /* Register for changes in SIM insertion */
963+ g_ril_register(ril->modem, MTK_RIL_UNSOL_SIM_PLUG_OUT,
964+ sim_removed, modem);
965+ g_ril_register(ril->modem, MTK_RIL_UNSOL_SIM_PLUG_IN,
966+ sim_inserted, modem);
967 }
968
969 static void mtk_sim_mode_cb(struct ril_msg *message, gpointer user_data)
970@@ -546,11 +541,18 @@
971 CALLBACK_WITH_FAILURE(cb, cbd->data);
972 }
973
974+ if (ril->ofono_online)
975+ ril->mtk_settings =
976+ mtk_settings_create(ril->ofono_modem, ril->modem,
977+ ril->has_3g);
978+ else
979+ mtk_settings_remove(ril->mtk_settings);
980+
981 /* Execute possible pending operation on the other modem */
982
983 ril_c = ril_complement(ril);
984
985- if (ril_c->pending_online_cbd) {
986+ if (ril_c != NULL && ril_c->pending_online_cbd) {
987 struct cb_data *pending_cbd = ril_c->pending_online_cbd;
988 ofono_modem_online_cb_t pending_cb = pending_cbd->cb;
989
990@@ -671,6 +673,8 @@
991 if (message->error == RIL_E_SUCCESS) {
992 g_ril_print_response_no_args(ril->modem, message);
993
994+ mtk_settings_remove(ril->mtk_settings);
995+
996 CALLBACK_WITH_SUCCESS(cb, cbd->data);
997 } else {
998 ofono_error("%s: RIL error %s", __func__,
999@@ -751,6 +755,39 @@
1000 }
1001 }
1002
1003+static void set_online_cb(const struct ofono_error *error, void *data)
1004+{
1005+ if (mtk_1->ofono_online_target && !mtk_1->ofono_online)
1006+ mtk_set_online(mtk_1->ofono_modem, TRUE, set_online_cb, NULL);
1007+}
1008+
1009+static void set_offline_cb(const struct ofono_error *error, void *data)
1010+{
1011+ if (mtk_1->ofono_online)
1012+ mtk_set_online(mtk_1->ofono_modem, FALSE, set_offline_cb, NULL);
1013+ else if (mtk_0->ofono_online_target)
1014+ mtk_set_online(mtk_0->ofono_modem, TRUE, set_online_cb, NULL);
1015+ else
1016+ mtk_set_online(mtk_1->ofono_modem, TRUE, set_online_cb, NULL);
1017+}
1018+
1019+void mtk_reset_all_modems(void)
1020+{
1021+ if (!mtk_0->ofono_online && !mtk_1->ofono_online)
1022+ return;
1023+
1024+ mtk_0->ofono_online_target = mtk_0->ofono_online;
1025+ mtk_1->ofono_online_target = mtk_1->ofono_online;
1026+
1027+ ofono_modem_set_powered(mtk_0->ofono_modem, FALSE);
1028+ ofono_modem_set_powered(mtk_1->ofono_modem, FALSE);
1029+
1030+ if (mtk_0->ofono_online)
1031+ mtk_set_online(mtk_0->ofono_modem, FALSE, set_offline_cb, NULL);
1032+ else
1033+ mtk_set_online(mtk_1->ofono_modem, FALSE, set_offline_cb, NULL);
1034+}
1035+
1036 static void create_atoms_on_connection(struct ofono_modem *modem)
1037 {
1038 struct mtk_data *ril = ofono_modem_get_data(modem);
1039@@ -770,14 +807,97 @@
1040 {
1041 struct mtk_data *ril = ofono_modem_get_data(modem);
1042
1043- ofono_call_volume_remove(ril->callvolume);
1044+ if (__ofono_modem_find_atom(modem, OFONO_ATOM_TYPES_CALL_VOLUME))
1045+ ofono_call_volume_remove(ril->callvolume);
1046 ril->callvolume = NULL;
1047- ofono_voicecall_remove(ril->voicecall);
1048+ if (__ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_VOICECALL))
1049+ ofono_voicecall_remove(ril->voicecall);
1050 ril->voicecall = NULL;
1051- ofono_devinfo_remove(ril->devinfo);
1052+ if (__ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_DEVINFO))
1053+ ofono_devinfo_remove(ril->devinfo);
1054 ril->devinfo = NULL;
1055 }
1056
1057+static void start_slot(struct mtk_data *ril, struct socket_data *sock,
1058+ const char *hex_prefix)
1059+{
1060+ ofono_info("Physical slot %d in socket %s", ril->slot, sock->path);
1061+
1062+ ril->modem = sock->gril;
1063+ ril->radio_state = sock->radio_state;
1064+
1065+ g_ril_set_slot(ril->modem, ril->slot);
1066+
1067+ if (getenv("OFONO_RIL_TRACE"))
1068+ g_ril_set_trace(ril->modem, TRUE);
1069+
1070+ if (getenv("OFONO_RIL_HEX_TRACE"))
1071+ g_ril_set_debugf(ril->modem, mtk_debug, (char *) hex_prefix);
1072+
1073+ g_ril_set_disconnect_function(ril->modem, socket_disconnected,
1074+ ril->ofono_modem);
1075+
1076+ g_ril_unregister(sock->gril, sock->radio_state_ev_id);
1077+
1078+ g_ril_register(ril->modem, RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
1079+ mtk_radio_state_changed, ril->ofono_modem);
1080+
1081+ mtk_connected(ril->ofono_modem);
1082+}
1083+
1084+static void query_3g_caps_cb(struct ril_msg *message, gpointer user_data)
1085+{
1086+ struct socket_data *sock = user_data;
1087+ struct socket_data *sock_for_mtk_0, *sock_for_mtk_1;
1088+ int slot_3g;
1089+
1090+ if (message->error != RIL_E_SUCCESS) {
1091+ ofono_error("%s: error %s", __func__,
1092+ ril_error_to_string(message->error));
1093+ return;
1094+ }
1095+
1096+ slot_3g = g_mtk_reply_parse_get_3g_capability(sock->gril, message);
1097+
1098+ /*
1099+ * The socket at sock_slot_0 always connects to the slot with 3G
1100+ * capabilities, while sock_slot_1 connects to the slot that is just 2G.
1101+ * However, the physical slot that owns the 3G capabilities can be
1102+ * changed dynamically using a RILd request, so the sockets can connect
1103+ * to different physical slots depending on the current configuration.
1104+ * We want to keep the relationship between the physical slots and
1105+ * the modem names in DBus (so /ril_0 and /ril_1 always refer to the
1106+ * same physical slots), so here we assign the sockets needed by mtk_0
1107+ * and mtk_1 structures to make sure that happens.
1108+ */
1109+ if (slot_3g == MULTISIM_SLOT_0) {
1110+ sock_for_mtk_0 = sock_0;
1111+ sock_for_mtk_1 = sock_1;
1112+ mtk_0->has_3g = TRUE;
1113+ mtk_1->has_3g = FALSE;
1114+ } else {
1115+ sock_for_mtk_0 = sock_1;
1116+ sock_for_mtk_1 = sock_0;
1117+ mtk_0->has_3g = FALSE;
1118+ mtk_1->has_3g = TRUE;
1119+ }
1120+
1121+ start_slot(mtk_0, sock_for_mtk_0, hex_slot_0);
1122+ start_slot(mtk_1, sock_for_mtk_1, hex_slot_1);
1123+
1124+ g_free(sock_0);
1125+ sock_0 = NULL;
1126+ g_free(sock_1);
1127+ sock_1 = NULL;
1128+}
1129+
1130+static void query_3g_caps(struct socket_data *sock)
1131+{
1132+ if (g_ril_send(sock->gril, MTK_RIL_REQUEST_GET_3G_CAPABILITY, NULL,
1133+ query_3g_caps_cb, sock, NULL) <= 0)
1134+ ofono_error("%s Error querying 3G capabilities", __func__);
1135+}
1136+
1137 static gboolean mtk_connected(gpointer user_data)
1138 {
1139 struct ofono_modem *modem = (struct ofono_modem *) user_data;
1140@@ -787,10 +907,14 @@
1141
1142 DBG("calling set_powered(TRUE)");
1143
1144- ofono_modem_set_powered(modem, TRUE);
1145+ if (!ofono_modem_get_powered(modem))
1146+ ofono_modem_set_powered(modem, TRUE);
1147
1148 create_atoms_on_connection(modem);
1149
1150+ if (ril->pending_cb)
1151+ ril->pending_cb(ril->pending_cbd);
1152+
1153 /* Call the function just once */
1154 return FALSE;
1155 }
1156@@ -805,11 +929,6 @@
1157 if (create_gril(modem) < 0)
1158 return TRUE;
1159
1160- create_atoms_on_connection(modem);
1161-
1162- if (ril->pending_cb)
1163- ril->pending_cb(ril->pending_cbd);
1164-
1165 /* Reconnected: do not call this again */
1166 return FALSE;
1167 }
1168@@ -841,30 +960,34 @@
1169
1170 static const char sock_slot_0[] = "/dev/socket/rild";
1171 static const char sock_slot_1[] = "/dev/socket/rild2";
1172-static const char hex_slot_0[] = "Slot 0: ";
1173-static const char hex_slot_1[] = "Slot 1: ";
1174
1175 static int create_gril(struct ofono_modem *modem)
1176 {
1177 struct mtk_data *ril = ofono_modem_get_data(modem);
1178- const char *sock_path;
1179- const char *hex_prefix;
1180+ struct socket_data *sock;
1181+ int sock_num;
1182
1183 DBG("slot %d", ril->slot);
1184
1185 if (ril->modem != NULL)
1186 return 0;
1187
1188+ sock = g_try_malloc0(sizeof(*sock));
1189+ if (sock == NULL) {
1190+ ofono_error("%s: Cannot allocate socket_data", __func__);
1191+ return -ENOMEM;
1192+ }
1193+
1194 if (ril->slot == MULTISIM_SLOT_0) {
1195- sock_path = sock_slot_0;
1196- hex_prefix = hex_slot_0;
1197+ sock_num = SOCKET_NUM_FOR_DBG_0;
1198+ sock->path = sock_slot_0;
1199 } else {
1200- sock_path = sock_slot_1;
1201- hex_prefix = hex_slot_1;
1202+ sock_num = SOCKET_NUM_FOR_DBG_1;
1203+ sock->path = sock_slot_1;
1204 }
1205
1206 /* Opens the socket to RIL */
1207- ril->modem = g_ril_new(sock_path, OFONO_RIL_VENDOR_MTK);
1208+ sock->gril = g_ril_new(sock->path, OFONO_RIL_VENDOR_MTK);
1209
1210 /*
1211 * NOTE: Since AT modems open a tty, and then call
1212@@ -875,28 +998,34 @@
1213 * abstraction... ( probaby not a bad idea ).
1214 */
1215
1216- if (ril->modem == NULL) {
1217- ofono_error("g_ril_new() failed to create modem %d!",
1218- ril->slot);
1219+ if (sock->gril == NULL) {
1220+ ofono_error("g_ril_new() failed to connect to %s!", sock->path);
1221+ g_free(sock);
1222 return -EIO;
1223+ } else if (ril->slot == MULTISIM_SLOT_0) {
1224+ sock_0 = sock;
1225+ } else {
1226+ sock_1 = sock;
1227 }
1228
1229- g_ril_set_slot(ril->modem, ril->slot);
1230-
1231- g_ril_set_vendor_print_msg_id_funcs(ril->modem,
1232+ sock->radio_state = RADIO_STATE_UNAVAILABLE;
1233+ sock->radio_state_ev_id =
1234+ g_ril_register(sock->gril,
1235+ RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
1236+ radio_state_changed, sock);
1237+
1238+ /* sock_num is negative to avoid confusion with physical slots */
1239+ g_ril_set_slot(sock->gril, sock_num);
1240+
1241+ g_ril_set_vendor_print_msg_id_funcs(sock->gril,
1242 mtk_request_id_to_string,
1243 mtk_unsol_request_to_string);
1244
1245 if (getenv("OFONO_RIL_TRACE"))
1246- g_ril_set_trace(ril->modem, TRUE);
1247+ g_ril_set_trace(sock->gril, TRUE);
1248
1249 if (getenv("OFONO_RIL_HEX_TRACE"))
1250- g_ril_set_debugf(ril->modem, mtk_debug, (char *) hex_prefix);
1251-
1252- g_ril_set_disconnect_function(ril->modem, socket_disconnected, modem);
1253-
1254- g_ril_register(ril->modem, RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
1255- mtk_radio_state_changed, modem);
1256+ g_ril_set_debugf(sock->gril, mtk_debug, (char *) sock->path);
1257
1258 return 0;
1259 }
1260@@ -923,14 +1052,14 @@
1261 {
1262 int ret;
1263
1264+ /* We handle SIM states due to MTK peculiarities */
1265+ ofono_modem_set_driver_watches_sim(modem, TRUE);
1266+
1267 ret = create_gril(modem);
1268 if (ret < 0)
1269 g_timeout_add_seconds(RILD_CONNECT_RETRY_TIME_S,
1270 connect_rild, modem);
1271
1272- /* We handle SIM states due to MTK peculiarities */
1273- ofono_modem_set_driver_watches_sim(modem, TRUE);
1274-
1275 /*
1276 * We will mark the modem as powered when we receive an event that
1277 * confirms that the radio is in a state different from unavailable
1278
1279=== modified file 'plugins/ril.c'
1280--- plugins/ril.c 2015-01-13 14:13:08 +0000
1281+++ plugins/ril.c 2015-02-06 15:08:43 +0000
1282@@ -84,8 +84,6 @@
1283 int rild_connect_retries;
1284 };
1285
1286-static void send_get_sim_status(struct ofono_modem *modem);
1287-
1288 static void ril_debug(const char *str, void *user_data)
1289 {
1290 const char *prefix = user_data;
1291@@ -93,15 +91,6 @@
1292 ofono_info("%s%s", prefix, str);
1293 }
1294
1295-static gboolean sim_status_retry(gpointer user_data)
1296-{
1297- struct ofono_modem *modem = user_data;
1298- send_get_sim_status(modem);
1299-
1300- /* Makes this a single shot */
1301- return FALSE;
1302-}
1303-
1304 static void ril_radio_state_changed(struct ril_msg *message, gpointer user_data)
1305 {
1306 struct ofono_modem *modem = user_data;
1307@@ -127,7 +116,6 @@
1308 ril->vendor, RILMODEM,
1309 ril->modem);
1310
1311- send_get_sim_status(modem);
1312 break;
1313
1314 case RADIO_STATE_UNAVAILABLE:
1315@@ -150,56 +138,6 @@
1316 }
1317 }
1318
1319-static void sim_status_cb(struct ril_msg *message, gpointer user_data)
1320-{
1321- struct ofono_modem *modem = user_data;
1322- struct ril_data *ril = ofono_modem_get_data(modem);
1323- struct reply_sim_status *status;
1324-
1325- DBG("");
1326-
1327- if (message->error != RIL_E_SUCCESS) {
1328- ril->sim_status_retries++;
1329-
1330- ofono_error("GET_SIM_STATUS request failed: %s; retries: %d",
1331- ril_error_to_string(message->error),
1332- ril->sim_status_retries);
1333-
1334- if (ril->sim_status_retries < MAX_SIM_STATUS_RETRIES)
1335- g_timeout_add_seconds(2, sim_status_retry, modem);
1336- else
1337- ofono_error("Max retries for GET_SIM_STATUS exceeded!");
1338- } else {
1339-
1340- if ((status = g_ril_reply_parse_sim_status(ril->modem, message))
1341- != NULL) {
1342-
1343- if (status->card_state == RIL_CARDSTATE_PRESENT) {
1344- DBG("Card PRESENT; num_apps: %d",
1345- status->num_apps);
1346-
1347- ofono_sim_inserted_notify(ril->sim, TRUE);
1348-
1349- } else {
1350- ofono_warn("Card NOT_PRESENT.");
1351-
1352- ofono_sim_inserted_notify(ril->sim, FALSE);
1353- }
1354- g_ril_reply_free_sim_status(status);
1355- }
1356- }
1357-}
1358-
1359-static void send_get_sim_status(struct ofono_modem *modem)
1360-{
1361- struct ril_data *ril = ofono_modem_get_data(modem);
1362-
1363- DBG("");
1364-
1365- g_ril_send(ril->modem, RIL_REQUEST_GET_SIM_STATUS, NULL,
1366- sim_status_cb, modem, NULL);
1367-}
1368-
1369 int ril_create(struct ofono_modem *modem, enum ofono_ril_vendor vendor)
1370 {
1371 struct ril_data *ril = g_try_new0(struct ril_data, 1);
1372
1373=== added file 'test/set-3g-slot'
1374--- test/set-3g-slot 1970-01-01 00:00:00 +0000
1375+++ test/set-3g-slot 2015-02-06 15:08:43 +0000
1376@@ -0,0 +1,20 @@
1377+#!/usr/bin/python3
1378+
1379+import dbus
1380+import sys
1381+
1382+bus = dbus.SystemBus()
1383+
1384+if len(sys.argv) == 2:
1385+ path = sys.argv[1]
1386+else:
1387+ manager = dbus.Interface(bus.get_object('org.ofono', '/'),
1388+ 'org.ofono.Manager')
1389+ modems = manager.GetModems()
1390+ path = modems[0][0]
1391+
1392+print("Activate 3G for %s..." % path)
1393+mtks = dbus.Interface(bus.get_object('org.ofono', path),
1394+ 'org.ofono.MtkSettings')
1395+
1396+mtks.SetProperty("Has3G", True)
1397
1398=== modified file 'unit/test-mtkreply.c'
1399--- unit/test-mtkreply.c 2014-07-29 16:35:05 +0000
1400+++ unit/test-mtkreply.c 2015-02-06 15:08:43 +0000
1401@@ -53,7 +53,7 @@
1402 };
1403
1404 struct rep_3g_capability_test {
1405- int is_3g;
1406+ int slot_3g;
1407 const struct ril_msg msg;
1408 };
1409
1410@@ -113,7 +113,7 @@
1411 };
1412
1413 static const struct rep_3g_capability_test mtk_reply_3g_capability_valid_1 = {
1414- .is_3g = 1,
1415+ .slot_3g = 0,
1416 .msg = {
1417 .buf = (char *) &mtk_reply_3g_capability_valid_parcel1,
1418 .buf_len = sizeof(mtk_reply_3g_capability_valid_parcel1),
1419@@ -153,9 +153,9 @@
1420 {
1421 GRil *gril = g_ril_new(NULL, OFONO_RIL_VENDOR_MTK);
1422 const struct rep_3g_capability_test *test = data;
1423- int is_3g = g_mtk_reply_parse_get_3g_capability(gril, &test->msg);
1424+ int slot_3g = g_mtk_reply_parse_get_3g_capability(gril, &test->msg);
1425
1426- g_assert(is_3g == test->is_3g);
1427+ g_assert(slot_3g == test->slot_3g);
1428
1429 g_ril_unref(gril);
1430 }
1431
1432=== modified file 'unit/test-mtkrequest.c'
1433--- unit/test-mtkrequest.c 2014-06-12 11:02:03 +0000
1434+++ unit/test-mtkrequest.c 2015-02-06 15:08:43 +0000
1435@@ -207,6 +207,18 @@
1436 .parcel_size = sizeof(req_set_fd_mode_parcel_valid_2),
1437 };
1438
1439+/* MTK: set_3g_capability tests */
1440+
1441+static const guchar req_set_3g_capability_valid_1[] = {
1442+ 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
1443+};
1444+
1445+static const struct request_test_data set_set_3g_capability_valid_test_1 = {
1446+ .request = NULL,
1447+ .parcel_data = req_set_3g_capability_valid_1,
1448+ .parcel_size = sizeof(req_set_3g_capability_valid_1),
1449+};
1450+
1451 /* Test functions */
1452
1453 static void test_mtk_req_sim_read_binary_valid(gconstpointer data)
1454@@ -322,6 +334,19 @@
1455 parcel_free(&rilp);
1456 }
1457
1458+static void test_request_set_3g_capability(gconstpointer data)
1459+{
1460+ const struct request_test_data *test_data = data;
1461+ struct parcel rilp;
1462+
1463+ g_mtk_request_set_3g_capability(NULL, &rilp);
1464+
1465+ g_assert(!memcmp(rilp.data, test_data->parcel_data,
1466+ test_data->parcel_size));
1467+
1468+ parcel_free(&rilp);
1469+}
1470+
1471 #endif /* LITTLE_ENDIAN */
1472
1473 int main(int argc, char **argv)
1474@@ -376,6 +401,11 @@
1475 &set_fd_mode_valid_test_2,
1476 test_request_set_fd_mode);
1477
1478+ g_test_add_data_func("/testmtkrequest/mtk-settings: "
1479+ "valid SET_3G_CAPABILITY Test 1",
1480+ &set_set_3g_capability_valid_test_1,
1481+ test_request_set_3g_capability);
1482+
1483 #endif /* LITTLE_ENDIAN */
1484
1485 return g_test_run();

Subscribers

People subscribed via source and target branches

to all changes: