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
=== modified file 'Makefile.am'
--- Makefile.am 2014-06-24 18:59:26 +0000
+++ Makefile.am 2014-07-21 18:55:43 +0000
@@ -127,6 +127,9 @@
127builtin_modules += mtk127builtin_modules += mtk
128builtin_sources += plugins/mtk.c128builtin_sources += plugins/mtk.c
129129
130builtin_modules += infineon
131builtin_sources += plugins/infineon.c
132
130builtin_modules += androidspntable133builtin_modules += androidspntable
131builtin_sources += plugins/android-spn-table.c134builtin_sources += plugins/android-spn-table.c
132135
@@ -506,13 +509,13 @@
506509
507if PROVISION510if PROVISION
508builtin_sources += plugins/mbpi.h plugins/mbpi.c511builtin_sources += plugins/mbpi.h plugins/mbpi.c
509builtin_sources += plugins/android-apndb.h plugins/android-apndb.c512builtin_sources += plugins/ubuntu-apndb.h plugins/ubuntu-apndb.c
510513
511builtin_modules += provision514builtin_modules += provision
512builtin_sources += plugins/provision.c515builtin_sources += plugins/provision.c
513516
514builtin_modules += android_provision517builtin_modules += ubuntu_provision
515builtin_sources += plugins/android-provision.c518builtin_sources += plugins/ubuntu-provision.c
516519
517builtin_modules += cdma_provision520builtin_modules += cdma_provision
518builtin_sources += plugins/cdma-provision.c521builtin_sources += plugins/cdma-provision.c
519522
=== modified file 'debian/changelog'
--- debian/changelog 2014-06-25 00:58:02 +0000
+++ debian/changelog 2014-07-21 18:55:43 +0000
@@ -1,3 +1,22 @@
1ofono (1.12.bzr6870+14.10.20140625-0ubuntu1) UNRELEASED; urgency=medium
2
3 [ Martti Piirainen ]
4 * drivers/rilmodem/sim.c: notify on SIM removal (LP: #1332306)
5 * unit/rilmodem/test-sim-online: fix serial number check (LP: #1334867)
6
7 [ Alfonso Sanchez-Beato ]
8 * plugins/mtk.c: fix race condition when onlining modem
9 * build, drivers/infeonmodem, drivers/rilmodem, gril,
10 plugins/infeon.c, plugins/ril.*, unit: add Infeon OEM hooks
11
12 [ Tony Espy ]
13 * build, plugins/ubuntu-provision.c, ubuntu-apndb.*: re-named
14 provisioning plugin code from android-* to ubuntu-*. Also removed
15 code that queries mobile-broadband-provider-info's db, and finally
16 implemented a /custom hook for custom apn dbs (LP: #1315509).
17
18 -- Tony Espy <espy@canonical.com> Wed, 16 Jul 2014 15:06:02 -0400
19
1ofono (1.12.bzr6868+14.10.20140625-0ubuntu1) utopic; urgency=medium20ofono (1.12.bzr6868+14.10.20140625-0ubuntu1) utopic; urgency=medium
221
3 [ Alfonso Sanchez-Beato ]22 [ Alfonso Sanchez-Beato ]
423
=== added directory 'drivers/infineonmodem'
=== added file 'drivers/infineonmodem/infineon_constants.h'
--- drivers/infineonmodem/infineon_constants.h 1970-01-01 00:00:00 +0000
+++ drivers/infineonmodem/infineon_constants.h 2014-07-21 18:55:43 +0000
@@ -0,0 +1,77 @@
1/*
2 *
3 * RIL constants for infineon modem
4 *
5 * Copyright (C) 2014 Canonical Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22#ifndef INFINEON_CONSTANTS_H
23#define INFINEON_CONSTANTS_H
24
25/* Messages encapsulated in RIL_REQUEST_OEM_HOOK_RAW requests */
26#define INF_RIL_REQUEST_OEM_QUERY_SELECT_BAND 1
27#define INF_RIL_REQUEST_OEM_SET_SELECT_BAND 2
28#define INF_RIL_REQUEST_OEM_SET_CIRCUIT_SWITCHING_PAGING 3
29#define INF_RIL_REQUEST_OEM_GET_LAST_FAILURE_REPORT_FOR_CS_REGISTRATION 4
30#define INF_RIL_REQUEST_OEM_GET_SELECT_BEARER_SERVICE_TYPE 5
31#define INF_RIL_REQUEST_OEM_GET_XPROGRESS_STATUS 6
32#define INF_RIL_REQUEST_OEM_SET_SS_NOTIFY 7
33#define INF_RIL_REQUEST_OEM_GET_SS_NOTIFY 8
34#define INF_RIL_REQUEST_OEM_SET_AUTHENTICATION_TYPE 9
35#define INF_RIL_REQUEST_OEM_SWITCH_OFF_MS 10
36#define INF_RIL_REQUEST_OEM_SET_AUTO_TIMEZONE_UPDATE 11
37#define INF_RIL_REQUEST_OEM_SET_TIMEZONE_RESPORTING 12
38#define INF_RIL_REQUEST_OEM_SET_DISPLAY_SIM_AND_PB_STATUS 13
39#define INF_RIL_REQUEST_OEM_GET_REMAIN_SIM_PIN_ATTEMPTS 14
40#define INF_RIL_REQUEST_OEM_SET_AUTO_REDIAL 15
41#define INF_RIL_REQUEST_OEM_QUERY_CALL_STATUS_REPORTING 16
42#define INF_RIL_REQUEST_OEM_SET_AUTO_ANSWER 17
43#define INF_RIL_REQUEST_OEM_SET_LINE 18
44#define INF_RIL_REQUEST_OEM_PDP_ACTIVATE_OR_DEACTIVATE 19
45#define INF_RIL_REQUEST_OEM_QUERY_GPRS_MS_CLASS 20
46#define INF_RIL_REQUEST_OEM_SET_TRACE_AND_AT_INTERFACES 21
47#define INF_RIL_REQUEST_OEM_QUERY_TRACE_AND_AT_INTERFACES_CONFIGURE 22
48#define INF_RIL_REQUEST_OEM_SWITCH_TRACE_ON_OR_OFF 23
49#define INF_RIL_REQUEST_OEM_READ_EXCEPTION_LOG 24
50#define INF_RIL_REQUEST_OEM_GET_PHONE_ACTIVITY_STATUS 25
51#define INF_RIL_REQUEST_OEM_INITIATE_RESEND_SMS_IF_GPRS_FAILS 26
52#define INF_RIL_REQUEST_OEM_GET_DEVICE_NUMBER 27
53#define INF_RIL_REQUEST_OEM_ENABLE_STK 28
54#define INF_RIL_REQUEST_OEM_GET_SUBSCRIBER_NUMBER 29
55#define INF_RIL_REQUEST_OEM_SELECT_PHONE_BOOK 30
56#define INF_RIL_REQUEST_OEM_READ_PHONE_BOOK 31
57#define INF_RIL_REQUEST_OEM_INSERT_RECORD_TO_PHONE_BOOK 32
58#define INF_RIL_REQUEST_OEM_DELECT_RECORD_IN_PHONE_BOOK 33
59#define INF_RIL_REQUEST_OEM_GET_RECORD_FIELDS_MAX_LEN 34
60#define INF_RIL_REQUEST_OEM_SET_SERIAL_PORT 35
61#define INF_RIL_REQUEST_OEM_SET_DATA_PREFERED 36
62#define INF_RIL_REQUEST_OEM_SET_MODEM_ROUTING 37
63#define INF_RIL_REQUEST_OEM_CLEAR_MISS_NUMBER 38
64#define INF_RIL_REQUEST_OEM_ATH 39
65#define INF_RIL_REQUEST_OEM_NOSIG_MODE_TEST 40
66#define INF_RIL_REQUEST_OEM_SELECT_3G_BAND 41
67#define INF_RIL_REQUEST_OEM_QUERY_3G_BAND 42
68#define INF_RIL_REQUEST_OEM_HW_RESET_MODEM 43
69#define INF_RIL_REQUEST_OEM_QUERY_DIRECT 44
70#define INF_RIL_REQUEST_OEM_USER_PLMN_QUERY 45
71#define INF_RIL_REQUEST_OEM_USER_PLMN_SET 46
72#define INF_RIL_REQUEST_OEM_USER_PLMN_DELTE 47
73#define INF_RIL_REQUEST_OEM_SET_USB_LOG 48
74#define INF_RIL_REQUEST_OEM_UPDATE_CSQ 49
75#define INF_RIL_REQUEST_OEM_DUMP_CELL_ENV 50
76
77#endif /* INFINEON_CONSTANTS_H */
078
=== modified file 'drivers/rilmodem/sim.c'
--- drivers/rilmodem/sim.c 2014-06-24 18:59:26 +0000
+++ drivers/rilmodem/sim.c 2014-07-21 18:55:43 +0000
@@ -51,6 +51,8 @@
51#include "grilrequest.h"51#include "grilrequest.h"
52#include "grilunsol.h"52#include "grilunsol.h"
5353
54#include "drivers/infineonmodem/infineon_constants.h"
55
54/*56/*
55 * Based on ../drivers/atmodem/sim.c.57 * Based on ../drivers/atmodem/sim.c.
56 *58 *
@@ -72,6 +74,7 @@
72 */74 */
73struct sim_data {75struct sim_data {
74 GRil *ril;76 GRil *ril;
77 enum ofono_ril_vendor vendor;
75 gchar *aid_str;78 gchar *aid_str;
76 guint app_type;79 guint app_type;
77 gchar *app_str;80 gchar *app_str;
@@ -675,6 +678,9 @@
675 */678 */
676 __ofono_sim_recheck_pin(sim);679 __ofono_sim_recheck_pin(sim);
677 }680 }
681 } else if (status && status->card_state == RIL_CARDSTATE_ABSENT) {
682 ofono_info("SIM card absent");
683 ofono_sim_inserted_notify(sim, FALSE);
678 }684 }
679685
680 g_ril_reply_free_sim_status(status);686 g_ril_reply_free_sim_status(status);
@@ -703,12 +709,72 @@
703 send_get_sim_status(sim);709 send_get_sim_status(sim);
704}710}
705711
712static void inf_pin_retries_cb(struct ril_msg *message, gpointer user_data)
713{
714 struct cb_data *cbd = user_data;
715 ofono_sim_pin_retries_cb_t cb = cbd->cb;
716 struct sim_data *sd = cbd->user;
717 struct reply_oem_hook *reply = NULL;
718 int32_t *ret_data;
719
720 if (message->error != RIL_E_SUCCESS) {
721 ofono_error("Reply failure: %s",
722 ril_error_to_string(message->error));
723 goto error;
724 }
725
726 reply = g_ril_reply_oem_hook_raw(sd->ril, message);
727 if (reply == NULL) {
728 ofono_error("%s: parse error", __func__);
729 goto error;
730 }
731
732 if (reply->length < 5 * (int) sizeof(int32_t)) {
733 ofono_error("%s: reply too small", __func__);
734 goto error;
735 }
736
737 /* First integer is INF_RIL_REQUEST_OEM_GET_REMAIN_SIM_PIN_ATTEMPTS */
738 ret_data = reply->data;
739 sd->retries[OFONO_SIM_PASSWORD_SIM_PIN] = *(++ret_data);
740 sd->retries[OFONO_SIM_PASSWORD_SIM_PIN2] = *(++ret_data);
741 sd->retries[OFONO_SIM_PASSWORD_SIM_PUK] = *(++ret_data);
742 sd->retries[OFONO_SIM_PASSWORD_SIM_PUK2] = *(++ret_data);
743
744 g_ril_reply_free_oem_hook(reply);
745 CALLBACK_WITH_SUCCESS(cb, sd->retries, cbd->data);
746
747 return;
748
749error:
750 g_ril_reply_free_oem_hook(reply);
751 CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
752}
753
706static void ril_query_pin_retries(struct ofono_sim *sim,754static void ril_query_pin_retries(struct ofono_sim *sim,
707 ofono_sim_pin_retries_cb_t cb,755 ofono_sim_pin_retries_cb_t cb,
708 void *data)756 void *data)
709{757{
710 struct sim_data *sd = ofono_sim_get_data(sim);758 struct sim_data *sd = ofono_sim_get_data(sim);
711 CALLBACK_WITH_SUCCESS(cb, sd->retries, data);759
760 if (sd->vendor == OFONO_RIL_VENDOR_INFINEON) {
761 struct cb_data *cbd = cb_data_new(cb, data, sd);
762 struct parcel rilp;
763 int32_t oem_req =
764 INF_RIL_REQUEST_OEM_GET_REMAIN_SIM_PIN_ATTEMPTS;
765
766 g_ril_request_oem_hook_raw(sd->ril, &oem_req,
767 sizeof(oem_req), &rilp);
768
769 /* Send request to RIL */
770 if (g_ril_send(sd->ril, RIL_REQUEST_OEM_HOOK_RAW, &rilp,
771 inf_pin_retries_cb, cbd, g_free) == 0) {
772 g_free(cbd);
773 CALLBACK_WITH_FAILURE(cb, NULL, data);
774 }
775 } else {
776 CALLBACK_WITH_SUCCESS(cb, sd->retries, data);
777 }
712}778}
713779
714static void ril_query_passwd_state(struct ofono_sim *sim,780static void ril_query_passwd_state(struct ofono_sim *sim,
@@ -893,6 +959,7 @@
893959
894 sd = g_new0(struct sim_data, 1);960 sd = g_new0(struct sim_data, 1);
895 sd->ril = g_ril_clone(ril);961 sd->ril = g_ril_clone(ril);
962 sd->vendor = vendor;
896 sd->aid_str = NULL;963 sd->aid_str = NULL;
897 sd->app_str = NULL;964 sd->app_str = NULL;
898 sd->app_type = RIL_APPTYPE_UNKNOWN;965 sd->app_type = RIL_APPTYPE_UNKNOWN;
899966
=== modified file 'drivers/rilmodem/vendor.h'
--- drivers/rilmodem/vendor.h 2014-03-20 07:46:16 +0000
+++ drivers/rilmodem/vendor.h 2014-07-21 18:55:43 +0000
@@ -24,7 +24,8 @@
2424
25enum ofono_ril_vendor {25enum ofono_ril_vendor {
26 OFONO_RIL_VENDOR_AOSP = 0,26 OFONO_RIL_VENDOR_AOSP = 0,
27 OFONO_RIL_VENDOR_MTK27 OFONO_RIL_VENDOR_MTK,
28 OFONO_RIL_VENDOR_INFINEON
28};29};
2930
30#endif /* RILMODEM_VENDOR_H */31#endif /* RILMODEM_VENDOR_H */
3132
=== modified file 'gril/grilreply.c'
--- gril/grilreply.c 2014-05-13 01:21:09 +0000
+++ gril/grilreply.c 2014-07-21 18:55:43 +0000
@@ -1204,6 +1204,11 @@
1204 retries[OFONO_SIM_PASSWORD_SIM_PUK],1204 retries[OFONO_SIM_PASSWORD_SIM_PUK],
1205 retries[OFONO_SIM_PASSWORD_SIM_PUK2]);1205 retries[OFONO_SIM_PASSWORD_SIM_PUK2]);
1206 break;1206 break;
1207 case OFONO_RIL_VENDOR_INFINEON:
1208 ofono_error("%s: infineon type should not arrive here",
1209 __func__);
1210 g_assert(FALSE);
1211 break;
1207 }1212 }
12081213
1209 if (rilp.malformed) {1214 if (rilp.malformed) {
@@ -1220,3 +1225,50 @@
12201225
1221 return NULL;1226 return NULL;
1222}1227}
1228
1229void g_ril_reply_free_oem_hook(struct reply_oem_hook *oem_hook)
1230{
1231 if (oem_hook) {
1232 g_free(oem_hook->data);
1233 g_free(oem_hook);
1234 }
1235}
1236
1237struct reply_oem_hook *g_ril_reply_oem_hook_raw(GRil *gril,
1238 const struct ril_msg *message)
1239{
1240 struct reply_oem_hook *reply = NULL;
1241 struct parcel rilp;
1242
1243 reply = g_try_malloc0(sizeof(*reply));
1244 if (reply == NULL) {
1245 ofono_error("%s: out of memory", __func__);
1246 goto end;
1247 }
1248
1249 g_ril_init_parcel(message, &rilp);
1250
1251 reply->data = parcel_r_raw(&rilp, &(reply->length));
1252
1253 if (rilp.malformed) {
1254 ofono_error("%s: malformed parcel", __func__);
1255 g_ril_reply_free_oem_hook(reply);
1256 reply = NULL;
1257 goto end;
1258 }
1259
1260 g_ril_append_print_buf(gril, "{%d", reply->length);
1261
1262 if (reply->data != NULL) {
1263 char *hex_dump;
1264 hex_dump = encode_hex(reply->data, reply->length, '\0');
1265 g_ril_append_print_buf(gril, "%s,%s", print_buf, hex_dump);
1266 g_free(hex_dump);
1267 }
1268
1269 g_ril_append_print_buf(gril, "%s}", print_buf);
1270 g_ril_print_response(gril, message);
1271
1272end:
1273 return reply;
1274}
12231275
=== modified file 'gril/grilreply.h'
--- gril/grilreply.h 2014-04-29 15:50:22 +0000
+++ gril/grilreply.h 2014-07-21 18:55:43 +0000
@@ -89,6 +89,11 @@
89 int provisioned;89 int provisioned;
90};90};
9191
92struct reply_oem_hook {
93 int length;
94 void *data;
95};
96
92void g_ril_reply_free_avail_ops(struct reply_avail_ops *reply);97void g_ril_reply_free_avail_ops(struct reply_avail_ops *reply);
9398
94struct reply_avail_ops *g_ril_reply_parse_avail_ops(GRil *gril,99struct reply_avail_ops *g_ril_reply_parse_avail_ops(GRil *gril,
@@ -160,6 +165,11 @@
160int *g_ril_reply_parse_retries(GRil *gril, const struct ril_msg *message,165int *g_ril_reply_parse_retries(GRil *gril, const struct ril_msg *message,
161 enum ofono_sim_password_type passwd_type);166 enum ofono_sim_password_type passwd_type);
162167
168void g_ril_reply_free_oem_hook(struct reply_oem_hook *oem_hook);
169
170struct reply_oem_hook *g_ril_reply_oem_hook_raw(GRil *gril,
171 const struct ril_msg *message);
172
163#ifdef __cplusplus173#ifdef __cplusplus
164}174}
165#endif175#endif
166176
=== modified file 'gril/grilrequest.c'
--- gril/grilrequest.c 2014-06-12 08:29:40 +0000
+++ gril/grilrequest.c 2014-07-21 18:55:43 +0000
@@ -1030,3 +1030,18 @@
1030 g_ril_append_print_buf(gril, "(%s,%s,%s)",1030 g_ril_append_print_buf(gril, "(%s,%s,%s)",
1031 facility, old_passwd, new_passwd);1031 facility, old_passwd, new_passwd);
1032}1032}
1033
1034void g_ril_request_oem_hook_raw(GRil *gril, const void *payload, size_t length,
1035 struct parcel *rilp)
1036{
1037 char *hex_dump = NULL;
1038
1039 parcel_init(rilp);
1040 parcel_w_raw(rilp, payload, length);
1041
1042 if (payload != NULL)
1043 hex_dump = encode_hex(payload, length, '\0');
1044
1045 g_ril_append_print_buf(gril, "(%s)", hex_dump? hex_dump: "(null)");
1046 g_free(hex_dump);
1047}
10331048
=== modified file 'gril/grilrequest.h'
--- gril/grilrequest.h 2014-06-12 08:29:40 +0000
+++ gril/grilrequest.h 2014-07-21 18:55:43 +0000
@@ -265,6 +265,9 @@
265 const char *new_passwd,265 const char *new_passwd,
266 struct parcel *rilp);266 struct parcel *rilp);
267267
268void g_ril_request_oem_hook_raw(GRil *gril, const void *payload, size_t length,
269 struct parcel *rilp);
270
268#ifdef __cplusplus271#ifdef __cplusplus
269}272}
270#endif273#endif
271274
=== modified file 'gril/parcel.c'
--- gril/parcel.c 2013-12-05 13:53:09 +0000
+++ gril/parcel.c 2014-07-21 18:55:43 +0000
@@ -201,6 +201,58 @@
201 return ret;201 return ret;
202}202}
203203
204int parcel_w_raw(struct parcel *p, const void* data, size_t len)
205{
206 if (data == NULL) {
207 parcel_w_int32(p, -1);
208 return 0;
209 }
210
211 parcel_w_int32(p, len);
212
213 for (;;) {
214
215 if (p->offset + len < p->capacity) {
216 /* There's enough space */
217 memcpy(p->data + p->offset, data, len);
218 p->offset += len;
219 p->size += len;
220 break;
221 } else {
222 /* Grow data and retry */
223 parcel_grow(p, len);
224 }
225 }
226 return 0;
227}
228
229void *parcel_r_raw(struct parcel *p, int *len)
230{
231 char *ret;
232
233 *len = parcel_r_int32(p);
234
235 if (p->malformed || *len <= 0)
236 return NULL;
237
238 if (p->offset + *len > p->size) {
239 ofono_error("%s: parcel is too small", __func__);
240 p->malformed = 1;
241 return NULL;
242 }
243
244 ret = g_try_malloc0(*len);
245 if (ret == NULL) {
246 ofono_error("%s: out of memory (%d bytes)", __func__, *len);
247 return NULL;
248 }
249
250 memcpy(ret, p->data + p->offset, *len);
251 p->offset += *len;
252
253 return ret;
254}
255
204size_t parcel_data_avail(struct parcel *p)256size_t parcel_data_avail(struct parcel *p)
205{257{
206 return (p->size - p->offset);258 return (p->size - p->offset);
207259
=== modified file 'gril/parcel.h'
--- gril/parcel.h 2013-12-05 13:53:09 +0000
+++ gril/parcel.h 2014-07-21 18:55:43 +0000
@@ -39,6 +39,8 @@
39int parcel_w_int32(struct parcel *p, int32_t val);39int parcel_w_int32(struct parcel *p, int32_t val);
40int parcel_w_string(struct parcel *p, const char *str);40int parcel_w_string(struct parcel *p, const char *str);
41char *parcel_r_string(struct parcel *p);41char *parcel_r_string(struct parcel *p);
42int parcel_w_raw(struct parcel *p, const void *data, size_t len);
43void *parcel_r_raw(struct parcel *p, int *len);
42size_t parcel_data_avail(struct parcel *p);44size_t parcel_data_avail(struct parcel *p);
4345
44#endif46#endif
4547
=== removed file 'plugins/android-apndb.c'
--- plugins/android-apndb.c 2014-04-25 16:10:01 +0000
+++ plugins/android-apndb.c 1970-01-01 00:00:00 +0000
@@ -1,494 +0,0 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
6 * 2013 Simon Busch <morphis@gravedo.de>
7 * Copyright (C) 2014 Canonical Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <string.h>
29#include <fcntl.h>
30#include <sys/mman.h>
31#include <sys/stat.h>
32#include <sys/types.h>
33#include <errno.h>
34#include <stdlib.h>
35#include <unistd.h>
36
37#include <glib.h>
38
39#define OFONO_API_SUBJECT_TO_CHANGE
40#include <ofono/modem.h>
41#include <ofono/gprs-provision.h>
42#include <ofono/log.h>
43
44#include "android-apndb.h"
45
46/* TODO: consider reading path from an environment variable */
47
48#ifndef ANDROID_APN_DATABASE
49#define ANDROID_APN_DATABASE "/android/system/etc/apns-conf.xml"
50#endif
51
52struct apndb_data {
53 const char *match_mcc;
54 const char *match_mnc;
55 const char *match_imsi;
56 const char *match_spn;
57 const char *match_gid1;
58 GSList *apns;
59 gboolean allow_duplicates;
60 gboolean mvno_found;
61};
62
63void android_apndb_ap_free(gpointer data)
64{
65 struct apndb_provision_data *ap = data;
66
67 g_free(ap->gprs_data.name);
68 g_free(ap->gprs_data.apn);
69 g_free(ap->gprs_data.username);
70 g_free(ap->gprs_data.password);
71 g_free(ap->gprs_data.message_proxy);
72 g_free(ap->gprs_data.message_center);
73
74 g_free(ap);
75}
76
77static void android_apndb_g_set_error(GMarkupParseContext *context,
78 GError **error,
79 GQuark domain,
80 gint code,
81 const gchar *fmt, ...)
82{
83 va_list ap;
84 gint line_number, char_number;
85
86 g_markup_parse_context_get_position(context, &line_number,
87 &char_number);
88 va_start(ap, fmt);
89
90 *error = g_error_new_valist(domain, code, fmt, ap);
91
92 va_end(ap);
93
94 g_prefix_error(error, "%s:%d ", ANDROID_APN_DATABASE, line_number);
95}
96
97static gboolean imsi_match(const char *imsi, const char *match)
98{
99 gboolean result = FALSE;
100 size_t imsi_len = strlen(imsi);
101 size_t match_len = strlen(match);
102 unsigned int i;
103
104 DBG("imsi %s match %s", imsi, match);
105
106 if (imsi_len != match_len)
107 goto done;
108
109 for (i = 0; i < imsi_len; i++) {
110 if (*(imsi + i) == *(match + i))
111 continue;
112 else if (*(match + i) == 'x')
113 continue;
114 else
115 goto done;
116 }
117
118 result = TRUE;
119
120done:
121 return result;
122}
123
124static enum ofono_gprs_context_type determine_apn_type(const char *types)
125{
126 /*
127 * The database contains entries with the following type field contents:
128 * - default
129 * - default,mms
130 * - default,supl
131 * - defualt,supl,dun
132 * - default,supl,mms
133 * - mms
134 */
135
136 if (g_strcmp0(types, "mms") == 0)
137 return OFONO_GPRS_CONTEXT_TYPE_MMS;
138 else if (g_str_has_prefix(types, "default"))
139 return OFONO_GPRS_CONTEXT_TYPE_INTERNET;
140 else
141 return OFONO_GPRS_CONTEXT_TYPE_ANY;
142}
143
144static char *android_apndb_sanitize_ipv4_address(const char *address)
145{
146 char **numbers = NULL;
147 char *sanitized_numbers[4];
148 unsigned int count = 0;
149 char *result = NULL;
150 char *numeral;
151
152 /*
153 * As src/gprs.c expects MMS proxies to always be
154 * specified using IPV4 numbers-and-dot notation,
155 * we need to strip any leading "0"s from the
156 * individual numeric components, otherwise they
157 * will be treated as octal numbers
158 * ( see 'man inet_aton' for details ).
159 */
160
161 if (g_ascii_isdigit(*address) == FALSE)
162 goto done;
163
164 numbers = g_strsplit(address, ".", 4);
165
166 for (; (numeral = *(numbers+count)); count++) {
167 if (count > 3)
168 goto done;
169
170 for (; *numeral; numeral++) {
171 if (g_ascii_isdigit(*numeral) == FALSE)
172 goto done;
173 else if (*numeral == '0')
174 continue;
175 else
176 break;
177 }
178
179 if (*numeral)
180 sanitized_numbers[count] = numeral;
181 else
182 sanitized_numbers[count] = "0";
183 }
184
185 if (count != 4)
186 goto done;
187
188 result = g_strdup_printf("%s.%s.%s.%s",
189 sanitized_numbers[0],
190 sanitized_numbers[1],
191 sanitized_numbers[2],
192 sanitized_numbers[3]);
193
194done:
195 if (numbers != NULL)
196 g_strfreev(numbers);
197
198 return result;
199}
200
201static void toplevel_apndb_start(GMarkupParseContext *context,
202 const gchar *element_name,
203 const gchar **attribute_names,
204 const gchar **attribute_values,
205 gpointer userdata, GError **error)
206{
207 struct apndb_data *apndb = userdata;
208 struct apndb_provision_data *ap = NULL;
209 int i;
210 const gchar *carrier = NULL;
211 const gchar *mcc = NULL;
212 const gchar *mnc = NULL;
213 const gchar *apn = NULL;
214 const gchar *username = NULL;
215 const gchar *password = NULL;
216 const gchar *types = NULL;
217 const gchar *protocol = NULL;
218 const gchar *mmsproxy = NULL;
219 const gchar *mmsport = NULL;
220 const gchar *mmscenter = NULL;
221 const gchar *mvnomatch = NULL;
222 const gchar *mvnotype = NULL;
223 enum ofono_gprs_proto proto = OFONO_GPRS_PROTO_IP;
224 enum ofono_gprs_context_type type;
225
226 if (g_strcmp0(element_name, "apn") != 0)
227 return;
228
229 for (i = 0; attribute_names[i]; i++) {
230 if (g_strcmp0(attribute_names[i], "carrier") == 0)
231 carrier = attribute_values[i];
232 else if (g_strcmp0(attribute_names[i], "mcc") == 0)
233 mcc = attribute_values[i];
234 else if (g_strcmp0(attribute_names[i], "mnc") == 0)
235 mnc = attribute_values[i];
236 }
237
238 if (mcc == NULL) {
239 android_apndb_g_set_error(context, error, G_MARKUP_ERROR,
240 G_MARKUP_ERROR_MISSING_ATTRIBUTE,
241 "Missing attribute: mcc");
242 return;
243 }
244
245 if (mnc == NULL) {
246 android_apndb_g_set_error(context, error, G_MARKUP_ERROR,
247 G_MARKUP_ERROR_MISSING_ATTRIBUTE,
248 "Missing attribute: mnc");
249 return;
250 }
251
252 if (g_strcmp0(mcc, apndb->match_mcc) != 0 ||
253 g_strcmp0(mnc, apndb->match_mnc) != 0)
254 return;
255
256 for (i = 0; attribute_names[i]; i++) {
257 if (g_strcmp0(attribute_names[i], "apn") == 0)
258 apn = attribute_values[i];
259 else if (g_strcmp0(attribute_names[i], "user") == 0)
260 username = attribute_values[i];
261 else if (g_strcmp0(attribute_names[i], "password") == 0)
262 password = attribute_values[i];
263 else if (g_strcmp0(attribute_names[i], "type") == 0)
264 types = attribute_values[i];
265 else if (g_strcmp0(attribute_names[i], "protocol") == 0)
266 protocol = attribute_values[i];
267 else if (g_strcmp0(attribute_names[i], "mmsc") == 0)
268 mmscenter = attribute_values[i];
269 else if (g_strcmp0(attribute_names[i], "mmsproxy") == 0)
270 mmsproxy = attribute_values[i];
271 else if (g_strcmp0(attribute_names[i], "mmsport") == 0)
272 mmsport = attribute_values[i];
273 else if (g_strcmp0(attribute_names[i], "mvno_match_data") == 0)
274 mvnomatch = attribute_values[i];
275 else if (g_strcmp0(attribute_names[i], "mvno_type") == 0)
276 mvnotype = attribute_values[i];
277 }
278
279 if (apn == NULL) {
280 android_apndb_g_set_error(context, error, G_MARKUP_ERROR,
281 G_MARKUP_ERROR_MISSING_ATTRIBUTE,
282 "APN attribute missing");
283 return;
284 }
285
286 if (types == NULL) {
287 ofono_error("%s: apn for %s missing type attribute", __func__,
288 carrier);
289 return;
290 }
291
292 if (protocol != NULL) {
293 if (g_strcmp0(protocol, "IP") == 0) {
294 proto = OFONO_GPRS_PROTO_IP;
295 } else if (g_strcmp0(protocol, "IPV6") == 0) {
296 proto = OFONO_GPRS_PROTO_IPV6;
297 } else if (g_strcmp0(protocol, "IPV4V6") == 0) {
298 proto = OFONO_GPRS_PROTO_IPV4V6;
299 } else {
300 ofono_error("%s: APN %s has invalid protocol=%s"
301 "attribute", __func__, carrier,
302 protocol);
303 return;
304 }
305 }
306
307 if (mvnotype != NULL && mvnomatch != NULL) {
308
309 if (g_strcmp0(mvnotype, "imsi") == 0) {
310 DBG("APN %s is mvno_type 'imsi'", carrier);
311
312 if (apndb->match_imsi == NULL ||
313 imsi_match(apndb->match_imsi,
314 mvnomatch) == FALSE) {
315 DBG("Skipping MVNO 'imsi' APN %s with"
316 " match_data: %s", carrier, mvnomatch);
317 return;
318 }
319 } else if (g_strcmp0(mvnotype, "spn") == 0) {
320 DBG("APN %s is mvno_type 'spn'", carrier);
321
322 if (g_strcmp0(mvnomatch, apndb->match_spn) != 0) {
323 DBG("Skipping mvno 'spn' APN %s with"
324 " match_data: %s", carrier, mvnomatch);
325 return;
326 }
327
328 } else if (g_strcmp0(mvnotype, "gid") == 0) {
329 int match_len = strlen(mvnomatch);
330
331 DBG("APN %s is mvno_type 'gid'", carrier);
332
333 /* Check initial part of GID1 against match data */
334 if (apndb->match_gid1 == NULL ||
335 g_ascii_strncasecmp(mvnomatch,
336 apndb->match_gid1,
337 match_len) != 0) {
338 DBG("Skipping mvno 'gid' APN %s with"
339 " match_data: %s", carrier, mvnomatch);
340 return;
341 }
342 }
343 }
344
345 type = determine_apn_type(types);
346
347 if (type == OFONO_GPRS_CONTEXT_TYPE_ANY ||
348 (type == OFONO_GPRS_CONTEXT_TYPE_MMS && mmsproxy == NULL)) {
349 DBG("Skipping %s context; types: %s", apn, types);
350 return;
351 }
352
353 ap = g_try_new0(struct apndb_provision_data, 1);
354 if (ap == NULL) {
355 ofono_error("%s: out-of-memory trying to provision APN - %s",
356 __func__, carrier);
357 return;
358 }
359
360 ap->gprs_data.type = type;
361
362 if (carrier != NULL)
363 ap->gprs_data.name = g_strdup(carrier);
364
365 if (apn != NULL)
366 ap->gprs_data.apn = g_strdup(apn);
367
368 if (username != NULL)
369 ap->gprs_data.username = g_strdup(username);
370
371 if (password != NULL)
372 ap->gprs_data.password = g_strdup(password);
373
374 if (mmscenter != NULL && strlen(mmscenter) > 0)
375 ap->gprs_data.message_center = g_strdup(mmscenter);
376
377 if (mmsproxy != NULL && strlen(mmsproxy) > 0) {
378 char *tmp = android_apndb_sanitize_ipv4_address(mmsproxy);
379 if (tmp != NULL)
380 mmsproxy = tmp;
381
382 if (mmsport != NULL)
383 ap->gprs_data.message_proxy =
384 g_strdup_printf("%s:%s", mmsproxy, mmsport);
385 else
386 ap->gprs_data.message_proxy = g_strdup(mmsproxy);
387
388 g_free(tmp);
389 }
390
391 ap->gprs_data.proto = proto;
392
393 if (mvnotype != NULL) {
394 ap->mvno = TRUE;
395 apndb->mvno_found = TRUE;
396 }
397
398 apndb->apns = g_slist_append(apndb->apns, ap);
399}
400
401static void toplevel_apndb_end(GMarkupParseContext *context,
402 const gchar *element_name,
403 gpointer userdata, GError **error)
404{
405}
406
407static const GMarkupParser toplevel_apndb_parser = {
408 toplevel_apndb_start,
409 toplevel_apndb_end,
410 NULL,
411 NULL,
412 NULL,
413};
414
415static gboolean android_apndb_parse(const GMarkupParser *parser,
416 gpointer userdata,
417 GError **error)
418{
419 struct stat st;
420 char *db;
421 int fd;
422 GMarkupParseContext *context;
423 gboolean ret;
424 const char *apndb_path;
425
426 if ((apndb_path = getenv("OFONO_APNDB_PATH")) == NULL)
427 apndb_path = ANDROID_APN_DATABASE;
428
429 fd = open(apndb_path, O_RDONLY);
430 if (fd < 0) {
431 g_set_error(error, G_FILE_ERROR,
432 g_file_error_from_errno(errno),
433 "open(%s) failed: %s", apndb_path,
434 g_strerror(errno));
435 return FALSE;
436 }
437
438 if (fstat(fd, &st) < 0) {
439 close(fd);
440 g_set_error(error, G_FILE_ERROR,
441 g_file_error_from_errno(errno),
442 "fstat(%s) failed: %s", apndb_path,
443 g_strerror(errno));
444 return FALSE;
445 }
446
447 db = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
448 if (db == MAP_FAILED) {
449 close(fd);
450 g_set_error(error, G_FILE_ERROR,
451 g_file_error_from_errno(errno),
452 "mmap(%s) failed: %s", apndb_path,
453 g_strerror(errno));
454 return FALSE;
455 }
456
457 context = g_markup_parse_context_new(parser,
458 G_MARKUP_TREAT_CDATA_AS_TEXT,
459 userdata, NULL);
460
461 ret = g_markup_parse_context_parse(context, db, st.st_size, error);
462
463 if (ret == TRUE)
464 g_markup_parse_context_end_parse(context, error);
465
466 munmap(db, st.st_size);
467 close(fd);
468 g_markup_parse_context_free(context);
469
470 return ret;
471}
472
473GSList *android_apndb_lookup_apn(const char *mcc, const char *mnc,
474 const char *spn, const char *imsi, const char *gid1,
475 gboolean *mvno_found, GError **error)
476{
477 struct apndb_data apndb = { NULL };
478
479 apndb.match_mcc = mcc;
480 apndb.match_mnc = mnc;
481 apndb.match_spn = spn;
482 apndb.match_imsi = imsi;
483 apndb.match_gid1 = gid1;
484
485 if (android_apndb_parse(&toplevel_apndb_parser, &apndb,
486 error) == FALSE) {
487 g_slist_free_full(apndb.apns, android_apndb_ap_free);
488 apndb.apns = NULL;
489 }
490
491 *mvno_found = apndb.mvno_found;
492
493 return apndb.apns;
494}
4950
=== removed file 'plugins/android-apndb.h'
--- plugins/android-apndb.h 2014-04-14 13:59:23 +0000
+++ plugins/android-apndb.h 1970-01-01 00:00:00 +0000
@@ -1,33 +0,0 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
6 * 2013 Simon Busch <morphis@gravedo.de>
7 * Copyright (C) 2014 Canonical Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24struct apndb_provision_data {
25 struct ofono_gprs_provision_data gprs_data;
26 gboolean mvno;
27};
28
29void android_apndb_ap_free(gpointer data);
30
31GSList *android_apndb_lookup_apn(const char *mcc, const char *mnc,
32 const char *spn, const char *imsi, const char *gid1,
33 gboolean *mvno_found, GError **error);
340
=== removed file 'plugins/android-provision.c'
--- plugins/android-provision.c 2014-05-13 17:15:55 +0000
+++ plugins/android-provision.c 1970-01-01 00:00:00 +0000
@@ -1,227 +0,0 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
6 * 2013 Simon Busch <morphis@gravedo.de>
7 * Copyright (C) 2014 Canonical Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <errno.h>
29#include <string.h>
30
31#include <glib.h>
32
33#define OFONO_API_SUBJECT_TO_CHANGE
34#include <ofono/types.h>
35#include <ofono/log.h>
36#include <ofono/plugin.h>
37#include <ofono/modem.h>
38#include <ofono/gprs-provision.h>
39
40#include "android-apndb.h"
41#include "mbpi.h"
42
43static unsigned int filter_apns(GSList **apns, GSList *mbpi_apns,
44 gboolean mvno_found)
45{
46 GSList *l = NULL;
47 GSList *l2 = NULL;
48 gboolean found = FALSE;
49 unsigned int ap_count = g_slist_length(*apns);
50 struct apndb_provision_data *ap;
51
52 if (mvno_found == TRUE) {
53
54 for (l = *apns; l;) {
55 ap = l->data;
56 l = l->next;
57
58 if (ap->mvno == FALSE) {
59 DBG("Removing: %s", ap->gprs_data.apn);
60 *apns = g_slist_remove(*apns,
61 (gconstpointer) ap);
62 android_apndb_ap_free(ap);
63 ap_count--;
64 }
65 }
66
67 goto done;
68 }
69
70 for (l = mbpi_apns; l; l = l->next, found = FALSE) {
71 struct ofono_gprs_provision_data *ap2 = l->data;
72
73 if (ap2->apn == NULL) {
74 ofono_error("%s: invalid mbpi entry - %s found",
75 __func__, ap2->name);
76 continue;
77 }
78
79 for (l2 = *apns; l2; l2 = l2->next) {
80 ap = l2->data;
81
82 if (ap->gprs_data.apn != NULL &&
83 ap->gprs_data.type ==
84 OFONO_GPRS_CONTEXT_TYPE_INTERNET &&
85 g_strcmp0(ap2->apn, ap->gprs_data.apn) == 0) {
86
87 found = TRUE;
88 break;
89 }
90 }
91
92 if (found == FALSE) {
93 DBG("Adding %s to apns", ap2->apn);
94
95 ap = g_try_new0(struct apndb_provision_data, 1);
96 if (ap == NULL) {
97 ofono_error("%s: out-of-memory trying to"
98 " provision APN - %s",
99 __func__, ap2->name);
100 goto done;
101 }
102
103 memcpy(&ap->gprs_data, ap2, sizeof(ap->gprs_data));
104 *apns = g_slist_append(*apns, ap);
105 ap_count++;
106 g_free(ap2);
107 } else {
108 mbpi_ap_free(ap2);
109 }
110 }
111
112done:
113 return ap_count;
114}
115
116static int provision_get_settings(const char *mcc, const char *mnc,
117 const char *spn,
118 const char *imsi, const char *gid1,
119 struct ofono_gprs_provision_data **settings,
120 int *count)
121{
122 GSList *apns = NULL;
123 GSList *mbpi_apns = NULL;
124 GSList *l = NULL;
125 GError *error = NULL;
126 gboolean mvno_found = FALSE;
127 unsigned int ap_count;
128 unsigned int i;
129
130 ofono_info("Provisioning for MCC %s, MNC %s, SPN '%s', IMSI '%s', "
131 "GID1 '%s'", mcc, mnc, spn, imsi, gid1);
132
133 apns = android_apndb_lookup_apn(mcc, mnc, spn, imsi, gid1,
134 &mvno_found, &error);
135 if (apns == NULL) {
136 if (error != NULL) {
137 ofono_error("%s: apndb_lookup error -%s for mcc %s"
138 " mnc %s spn %s imsi %s", __func__,
139 error->message, mcc, mnc, spn, imsi);
140 g_error_free(error);
141 error = NULL;
142 }
143 }
144
145 /* If an mvno apn was found, only provision mvno apns */
146 if (mvno_found == FALSE) {
147 mbpi_apns = mbpi_lookup_apn(mcc, mnc,
148 OFONO_GPRS_CONTEXT_TYPE_INTERNET,
149 TRUE, &error);
150 if (mbpi_apns == NULL) {
151 if (error != NULL) {
152 ofono_error("%s: MBPI error - %s for mcc %s"
153 " mnc %s spn: %s", __func__,
154 error->message, mcc, mnc, spn);
155 g_error_free(error);
156 error = NULL;
157 }
158 }
159 }
160
161 ap_count = filter_apns(&apns, mbpi_apns, mvno_found);
162 if (ap_count == 0) {
163 ofono_warn("%s: No APNs found for mcc %s mnc %s spn: %s"
164 " imsi: %s", __func__, mcc, mnc, spn, imsi);
165
166 *count = 0;
167 return -ENOENT;
168 }
169
170 *settings = g_try_new0(struct ofono_gprs_provision_data, ap_count);
171 if (*settings == NULL) {
172 ofono_error("%s: provisioning failed: %s", __func__,
173 g_strerror(errno));
174
175 g_slist_free_full(apns, android_apndb_ap_free);
176
177 *count = 0;
178 return -ENOMEM;
179 }
180
181 *count = ap_count;
182
183 for (l = apns, i = 0; l; l = l->next, i++) {
184 struct apndb_provision_data *ap = l->data;
185
186 DBG("Name: '%s'", ap->gprs_data.name);
187 DBG("APN: '%s'", ap->gprs_data.apn);
188 DBG("Type: %s", mbpi_ap_type(ap->gprs_data.type));
189 DBG("Username: '%s'", ap->gprs_data.username);
190 DBG("Password: '%s'", ap->gprs_data.password);
191 DBG("Message Proxy: '%s'", ap->gprs_data.message_proxy);
192 DBG("Message Center: '%s'", ap->gprs_data.message_center);
193 DBG("MVNO: %u", ap->mvno);
194
195 memcpy(*settings + i, &ap->gprs_data, sizeof(ap->gprs_data));
196
197 g_free(ap);
198 }
199
200 if (apns != NULL)
201 g_slist_free(apns);
202
203 if (mbpi_apns != NULL)
204 g_slist_free(mbpi_apns);
205
206 return 0;
207}
208
209static struct ofono_gprs_provision_driver android_provision_driver = {
210 .name = "Android APN database Provisioning",
211 .get_settings = provision_get_settings
212};
213
214static int android_provision_init(void)
215{
216 return ofono_gprs_provision_driver_register(&android_provision_driver);
217}
218
219static void android_provision_exit(void)
220{
221 ofono_gprs_provision_driver_unregister(&android_provision_driver);
222}
223
224OFONO_PLUGIN_DEFINE(android_provision,
225 "Android APN database Provisioning Plugin", VERSION,
226 OFONO_PLUGIN_PRIORITY_DEFAULT,
227 android_provision_init, android_provision_exit)
2280
=== added file 'plugins/infineon.c'
--- plugins/infineon.c 1970-01-01 00:00:00 +0000
+++ plugins/infineon.c 2014-07-21 18:55:43 +0000
@@ -0,0 +1,76 @@
1/*
2 *
3 * oFono - Open Source Telephony - RIL-based devices: infineon modems
4 *
5 * Copyright (C) 2014 Canonical Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22#ifdef HAVE_CONFIG_H
23#include <config.h>
24#endif
25
26#define OFONO_API_SUBJECT_TO_CHANGE
27
28#include <ofono/plugin.h>
29#include <ofono/log.h>
30#include <ofono/modem.h>
31
32#include "ofono.h"
33
34#include "drivers/rilmodem/vendor.h"
35#include "ril.h"
36
37static int inf_probe(struct ofono_modem *modem)
38{
39 return ril_create(modem, OFONO_RIL_VENDOR_INFINEON);
40}
41
42static struct ofono_modem_driver infineon_driver = {
43 .name = "infineon",
44 .probe = inf_probe,
45 .remove = ril_remove,
46 .enable = ril_enable,
47 .disable = ril_disable,
48 .pre_sim = ril_pre_sim,
49 .post_sim = ril_post_sim,
50 .post_online = ril_post_online,
51 .set_online = ril_set_online,
52};
53
54/*
55 * This plugin is a device plugin for infineon modems that use RIL interface.
56 * The plugin 'rildev' is used to determine which RIL plugin should be loaded
57 * based upon an environment variable.
58 */
59static int inf_init(void)
60{
61 int retval = 0;
62
63 if ((retval = ofono_modem_driver_register(&infineon_driver)))
64 DBG("ofono_modem_driver_register returned: %d", retval);
65
66 return retval;
67}
68
69static void inf_exit(void)
70{
71 DBG("");
72 ofono_modem_driver_unregister(&infineon_driver);
73}
74
75OFONO_PLUGIN_DEFINE(infineon, "Infineon modem driver", VERSION,
76 OFONO_PLUGIN_PRIORITY_DEFAULT, inf_init, inf_exit)
077
=== modified file 'plugins/mtk.c'
--- plugins/mtk.c 2014-06-12 10:52:45 +0000
+++ plugins/mtk.c 2014-07-21 18:55:43 +0000
@@ -92,6 +92,8 @@
92 int slot;92 int slot;
93 struct ril_sim_data sim_data;93 struct ril_sim_data sim_data;
94 struct ofono_devinfo *devinfo;94 struct ofono_devinfo *devinfo;
95 struct cb_data *pending_online_cbd;
96 ofono_bool_t pending_online;
95};97};
9698
97/*99/*
@@ -106,6 +108,8 @@
106static void send_get_sim_status(struct ofono_modem *modem);108static void send_get_sim_status(struct ofono_modem *modem);
107static int create_gril(struct ofono_modem *modem);109static int create_gril(struct ofono_modem *modem);
108static gboolean mtk_connected(gpointer user_data);110static gboolean mtk_connected(gpointer user_data);
111static void mtk_set_online(struct ofono_modem *modem, ofono_bool_t online,
112 ofono_modem_online_cb_t callback, void *data);
109113
110static void mtk_debug(const char *str, void *user_data)114static void mtk_debug(const char *str, void *user_data)
111{115{
@@ -372,14 +376,23 @@
372 send_get_sim_status(modem);376 send_get_sim_status(modem);
373}377}
374378
379static struct mtk_data *ril_complement(struct mtk_data *ril)
380{
381 if (ril->slot == MULTISIM_SLOT_0)
382 return mtk_1;
383 else
384 return mtk_0;
385}
386
375static void mtk_sim_mode_cb(struct ril_msg *message, gpointer user_data)387static void mtk_sim_mode_cb(struct ril_msg *message, gpointer user_data)
376{388{
377 struct cb_data *cbd = user_data;389 struct cb_data *cbd = user_data;
378 ofono_modem_online_cb_t cb = cbd->cb;390 ofono_modem_online_cb_t cb = cbd->cb;
379 struct ofono_modem *modem = cbd->user;391 struct ofono_modem *modem = cbd->user;
380 struct mtk_data *ril = ofono_modem_get_data(modem);392 struct mtk_data *ril = ofono_modem_get_data(modem);
393 struct mtk_data *ril_c;
381394
382 ril->pending_cb = NULL;395 mtk_0->pending_cb = NULL;
383396
384 if (message->error == RIL_E_SUCCESS) {397 if (message->error == RIL_E_SUCCESS) {
385 g_ril_print_response_no_args(ril->modem, message);398 g_ril_print_response_no_args(ril->modem, message);
@@ -390,6 +403,21 @@
390 ril_error_to_string(message->error));403 ril_error_to_string(message->error));
391 CALLBACK_WITH_FAILURE(cb, cbd->data);404 CALLBACK_WITH_FAILURE(cb, cbd->data);
392 }405 }
406
407 /* Execute possible pending operation on the other modem */
408
409 ril_c = ril_complement(ril);
410
411 if (ril_c->pending_online_cbd) {
412 struct cb_data *pending_cbd = ril_c->pending_online_cbd;
413 ofono_modem_online_cb_t pending_cb = pending_cbd->cb;
414
415 mtk_set_online(pending_cbd->user, ril_c->pending_online,
416 pending_cb, pending_cbd->data);
417
418 g_free(ril_c->pending_online_cbd);
419 ril_c->pending_online_cbd = NULL;
420 }
393}421}
394422
395static int sim_state()423static int sim_state()
@@ -484,6 +512,25 @@
484 ofono_modem_online_cb_t cb = cbd->cb;512 ofono_modem_online_cb_t cb = cbd->cb;
485 int current_state, next_state;513 int current_state, next_state;
486514
515 /*
516 * Serialize online requests to avoid incoherent states. When changing
517 * the online state of *one* of the modems, we need to send a
518 * DUAL_SIM_MODE_SWITCH request, which affects *both* modems. Also, when
519 * we want to online one modem and at that time both modems are
520 * offline a RADIO_POWERON needs to be sent before DUAL_SIM_MODE_SWITCH,
521 * with the additional complexity of being disconnected from the rild
522 * socket while doing the sequence. This can take some time, and we
523 * cannot change the state of the other modem while the sequence is
524 * happenig, as DUAL_SIM_MODE_SWITCH affects both states. Therefore, we
525 * need to do this serialization, which is different from the one done
526 * per modem by ofono core.
527 */
528 if (mtk_0->pending_cb != NULL) {
529 ril->pending_online_cbd = cbd;
530 ril->pending_online = online;
531 return;
532 }
533
487 current_state = sim_state();534 current_state = sim_state();
488535
489 ril->ofono_online = online;536 ril->ofono_online = online;
490537
=== modified file 'plugins/ril.c'
--- plugins/ril.c 2014-06-24 18:59:26 +0000
+++ plugins/ril.c 2014-07-21 18:55:43 +0000
@@ -60,6 +60,7 @@
60#include <grilrequest.h>60#include <grilrequest.h>
61#include <grilunsol.h>61#include <grilunsol.h>
6262
63#include "ril.h"
63#include "drivers/rilmodem/rilmodem.h"64#include "drivers/rilmodem/rilmodem.h"
64#include "drivers/rilmodem/vendor.h"65#include "drivers/rilmodem/vendor.h"
6566
@@ -69,6 +70,7 @@
6970
70struct ril_data {71struct ril_data {
71 GRil *modem;72 GRil *modem;
73 enum ofono_ril_vendor vendor;
72 int sim_status_retries;74 int sim_status_retries;
73 ofono_bool_t connected;75 ofono_bool_t connected;
74 ofono_bool_t have_sim;76 ofono_bool_t have_sim;
@@ -118,7 +120,7 @@
118 if (ril->voice == NULL)120 if (ril->voice == NULL)
119 ril->voice =121 ril->voice =
120 ofono_voicecall_create(modem,122 ofono_voicecall_create(modem,
121 0,123 ril->vendor,
122 RILMODEM,124 RILMODEM,
123 ril->modem);125 ril->modem);
124126
@@ -205,7 +207,7 @@
205 sim_status_cb, modem, NULL);207 sim_status_cb, modem, NULL);
206}208}
207209
208static int ril_probe(struct ofono_modem *modem)210int ril_create(struct ofono_modem *modem, enum ofono_ril_vendor vendor)
209{211{
210 struct ril_data *ril = g_try_new0(struct ril_data, 1);212 struct ril_data *ril = g_try_new0(struct ril_data, 1);
211 if (ril == NULL) {213 if (ril == NULL) {
@@ -215,6 +217,7 @@
215217
216 DBG("");218 DBG("");
217219
220 ril->vendor = vendor;
218 ril->have_sim = FALSE;221 ril->have_sim = FALSE;
219 ril->ofono_online = FALSE;222 ril->ofono_online = FALSE;
220 ril->radio_state = RADIO_STATE_OFF;223 ril->radio_state = RADIO_STATE_OFF;
@@ -229,11 +232,15 @@
229 return -errno;232 return -errno;
230}233}
231234
232static void ril_remove(struct ofono_modem *modem)235static int ril_probe(struct ofono_modem *modem)
236{
237 return ril_create(modem, OFONO_RIL_VENDOR_AOSP);
238}
239
240void ril_remove(struct ofono_modem *modem)
233{241{
234 struct ril_data *ril = ofono_modem_get_data(modem);242 struct ril_data *ril = ofono_modem_get_data(modem);
235243
236
237 ofono_modem_set_data(modem, NULL);244 ofono_modem_set_data(modem, NULL);
238245
239 if (!ril)246 if (!ril)
@@ -244,24 +251,24 @@
244 g_free(ril);251 g_free(ril);
245}252}
246253
247static void ril_pre_sim(struct ofono_modem *modem)254void ril_pre_sim(struct ofono_modem *modem)
248{255{
249 struct ril_data *ril = ofono_modem_get_data(modem);256 struct ril_data *ril = ofono_modem_get_data(modem);
250 struct ril_sim_data sim_data;257 struct ril_sim_data sim_data;
251258
252 DBG("");259 DBG("");
253260
254 ofono_devinfo_create(modem, 0, RILMODEM, ril->modem);261 ofono_devinfo_create(modem, ril->vendor, RILMODEM, ril->modem);
255262
256 sim_data.gril = ril->modem;263 sim_data.gril = ril->modem;
257 sim_data.modem = modem;264 sim_data.modem = modem;
258 sim_data.ril_state_watch = NULL;265 sim_data.ril_state_watch = NULL;
259266
260 ril->sim = ofono_sim_create(modem, 0, RILMODEM, &sim_data);267 ril->sim = ofono_sim_create(modem, ril->vendor, RILMODEM, &sim_data);
261 g_assert(ril->sim != NULL);268 g_assert(ril->sim != NULL);
262}269}
263270
264static void ril_post_sim(struct ofono_modem *modem)271void ril_post_sim(struct ofono_modem *modem)
265{272{
266 struct ril_data *ril = ofono_modem_get_data(modem);273 struct ril_data *ril = ofono_modem_get_data(modem);
267 struct ofono_gprs *gprs;274 struct ofono_gprs *gprs;
@@ -273,10 +280,11 @@
273 * - stk ( SIM toolkit )280 * - stk ( SIM toolkit )
274 * - radio_settings281 * - radio_settings
275 */282 */
276 ofono_sms_create(modem, 0, RILMODEM, ril->modem);283 ofono_sms_create(modem, ril->vendor, RILMODEM, ril->modem);
277284
278 gprs = ofono_gprs_create(modem, 0, RILMODEM, ril->modem);285 gprs = ofono_gprs_create(modem, ril->vendor, RILMODEM, ril->modem);
279 gc = ofono_gprs_context_create(modem, 0, RILMODEM, ril->modem);286 gc = ofono_gprs_context_create(modem, ril->vendor,
287 RILMODEM, ril->modem);
280288
281 if (gc) {289 if (gc) {
282 ofono_gprs_context_set_type(gc,290 ofono_gprs_context_set_type(gc,
@@ -284,7 +292,8 @@
284 ofono_gprs_add_context(gprs, gc);292 ofono_gprs_add_context(gprs, gc);
285 }293 }
286294
287 gc = ofono_gprs_context_create(modem, 0, RILMODEM, ril->modem);295 gc = ofono_gprs_context_create(modem, ril->vendor,
296 RILMODEM, ril->modem);
288297
289 if (gc) {298 if (gc) {
290 ofono_gprs_context_set_type(gc,299 ofono_gprs_context_set_type(gc,
@@ -296,19 +305,19 @@
296 if (mw)305 if (mw)
297 ofono_message_waiting_register(mw);306 ofono_message_waiting_register(mw);
298307
299 ofono_call_forwarding_create(modem, 0, RILMODEM, ril->modem);308 ofono_call_forwarding_create(modem, ril->vendor, RILMODEM, ril->modem);
300}309}
301310
302static void ril_post_online(struct ofono_modem *modem)311void ril_post_online(struct ofono_modem *modem)
303{312{
304 struct ril_data *ril = ofono_modem_get_data(modem);313 struct ril_data *ril = ofono_modem_get_data(modem);
305314
306 ofono_call_volume_create(modem, 0, RILMODEM, ril->modem);315 ofono_call_volume_create(modem, ril->vendor, RILMODEM, ril->modem);
307 ofono_netreg_create(modem, 0, RILMODEM, ril->modem);316 ofono_netreg_create(modem, ril->vendor, RILMODEM, ril->modem);
308 ofono_ussd_create(modem, 0, RILMODEM, ril->modem);317 ofono_ussd_create(modem, ril->vendor, RILMODEM, ril->modem);
309 ofono_call_settings_create(modem, 0, RILMODEM, ril->modem);318 ofono_call_settings_create(modem, ril->vendor, RILMODEM, ril->modem);
310 ofono_radio_settings_create(modem, 0, RILMODEM, ril->modem);319 ofono_radio_settings_create(modem, ril->vendor, RILMODEM, ril->modem);
311 ofono_call_barring_create(modem, 0, RILMODEM, ril->modem);320 ofono_call_barring_create(modem, ril->vendor, RILMODEM, ril->modem);
312}321}
313322
314static void ril_set_online_cb(struct ril_msg *message, gpointer user_data)323static void ril_set_online_cb(struct ril_msg *message, gpointer user_data)
@@ -354,8 +363,8 @@
354 }363 }
355}364}
356365
357static void ril_set_online(struct ofono_modem *modem, ofono_bool_t online,366void ril_set_online(struct ofono_modem *modem, ofono_bool_t online,
358 ofono_modem_online_cb_t callback, void *data)367 ofono_modem_online_cb_t callback, void *data)
359{368{
360 struct ril_data *ril = ofono_modem_get_data(modem);369 struct ril_data *ril = ofono_modem_get_data(modem);
361 struct cb_data *cbd = cb_data_new(callback, data, ril);370 struct cb_data *cbd = cb_data_new(callback, data, ril);
@@ -417,7 +426,7 @@
417 return 0;426 return 0;
418}427}
419428
420static int ril_enable(struct ofono_modem *modem)429int ril_enable(struct ofono_modem *modem)
421{430{
422 int ret;431 int ret;
423432
@@ -430,7 +439,7 @@
430 return -EINPROGRESS;439 return -EINPROGRESS;
431}440}
432441
433static int ril_disable(struct ofono_modem *modem)442int ril_disable(struct ofono_modem *modem)
434{443{
435 struct ril_data *ril = ofono_modem_get_data(modem);444 struct ril_data *ril = ofono_modem_get_data(modem);
436445
437446
=== added file 'plugins/ril.h'
--- plugins/ril.h 1970-01-01 00:00:00 +0000
+++ plugins/ril.h 2014-07-21 18:55:43 +0000
@@ -0,0 +1,30 @@
1/*
2 *
3 * oFono - Open Source Telephony - RIL-based devices
4 *
5 * Copyright (C) 2014 Canonical Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22int ril_create(struct ofono_modem *modem, enum ofono_ril_vendor vendor);
23void ril_remove(struct ofono_modem *modem);
24int ril_enable(struct ofono_modem *modem);
25int ril_disable(struct ofono_modem *modem);
26void ril_pre_sim(struct ofono_modem *modem);
27void ril_post_sim(struct ofono_modem *modem);
28void ril_post_online(struct ofono_modem *modem);
29void ril_set_online(struct ofono_modem *modem, ofono_bool_t online,
30 ofono_modem_online_cb_t callback, void *data);
031
=== added file 'plugins/ubuntu-apndb.c'
--- plugins/ubuntu-apndb.c 1970-01-01 00:00:00 +0000
+++ plugins/ubuntu-apndb.c 2014-07-21 18:55:43 +0000
@@ -0,0 +1,596 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
6 * 2013 Simon Busch <morphis@gravedo.de>
7 * Copyright (C) 2014 Canonical Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <string.h>
29#include <fcntl.h>
30#include <sys/mman.h>
31#include <sys/stat.h>
32#include <sys/types.h>
33#include <errno.h>
34#include <stdlib.h>
35#include <unistd.h>
36
37#include <glib.h>
38
39#define OFONO_API_SUBJECT_TO_CHANGE
40#include <ofono/modem.h>
41#include <ofono/gprs-provision.h>
42#include <ofono/log.h>
43
44#include "ubuntu-apndb.h"
45
46#ifndef SYSTEM_APNDB_PATH
47#define SYSTEM_APNDB_PATH "/system/etc/apns-conf.xml"
48#define CUSTOM_APNDB_PATH "/custom/etc/apns-conf.xml"
49#endif
50
51struct apndb_data {
52 const char *match_mcc;
53 const char *match_mnc;
54 const char *match_imsi;
55 const char *match_spn;
56 const char *match_gid1;
57 GSList *apns;
58 gboolean allow_duplicates;
59 gboolean mvno_found;
60};
61
62void ubuntu_apndb_ap_free(gpointer data)
63{
64 struct apndb_provision_data *ap = data;
65
66 g_free(ap->gprs_data.name);
67 g_free(ap->gprs_data.apn);
68 g_free(ap->gprs_data.username);
69 g_free(ap->gprs_data.password);
70 g_free(ap->gprs_data.message_proxy);
71 g_free(ap->gprs_data.message_center);
72
73 g_free(ap);
74}
75
76static gboolean imsi_match(const char *imsi, const char *match)
77{
78 gboolean result = FALSE;
79 size_t imsi_len = strlen(imsi);
80 size_t match_len = strlen(match);
81 unsigned int i;
82
83 DBG("imsi %s match %s", imsi, match);
84
85 if (imsi_len != match_len)
86 goto done;
87
88 for (i = 0; i < imsi_len; i++) {
89 if (*(imsi + i) == *(match + i))
90 continue;
91 else if (*(match + i) == 'x')
92 continue;
93 else
94 goto done;
95 }
96
97 result = TRUE;
98
99done:
100 return result;
101}
102
103static void strip_non_mvno_apns(GSList **apns)
104{
105 GSList *l = NULL;
106 unsigned int ap_count = g_slist_length(*apns);
107 struct apndb_provision_data *ap;
108
109 DBG("");
110
111 for (l = *apns; l;) {
112 ap = l->data;
113 l = l->next;
114
115 if (ap->mvno == FALSE) {
116 DBG("Removing: %s", ap->gprs_data.apn);
117 *apns = g_slist_remove(*apns,
118 (gconstpointer) ap);
119 ubuntu_apndb_ap_free(ap);
120 ap_count--;
121 }
122 }
123}
124
125static GSList *merge_apn_lists(GSList *custom_apns, GSList *base_apns)
126{
127 GSList *l = NULL;
128 GSList *l2 = NULL;
129 gboolean found = FALSE;
130 struct apndb_provision_data *ap;
131
132 DBG("");
133
134 if (custom_apns == NULL)
135 return base_apns;
136
137 for (l = custom_apns; l; l = l->next, found = FALSE) {
138 struct apndb_provision_data *ap2 = l->data;
139
140 if (ap2->gprs_data.apn == NULL) {
141 ofono_error("%s: invalid custom apn entry - %s found",
142 __func__, ap2->gprs_data.name);
143 continue;
144 }
145
146 for (l2 = base_apns; l2; l2 = l2->next) {
147 ap = l2->data;
148
149 if (ap->gprs_data.apn != NULL &&
150 ap->gprs_data.type == ap2->gprs_data.type &&
151 g_strcmp0(ap2->gprs_data.apn,
152 ap->gprs_data.apn) == 0) {
153
154 found = TRUE;
155 break;
156 }
157 }
158
159 if (found == TRUE) {
160 DBG("found=TRUE; removing '%s'", ap->gprs_data.apn);
161
162 base_apns = g_slist_remove(base_apns, ap);
163 ubuntu_apndb_ap_free(ap);
164 }
165 }
166
167 custom_apns = g_slist_reverse(custom_apns);
168
169 for (l = custom_apns; l; l = l->next) {
170 struct ap2 *ap2 = l->data;
171
172 base_apns = g_slist_prepend(base_apns, ap2);
173 }
174
175 g_slist_free(custom_apns);
176
177 return base_apns;
178}
179
180static enum ofono_gprs_context_type determine_apn_type(const char *types)
181{
182 /*
183 * The database contains entries with the following type field contents:
184 * - default
185 * - default,mms
186 * - default,supl
187 * - defualt,supl,dun
188 * - default,supl,mms
189 * - mms
190 */
191
192 if (g_strcmp0(types, "mms") == 0)
193 return OFONO_GPRS_CONTEXT_TYPE_MMS;
194 else if (g_str_has_prefix(types, "default"))
195 return OFONO_GPRS_CONTEXT_TYPE_INTERNET;
196 else
197 return OFONO_GPRS_CONTEXT_TYPE_ANY;
198}
199
200static char *ubuntu_apndb_sanitize_ipv4_address(const char *address)
201{
202 char **numbers = NULL;
203 char *sanitized_numbers[4];
204 unsigned int count = 0;
205 char *result = NULL;
206 char *numeral;
207
208 /*
209 * As src/gprs.c expects MMS proxies to always be
210 * specified using IPV4 numbers-and-dot notation,
211 * we need to strip any leading "0"s from the
212 * individual numeric components, otherwise they
213 * will be treated as octal numbers
214 * ( see 'man inet_aton' for details ).
215 */
216
217 if (g_ascii_isdigit(*address) == FALSE)
218 goto done;
219
220 numbers = g_strsplit(address, ".", 4);
221
222 for (; (numeral = *(numbers+count)); count++) {
223 if (count > 3)
224 goto done;
225
226 for (; *numeral; numeral++) {
227 if (g_ascii_isdigit(*numeral) == FALSE)
228 goto done;
229 else if (*numeral == '0')
230 continue;
231 else
232 break;
233 }
234
235 if (*numeral)
236 sanitized_numbers[count] = numeral;
237 else
238 sanitized_numbers[count] = "0";
239 }
240
241 if (count != 4)
242 goto done;
243
244 result = g_strdup_printf("%s.%s.%s.%s",
245 sanitized_numbers[0],
246 sanitized_numbers[1],
247 sanitized_numbers[2],
248 sanitized_numbers[3]);
249
250done:
251 if (numbers != NULL)
252 g_strfreev(numbers);
253
254 return result;
255}
256
257static void toplevel_apndb_start(GMarkupParseContext *context,
258 const gchar *element_name,
259 const gchar **attribute_names,
260 const gchar **attribute_values,
261 gpointer userdata, GError **error)
262{
263 struct apndb_data *apndb = userdata;
264 struct apndb_provision_data *ap = NULL;
265 int i;
266 const gchar *carrier = NULL;
267 const gchar *mcc = NULL;
268 const gchar *mnc = NULL;
269 const gchar *apn = NULL;
270 const gchar *username = NULL;
271 const gchar *password = NULL;
272 const gchar *types = NULL;
273 const gchar *protocol = NULL;
274 const gchar *mmsproxy = NULL;
275 const gchar *mmsport = NULL;
276 const gchar *mmscenter = NULL;
277 const gchar *mvnomatch = NULL;
278 const gchar *mvnotype = NULL;
279 enum ofono_gprs_proto proto = OFONO_GPRS_PROTO_IP;
280 enum ofono_gprs_context_type type;
281
282 if (g_strcmp0(element_name, "apn") != 0)
283 return;
284
285 for (i = 0; attribute_names[i]; i++) {
286 if (g_strcmp0(attribute_names[i], "carrier") == 0)
287 carrier = attribute_values[i];
288 else if (g_strcmp0(attribute_names[i], "mcc") == 0)
289 mcc = attribute_values[i];
290 else if (g_strcmp0(attribute_names[i], "mnc") == 0)
291 mnc = attribute_values[i];
292 }
293
294 if (mcc == NULL) {
295 ofono_error("%s: apn for %s missing 'mcc' attribute", __func__,
296 carrier);
297 return;
298 }
299
300 if (mnc == NULL) {
301 ofono_error("%s: apn for %s missing 'mnc' attribute", __func__,
302 carrier);
303 return;
304 }
305
306 if (g_strcmp0(mcc, apndb->match_mcc) != 0 ||
307 g_strcmp0(mnc, apndb->match_mnc) != 0)
308 return;
309
310 for (i = 0; attribute_names[i]; i++) {
311 if (g_strcmp0(attribute_names[i], "apn") == 0)
312 apn = attribute_values[i];
313 else if (g_strcmp0(attribute_names[i], "user") == 0)
314 username = attribute_values[i];
315 else if (g_strcmp0(attribute_names[i], "password") == 0)
316 password = attribute_values[i];
317 else if (g_strcmp0(attribute_names[i], "type") == 0)
318 types = attribute_values[i];
319 else if (g_strcmp0(attribute_names[i], "protocol") == 0)
320 protocol = attribute_values[i];
321 else if (g_strcmp0(attribute_names[i], "mmsc") == 0)
322 mmscenter = attribute_values[i];
323 else if (g_strcmp0(attribute_names[i], "mmsproxy") == 0)
324 mmsproxy = attribute_values[i];
325 else if (g_strcmp0(attribute_names[i], "mmsport") == 0)
326 mmsport = attribute_values[i];
327 else if (g_strcmp0(attribute_names[i], "mvno_match_data") == 0)
328 mvnomatch = attribute_values[i];
329 else if (g_strcmp0(attribute_names[i], "mvno_type") == 0)
330 mvnotype = attribute_values[i];
331 }
332
333 if (apn == NULL) {
334 ofono_error("%s: apn for %s missing 'apn' attribute", __func__,
335 carrier);
336 return;
337 }
338
339 if (types == NULL) {
340 ofono_error("%s: apn for %s missing type attribute", __func__,
341 carrier);
342 return;
343 }
344
345 if (protocol != NULL) {
346 if (g_strcmp0(protocol, "IP") == 0) {
347 proto = OFONO_GPRS_PROTO_IP;
348 } else if (g_strcmp0(protocol, "IPV6") == 0) {
349 proto = OFONO_GPRS_PROTO_IPV6;
350 } else if (g_strcmp0(protocol, "IPV4V6") == 0) {
351 proto = OFONO_GPRS_PROTO_IPV4V6;
352 } else {
353 ofono_error("%s: APN %s has invalid protocol=%s"
354 "attribute", __func__, carrier,
355 protocol);
356 return;
357 }
358 }
359
360 if (mvnotype != NULL && mvnomatch != NULL) {
361
362 if (g_strcmp0(mvnotype, "imsi") == 0) {
363 DBG("APN %s is mvno_type 'imsi'", carrier);
364
365 if (apndb->match_imsi == NULL ||
366 imsi_match(apndb->match_imsi,
367 mvnomatch) == FALSE) {
368 DBG("Skipping MVNO 'imsi' APN %s with"
369 " match_data: %s", carrier, mvnomatch);
370 return;
371 }
372 } else if (g_strcmp0(mvnotype, "spn") == 0) {
373 DBG("APN %s is mvno_type 'spn'", carrier);
374
375 if (g_strcmp0(mvnomatch, apndb->match_spn) != 0) {
376 DBG("Skipping mvno 'spn' APN %s with"
377 " match_data: %s", carrier, mvnomatch);
378 return;
379 }
380
381 } else if (g_strcmp0(mvnotype, "gid") == 0) {
382 int match_len = strlen(mvnomatch);
383
384 DBG("APN %s is mvno_type 'gid'", carrier);
385
386 /* Check initial part of GID1 against match data */
387 if (apndb->match_gid1 == NULL ||
388 g_ascii_strncasecmp(mvnomatch,
389 apndb->match_gid1,
390 match_len) != 0) {
391 DBG("Skipping mvno 'gid' APN %s with"
392 " match_data: %s", carrier, mvnomatch);
393 return;
394 }
395 }
396 }
397
398 type = determine_apn_type(types);
399
400 if (type == OFONO_GPRS_CONTEXT_TYPE_ANY ||
401 (type == OFONO_GPRS_CONTEXT_TYPE_MMS && mmsproxy == NULL)) {
402 DBG("Skipping %s context; types: %s", apn, types);
403 return;
404 }
405
406 ap = g_try_new0(struct apndb_provision_data, 1);
407 if (ap == NULL) {
408 ofono_error("%s: out-of-memory trying to provision APN - %s",
409 __func__, carrier);
410 return;
411 }
412
413 ap->gprs_data.type = type;
414
415 if (carrier != NULL)
416 ap->gprs_data.name = g_strdup(carrier);
417
418 if (apn != NULL)
419 ap->gprs_data.apn = g_strdup(apn);
420
421 if (username != NULL)
422 ap->gprs_data.username = g_strdup(username);
423
424 if (password != NULL)
425 ap->gprs_data.password = g_strdup(password);
426
427 if (mmscenter != NULL && strlen(mmscenter) > 0)
428 ap->gprs_data.message_center = g_strdup(mmscenter);
429
430 if (mmsproxy != NULL && strlen(mmsproxy) > 0) {
431 char *tmp = ubuntu_apndb_sanitize_ipv4_address(mmsproxy);
432 if (tmp != NULL)
433 mmsproxy = tmp;
434
435 if (mmsport != NULL)
436 ap->gprs_data.message_proxy =
437 g_strdup_printf("%s:%s", mmsproxy, mmsport);
438 else
439 ap->gprs_data.message_proxy = g_strdup(mmsproxy);
440
441 g_free(tmp);
442 }
443
444 ap->gprs_data.proto = proto;
445
446 if (mvnotype != NULL) {
447 ap->mvno = TRUE;
448 apndb->mvno_found = TRUE;
449 }
450
451 apndb->apns = g_slist_append(apndb->apns, ap);
452}
453
454static void toplevel_apndb_end(GMarkupParseContext *context,
455 const gchar *element_name,
456 gpointer userdata, GError **error)
457{
458}
459
460static const GMarkupParser toplevel_apndb_parser = {
461 toplevel_apndb_start,
462 toplevel_apndb_end,
463 NULL,
464 NULL,
465 NULL,
466};
467
468static gboolean ubuntu_apndb_parse(const GMarkupParser *parser,
469 gpointer userdata,
470 const char *apndb_path,
471 GError **error)
472{
473 struct stat st;
474 char *db;
475 int fd;
476 GMarkupParseContext *context;
477 gboolean ret;
478
479 fd = open(apndb_path, O_RDONLY);
480 if (fd < 0) {
481 g_set_error(error, G_FILE_ERROR,
482 g_file_error_from_errno(errno),
483 "open(%s) failed: %s", apndb_path,
484 g_strerror(errno));
485 return FALSE;
486 }
487
488 if (fstat(fd, &st) < 0) {
489 close(fd);
490 g_set_error(error, G_FILE_ERROR,
491 g_file_error_from_errno(errno),
492 "fstat(%s) failed: %s", apndb_path,
493 g_strerror(errno));
494 return FALSE;
495 }
496
497 db = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
498 if (db == MAP_FAILED) {
499 close(fd);
500 g_set_error(error, G_FILE_ERROR,
501 g_file_error_from_errno(errno),
502 "mmap(%s) failed: %s", apndb_path,
503 g_strerror(errno));
504 return FALSE;
505 }
506
507 context = g_markup_parse_context_new(parser,
508 G_MARKUP_TREAT_CDATA_AS_TEXT,
509 userdata, NULL);
510
511 ret = g_markup_parse_context_parse(context, db, st.st_size, error);
512
513 if (ret == TRUE)
514 g_markup_parse_context_end_parse(context, error);
515
516 munmap(db, st.st_size);
517 close(fd);
518 g_markup_parse_context_free(context);
519
520 return ret;
521}
522
523GSList *ubuntu_apndb_lookup_apn(const char *mcc, const char *mnc,
524 const char *spn, const char *imsi, const char *gid1,
525 GError **error)
526{
527 struct apndb_data apndb = { NULL };
528 struct apndb_data custom_apndb = { NULL };
529 const char *apndb_path;
530 GSList *merged_apns;
531
532 /*
533 * Lookup /custom apns first, if mvno apns found,
534 * strip non-mvno apns from list
535 *
536 * Lookup /system next, apply same mvno logic...
537 *
538 * Merge both lists, any custom apns that match the type
539 * and apn fields of a /system apn replace it.
540 */
541
542 custom_apndb.match_mcc = mcc;
543 custom_apndb.match_mnc = mnc;
544 custom_apndb.match_spn = spn;
545 custom_apndb.match_imsi = imsi;
546 custom_apndb.match_gid1 = gid1;
547
548 if ((apndb_path = getenv("OFONO_CUSTOM_APNDB_PATH")) == NULL)
549 apndb_path = CUSTOM_APNDB_PATH;
550
551 if (ubuntu_apndb_parse(&toplevel_apndb_parser, &custom_apndb,
552 apndb_path,
553 error) == FALSE) {
554 g_slist_free_full(custom_apndb.apns, ubuntu_apndb_ap_free);
555 custom_apndb.apns = NULL;
556
557 if (*error) {
558 if ((*error)->domain != G_FILE_ERROR)
559 ofono_error("%s: custom apn_lookup error -%s",
560 __func__, (*error)->message);
561
562 g_error_free(*error);
563 *error = NULL;
564 }
565 }
566
567 if (custom_apndb.apns && custom_apndb.mvno_found)
568 strip_non_mvno_apns(&custom_apndb.apns);
569
570 DBG("custom_apndb: found '%d' APNs", g_slist_length(custom_apndb.apns));
571
572 apndb.match_mcc = mcc;
573 apndb.match_mnc = mnc;
574 apndb.match_spn = spn;
575 apndb.match_imsi = imsi;
576 apndb.match_gid1 = gid1;
577
578 if ((apndb_path = getenv("OFONO_SYSTEM_APNDB_PATH")) == NULL)
579 apndb_path = SYSTEM_APNDB_PATH;
580
581 if (ubuntu_apndb_parse(&toplevel_apndb_parser, &apndb,
582 apndb_path,
583 error) == FALSE) {
584 g_slist_free_full(apndb.apns, ubuntu_apndb_ap_free);
585 apndb.apns = NULL;
586 }
587
588 DBG("apndb: found '%d' APNs", g_slist_length(apndb.apns));
589
590 if (apndb.apns && apndb.mvno_found)
591 strip_non_mvno_apns(&apndb.apns);
592
593 merged_apns = merge_apn_lists(custom_apndb.apns, apndb.apns);
594
595 return merged_apns;
596}
0597
=== added file 'plugins/ubuntu-apndb.h'
--- plugins/ubuntu-apndb.h 1970-01-01 00:00:00 +0000
+++ plugins/ubuntu-apndb.h 2014-07-21 18:55:43 +0000
@@ -0,0 +1,33 @@
1/*
2 *
3 * ofono - Open Source Telephony
4 *
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
6 * 2013 Simon Busch <morphis@gravedo.de>
7 * Copyright (C) 2014 Canonical Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24struct apndb_provision_data {
25 struct ofono_gprs_provision_data gprs_data;
26 gboolean mvno;
27};
28
29void ubuntu_apndb_ap_free(gpointer data);
30
31GSList *ubuntu_apndb_lookup_apn(const char *mcc, const char *mnc,
32 const char *spn, const char *imsi, const char *gid1,
33 GError **error);
034
=== added file 'plugins/ubuntu-provision.c'
--- plugins/ubuntu-provision.c 1970-01-01 00:00:00 +0000
+++ plugins/ubuntu-provision.c 2014-07-21 18:55:43 +0000
@@ -0,0 +1,150 @@
1/*
2 *
3 * oFono - Open Source Telephony
4 *
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
6 * 2013 Simon Busch <morphis@gravedo.de>
7 * Copyright (C) 2014 Canonical Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <errno.h>
29#include <stdlib.h>
30#include <string.h>
31
32#include <glib.h>
33
34#define OFONO_API_SUBJECT_TO_CHANGE
35#include <ofono/types.h>
36#include <ofono/log.h>
37#include <ofono/plugin.h>
38#include <ofono/modem.h>
39#include <ofono/gprs-provision.h>
40
41#include "ubuntu-apndb.h"
42#include "mbpi.h"
43
44static int provision_get_settings(const char *mcc, const char *mnc,
45 const char *spn,
46 const char *imsi, const char *gid1,
47 struct ofono_gprs_provision_data **settings,
48 int *count)
49{
50 GSList *apns = NULL;
51 GSList *l = NULL;
52 GError *error = NULL;
53 unsigned int i;
54 char *tmp;
55 int retval = 0;
56
57 if ((tmp = getenv("OFONO_CUSTOM_MCC")) != NULL)
58 mcc = tmp;
59
60 if ((tmp = getenv("OFONO_CUSTOM_MNC")) != NULL)
61 mnc = tmp;
62
63 if ((tmp = getenv("OFONO_CUSTOM_SPN")) != NULL)
64 spn = tmp;
65
66 if ((tmp = getenv("OFONO_CUSTOM_IMSI")) != NULL)
67 imsi = tmp;
68
69 if ((tmp = getenv("OFONO_CUSTOM_GID1")) != NULL)
70 gid1 = tmp;
71
72 ofono_info("Provisioning for MCC %s, MNC %s, SPN '%s', IMSI '%s', "
73 "GID1 '%s'", mcc, mnc, spn, imsi, gid1);
74
75 apns = ubuntu_apndb_lookup_apn(mcc, mnc, spn, imsi, gid1, &error);
76 if (apns == NULL) {
77 if (error != NULL) {
78 ofono_error("%s: apndb_lookup error -%s for mcc %s"
79 " mnc %s spn %s imsi %s", __func__,
80 error->message, mcc, mnc, spn, imsi);
81 g_error_free(error);
82 error = NULL;
83 }
84 }
85
86 *count = g_slist_length(apns);
87
88 DBG("ap_count: '%d'", *count);
89
90 if (*count == 0) {
91 ofono_error("%s: provisioning failed - no APNs found.",
92 __func__);
93
94 retval = -1;
95 goto done;
96 }
97
98 *settings = g_try_new0(struct ofono_gprs_provision_data, *count);
99 if (*settings == NULL) {
100 ofono_error("%s: provisioning failed: out-of-memory", __func__);
101
102 g_slist_free_full(apns, ubuntu_apndb_ap_free);
103
104 *count = 0;
105 return -ENOMEM;
106 }
107
108 for (l = apns, i = 0; l; l = l->next, i++) {
109 struct apndb_provision_data *ap = l->data;
110
111 DBG("Name: '%s'", ap->gprs_data.name);
112 DBG("APN: '%s'", ap->gprs_data.apn);
113 DBG("Type: %s", mbpi_ap_type(ap->gprs_data.type));
114 DBG("Username: '%s'", ap->gprs_data.username);
115 DBG("Password: '%s'", ap->gprs_data.password);
116 DBG("Message Proxy: '%s'", ap->gprs_data.message_proxy);
117 DBG("Message Center: '%s'", ap->gprs_data.message_center);
118 DBG("MVNO: %u", ap->mvno);
119
120 memcpy(*settings + i, &ap->gprs_data, sizeof(ap->gprs_data));
121
122 g_free(ap);
123 }
124
125done:
126 if (apns != NULL)
127 g_slist_free(apns);
128
129 return retval;
130}
131
132static struct ofono_gprs_provision_driver ubuntu_provision_driver = {
133 .name = "Ubuntu APN database Provisioning",
134 .get_settings = provision_get_settings
135};
136
137static int ubuntu_provision_init(void)
138{
139 return ofono_gprs_provision_driver_register(&ubuntu_provision_driver);
140}
141
142static void ubuntu_provision_exit(void)
143{
144 ofono_gprs_provision_driver_unregister(&ubuntu_provision_driver);
145}
146
147OFONO_PLUGIN_DEFINE(ubuntu_provision,
148 "Ubuntu APN database Provisioning Plugin", VERSION,
149 OFONO_PLUGIN_PRIORITY_DEFAULT,
150 ubuntu_provision_init, ubuntu_provision_exit)
0151
=== modified file 'test/rilmodem/test-sim-online'
--- test/rilmodem/test-sim-online 2014-06-24 18:59:26 +0000
+++ test/rilmodem/test-sim-online 2014-07-21 18:55:43 +0000
@@ -193,7 +193,8 @@
193 assert properties["Model"] == "Fake Modem Model"193 assert properties["Model"] == "Fake Modem Model"
194 assert properties["Type"] == "hardware"194 assert properties["Type"] == "hardware"
195195
196 assert properties["Serial"] == "000000000000000"196 if args.emulator:
197 assert properties["Serial"] == "000000000000000"
197198
198 assert properties["Manufacturer"] == "Fake Manufacturer"199 assert properties["Manufacturer"] == "Fake Manufacturer"
199200
200201
=== modified file 'unit/test-grilreply.c'
--- unit/test-grilreply.c 2014-05-13 01:21:09 +0000
+++ unit/test-grilreply.c 2014-07-21 18:55:43 +0000
@@ -79,6 +79,12 @@
79 const struct ril_msg msg;79 const struct ril_msg msg;
80};80};
8181
82struct oem_hook_raw_test {
83 const unsigned char *data;
84 int size;
85 const struct ril_msg msg;
86};
87
82/* Invalid RIL_REQUEST_DATA_REGISTRATION_STATE: buffer too small */88/* Invalid RIL_REQUEST_DATA_REGISTRATION_STATE: buffer too small */
83static const struct ril_msg reply_data_reg_state_invalid_1 = {89static const struct ril_msg reply_data_reg_state_invalid_1 = {
84 .buf = "XYZ",90 .buf = "XYZ",
@@ -1451,6 +1457,49 @@
1451 }1457 }
1452};1458};
14531459
1460/*
1461 * The following structure contains test data for a valid
1462 * RIL_REQUEST_OEM_HOOK_RAW reply with parameter {4,0x11111111}
1463 */
1464static const guchar reply_oem_hook_raw_valid_parcel1[] = {
1465 0x04, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11
1466};
1467
1468static const struct oem_hook_raw_test reply_oem_hook_raw_valid_1 = {
1469 .data = reply_oem_hook_raw_valid_parcel1 + sizeof(int32_t),
1470 .size = (int) (sizeof(reply_oem_hook_raw_valid_parcel1)
1471 - sizeof(int32_t)),
1472 .msg = {
1473 .buf = (gchar *) reply_oem_hook_raw_valid_parcel1,
1474 .buf_len = sizeof(reply_oem_hook_raw_valid_parcel1),
1475 .unsolicited = FALSE,
1476 .req = RIL_REQUEST_OEM_HOOK_RAW,
1477 .serial_no = 0,
1478 .error = RIL_E_SUCCESS,
1479 }
1480};
1481
1482/*
1483 * The following structure contains test data for a valid
1484 * RIL_REQUEST_OEM_HOOK_RAW reply with parameter {-1}
1485 */
1486static const guchar reply_oem_hook_raw_valid_parcel2[] = {
1487 0xFF, 0xFF, 0xFF, 0xFF
1488};
1489
1490static const struct oem_hook_raw_test reply_oem_hook_raw_valid_2 = {
1491 .data = NULL,
1492 .size = -1,
1493 .msg = {
1494 .buf = (gchar *) reply_oem_hook_raw_valid_parcel2,
1495 .buf_len = sizeof(reply_oem_hook_raw_valid_parcel2),
1496 .unsolicited = FALSE,
1497 .req = RIL_REQUEST_OEM_HOOK_RAW,
1498 .serial_no = 0,
1499 .error = RIL_E_SUCCESS,
1500 }
1501};
1502
1454static void test_reply_reg_state_invalid(gconstpointer data)1503static void test_reply_reg_state_invalid(gconstpointer data)
1455{1504{
1456 struct reply_reg_state *reply = g_ril_reply_parse_reg_state(NULL, data);1505 struct reply_reg_state *reply = g_ril_reply_parse_reg_state(NULL, data);
@@ -1669,6 +1718,19 @@
1669 g_free(retries);1718 g_free(retries);
1670}1719}
16711720
1721static void test_reply_oem_hook_raw_valid(gconstpointer data)
1722{
1723 const struct oem_hook_raw_test *test = data;
1724 struct reply_oem_hook *reply =
1725 g_ril_reply_oem_hook_raw(NULL, &test->msg);
1726
1727 g_assert(reply->length == test->size);
1728 if (reply->length >= 0)
1729 g_assert(!memcmp(reply->data, test->data, test->size));
1730 else
1731 g_assert(reply->data == NULL);
1732}
1733
1672#endif1734#endif
16731735
1674int main(int argc, char **argv)1736int main(int argc, char **argv)
@@ -1958,6 +2020,16 @@
1958 &reply_enter_sim_pin_valid_2,2020 &reply_enter_sim_pin_valid_2,
1959 test_reply_enter_sim_pin_valid);2021 test_reply_enter_sim_pin_valid);
19602022
2023 g_test_add_data_func("/testgrilreply/oem: "
2024 "valid OEM_HOOK_RAW Test 1",
2025 &reply_oem_hook_raw_valid_1,
2026 test_reply_oem_hook_raw_valid);
2027
2028 g_test_add_data_func("/testgrilreply/oem: "
2029 "valid OEM_HOOK_RAW Test 2",
2030 &reply_oem_hook_raw_valid_2,
2031 test_reply_oem_hook_raw_valid);
2032
1961#endif2033#endif
19622034
1963 return g_test_run();2035 return g_test_run();
19642036
=== modified file 'unit/test-grilrequest.c'
--- unit/test-grilrequest.c 2014-06-24 18:59:26 +0000
+++ unit/test-grilrequest.c 2014-07-21 18:55:43 +0000
@@ -790,6 +790,37 @@
790 .parcel_size = sizeof(req_change_barring_password_valid_1),790 .parcel_size = sizeof(req_change_barring_password_valid_1),
791};791};
792792
793/* oem_hook_raw tests */
794
795struct request_test_oem_hook_raw_data {
796 const guchar *data;
797 gsize size;
798 const guchar *parcel_data;
799 gsize parcel_size;
800};
801
802static const guchar req_oem_hook_raw_valid_1[] = {
803 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
804};
805
806static const struct request_test_oem_hook_raw_data oem_hook_raw_valid_test_1 = {
807 .data = req_oem_hook_raw_valid_1 + sizeof(int32_t),
808 .size = sizeof(req_oem_hook_raw_valid_1) - sizeof(int32_t),
809 .parcel_data = (guchar *) &req_oem_hook_raw_valid_1,
810 .parcel_size = sizeof(req_oem_hook_raw_valid_1),
811};
812
813static const guchar req_oem_hook_raw_valid_2[] = {
814 0xFF, 0xFF, 0xFF, 0xFF
815};
816
817static const struct request_test_oem_hook_raw_data oem_hook_raw_valid_test_2 = {
818 .data = NULL,
819 .size = 0,
820 .parcel_data = (guchar *) &req_oem_hook_raw_valid_2,
821 .parcel_size = sizeof(req_oem_hook_raw_valid_2),
822};
823
793/*824/*
794 * The following hexadecimal data represents a serialized Binder parcel825 * The following hexadecimal data represents a serialized Binder parcel
795 * instance containing a valid RIL_REQUEST_RADIO_POWER 'OFF' message.826 * instance containing a valid RIL_REQUEST_RADIO_POWER 'OFF' message.
@@ -1322,6 +1353,21 @@
13221353
1323 parcel_free(&rilp);1354 parcel_free(&rilp);
1324}1355}
1356
1357static void test_request_oem_hook_raw(gconstpointer data)
1358{
1359 const struct request_test_oem_hook_raw_data *test_data = data;
1360 struct parcel rilp;
1361
1362 g_ril_request_oem_hook_raw(NULL, test_data->data,
1363 test_data->size, &rilp);
1364
1365 g_assert(!memcmp(rilp.data, test_data->parcel_data,
1366 test_data->parcel_size));
1367
1368 parcel_free(&rilp);
1369}
1370
1325#endif1371#endif
13261372
1327int main(int argc, char **argv)1373int main(int argc, char **argv)
@@ -1571,6 +1617,16 @@
1571 &change_barring_password_valid_test_1,1617 &change_barring_password_valid_test_1,
1572 test_request_change_barring_password);1618 test_request_change_barring_password);
15731619
1620 g_test_add_data_func("/testgrilrequest/oem-hook-raw: "
1621 "valid OEM_HOOK_RAW Test 1",
1622 &oem_hook_raw_valid_test_1,
1623 test_request_oem_hook_raw);
1624
1625 g_test_add_data_func("/testgrilrequest/oem-hook-raw: "
1626 "valid OEM_HOOK_RAW Test 2",
1627 &oem_hook_raw_valid_test_2,
1628 test_request_oem_hook_raw);
1629
1574#endif1630#endif
1575 return g_test_run();1631 return g_test_run();
1576}1632}

Subscribers

People subscribed via source and target branches

to all changes: