Merge lp:~phablet-team/ofono/mbpi-nettime-plus-oem-fixes into lp:~phablet-team/ofono/ubuntu

Proposed by Tony Espy
Status: Merged
Approved by: Tony Espy
Approved revision: 6870
Merged at revision: 6870
Proposed branch: lp:~phablet-team/ofono/mbpi-nettime-plus-oem-fixes
Merge into: lp:~phablet-team/ofono/ubuntu
Diff against target: 2623 lines (+1402/-785)
24 files modified
Makefile.am (+6/-3)
debian/changelog (+19/-0)
drivers/infineonmodem/infineon_constants.h (+77/-0)
drivers/rilmodem/sim.c (+68/-1)
drivers/rilmodem/vendor.h (+2/-1)
gril/grilreply.c (+52/-0)
gril/grilreply.h (+10/-0)
gril/grilrequest.c (+15/-0)
gril/grilrequest.h (+3/-0)
gril/parcel.c (+52/-0)
gril/parcel.h (+2/-0)
plugins/android-apndb.c (+0/-494)
plugins/android-apndb.h (+0/-33)
plugins/android-provision.c (+0/-227)
plugins/infineon.c (+76/-0)
plugins/mtk.c (+48/-1)
plugins/ril.c (+33/-24)
plugins/ril.h (+30/-0)
plugins/ubuntu-apndb.c (+596/-0)
plugins/ubuntu-apndb.h (+33/-0)
plugins/ubuntu-provision.c (+150/-0)
test/rilmodem/test-sim-online (+2/-1)
unit/test-grilreply.c (+72/-0)
unit/test-grilrequest.c (+56/-0)
To merge this branch: bzr merge lp:~phablet-team/ofono/mbpi-nettime-plus-oem-fixes
Reviewer Review Type Date Requested Status
Alfonso Sanchez-Beato Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+227122@code.launchpad.net

