Merge lp:~awe/phablet-extras/ofono-gprs-support into lp:phablet-extras/ofono

Proposed by Tony Espy
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 66
Merged at revision: 37
Proposed branch: lp:~awe/phablet-extras/ofono-gprs-support
Merge into: lp:phablet-extras/ofono
Diff against target: 2469 lines (+1530/-257)
18 files modified
Makefile.am (+2/-0)
debian/changelog (+4/-0)
drivers/rilmodem/gprs-context.c (+548/-0)
drivers/rilmodem/gprs.c (+276/-0)
drivers/rilmodem/network-registration.c (+3/-5)
drivers/rilmodem/rilmodem.c (+7/-1)
drivers/rilmodem/rilmodem.h (+6/-0)
drivers/rilmodem/rilutil.c (+309/-88)
drivers/rilmodem/rilutil.h (+51/-1)
drivers/rilmodem/sim.c (+132/-20)
drivers/rilmodem/voicecall.c (+0/-2)
gril/gril.c (+64/-94)
gril/grilutil.c (+60/-36)
gril/grilutil.h (+1/-0)
gril/parcel.c (+16/-6)
gril/ril_constants.h (+20/-0)
plugins/provision.c (+6/-1)
plugins/ril.c (+25/-3)
To merge this branch: bzr merge lp:~awe/phablet-extras/ofono-gprs-support
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+166294@code.launchpad.net

Commit message

[rilmodem] Initial GPRS support.

Description of the change

This change adds basic GPRS support to our ofono/rilmodem code.

New source files in drivers/rilmodem include gprs.c and gprs-context.c.

In addition to the GPRS changes, some re-factoring of the debug logging code is also present in this MP. This includes removal of some of the low-level /gril log calls ( which have been commented out and marked as TODO: make conditional ), and addition of RIL message logging which mimics the logging done by the native RIL code. This latter change has not been 100% implemented yet, however it was critical to getting the GPRS code to work.

This code has been tested on maguro and mako, using an AT&T SIM in the US.

Testing requires installation of the python test scripts bundled with oFono. Sergio is working on packaging these scripts into a stand-alone package. For now they can be copied to the phone ( note, they require the additional package python-dbus ).

To test:

1. Run list-contexts to see the existing contexts.

2. Use activate-context to activate 3g. If multiple contexts exist, you may need to specify a 0-based index to tell oFono to use the correct context.

3. Use list-contexts to see the settings returned by RILD for the data call.

4. Use ifconfig to confirm that the interface has been correctly setup ( rmnet0 or rmnet_usb0 depending on the phone ).

5. On both phones, you'll need to manually configured DNS. My shortcut is just:

# echo "nameserver 8.8.8.8" > /etc/resolv.conf

6. On maguro, the default route is not configured by default; that said, you should see the network route ( use netstat -rn to see the routing table ). To configured the default route, run the following command:

# route add default gw <gateway-address> <iface-name>

6. To disable the connection, run deactivate-context

Note, sometimes it take awhile for GPRS to be attached. If you try to activate the context while !attached, activate-context will return an error. You can use the list-modems command to examine the ConnectionManager properties ( one of which is 'Attached' ).

A couple of other comments:

 * No disconnect nor suspend testing has yet been done.

 * Data roaming is disabled by default, and is not yet implemented.

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

[rilmodem] Get rid of unused gprs_context_data vendor field.

57. By Tony Espy

[rilmodem] Get rid of unused gprs_data vendor field.

58. By Tony Espy

[rilmodem] Add comments explaining lack of usage of core gprs suspend/resume/bearer functions.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Tony Espy (awe) wrote :

I just re-factored the DATA_CALL response code based on feedback from cyphermox:

1. The code that calculates netmasks has been moved to rilutil, so that it can be unit-tested ( TODO ).

2. The code now handles multiple IP address and/or gateways returned from RILD in a more graceful manner, in that it splits the addresses, and only hands the first address and gateway to the core ofono code ( which only handles single IP addresses and gateways ).

3. The code now strips IP address prefixes, as NM doesn't handle them properly.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :
Download full text (3.7 KiB)

91 +static char printBuf[PRINTBUF_SIZE];

574 +static char printBuf[PRINTBUF_SIZE];

910 +static char printBuf[PRINTBUF_SIZE];

2390 +static char printBuf[PRINTBUF_SIZE];

Do we really need a global string? Would avoid calling clear.

1467 + * $AOSP/hardware/ril/libril/ril.cpp
1468 + */
1469 +#define startRequest sprintf(printBuf, "(")
1470 +#define closeRequest sprintf(printBuf, "%s)", printBuf)
1471 +#define printRequest(token, req) \
1472 + ofono_debug("[%04d]> %s %s", token, ril_request_id_to_string(req), printBuf)
1473 +
1474 +#define startResponse sprintf(printBuf, "%s {", printBuf)
1475 +#define closeResponse sprintf(printBuf, "%s}", printBuf)
1476 +#define printResponse ofono_debug("%s", printBuf)
1477 +
1478 +#define clearPrintBuf printBuf[0] = 0
1479 +#define removeLastChar printBuf[strlen(printBuf)-1] = 0
1480 +#define appendPrintBuf(x...) sprintf(printBuf, x)

91 +static char printBuf[PRINTBUF_SIZE];

Coding style here might be an issue when pushing this code upstream. I'd guess it'd be better to use print_buf instead.

114 + if (message->buf_len < 36) {
115 + DBG("Parcel is less then minimum DataCallResponseV6 size!");

Missing "decode_ril_error(&error, "FAIL");".

126 + /* TODO: make conditional */
127 + appendPrintBuf("[%04d]< %s",
128 + message->serial_no,
129 + ril_request_id_to_string(message->req));
130 + startResponse;
131 + /* TODO: make conditional */

Mind moving this code a bit bellow so it can be near the rest of the append/close/print logic? Otherwise it's hard to track which message it's actually covering (in case of another message setup later).

135 + /* RIL version */
136 + version = parcel_r_int32(&rilp);
137 +
138 + /* Size of call list */
139 + /* TODO: What if there's more than 1 call in the list?? */
140 + num = parcel_r_int32(&rilp);

Isn't the reply just a RIL_Data_Call_Response_v6 struct? If so, mind adding a comment saying that the version and num arguments were not described correctly by the Android ril.h file?

175 + if (status != 0) {
176 + DBG("Reply failure; status %d", status);
177 + gcd->state = STATE_IDLE;
178 + goto error;
179 + }

203 + if (ip_addrs[0] == NULL) {
204 + DBG("Invalid IP address field returned: %s", raw_ip_addrs);
205 + goto error;
206 + }

217 + if (split_ip_addr[0] == NULL) {
218 + ofono_error("Invalid IP address; can't strip prefix: %s",
219 + ip_addrs[0]);
220 + goto error;
221 + }

230 + if (gateways[0] == NULL) {
231 + DBG("Invalid gateways field returned: %s", raw_gws);
232 + goto error;
233 + }

Don't you also need to update error.error here?

Also, in case of error, we're not releasing any of the strings allocated with parcel_r_string (your code just free them in case it all works).

266 + guchar profile[5] = { 0x00 };

Not used.

329 + DBG("Invalid protocol");

Mind doing a better error message here? Otherwise it will be hard to get from the ofono log.

334 + appendPrintBuf("%s %s,%s,%s,%s,%s,%s,%s",
335 + printBuf,
336 + tech,
337 + DATA_PROFILE_DEFAULT,
338 + ctx->apn,
339 + ctx->username,
340 + ctx->password,
341 + CHAP_PAP_OK,
342 + protocol);
343 +
344 + ret = g_ril_send(gcd->ril,
345 + request,
346 + rilp.data,
347 + rilp.size,
348 + ril_setup_data_call_cb, cbd, g_...

Read more...

59. By Tony Espy

[rilmodem] Move DATA_CALL_LIST code from gprs to gprs-context.

60. By Tony Espy

[rilmodem] Re-merge from trunk.

61. By Tony Espy

[rilmodem] Added code to detect disconnects based on updated DATA_CALL_LIST.

62. By Tony Espy

Re-merge from trunk

63. By Tony Espy

[rilmodem] Re-factored debug trace code, and some error logic based on review comments.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

30 - [ Tony Espy ]

Don't need to change previous changelog entries.

Rest looks fine, will test it more and happrove it tomorrow.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Tony Espy (awe) wrote :

Fixed the changelog.

I've tested on maguro and mako and data, voice and SMS all work as advertised.

Still little to no mileage on the disconnect code unfortunately.

Also seeing problems on both systems with deactivate-context, including a segfault ( looks like a day-one bug ) after deactivating and then trying to send an SMS from the device.

64. By Tony Espy

Restore mangled debian/changelog.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
65. By Tony Espy

Another re-merge from trunk.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
66. By Tony Espy

[rilmodem] Updated DATA_CALL_LIST disconnect logic.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

All good, thanks for the hard work.

review: Approve

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 2013-04-11 19:32:47 +0000
3+++ Makefile.am 2013-05-31 21:04:26 +0000
4@@ -120,6 +120,8 @@
5 drivers/rilmodem/network-registration.c \
6 drivers/rilmodem/voicecall.c \
7 drivers/rilmodem/call-volume.c \
8+ drivers/rilmodem/gprs.c \
9+ drivers/rilmodem/gprs-context.c \
10 drivers/rilmodem/sim.c \
11 drivers/rilmodem/sms.c \
12 drivers/rilmodem/rilutil.c \
13
14=== modified file 'debian/changelog'
15--- debian/changelog 2013-05-30 20:11:44 +0000
16+++ debian/changelog 2013-05-31 21:04:26 +0000
17@@ -1,5 +1,9 @@
18 ofono (1.12phablet3) UNRELEASED; urgency=low
19
20+ [ Tony Espy ]
21+ * [ril/rilmodem] Initial support for mobile data (GPRS).
22+
23+ [ Sergio Schvezov ]
24 * Adding test and maintenance scripts ofono-scripts binary package.
25
26 -- Sergio Schvezov <sergio.schvezov@canonical.com> Thu, 30 May 2013 17:10:33 -0300
27
28=== added file 'drivers/rilmodem/gprs-context.c'
29--- drivers/rilmodem/gprs-context.c 1970-01-01 00:00:00 +0000
30+++ drivers/rilmodem/gprs-context.c 2013-05-31 21:04:26 +0000
31@@ -0,0 +1,548 @@
32+/*
33+ *
34+ * oFono - Open Source Telephony
35+ *
36+ * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
37+ * Copyright (C) 2013 Canonical Ltd.
38+ *
39+ * This program is free software; you can redistribute it and/or modify
40+ * it under the terms of the GNU General Public License version 2 as
41+ * published by the Free Software Foundation.
42+ *
43+ * This program is distributed in the hope that it will be useful,
44+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
45+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46+ * GNU General Public License for more details.
47+ *
48+ * You should have received a copy of the GNU General Public License
49+ * along with this program; if not, write to the Free Software
50+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
51+ *
52+ */
53+
54+#ifdef HAVE_CONFIG_H
55+#include <config.h>
56+#endif
57+
58+#define _GNU_SOURCE
59+#include <string.h>
60+#include <stdlib.h>
61+#include <stdio.h>
62+#include <errno.h>
63+#include <sys/stat.h>
64+
65+#include <glib.h>
66+
67+#include <ofono/log.h>
68+#include <ofono/modem.h>
69+#include <ofono/gprs-context.h>
70+#include <ofono/types.h>
71+
72+#include "gril.h"
73+#include "grilutil.h"
74+
75+#include "rilmodem.h"
76+
77+/* REQUEST_DEACTIVATE_DATA_CALL parameter values */
78+#define DEACTIVATE_DATA_CALL_NUM_PARAMS 2
79+#define DEACTIVATE_DATA_CALL_NO_REASON "0"
80+
81+/* REQUEST_SETUP_DATA_CALL parameter values */
82+#define SETUP_DATA_CALL_PARAMS 7
83+#define CHAP_PAP_OK "3"
84+#define DATA_PROFILE_DEFAULT "0"
85+#define PROTO_IP "IP"
86+#define PROTO_IPV6 "IPV6"
87+#define PROTO_IPV4V6 "IPV4V6"
88+
89+enum state {
90+ STATE_IDLE,
91+ STATE_ENABLING,
92+ STATE_DISABLING,
93+ STATE_ACTIVE,
94+};
95+
96+struct gprs_context_data {
97+ GRil *ril;
98+ unsigned int active_ctx_cid;
99+ unsigned int active_rild_cid;
100+ char username[OFONO_GPRS_MAX_USERNAME_LENGTH + 1];
101+ char password[OFONO_GPRS_MAX_PASSWORD_LENGTH + 1];
102+ enum state state;
103+};
104+
105+/* TODO: make conditional */
106+static char print_buf[PRINT_BUF_SIZE];
107+
108+static void ril_gprs_context_call_list_changed(struct ril_msg *message,
109+ gpointer user_data)
110+{
111+ struct ofono_gprs_context *gc = user_data;
112+ struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
113+ struct data_call *call = NULL;
114+ gboolean active_cid_found = FALSE;
115+ gboolean disconnect = FALSE;
116+ GSList *calls = NULL, *iterator = NULL;
117+
118+ DBG("");
119+
120+ if (message->req != RIL_UNSOL_DATA_CALL_LIST_CHANGED) {
121+ ofono_error("ril_gprs_update_calls: invalid message received %d",
122+ message->req);
123+ return;
124+ }
125+
126+ calls = ril_util_parse_data_call_list(message);
127+
128+ DBG("number of call in call_list_changed is: %d", g_slist_length(calls));
129+
130+ for (iterator = calls; iterator; iterator = iterator->next) {
131+ call = (struct data_call *) iterator->data;
132+
133+ if (call->cid == gcd->active_rild_cid) {
134+ DBG("Found current call in call list: %d", call->cid);
135+ active_cid_found = TRUE;
136+
137+ if (call->active == 0) {
138+ DBG("call->status is DISCONNECTED for cid: %d", call->cid);
139+ disconnect = TRUE;
140+ ofono_gprs_context_deactivated(gc, gcd->active_ctx_cid);
141+ }
142+
143+ break;
144+ }
145+ }
146+
147+ if (disconnect || active_cid_found == FALSE) {
148+ DBG("Clearing active context");
149+
150+ gcd->active_ctx_cid = -1;
151+ gcd->active_rild_cid = -1;
152+ gcd->state = STATE_IDLE;
153+ }
154+
155+ g_slist_foreach(calls, (GFunc) g_free, NULL);
156+ g_slist_free(calls);
157+}
158+
159+static void ril_setup_data_call_cb(struct ril_msg *message, gpointer user_data)
160+{
161+ struct cb_data *cbd = user_data;
162+ ofono_gprs_context_cb_t cb = cbd->cb;
163+ struct ofono_gprs_context *gc = cbd->user;
164+ struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
165+ struct ofono_error error;
166+ struct parcel rilp;
167+ int status, retry_time, cid, active, num, version;
168+ char *dnses = NULL, *ifname = NULL;
169+ char *raw_ip_addrs = NULL, *raw_gws = NULL, *type = NULL;
170+ char **dns_addresses = NULL, **gateways = NULL;
171+ char **ip_addrs = NULL, **split_ip_addr = NULL;
172+
173+ /* TODO:
174+ * Cleanup duplicate code between this function and
175+ * ril_util_parse_data_call_list().
176+ */
177+
178+ /* valid size: 36 (34 if HCRADIO defined) */
179+ if (message->buf_len < 36) {
180+ DBG("Parcel is less then minimum DataCallResponseV6 size!");
181+ decode_ril_error(&error, "FAIL");
182+ goto error;
183+ }
184+
185+ if (message->error != RIL_E_SUCCESS) {
186+ DBG("Reply failure: %s", ril_error_to_string(message->error));
187+ decode_ril_error(&error, "FAIL");
188+ error.error = message->error;
189+ goto error;
190+ }
191+
192+ ril_util_init_parcel(message, &rilp);
193+
194+ /*
195+ * ril.h documents the reply to a RIL_REQUEST_SETUP_DATA_CALL
196+ * as being a RIL_Data_Call_Response_v6 struct, however in
197+ * reality, the response actually includes the version of the
198+ * struct, followed by an array of calls, so the array size
199+ * also has to be read after the version.
200+ *
201+ * TODO: What if there's more than 1 call in the list??
202+ */
203+ version = parcel_r_int32(&rilp);
204+ num = parcel_r_int32(&rilp);
205+
206+ status = parcel_r_int32(&rilp);
207+ retry_time = parcel_r_int32(&rilp);
208+ cid = parcel_r_int32(&rilp);
209+ active = parcel_r_int32(&rilp);
210+
211+ type = parcel_r_string(&rilp);
212+ ifname = parcel_r_string(&rilp);
213+ raw_ip_addrs = parcel_r_string(&rilp);
214+ dnses = parcel_r_string(&rilp);
215+ raw_gws = parcel_r_string(&rilp);
216+
217+ /* TODO: make conditional */
218+ ril_append_print_buf("[%04d]< %s",
219+ message->serial_no,
220+ ril_request_id_to_string(message->req));
221+ ril_start_response;
222+
223+ ril_append_print_buf("%sversion=%d,num=%d",
224+ print_buf,
225+ version,
226+ num);
227+
228+ ril_append_print_buf("%s [status=%d,retry=%d,cid=%d,active=%d,type=%s,ifname=%s,address=%s,dns=%s,gateways=%s]",
229+ print_buf,
230+ status,
231+ retry_time,
232+ cid,
233+ active,
234+ type,
235+ ifname,
236+ raw_ip_addrs,
237+ dnses,
238+ raw_gws);
239+ ril_close_response;
240+ ril_print_response;
241+ /* TODO: make conditional */
242+
243+ if (status != 0) {
244+ DBG("Reply failure; status %d", status);
245+ gcd->state = STATE_IDLE;
246+ goto error;
247+ }
248+
249+ gcd->state = STATE_ACTIVE;
250+ gcd->active_rild_cid = cid;
251+
252+ ofono_gprs_context_set_interface(gc, ifname);
253+
254+ /*
255+ * TODO: re-factor the following code into a
256+ * ril_util function that can be unit-tested.
257+ */
258+
259+ /* TODO:
260+ * RILD can return multiple addresses; oFono only supports
261+ * setting a single IPv4 address. At this time, we only
262+ * use the first address. It's possible that a RIL may
263+ * just specify the end-points of the point-to-point
264+ * connection, in which case this code will need to
265+ * changed to handle such a device.
266+ *
267+ * For now split into a maximum of three, and only use
268+ * the first address for the remaining operations.
269+ */
270+ ip_addrs = g_strsplit(raw_ip_addrs, " ", 3);
271+ if (ip_addrs[0] == NULL) {
272+ DBG("No IP address specified: %s", raw_ip_addrs);
273+ decode_ril_error(&error, "FAIL");
274+ goto error;
275+ }
276+
277+ ofono_gprs_context_set_ipv4_netmask(gc,
278+ ril_util_get_netmask(ip_addrs[0]));
279+
280+ /*
281+ * Note - the address may optionally include a prefix size
282+ * ( Eg. "/30" ). As this confuses NetworkManager, we
283+ * explicitly strip any prefix after calculating the netmask.
284+ */
285+ split_ip_addr = g_strsplit(ip_addrs[0], "/", 2);
286+ if (split_ip_addr[0] == NULL) {
287+ DBG("Invalid IP address field returned: %s", raw_ip_addrs);
288+ decode_ril_error(&error, "FAIL");
289+ goto error;
290+ }
291+
292+ ofono_gprs_context_set_ipv4_address(gc, split_ip_addr[0], TRUE);
293+
294+ /*
295+ * RILD can return multiple addresses; oFono only supports
296+ * setting a single IPv4 gateway.
297+ */
298+ gateways = g_strsplit(raw_gws, " ", 3);
299+ if (gateways[0] == NULL) {
300+ DBG("Invalid gateways field returned: %s", raw_gws);
301+ decode_ril_error(&error, "FAIL");
302+ goto error;
303+ }
304+
305+ ofono_gprs_context_set_ipv4_gateway(gc, gateways[0]);
306+
307+ /* Split DNS addresses */
308+ dns_addresses = g_strsplit(dnses, " ", 3);
309+ ofono_gprs_context_set_ipv4_dns_servers(gc,
310+ (const char **) dns_addresses);
311+
312+ decode_ril_error(&error, "OK");
313+
314+error:
315+ g_strfreev(dns_addresses);
316+ g_strfreev(ip_addrs);
317+ g_strfreev(split_ip_addr);
318+ g_strfreev(gateways);
319+
320+ g_free(type);
321+ g_free(ifname);
322+ g_free(raw_ip_addrs);
323+ g_free(dnses);
324+ g_free(raw_gws);
325+
326+ cb(&error, cbd->data);
327+}
328+
329+static void ril_gprs_context_activate_primary(struct ofono_gprs_context *gc,
330+ const struct ofono_gprs_primary_context *ctx,
331+ ofono_gprs_context_cb_t cb, void *data)
332+{
333+ struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
334+ struct cb_data *cbd = cb_data_new(cb, data);
335+ struct parcel rilp;
336+ gchar *protocol = PROTO_IP;
337+ gchar tech[3];
338+ int request = RIL_REQUEST_SETUP_DATA_CALL;
339+ int ret;
340+
341+ cbd->user = gc;
342+ gcd->active_ctx_cid = ctx->cid;
343+ gcd->state = STATE_ENABLING;
344+
345+ memcpy(gcd->username, ctx->username, sizeof(ctx->username));
346+ memcpy(gcd->password, ctx->password, sizeof(ctx->password));
347+
348+ parcel_init(&rilp);
349+ parcel_w_int32(&rilp, SETUP_DATA_CALL_PARAMS);
350+
351+ /* RadioTech: hardcoded to HSPA for now... */
352+ sprintf((char *) tech, "%d", (int) RADIO_TECH_HSPA);
353+ DBG("setting tech to: %s", tech);
354+ parcel_w_string(&rilp, (char *) tech);
355+
356+ /*
357+ * TODO ( OEM/Tethering ): DataProfile:
358+ *
359+ * Other options are TETHERING (1) or OEM_BASE (1000).
360+ */
361+ parcel_w_string(&rilp, DATA_PROFILE_DEFAULT);
362+
363+ /* APN */
364+ parcel_w_string(&rilp, (char *) (ctx->apn));
365+
366+ if (ctx->username && strlen(ctx->username)) {
367+ parcel_w_string(&rilp, (char *) (ctx->username));
368+ } else {
369+ parcel_w_string(&rilp, NULL);
370+ }
371+
372+ if (ctx->password && strlen(ctx->password)) {
373+ parcel_w_string(&rilp, (char *) (ctx->password));
374+ } else {
375+ parcel_w_string(&rilp, NULL);
376+ }
377+
378+ /*
379+ * TODO: review with operators...
380+ * Auth type: PAP/CHAP may be performed
381+ */
382+ parcel_w_string(&rilp, CHAP_PAP_OK);
383+
384+ switch (ctx->proto) {
385+ case OFONO_GPRS_PROTO_IPV6:
386+ protocol = PROTO_IPV6;
387+ break;
388+ case OFONO_GPRS_PROTO_IPV4V6:
389+ protocol = PROTO_IPV4V6;
390+ break;
391+ case OFONO_GPRS_PROTO_IP:
392+ break;
393+ default:
394+ DBG("Invalid protocol: %d", ctx->proto);
395+ }
396+
397+ parcel_w_string(&rilp, protocol);
398+
399+ ret = g_ril_send(gcd->ril,
400+ request,
401+ rilp.data,
402+ rilp.size,
403+ ril_setup_data_call_cb, cbd, g_free);
404+
405+ /* TODO: make conditional */
406+ ril_start_request;
407+ ril_append_print_buf("%s %s,%s,%s,%s,%s,%s,%s",
408+ print_buf,
409+ tech,
410+ DATA_PROFILE_DEFAULT,
411+ ctx->apn,
412+ ctx->username,
413+ ctx->password,
414+ CHAP_PAP_OK,
415+ protocol);
416+
417+ ril_close_request;
418+ ril_print_request(ret, request);
419+ /* TODO: make conditional */
420+
421+ parcel_free(&rilp);
422+ if (ret <= 0) {
423+ ofono_error("Send RIL_REQUEST_SETUP_DATA_CALL failed.");
424+
425+ g_free(cbd);
426+ CALLBACK_WITH_FAILURE(cb, data);
427+ }
428+}
429+
430+static void ril_deactivate_data_call_cb(struct ril_msg *message, gpointer user_data)
431+{
432+ struct cb_data *cbd = user_data;
433+ ofono_gprs_context_cb_t cb = cbd->cb;
434+ struct ofono_gprs_context *gc = cbd->user;
435+ struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
436+ struct ofono_error error;
437+
438+ DBG("");
439+
440+ /* Reply has no data... */
441+ if (message->error == RIL_E_SUCCESS) {
442+
443+ /* TODO: make conditional */
444+ ril_append_print_buf("[%04d]< %s",
445+ message->serial_no,
446+ ril_request_id_to_string(message->req));
447+ ril_print_response;
448+ /* TODO: make conditional */
449+
450+ gcd->state = STATE_IDLE;
451+ CALLBACK_WITH_SUCCESS(cb, cbd->data);
452+
453+ } else {
454+ DBG("Reply failure: %s", ril_error_to_string(message->error));
455+
456+ decode_ril_error(&error, "FAIL");
457+ error.error = message->error;
458+
459+ cb(&error, cbd->data);
460+ }
461+}
462+
463+static void ril_gprs_context_deactivate_primary(struct ofono_gprs_context *gc,
464+ unsigned int id,
465+ ofono_gprs_context_cb_t cb, void *data)
466+{
467+ struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
468+ struct cb_data *cbd = cb_data_new(cb, data);
469+ struct parcel rilp;
470+ gchar *cid = NULL;
471+ int request = RIL_REQUEST_DEACTIVATE_DATA_CALL;
472+ int ret;
473+
474+ cbd->user = gc;
475+
476+ gcd->state = STATE_DISABLING;
477+
478+ parcel_init(&rilp);
479+ parcel_w_int32(&rilp, DEACTIVATE_DATA_CALL_NUM_PARAMS);
480+
481+ cid = g_strdup_printf("%d", gcd->active_rild_cid);
482+ parcel_w_string(&rilp, cid);
483+
484+ /*
485+ * TODO: airplane-mode; change reason to '1',
486+ * which means "radio power off".
487+ */
488+ parcel_w_string(&rilp, DEACTIVATE_DATA_CALL_NO_REASON);
489+
490+ ret = g_ril_send(gcd->ril,
491+ request,
492+ rilp.data,
493+ rilp.size,
494+ ril_deactivate_data_call_cb, cbd, g_free);
495+
496+ /* TODO: make conditional */
497+ ril_start_request;
498+ ril_append_print_buf("%s%s,0",
499+ print_buf,
500+ cid);
501+
502+ ril_close_request;
503+ ril_print_request(ret, request);
504+ /* TODO: make conditional */
505+
506+ parcel_free(&rilp);
507+ g_free(cid);
508+
509+ if (ret <= 0) {
510+ ofono_error("Send RIL_REQUEST_DEACTIVATE_DATA_CALL failed.");
511+ g_free(cbd);
512+ CALLBACK_WITH_FAILURE(cb, data);
513+ }
514+}
515+
516+static void ril_gprs_context_detach_shutdown(struct ofono_gprs_context *gc,
517+ unsigned int id)
518+{
519+ DBG("");
520+}
521+
522+static int ril_gprs_context_probe(struct ofono_gprs_context *gc,
523+ unsigned int vendor, void *data)
524+{
525+ GRil *ril = data;
526+ struct gprs_context_data *gcd;
527+
528+ DBG("");
529+
530+ gcd = g_try_new0(struct gprs_context_data, 1);
531+ if (gcd == NULL)
532+ return -ENOMEM;
533+
534+ gcd->ril = g_ril_clone(ril);
535+ gcd->active_ctx_cid = -1;
536+ gcd->active_rild_cid = -1;
537+ gcd->state = STATE_IDLE;
538+
539+ ofono_gprs_context_set_data(gc, gcd);
540+
541+ g_ril_register(gcd->ril, RIL_UNSOL_DATA_CALL_LIST_CHANGED,
542+ ril_gprs_context_call_list_changed, gc);
543+ return 0;
544+}
545+
546+static void ril_gprs_context_remove(struct ofono_gprs_context *gc)
547+{
548+ struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
549+
550+ DBG("");
551+
552+ if (gcd->state != STATE_IDLE) {
553+ /* TODO: call detach_shutdown */
554+ }
555+
556+ ofono_gprs_context_set_data(gc, NULL);
557+
558+ g_ril_unref(gcd->ril);
559+ g_free(gcd);
560+}
561+
562+static struct ofono_gprs_context_driver driver = {
563+ .name = "rilmodem",
564+ .probe = ril_gprs_context_probe,
565+ .remove = ril_gprs_context_remove,
566+ .activate_primary = ril_gprs_context_activate_primary,
567+ .deactivate_primary = ril_gprs_context_deactivate_primary,
568+ .detach_shutdown = ril_gprs_context_detach_shutdown,
569+};
570+
571+void ril_gprs_context_init(void)
572+{
573+ ofono_gprs_context_driver_register(&driver);
574+}
575+
576+void ril_gprs_context_exit(void)
577+{
578+ ofono_gprs_context_driver_unregister(&driver);
579+}
580
581=== added file 'drivers/rilmodem/gprs.c'
582--- drivers/rilmodem/gprs.c 1970-01-01 00:00:00 +0000
583+++ drivers/rilmodem/gprs.c 2013-05-31 21:04:26 +0000
584@@ -0,0 +1,276 @@
585+/*
586+ *
587+ * oFono - Open Source Telephony
588+ *
589+ * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
590+ * Copyright (C) 2010 ST-Ericsson AB.
591+ * Copyright (C) 2013 Canonical Ltd.
592+ *
593+ * This program is free software; you can redistribute it and/or modify
594+ * it under the terms of the GNU General Public License version 2 as
595+ * published by the Free Software Foundation.
596+ *
597+ * This program is distributed in the hope that it will be useful,
598+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
599+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
600+ * GNU General Public License for more details.
601+ *
602+ * You should have received a copy of the GNU General Public License
603+ * along with this program; if not, write to the Free Software
604+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
605+ *
606+ */
607+
608+#ifdef HAVE_CONFIG_H
609+#include <config.h>
610+#endif
611+
612+#define _GNU_SOURCE
613+#include <string.h>
614+#include <stdlib.h>
615+#include <stdio.h>
616+#include <errno.h>
617+
618+#include <glib.h>
619+
620+#include <ofono/log.h>
621+#include <ofono/modem.h>
622+#include <ofono/gprs.h>
623+#include <ofono/types.h>
624+
625+#include "gril.h"
626+#include "grilutil.h"
627+#include "common.h"
628+#include "rilmodem.h"
629+
630+/*
631+ * This module is the ofono_gprs_driver implementation for rilmodem.
632+ *
633+ * Notes:
634+ *
635+ * 1. ofono_gprs_suspend/resume() are not used by this module, as
636+ * the concept of suspended GPRS is not exposed by RILD.
637+ *
638+ * 2. ofono_gprs_bearer_notify() is never called as RILD does not
639+ * expose an unsolicited event equivalent to +CPSB ( see 27.007
640+ * 7.29 ), and the tech values returned by REQUEST_DATA/VOICE
641+ * _REGISTRATION requests do not match the values defined for
642+ * <AcT> in the +CPSB definition. Note, the values returned by
643+ * the *REGISTRATION commands are aligned with those defined by
644+ * +CREG ( see 27.003 7.2 ).
645+ */
646+
647+struct gprs_data {
648+ GRil *ril;
649+ int max_cids;
650+ int tech;
651+ int status;
652+};
653+
654+/* TODO: make conditional */
655+static char print_buf[PRINT_BUF_SIZE];
656+
657+static void ril_gprs_registration_status(struct ofono_gprs *gprs,
658+ ofono_gprs_status_cb_t cb,
659+ void *data);
660+
661+static void ril_gprs_state_change(struct ril_msg *message, gpointer user_data)
662+{
663+ struct ofono_gprs *gprs = user_data;
664+
665+ if (message->req != RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED) {
666+ ofono_error("ril_gprs_state_change: invalid message received %d",
667+ message->req);
668+ return;
669+ }
670+
671+ ril_gprs_registration_status(gprs, NULL, NULL);
672+}
673+
674+static void ril_gprs_set_pref_network_cb(struct ril_msg *message,
675+ gpointer user_data)
676+{
677+ if (message->error != RIL_E_SUCCESS) {
678+ ofono_error("SET_PREF_NETWORK reply failure: %s", ril_error_to_string(message->error));
679+ }
680+}
681+
682+static void ril_gprs_set_pref_network(struct ofono_gprs *gprs)
683+{
684+ struct gprs_data *gd = ofono_gprs_get_data(gprs);
685+ struct parcel rilp;
686+
687+ DBG("");
688+
689+ /*
690+ * TODO (OEM):
691+ *
692+ * The preferred network type may need to be set
693+ * on a device-specific basis. For now, we use
694+ * GSM_WCDMA which prefers WCDMA ( ie. HS* ) over
695+ * the base GSM.
696+ */
697+ parcel_init(&rilp);
698+ parcel_w_int32(&rilp, PREF_NET_TYPE_GSM_WCDMA);
699+
700+ if (g_ril_send(gd->ril, RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE,
701+ rilp.data, rilp.size, ril_gprs_set_pref_network_cb, NULL, NULL) <= 0) {
702+ ofono_error("Send RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE failed.");
703+ }
704+
705+ parcel_free(&rilp);
706+}
707+
708+static void ril_gprs_set_attached(struct ofono_gprs *gprs, int attached,
709+ ofono_gprs_cb_t cb, void *data)
710+{
711+ struct cb_data *cbd = cb_data_new(cb, data);
712+ struct ofono_error error;
713+
714+ DBG("");
715+
716+ decode_ril_error(&error, "OK");
717+
718+ /* This code should just call the callback with OK, and be done
719+ * there's no explicit RIL command to cause an attach.
720+ *
721+ * The core gprs code calls driver->set_attached() when a netreg
722+ * notificaiton is received and any configured roaming conditions
723+ * are met.
724+ */
725+
726+ cb(&error, cbd->data);
727+ g_free(cbd);
728+}
729+
730+static void ril_data_reg_cb(struct ril_msg *message, gpointer user_data)
731+{
732+ struct cb_data *cbd = user_data;
733+ ofono_gprs_status_cb_t cb = cbd->cb;
734+ struct ofono_gprs *gprs = cbd->user;
735+ struct gprs_data *gd = ofono_gprs_get_data(gprs);
736+ struct ofono_error error;
737+ int status, lac, ci, tech;
738+ int max_cids = 1;
739+
740+ if (message->error == RIL_E_SUCCESS) {
741+ decode_ril_error(&error, "OK");
742+ } else {
743+ ofono_error("ril_data_reg_cb: reply failure: %s",
744+ ril_error_to_string(message->error));
745+ decode_ril_error(&error, "FAIL");
746+ error.error = message->error;
747+ status = -1;
748+ goto error;
749+ }
750+
751+ if (ril_util_parse_reg(message, &status,
752+ &lac, &ci, &tech, &max_cids) == FALSE) {
753+ ofono_error("Failure parsing data registration response.");
754+ decode_ril_error(&error, "FAIL");
755+ status = -1;
756+ goto error;
757+ }
758+
759+ if (gd->status == -1) {
760+ DBG("calling ofono_gprs_register...");
761+ ofono_gprs_register(gprs);
762+
763+ g_ril_register(gd->ril, RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED,
764+ ril_gprs_state_change, gprs);
765+ }
766+
767+ if (max_cids > gd->max_cids) {
768+ DBG("Setting max cids to %d", max_cids);
769+ gd->max_cids = max_cids;
770+ ofono_gprs_set_cid_range(gprs, 1, max_cids);
771+ }
772+
773+ if (gd->status != status) {
774+ DBG("gd->status: %d status: %d", gd->status, status);
775+ ofono_gprs_status_notify(gprs, status);
776+ }
777+
778+ gd->status = status;
779+ gd->tech = tech;
780+
781+error:
782+ if (cb)
783+ cb(&error, status, cbd->data);
784+}
785+
786+static void ril_gprs_registration_status(struct ofono_gprs *gprs,
787+ ofono_gprs_status_cb_t cb,
788+ void *data)
789+{
790+ struct gprs_data *gd = ofono_gprs_get_data(gprs);
791+ struct cb_data *cbd = cb_data_new(cb, data);
792+ guint ret;
793+
794+ cbd->user = gprs;
795+
796+ ret = g_ril_send(gd->ril, RIL_REQUEST_DATA_REGISTRATION_STATE,
797+ NULL, 0, ril_data_reg_cb, cbd, g_free);
798+
799+ ril_clear_print_buf;
800+ ril_print_request(ret, RIL_REQUEST_DATA_REGISTRATION_STATE);
801+
802+ if (ret <= 0) {
803+ ofono_error("Send RIL_REQUEST_DATA_RESTISTRATION_STATE failed.");
804+ g_free(cbd);
805+ CALLBACK_WITH_FAILURE(cb, -1, data);
806+ }
807+}
808+
809+static int ril_gprs_probe(struct ofono_gprs *gprs,
810+ unsigned int vendor, void *data)
811+{
812+ GRil *ril = data;
813+ struct gprs_data *gd;
814+
815+ DBG("");
816+
817+ gd = g_try_new0(struct gprs_data, 1);
818+ if (gd == NULL)
819+ return -ENOMEM;
820+
821+ gd->ril = g_ril_clone(ril);
822+ gd->max_cids = 0;
823+ gd->status = -1;
824+
825+ ofono_gprs_set_data(gprs, gd);
826+
827+ ril_gprs_registration_status(gprs, NULL, NULL);
828+
829+ return 0;
830+}
831+
832+static void ril_gprs_remove(struct ofono_gprs *gprs)
833+{
834+ struct gprs_data *gd = ofono_gprs_get_data(gprs);
835+
836+ DBG("");
837+
838+ ofono_gprs_set_data(gprs, NULL);
839+
840+ g_ril_unref(gd->ril);
841+ g_free(gd);
842+}
843+
844+static struct ofono_gprs_driver driver = {
845+ .name = "rilmodem",
846+ .probe = ril_gprs_probe,
847+ .remove = ril_gprs_remove,
848+ .set_attached = ril_gprs_set_attached,
849+ .attached_status = ril_gprs_registration_status,
850+};
851+
852+void ril_gprs_init(void)
853+{
854+ ofono_gprs_driver_register(&driver);
855+}
856+
857+void ril_gprs_exit(void)
858+{
859+ ofono_gprs_driver_unregister(&driver);
860+}
861
862=== modified file 'drivers/rilmodem/network-registration.c'
863--- drivers/rilmodem/network-registration.c 2013-04-11 19:31:21 +0000
864+++ drivers/rilmodem/network-registration.c 2013-05-31 21:04:26 +0000
865@@ -36,12 +36,9 @@
866 #include <ofono/modem.h>
867 #include <ofono/netreg.h>
868
869+#include "common.h"
870 #include "gril.h"
871-
872 #include "rilmodem.h"
873-#include "parcel.h"
874-#include "common.h"
875-#include "parcel.h"
876
877 struct netreg_data {
878 GRil *ril;
879@@ -102,7 +99,7 @@
880 decode_ril_error(&error, "OK");
881
882 if (ril_util_parse_reg(message, &status,
883- &lac, &ci, &tech) == FALSE) {
884+ &lac, &ci, &tech, NULL) == FALSE) {
885 CALLBACK_WITH_FAILURE(cb, -1, -1, -1, -1, cbd->data);
886 return;
887 }
888@@ -301,6 +298,7 @@
889
890 extract_mcc_mnc(numeric, list[i].mcc, list[i].mnc);
891
892+ /* FIXME: need to fix this for CDMA */
893 /* Use GSM as default, as RIL doesn't pass that info to us */
894 list[i].tech = ACCESS_TECHNOLOGY_GSM;
895
896
897=== modified file 'drivers/rilmodem/rilmodem.c'
898--- drivers/rilmodem/rilmodem.c 2013-04-12 18:51:33 +0000
899+++ drivers/rilmodem/rilmodem.c 2013-05-31 21:04:26 +0000
900@@ -3,7 +3,7 @@
901 * oFono - Open Source Telephony - RIL Modem Support
902 *
903 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
904- * Copyright (C) 2012 Canonical Ltd.
905+ * Copyright (C) 2012 Canonical, Ltd. All rights reserved.
906 *
907 * This program is free software; you can redistribute it and/or modify
908 * it under the terms of the GNU General Public License version 2 as
909@@ -30,6 +30,7 @@
910 #define OFONO_API_SUBJECT_TO_CHANGE
911 #include <ofono/plugin.h>
912 #include <ofono/log.h>
913+#include <ofono/types.h>
914
915 #include "rilmodem.h"
916
917@@ -44,6 +45,9 @@
918 ril_netreg_init();
919 ril_call_volume_init();
920
921+ ril_gprs_init();
922+ ril_gprs_context_init();
923+
924 return 0;
925 }
926
927@@ -57,6 +61,8 @@
928 ril_sms_exit();
929 ril_netreg_exit();
930 ril_call_volume_exit();
931+ ril_gprs_exit();
932+ ril_gprs_context_exit();
933 }
934
935 OFONO_PLUGIN_DEFINE(rilmodem, "RIL modem driver", VERSION,
936
937=== modified file 'drivers/rilmodem/rilmodem.h'
938--- drivers/rilmodem/rilmodem.h 2013-04-11 19:31:21 +0000
939+++ drivers/rilmodem/rilmodem.h 2013-05-31 21:04:26 +0000
940@@ -43,3 +43,9 @@
941
942 extern void ril_netreg_init(void);
943 extern void ril_netreg_exit(void);
944+
945+extern void ril_gprs_init(void);
946+extern void ril_gprs_exit(void);
947+
948+extern void ril_gprs_context_init(void);
949+extern void ril_gprs_context_exit(void);
950
951=== modified file 'drivers/rilmodem/rilutil.c'
952--- drivers/rilmodem/rilutil.c 2013-05-20 19:16:56 +0000
953+++ drivers/rilmodem/rilutil.c 2013-05-31 21:04:26 +0000
954@@ -35,7 +35,6 @@
955
956 #include "common.h"
957 #include "rilutil.h"
958-#include "parcel.h"
959 #include "simutil.h"
960 #include "util.h"
961 #include "ril_constants.h"
962@@ -51,6 +50,9 @@
963 GDestroyNotify destroy;
964 };
965
966+/* TODO: make conditional */
967+static char print_buf[PRINT_BUF_SIZE];
968+
969 static gboolean cpin_check(gpointer userdata);
970
971 void decode_ril_error(struct ofono_error *error, const char *final)
972@@ -98,6 +100,20 @@
973 return 0;
974 }
975
976+gint ril_util_data_call_compare(gconstpointer a, gconstpointer b)
977+{
978+ const struct data_call *ca = a;
979+ const struct data_call *cb = b;
980+
981+ if (ca->cid < cb->cid)
982+ return -1;
983+
984+ if (ca->cid > cb->cid)
985+ return 1;
986+
987+ return 0;
988+}
989+
990 gint ril_util_call_compare(gconstpointer a, gconstpointer b)
991 {
992 const struct ofono_call *ca = a;
993@@ -121,6 +137,52 @@
994 return FALSE;
995 }
996
997+gchar *ril_util_get_netmask(const gchar *address)
998+{
999+ char *result;
1000+
1001+ if (g_str_has_suffix(address, "/30")) {
1002+ result = PREFIX_30_NETMASK;
1003+ } else if (g_str_has_suffix(address, "/29")) {
1004+ result = PREFIX_29_NETMASK;
1005+ } else if (g_str_has_suffix(address, "/28")) {
1006+ result = PREFIX_28_NETMASK;
1007+ } else if (g_str_has_suffix(address, "/27")) {
1008+ result = PREFIX_27_NETMASK;
1009+ } else if (g_str_has_suffix(address, "/26")) {
1010+ result = PREFIX_26_NETMASK;
1011+ } else if (g_str_has_suffix(address, "/25")) {
1012+ result = PREFIX_25_NETMASK;
1013+ } else if (g_str_has_suffix(address, "/24")) {
1014+ result = PREFIX_24_NETMASK;
1015+ } else {
1016+ /*
1017+ * This handles the case where the
1018+ * Samsung RILD returns an address without
1019+ * a prefix, however it explicitly sets a
1020+ * /24 netmask ( which isn't returned as
1021+ * an attribute of the DATA_CALL.
1022+ *
1023+ * TODO/OEM: this might need to be quirked
1024+ * for specific devices.
1025+ */
1026+ result = PREFIX_24_NETMASK;
1027+ }
1028+
1029+ DBG("address: %s netmask: %s", address, result);
1030+
1031+ return result;
1032+}
1033+
1034+void ril_util_init_parcel(struct ril_msg *message, struct parcel *rilp)
1035+{
1036+ /* Set up Parcel struct for proper parsing */
1037+ rilp->data = message->buf;
1038+ rilp->size = message->buf_len;
1039+ rilp->capacity = message->buf_len;
1040+ rilp->offset = 0;
1041+}
1042+
1043 struct ril_util_sim_state_query *ril_util_sim_state_query_new(GRil *ril,
1044 guint interval, guint num_times,
1045 ril_util_sim_inserted_cb_t cb,
1046@@ -165,11 +227,7 @@
1047 int num, i;
1048 gchar *number, *name;
1049
1050- /* Set up Parcel struct for proper parsing */
1051- rilp.data = message->buf;
1052- rilp.size = message->buf_len;
1053- rilp.capacity = message->buf_len;
1054- rilp.offset = 0;
1055+ ril_util_init_parcel(message, &rilp);
1056
1057 /* Number of RIL_Call structs */
1058 num = parcel_r_int32(&rilp);
1059@@ -218,6 +276,83 @@
1060 return l;
1061 }
1062
1063+GSList *ril_util_parse_data_call_list(struct ril_msg *message)
1064+{
1065+ struct data_call *call;
1066+ struct parcel rilp;
1067+ GSList *l = NULL;
1068+ int num, i, version;
1069+ gchar *number, *name;
1070+
1071+ ril_util_init_parcel(message, &rilp);
1072+
1073+ /*
1074+ * ril.h documents the reply to a RIL_REQUEST_DATA_CALL_LIST
1075+ * as being an array of RIL_Data_Call_Response_v6 structs,
1076+ * however in reality, the response also includes a version
1077+ * to start.
1078+ */
1079+ version = parcel_r_int32(&rilp);
1080+
1081+ /* Number of calls */
1082+ num = parcel_r_int32(&rilp);
1083+
1084+ /* TODO: make conditional */
1085+ ril_append_print_buf("[%04d]< %s",
1086+ message->serial_no,
1087+ ril_unsol_request_to_string(message->req));
1088+
1089+ ril_start_response;
1090+
1091+ ril_append_print_buf("%sversion=%d,num=%d",
1092+ print_buf,
1093+ version,
1094+ num);
1095+ /* TODO: make conditional */
1096+
1097+ for (i = 0; i < num; i++) {
1098+ call = g_try_new(struct data_call, 1);
1099+ if (call == NULL)
1100+ break;
1101+
1102+ call->status = parcel_r_int32(&rilp);
1103+ call->retry = parcel_r_int32(&rilp);
1104+ call->cid = parcel_r_int32(&rilp);
1105+ call->active = parcel_r_int32(&rilp);
1106+
1107+ call->type = parcel_r_string(&rilp);
1108+ call->ifname = parcel_r_string(&rilp);
1109+ call->addresses = parcel_r_string(&rilp);
1110+ call->dnses = parcel_r_string(&rilp);
1111+ call->gateways = parcel_r_string(&rilp);
1112+
1113+ /* TODO: make conditional */
1114+ /* TODO: figure out how to line-wrap properly
1115+ * without introducing spaces in string.
1116+ */
1117+ ril_append_print_buf("%s [status=%d,retry=%d,cid=%d,active=%d,type=%s,ifname=%s,address=%s,dns=%s,gateways=%s]",
1118+ print_buf,
1119+ call->status,
1120+ call->retry,
1121+ call->cid,
1122+ call->active,
1123+ call->type,
1124+ call->ifname,
1125+ call->addresses,
1126+ call->dnses,
1127+ call->gateways);
1128+ /* TODO: make conditional */
1129+
1130+ l = g_slist_insert_sorted(l, call, ril_util_data_call_compare);
1131+ }
1132+
1133+ ril_close_response;
1134+ ril_print_response;
1135+ /* TODO: make conditional */
1136+
1137+ return l;
1138+}
1139+
1140 char *ril_util_parse_sim_io_rsp(struct ril_msg *message,
1141 int *sw1, int *sw2,
1142 int *hex_len)
1143@@ -236,22 +371,36 @@
1144 return FALSE;
1145 }
1146
1147- /* Set up Parcel struct for proper parsing */
1148- rilp.data = message->buf;
1149- rilp.size = message->buf_len;
1150- rilp.capacity = message->buf_len;
1151- rilp.offset = 0;
1152+ DBG("message->buf_len is: %d", message->buf_len);
1153+
1154+ ril_util_init_parcel(message, &rilp);
1155
1156 *sw1 = parcel_r_int32(&rilp);
1157 *sw2 = parcel_r_int32(&rilp);
1158
1159 response = parcel_r_string(&rilp);
1160 if (response) {
1161- hex_response = (char *) decode_hex((const char *) response, strlen(response),
1162+ DBG("response is set; len is: %d", strlen(response));
1163+ hex_response = (char *) decode_hex((const char *) response,
1164+ strlen(response),
1165 (long *) hex_len, -1);
1166- g_free(response);
1167 }
1168
1169+ /* TODO: make conditional */
1170+ ril_append_print_buf("[%04d]< %s",
1171+ message->serial_no,
1172+ ril_request_id_to_string(message->req));
1173+ ril_start_response;
1174+ ril_append_print_buf("%ssw1=0x%.2X,sw2=0x%.2X,%s",
1175+ print_buf,
1176+ *sw1,
1177+ *sw2,
1178+ response);
1179+ ril_close_response;
1180+ ril_print_response;
1181+ /* TODO: make conditional */
1182+
1183+ g_free(response);
1184 return hex_response;
1185 }
1186
1187@@ -262,20 +411,18 @@
1188 char *aid_str = NULL;
1189 char *app_str = NULL;
1190 int i, card_state, num_apps, pin_state, gsm_umts_index, ims_index;
1191- int app_state, app_type, pin_replaced, pin1_state, pin2_state;
1192+ int app_state, app_type, pin_replaced, pin1_state, pin2_state, perso_substate;
1193
1194- DBG("");
1195+ ril_append_print_buf("[%04d]< %s",
1196+ message->serial_no,
1197+ ril_request_id_to_string(message->req));
1198
1199 if (app) {
1200 app->app_type = RIL_APPTYPE_UNKNOWN;
1201 app->app_id = NULL;
1202 }
1203
1204- /* Set up Parcel struct for proper parsing */
1205- rilp.data = message->buf;
1206- rilp.size = message->buf_len;
1207- rilp.capacity = message->buf_len;
1208- rilp.offset = 0;
1209+ ril_util_init_parcel(message, &rilp);
1210
1211 /*
1212 * FIXME: Need to come up with a common scheme for verifying the
1213@@ -289,8 +436,11 @@
1214 * 20 is the min length of RIL_CardStatus_v6 as the AppState
1215 * array can be 0-length.
1216 */
1217- if (message->buf_len < 20)
1218+ if (message->buf_len < 20) {
1219+ ofono_error("Size of SIM_STATUS reply too small: %d bytes",
1220+ message->buf_len);
1221 goto done;
1222+ }
1223
1224 card_state = parcel_r_int32(&rilp);
1225 pin_state = parcel_r_int32(&rilp);
1226@@ -299,10 +449,25 @@
1227 ims_index = parcel_r_int32(&rilp);
1228 num_apps = parcel_r_int32(&rilp);
1229
1230+ ril_start_response;
1231+
1232+ /* TODO:
1233+ * How do we handle long (>80 chars) ril_append_print_buf strings?
1234+ * Using line wrapping ( via '\' ) introduces spaces in the output.
1235+ * Do we just make a style-guide exception for PrintBuf operations?
1236+ */
1237+ ril_append_print_buf("%s card_state=%d,universal_pin_state=%d,gsm_umts_index=%d,cdma_index=%d,ims_index=%d, ",
1238+ print_buf,
1239+ card_state,
1240+ pin_state,
1241+ gsm_umts_index,
1242+ -1,
1243+ ims_index);
1244+
1245 for (i = 0; i < num_apps; i++) {
1246 app_type = parcel_r_int32(&rilp);
1247 app_state = parcel_r_int32(&rilp);
1248- parcel_r_int32(&rilp); /* Ignore perso_substate for now */
1249+ perso_substate = parcel_r_int32(&rilp);
1250
1251 /* TODO: we need a way to instruct parcel to skip
1252 * a string, without allocating memory...
1253@@ -314,14 +479,16 @@
1254 pin1_state = parcel_r_int32(&rilp);
1255 pin2_state = parcel_r_int32(&rilp);
1256
1257- DBG("SIM app type: %s state: %s",
1258- ril_apptype_to_string(app_type),
1259- ril_appstate_to_string(app_state));
1260-
1261- DBG("pin_replaced: %d pin1_state: %s pin2_state: %s",
1262- pin_replaced,
1263- ril_pinstate_to_string(pin1_state),
1264- ril_pinstate_to_string(pin2_state));
1265+ ril_append_print_buf("%s[app_type=%d,app_state=%d,perso_substate=%d,aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
1266+ print_buf,
1267+ app_type,
1268+ app_state,
1269+ perso_substate,
1270+ aid_str,
1271+ app_str,
1272+ pin_replaced,
1273+ pin1_state,
1274+ pin2_state);
1275
1276 /* FIXME: CDMA/IMS -- see comment @ top-of-source. */
1277 if (i == gsm_umts_index && app) {
1278@@ -337,15 +504,8 @@
1279 g_free(app_str);
1280 }
1281
1282- DBG("card_state: %s (%d) pin_state: %s (%d) num_apps: %d",
1283- ril_cardstate_to_string(card_state),
1284- card_state,
1285- ril_pinstate_to_string(pin_state),
1286- pin_state,
1287- num_apps);
1288-
1289- DBG("gsm_umts_index: %d; ims_index: %d",
1290- gsm_umts_index, ims_index);
1291+ ril_close_response;
1292+ ril_print_response;
1293
1294 if (card_state == RIL_CARDSTATE_PRESENT)
1295 result = TRUE;
1296@@ -354,69 +514,131 @@
1297 }
1298
1299 gboolean ril_util_parse_reg(struct ril_msg *message, int *status,
1300- int *lac, int *ci, int *tech)
1301+ int *lac, int *ci, int *tech, int *max_calls)
1302 {
1303 struct parcel rilp;
1304- gchar *sstatus, *slac, *sci, *stech;
1305-
1306- /* Set up Parcel struct for proper parsing */
1307- rilp.data = message->buf;
1308- rilp.size = message->buf_len;
1309- rilp.capacity = message->buf_len;
1310- rilp.offset = 0;
1311-
1312- /* Size of char ** */
1313- if (parcel_r_int32(&rilp) == 0)
1314- return FALSE;
1315+ int tmp;
1316+ gchar *sstatus = NULL, *slac = NULL, *sci = NULL;
1317+ gchar *stech = NULL, *sreason = NULL, *smax = NULL;
1318+
1319+ ril_util_init_parcel(message, &rilp);
1320+
1321+
1322+ /* TODO: make conditional */
1323+ ril_append_print_buf("[%04d]< %s",
1324+ message->serial_no,
1325+ ril_request_id_to_string(message->req));
1326+
1327+ ril_start_response;
1328+ /* TODO: make conditional */
1329+
1330+ /* FIXME: need minimum message size check FIRST!!! */
1331+
1332+ /* Size of response string array
1333+ *
1334+ * Should be:
1335+ * >= 4 for VOICE_REG reply
1336+ * >= 5 for DATA_REG reply
1337+ */
1338+ if ((tmp = parcel_r_int32(&rilp)) < 4) {
1339+ DBG("Size of response array is too small: %d", tmp);
1340+ goto error;
1341+ }
1342
1343 sstatus = parcel_r_string(&rilp);
1344 slac = parcel_r_string(&rilp);
1345 sci = parcel_r_string(&rilp);
1346 stech = parcel_r_string(&rilp);
1347
1348- DBG("RIL reg - status: %s, lac: %s, ci: %s, radio tech: %s",
1349- sstatus, slac, sci, stech);
1350-
1351- if (status)
1352+ tmp -= 4;
1353+
1354+ /* FIXME: need to review VOICE_REGISTRATION response
1355+ * as it returns ~15 parameters ( vs. 6 for DATA ).
1356+ *
1357+ * The first four parameters are the same for both
1358+ * responses ( although status includes values for
1359+ * emergency calls for VOICE response ).
1360+ *
1361+ * Parameters 5 & 6 have different meanings for
1362+ * voice & data response.
1363+ */
1364+ if (tmp--) {
1365+ sreason = parcel_r_string(&rilp); /* TODO: different use for CDMA */
1366+
1367+ if (tmp--) {
1368+ smax = parcel_r_string(&rilp); /* TODO: different use for CDMA */
1369+
1370+ if (smax && max_calls)
1371+ *max_calls = atoi(smax);
1372+ }
1373+ }
1374+
1375+ /* TODO: make conditional */
1376+ ril_append_print_buf("%s%s,%s,%s,%s,%s,%s",
1377+ print_buf,
1378+ sstatus,
1379+ slac,
1380+ sci,
1381+ stech,
1382+ sreason,
1383+ smax);
1384+ ril_close_response;
1385+ ril_print_response;
1386+ /* TODO: make conditional */
1387+
1388+ if (status) {
1389+ if (!sstatus) {
1390+ DBG("No sstatus value returned!");
1391+ goto error;
1392+ }
1393+
1394 *status = atoi(sstatus);
1395+ }
1396+
1397 if (lac) {
1398 if (slac)
1399 *lac = strtol(slac, NULL, 16);
1400 else
1401 *lac = -1;
1402 }
1403+
1404 if (ci) {
1405 if (sci)
1406 *ci = strtol(sci, NULL, 16);
1407 else
1408 *ci = -1;
1409 }
1410+
1411+
1412 if (tech) {
1413- switch(atoi(stech)) {
1414- case RADIO_TECH_UNKNOWN:
1415- *tech = -1;
1416- break;
1417- case RADIO_TECH_GPRS:
1418- *tech = ACCESS_TECHNOLOGY_GSM;
1419- break;
1420- case RADIO_TECH_EDGE:
1421- *tech = ACCESS_TECHNOLOGY_GSM_EGPRS;
1422- break;
1423- case RADIO_TECH_UMTS:
1424- *tech = ACCESS_TECHNOLOGY_UTRAN;
1425- break;
1426- case RADIO_TECH_HSDPA:
1427- *tech = ACCESS_TECHNOLOGY_UTRAN_HSDPA;
1428- break;
1429- case RADIO_TECH_HSUPA:
1430- *tech = ACCESS_TECHNOLOGY_UTRAN_HSUPA;
1431- break;
1432- case RADIO_TECH_HSPA:
1433- *tech = ACCESS_TECHNOLOGY_UTRAN_HSDPA_HSUPA;
1434- break;
1435- default:
1436- *tech = -1;
1437- }
1438+ if (stech) {
1439+ switch(atoi(stech)) {
1440+ case RADIO_TECH_UNKNOWN:
1441+ *tech = -1;
1442+ break;
1443+ case RADIO_TECH_GPRS:
1444+ *tech = ACCESS_TECHNOLOGY_GSM;
1445+ break;
1446+ case RADIO_TECH_EDGE:
1447+ *tech = ACCESS_TECHNOLOGY_GSM_EGPRS;
1448+ break;
1449+ case RADIO_TECH_UMTS:
1450+ *tech = ACCESS_TECHNOLOGY_UTRAN;
1451+ break;
1452+ case RADIO_TECH_HSDPA:
1453+ *tech = ACCESS_TECHNOLOGY_UTRAN_HSDPA;
1454+ break;
1455+ case RADIO_TECH_HSUPA:
1456+ *tech = ACCESS_TECHNOLOGY_UTRAN_HSUPA;
1457+ break;
1458+ case RADIO_TECH_HSPA:
1459+ *tech = ACCESS_TECHNOLOGY_UTRAN_HSDPA_HSUPA;
1460+ break;
1461+ default:
1462+ *tech = -1;
1463+ }
1464+ } else
1465+ *tech = -1;
1466 }
1467
1468 /* Free our parcel handlers */
1469@@ -424,8 +646,13 @@
1470 g_free(slac);
1471 g_free(sci);
1472 g_free(stech);
1473+ g_free(sreason);
1474+ g_free(smax);
1475
1476 return TRUE;
1477+
1478+error:
1479+ return FALSE;
1480 }
1481
1482 gint ril_util_parse_sms_response(struct ril_msg *message)
1483@@ -435,10 +662,7 @@
1484 char *ack_pdu;
1485
1486 /* Set up Parcel struct for proper parsing */
1487- rilp.data = message->buf;
1488- rilp.size = message->buf_len;
1489- rilp.capacity = message->buf_len;
1490- rilp.offset = 0;
1491+ ril_util_init_parcel(message, &rilp);
1492
1493 /* TP-Message-Reference for GSM/
1494 * BearerData MessageId for CDMA
1495@@ -459,10 +683,7 @@
1496 int gw_signal, cdma_dbm, evdo_dbm, lte_signal;
1497
1498 /* Set up Parcel struct for proper parsing */
1499- rilp.data = message->buf;
1500- rilp.size = message->buf_len;
1501- rilp.capacity = message->buf_len;
1502- rilp.offset = 0;
1503+ ril_util_init_parcel(message, &rilp);
1504
1505 /* RIL_SignalStrength_v6 */
1506 /* GW_SignalStrength */
1507
1508=== modified file 'drivers/rilmodem/rilutil.h'
1509--- drivers/rilmodem/rilutil.h 2013-05-15 19:37:23 +0000
1510+++ drivers/rilmodem/rilutil.h 2013-05-31 21:04:26 +0000
1511@@ -20,6 +20,41 @@
1512 *
1513 */
1514
1515+#include <stdio.h>
1516+
1517+#include "parcel.h"
1518+
1519+/* TODO:
1520+ * Guard with #ifdef RIL_DEBUG
1521+ * Based on code from:
1522+ *
1523+ * $AOSP/hardware/ril/libril/ril.cpp
1524+ */
1525+#define ril_start_request sprintf(print_buf, "(")
1526+#define ril_close_request sprintf(print_buf, "%s)", print_buf)
1527+#define ril_print_request(token, req) \
1528+ ofono_debug("[%04d]> %s %s", token, ril_request_id_to_string(req), print_buf)
1529+
1530+#define ril_start_response sprintf(print_buf, "%s {", print_buf)
1531+#define ril_close_response sprintf(print_buf, "%s}", print_buf)
1532+#define ril_print_response ofono_debug("%s", print_buf)
1533+
1534+#define ril_clear_print_buf print_buf[0] = 0
1535+#define ril_remove_last_char print_buf[strlen(print_buf)-1] = 0
1536+#define ril_append_print_buf(x...) sprintf(print_buf, x)
1537+
1538+// request, response, and unsolicited msg print macro
1539+#define PRINT_BUF_SIZE 8096
1540+
1541+/* TODO: create a table lookup*/
1542+#define PREFIX_30_NETMASK "255.255.255.252"
1543+#define PREFIX_29_NETMASK "255.255.255.248"
1544+#define PREFIX_28_NETMASK "255.255.255.240"
1545+#define PREFIX_27_NETMASK "255.255.255.224"
1546+#define PREFIX_26_NETMASK "255.255.255.192"
1547+#define PREFIX_25_NETMASK "255.255.255.128"
1548+#define PREFIX_24_NETMASK "255.255.255.0"
1549+
1550 enum ril_util_sms_store {
1551 RIL_UTIL_SMS_STORE_SM = 0,
1552 RIL_UTIL_SMS_STORE_ME = 1,
1553@@ -49,6 +84,18 @@
1554 RIL_UTIL_CHARSET_8859_H = 0x10000,
1555 };
1556
1557+struct data_call {
1558+ int status;
1559+ int retry;
1560+ int cid;
1561+ int active;
1562+ char * type;
1563+ char * ifname;
1564+ char * addresses;
1565+ char * dnses;
1566+ char * gateways;
1567+};
1568+
1569 struct sim_app {
1570 char *app_id;
1571 guint app_type;
1572@@ -61,6 +108,8 @@
1573 gint ril_util_call_compare_by_phone_number(gconstpointer a, gconstpointer b);
1574 gint ril_util_call_compare_by_id(gconstpointer a, gconstpointer b);
1575 gint ril_util_call_compare(gconstpointer a, gconstpointer b);
1576+gchar *ril_util_get_netmask(const char *address);
1577+void ril_util_init_parcel(struct ril_msg *message, struct parcel *rilp);
1578
1579 struct ril_util_sim_state_query *ril_util_sim_state_query_new(GRil *ril,
1580 guint interval, guint num_times,
1581@@ -70,12 +119,13 @@
1582 void ril_util_sim_state_query_free(struct ril_util_sim_state_query *req);
1583
1584 GSList *ril_util_parse_clcc(struct ril_msg *message);
1585+GSList *ril_util_parse_data_call_list(struct ril_msg *message);
1586 char *ril_util_parse_sim_io_rsp(struct ril_msg *message,
1587 int *sw1, int *sw2,
1588 int *hex_len);
1589 gboolean ril_util_parse_sim_status(struct ril_msg *message, struct sim_app *app);
1590 gboolean ril_util_parse_reg(struct ril_msg *message, int *status,
1591- int *lac, int *ci, int *tech);
1592+ int *lac, int *ci, int *tech, int *max_calls);
1593
1594 gint ril_util_parse_sms_response(struct ril_msg *message);
1595
1596
1597=== modified file 'drivers/rilmodem/sim.c'
1598--- drivers/rilmodem/sim.c 2013-05-20 19:16:56 +0000
1599+++ drivers/rilmodem/sim.c 2013-05-31 21:04:26 +0000
1600@@ -64,6 +64,8 @@
1601 /* FID/path of SIM/USIM root directory */
1602 #define ROOTMF "3F00"
1603
1604+static char print_buf[PRINT_BUF_SIZE];
1605+
1606 /*
1607 * TODO: CDMA/IMS
1608 *
1609@@ -96,6 +98,8 @@
1610 char *hex_path = NULL;
1611 int len = 0;
1612
1613+ DBG("");
1614+
1615 if (path_len > 0 && path_len < 7) {
1616 memcpy(db_path, path, path_len);
1617 len = path_len;
1618@@ -110,7 +114,15 @@
1619 if (len > 0) {
1620 hex_path = encode_hex(db_path, len, 0);
1621 parcel_w_string(rilp, (char *) hex_path);
1622- DBG("encoded path is: %s", hex_path);
1623+
1624+ DBG("len > 0");
1625+
1626+ /* TODO: make conditional */
1627+ ril_append_print_buf("%spath=%s,",
1628+ print_buf,
1629+ hex_path);
1630+ /* TODO: make conditional */
1631+
1632 g_free(hex_path);
1633 } else if (fileid == SIM_EF_ICCID_FILEID || fileid == SIM_EFPL_FILEID) {
1634 /*
1635@@ -124,7 +136,23 @@
1636 * ../../src/simutil.c for more details.
1637 */
1638 parcel_w_string(rilp, (char *) ROOTMF);
1639- DBG("encoded path is: %s", ROOTMF);
1640+
1641+ /* TODO: make conditional */
1642+ ril_append_print_buf("%spath=%s,",
1643+ print_buf,
1644+ ROOTMF);
1645+ /* TODO: make conditional */
1646+ } else {
1647+ /*
1648+ * The only known case of this is EFPHASE_FILED (0x6FAE).
1649+ * The ef_db table ( see /src/simutil.c ) entry for
1650+ * EFPHASE contains a value of 0x0000 for it's
1651+ * 'parent3g' member. This causes a NULL path to
1652+ * be returned.
1653+ */
1654+
1655+ DBG("db_get_path*() returned empty path.");
1656+ parcel_w_string(rilp, NULL);
1657 }
1658 }
1659
1660@@ -211,13 +239,20 @@
1661 int ret;
1662
1663 parcel_init(&rilp);
1664+
1665 parcel_w_int32(&rilp, CMD_GET_RESPONSE);
1666 parcel_w_int32(&rilp, fileid);
1667
1668+ /* TODO: make conditional */
1669+ ril_start_request;
1670+ ril_append_print_buf("%scmd=0x%.2X,efid=0x%.4X,",
1671+ print_buf,
1672+ CMD_GET_RESPONSE,
1673+ fileid);
1674+ /* TODO: make conditional */
1675+
1676 set_path(sd, &rilp, fileid, path, path_len);
1677
1678- DBG("fileid: %s (%x)", sim_fileid_to_string(fileid), fileid);
1679-
1680 parcel_w_int32(&rilp, 0); /* P1 */
1681 parcel_w_int32(&rilp, 0); /* P2 */
1682
1683@@ -240,6 +275,20 @@
1684 rilp.size,
1685 ril_file_info_cb, cbd, g_free);
1686
1687+ /* TODO: make conditional */
1688+ ril_append_print_buf("%s%d,%d,%d,%s,pin2=%s,aid=%s",
1689+ print_buf,
1690+ 0,
1691+ 0,
1692+ 15,
1693+ NULL,
1694+ NULL,
1695+ sd->app_id);
1696+
1697+ ril_close_request;
1698+ ril_print_request(ret, RIL_REQUEST_SIM_IO);
1699+ /* TODO: make conditional */
1700+
1701 parcel_free(&rilp);
1702
1703 if (ret <= 0) {
1704@@ -297,6 +346,14 @@
1705 DBG("fileid: %s (%x) path: %s", sim_fileid_to_string(fileid),
1706 fileid, path);
1707
1708+ /* TODO: make conditional */
1709+ ril_start_request;
1710+ ril_append_print_buf("%scmd=0x%.2X,efid=0x%.4X,",
1711+ print_buf,
1712+ CMD_READ_BINARY,
1713+ fileid);
1714+ /* TODO: make conditional */
1715+
1716 parcel_init(&rilp);
1717 parcel_w_int32(&rilp, CMD_READ_BINARY);
1718 parcel_w_int32(&rilp, fileid);
1719@@ -315,6 +372,21 @@
1720 rilp.data,
1721 rilp.size,
1722 ril_file_io_cb, cbd, g_free);
1723+
1724+ /* TODO: make conditional */
1725+ ril_append_print_buf("%s%d,%d,%d,%s,pin2=%s,aid=%s",
1726+ print_buf,
1727+ (start >> 8),
1728+ (start & 0xff),
1729+ length,
1730+ NULL,
1731+ NULL,
1732+ sd->app_id);
1733+
1734+ ril_close_request;
1735+ ril_print_request(ret, RIL_REQUEST_SIM_IO);
1736+ /* TODO: make conditional */
1737+
1738 parcel_free(&rilp);
1739
1740 if (ret <= 0) {
1741@@ -333,8 +405,13 @@
1742 struct parcel rilp;
1743 int ret;
1744
1745- DBG("fileid: %s (%x) path: %s", sim_fileid_to_string(fileid),
1746- fileid, path);
1747+ /* TODO: make conditional */
1748+ ril_start_request;
1749+ ril_append_print_buf("%scmd=0x%.2X,efid=0x%.4X,",
1750+ print_buf,
1751+ CMD_GET_RESPONSE,
1752+ fileid);
1753+ /* TODO: make conditional */
1754
1755 parcel_init(&rilp);
1756 parcel_w_int32(&rilp, CMD_READ_RECORD);
1757@@ -355,6 +432,19 @@
1758 rilp.size,
1759 ril_file_io_cb, cbd, g_free);
1760
1761+ /* TODO: make conditional */
1762+ ril_append_print_buf("%s%d,%d,%d,%s,pin2=%s,aid=%s",
1763+ print_buf,
1764+ record,
1765+ 4,
1766+ length,
1767+ NULL,
1768+ NULL,
1769+ sd->app_id);
1770+ ril_close_request;
1771+ ril_print_request(ret, RIL_REQUEST_SIM_IO);
1772+ /* TODO: make conditional */
1773+
1774 parcel_free(&rilp);
1775
1776 if (ret <= 0) {
1777@@ -381,19 +471,27 @@
1778 return;
1779 }
1780
1781- /* Set up Parcel struct for proper parsing */
1782- rilp.data = message->buf;
1783- rilp.size = message->buf_len;
1784- rilp.capacity = message->buf_len;
1785- rilp.offset = 0;
1786+ ril_util_init_parcel(message, &rilp);
1787
1788 /* 15 is the max length of IMSI
1789 * add 4 bytes for string length */
1790 /* FIXME: g_assert(message->buf_len <= 19); */
1791-
1792 imsi = parcel_r_string(&rilp);
1793
1794- DBG("ril_imsi_cb: IMSI: %s", imsi);
1795+ /* TODO: make conditional */
1796+ ril_append_print_buf("[%04d]< %s",
1797+ message->serial_no,
1798+ ril_request_id_to_string(message->req));
1799+
1800+ ril_start_response;
1801+
1802+ ril_append_print_buf("%s%s",
1803+ print_buf,
1804+ imsi);
1805+
1806+ ril_close_response;
1807+ ril_print_response;
1808+ /* TODO: make conditional */
1809
1810 cb(&error, imsi, cbd->data);
1811 g_free(imsi);
1812@@ -415,6 +513,14 @@
1813
1814 ret = g_ril_send(sd->ril, RIL_REQUEST_GET_IMSI,
1815 rilp.data, rilp.size, ril_imsi_cb, cbd, g_free);
1816+
1817+ /* TODO: make conditional */
1818+ ril_start_request;
1819+ ril_append_print_buf("%s%s", print_buf, sd->app_id);
1820+ ril_close_request;
1821+ ril_print_request(ret, RIL_REQUEST_GET_IMSI);
1822+ /* TODO: make conditional */
1823+
1824 parcel_free(&rilp);
1825
1826 if (ret <= 0) {
1827@@ -437,15 +543,27 @@
1828
1829 if (app.app_type != RIL_APPTYPE_UNKNOWN)
1830 sd->app_type = app.app_type;
1831+
1832+ ofono_sim_register(sim);
1833 }
1834+
1835+ /* TODO: if no SIM present, handle emergency calling. */
1836 }
1837
1838 static int send_get_sim_status(struct ofono_sim *sim)
1839 {
1840 struct sim_data *sd = ofono_sim_get_data(sim);
1841+ int ret;
1842
1843- return g_ril_send(sd->ril, RIL_REQUEST_GET_SIM_STATUS,
1844+ ret = g_ril_send(sd->ril, RIL_REQUEST_GET_SIM_STATUS,
1845 NULL, 0, sim_status_cb, sim, NULL);
1846+
1847+ /* TODO: make conditional */
1848+ ril_clear_print_buf;
1849+ ril_print_request(ret, RIL_REQUEST_GET_SIM_STATUS);
1850+ /* TODO: make conditional */
1851+
1852+ return ret;
1853 }
1854
1855 static gboolean ril_sim_register(gpointer user)
1856@@ -455,12 +573,6 @@
1857 DBG("");
1858
1859 send_get_sim_status(sim);
1860-
1861- /* TODO: consider replacing idle call of register
1862- * with call in sim_status_cb().
1863- */
1864- ofono_sim_register(sim);
1865-
1866 return FALSE;
1867 }
1868
1869
1870=== modified file 'drivers/rilmodem/voicecall.c'
1871--- drivers/rilmodem/voicecall.c 2013-04-11 19:31:21 +0000
1872+++ drivers/rilmodem/voicecall.c 2013-05-31 21:04:26 +0000
1873@@ -43,9 +43,7 @@
1874 #include "grilutil.h"
1875
1876 #include "common.h"
1877-
1878 #include "rilmodem.h"
1879-#include "parcel.h"
1880
1881 /* Amount of ms we wait between CLCC calls */
1882 #define POLL_CLCC_INTERVAL 300
1883
1884=== modified file 'gril/gril.c'
1885--- gril/gril.c 2013-03-28 12:50:26 +0000
1886+++ gril/gril.c 2013-05-31 21:04:26 +0000
1887@@ -47,8 +47,9 @@
1888 #define RILD_DBG_SOCKET "/dev/socket/rild-debug"
1889
1890 struct ril_request {
1891- gchar *req;
1892- guint req_len;
1893+ gchar *data;
1894+ guint data_len;
1895+ guint req;
1896 guint id;
1897 guint gid;
1898 GRilResponseFunc callback;
1899@@ -199,73 +200,6 @@
1900 return TRUE;
1901 }
1902
1903-/* TODO: move to grilutil.h */
1904-static const char *err_name(int error)
1905-{
1906- switch(error) {
1907- case RIL_E_SUCCESS: return "SUCCESS";
1908- case RIL_E_RADIO_NOT_AVAILABLE: return "RADIO_NOT_AVAILABLE";
1909- case RIL_E_GENERIC_FAILURE: return "GENERIC_FAILURE";
1910- case RIL_E_PASSWORD_INCORRECT: return "PASSWORD_INCORRECT";
1911- case RIL_E_SIM_PIN2: return "SIM_PIN2";
1912- case RIL_E_SIM_PUK2: return "SIM_PUK2";
1913- case RIL_E_REQUEST_NOT_SUPPORTED: return "REQUEST_NOT_SUPPORTED";
1914- case RIL_E_CANCELLED: return "CANCELLED";
1915- case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "OP_NOT_ALLOWED_DURING_VOICE_CALL";
1916- case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
1917- case RIL_E_SMS_SEND_FAIL_RETRY: return "SMS_SEND_FAIL_RETRY";
1918- case RIL_E_SIM_ABSENT: return "SIM_ABSENT";
1919- case RIL_E_SUBSCRIPTION_NOT_AVAILABLE: return "SUBSCRIPTION_NOT_AVAILABLE";
1920- case RIL_E_MODE_NOT_SUPPORTED: return "MODE_NOT_SUPPORTED";
1921- case RIL_E_FDN_CHECK_FAILURE: return "FDN_CHECK_FAILURE";
1922- case RIL_E_ILLEGAL_SIM_OR_ME: return "ILLEGAL_SIM_OR_ME";
1923- default: return "<unknown errno>";
1924- }
1925-}
1926-
1927-/* TODO: move to grilutil.h */
1928-static const char *unsol_request_name(int request)
1929-{
1930- switch(request) {
1931- case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
1932- case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
1933- case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
1934- case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
1935- case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
1936- case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
1937- case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
1938- case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
1939- case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
1940- case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
1941- case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
1942- case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
1943- case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
1944- case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
1945- case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
1946- case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
1947- case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
1948- case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
1949- case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
1950- case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
1951- case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
1952- case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
1953- case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
1954- case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
1955- case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
1956- case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
1957- case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
1958- case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
1959- case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
1960- case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
1961- case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
1962- case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
1963- case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
1964- case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
1965- default:
1966- DBG("Got unknown request number %d", request);
1967- return "<unknown request>";
1968- }
1969-}
1970
1971 /*
1972 * This function creates a RIL request. For a good reference on
1973@@ -302,21 +236,21 @@
1974 len = 8 + data_len;
1975
1976 /* Add 4 bytes to buffer length to include length prefix */
1977- r->req_len = len + 4;
1978+ r->data_len = len + 4;
1979
1980- r->req = g_try_new(char, r->req_len);
1981- if (r->req == NULL) {
1982+ r->data = g_try_new(char, r->data_len);
1983+ if (r->data == NULL) {
1984 ofono_error("ril_request: can't allocate new request.");
1985 g_free(r);
1986 return 0;
1987 }
1988
1989 /* convert length to network byte order (Big Endian) */
1990- net_length = (guint32 *) r->req;
1991+ net_length = (guint32 *) r->data;
1992 *net_length = htonl(len);
1993
1994 /* advance past initial length */
1995- cur_bufp = r->req + 4;
1996+ cur_bufp = r->data + 4;
1997
1998 /* write request code */
1999 request = (guint32 *) cur_bufp;
2000@@ -331,6 +265,7 @@
2001 /* copy request data */
2002 memcpy(cur_bufp, (const void *) data, data_len);
2003
2004+ r->req = req;
2005 r->gid = gid;
2006 r->id = id;
2007 r->callback = func;
2008@@ -345,7 +280,7 @@
2009 if (req->notify)
2010 req->notify(req->user_data);
2011
2012- g_free(req->req);
2013+ g_free(req->data);
2014 g_free(req);
2015 }
2016
2017@@ -390,18 +325,29 @@
2018 {
2019 gsize count = g_queue_get_length(p->command_queue);
2020 struct ril_request *req;
2021+ gboolean found = FALSE;
2022 int i;
2023
2024 g_assert(count > 0);
2025
2026 for (i = 0; i < count; i++) {
2027 req = g_queue_peek_nth(p->command_queue, i);
2028- DBG("comparing req->id: %d to message->serial_no: %d",
2029- req->id, message->serial_no);
2030+
2031+ /* TODO: make conditional
2032+ * DBG("comparing req->id: %d to message->serial_no: %d",
2033+ * req->id, message->serial_no);
2034+ */
2035
2036 if (req->id == message->serial_no) {
2037+ found = TRUE;
2038+ message->req = req->req;
2039+
2040+ DBG("RIL Reply: %s serial-no: %d errno: %s",
2041+ ril_request_id_to_string(message->req),
2042+ message->serial_no,
2043+ ril_error_to_string(message->error));
2044+
2045 req = g_queue_pop_nth(p->command_queue, i);
2046-
2047 if (req->callback)
2048 req->callback(message, req->user_data);
2049
2050@@ -426,6 +372,12 @@
2051 break;
2052 }
2053 }
2054+
2055+ if (found == FALSE)
2056+ DBG("Reply: %s serial_no: %d without a matching request!",
2057+ ril_request_id_to_string(message->req),
2058+ message->serial_no);
2059+
2060 }
2061
2062 static void handle_unsol_req(struct ril_s *p, struct ril_msg *message)
2063@@ -448,7 +400,10 @@
2064 req_key = *((int *)key);
2065 notify = value;
2066
2067- DBG("checking req_key: %d to req: %d", req_key, message->req);
2068+ /*
2069+ * TODO: add #ifdef...
2070+ * DBG("checking req_key: %d to req: %d", req_key, message->req);
2071+ */
2072
2073 if (req_key != message->req)
2074 continue;
2075@@ -458,8 +413,11 @@
2076 while (list_item != NULL) {
2077 node = list_item->data;
2078
2079- DBG("about to callback: notify: %x, node: %x, notify->nodes: %x, callback: %x",
2080- notify, node, notify->nodes, node->callback);
2081+ /*
2082+ * TODO: add #ifdef...
2083+ * DBG("about to callback: notify: %x, node: %x, notify->nodes: %x, callback: %x",
2084+ * notify, node, notify->nodes, node->callback);
2085+ */
2086
2087 node->callback(message, node->user_data);
2088
2089@@ -533,14 +491,11 @@
2090 }
2091
2092 if (message->unsolicited == TRUE) {
2093- DBG("RIL Event: %s\n", unsol_request_name(message->req));
2094+ DBG("RIL Event: %s\n",
2095+ ril_unsol_request_to_string(message->req));
2096
2097 handle_unsol_req(p, message);
2098 } else {
2099- DBG("RIL Reply: serial-no: %d errno: %s\n",
2100- message->serial_no,
2101- err_name(message->error));
2102-
2103 handle_response(p, message);
2104 }
2105 error:
2106@@ -606,13 +561,18 @@
2107
2108 p->in_read_handler = TRUE;
2109
2110- DBG("len: %d, wrap: %d", len, wrap);
2111-
2112+ /*
2113+ * TODO: make conditional
2114+ * DBG("len: %d, wrap: %d", len, wrap);
2115+ */
2116 while (p->suspended == FALSE && (p->read_so_far < len)) {
2117 gsize rbytes = MIN(len - p->read_so_far, wrap - p->read_so_far);
2118
2119 if (rbytes < 4) {
2120- DBG("Not enough bytes for header length: len: %d", len);
2121+ /*
2122+ * TODO: make conditional
2123+ * DBG("Not enough bytes for header length: len: %d", len);
2124+ */
2125 return;
2126 }
2127
2128@@ -626,7 +586,10 @@
2129
2130 /* wait for the rest of the record... */
2131 if (message == NULL) {
2132- DBG("Not enough bytes for fixed record");
2133+
2134+ /* TODO: make conditional
2135+ * DBG("Not enough bytes for fixed record");
2136+ */
2137 break;
2138 }
2139
2140@@ -671,8 +634,12 @@
2141 if (req == NULL)
2142 return FALSE;
2143
2144- len = req->req_len;
2145- DBG("len: %d, req_bytes_written: %d", len, ril->req_bytes_written);
2146+ len = req->data_len;
2147+
2148+ /*
2149+ * TODO: make conditional:
2150+ * DBG("len: %d, req_bytes_written: %d", len, ril->req_bytes_written);
2151+ */
2152
2153 /* For some reason write watcher fired, but we've already
2154 * written the entire command out to the io channel,
2155@@ -705,10 +672,13 @@
2156 #endif
2157
2158 bytes_written = g_ril_io_write(ril->io,
2159- req->req + ril->req_bytes_written,
2160+ req->data + ril->req_bytes_written,
2161 towrite);
2162
2163- DBG("bytes_written: %d", bytes_written);
2164+ /*
2165+ * TODO: make conditional
2166+ * DBG("bytes_written: %d", bytes_written);
2167+ */
2168
2169 if (bytes_written == 0)
2170 return FALSE;
2171
2172=== modified file 'gril/grilutil.c'
2173--- gril/grilutil.c 2013-04-11 19:26:26 +0000
2174+++ gril/grilutil.c 2013-05-31 21:04:26 +0000
2175@@ -90,42 +90,24 @@
2176
2177 const char *ril_error_to_string(int error)
2178 {
2179-
2180- switch (error) {
2181- case RIL_E_SUCCESS:
2182- return "SUCCESS";
2183- case RIL_E_RADIO_NOT_AVAILABLE:
2184- return "RADIO_NOT_AVAILABLE";
2185- case RIL_E_GENERIC_FAILURE:
2186- return "GENERIC_FAILURE";
2187- case RIL_E_PASSWORD_INCORRECT:
2188- return "PASSWORD_INCORRECT";
2189- case RIL_E_SIM_PIN2:
2190- return "SIM_PIN2";
2191- case RIL_E_SIM_PUK2:
2192- return "SIM_PUK2";
2193- case RIL_E_REQUEST_NOT_SUPPORTED:
2194- return "REQUEST_NOT_SUPPORTED";
2195- case RIL_E_CANCELLED:
2196- return "CANCELLED";
2197- case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL:
2198- return "OP_NOT_ALLOWED_DURING_VOICE_CALL";
2199- case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW:
2200- return "OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
2201- case RIL_E_SMS_SEND_FAIL_RETRY:
2202- return "SMS_SEND_FAIL_RETRY";
2203- case RIL_E_SIM_ABSENT:
2204- return "SIM_ABSENT";
2205- case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:
2206- return "SUBSCRIPTION_NOT_AVAILABLE";
2207- case RIL_E_MODE_NOT_SUPPORTED:
2208- return "MODE_NOT_SUPPORTED";
2209- case RIL_E_FDN_CHECK_FAILURE:
2210- return "FDN_CHECK_FAILURE";
2211- case RIL_E_ILLEGAL_SIM_OR_ME:
2212- return "ILLEGAL_SIM_OR_ME";
2213- default:
2214- return "<Unknown Error>";
2215+ switch(error) {
2216+ case RIL_E_SUCCESS: return "SUCCESS";
2217+ case RIL_E_RADIO_NOT_AVAILABLE: return "RADIO_NOT_AVAILABLE";
2218+ case RIL_E_GENERIC_FAILURE: return "GENERIC_FAILURE";
2219+ case RIL_E_PASSWORD_INCORRECT: return "PASSWORD_INCORRECT";
2220+ case RIL_E_SIM_PIN2: return "SIM_PIN2";
2221+ case RIL_E_SIM_PUK2: return "SIM_PUK2";
2222+ case RIL_E_REQUEST_NOT_SUPPORTED: return "REQUEST_NOT_SUPPORTED";
2223+ case RIL_E_CANCELLED: return "CANCELLED";
2224+ case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "OP_NOT_ALLOWED_DURING_VOICE_CALL";
2225+ case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
2226+ case RIL_E_SMS_SEND_FAIL_RETRY: return "SMS_SEND_FAIL_RETRY";
2227+ case RIL_E_SIM_ABSENT: return "SIM_ABSENT";
2228+ case RIL_E_SUBSCRIPTION_NOT_AVAILABLE: return "SUBSCRIPTION_NOT_AVAILABLE";
2229+ case RIL_E_MODE_NOT_SUPPORTED: return "MODE_NOT_SUPPORTED";
2230+ case RIL_E_FDN_CHECK_FAILURE: return "FDN_CHECK_FAILURE";
2231+ case RIL_E_ILLEGAL_SIM_OR_ME: return "ILLEGAL_SIM_OR_ME";
2232+ default: return "<unknown errno>";
2233 }
2234 }
2235
2236@@ -371,6 +353,48 @@
2237 }
2238 }
2239
2240+const char *ril_unsol_request_to_string(int request)
2241+{
2242+ switch(request) {
2243+ case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
2244+ case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
2245+ case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
2246+ case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
2247+ case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
2248+ case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
2249+ case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
2250+ case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
2251+ case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
2252+ case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
2253+ case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
2254+ case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
2255+ case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
2256+ case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
2257+ case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
2258+ case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
2259+ case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
2260+ case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
2261+ case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
2262+ case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
2263+ case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
2264+ case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
2265+ case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
2266+ case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
2267+ case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
2268+ case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
2269+ case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
2270+ case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
2271+ case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
2272+ case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
2273+ case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
2274+ case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
2275+ case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
2276+ case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
2277+ default:
2278+ return "<unknown request>";
2279+ }
2280+}
2281+
2282 void g_ril_util_debug_chat(gboolean in, const char *str, gsize len,
2283 GRilDebugFunc debugf, gpointer user_data)
2284 {
2285
2286=== modified file 'gril/grilutil.h'
2287--- gril/grilutil.h 2013-04-11 19:26:26 +0000
2288+++ gril/grilutil.h 2013-05-31 21:04:26 +0000
2289@@ -35,6 +35,7 @@
2290 const char *ril_error_to_string(int error);
2291 const char *ril_pinstate_to_string(int pin_state);
2292 const char *ril_request_id_to_string(int req);
2293+const char *ril_unsol_request_to_string(int request);
2294
2295 void g_ril_util_debug_chat(gboolean in, const char *str, gsize len,
2296 GRilDebugFunc debugf, gpointer user_data);
2297
2298=== modified file 'gril/parcel.c'
2299--- gril/parcel.c 2013-03-28 12:50:26 +0000
2300+++ gril/parcel.c 2013-05-31 21:04:26 +0000
2301@@ -81,8 +81,12 @@
2302 int parcel_w_int32(struct parcel *p, int32_t val)
2303 {
2304 for (;;) {
2305- DBG("parcel_w_int32(%d): offset = %d, cap = %d, size = %d",
2306- val, p->offset, p->capacity, p->size);
2307+
2308+ /*
2309+ * TODO: make conditional:
2310+ * DBG("parcel_w_int32(%d): offset = %d, cap = %d, size = %d",
2311+ * val, p->offset, p->capacity, p->size);
2312+ */
2313 if (p->offset + sizeof(int32_t) < p->capacity) {
2314 /* There's enough space */
2315 *((int32_t *) (p->data + p->offset)) = val;
2316@@ -117,8 +121,11 @@
2317 len = (gs16_len + 1) * sizeof(char16_t);
2318 for (;;) {
2319 size_t padded = PAD_SIZE(len);
2320- DBG("parcel_w_string(\"%s\"): offset %d, cap %d, size %d",
2321- str, p->offset, p->capacity, p->size);
2322+ /*
2323+ * TODO: make conditional:
2324+ * DBG("parcel_w_string(\"%s\"): offset %d, cap %d, size %d",
2325+ * str, p->offset, p->capacity, p->size);
2326+ */
2327 if (p->offset + len < p->capacity) {
2328 /* There's enough space */
2329 memcpy(p->data + p->offset, gs16,
2330@@ -127,8 +134,11 @@
2331 p->offset += padded;
2332 p->size += padded;
2333 if (padded != len) {
2334- DBG("Writing %d bytes, padded to %d",
2335- len, padded);
2336+ /*
2337+ * TODO: make conditional:
2338+ * DBG("Writing %d bytes, padded to %d",
2339+ * len, padded);
2340+ */
2341 #if BYTE_ORDER == BIG_ENDIAN
2342 static const uint32_t mask[4] = {
2343 0x00000000, 0xffffff00,
2344
2345=== modified file 'gril/ril_constants.h'
2346--- gril/ril_constants.h 2013-03-28 12:50:26 +0000
2347+++ gril/ril_constants.h 2013-05-31 21:04:26 +0000
2348@@ -43,6 +43,20 @@
2349 #define RIL_E_FDN_CHECK_FAILURE 14
2350 #define RIL_E_ILLEGAL_SIM_OR_ME 15
2351
2352+/* Preferred network types */
2353+#define PREF_NET_TYPE_GSM_WCDMA 0
2354+#define PREF_NET_TYPE_GSM_ONLY 1
2355+#define PREF_NET_TYPE_WCDMA 2
2356+#define PREF_NET_TYPE_GSM_WCDMA_AUTO 3
2357+#define PREF_NET_TYPE_CDMA_EVDO_AUTO 4
2358+#define PREF_NET_TYPE_CDMA_ONLY 5
2359+#define PREF_NET_TYPE_EVDO_ONLY 6
2360+#define PREF_NET_TYPE_GSM_WCDMA_CDMA_EVDO_AUTO 7
2361+#define PREF_NET_TYPE_LTE_CDMA_EVDO 8
2362+#define PREF_NET_TYPE_LTE_GSM_WCDMA 9
2363+#define PREF_NET_TYPE_LTE_CMDA_EVDO_GSM_WCDMA 10
2364+#define PREF_NET_TYPE_LTE_ONLY 11
2365+
2366 /* Radio technologies */
2367 #define RADIO_TECH_UNKNOWN 0
2368 #define RADIO_TECH_GPRS 1
2369@@ -62,6 +76,12 @@
2370 #define RADIO_TECH_HSPAP 15
2371 #define RADIO_TECH_GSM 16
2372
2373+/* See RIL_REQUEST_SETUP_DATA_CALL */
2374+
2375+#define RIL_DATA_PROFILE_DEFAULT 0
2376+#define RIL_DATA_PROFILE_TETHERED 1
2377+#define RIL_DATA_PROFILE_OEM_BASE 1000 /* Start of OEM-specific profiles */
2378+
2379 /* SIM card states */
2380 #define RIL_CARDSTATE_ABSENT 0
2381 #define RIL_CARDSTATE_PRESENT 1
2382
2383=== modified file 'plugins/provision.c'
2384--- plugins/provision.c 2012-06-02 00:55:18 +0000
2385+++ plugins/provision.c 2013-05-31 21:04:26 +0000
2386@@ -50,7 +50,12 @@
2387
2388 DBG("Provisioning for MCC %s, MNC %s, SPN '%s'", mcc, mnc, spn);
2389
2390- apns = mbpi_lookup_apn(mcc, mnc, FALSE, &error);
2391+ /*
2392+ * TODO: review with upstream. Default behavior was to
2393+ * disallow duplicate APN entries, which unfortunately exist
2394+ * in the mobile-broadband-provider-info db.
2395+ */
2396+ apns = mbpi_lookup_apn(mcc, mnc, TRUE, &error);
2397 if (apns == NULL) {
2398 if (error != NULL) {
2399 ofono_error("%s", error->message);
2400
2401=== modified file 'plugins/ril.c'
2402--- plugins/ril.c 2013-05-15 19:37:23 +0000
2403+++ plugins/ril.c 2013-05-31 21:04:26 +0000
2404@@ -53,6 +53,7 @@
2405 #include <ofono/gprs.h>
2406 #include <ofono/gprs-context.h>
2407 #include <ofono/audio-settings.h>
2408+#include <ofono/types.h>
2409
2410 #include "drivers/rilmodem/rilmodem.h"
2411
2412@@ -68,6 +69,8 @@
2413 ofono_bool_t reported;
2414 };
2415
2416+static char print_buf[PRINT_BUF_SIZE];
2417+
2418 static gboolean power_on(gpointer user_data);
2419
2420 static void ril_debug(const char *str, void *user_data)
2421@@ -141,9 +144,17 @@
2422 static int send_get_sim_status(struct ofono_modem *modem)
2423 {
2424 struct ril_data *ril = ofono_modem_get_data(modem);
2425+ int ret;
2426
2427- return g_ril_send(ril->modem, RIL_REQUEST_GET_SIM_STATUS,
2428+ ret = g_ril_send(ril->modem, RIL_REQUEST_GET_SIM_STATUS,
2429 NULL, 0, sim_status_cb, modem, NULL);
2430+
2431+ /* TODO: make conditional */
2432+ ril_clear_print_buf;
2433+ ril_print_request(ret, RIL_REQUEST_GET_SIM_STATUS);
2434+ /* TODO: make conditional */
2435+
2436+ return ret;
2437 }
2438
2439 static int ril_probe(struct ofono_modem *modem)
2440@@ -212,16 +223,27 @@
2441 static void ril_post_sim(struct ofono_modem *modem)
2442 {
2443 struct ril_data *ril = ofono_modem_get_data(modem);
2444+ struct ofono_gprs *gprs;
2445+ struct ofono_gprs_context *gc;
2446+
2447+
2448
2449 DBG("(%p) with %s", modem, ril->ifname);
2450
2451 /* TODO: this function should setup:
2452 * - phonebook
2453 * - stk ( SIM toolkit )
2454- * - radio_settings (why?)
2455- * - sms ( this could go to post_online ); ask ofono upstream...
2456+ * - radio_settings
2457 */
2458 ofono_sms_create(modem, 0, "rilmodem", ril->modem);
2459+
2460+ gprs = ofono_gprs_create(modem, 0, "rilmodem", ril->modem);
2461+ gc = ofono_gprs_context_create(modem, 0, "rilmodem", ril->modem);
2462+
2463+ if (gprs && gc) {
2464+ DBG("calling gprs_add_context");
2465+ ofono_gprs_add_context(gprs, gc);
2466+ }
2467 }
2468
2469 static void ril_post_online(struct ofono_modem *modem)

Subscribers

People subscribed via source and target branches