Merge lp:~rsalveti/ofono/ubuntu-fixes-online-offline-netreg-mute into lp:~phablet-team/ofono/ubuntu

Proposed by Ricardo Salveti
Status: Merged
Approved by: Tony Espy
Approved revision: 6835
Merged at revision: 6835
Proposed branch: lp:~rsalveti/ofono/ubuntu-fixes-online-offline-netreg-mute
Merge into: lp:~phablet-team/ofono/ubuntu
Diff against target: 867 lines (+277/-149)
7 files modified
drivers/rilmodem/call-volume.c (+3/-0)
drivers/rilmodem/network-registration.c (+5/-0)
gril/gril.c (+96/-70)
gril/grilrequest.c (+16/-0)
gril/grilrequest.h (+4/-0)
plugins/ril.c (+99/-79)
unit/test-grilrequest.c (+54/-0)
To merge this branch: bzr merge lp:~rsalveti/ofono/ubuntu-fixes-online-offline-netreg-mute
Reviewer Review Type Date Requested Status
Tony Espy Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+189204@code.launchpad.net

Commit message

- Ensure that *netreg_data is always set in callback data (LP: #1234491)
- Re-factor rilmodem initialization code to enable set online/offline (LP: #1210502)
- Fixing parcel parsing when probing for mute

To post a comment you must log in.
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Tested with both mako and maguro, working as expected.

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

Tesed voice calls ( in/out ), SMS ( in/out ), call mute/volume, and GPRS on both maguro/mako using the pre-built debs installed on freshly flashed r/w system image #78.

A couple of problem observed, but unrelated to the MR:

 - call volume doesn't work on maguro

 - call mute doesn't work on mako ( known bug, in-progress )

Other then these issues, all good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'drivers/rilmodem/call-volume.c'
2--- drivers/rilmodem/call-volume.c 2013-09-09 19:21:32 +0000
3+++ drivers/rilmodem/call-volume.c 2013-10-04 03:07:28 +0000
4@@ -111,6 +111,9 @@
5 }
6
7 ril_util_init_parcel(message, &rilp);
8+
9+ /* skip length of int[] */
10+ parcel_r_int32(&rilp);
11 muted = parcel_r_int32(&rilp);
12
13 g_ril_append_print_buf(cvd->ril, "{%d}", muted);
14
15=== modified file 'drivers/rilmodem/network-registration.c'
16--- drivers/rilmodem/network-registration.c 2013-09-09 19:21:32 +0000
17+++ drivers/rilmodem/network-registration.c 2013-10-04 03:07:28 +0000
18@@ -384,6 +384,8 @@
19 struct cb_data *cbd = cb_data_new(cb, data);
20 int request = RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC;
21 int ret;
22+
23+ /* add *netreg_data to callback */
24 cbd->user = nd;
25
26 ret = g_ril_send(nd->ril, request,
27@@ -408,6 +410,9 @@
28 int request = RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL;
29 int ret;
30
31+ /* add *netreg_data to callback */
32+ cbd->user = nd;
33+
34 parcel_init(&rilp);
35
36 /* RIL expects a char * specifying MCCMNC of network to select */
37
38=== modified file 'gril/gril.c'
39--- gril/gril.c 2013-09-09 19:21:32 +0000
40+++ gril/gril.c 2013-10-04 03:07:28 +0000
41@@ -3,7 +3,8 @@
42 * RIL library with GLib integration
43 *
44 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
45- * Copyright (C) 2012 Canonical Ltd.
46+ * Copyright (C) 2012-2013 Canonical Ltd.
47+ * Copyright (C) 2013 Jolla Ltd.
48 *
49 * This program is free software; you can redistribute it and/or modify
50 * it under the terms of the GNU General Public License version 2 as
51@@ -43,8 +44,8 @@
52 #include "grilutil.h"
53
54 #define RIL_TRACE(ril, fmt, arg...) do { \
55- if (ril->trace == TRUE) \
56- ofono_debug(fmt, ## arg); \
57+ if (ril->trace == TRUE) \
58+ ofono_debug(fmt, ## arg); \
59 } while (0)
60
61 #define COMMAND_FLAG_EXPECT_PDU 0x1
62@@ -97,7 +98,6 @@
63 gpointer debug_data; /* Data to pass to debug func */
64 gboolean debug;
65 gboolean trace;
66- GSList *response_lines; /* char * lines of the response */
67 gint timeout_source;
68 gboolean destroyed; /* Re-entrancy guard */
69 gboolean in_read_handler; /* Re-entrancy guard */
70@@ -246,11 +246,11 @@
71 DBG("req: %s, id: %d, data_len: %d",
72 ril_request_id_to_string(req), id, (int) data_len);
73
74- /* RIL request: 8 byte header + data */
75- len = 8 + data_len;
76+ /* RIL request: 8 byte header + data */
77+ len = 8 + data_len;
78
79- /* Add 4 bytes to buffer length to include length prefix */
80- r->data_len = len + 4;
81+ /* Add 4 bytes to buffer length to include length prefix */
82+ r->data_len = len + 4;
83
84 r->data = g_try_new(char, r->data_len);
85 if (r->data == NULL) {
86@@ -259,12 +259,12 @@
87 return 0;
88 }
89
90- /* convert length to network byte order (Big Endian) */
91- net_length = (guint32 *) r->data;
92- *net_length = htonl(len);
93+ /* convert length to network byte order (Big Endian) */
94+ net_length = (guint32 *) r->data;
95+ *net_length = htonl(len);
96
97 /* advance past initial length */
98- cur_bufp = r->data + 4;
99+ cur_bufp = r->data + 4;
100
101 /* write request code */
102 request = (guint32 *) cur_bufp;
103@@ -303,12 +303,7 @@
104 /* Cleanup pending commands */
105
106 g_queue_free(p->command_queue);
107- p->command_queue = NULL;
108-
109- /* Cleanup any response lines we have pending */
110- g_slist_foreach(p->response_lines, (GFunc)g_free, NULL);
111- g_slist_free(p->response_lines);
112- p->response_lines = NULL;
113+ p->command_queue = NULL;
114
115 p->connected = FALSE;
116
117@@ -357,9 +352,9 @@
118
119 if (message->error != RIL_E_SUCCESS)
120 RIL_TRACE(p, "[%04d]< %s failed %s",
121- message->serial_no,
122- ril_request_id_to_string(message->req),
123- ril_error_to_string(message->error));
124+ message->serial_no,
125+ ril_request_id_to_string(message->req),
126+ ril_error_to_string(message->error));
127
128 req = g_queue_pop_nth(p->command_queue, i);
129 if (req->callback)
130@@ -411,9 +406,8 @@
131
132 g_hash_table_iter_init(&iter, p->notify_list);
133
134- if (message->req == RIL_UNSOL_RIL_CONNECTED) {
135+ if (message->req == RIL_UNSOL_RIL_CONNECTED)
136 p->connected = TRUE;
137- }
138
139 while (g_hash_table_iter_next(&iter, &key, &value)) {
140 req_key = *((int *)key);
141@@ -462,9 +456,9 @@
142 message->req = (int) *id_num_field;
143
144 /*
145- * A RIL Unsolicited Event is two UINT32 fields ( unsolicited, and req/ev ),
146- * so subtract the length of the header from the overall length to calculate
147- * the length of the Event Data.
148+ * A RIL Unsolicited Event is two UINT32 fields ( unsolicited,
149+ * and req/ev ), so subtract the length of the header from the
150+ * overall length to calculate the length of the Event Data.
151 */
152 data_len = message->buf_len - 8;
153 } else {
154@@ -474,14 +468,15 @@
155 message->error = *((guint32 *) bufp);
156
157 /*
158- * A RIL Solicited Response is three UINT32 fields ( unsolicied, serial_no
159- * and error ), so subtract the length of the header from the overall length
160- * to calculate the length of the Event Data.
161+ * A RIL Solicited Response is three UINT32 fields ( unsolicied,
162+ * serial_no and error ), so subtract the length of the header
163+ * from the overall length to calculate the length of the Event
164+ * Data.
165 */
166 data_len = message->buf_len - 12;
167 }
168
169- /* advance to start of data.. */
170+ /* advance to start of data.. */
171 bufp += 4;
172
173 /* Now, allocate new buffer for data only, copy from
174@@ -503,11 +498,11 @@
175 message->buf_len = data_len;
176 }
177
178- if (message->unsolicited == TRUE) {
179+ if (message->unsolicited == TRUE)
180 handle_unsol_req(p, message);
181- } else {
182+ else
183 handle_response(p, message);
184- }
185+
186 error:
187 g_free(message->buf);
188 g_free(message);
189@@ -539,22 +534,21 @@
190 */
191
192 message_len = *len - 4;
193- if (message_len < plen) {
194+ if (message_len < plen)
195 return NULL;
196- }
197
198 /* FIXME: add check for message_len = 0? */
199
200- message = g_try_malloc(sizeof(struct ril_msg));
201- g_assert(message != NULL);
202-
203- /* allocate ril_msg->buffer */
204- message->buf_len = plen;
205- message->buf = g_try_malloc(plen);
206- g_assert(message->buf != NULL);
207-
208- /* Copy bytes into message buffer */
209- memmove(message->buf, (const void *) bytes, plen);
210+ message = g_try_malloc(sizeof(struct ril_msg));
211+ g_assert(message != NULL);
212+
213+ /* allocate ril_msg->buffer */
214+ message->buf_len = plen;
215+ message->buf = g_try_malloc(plen);
216+ g_assert(message->buf != NULL);
217+
218+ /* Copy bytes into message buffer */
219+ memmove(message->buf, (const void *) bytes, plen);
220
221 /* Indicate to caller size of record we extracted */
222 *len = plen + 4;
223@@ -649,7 +643,7 @@
224 if (ril->req_bytes_written >= len)
225 return FALSE;
226
227- /*
228+ /*
229 * AT modems need to be woken up via a command set by the
230 * upper layers. RIL has no such concept, hence wakeup needed
231 * NOTE - I'm keeping the if statement here commented out, just
232@@ -657,7 +651,8 @@
233 *
234 * if (ril->req_bytes_written == 0 && wakeup_first == TRUE) {
235 * cmd = at_command_create(0, chat->wakeup, none_prefix, 0,
236- * NULL, wakeup_cb, chat, NULL, TRUE);
237+ * NULL, wakeup_cb, chat, NULL,
238+ * TRUE);
239 * g_queue_push_head(chat->command_queue, cmd);
240 * len = strlen(chat->wakeup);
241 * chat->timeout_source = g_timeout_add(chat->wakeup_timeout,
242@@ -697,7 +692,7 @@
243
244 g_ril_io_set_write_handler(ril->io, NULL, NULL);
245 g_ril_io_set_read_handler(ril->io, NULL, NULL);
246- g_ril_io_set_debug(ril->io, NULL, NULL);
247+ g_ril_io_set_debug(ril->io, NULL, NULL);
248 }
249
250 /*
251@@ -711,9 +706,9 @@
252 ril->suspended = FALSE;
253
254 if (g_ril_io_get_channel(ril->io) == NULL) {
255- io_disconnect(ril);
256- return;
257- }
258+ io_disconnect(ril);
259+ return;
260+ }
261
262 g_ril_io_set_disconnect_function(ril->io, io_disconnect, ril);
263
264@@ -722,7 +717,7 @@
265 g_ril_io_set_read_handler(ril->io, new_bytes, ril);
266
267 if (g_queue_get_length(ril->command_queue) > 0)
268- ril_wakeup_writer(ril);
269+ ril_wakeup_writer(ril);
270 }
271
272 static gboolean ril_set_debug(struct ril_s *ril,
273@@ -747,12 +742,12 @@
274 if (is_zero == FALSE)
275 return;
276
277- if (ril->io) {
278- ril_suspend(ril);
279+ if (ril->io) {
280+ ril_suspend(ril);
281 g_ril_io_unref(ril->io);
282- ril->io = NULL;
283- ril_cleanup(ril);
284- }
285+ ril->io = NULL;
286+ ril_cleanup(ril);
287+ }
288
289 if (ril->in_read_handler)
290 ril->destroyed = TRUE;
291@@ -809,20 +804,20 @@
292 goto error;
293 }
294
295- io = g_io_channel_unix_new(sk);
296- if (io == NULL) {
297+ io = g_io_channel_unix_new(sk);
298+ if (io == NULL) {
299 ofono_error("create_ril: can't connect to RILD: %s (%d)\n",
300 strerror(errno), errno);
301 return NULL;
302- }
303+ }
304
305 g_io_channel_set_close_on_unref(io, TRUE);
306 g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
307
308- ril->io = g_ril_io_new(io);
309- if (ril->io == NULL) {
310+ ril->io = g_ril_io_new(io);
311+ if (ril->io == NULL) {
312 ofono_error("create_ril: can't create ril->io");
313- goto error;
314+ goto error;
315 }
316
317 g_ril_io_set_disconnect_function(ril->io, io_disconnect, ril);
318@@ -834,7 +829,8 @@
319 }
320
321 ril->notify_list = g_hash_table_new_full(g_int_hash, g_int_equal,
322- g_free, ril_notify_destroy);
323+ g_free,
324+ ril_notify_destroy);
325
326 g_ril_io_set_read_handler(ril->io, new_bytes, ril);
327
328@@ -866,6 +862,31 @@
329 return notify;
330 }
331
332+static void ril_cancel_group(struct ril_s *ril, guint group)
333+{
334+ int n = 0;
335+ struct ril_request *req;
336+
337+ if (ril->command_queue == NULL)
338+ return;
339+
340+ while ((req = g_queue_peek_nth(ril->command_queue, n)) != NULL) {
341+ if (req->gid != group) {
342+ n += 1;
343+ continue;
344+ }
345+
346+ if (n == 0 && ril->req_bytes_written > 0) {
347+ req->callback = NULL;
348+ n += 1;
349+ continue;
350+ }
351+
352+ g_queue_remove(ril->command_queue, req);
353+ ril_request_destroy(req);
354+ }
355+}
356+
357 static guint ril_register(struct ril_s *ril, guint group,
358 const int req, GRilNotifyFunc func,
359 gpointer user_data)
360@@ -1011,7 +1032,7 @@
361 GIOChannel *g_ril_get_channel(GRil *ril)
362 {
363 if (ril == NULL || ril->parent->io == NULL)
364- return NULL;
365+ return NULL;
366
367 return g_ril_io_get_channel(ril->parent->io);
368
369@@ -1042,10 +1063,12 @@
370 struct ril_request *r;
371 struct ril_s *p;
372
373- if (ril == NULL || ril->parent == NULL || ril->parent->command_queue == NULL)
374- return 0;
375+ if (ril == NULL
376+ || ril->parent == NULL
377+ || ril->parent->command_queue == NULL)
378+ return 0;
379
380- p = ril->parent;
381+ p = ril->parent;
382
383 r = ril_request_create(p, ril->group, reqid, p->next_cmd_id,
384 data, data_len, func,
385@@ -1058,7 +1081,8 @@
386 g_queue_push_tail(p->command_queue, r);
387
388 if (g_queue_get_length(p->command_queue) == 1) {
389- DBG("calling wakeup_writer: qlen: %d", g_queue_get_length(p->command_queue));
390+ DBG("calling wakeup_writer: qlen: %d",
391+ g_queue_get_length(p->command_queue));
392 ril_wakeup_writer(p);
393 }
394
395@@ -1093,6 +1117,8 @@
396 if (is_zero == FALSE)
397 return;
398
399+ ril_cancel_group(ril->parent, ril->group);
400+ g_ril_unregister_all(ril);
401 ril_unref(ril->parent);
402
403 g_free(ril);
404@@ -1113,7 +1139,7 @@
405 if (ril == NULL || ril->parent == NULL)
406 return FALSE;
407
408- return (ril->parent->trace = trace);
409+ return ril->parent->trace = trace;
410 }
411
412 gboolean g_ril_set_debugf(GRil *ril,
413
414=== modified file 'gril/grilrequest.c'
415--- gril/grilrequest.c 2013-09-09 19:21:32 +0000
416+++ gril/grilrequest.c 2013-10-04 03:07:28 +0000
417@@ -40,6 +40,9 @@
418 /* DEACTIVATE_DATA_CALL request parameters */
419 #define DEACTIVATE_DATA_CALL_NUM_PARAMS 2
420
421+/* POWER request parameters */
422+#define POWER_PARAMS 1
423+
424 /* SETUP_DATA_CALL_PARAMS request parameters */
425 #define SETUP_DATA_CALL_PARAMS 7
426 #define DATA_PROFILE_DEFAULT_STR "0"
427@@ -104,6 +107,19 @@
428 return FALSE;
429 }
430
431+void g_ril_request_power(GRil *gril,
432+ const gboolean power,
433+ struct parcel *rilp)
434+{
435+ DBG("");
436+
437+ parcel_init(rilp);
438+ parcel_w_int32(rilp, POWER_PARAMS);
439+ parcel_w_int32(rilp, (int32_t) power);
440+
441+ g_ril_append_print_buf(gril, "(%d)", power);
442+}
443+
444 gboolean g_ril_request_setup_data_call(GRil *gril,
445 const struct req_setup_data_call *req,
446 struct parcel *rilp,
447
448=== modified file 'gril/grilrequest.h'
449--- gril/grilrequest.h 2013-09-09 19:21:32 +0000
450+++ gril/grilrequest.h 2013-10-04 03:07:28 +0000
451@@ -51,6 +51,10 @@
452 struct parcel *rilp,
453 struct ofono_error *error);
454
455+void g_ril_request_power(GRil *gril,
456+ gboolean power,
457+ struct parcel *rilp);
458+
459 gboolean g_ril_request_setup_data_call(GRil *gril,
460 const struct req_setup_data_call *req,
461 struct parcel *rilp,
462
463=== modified file 'plugins/ril.c'
464--- plugins/ril.c 2013-09-09 19:21:32 +0000
465+++ plugins/ril.c 2013-10-04 03:07:28 +0000
466@@ -3,7 +3,8 @@
467 * oFono - Open Source Telephony - RIL-based devices
468 *
469 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
470- * Copyright (C) 2012 Canonical Ltd.
471+ * Copyright (C) 2012-2013 Canonical Ltd.
472+ * Copyright (C) 2013 Jolla Ltd.
473 *
474 * This program is free software; you can redistribute it and/or modify
475 * it under the terms of the GNU General Public License version 2 as
476@@ -57,20 +58,16 @@
477
478 #include "drivers/rilmodem/rilmodem.h"
479
480-#define MAX_POWER_ON_RETRIES 5
481 #define MAX_SIM_STATUS_RETRIES 15
482
483 struct ril_data {
484 GRil *modem;
485- int power_on_retries;
486 int sim_status_retries;
487 ofono_bool_t connected;
488 ofono_bool_t have_sim;
489- ofono_bool_t online;
490- ofono_bool_t reported;
491 };
492
493-static int send_get_sim_status(struct ofono_modem *modem);
494+static void send_get_sim_status(struct ofono_modem *modem);
495 static gboolean power_on(gpointer user_data);
496
497 static void ril_debug(const char *str, void *user_data)
498@@ -80,48 +77,10 @@
499 ofono_info("%s%s", prefix, str);
500 }
501
502-static void power_cb(struct ril_msg *message, gpointer user_data)
503-{
504- struct ofono_modem *modem = user_data;
505- struct ril_data *ril = ofono_modem_get_data(modem);
506-
507- if (message->error != RIL_E_SUCCESS) {
508- ril->power_on_retries++;
509- ofono_warn("Radio Power On request failed: %s; retries: %d",
510- ril_error_to_string(message->error),
511- ril->power_on_retries);
512-
513- if (ril->power_on_retries < MAX_POWER_ON_RETRIES)
514- g_timeout_add_seconds(1, power_on, modem);
515- else
516- ofono_error("Max retries for radio power on exceeded!");
517- } else {
518-
519- g_ril_print_response_no_args(ril->modem, message);
520- DBG("Radio POWER-ON OK, calling set_powered(TRUE).");
521- ofono_modem_set_powered(modem, TRUE);
522- }
523-}
524-
525-static gboolean power_on(gpointer user_data)
526-{
527- struct ofono_modem *modem = user_data;
528- struct parcel rilp;
529- struct ril_data *ril = ofono_modem_get_data(modem);
530- int request = RIL_REQUEST_RADIO_POWER;
531- guint ret;
532-
533- parcel_init(&rilp);
534- parcel_w_int32(&rilp, 1); /* size of array */
535- parcel_w_int32(&rilp, 1); /* POWER=ON */
536-
537- ret = g_ril_send(ril->modem, request,
538- rilp.data, rilp.size, power_cb, modem, NULL);
539-
540- g_ril_append_print_buf(ril->modem, "(1)");
541- g_ril_print_request(ril->modem, ret, request);
542-
543- parcel_free(&rilp);
544+static gboolean sim_status_retry(gpointer user_data)
545+{
546+ struct ofono_modem *modem = user_data;
547+ send_get_sim_status(modem);
548
549 /* Makes this a single shot */
550 return FALSE;
551@@ -151,7 +110,7 @@
552 message->error, ril->sim_status_retries);
553
554 if (ril->sim_status_retries < MAX_SIM_STATUS_RETRIES)
555- g_timeout_add_seconds(2, (GSourceFunc) send_get_sim_status, (gpointer) modem);
556+ g_timeout_add_seconds(2, sim_status_retry, modem);
557 else
558 ofono_error("Max retries for GET_SIM_STATUS exceeded!");
559 } else {
560@@ -166,14 +125,16 @@
561 ril_util_free_sim_apps(apps, status.num_apps);
562
563 ril->have_sim = TRUE;
564- power_on(modem);
565 } else
566 ofono_warn("No SIM card present.");
567+
568+ DBG("calling set_powered(TRUE)");
569+ ofono_modem_set_powered(modem, TRUE);
570 }
571 /* TODO: handle emergency calls if SIM !present or locked */
572 }
573
574-static int send_get_sim_status(struct ofono_modem *modem)
575+static void send_get_sim_status(struct ofono_modem *modem)
576 {
577 struct ril_data *ril = ofono_modem_get_data(modem);
578 int request = RIL_REQUEST_GET_SIM_STATUS;
579@@ -182,9 +143,8 @@
580 ret = g_ril_send(ril->modem, request,
581 NULL, 0, sim_status_cb, modem, NULL);
582
583- g_ril_print_request_no_args(ril->modem, ret, request);
584-
585- return ret;
586+ if (ret > 0)
587+ g_ril_print_request_no_args(ril->modem, ret, request);
588 }
589
590 static int ril_probe(struct ofono_modem *modem)
591@@ -197,7 +157,7 @@
592 goto error;
593 }
594
595- ril->modem = NULL;
596+ ril->modem = NULL;
597
598 ofono_modem_set_data(modem, ril);
599
600@@ -229,9 +189,8 @@
601 struct ril_data *ril = ofono_modem_get_data(modem);
602 struct ofono_sim *sim;
603
604- sim = ofono_sim_create(modem, 0, "rilmodem", ril->modem);
605- ofono_devinfo_create(modem, 0, "rilmodem", ril->modem);
606- ofono_voicecall_create(modem, 0, "rilmodem", ril->modem);
607+ sim = ofono_sim_create(modem, 0, RILMODEM, ril->modem);
608+ ofono_voicecall_create(modem, 0, RILMODEM, ril->modem);
609
610 if (sim && ril->have_sim)
611 ofono_sim_inserted_notify(sim, TRUE);
612@@ -248,10 +207,10 @@
613 * - stk ( SIM toolkit )
614 * - radio_settings
615 */
616- ofono_sms_create(modem, 0, "rilmodem", ril->modem);
617+ ofono_sms_create(modem, 0, RILMODEM, ril->modem);
618
619- gprs = ofono_gprs_create(modem, 0, "rilmodem", ril->modem);
620- gc = ofono_gprs_context_create(modem, 0, "rilmodem", ril->modem);
621+ gprs = ofono_gprs_create(modem, 0, RILMODEM, ril->modem);
622+ gc = ofono_gprs_context_create(modem, 0, RILMODEM, ril->modem);
623
624 if (gprs && gc) {
625 DBG("calling gprs_add_context");
626@@ -263,8 +222,64 @@
627 {
628 struct ril_data *ril = ofono_modem_get_data(modem);
629
630- ofono_call_volume_create(modem, 0, "rilmodem", ril->modem);
631- ofono_netreg_create(modem, 0, "rilmodem", ril->modem);
632+ ofono_call_volume_create(modem, 0, RILMODEM, ril->modem);
633+ ofono_netreg_create(modem, 0, RILMODEM, ril->modem);
634+}
635+
636+static void ril_set_online_cb(struct ril_msg *message, gpointer user_data)
637+{
638+ ofono_bool_t online_state;
639+ struct cb_data *cbd = user_data;
640+ ofono_modem_online_cb_t cb = cbd->cb;
641+
642+ if (message->error == RIL_E_SUCCESS)
643+ CALLBACK_WITH_SUCCESS(cb, cbd->data);
644+ else
645+ CALLBACK_WITH_FAILURE(cb, cbd->data);
646+}
647+
648+static void ril_send_power(struct ril_data *ril, ofono_bool_t online,
649+ GRilResponseFunc func,
650+ ofono_modem_online_cb_t callback,
651+ void *data)
652+{
653+ struct cb_data *cbd;
654+ GDestroyNotify notify;
655+ int request = RIL_REQUEST_RADIO_POWER;
656+ struct parcel rilp;
657+ int ret;
658+
659+ if (callback) {
660+ cbd = cb_data_new(callback, data);
661+ notify = g_free;
662+ g_assert(func);
663+ } else {
664+ cbd = NULL;
665+ notify = NULL;
666+ }
667+
668+ DBG("(online = 1, offline = 0)): %i", online);
669+
670+ g_ril_request_power(ril->modem, (const gboolean) online, &rilp);
671+
672+ ret = g_ril_send(ril->modem, request, rilp.data,
673+ rilp.size, func, cbd, notify);
674+
675+ parcel_free(&rilp);
676+
677+ if (ret <= 0) {
678+ g_free(cbd);
679+ CALLBACK_WITH_FAILURE(callback, data);
680+ } else
681+ g_ril_print_request(ril->modem, ret, request);
682+
683+}
684+
685+static void ril_set_online(struct ofono_modem *modem, ofono_bool_t online,
686+ ofono_modem_online_cb_t callback, void *data)
687+{
688+ struct ril_data *ril = ofono_modem_get_data(modem);
689+ ril_send_power(ril, online, ril_set_online_cb, callback, data);
690 }
691
692 static void ril_connected(struct ril_msg *message, gpointer user_data)
693@@ -272,9 +287,7 @@
694 struct ofono_modem *modem = (struct ofono_modem *) user_data;
695 struct ril_data *ril = ofono_modem_get_data(modem);
696
697- /* TODO: make conditional */
698- ofono_debug("[UNSOL]< %s", ril_unsol_request_to_string(message->req));
699- /* TODO: make conditional */
700+ ofono_info("[UNSOL]< %s", ril_unsol_request_to_string(message->req));
701
702 /* TODO: need a disconnect function to restart things! */
703 ril->connected = TRUE;
704@@ -288,9 +301,9 @@
705
706 ril->have_sim = FALSE;
707
708- ril->modem = g_ril_new();
709+ ril->modem = g_ril_new();
710
711- /* NOTE: Since AT modems open a tty, and then call
712+ /* NOTE: Since AT modems open a tty, and then call
713 * g_at_chat_new(), they're able to return -EIO if
714 * the first fails, and -ENOMEM if the second fails.
715 * in our case, we already return -EIO if the ril_new
716@@ -298,28 +311,34 @@
717 * abstraction... ( probaby not a bad idea ).
718 */
719
720- if (ril->modem == NULL) {
721+ if (ril->modem == NULL) {
722 DBG("g_ril_new() failed to create modem!");
723 return -EIO;
724 }
725
726- if (getenv("OFONO_RIL_TRACE")) {
727+ if (getenv("OFONO_RIL_TRACE"))
728 g_ril_set_trace(ril->modem, TRUE);
729- }
730
731- if (getenv("OFONO_RIL_HEX_TRACE")) {
732+ if (getenv("OFONO_RIL_HEX_TRACE"))
733 g_ril_set_debugf(ril->modem, ril_debug, "Device: ");
734- }
735
736 g_ril_register(ril->modem, RIL_UNSOL_RIL_CONNECTED,
737 ril_connected, modem);
738
739- return -EINPROGRESS;
740+ ofono_devinfo_create(modem, 0, RILMODEM, ril->modem);
741+
742+ return -EINPROGRESS;
743 }
744
745 static int ril_disable(struct ofono_modem *modem)
746 {
747- return 0;
748+ struct ril_data *ril = ofono_modem_get_data(modem);
749+
750+ DBG("%p", modem);
751+
752+ ril_send_power(ril, FALSE, NULL, NULL, NULL);
753+
754+ return 0;
755 }
756
757 static struct ofono_modem_driver ril_driver = {
758@@ -331,6 +350,7 @@
759 .pre_sim = ril_pre_sim,
760 .post_sim = ril_post_sim,
761 .post_online = ril_post_online,
762+ .set_online = ril_set_online,
763 };
764
765 /*
766@@ -357,10 +377,10 @@
767
768 if ((retval = ofono_modem_driver_register(&ril_driver))) {
769 DBG("ofono_modem_driver_register returned: %d", retval);
770- return retval;
771- }
772+ return retval;
773+ }
774
775- /* everything after _modem_driver_register, is
776+ /* everything after _modem_driver_register, is
777 * non-standard ( see udev comment above ).
778 * usually called by undevng::create_modem
779 *
780@@ -376,7 +396,7 @@
781 retval = ofono_modem_register(modem);
782 DBG("ofono_modem_register returned: %d", retval);
783
784- /* kickstart the modem:
785+ /* kickstart the modem:
786 * causes core modem code to call
787 * - set_powered(TRUE) - which in turn
788 * calls driver->enable()
789
790=== modified file 'unit/test-grilrequest.c'
791--- unit/test-grilrequest.c 2013-09-09 19:21:32 +0000
792+++ unit/test-grilrequest.c 2013-10-04 03:07:28 +0000
793@@ -165,6 +165,37 @@
794 .protocol = OFONO_GPRS_PROTO_IPV6,
795 };
796
797+/*
798+ * The following hexadecimal data represents a serialized Binder parcel
799+ * instance containing a valid RIL_REQUEST_RADIO_POWER 'OFF' message.
800+ */
801+static const guchar req_power_off_valid_parcel1[8] = {
802+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
803+};
804+
805+/*
806+ * The following hexadecimal data represents a serialized Binder parcel
807+ * instance containing a valid RIL_REQUEST_RADIO_POWER 'ON' message.
808+ */
809+static const guchar req_power_on_valid_parcel2[8] = {
810+ 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00
811+};
812+
813+static const gboolean power_off = FALSE;
814+static const gboolean power_on = TRUE;
815+
816+static const struct request_test_data power_valid_test_1 = {
817+ .request = &power_off,
818+ .parcel_data = (guchar *) &req_power_off_valid_parcel1,
819+ .parcel_size = 8,
820+};
821+
822+static const struct request_test_data power_valid_test_2 = {
823+ .request = &power_on,
824+ .parcel_data = (guchar *) &req_power_on_valid_parcel2,
825+ .parcel_size = 8,
826+};
827+
828 static void test_deactivate_data_call_invalid(gconstpointer data)
829 {
830 const struct req_deactivate_data_call *request = data;
831@@ -234,6 +265,19 @@
832 /* TODO: add unit 3 tests to validate binary parcel result */
833 }
834
835+static void test_request_power_valid(gconstpointer data)
836+{
837+ const struct request_test_data *test_data = data;
838+ const gboolean *online = test_data->request;
839+ struct parcel rilp;
840+
841+ g_ril_request_power(NULL, *online, &rilp);
842+
843+ g_assert(!memcmp(rilp.data, test_data->parcel_data, test_data->parcel_size));
844+
845+ parcel_free(&rilp);
846+}
847+
848 int main(int argc, char **argv)
849 {
850 g_test_init(&argc, &argv, NULL);
851@@ -316,6 +360,16 @@
852 &req_setup_data_call_valid_4,
853 test_request_setup_data_call_valid);
854
855+ g_test_add_data_func("/testgrilrequest/power: "
856+ "valid POWER Test 1",
857+ &power_valid_test_1,
858+ test_request_power_valid);
859+
860+ g_test_add_data_func("/testgrilrequest/power: "
861+ "valid POWER Test 1",
862+ &power_valid_test_2,
863+ test_request_power_valid);
864+
865 #endif
866 return g_test_run();
867 }

Subscribers

People subscribed via source and target branches