Commit message

  * drivers/rilmodem/sim.c: notify on SIM removal (LP: #1332306)
  * unit/rilmodem/test-sim-online: fix serial number check (LP: #1334867)
  * plugins/mtk.c: fix race condition when onlining modem
  * build, drivers/infeonmodem, drivers/rilmodem, gril,
    plugins/infeon.c, plugins/ril.*, unit: add Infeon OEM hooks
  * build, plugins/ubuntu-provision.c, ubuntu-apndb.*: re-named
    provisioning plugin code from android-* to ubuntu-*. Also removed
    code that queries mobile-broadband-provider-info's db, and finally
    implemented a /custom hook for custom apn dbs (LP: #1315509).

Description of the change

This branch includes the following changes and bug fixes:

1. It removes querying of the mobile-broadband-provider-info apn db during GPRS/MMS provisioning.

2. It adds a custom hook to GPRS/MSS provisioning ( see bug #1315509 ).

3. It allows the custom and system apn dbs to be overriden by environment variables ( OFONO_CUSTOM_APNDB_PATH & OFONO_SYSTEM_APNDB_PATH) for test purposes.

4. It adds new OEM hooks which allow enablement of Infeon-based modems.

5. It fixes a race condition with dual-SIM MTK-based modems.

6. The rilmodem driver code now notifies the ofono core when SIM card removal is detected ( see bug #1332306 ).

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) :
review: Approve
6871. By Tony Espy

plugins: added debug hooks to ubuntu-provision

6872. By Tony Espy

plugins: fix ubuntu-provision's error logic

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-06-24 18:59:26 +0000
3+++ Makefile.am 2014-07-21 18:55:43 +0000
4@@ -127,6 +127,9 @@
5 builtin_modules += mtk
6 builtin_sources += plugins/mtk.c
7
8+builtin_modules += infineon
9+builtin_sources += plugins/infineon.c
10+
11 builtin_modules += androidspntable
12 builtin_sources += plugins/android-spn-table.c
13
14@@ -506,13 +509,13 @@
15
16 if PROVISION
17 builtin_sources += plugins/mbpi.h plugins/mbpi.c
18-builtin_sources += plugins/android-apndb.h plugins/android-apndb.c
19+builtin_sources += plugins/ubuntu-apndb.h plugins/ubuntu-apndb.c
20
21 builtin_modules += provision
22 builtin_sources += plugins/provision.c
23
24-builtin_modules += android_provision
25-builtin_sources += plugins/android-provision.c
26+builtin_modules += ubuntu_provision
27+builtin_sources += plugins/ubuntu-provision.c
28
29 builtin_modules += cdma_provision
30 builtin_sources += plugins/cdma-provision.c
31
32=== modified file 'debian/changelog'
33--- debian/changelog 2014-06-25 00:58:02 +0000
34+++ debian/changelog 2014-07-21 18:55:43 +0000
35@@ -1,3 +1,22 @@
36+ofono (1.12.bzr6870+14.10.20140625-0ubuntu1) UNRELEASED; urgency=medium
37+
38+ [ Martti Piirainen ]
39+ * drivers/rilmodem/sim.c: notify on SIM removal (LP: #1332306)
40+ * unit/rilmodem/test-sim-online: fix serial number check (LP: #1334867)
41+
42+ [ Alfonso Sanchez-Beato ]
43+ * plugins/mtk.c: fix race condition when onlining modem
44+ * build, drivers/infeonmodem, drivers/rilmodem, gril,
45+ plugins/infeon.c, plugins/ril.*, unit: add Infeon OEM hooks
46+
47+ [ Tony Espy ]
48+ * build, plugins/ubuntu-provision.c, ubuntu-apndb.*: re-named
49+ provisioning plugin code from android-* to ubuntu-*. Also removed
50+ code that queries mobile-broadband-provider-info's db, and finally
51+ implemented a /custom hook for custom apn dbs (LP: #1315509).
52+
53+ -- Tony Espy <espy@canonical.com> Wed, 16 Jul 2014 15:06:02 -0400
54+
55 ofono (1.12.bzr6868+14.10.20140625-0ubuntu1) utopic; urgency=medium
56
57 [ Alfonso Sanchez-Beato ]
58
59=== added directory 'drivers/infineonmodem'
60=== added file 'drivers/infineonmodem/infineon_constants.h'
61--- drivers/infineonmodem/infineon_constants.h 1970-01-01 00:00:00 +0000
62+++ drivers/infineonmodem/infineon_constants.h 2014-07-21 18:55:43 +0000
63@@ -0,0 +1,77 @@
64+/*
65+ *
66+ * RIL constants for infineon modem
67+ *
68+ * Copyright (C) 2014 Canonical Ltd.
69+ *
70+ * This program is free software; you can redistribute it and/or modify
71+ * it under the terms of the GNU General Public License version 2 as
72+ * published by the Free Software Foundation.
73+ *
74+ * This program is distributed in the hope that it will be useful,
75+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
76+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
77+ * GNU General Public License for more details.
78+ *
79+ * You should have received a copy of the GNU General Public License
80+ * along with this program; if not, write to the Free Software
81+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
82+ *
83+ */
84+
85+#ifndef INFINEON_CONSTANTS_H
86+#define INFINEON_CONSTANTS_H
87+
88+/* Messages encapsulated in RIL_REQUEST_OEM_HOOK_RAW requests */
89+#define INF_RIL_REQUEST_OEM_QUERY_SELECT_BAND 1
90+#define INF_RIL_REQUEST_OEM_SET_SELECT_BAND 2
91+#define INF_RIL_REQUEST_OEM_SET_CIRCUIT_SWITCHING_PAGING 3
92+#define INF_RIL_REQUEST_OEM_GET_LAST_FAILURE_REPORT_FOR_CS_REGISTRATION 4
93+#define INF_RIL_REQUEST_OEM_GET_SELECT_BEARER_SERVICE_TYPE 5
94+#define INF_RIL_REQUEST_OEM_GET_XPROGRESS_STATUS 6
95+#define INF_RIL_REQUEST_OEM_SET_SS_NOTIFY 7
96+#define INF_RIL_REQUEST_OEM_GET_SS_NOTIFY 8
97+#define INF_RIL_REQUEST_OEM_SET_AUTHENTICATION_TYPE 9
98+#define INF_RIL_REQUEST_OEM_SWITCH_OFF_MS 10
99+#define INF_RIL_REQUEST_OEM_SET_AUTO_TIMEZONE_UPDATE 11
100+#define INF_RIL_REQUEST_OEM_SET_TIMEZONE_RESPORTING 12
101+#define INF_RIL_REQUEST_OEM_SET_DISPLAY_SIM_AND_PB_STATUS 13
102+#define INF_RIL_REQUEST_OEM_GET_REMAIN_SIM_PIN_ATTEMPTS 14
103+#define INF_RIL_REQUEST_OEM_SET_AUTO_REDIAL 15
104+#define INF_RIL_REQUEST_OEM_QUERY_CALL_STATUS_REPORTING 16
105+#define INF_RIL_REQUEST_OEM_SET_AUTO_ANSWER 17
106+#define INF_RIL_REQUEST_OEM_SET_LINE 18
107+#define INF_RIL_REQUEST_OEM_PDP_ACTIVATE_OR_DEACTIVATE 19
108+#define INF_RIL_REQUEST_OEM_QUERY_GPRS_MS_CLASS 20
109+#define INF_RIL_REQUEST_OEM_SET_TRACE_AND_AT_INTERFACES 21
110+#define INF_RIL_REQUEST_OEM_QUERY_TRACE_AND_AT_INTERFACES_CONFIGURE 22
111+#define INF_RIL_REQUEST_OEM_SWITCH_TRACE_ON_OR_OFF 23
112+#define INF_RIL_REQUEST_OEM_READ_EXCEPTION_LOG 24
113+#define INF_RIL_REQUEST_OEM_GET_PHONE_ACTIVITY_STATUS 25
114+#define INF_RIL_REQUEST_OEM_INITIATE_RESEND_SMS_IF_GPRS_FAILS 26
115+#define INF_RIL_REQUEST_OEM_GET_DEVICE_NUMBER 27
116+#define INF_RIL_REQUEST_OEM_ENABLE_STK 28
117+#define INF_RIL_REQUEST_OEM_GET_SUBSCRIBER_NUMBER 29
118+#define INF_RIL_REQUEST_OEM_SELECT_PHONE_BOOK 30
119+#define INF_RIL_REQUEST_OEM_READ_PHONE_BOOK 31
120+#define INF_RIL_REQUEST_OEM_INSERT_RECORD_TO_PHONE_BOOK 32
121+#define INF_RIL_REQUEST_OEM_DELECT_RECORD_IN_PHONE_BOOK 33
122+#define INF_RIL_REQUEST_OEM_GET_RECORD_FIELDS_MAX_LEN 34
123+#define INF_RIL_REQUEST_OEM_SET_SERIAL_PORT 35
124+#define INF_RIL_REQUEST_OEM_SET_DATA_PREFERED 36
125+#define INF_RIL_REQUEST_OEM_SET_MODEM_ROUTING 37
126+#define INF_RIL_REQUEST_OEM_CLEAR_MISS_NUMBER 38
127+#define INF_RIL_REQUEST_OEM_ATH 39
128+#define INF_RIL_REQUEST_OEM_NOSIG_MODE_TEST 40
129+#define INF_RIL_REQUEST_OEM_SELECT_3G_BAND 41
130+#define INF_RIL_REQUEST_OEM_QUERY_3G_BAND 42
131+#define INF_RIL_REQUEST_OEM_HW_RESET_MODEM 43
132+#define INF_RIL_REQUEST_OEM_QUERY_DIRECT 44
133+#define INF_RIL_REQUEST_OEM_USER_PLMN_QUERY 45
134+#define INF_RIL_REQUEST_OEM_USER_PLMN_SET 46
135+#define INF_RIL_REQUEST_OEM_USER_PLMN_DELTE 47
136+#define INF_RIL_REQUEST_OEM_SET_USB_LOG 48
137+#define INF_RIL_REQUEST_OEM_UPDATE_CSQ 49
138+#define INF_RIL_REQUEST_OEM_DUMP_CELL_ENV 50
139+
140+#endif /* INFINEON_CONSTANTS_H */
141
142=== modified file 'drivers/rilmodem/sim.c'
143--- drivers/rilmodem/sim.c 2014-06-24 18:59:26 +0000
144+++ drivers/rilmodem/sim.c 2014-07-21 18:55:43 +0000
145@@ -51,6 +51,8 @@
146 #include "grilrequest.h"
147 #include "grilunsol.h"
148
149+#include "drivers/infineonmodem/infineon_constants.h"
150+
151 /*
152 * Based on ../drivers/atmodem/sim.c.
153 *
154@@ -72,6 +74,7 @@
155 */
156 struct sim_data {
157 GRil *ril;
158+ enum ofono_ril_vendor vendor;
159 gchar *aid_str;
160 guint app_type;
161 gchar *app_str;
162@@ -675,6 +678,9 @@
163 */
164 __ofono_sim_recheck_pin(sim);
165 }
166+ } else if (status && status->card_state == RIL_CARDSTATE_ABSENT) {
167+ ofono_info("SIM card absent");
168+ ofono_sim_inserted_notify(sim, FALSE);
169 }
170
171 g_ril_reply_free_sim_status(status);
172@@ -703,12 +709,72 @@
173 send_get_sim_status(sim);
174 }
175
176+static void inf_pin_retries_cb(struct ril_msg *message, gpointer user_data)
177+{
178+ struct cb_data *cbd = user_data;
179+ ofono_sim_pin_retries_cb_t cb = cbd->cb;
180+ struct sim_data *sd = cbd->user;
181+ struct reply_oem_hook *reply = NULL;
182+ int32_t *ret_data;
183+
184+ if (message->error != RIL_E_SUCCESS) {
185+ ofono_error("Reply failure: %s",
186+ ril_error_to_string(message->error));
187+ goto error;
188+ }
189+
190+ reply = g_ril_reply_oem_hook_raw(sd->ril, message);
191+ if (reply == NULL) {
192+ ofono_error("%s: parse error", __func__);
193+ goto error;
194+ }
195+
196+ if (reply->length < 5 * (int) sizeof(int32_t)) {
197+ ofono_error("%s: reply too small", __func__);
198+ goto error;
199+ }
200+
201+ /* First integer is INF_RIL_REQUEST_OEM_GET_REMAIN_SIM_PIN_ATTEMPTS */
202+ ret_data = reply->data;
203+ sd->retries[OFONO_SIM_PASSWORD_SIM_PIN] = *(++ret_data);
204+ sd->retries[OFONO_SIM_PASSWORD_SIM_PIN2] = *(++ret_data);
205+ sd->retries[OFONO_SIM_PASSWORD_SIM_PUK] = *(++ret_data);
206+ sd->retries[OFONO_SIM_PASSWORD_SIM_PUK2] = *(++ret_data);
207+
208+ g_ril_reply_free_oem_hook(reply);
209+ CALLBACK_WITH_SUCCESS(cb, sd->retries, cbd->data);
210+
211+ return;
212+
213+error:
214+ g_ril_reply_free_oem_hook(reply);
215+ CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
216+}
217+
218 static void ril_query_pin_retries(struct ofono_sim *sim,
219 ofono_sim_pin_retries_cb_t cb,
220 void *data)
221 {
222 struct sim_data *sd = ofono_sim_get_data(sim);
223- CALLBACK_WITH_SUCCESS(cb, sd->retries, data);
224+
225+ if (sd->vendor == OFONO_RIL_VENDOR_INFINEON) {
226+ struct cb_data *cbd = cb_data_new(cb, data, sd);
227+ struct parcel rilp;
228+ int32_t oem_req =
229+ INF_RIL_REQUEST_OEM_GET_REMAIN_SIM_PIN_ATTEMPTS;
230+
231+ g_ril_request_oem_hook_raw(sd->ril, &oem_req,
232+ sizeof(oem_req), &rilp);
233+
234+ /* Send request to RIL */
235+ if (g_ril_send(sd->ril, RIL_REQUEST_OEM_HOOK_RAW, &rilp,
236+ inf_pin_retries_cb, cbd, g_free) == 0) {
237+ g_free(cbd);
238+ CALLBACK_WITH_FAILURE(cb, NULL, data);
239+ }
240+ } else {
241+ CALLBACK_WITH_SUCCESS(cb, sd->retries, data);
242+ }
243 }
244
245 static void ril_query_passwd_state(struct ofono_sim *sim,
246@@ -893,6 +959,7 @@
247
248 sd = g_new0(struct sim_data, 1);
249 sd->ril = g_ril_clone(ril);
250+ sd->vendor = vendor;
251 sd->aid_str = NULL;
252 sd->app_str = NULL;
253 sd->app_type = RIL_APPTYPE_UNKNOWN;
254
255=== modified file 'drivers/rilmodem/vendor.h'
256--- drivers/rilmodem/vendor.h 2014-03-20 07:46:16 +0000
257+++ drivers/rilmodem/vendor.h 2014-07-21 18:55:43 +0000
258@@ -24,7 +24,8 @@
259
260 enum ofono_ril_vendor {
261 OFONO_RIL_VENDOR_AOSP = 0,
262- OFONO_RIL_VENDOR_MTK
263+ OFONO_RIL_VENDOR_MTK,
264+ OFONO_RIL_VENDOR_INFINEON
265 };
266
267 #endif /* RILMODEM_VENDOR_H */
268
269=== modified file 'gril/grilreply.c'
270--- gril/grilreply.c 2014-05-13 01:21:09 +0000
271+++ gril/grilreply.c 2014-07-21 18:55:43 +0000
272@@ -1204,6 +1204,11 @@
273 retries[OFONO_SIM_PASSWORD_SIM_PUK],
274 retries[OFONO_SIM_PASSWORD_SIM_PUK2]);
275 break;
276+ case OFONO_RIL_VENDOR_INFINEON:
277+ ofono_error("%s: infineon type should not arrive here",
278+ __func__);
279+ g_assert(FALSE);
280+ break;
281 }
282
283 if (rilp.malformed) {
284@@ -1220,3 +1225,50 @@
285
286 return NULL;
287 }
288+
289+void g_ril_reply_free_oem_hook(struct reply_oem_hook *oem_hook)
290+{
291+ if (oem_hook) {
292+ g_free(oem_hook->data);
293+ g_free(oem_hook);
294+ }
295+}
296+
297+struct reply_oem_hook *g_ril_reply_oem_hook_raw(GRil *gril,
298+ const struct ril_msg *message)
299+{
300+ struct reply_oem_hook *reply = NULL;
301+ struct parcel rilp;
302+
303+ reply = g_try_malloc0(sizeof(*reply));
304+ if (reply == NULL) {
305+ ofono_error("%s: out of memory", __func__);
306+ goto end;
307+ }
308+
309+ g_ril_init_parcel(message, &rilp);
310+
311+ reply->data = parcel_r_raw(&rilp, &(reply->length));
312+
313+ if (rilp.malformed) {
314+ ofono_error("%s: malformed parcel", __func__);
315+ g_ril_reply_free_oem_hook(reply);
316+ reply = NULL;
317+ goto end;
318+ }
319+
320+ g_ril_append_print_buf(gril, "{%d", reply->length);
321+
322+ if (reply->data != NULL) {
323+ char *hex_dump;
324+ hex_dump = encode_hex(reply->data, reply->length, '\0');
325+ g_ril_append_print_buf(gril, "%s,%s", print_buf, hex_dump);
326+ g_free(hex_dump);
327+ }
328+
329+ g_ril_append_print_buf(gril, "%s}", print_buf);
330+ g_ril_print_response(gril, message);
331+
332+end:
333+ return reply;
334+}
335
336=== modified file 'gril/grilreply.h'
337--- gril/grilreply.h 2014-04-29 15:50:22 +0000
338+++ gril/grilreply.h 2014-07-21 18:55:43 +0000
339@@ -89,6 +89,11 @@
340 int provisioned;
341 };
342
343+struct reply_oem_hook {
344+ int length;
345+ void *data;
346+};
347+
348 void g_ril_reply_free_avail_ops(struct reply_avail_ops *reply);
349
350 struct reply_avail_ops *g_ril_reply_parse_avail_ops(GRil *gril,
351@@ -160,6 +165,11 @@
352 int *g_ril_reply_parse_retries(GRil *gril, const struct ril_msg *message,
353 enum ofono_sim_password_type passwd_type);
354
355+void g_ril_reply_free_oem_hook(struct reply_oem_hook *oem_hook);
356+
357+struct reply_oem_hook *g_ril_reply_oem_hook_raw(GRil *gril,
358+ const struct ril_msg *message);
359+
360 #ifdef __cplusplus
361 }
362 #endif
363
364=== modified file 'gril/grilrequest.c'
365--- gril/grilrequest.c 2014-06-12 08:29:40 +0000
366+++ gril/grilrequest.c 2014-07-21 18:55:43 +0000
367@@ -1030,3 +1030,18 @@
368 g_ril_append_print_buf(gril, "(%s,%s,%s)",
369 facility, old_passwd, new_passwd);
370 }
371+
372+void g_ril_request_oem_hook_raw(GRil *gril, const void *payload, size_t length,
373+ struct parcel *rilp)
374+{
375+ char *hex_dump = NULL;
376+
377+ parcel_init(rilp);
378+ parcel_w_raw(rilp, payload, length);
379+
380+ if (payload != NULL)
381+ hex_dump = encode_hex(payload, length, '\0');
382+
383+ g_ril_append_print_buf(gril, "(%s)", hex_dump? hex_dump: "(null)");
384+ g_free(hex_dump);
385+}
386
387=== modified file 'gril/grilrequest.h'
388--- gril/grilrequest.h 2014-06-12 08:29:40 +0000
389+++ gril/grilrequest.h 2014-07-21 18:55:43 +0000
390@@ -265,6 +265,9 @@
391 const char *new_passwd,
392 struct parcel *rilp);
393
394+void g_ril_request_oem_hook_raw(GRil *gril, const void *payload, size_t length,
395+ struct parcel *rilp);
396+
397 #ifdef __cplusplus
398 }
399 #endif
400
401=== modified file 'gril/parcel.c'
402--- gril/parcel.c 2013-12-05 13:53:09 +0000
403+++ gril/parcel.c 2014-07-21 18:55:43 +0000
404@@ -201,6 +201,58 @@
405 return ret;
406 }
407
408+int parcel_w_raw(struct parcel *p, const void* data, size_t len)
409+{
410+ if (data == NULL) {
411+ parcel_w_int32(p, -1);
412+ return 0;
413+ }
414+
415+ parcel_w_int32(p, len);
416+
417+ for (;;) {
418+
419+ if (p->offset + len < p->capacity) {
420+ /* There's enough space */
421+ memcpy(p->data + p->offset, data, len);
422+ p->offset += len;
423+ p->size += len;
424+ break;
425+ } else {
426+ /* Grow data and retry */
427+ parcel_grow(p, len);
428+ }
429+ }
430+ return 0;
431+}
432+
433+void *parcel_r_raw(struct parcel *p, int *len)
434+{
435+ char *ret;
436+
437+ *len = parcel_r_int32(p);
438+
439+ if (p->malformed || *len <= 0)
440+ return NULL;
441+
442+ if (p->offset + *len > p->size) {
443+ ofono_error("%s: parcel is too small", __func__);
444+ p->malformed = 1;
445+ return NULL;
446+ }
447+
448+ ret = g_try_malloc0(*len);
449+ if (ret == NULL) {
450+ ofono_error("%s: out of memory (%d bytes)", __func__, *len);
451+ return NULL;
452+ }
453+
454+ memcpy(ret, p->data + p->offset, *len);
455+ p->offset += *len;
456+
457+ return ret;
458+}
459+
460 size_t parcel_data_avail(struct parcel *p)
461 {
462 return (p->size - p->offset);
463
464=== modified file 'gril/parcel.h'
465--- gril/parcel.h 2013-12-05 13:53:09 +0000
466+++ gril/parcel.h 2014-07-21 18:55:43 +0000
467@@ -39,6 +39,8 @@
468 int parcel_w_int32(struct parcel *p, int32_t val);
469 int parcel_w_string(struct parcel *p, const char *str);
470 char *parcel_r_string(struct parcel *p);
471+int parcel_w_raw(struct parcel *p, const void *data, size_t len);
472+void *parcel_r_raw(struct parcel *p, int *len);
473 size_t parcel_data_avail(struct parcel *p);
474
475 #endif
476
477=== removed file 'plugins/android-apndb.c'
478--- plugins/android-apndb.c 2014-04-25 16:10:01 +0000
479+++ plugins/android-apndb.c 1970-01-01 00:00:00 +0000
480@@ -1,494 +0,0 @@
481-/*
482- *
483- * oFono - Open Source Telephony
484- *
485- * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
486- * 2013 Simon Busch <morphis@gravedo.de>
487- * Copyright (C) 2014 Canonical Ltd.
488- *
489- * This program is free software; you can redistribute it and/or modify
490- * it under the terms of the GNU General Public License version 2 as
491- * published by the Free Software Foundation.
492- *
493- * This program is distributed in the hope that it will be useful,
494- * but WITHOUT ANY WARRANTY; without even the implied warranty of
495- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
496- * GNU General Public License for more details.
497- *
498- * You should have received a copy of the GNU General Public License
499- * along with this program; if not, write to the Free Software
500- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
501- *
502- */
503-
504-#ifdef HAVE_CONFIG_H
505-#include <config.h>
506-#endif
507-
508-#include <string.h>
509-#include <fcntl.h>
510-#include <sys/mman.h>
511-#include <sys/stat.h>
512-#include <sys/types.h>
513-#include <errno.h>
514-#include <stdlib.h>
515-#include <unistd.h>
516-
517-#include <glib.h>
518-
519-#define OFONO_API_SUBJECT_TO_CHANGE
520-#include <ofono/modem.h>
521-#include <ofono/gprs-provision.h>
522-#include <ofono/log.h>
523-
524-#include "android-apndb.h"
525-
526-/* TODO: consider reading path from an environment variable */
527-
528-#ifndef ANDROID_APN_DATABASE
529-#define ANDROID_APN_DATABASE "/android/system/etc/apns-conf.xml"
530-#endif
531-
532-struct apndb_data {
533- const char *match_mcc;
534- const char *match_mnc;
535- const char *match_imsi;
536- const char *match_spn;
537- const char *match_gid1;
538- GSList *apns;
539- gboolean allow_duplicates;
540- gboolean mvno_found;
541-};
542-
543-void android_apndb_ap_free(gpointer data)
544-{
545- struct apndb_provision_data *ap = data;
546-
547- g_free(ap->gprs_data.name);
548- g_free(ap->gprs_data.apn);
549- g_free(ap->gprs_data.username);
550- g_free(ap->gprs_data.password);
551- g_free(ap->gprs_data.message_proxy);
552- g_free(ap->gprs_data.message_center);
553-
554- g_free(ap);
555-}
556-
557-static void android_apndb_g_set_error(GMarkupParseContext *context,
558- GError **error,
559- GQuark domain,
560- gint code,
561- const gchar *fmt, ...)
562-{
563- va_list ap;
564- gint line_number, char_number;
565-
566- g_markup_parse_context_get_position(context, &line_number,
567- &char_number);
568- va_start(ap, fmt);
569-
570- *error = g_error_new_valist(domain, code, fmt, ap);
571-
572- va_end(ap);
573-
574- g_prefix_error(error, "%s:%d ", ANDROID_APN_DATABASE, line_number);
575-}
576-
577-static gboolean imsi_match(const char *imsi, const char *match)
578-{
579- gboolean result = FALSE;
580- size_t imsi_len = strlen(imsi);
581- size_t match_len = strlen(match);
582- unsigned int i;
583-
584- DBG("imsi %s match %s", imsi, match);
585-
586- if (imsi_len != match_len)
587- goto done;
588-
589- for (i = 0; i < imsi_len; i++) {
590- if (*(imsi + i) == *(match + i))
591- continue;
592- else if (*(match + i) == 'x')
593- continue;
594- else
595- goto done;
596- }
597-
598- result = TRUE;
599-
600-done:
601- return result;
602-}
603-
604-static enum ofono_gprs_context_type determine_apn_type(const char *types)
605-{
606- /*
607- * The database contains entries with the following type field contents:
608- * - default
609- * - default,mms
610- * - default,supl
611- * - defualt,supl,dun
612- * - default,supl,mms
613- * - mms
614- */
615-
616- if (g_strcmp0(types, "mms") == 0)
617- return OFONO_GPRS_CONTEXT_TYPE_MMS;
618- else if (g_str_has_prefix(types, "default"))
619- return OFONO_GPRS_CONTEXT_TYPE_INTERNET;
620- else
621- return OFONO_GPRS_CONTEXT_TYPE_ANY;
622-}
623-
624-static char *android_apndb_sanitize_ipv4_address(const char *address)
625-{
626- char **numbers = NULL;
627- char *sanitized_numbers[4];
628- unsigned int count = 0;
629- char *result = NULL;
630- char *numeral;
631-
632- /*
633- * As src/gprs.c expects MMS proxies to always be
634- * specified using IPV4 numbers-and-dot notation,
635- * we need to strip any leading "0"s from the
636- * individual numeric components, otherwise they
637- * will be treated as octal numbers
638- * ( see 'man inet_aton' for details ).
639- */
640-
641- if (g_ascii_isdigit(*address) == FALSE)
642- goto done;
643-
644- numbers = g_strsplit(address, ".", 4);
645-
646- for (; (numeral = *(numbers+count)); count++) {
647- if (count > 3)
648- goto done;
649-
650- for (; *numeral; numeral++) {
651- if (g_ascii_isdigit(*numeral) == FALSE)
652- goto done;
653- else if (*numeral == '0')
654- continue;
655- else
656- break;
657- }
658-
659- if (*numeral)
660- sanitized_numbers[count] = numeral;
661- else
662- sanitized_numbers[count] = "0";
663- }
664-
665- if (count != 4)
666- goto done;
667-
668- result = g_strdup_printf("%s.%s.%s.%s",
669- sanitized_numbers[0],
670- sanitized_numbers[1],
671- sanitized_numbers[2],
672- sanitized_numbers[3]);
673-
674-done:
675- if (numbers != NULL)
676- g_strfreev(numbers);
677-
678- return result;
679-}
680-
681-static void toplevel_apndb_start(GMarkupParseContext *context,
682- const gchar *element_name,
683- const gchar **attribute_names,
684- const gchar **attribute_values,
685- gpointer userdata, GError **error)
686-{
687- struct apndb_data *apndb = userdata;
688- struct apndb_provision_data *ap = NULL;
689- int i;
690- const gchar *carrier = NULL;
691- const gchar *mcc = NULL;
692- const gchar *mnc = NULL;
693- const gchar *apn = NULL;
694- const gchar *username = NULL;
695- const gchar *password = NULL;
696- const gchar *types = NULL;
697- const gchar *protocol = NULL;
698- const gchar *mmsproxy = NULL;
699- const gchar *mmsport = NULL;
700- const gchar *mmscenter = NULL;
701- const gchar *mvnomatch = NULL;
702- const gchar *mvnotype = NULL;
703- enum ofono_gprs_proto proto = OFONO_GPRS_PROTO_IP;
704- enum ofono_gprs_context_type type;
705-
706- if (g_strcmp0(element_name, "apn") != 0)
707- return;
708-
709- for (i = 0; attribute_names[i]; i++) {
710- if (g_strcmp0(attribute_names[i], "carrier") == 0)
711- carrier = attribute_values[i];
712- else if (g_strcmp0(attribute_names[i], "mcc") == 0)
713- mcc = attribute_values[i];
714- else if (g_strcmp0(attribute_names[i], "mnc") == 0)
715- mnc = attribute_values[i];
716- }
717-
718- if (mcc == NULL) {
719- android_apndb_g_set_error(context, error, G_MARKUP_ERROR,
720- G_MARKUP_ERROR_MISSING_ATTRIBUTE,
721- "Missing attribute: mcc");
722- return;
723- }
724-
725- if (mnc == NULL) {
726- android_apndb_g_set_error(context, error, G_MARKUP_ERROR,
727- G_MARKUP_ERROR_MISSING_ATTRIBUTE,
728- "Missing attribute: mnc");
729- return;
730- }
731-
732- if (g_strcmp0(mcc, apndb->match_mcc) != 0 ||
733- g_strcmp0(mnc, apndb->match_mnc) != 0)
734- return;
735-
736- for (i = 0; attribute_names[i]; i++) {
737- if (g_strcmp0(attribute_names[i], "apn") == 0)
738- apn = attribute_values[i];
739- else if (g_strcmp0(attribute_names[i], "user") == 0)
740- username = attribute_values[i];
741- else if (g_strcmp0(attribute_names[i], "password") == 0)
742- password = attribute_values[i];
743- else if (g_strcmp0(attribute_names[i], "type") == 0)
744- types = attribute_values[i];
745- else if (g_strcmp0(attribute_names[i], "protocol") == 0)
746- protocol = attribute_values[i];
747- else if (g_strcmp0(attribute_names[i], "mmsc") == 0)
748- mmscenter = attribute_values[i];
749- else if (g_strcmp0(attribute_names[i], "mmsproxy") == 0)
750- mmsproxy = attribute_values[i];
751- else if (g_strcmp0(attribute_names[i], "mmsport") == 0)
752- mmsport = attribute_values[i];
753- else if (g_strcmp0(attribute_names[i], "mvno_match_data") == 0)
754- mvnomatch = attribute_values[i];
755- else if (g_strcmp0(attribute_names[i], "mvno_type") == 0)
756- mvnotype = attribute_values[i];
757- }
758-
759- if (apn == NULL) {
760- android_apndb_g_set_error(context, error, G_MARKUP_ERROR,
761- G_MARKUP_ERROR_MISSING_ATTRIBUTE,
762- "APN attribute missing");
763- return;
764- }
765-
766- if (types == NULL) {
767- ofono_error("%s: apn for %s missing type attribute", __func__,
768- carrier);
769- return;
770- }
771-
772- if (protocol != NULL) {
773- if (g_strcmp0(protocol, "IP") == 0) {
774- proto = OFONO_GPRS_PROTO_IP;
775- } else if (g_strcmp0(protocol, "IPV6") == 0) {
776- proto = OFONO_GPRS_PROTO_IPV6;
777- } else if (g_strcmp0(protocol, "IPV4V6") == 0) {
778- proto = OFONO_GPRS_PROTO_IPV4V6;
779- } else {
780- ofono_error("%s: APN %s has invalid protocol=%s"
781- "attribute", __func__, carrier,
782- protocol);
783- return;
784- }
785- }
786-
787- if (mvnotype != NULL && mvnomatch != NULL) {
788-
789- if (g_strcmp0(mvnotype, "imsi") == 0) {
790- DBG("APN %s is mvno_type 'imsi'", carrier);
791-
792- if (apndb->match_imsi == NULL ||
793- imsi_match(apndb->match_imsi,
794- mvnomatch) == FALSE) {
795- DBG("Skipping MVNO 'imsi' APN %s with"
796- " match_data: %s", carrier, mvnomatch);
797- return;
798- }
799- } else if (g_strcmp0(mvnotype, "spn") == 0) {
800- DBG("APN %s is mvno_type 'spn'", carrier);
801-
802- if (g_strcmp0(mvnomatch, apndb->match_spn) != 0) {
803- DBG("Skipping mvno 'spn' APN %s with"
804- " match_data: %s", carrier, mvnomatch);
805- return;
806- }
807-
808- } else if (g_strcmp0(mvnotype, "gid") == 0) {
809- int match_len = strlen(mvnomatch);
810-
811- DBG("APN %s is mvno_type 'gid'", carrier);
812-
813- /* Check initial part of GID1 against match data */
814- if (apndb->match_gid1 == NULL ||
815- g_ascii_strncasecmp(mvnomatch,
816- apndb->match_gid1,
817- match_len) != 0) {
818- DBG("Skipping mvno 'gid' APN %s with"
819- " match_data: %s", carrier, mvnomatch);
820- return;
821- }
822- }
823- }
824-
825- type = determine_apn_type(types);
826-
827- if (type == OFONO_GPRS_CONTEXT_TYPE_ANY ||
828- (type == OFONO_GPRS_CONTEXT_TYPE_MMS && mmsproxy == NULL)) {
829- DBG("Skipping %s context; types: %s", apn, types);
830- return;
831- }
832-
833- ap = g_try_new0(struct apndb_provision_data, 1);
834- if (ap == NULL) {
835- ofono_error("%s: out-of-memory trying to provision APN - %s",
836- __func__, carrier);
837- return;
838- }
839-
840- ap->gprs_data.type = type;
841-
842- if (carrier != NULL)
843- ap->gprs_data.name = g_strdup(carrier);
844-
845- if (apn != NULL)
846- ap->gprs_data.apn = g_strdup(apn);
847-
848- if (username != NULL)
849- ap->gprs_data.username = g_strdup(username);
850-
851- if (password != NULL)
852- ap->gprs_data.password = g_strdup(password);
853-
854- if (mmscenter != NULL && strlen(mmscenter) > 0)
855- ap->gprs_data.message_center = g_strdup(mmscenter);
856-
857- if (mmsproxy != NULL && strlen(mmsproxy) > 0) {
858- char *tmp = android_apndb_sanitize_ipv4_address(mmsproxy);
859- if (tmp != NULL)
860- mmsproxy = tmp;
861-
862- if (mmsport != NULL)
863- ap->gprs_data.message_proxy =
864- g_strdup_printf("%s:%s", mmsproxy, mmsport);
865- else
866- ap->gprs_data.message_proxy = g_strdup(mmsproxy);
867-
868- g_free(tmp);
869- }
870-
871- ap->gprs_data.proto = proto;
872-
873- if (mvnotype != NULL) {
874- ap->mvno = TRUE;
875- apndb->mvno_found = TRUE;
876- }
877-
878- apndb->apns = g_slist_append(apndb->apns, ap);
879-}
880-
881-static void toplevel_apndb_end(GMarkupParseContext *context,
882- const gchar *element_name,
883- gpointer userdata, GError **error)
884-{
885-}
886-
887-static const GMarkupParser toplevel_apndb_parser = {
888- toplevel_apndb_start,
889- toplevel_apndb_end,
890- NULL,
891- NULL,
892- NULL,
893-};
894-
895-static gboolean android_apndb_parse(const GMarkupParser *parser,
896- gpointer userdata,
897- GError **error)
898-{
899- struct stat st;
900- char *db;
901- int fd;
902- GMarkupParseContext *context;
903- gboolean ret;
904- const char *apndb_path;
905-
906- if ((apndb_path = getenv("OFONO_APNDB_PATH")) == NULL)
907- apndb_path = ANDROID_APN_DATABASE;
908-
909- fd = open(apndb_path, O_RDONLY);
910- if (fd < 0) {
911- g_set_error(error, G_FILE_ERROR,
912- g_file_error_from_errno(errno),
913- "open(%s) failed: %s", apndb_path,
914- g_strerror(errno));
915- return FALSE;
916- }
917-
918- if (fstat(fd, &st) < 0) {
919- close(fd);
920- g_set_error(error, G_FILE_ERROR,
921- g_file_error_from_errno(errno),
922- "fstat(%s) failed: %s", apndb_path,
923- g_strerror(errno));
924- return FALSE;
925- }
926-
927- db = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
928- if (db == MAP_FAILED) {
929- close(fd);
930- g_set_error(error, G_FILE_ERROR,
931- g_file_error_from_errno(errno),
932- "mmap(%s) failed: %s", apndb_path,
933- g_strerror(errno));
934- return FALSE;
935- }
936-
937- context = g_markup_parse_context_new(parser,
938- G_MARKUP_TREAT_CDATA_AS_TEXT,
939- userdata, NULL);
940-
941- ret = g_markup_parse_context_parse(context, db, st.st_size, error);
942-
943- if (ret == TRUE)
944- g_markup_parse_context_end_parse(context, error);
945-
946- munmap(db, st.st_size);
947- close(fd);
948- g_markup_parse_context_free(context);
949-
950- return ret;
951-}
952-
953-GSList *android_apndb_lookup_apn(const char *mcc, const char *mnc,
954- const char *spn, const char *imsi, const char *gid1,
955- gboolean *mvno_found, GError **error)
956-{
957- struct apndb_data apndb = { NULL };
958-
959- apndb.match_mcc = mcc;
960- apndb.match_mnc = mnc;
961- apndb.match_spn = spn;
962- apndb.match_imsi = imsi;
963- apndb.match_gid1 = gid1;
964-
965- if (android_apndb_parse(&toplevel_apndb_parser, &apndb,
966- error) == FALSE) {
967- g_slist_free_full(apndb.apns, android_apndb_ap_free);
968- apndb.apns = NULL;
969- }
970-
971- *mvno_found = apndb.mvno_found;
972-
973- return apndb.apns;
974-}
975
976=== removed file 'plugins/android-apndb.h'
977--- plugins/android-apndb.h 2014-04-14 13:59:23 +0000
978+++ plugins/android-apndb.h 1970-01-01 00:00:00 +0000
979@@ -1,33 +0,0 @@
980-/*
981- *
982- * oFono - Open Source Telephony
983- *
984- * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
985- * 2013 Simon Busch <morphis@gravedo.de>
986- * Copyright (C) 2014 Canonical Ltd.
987- *
988- * This program is free software; you can redistribute it and/or modify
989- * it under the terms of the GNU General Public License version 2 as
990- * published by the Free Software Foundation.
991- *
992- * This program is distributed in the hope that it will be useful,
993- * but WITHOUT ANY WARRANTY; without even the implied warranty of
994- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
995- * GNU General Public License for more details.
996- *
997- * You should have received a copy of the GNU General Public License
998- * along with this program; if not, write to the Free Software
999- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1000- *
1001- */
1002-
1003-struct apndb_provision_data {
1004- struct ofono_gprs_provision_data gprs_data;
1005- gboolean mvno;
1006-};
1007-
1008-void android_apndb_ap_free(gpointer data);
1009-
1010-GSList *android_apndb_lookup_apn(const char *mcc, const char *mnc,
1011- const char *spn, const char *imsi, const char *gid1,
1012- gboolean *mvno_found, GError **error);
1013
1014=== removed file 'plugins/android-provision.c'
1015--- plugins/android-provision.c 2014-05-13 17:15:55 +0000
1016+++ plugins/android-provision.c 1970-01-01 00:00:00 +0000
1017@@ -1,227 +0,0 @@
1018-/*
1019- *
1020- * oFono - Open Source Telephony
1021- *
1022- * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
1023- * 2013 Simon Busch <morphis@gravedo.de>
1024- * Copyright (C) 2014 Canonical Ltd.
1025- *
1026- * This program is free software; you can redistribute it and/or modify
1027- * it under the terms of the GNU General Public License version 2 as
1028- * published by the Free Software Foundation.
1029- *
1030- * This program is distributed in the hope that it will be useful,
1031- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1032- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1033- * GNU General Public License for more details.
1034- *
1035- * You should have received a copy of the GNU General Public License
1036- * along with this program; if not, write to the Free Software
1037- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1038- *
1039- */
1040-
1041-#ifdef HAVE_CONFIG_H
1042-#include <config.h>
1043-#endif
1044-
1045-#include <errno.h>
1046-#include <string.h>
1047-
1048-#include <glib.h>
1049-
1050-#define OFONO_API_SUBJECT_TO_CHANGE
1051-#include <ofono/types.h>
1052-#include <ofono/log.h>
1053-#include <ofono/plugin.h>
1054-#include <ofono/modem.h>
1055-#include <ofono/gprs-provision.h>
1056-
1057-#include "android-apndb.h"
1058-#include "mbpi.h"
1059-
1060-static unsigned int filter_apns(GSList **apns, GSList *mbpi_apns,
1061- gboolean mvno_found)
1062-{
1063- GSList *l = NULL;
1064- GSList *l2 = NULL;
1065- gboolean found = FALSE;
1066- unsigned int ap_count = g_slist_length(*apns);
1067- struct apndb_provision_data *ap;
1068-
1069- if (mvno_found == TRUE) {
1070-
1071- for (l = *apns; l;) {
1072- ap = l->data;
1073- l = l->next;
1074-
1075- if (ap->mvno == FALSE) {
1076- DBG("Removing: %s", ap->gprs_data.apn);
1077- *apns = g_slist_remove(*apns,
1078- (gconstpointer) ap);
1079- android_apndb_ap_free(ap);
1080- ap_count--;
1081- }
1082- }
1083-
1084- goto done;
1085- }
1086-
1087- for (l = mbpi_apns; l; l = l->next, found = FALSE) {
1088- struct ofono_gprs_provision_data *ap2 = l->data;
1089-
1090- if (ap2->apn == NULL) {
1091- ofono_error("%s: invalid mbpi entry - %s found",
1092- __func__, ap2->name);
1093- continue;
1094- }
1095-
1096- for (l2 = *apns; l2; l2 = l2->next) {
1097- ap = l2->data;
1098-
1099- if (ap->gprs_data.apn != NULL &&
1100- ap->gprs_data.type ==
1101- OFONO_GPRS_CONTEXT_TYPE_INTERNET &&
1102- g_strcmp0(ap2->apn, ap->gprs_data.apn) == 0) {
1103-
1104- found = TRUE;
1105- break;
1106- }
1107- }
1108-
1109- if (found == FALSE) {
1110- DBG("Adding %s to apns", ap2->apn);
1111-
1112- ap = g_try_new0(struct apndb_provision_data, 1);
1113- if (ap == NULL) {
1114- ofono_error("%s: out-of-memory trying to"
1115- " provision APN - %s",
1116- __func__, ap2->name);
1117- goto done;
1118- }
1119-
1120- memcpy(&ap->gprs_data, ap2, sizeof(ap->gprs_data));
1121- *apns = g_slist_append(*apns, ap);
1122- ap_count++;
1123- g_free(ap2);
1124- } else {
1125- mbpi_ap_free(ap2);
1126- }
1127- }
1128-
1129-done:
1130- return ap_count;
1131-}
1132-
1133-static int provision_get_settings(const char *mcc, const char *mnc,
1134- const char *spn,
1135- const char *imsi, const char *gid1,
1136- struct ofono_gprs_provision_data **settings,
1137- int *count)
1138-{
1139- GSList *apns = NULL;
1140- GSList *mbpi_apns = NULL;
1141- GSList *l = NULL;
1142- GError *error = NULL;
1143- gboolean mvno_found = FALSE;
1144- unsigned int ap_count;
1145- unsigned int i;
1146-
1147- ofono_info("Provisioning for MCC %s, MNC %s, SPN '%s', IMSI '%s', "
1148- "GID1 '%s'", mcc, mnc, spn, imsi, gid1);
1149-
1150- apns = android_apndb_lookup_apn(mcc, mnc, spn, imsi, gid1,
1151- &mvno_found, &error);
1152- if (apns == NULL) {
1153- if (error != NULL) {
1154- ofono_error("%s: apndb_lookup error -%s for mcc %s"
1155- " mnc %s spn %s imsi %s", __func__,
1156- error->message, mcc, mnc, spn, imsi);
1157- g_error_free(error);
1158- error = NULL;
1159- }
1160- }
1161-
1162- /* If an mvno apn was found, only provision mvno apns */
1163- if (mvno_found == FALSE) {
1164- mbpi_apns = mbpi_lookup_apn(mcc, mnc,
1165- OFONO_GPRS_CONTEXT_TYPE_INTERNET,
1166- TRUE, &error);
1167- if (mbpi_apns == NULL) {
1168- if (error != NULL) {
1169- ofono_error("%s: MBPI error - %s for mcc %s"
1170- " mnc %s spn: %s", __func__,
1171- error->message, mcc, mnc, spn);
1172- g_error_free(error);
1173- error = NULL;
1174- }
1175- }
1176- }
1177-
1178- ap_count = filter_apns(&apns, mbpi_apns, mvno_found);
1179- if (ap_count == 0) {
1180- ofono_warn("%s: No APNs found for mcc %s mnc %s spn: %s"
1181- " imsi: %s", __func__, mcc, mnc, spn, imsi);
1182-
1183- *count = 0;
1184- return -ENOENT;
1185- }
1186-
1187- *settings = g_try_new0(struct ofono_gprs_provision_data, ap_count);
1188- if (*settings == NULL) {
1189- ofono_error("%s: provisioning failed: %s", __func__,
1190- g_strerror(errno));
1191-
1192- g_slist_free_full(apns, android_apndb_ap_free);
1193-
1194- *count = 0;
1195- return -ENOMEM;
1196- }
1197-
1198- *count = ap_count;
1199-
1200- for (l = apns, i = 0; l; l = l->next, i++) {
1201- struct apndb_provision_data *ap = l->data;
1202-
1203- DBG("Name: '%s'", ap->gprs_data.name);
1204- DBG("APN: '%s'", ap->gprs_data.apn);
1205- DBG("Type: %s", mbpi_ap_type(ap->gprs_data.type));
1206- DBG("Username: '%s'", ap->gprs_data.username);
1207- DBG("Password: '%s'", ap->gprs_data.password);
1208- DBG("Message Proxy: '%s'", ap->gprs_data.message_proxy);
1209- DBG("Message Center: '%s'", ap->gprs_data.message_center);
1210- DBG("MVNO: %u", ap->mvno);
1211-
1212- memcpy(*settings + i, &ap->gprs_data, sizeof(ap->gprs_data));
1213-
1214- g_free(ap);
1215- }
1216-
1217- if (apns != NULL)
1218- g_slist_free(apns);
1219-
1220- if (mbpi_apns != NULL)
1221- g_slist_free(mbpi_apns);
1222-
1223- return 0;
1224-}
1225-
1226-static struct ofono_gprs_provision_driver android_provision_driver = {
1227- .name = "Android APN database Provisioning",
1228- .get_settings = provision_get_settings
1229-};
1230-
1231-static int android_provision_init(void)
1232-{
1233- return ofono_gprs_provision_driver_register(&android_provision_driver);
1234-}
1235-
1236-static void android_provision_exit(void)
1237-{
1238- ofono_gprs_provision_driver_unregister(&android_provision_driver);
1239-}
1240-
1241-OFONO_PLUGIN_DEFINE(android_provision,
1242- "Android APN database Provisioning Plugin", VERSION,
1243- OFONO_PLUGIN_PRIORITY_DEFAULT,
1244- android_provision_init, android_provision_exit)
1245
1246=== added file 'plugins/infineon.c'
1247--- plugins/infineon.c 1970-01-01 00:00:00 +0000
1248+++ plugins/infineon.c 2014-07-21 18:55:43 +0000
1249@@ -0,0 +1,76 @@
1250+/*
1251+ *
1252+ * oFono - Open Source Telephony - RIL-based devices: infineon modems
1253+ *
1254+ * Copyright (C) 2014 Canonical Ltd.
1255+ *
1256+ * This program is free software; you can redistribute it and/or modify
1257+ * it under the terms of the GNU General Public License version 2 as
1258+ * published by the Free Software Foundation.
1259+ *
1260+ * This program is distributed in the hope that it will be useful,
1261+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1262+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1263+ * GNU General Public License for more details.
1264+ *
1265+ * You should have received a copy of the GNU General Public License
1266+ * along with this program; if not, write to the Free Software
1267+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1268+ *
1269+ */
1270+
1271+#ifdef HAVE_CONFIG_H
1272+#include <config.h>
1273+#endif
1274+
1275+#define OFONO_API_SUBJECT_TO_CHANGE
1276+
1277+#include <ofono/plugin.h>
1278+#include <ofono/log.h>
1279+#include <ofono/modem.h>
1280+
1281+#include "ofono.h"
1282+
1283+#include "drivers/rilmodem/vendor.h"
1284+#include "ril.h"
1285+
1286+static int inf_probe(struct ofono_modem *modem)
1287+{
1288+ return ril_create(modem, OFONO_RIL_VENDOR_INFINEON);
1289+}
1290+
1291+static struct ofono_modem_driver infineon_driver = {
1292+ .name = "infineon",
1293+ .probe = inf_probe,
1294+ .remove = ril_remove,
1295+ .enable = ril_enable,
1296+ .disable = ril_disable,
1297+ .pre_sim = ril_pre_sim,
1298+ .post_sim = ril_post_sim,
1299+ .post_online = ril_post_online,
1300+ .set_online = ril_set_online,
1301+};
1302+
1303+/*
1304+ * This plugin is a device plugin for infineon modems that use RIL interface.
1305+ * The plugin 'rildev' is used to determine which RIL plugin should be loaded
1306+ * based upon an environment variable.
1307+ */
1308+static int inf_init(void)
1309+{
1310+ int retval = 0;
1311+
1312+ if ((retval = ofono_modem_driver_register(&infineon_driver)))
1313+ DBG("ofono_modem_driver_register returned: %d", retval);
1314+
1315+ return retval;
1316+}
1317+
1318+static void inf_exit(void)
1319+{
1320+ DBG("");
1321+ ofono_modem_driver_unregister(&infineon_driver);
1322+}
1323+
1324+OFONO_PLUGIN_DEFINE(infineon, "Infineon modem driver", VERSION,
1325+ OFONO_PLUGIN_PRIORITY_DEFAULT, inf_init, inf_exit)
1326
1327=== modified file 'plugins/mtk.c'
1328--- plugins/mtk.c 2014-06-12 10:52:45 +0000
1329+++ plugins/mtk.c 2014-07-21 18:55:43 +0000
1330@@ -92,6 +92,8 @@
1331 int slot;
1332 struct ril_sim_data sim_data;
1333 struct ofono_devinfo *devinfo;
1334+ struct cb_data *pending_online_cbd;
1335+ ofono_bool_t pending_online;
1336 };
1337
1338 /*
1339@@ -106,6 +108,8 @@
1340 static void send_get_sim_status(struct ofono_modem *modem);
1341 static int create_gril(struct ofono_modem *modem);
1342 static gboolean mtk_connected(gpointer user_data);
1343+static void mtk_set_online(struct ofono_modem *modem, ofono_bool_t online,
1344+ ofono_modem_online_cb_t callback, void *data);
1345
1346 static void mtk_debug(const char *str, void *user_data)
1347 {
1348@@ -372,14 +376,23 @@
1349 send_get_sim_status(modem);
1350 }
1351
1352+static struct mtk_data *ril_complement(struct mtk_data *ril)
1353+{
1354+ if (ril->slot == MULTISIM_SLOT_0)
1355+ return mtk_1;
1356+ else
1357+ return mtk_0;
1358+}
1359+
1360 static void mtk_sim_mode_cb(struct ril_msg *message, gpointer user_data)
1361 {
1362 struct cb_data *cbd = user_data;
1363 ofono_modem_online_cb_t cb = cbd->cb;
1364 struct ofono_modem *modem = cbd->user;
1365 struct mtk_data *ril = ofono_modem_get_data(modem);
1366+ struct mtk_data *ril_c;
1367
1368- ril->pending_cb = NULL;
1369+ mtk_0->pending_cb = NULL;
1370
1371 if (message->error == RIL_E_SUCCESS) {
1372 g_ril_print_response_no_args(ril->modem, message);
1373@@ -390,6 +403,21 @@
1374 ril_error_to_string(message->error));
1375 CALLBACK_WITH_FAILURE(cb, cbd->data);
1376 }
1377+
1378+ /* Execute possible pending operation on the other modem */
1379+
1380+ ril_c = ril_complement(ril);
1381+
1382+ if (ril_c->pending_online_cbd) {
1383+ struct cb_data *pending_cbd = ril_c->pending_online_cbd;
1384+ ofono_modem_online_cb_t pending_cb = pending_cbd->cb;
1385+
1386+ mtk_set_online(pending_cbd->user, ril_c->pending_online,
1387+ pending_cb, pending_cbd->data);
1388+
1389+ g_free(ril_c->pending_online_cbd);
1390+ ril_c->pending_online_cbd = NULL;
1391+ }
1392 }
1393
1394 static int sim_state()
1395@@ -484,6 +512,25 @@
1396 ofono_modem_online_cb_t cb = cbd->cb;
1397 int current_state, next_state;
1398
1399+ /*
1400+ * Serialize online requests to avoid incoherent states. When changing
1401+ * the online state of *one* of the modems, we need to send a
1402+ * DUAL_SIM_MODE_SWITCH request, which affects *both* modems. Also, when
1403+ * we want to online one modem and at that time both modems are
1404+ * offline a RADIO_POWERON needs to be sent before DUAL_SIM_MODE_SWITCH,
1405+ * with the additional complexity of being disconnected from the rild
1406+ * socket while doing the sequence. This can take some time, and we
1407+ * cannot change the state of the other modem while the sequence is
1408+ * happenig, as DUAL_SIM_MODE_SWITCH affects both states. Therefore, we
1409+ * need to do this serialization, which is different from the one done
1410+ * per modem by ofono core.
1411+ */
1412+ if (mtk_0->pending_cb != NULL) {
1413+ ril->pending_online_cbd = cbd;
1414+ ril->pending_online = online;
1415+ return;
1416+ }
1417+
1418 current_state = sim_state();
1419
1420 ril->ofono_online = online;
1421
1422=== modified file 'plugins/ril.c'
1423--- plugins/ril.c 2014-06-24 18:59:26 +0000
1424+++ plugins/ril.c 2014-07-21 18:55:43 +0000
1425@@ -60,6 +60,7 @@
1426 #include <grilrequest.h>
1427 #include <grilunsol.h>
1428
1429+#include "ril.h"
1430 #include "drivers/rilmodem/rilmodem.h"
1431 #include "drivers/rilmodem/vendor.h"
1432
1433@@ -69,6 +70,7 @@
1434
1435 struct ril_data {
1436 GRil *modem;
1437+ enum ofono_ril_vendor vendor;
1438 int sim_status_retries;
1439 ofono_bool_t connected;
1440 ofono_bool_t have_sim;
1441@@ -118,7 +120,7 @@
1442 if (ril->voice == NULL)
1443 ril->voice =
1444 ofono_voicecall_create(modem,
1445- 0,
1446+ ril->vendor,
1447 RILMODEM,
1448 ril->modem);
1449
1450@@ -205,7 +207,7 @@
1451 sim_status_cb, modem, NULL);
1452 }
1453
1454-static int ril_probe(struct ofono_modem *modem)
1455+int ril_create(struct ofono_modem *modem, enum ofono_ril_vendor vendor)
1456 {
1457 struct ril_data *ril = g_try_new0(struct ril_data, 1);
1458 if (ril == NULL) {
1459@@ -215,6 +217,7 @@
1460
1461 DBG("");
1462
1463+ ril->vendor = vendor;
1464 ril->have_sim = FALSE;
1465 ril->ofono_online = FALSE;
1466 ril->radio_state = RADIO_STATE_OFF;
1467@@ -229,11 +232,15 @@
1468 return -errno;
1469 }
1470
1471-static void ril_remove(struct ofono_modem *modem)
1472+static int ril_probe(struct ofono_modem *modem)
1473+{
1474+ return ril_create(modem, OFONO_RIL_VENDOR_AOSP);
1475+}
1476+
1477+void ril_remove(struct ofono_modem *modem)
1478 {
1479 struct ril_data *ril = ofono_modem_get_data(modem);
1480
1481-
1482 ofono_modem_set_data(modem, NULL);
1483
1484 if (!ril)
1485@@ -244,24 +251,24 @@
1486 g_free(ril);
1487 }
1488
1489-static void ril_pre_sim(struct ofono_modem *modem)
1490+void ril_pre_sim(struct ofono_modem *modem)
1491 {
1492 struct ril_data *ril = ofono_modem_get_data(modem);
1493 struct ril_sim_data sim_data;
1494
1495 DBG("");
1496
1497- ofono_devinfo_create(modem, 0, RILMODEM, ril->modem);
1498+ ofono_devinfo_create(modem, ril->vendor, RILMODEM, ril->modem);
1499
1500 sim_data.gril = ril->modem;
1501 sim_data.modem = modem;
1502 sim_data.ril_state_watch = NULL;
1503
1504- ril->sim = ofono_sim_create(modem, 0, RILMODEM, &sim_data);
1505+ ril->sim = ofono_sim_create(modem, ril->vendor, RILMODEM, &sim_data);
1506 g_assert(ril->sim != NULL);
1507 }
1508
1509-static void ril_post_sim(struct ofono_modem *modem)
1510+void ril_post_sim(struct ofono_modem *modem)
1511 {
1512 struct ril_data *ril = ofono_modem_get_data(modem);
1513 struct ofono_gprs *gprs;
1514@@ -273,10 +280,11 @@
1515 * - stk ( SIM toolkit )
1516 * - radio_settings
1517 */
1518- ofono_sms_create(modem, 0, RILMODEM, ril->modem);
1519+ ofono_sms_create(modem, ril->vendor, RILMODEM, ril->modem);
1520
1521- gprs = ofono_gprs_create(modem, 0, RILMODEM, ril->modem);
1522- gc = ofono_gprs_context_create(modem, 0, RILMODEM, ril->modem);
1523+ gprs = ofono_gprs_create(modem, ril->vendor, RILMODEM, ril->modem);
1524+ gc = ofono_gprs_context_create(modem, ril->vendor,
1525+ RILMODEM, ril->modem);
1526
1527 if (gc) {
1528 ofono_gprs_context_set_type(gc,
1529@@ -284,7 +292,8 @@
1530 ofono_gprs_add_context(gprs, gc);
1531 }
1532
1533- gc = ofono_gprs_context_create(modem, 0, RILMODEM, ril->modem);
1534+ gc = ofono_gprs_context_create(modem, ril->vendor,
1535+ RILMODEM, ril->modem);
1536
1537 if (gc) {
1538 ofono_gprs_context_set_type(gc,
1539@@ -296,19 +305,19 @@
1540 if (mw)
1541 ofono_message_waiting_register(mw);
1542
1543- ofono_call_forwarding_create(modem, 0, RILMODEM, ril->modem);
1544+ ofono_call_forwarding_create(modem, ril->vendor, RILMODEM, ril->modem);
1545 }
1546
1547-static void ril_post_online(struct ofono_modem *modem)
1548+void ril_post_online(struct ofono_modem *modem)
1549 {
1550 struct ril_data *ril = ofono_modem_get_data(modem);
1551
1552- ofono_call_volume_create(modem, 0, RILMODEM, ril->modem);
1553- ofono_netreg_create(modem, 0, RILMODEM, ril->modem);
1554- ofono_ussd_create(modem, 0, RILMODEM, ril->modem);
1555- ofono_call_settings_create(modem, 0, RILMODEM, ril->modem);
1556- ofono_radio_settings_create(modem, 0, RILMODEM, ril->modem);
1557- ofono_call_barring_create(modem, 0, RILMODEM, ril->modem);
1558+ ofono_call_volume_create(modem, ril->vendor, RILMODEM, ril->modem);
1559+ ofono_netreg_create(modem, ril->vendor, RILMODEM, ril->modem);
1560+ ofono_ussd_create(modem, ril->vendor, RILMODEM, ril->modem);
1561+ ofono_call_settings_create(modem, ril->vendor, RILMODEM, ril->modem);
1562+ ofono_radio_settings_create(modem, ril->vendor, RILMODEM, ril->modem);
1563+ ofono_call_barring_create(modem, ril->vendor, RILMODEM, ril->modem);
1564 }
1565
1566 static void ril_set_online_cb(struct ril_msg *message, gpointer user_data)
1567@@ -354,8 +363,8 @@
1568 }
1569 }
1570
1571-static void ril_set_online(struct ofono_modem *modem, ofono_bool_t online,
1572- ofono_modem_online_cb_t callback, void *data)
1573+void ril_set_online(struct ofono_modem *modem, ofono_bool_t online,
1574+ ofono_modem_online_cb_t callback, void *data)
1575 {
1576 struct ril_data *ril = ofono_modem_get_data(modem);
1577 struct cb_data *cbd = cb_data_new(callback, data, ril);
1578@@ -417,7 +426,7 @@
1579 return 0;
1580 }
1581
1582-static int ril_enable(struct ofono_modem *modem)
1583+int ril_enable(struct ofono_modem *modem)
1584 {
1585 int ret;
1586
1587@@ -430,7 +439,7 @@
1588 return -EINPROGRESS;
1589 }
1590
1591-static int ril_disable(struct ofono_modem *modem)
1592+int ril_disable(struct ofono_modem *modem)
1593 {
1594 struct ril_data *ril = ofono_modem_get_data(modem);
1595
1596
1597=== added file 'plugins/ril.h'
1598--- plugins/ril.h 1970-01-01 00:00:00 +0000
1599+++ plugins/ril.h 2014-07-21 18:55:43 +0000
1600@@ -0,0 +1,30 @@
1601+/*
1602+ *
1603+ * oFono - Open Source Telephony - RIL-based devices
1604+ *
1605+ * Copyright (C) 2014 Canonical Ltd.
1606+ *
1607+ * This program is free software; you can redistribute it and/or modify
1608+ * it under the terms of the GNU General Public License version 2 as
1609+ * published by the Free Software Foundation.
1610+ *
1611+ * This program is distributed in the hope that it will be useful,
1612+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1613+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1614+ * GNU General Public License for more details.
1615+ *
1616+ * You should have received a copy of the GNU General Public License
1617+ * along with this program; if not, write to the Free Software
1618+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1619+ *
1620+ */
1621+
1622+int ril_create(struct ofono_modem *modem, enum ofono_ril_vendor vendor);
1623+void ril_remove(struct ofono_modem *modem);
1624+int ril_enable(struct ofono_modem *modem);
1625+int ril_disable(struct ofono_modem *modem);
1626+void ril_pre_sim(struct ofono_modem *modem);
1627+void ril_post_sim(struct ofono_modem *modem);
1628+void ril_post_online(struct ofono_modem *modem);
1629+void ril_set_online(struct ofono_modem *modem, ofono_bool_t online,
1630+ ofono_modem_online_cb_t callback, void *data);
1631
1632=== added file 'plugins/ubuntu-apndb.c'
1633--- plugins/ubuntu-apndb.c 1970-01-01 00:00:00 +0000
1634+++ plugins/ubuntu-apndb.c 2014-07-21 18:55:43 +0000
1635@@ -0,0 +1,596 @@
1636+/*
1637+ *
1638+ * oFono - Open Source Telephony
1639+ *
1640+ * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
1641+ * 2013 Simon Busch <morphis@gravedo.de>
1642+ * Copyright (C) 2014 Canonical Ltd.
1643+ *
1644+ * This program is free software; you can redistribute it and/or modify
1645+ * it under the terms of the GNU General Public License version 2 as
1646+ * published by the Free Software Foundation.
1647+ *
1648+ * This program is distributed in the hope that it will be useful,
1649+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1650+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1651+ * GNU General Public License for more details.
1652+ *
1653+ * You should have received a copy of the GNU General Public License
1654+ * along with this program; if not, write to the Free Software
1655+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1656+ *
1657+ */
1658+
1659+#ifdef HAVE_CONFIG_H
1660+#include <config.h>
1661+#endif
1662+
1663+#include <string.h>
1664+#include <fcntl.h>
1665+#include <sys/mman.h>
1666+#include <sys/stat.h>
1667+#include <sys/types.h>
1668+#include <errno.h>
1669+#include <stdlib.h>
1670+#include <unistd.h>
1671+
1672+#include <glib.h>
1673+
1674+#define OFONO_API_SUBJECT_TO_CHANGE
1675+#include <ofono/modem.h>
1676+#include <ofono/gprs-provision.h>
1677+#include <ofono/log.h>
1678+
1679+#include "ubuntu-apndb.h"
1680+
1681+#ifndef SYSTEM_APNDB_PATH
1682+#define SYSTEM_APNDB_PATH "/system/etc/apns-conf.xml"
1683+#define CUSTOM_APNDB_PATH "/custom/etc/apns-conf.xml"
1684+#endif
1685+
1686+struct apndb_data {
1687+ const char *match_mcc;
1688+ const char *match_mnc;
1689+ const char *match_imsi;
1690+ const char *match_spn;
1691+ const char *match_gid1;
1692+ GSList *apns;
1693+ gboolean allow_duplicates;
1694+ gboolean mvno_found;
1695+};
1696+
1697+void ubuntu_apndb_ap_free(gpointer data)
1698+{
1699+ struct apndb_provision_data *ap = data;
1700+
1701+ g_free(ap->gprs_data.name);
1702+ g_free(ap->gprs_data.apn);
1703+ g_free(ap->gprs_data.username);
1704+ g_free(ap->gprs_data.password);
1705+ g_free(ap->gprs_data.message_proxy);
1706+ g_free(ap->gprs_data.message_center);
1707+
1708+ g_free(ap);
1709+}
1710+
1711+static gboolean imsi_match(const char *imsi, const char *match)
1712+{
1713+ gboolean result = FALSE;
1714+ size_t imsi_len = strlen(imsi);
1715+ size_t match_len = strlen(match);
1716+ unsigned int i;
1717+
1718+ DBG("imsi %s match %s", imsi, match);
1719+
1720+ if (imsi_len != match_len)
1721+ goto done;
1722+
1723+ for (i = 0; i < imsi_len; i++) {
1724+ if (*(imsi + i) == *(match + i))
1725+ continue;
1726+ else if (*(match + i) == 'x')
1727+ continue;
1728+ else
1729+ goto done;
1730+ }
1731+
1732+ result = TRUE;
1733+
1734+done:
1735+ return result;
1736+}
1737+
1738+static void strip_non_mvno_apns(GSList **apns)
1739+{
1740+ GSList *l = NULL;
1741+ unsigned int ap_count = g_slist_length(*apns);
1742+ struct apndb_provision_data *ap;
1743+
1744+ DBG("");
1745+
1746+ for (l = *apns; l;) {
1747+ ap = l->data;
1748+ l = l->next;
1749+
1750+ if (ap->mvno == FALSE) {
1751+ DBG("Removing: %s", ap->gprs_data.apn);
1752+ *apns = g_slist_remove(*apns,
1753+ (gconstpointer) ap);
1754+ ubuntu_apndb_ap_free(ap);
1755+ ap_count--;
1756+ }
1757+ }
1758+}
1759+
1760+static GSList *merge_apn_lists(GSList *custom_apns, GSList *base_apns)
1761+{
1762+ GSList *l = NULL;
1763+ GSList *l2 = NULL;
1764+ gboolean found = FALSE;
1765+ struct apndb_provision_data *ap;
1766+
1767+ DBG("");
1768+
1769+ if (custom_apns == NULL)
1770+ return base_apns;
1771+
1772+ for (l = custom_apns; l; l = l->next, found = FALSE) {
1773+ struct apndb_provision_data *ap2 = l->data;
1774+
1775+ if (ap2->gprs_data.apn == NULL) {
1776+ ofono_error("%s: invalid custom apn entry - %s found",
1777+ __func__, ap2->gprs_data.name);
1778+ continue;
1779+ }
1780+
1781+ for (l2 = base_apns; l2; l2 = l2->next) {
1782+ ap = l2->data;
1783+
1784+ if (ap->gprs_data.apn != NULL &&
1785+ ap->gprs_data.type == ap2->gprs_data.type &&
1786+ g_strcmp0(ap2->gprs_data.apn,
1787+ ap->gprs_data.apn) == 0) {
1788+
1789+ found = TRUE;
1790+ break;
1791+ }
1792+ }
1793+
1794+ if (found == TRUE) {
1795+ DBG("found=TRUE; removing '%s'", ap->gprs_data.apn);
1796+
1797+ base_apns = g_slist_remove(base_apns, ap);
1798+ ubuntu_apndb_ap_free(ap);
1799+ }
1800+ }
1801+
1802+ custom_apns = g_slist_reverse(custom_apns);
1803+
1804+ for (l = custom_apns; l; l = l->next) {
1805+ struct ap2 *ap2 = l->data;
1806+
1807+ base_apns = g_slist_prepend(base_apns, ap2);
1808+ }
1809+
1810+ g_slist_free(custom_apns);
1811+
1812+ return base_apns;
1813+}
1814+
1815+static enum ofono_gprs_context_type determine_apn_type(const char *types)
1816+{
1817+ /*
1818+ * The database contains entries with the following type field contents:
1819+ * - default
1820+ * - default,mms
1821+ * - default,supl
1822+ * - defualt,supl,dun
1823+ * - default,supl,mms
1824+ * - mms
1825+ */
1826+
1827+ if (g_strcmp0(types, "mms") == 0)
1828+ return OFONO_GPRS_CONTEXT_TYPE_MMS;
1829+ else if (g_str_has_prefix(types, "default"))
1830+ return OFONO_GPRS_CONTEXT_TYPE_INTERNET;
1831+ else
1832+ return OFONO_GPRS_CONTEXT_TYPE_ANY;
1833+}
1834+
1835+static char *ubuntu_apndb_sanitize_ipv4_address(const char *address)
1836+{
1837+ char **numbers = NULL;
1838+ char *sanitized_numbers[4];
1839+ unsigned int count = 0;
1840+ char *result = NULL;
1841+ char *numeral;
1842+
1843+ /*
1844+ * As src/gprs.c expects MMS proxies to always be
1845+ * specified using IPV4 numbers-and-dot notation,
1846+ * we need to strip any leading "0"s from the
1847+ * individual numeric components, otherwise they
1848+ * will be treated as octal numbers
1849+ * ( see 'man inet_aton' for details ).
1850+ */
1851+
1852+ if (g_ascii_isdigit(*address) == FALSE)
1853+ goto done;
1854+
1855+ numbers = g_strsplit(address, ".", 4);
1856+
1857+ for (; (numeral = *(numbers+count)); count++) {
1858+ if (count > 3)
1859+ goto done;
1860+
1861+ for (; *numeral; numeral++) {
1862+ if (g_ascii_isdigit(*numeral) == FALSE)
1863+ goto done;
1864+ else if (*numeral == '0')
1865+ continue;
1866+ else
1867+ break;
1868+ }
1869+
1870+ if (*numeral)
1871+ sanitized_numbers[count] = numeral;
1872+ else
1873+ sanitized_numbers[count] = "0";
1874+ }
1875+
1876+ if (count != 4)
1877+ goto done;
1878+
1879+ result = g_strdup_printf("%s.%s.%s.%s",
1880+ sanitized_numbers[0],
1881+ sanitized_numbers[1],
1882+ sanitized_numbers[2],
1883+ sanitized_numbers[3]);
1884+
1885+done:
1886+ if (numbers != NULL)
1887+ g_strfreev(numbers);
1888+
1889+ return result;
1890+}
1891+
1892+static void toplevel_apndb_start(GMarkupParseContext *context,
1893+ const gchar *element_name,
1894+ const gchar **attribute_names,
1895+ const gchar **attribute_values,
1896+ gpointer userdata, GError **error)
1897+{
1898+ struct apndb_data *apndb = userdata;
1899+ struct apndb_provision_data *ap = NULL;
1900+ int i;
1901+ const gchar *carrier = NULL;
1902+ const gchar *mcc = NULL;
1903+ const gchar *mnc = NULL;
1904+ const gchar *apn = NULL;
1905+ const gchar *username = NULL;
1906+ const gchar *password = NULL;
1907+ const gchar *types = NULL;
1908+ const gchar *protocol = NULL;
1909+ const gchar *mmsproxy = NULL;
1910+ const gchar *mmsport = NULL;
1911+ const gchar *mmscenter = NULL;
1912+ const gchar *mvnomatch = NULL;
1913+ const gchar *mvnotype = NULL;
1914+ enum ofono_gprs_proto proto = OFONO_GPRS_PROTO_IP;
1915+ enum ofono_gprs_context_type type;
1916+
1917+ if (g_strcmp0(element_name, "apn") != 0)
1918+ return;
1919+
1920+ for (i = 0; attribute_names[i]; i++) {
1921+ if (g_strcmp0(attribute_names[i], "carrier") == 0)
1922+ carrier = attribute_values[i];
1923+ else if (g_strcmp0(attribute_names[i], "mcc") == 0)
1924+ mcc = attribute_values[i];
1925+ else if (g_strcmp0(attribute_names[i], "mnc") == 0)
1926+ mnc = attribute_values[i];
1927+ }
1928+
1929+ if (mcc == NULL) {
1930+ ofono_error("%s: apn for %s missing 'mcc' attribute", __func__,
1931+ carrier);
1932+ return;
1933+ }
1934+
1935+ if (mnc == NULL) {
1936+ ofono_error("%s: apn for %s missing 'mnc' attribute", __func__,
1937+ carrier);
1938+ return;
1939+ }
1940+
1941+ if (g_strcmp0(mcc, apndb->match_mcc) != 0 ||
1942+ g_strcmp0(mnc, apndb->match_mnc) != 0)
1943+ return;
1944+
1945+ for (i = 0; attribute_names[i]; i++) {
1946+ if (g_strcmp0(attribute_names[i], "apn") == 0)
1947+ apn = attribute_values[i];
1948+ else if (g_strcmp0(attribute_names[i], "user") == 0)
1949+ username = attribute_values[i];
1950+ else if (g_strcmp0(attribute_names[i], "password") == 0)
1951+ password = attribute_values[i];
1952+ else if (g_strcmp0(attribute_names[i], "type") == 0)
1953+ types = attribute_values[i];
1954+ else if (g_strcmp0(attribute_names[i], "protocol") == 0)
1955+ protocol = attribute_values[i];
1956+ else if (g_strcmp0(attribute_names[i], "mmsc") == 0)
1957+ mmscenter = attribute_values[i];
1958+ else if (g_strcmp0(attribute_names[i], "mmsproxy") == 0)
1959+ mmsproxy = attribute_values[i];
1960+ else if (g_strcmp0(attribute_names[i], "mmsport") == 0)
1961+ mmsport = attribute_values[i];
1962+ else if (g_strcmp0(attribute_names[i], "mvno_match_data") == 0)
1963+ mvnomatch = attribute_values[i];
1964+ else if (g_strcmp0(attribute_names[i], "mvno_type") == 0)
1965+ mvnotype = attribute_values[i];
1966+ }
1967+
1968+ if (apn == NULL) {
1969+ ofono_error("%s: apn for %s missing 'apn' attribute", __func__,
1970+ carrier);
1971+ return;
1972+ }
1973+
1974+ if (types == NULL) {
1975+ ofono_error("%s: apn for %s missing type attribute", __func__,
1976+ carrier);
1977+ return;
1978+ }
1979+
1980+ if (protocol != NULL) {
1981+ if (g_strcmp0(protocol, "IP") == 0) {
1982+ proto = OFONO_GPRS_PROTO_IP;
1983+ } else if (g_strcmp0(protocol, "IPV6") == 0) {
1984+ proto = OFONO_GPRS_PROTO_IPV6;
1985+ } else if (g_strcmp0(protocol, "IPV4V6") == 0) {
1986+ proto = OFONO_GPRS_PROTO_IPV4V6;
1987+ } else {
1988+ ofono_error("%s: APN %s has invalid protocol=%s"
1989+ "attribute", __func__, carrier,
1990+ protocol);
1991+ return;
1992+ }
1993+ }
1994+
1995+ if (mvnotype != NULL && mvnomatch != NULL) {
1996+
1997+ if (g_strcmp0(mvnotype, "imsi") == 0) {
1998+ DBG("APN %s is mvno_type 'imsi'", carrier);
1999+
2000+ if (apndb->match_imsi == NULL ||
2001+ imsi_match(apndb->match_imsi,
2002+ mvnomatch) == FALSE) {
2003+ DBG("Skipping MVNO 'imsi' APN %s with"
2004+ " match_data: %s", carrier, mvnomatch);
2005+ return;
2006+ }
2007+ } else if (g_strcmp0(mvnotype, "spn") == 0) {
2008+ DBG("APN %s is mvno_type 'spn'", carrier);
2009+
2010+ if (g_strcmp0(mvnomatch, apndb->match_spn) != 0) {
2011+ DBG("Skipping mvno 'spn' APN %s with"
2012+ " match_data: %s", carrier, mvnomatch);
2013+ return;
2014+ }
2015+
2016+ } else if (g_strcmp0(mvnotype, "gid") == 0) {
2017+ int match_len = strlen(mvnomatch);
2018+
2019+ DBG("APN %s is mvno_type 'gid'", carrier);
2020+
2021+ /* Check initial part of GID1 against match data */
2022+ if (apndb->match_gid1 == NULL ||
2023+ g_ascii_strncasecmp(mvnomatch,
2024+ apndb->match_gid1,
2025+ match_len) != 0) {
2026+ DBG("Skipping mvno 'gid' APN %s with"
2027+ " match_data: %s", carrier, mvnomatch);
2028+ return;
2029+ }
2030+ }
2031+ }
2032+
2033+ type = determine_apn_type(types);
2034+
2035+ if (type == OFONO_GPRS_CONTEXT_TYPE_ANY ||
2036+ (type == OFONO_GPRS_CONTEXT_TYPE_MMS && mmsproxy == NULL)) {
2037+ DBG("Skipping %s context; types: %s", apn, types);
2038+ return;
2039+ }
2040+
2041+ ap = g_try_new0(struct apndb_provision_data, 1);
2042+ if (ap == NULL) {
2043+ ofono_error("%s: out-of-memory trying to provision APN - %s",
2044+ __func__, carrier);
2045+ return;
2046+ }
2047+
2048+ ap->gprs_data.type = type;
2049+
2050+ if (carrier != NULL)
2051+ ap->gprs_data.name = g_strdup(carrier);
2052+
2053+ if (apn != NULL)
2054+ ap->gprs_data.apn = g_strdup(apn);
2055+
2056+ if (username != NULL)
2057+ ap->gprs_data.username = g_strdup(username);
2058+
2059+ if (password != NULL)
2060+ ap->gprs_data.password = g_strdup(password);
2061+
2062+ if (mmscenter != NULL && strlen(mmscenter) > 0)
2063+ ap->gprs_data.message_center = g_strdup(mmscenter);
2064+
2065+ if (mmsproxy != NULL && strlen(mmsproxy) > 0) {
2066+ char *tmp = ubuntu_apndb_sanitize_ipv4_address(mmsproxy);
2067+ if (tmp != NULL)
2068+ mmsproxy = tmp;
2069+
2070+ if (mmsport != NULL)
2071+ ap->gprs_data.message_proxy =
2072+ g_strdup_printf("%s:%s", mmsproxy, mmsport);
2073+ else
2074+ ap->gprs_data.message_proxy = g_strdup(mmsproxy);
2075+
2076+ g_free(tmp);
2077+ }
2078+
2079+ ap->gprs_data.proto = proto;
2080+
2081+ if (mvnotype != NULL) {
2082+ ap->mvno = TRUE;
2083+ apndb->mvno_found = TRUE;
2084+ }
2085+
2086+ apndb->apns = g_slist_append(apndb->apns, ap);
2087+}
2088+
2089+static void toplevel_apndb_end(GMarkupParseContext *context,
2090+ const gchar *element_name,
2091+ gpointer userdata, GError **error)
2092+{
2093+}
2094+
2095+static const GMarkupParser toplevel_apndb_parser = {
2096+ toplevel_apndb_start,
2097+ toplevel_apndb_end,
2098+ NULL,
2099+ NULL,
2100+ NULL,
2101+};
2102+
2103+static gboolean ubuntu_apndb_parse(const GMarkupParser *parser,
2104+ gpointer userdata,
2105+ const char *apndb_path,
2106+ GError **error)
2107+{
2108+ struct stat st;
2109+ char *db;
2110+ int fd;
2111+ GMarkupParseContext *context;
2112+ gboolean ret;
2113+
2114+ fd = open(apndb_path, O_RDONLY);
2115+ if (fd < 0) {
2116+ g_set_error(error, G_FILE_ERROR,
2117+ g_file_error_from_errno(errno),
2118+ "open(%s) failed: %s", apndb_path,
2119+ g_strerror(errno));
2120+ return FALSE;
2121+ }
2122+
2123+ if (fstat(fd, &st) < 0) {
2124+ close(fd);
2125+ g_set_error(error, G_FILE_ERROR,
2126+ g_file_error_from_errno(errno),
2127+ "fstat(%s) failed: %s", apndb_path,
2128+ g_strerror(errno));
2129+ return FALSE;
2130+ }
2131+
2132+ db = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
2133+ if (db == MAP_FAILED) {
2134+ close(fd);
2135+ g_set_error(error, G_FILE_ERROR,
2136+ g_file_error_from_errno(errno),
2137+ "mmap(%s) failed: %s", apndb_path,
2138+ g_strerror(errno));
2139+ return FALSE;
2140+ }
2141+
2142+ context = g_markup_parse_context_new(parser,
2143+ G_MARKUP_TREAT_CDATA_AS_TEXT,
2144+ userdata, NULL);
2145+
2146+ ret = g_markup_parse_context_parse(context, db, st.st_size, error);
2147+
2148+ if (ret == TRUE)
2149+ g_markup_parse_context_end_parse(context, error);
2150+
2151+ munmap(db, st.st_size);
2152+ close(fd);
2153+ g_markup_parse_context_free(context);
2154+
2155+ return ret;
2156+}
2157+
2158+GSList *ubuntu_apndb_lookup_apn(const char *mcc, const char *mnc,
2159+ const char *spn, const char *imsi, const char *gid1,
2160+ GError **error)
2161+{
2162+ struct apndb_data apndb = { NULL };
2163+ struct apndb_data custom_apndb = { NULL };
2164+ const char *apndb_path;
2165+ GSList *merged_apns;
2166+
2167+ /*
2168+ * Lookup /custom apns first, if mvno apns found,
2169+ * strip non-mvno apns from list
2170+ *
2171+ * Lookup /system next, apply same mvno logic...
2172+ *
2173+ * Merge both lists, any custom apns that match the type
2174+ * and apn fields of a /system apn replace it.
2175+ */
2176+
2177+ custom_apndb.match_mcc = mcc;
2178+ custom_apndb.match_mnc = mnc;
2179+ custom_apndb.match_spn = spn;
2180+ custom_apndb.match_imsi = imsi;
2181+ custom_apndb.match_gid1 = gid1;
2182+
2183+ if ((apndb_path = getenv("OFONO_CUSTOM_APNDB_PATH")) == NULL)
2184+ apndb_path = CUSTOM_APNDB_PATH;
2185+
2186+ if (ubuntu_apndb_parse(&toplevel_apndb_parser, &custom_apndb,
2187+ apndb_path,
2188+ error) == FALSE) {
2189+ g_slist_free_full(custom_apndb.apns, ubuntu_apndb_ap_free);
2190+ custom_apndb.apns = NULL;
2191+
2192+ if (*error) {
2193+ if ((*error)->domain != G_FILE_ERROR)
2194+ ofono_error("%s: custom apn_lookup error -%s",
2195+ __func__, (*error)->message);
2196+
2197+ g_error_free(*error);
2198+ *error = NULL;
2199+ }
2200+ }
2201+
2202+ if (custom_apndb.apns && custom_apndb.mvno_found)
2203+ strip_non_mvno_apns(&custom_apndb.apns);
2204+
2205+ DBG("custom_apndb: found '%d' APNs", g_slist_length(custom_apndb.apns));
2206+
2207+ apndb.match_mcc = mcc;
2208+ apndb.match_mnc = mnc;
2209+ apndb.match_spn = spn;
2210+ apndb.match_imsi = imsi;
2211+ apndb.match_gid1 = gid1;
2212+
2213+ if ((apndb_path = getenv("OFONO_SYSTEM_APNDB_PATH")) == NULL)
2214+ apndb_path = SYSTEM_APNDB_PATH;
2215+
2216+ if (ubuntu_apndb_parse(&toplevel_apndb_parser, &apndb,
2217+ apndb_path,
2218+ error) == FALSE) {
2219+ g_slist_free_full(apndb.apns, ubuntu_apndb_ap_free);
2220+ apndb.apns = NULL;
2221+ }
2222+
2223+ DBG("apndb: found '%d' APNs", g_slist_length(apndb.apns));
2224+
2225+ if (apndb.apns && apndb.mvno_found)
2226+ strip_non_mvno_apns(&apndb.apns);
2227+
2228+ merged_apns = merge_apn_lists(custom_apndb.apns, apndb.apns);
2229+
2230+ return merged_apns;
2231+}
2232
2233=== added file 'plugins/ubuntu-apndb.h'
2234--- plugins/ubuntu-apndb.h 1970-01-01 00:00:00 +0000
2235+++ plugins/ubuntu-apndb.h 2014-07-21 18:55:43 +0000
2236@@ -0,0 +1,33 @@
2237+/*
2238+ *
2239+ * ofono - Open Source Telephony
2240+ *
2241+ * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
2242+ * 2013 Simon Busch <morphis@gravedo.de>
2243+ * Copyright (C) 2014 Canonical Ltd.
2244+ *
2245+ * This program is free software; you can redistribute it and/or modify
2246+ * it under the terms of the GNU General Public License version 2 as
2247+ * published by the Free Software Foundation.
2248+ *
2249+ * This program is distributed in the hope that it will be useful,
2250+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2251+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2252+ * GNU General Public License for more details.
2253+ *
2254+ * You should have received a copy of the GNU General Public License
2255+ * along with this program; if not, write to the Free Software
2256+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2257+ *
2258+ */
2259+
2260+struct apndb_provision_data {
2261+ struct ofono_gprs_provision_data gprs_data;
2262+ gboolean mvno;
2263+};
2264+
2265+void ubuntu_apndb_ap_free(gpointer data);
2266+
2267+GSList *ubuntu_apndb_lookup_apn(const char *mcc, const char *mnc,
2268+ const char *spn, const char *imsi, const char *gid1,
2269+ GError **error);
2270
2271=== added file 'plugins/ubuntu-provision.c'
2272--- plugins/ubuntu-provision.c 1970-01-01 00:00:00 +0000
2273+++ plugins/ubuntu-provision.c 2014-07-21 18:55:43 +0000
2274@@ -0,0 +1,150 @@
2275+/*
2276+ *
2277+ * oFono - Open Source Telephony
2278+ *
2279+ * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
2280+ * 2013 Simon Busch <morphis@gravedo.de>
2281+ * Copyright (C) 2014 Canonical Ltd.
2282+ *
2283+ * This program is free software; you can redistribute it and/or modify
2284+ * it under the terms of the GNU General Public License version 2 as
2285+ * published by the Free Software Foundation.
2286+ *
2287+ * This program is distributed in the hope that it will be useful,
2288+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2289+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2290+ * GNU General Public License for more details.
2291+ *
2292+ * You should have received a copy of the GNU General Public License
2293+ * along with this program; if not, write to the Free Software
2294+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2295+ *
2296+ */
2297+
2298+#ifdef HAVE_CONFIG_H
2299+#include <config.h>
2300+#endif
2301+
2302+#include <errno.h>
2303+#include <stdlib.h>
2304+#include <string.h>
2305+
2306+#include <glib.h>
2307+
2308+#define OFONO_API_SUBJECT_TO_CHANGE
2309+#include <ofono/types.h>
2310+#include <ofono/log.h>
2311+#include <ofono/plugin.h>
2312+#include <ofono/modem.h>
2313+#include <ofono/gprs-provision.h>
2314+
2315+#include "ubuntu-apndb.h"
2316+#include "mbpi.h"
2317+
2318+static int provision_get_settings(const char *mcc, const char *mnc,
2319+ const char *spn,
2320+ const char *imsi, const char *gid1,
2321+ struct ofono_gprs_provision_data **settings,
2322+ int *count)
2323+{
2324+ GSList *apns = NULL;
2325+ GSList *l = NULL;
2326+ GError *error = NULL;
2327+ unsigned int i;
2328+ char *tmp;
2329+ int retval = 0;
2330+
2331+ if ((tmp = getenv("OFONO_CUSTOM_MCC")) != NULL)
2332+ mcc = tmp;
2333+
2334+ if ((tmp = getenv("OFONO_CUSTOM_MNC")) != NULL)
2335+ mnc = tmp;
2336+
2337+ if ((tmp = getenv("OFONO_CUSTOM_SPN")) != NULL)
2338+ spn = tmp;
2339+
2340+ if ((tmp = getenv("OFONO_CUSTOM_IMSI")) != NULL)
2341+ imsi = tmp;
2342+
2343+ if ((tmp = getenv("OFONO_CUSTOM_GID1")) != NULL)
2344+ gid1 = tmp;
2345+
2346+ ofono_info("Provisioning for MCC %s, MNC %s, SPN '%s', IMSI '%s', "
2347+ "GID1 '%s'", mcc, mnc, spn, imsi, gid1);
2348+
2349+ apns = ubuntu_apndb_lookup_apn(mcc, mnc, spn, imsi, gid1, &error);
2350+ if (apns == NULL) {
2351+ if (error != NULL) {
2352+ ofono_error("%s: apndb_lookup error -%s for mcc %s"
2353+ " mnc %s spn %s imsi %s", __func__,
2354+ error->message, mcc, mnc, spn, imsi);
2355+ g_error_free(error);
2356+ error = NULL;
2357+ }
2358+ }
2359+
2360+ *count = g_slist_length(apns);
2361+
2362+ DBG("ap_count: '%d'", *count);
2363+
2364+ if (*count == 0) {
2365+ ofono_error("%s: provisioning failed - no APNs found.",
2366+ __func__);
2367+
2368+ retval = -1;
2369+ goto done;
2370+ }
2371+
2372+ *settings = g_try_new0(struct ofono_gprs_provision_data, *count);
2373+ if (*settings == NULL) {
2374+ ofono_error("%s: provisioning failed: out-of-memory", __func__);
2375+
2376+ g_slist_free_full(apns, ubuntu_apndb_ap_free);
2377+
2378+ *count = 0;
2379+ return -ENOMEM;
2380+ }
2381+
2382+ for (l = apns, i = 0; l; l = l->next, i++) {
2383+ struct apndb_provision_data *ap = l->data;
2384+
2385+ DBG("Name: '%s'", ap->gprs_data.name);
2386+ DBG("APN: '%s'", ap->gprs_data.apn);
2387+ DBG("Type: %s", mbpi_ap_type(ap->gprs_data.type));
2388+ DBG("Username: '%s'", ap->gprs_data.username);
2389+ DBG("Password: '%s'", ap->gprs_data.password);
2390+ DBG("Message Proxy: '%s'", ap->gprs_data.message_proxy);
2391+ DBG("Message Center: '%s'", ap->gprs_data.message_center);
2392+ DBG("MVNO: %u", ap->mvno);
2393+
2394+ memcpy(*settings + i, &ap->gprs_data, sizeof(ap->gprs_data));
2395+
2396+ g_free(ap);
2397+ }
2398+
2399+done:
2400+ if (apns != NULL)
2401+ g_slist_free(apns);
2402+
2403+ return retval;
2404+}
2405+
2406+static struct ofono_gprs_provision_driver ubuntu_provision_driver = {
2407+ .name = "Ubuntu APN database Provisioning",
2408+ .get_settings = provision_get_settings
2409+};
2410+
2411+static int ubuntu_provision_init(void)
2412+{
2413+ return ofono_gprs_provision_driver_register(&ubuntu_provision_driver);
2414+}
2415+
2416+static void ubuntu_provision_exit(void)
2417+{
2418+ ofono_gprs_provision_driver_unregister(&ubuntu_provision_driver);
2419+}
2420+
2421+OFONO_PLUGIN_DEFINE(ubuntu_provision,
2422+ "Ubuntu APN database Provisioning Plugin", VERSION,
2423+ OFONO_PLUGIN_PRIORITY_DEFAULT,
2424+ ubuntu_provision_init, ubuntu_provision_exit)
2425
2426=== modified file 'test/rilmodem/test-sim-online'
2427--- test/rilmodem/test-sim-online 2014-06-24 18:59:26 +0000
2428+++ test/rilmodem/test-sim-online 2014-07-21 18:55:43 +0000
2429@@ -193,7 +193,8 @@
2430 assert properties["Model"] == "Fake Modem Model"
2431 assert properties["Type"] == "hardware"
2432
2433- assert properties["Serial"] == "000000000000000"
2434+ if args.emulator:
2435+ assert properties["Serial"] == "000000000000000"
2436
2437 assert properties["Manufacturer"] == "Fake Manufacturer"
2438
2439
2440=== modified file 'unit/test-grilreply.c'
2441--- unit/test-grilreply.c 2014-05-13 01:21:09 +0000
2442+++ unit/test-grilreply.c 2014-07-21 18:55:43 +0000
2443@@ -79,6 +79,12 @@
2444 const struct ril_msg msg;
2445 };
2446
2447+struct oem_hook_raw_test {
2448+ const unsigned char *data;
2449+ int size;
2450+ const struct ril_msg msg;
2451+};
2452+
2453 /* Invalid RIL_REQUEST_DATA_REGISTRATION_STATE: buffer too small */
2454 static const struct ril_msg reply_data_reg_state_invalid_1 = {
2455 .buf = "XYZ",
2456@@ -1451,6 +1457,49 @@
2457 }
2458 };
2459
2460+/*
2461+ * The following structure contains test data for a valid
2462+ * RIL_REQUEST_OEM_HOOK_RAW reply with parameter {4,0x11111111}
2463+ */
2464+static const guchar reply_oem_hook_raw_valid_parcel1[] = {
2465+ 0x04, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11
2466+};
2467+
2468+static const struct oem_hook_raw_test reply_oem_hook_raw_valid_1 = {
2469+ .data = reply_oem_hook_raw_valid_parcel1 + sizeof(int32_t),
2470+ .size = (int) (sizeof(reply_oem_hook_raw_valid_parcel1)
2471+ - sizeof(int32_t)),
2472+ .msg = {
2473+ .buf = (gchar *) reply_oem_hook_raw_valid_parcel1,
2474+ .buf_len = sizeof(reply_oem_hook_raw_valid_parcel1),
2475+ .unsolicited = FALSE,
2476+ .req = RIL_REQUEST_OEM_HOOK_RAW,
2477+ .serial_no = 0,
2478+ .error = RIL_E_SUCCESS,
2479+ }
2480+};
2481+
2482+/*
2483+ * The following structure contains test data for a valid
2484+ * RIL_REQUEST_OEM_HOOK_RAW reply with parameter {-1}
2485+ */
2486+static const guchar reply_oem_hook_raw_valid_parcel2[] = {
2487+ 0xFF, 0xFF, 0xFF, 0xFF
2488+};
2489+
2490+static const struct oem_hook_raw_test reply_oem_hook_raw_valid_2 = {
2491+ .data = NULL,
2492+ .size = -1,
2493+ .msg = {
2494+ .buf = (gchar *) reply_oem_hook_raw_valid_parcel2,
2495+ .buf_len = sizeof(reply_oem_hook_raw_valid_parcel2),
2496+ .unsolicited = FALSE,
2497+ .req = RIL_REQUEST_OEM_HOOK_RAW,
2498+ .serial_no = 0,
2499+ .error = RIL_E_SUCCESS,
2500+ }
2501+};
2502+
2503 static void test_reply_reg_state_invalid(gconstpointer data)
2504 {
2505 struct reply_reg_state *reply = g_ril_reply_parse_reg_state(NULL, data);
2506@@ -1669,6 +1718,19 @@
2507 g_free(retries);
2508 }
2509
2510+static void test_reply_oem_hook_raw_valid(gconstpointer data)
2511+{
2512+ const struct oem_hook_raw_test *test = data;
2513+ struct reply_oem_hook *reply =
2514+ g_ril_reply_oem_hook_raw(NULL, &test->msg);
2515+
2516+ g_assert(reply->length == test->size);
2517+ if (reply->length >= 0)
2518+ g_assert(!memcmp(reply->data, test->data, test->size));
2519+ else
2520+ g_assert(reply->data == NULL);
2521+}
2522+
2523 #endif
2524
2525 int main(int argc, char **argv)
2526@@ -1958,6 +2020,16 @@
2527 &reply_enter_sim_pin_valid_2,
2528 test_reply_enter_sim_pin_valid);
2529
2530+ g_test_add_data_func("/testgrilreply/oem: "
2531+ "valid OEM_HOOK_RAW Test 1",
2532+ &reply_oem_hook_raw_valid_1,
2533+ test_reply_oem_hook_raw_valid);
2534+
2535+ g_test_add_data_func("/testgrilreply/oem: "
2536+ "valid OEM_HOOK_RAW Test 2",
2537+ &reply_oem_hook_raw_valid_2,
2538+ test_reply_oem_hook_raw_valid);
2539+
2540 #endif
2541
2542 return g_test_run();
2543
2544=== modified file 'unit/test-grilrequest.c'
2545--- unit/test-grilrequest.c 2014-06-24 18:59:26 +0000
2546+++ unit/test-grilrequest.c 2014-07-21 18:55:43 +0000
2547@@ -790,6 +790,37 @@
2548 .parcel_size = sizeof(req_change_barring_password_valid_1),
2549 };
2550
2551+/* oem_hook_raw tests */
2552+
2553+struct request_test_oem_hook_raw_data {
2554+ const guchar *data;
2555+ gsize size;
2556+ const guchar *parcel_data;
2557+ gsize parcel_size;
2558+};
2559+
2560+static const guchar req_oem_hook_raw_valid_1[] = {
2561+ 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2562+};
2563+
2564+static const struct request_test_oem_hook_raw_data oem_hook_raw_valid_test_1 = {
2565+ .data = req_oem_hook_raw_valid_1 + sizeof(int32_t),
2566+ .size = sizeof(req_oem_hook_raw_valid_1) - sizeof(int32_t),
2567+ .parcel_data = (guchar *) &req_oem_hook_raw_valid_1,
2568+ .parcel_size = sizeof(req_oem_hook_raw_valid_1),
2569+};
2570+
2571+static const guchar req_oem_hook_raw_valid_2[] = {
2572+ 0xFF, 0xFF, 0xFF, 0xFF
2573+};
2574+
2575+static const struct request_test_oem_hook_raw_data oem_hook_raw_valid_test_2 = {
2576+ .data = NULL,
2577+ .size = 0,
2578+ .parcel_data = (guchar *) &req_oem_hook_raw_valid_2,
2579+ .parcel_size = sizeof(req_oem_hook_raw_valid_2),
2580+};
2581+
2582 /*
2583 * The following hexadecimal data represents a serialized Binder parcel
2584 * instance containing a valid RIL_REQUEST_RADIO_POWER 'OFF' message.
2585@@ -1322,6 +1353,21 @@
2586
2587 parcel_free(&rilp);
2588 }
2589+
2590+static void test_request_oem_hook_raw(gconstpointer data)
2591+{
2592+ const struct request_test_oem_hook_raw_data *test_data = data;
2593+ struct parcel rilp;
2594+
2595+ g_ril_request_oem_hook_raw(NULL, test_data->data,
2596+ test_data->size, &rilp);
2597+
2598+ g_assert(!memcmp(rilp.data, test_data->parcel_data,
2599+ test_data->parcel_size));
2600+
2601+ parcel_free(&rilp);
2602+}
2603+
2604 #endif
2605
2606 int main(int argc, char **argv)
2607@@ -1571,6 +1617,16 @@
2608 &change_barring_password_valid_test_1,
2609 test_request_change_barring_password);
2610
2611+ g_test_add_data_func("/testgrilrequest/oem-hook-raw: "
2612+ "valid OEM_HOOK_RAW Test 1",
2613+ &oem_hook_raw_valid_test_1,
2614+ test_request_oem_hook_raw);
2615+
2616+ g_test_add_data_func("/testgrilrequest/oem-hook-raw: "
2617+ "valid OEM_HOOK_RAW Test 2",
2618+ &oem_hook_raw_valid_test_2,
2619+ test_request_oem_hook_raw);
2620+
2621 #endif
2622 return g_test_run();
2623 }

Subscribers

People subscribed via source and target branches

to all changes: