3 * oFono - Open Source Telephony
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 #define CALL_SETTINGS_FLAG_CACHED 0x1
40 static GSList *g_drivers = NULL;
42 /* 27.007 Section 7.7 */
44 CLIR_STATUS_NOT_PROVISIONED = 0,
45 CLIR_STATUS_PROVISIONED_PERMANENT = 1,
46 CLIR_STATUS_UNKNOWN = 2,
47 CLIR_STATUS_TEMPORARY_RESTRICTED = 3,
48 CLIR_STATUS_TEMPORARY_ALLOWED = 4
51 /* 27.007 Section 7.6 */
53 CLIP_STATUS_NOT_PROVISIONED = 0,
54 CLIP_STATUS_PROVISIONED = 1,
55 CLIP_STATUS_UNKNOWN = 2
58 /* 27.007 Section 7.30 */
60 CNAP_STATUS_NOT_PROVISIONED = 0,
61 CNAP_STATUS_PROVISIONED = 1,
62 CNAP_STATUS_UNKNOWN = 2
65 /* 27.007 Section 7.8 */
67 COLP_STATUS_NOT_PROVISIONED = 0,
68 COLP_STATUS_PROVISIONED = 1,
69 COLP_STATUS_UNKNOWN = 2
72 /* 27.007 Section 7.9 */
74 CDIP_STATUS_NOT_PROVISIONED = 0,
75 CDIP_STATUS_PROVISIONED = 1,
76 CDIP_STATUS_UNKNOWN = 2
79 /* This is not defined in 27.007, but presumably the same as CLIP/COLP */
81 COLR_STATUS_NOT_PROVISIONED = 0,
82 COLR_STATUS_PROVISIONED = 1,
83 COLR_STATUS_UNKNOWN = 2
86 enum call_setting_type {
87 CALL_SETTING_TYPE_CLIP = 0,
88 CALL_SETTING_TYPE_CNAP,
89 CALL_SETTING_TYPE_CDIP,
90 CALL_SETTING_TYPE_COLP,
91 CALL_SETTING_TYPE_COLR,
92 CALL_SETTING_TYPE_CLIR,
96 struct ofono_call_settings {
106 DBusMessage *pending;
109 enum call_setting_type ss_setting;
110 struct ofono_ussd *ussd;
111 unsigned int ussd_watch;
112 const struct ofono_call_settings_driver *driver;
114 struct ofono_atom *atom;
117 static const char *clip_status_to_string(int status)
120 case CLIP_STATUS_NOT_PROVISIONED:
122 case CLIP_STATUS_PROVISIONED:
129 static const char *cdip_status_to_string(int status)
132 case CDIP_STATUS_NOT_PROVISIONED:
134 case CDIP_STATUS_PROVISIONED:
141 static const char *cnap_status_to_string(int status)
144 case CNAP_STATUS_NOT_PROVISIONED:
146 case CNAP_STATUS_PROVISIONED:
153 static const char *colp_status_to_string(int status)
156 case COLP_STATUS_NOT_PROVISIONED:
158 case COLP_STATUS_PROVISIONED:
165 static const char *colr_status_to_string(int status)
168 case COLR_STATUS_NOT_PROVISIONED:
170 case COLR_STATUS_PROVISIONED:
177 static const char *hide_callerid_to_string(int status)
180 case OFONO_CLIR_OPTION_DEFAULT:
182 case OFONO_CLIR_OPTION_INVOCATION:
184 case OFONO_CLIR_OPTION_SUPPRESSION:
191 static const char *clir_status_to_string(int status)
194 case CLIR_STATUS_NOT_PROVISIONED:
196 case CLIR_STATUS_PROVISIONED_PERMANENT:
198 case CLIR_STATUS_TEMPORARY_RESTRICTED:
200 case CLIR_STATUS_TEMPORARY_ALLOWED:
207 static void set_clir_network(struct ofono_call_settings *cs, int clir)
209 DBusConnection *conn;
213 if (cs->clir == clir)
218 conn = ofono_dbus_get_connection();
219 path = __ofono_atom_get_path(cs->atom);
221 str = clir_status_to_string(clir);
223 ofono_dbus_signal_property_changed(conn, path,
224 OFONO_CALL_SETTINGS_INTERFACE,
225 "CallingLineRestriction",
226 DBUS_TYPE_STRING, &str);
229 static void set_clir_override(struct ofono_call_settings *cs, int override)
231 DBusConnection *conn;
235 if (cs->clir_setting == override)
238 cs->clir_setting = override;
240 conn = ofono_dbus_get_connection();
241 path = __ofono_atom_get_path(cs->atom);
243 str = hide_callerid_to_string(override);
245 ofono_dbus_signal_property_changed(conn, path,
246 OFONO_CALL_SETTINGS_INTERFACE,
248 DBUS_TYPE_STRING, &str);
251 static void set_cdip(struct ofono_call_settings *cs, int cdip)
253 DBusConnection *conn;
257 if (cs->cdip == cdip)
262 conn = ofono_dbus_get_connection();
263 path = __ofono_atom_get_path(cs->atom);
265 str = cdip_status_to_string(cdip);
267 ofono_dbus_signal_property_changed(conn, path,
268 OFONO_CALL_SETTINGS_INTERFACE,
269 "CalledLinePresentation",
270 DBUS_TYPE_STRING, &str);
273 static void set_clip(struct ofono_call_settings *cs, int clip)
275 DBusConnection *conn;
279 if (cs->clip == clip)
284 conn = ofono_dbus_get_connection();
285 path = __ofono_atom_get_path(cs->atom);
287 str = clip_status_to_string(clip);
289 ofono_dbus_signal_property_changed(conn, path,
290 OFONO_CALL_SETTINGS_INTERFACE,
291 "CallingLinePresentation",
292 DBUS_TYPE_STRING, &str);
295 static void set_cnap(struct ofono_call_settings *cs, int cnap)
297 DBusConnection *conn;
301 if (cs->cnap == cnap)
306 conn = ofono_dbus_get_connection();
307 path = __ofono_atom_get_path(cs->atom);
309 str = cnap_status_to_string(cnap);
311 ofono_dbus_signal_property_changed(conn, path,
312 OFONO_CALL_SETTINGS_INTERFACE,
313 "CallingNamePresentation",
314 DBUS_TYPE_STRING, &str);
317 static void set_colp(struct ofono_call_settings *cs, int colp)
319 DBusConnection *conn;
323 if (cs->colp == colp)
328 conn = ofono_dbus_get_connection();
329 path = __ofono_atom_get_path(cs->atom);
331 str = colp_status_to_string(colp);
333 ofono_dbus_signal_property_changed(conn, path,
334 OFONO_CALL_SETTINGS_INTERFACE,
335 "ConnectedLinePresentation",
336 DBUS_TYPE_STRING, &str);
339 static void set_colr(struct ofono_call_settings *cs, int colr)
341 DBusConnection *conn;
345 if (cs->colr == colr)
350 conn = ofono_dbus_get_connection();
351 path = __ofono_atom_get_path(cs->atom);
353 str = colr_status_to_string(colr);
355 ofono_dbus_signal_property_changed(conn, path,
356 OFONO_CALL_SETTINGS_INTERFACE,
357 "ConnectedLineRestriction",
358 DBUS_TYPE_STRING, &str);
361 static void set_cw(struct ofono_call_settings *cs, int new_cw, int mask)
363 DBusConnection *conn = ofono_dbus_get_connection();
364 const char *path = __ofono_atom_get_path(cs->atom);
369 for (j = 1; j <= BEARER_CLASS_PAD; j = j << 1) {
373 if ((cs->cw & j) == (new_cw & j))
381 snprintf(buf, sizeof(buf), "%sCallWaiting",
382 bearer_class_to_string(j));
383 ofono_dbus_signal_property_changed(conn, path,
384 OFONO_CALL_SETTINGS_INTERFACE,
385 buf, DBUS_TYPE_STRING,
392 static void property_append_cw_conditions(DBusMessageIter *dict,
393 int conditions, int mask)
399 for (i = 1; i <= BEARER_CLASS_PAD; i = i << 1) {
403 snprintf(prop, sizeof(prop), "%sCallWaiting",
404 bearer_class_to_string(i));
411 ofono_dbus_dict_append(dict, prop, DBUS_TYPE_STRING, &value);
415 static void generate_cw_ss_query_reply(struct ofono_call_settings *cs)
417 const char *sig = "(sa{sv})";
418 const char *ss_type = ss_control_type_to_string(cs->ss_req_type);
419 const char *context = "CallWaiting";
420 DBusMessageIter iter;
422 DBusMessageIter vstruct;
423 DBusMessageIter dict;
426 reply = dbus_message_new_method_return(cs->pending);
428 dbus_message_iter_init_append(reply, &iter);
430 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &context);
432 dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, sig, &var);
434 dbus_message_iter_open_container(&var, DBUS_TYPE_STRUCT, NULL,
437 dbus_message_iter_append_basic(&vstruct, DBUS_TYPE_STRING,
440 dbus_message_iter_open_container(&vstruct, DBUS_TYPE_ARRAY,
441 OFONO_PROPERTIES_ARRAY_SIGNATURE,
444 property_append_cw_conditions(&dict, cs->cw, cs->ss_req_cls);
446 dbus_message_iter_close_container(&vstruct, &dict);
448 dbus_message_iter_close_container(&var, &vstruct);
450 dbus_message_iter_close_container(&iter, &var);
452 __ofono_dbus_pending_reply(&cs->pending, reply);
455 static void cw_ss_query_callback(const struct ofono_error *error, int status,
458 struct ofono_call_settings *cs = data;
460 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
461 DBG("setting CW via SS failed");
463 cs->flags &= ~CALL_SETTINGS_FLAG_CACHED;
464 __ofono_dbus_pending_reply(&cs->pending,
465 __ofono_error_failed(cs->pending));
470 set_cw(cs, status, BEARER_CLASS_VOICE);
472 generate_cw_ss_query_reply(cs);
475 static void cw_ss_set_callback(const struct ofono_error *error, void *data)
477 struct ofono_call_settings *cs = data;
479 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
480 DBG("setting CW via SS failed with error: %s",
481 telephony_error_to_str(error));
482 __ofono_dbus_pending_reply(&cs->pending,
483 __ofono_error_from_error(error, cs->pending));
488 cs->driver->cw_query(cs, BEARER_CLASS_DEFAULT,
489 cw_ss_query_callback, cs);
492 static gboolean cw_ss_control(int type,
493 const char *sc, const char *sia,
494 const char *sib, const char *sic,
495 const char *dn, DBusMessage *msg, void *data)
497 struct ofono_call_settings *cs = data;
498 DBusConnection *conn = ofono_dbus_get_connection();
499 int cls = BEARER_CLASS_SS_DEFAULT;
505 if (strcmp(sc, "43"))
508 if (__ofono_call_settings_is_busy(cs)) {
509 reply = __ofono_error_busy(msg);
513 if (strlen(sib) || strlen(sib) || strlen(dn))
516 if ((type == SS_CONTROL_TYPE_QUERY && cs->driver->cw_query == NULL) ||
517 (type != SS_CONTROL_TYPE_QUERY && cs->driver->cw_set == NULL)) {
518 reply = __ofono_error_not_implemented(msg);
522 if (strlen(sia) > 0) {
526 service_code = strtoul(sia, &end, 10);
528 if (end == sia || *end != '\0')
531 cls = mmi_service_code_to_bearer_class(service_code);
536 cs->ss_req_cls = cls;
537 cs->pending = dbus_message_ref(msg);
539 /* For the default case use the more readily accepted value */
540 if (cls == BEARER_CLASS_SS_DEFAULT)
541 cls = BEARER_CLASS_DEFAULT;
544 case SS_CONTROL_TYPE_REGISTRATION:
545 case SS_CONTROL_TYPE_ACTIVATION:
546 cs->ss_req_type = SS_CONTROL_TYPE_ACTIVATION;
547 cs->driver->cw_set(cs, 1, cls, cw_ss_set_callback, cs);
550 case SS_CONTROL_TYPE_QUERY:
551 cs->ss_req_type = SS_CONTROL_TYPE_QUERY;
553 * Always query the entire set, SMS not applicable
554 * according to 22.004 Appendix A, so CLASS_DEFAULT
555 * is safe to use here
557 cs->driver->cw_query(cs, BEARER_CLASS_DEFAULT,
558 cw_ss_query_callback, cs);
561 case SS_CONTROL_TYPE_DEACTIVATION:
562 case SS_CONTROL_TYPE_ERASURE:
563 cs->ss_req_type = SS_CONTROL_TYPE_DEACTIVATION;
564 cs->driver->cw_set(cs, 0, cls, cw_ss_set_callback, cs);
571 reply = __ofono_error_invalid_format(msg);
573 g_dbus_send_message(conn, reply);
577 static void generate_ss_query_reply(struct ofono_call_settings *cs,
578 const char *context, const char *value)
580 const char *sig = "(ss)";
581 const char *ss_type = ss_control_type_to_string(cs->ss_req_type);
582 DBusMessageIter iter;
584 DBusMessageIter vstruct;
587 reply = dbus_message_new_method_return(cs->pending);
589 dbus_message_iter_init_append(reply, &iter);
591 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &context);
593 dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, sig, &var);
595 dbus_message_iter_open_container(&var, DBUS_TYPE_STRUCT, NULL,
598 dbus_message_iter_append_basic(&vstruct, DBUS_TYPE_STRING,
601 dbus_message_iter_append_basic(&vstruct, DBUS_TYPE_STRING, &value);
603 dbus_message_iter_close_container(&var, &vstruct);
605 dbus_message_iter_close_container(&iter, &var);
607 __ofono_dbus_pending_reply(&cs->pending, reply);
610 static void clip_cnap_colp_colr_ss_query_cb(const struct ofono_error *error,
611 int status, void *data)
613 struct ofono_call_settings *cs = data;
617 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
618 DBG("SS control query failed with error: %s",
619 telephony_error_to_str(error));
620 __ofono_dbus_pending_reply(&cs->pending,
621 __ofono_error_from_error(error, cs->pending));
626 switch (cs->ss_setting) {
627 case CALL_SETTING_TYPE_CLIP:
628 set_clip(cs, status);
629 value = clip_status_to_string(status);
630 context = "CallingLinePresentation";
633 case CALL_SETTING_TYPE_CNAP:
634 set_cnap(cs, status);
635 value = cnap_status_to_string(status);
636 context = "CallingNamePresentation";
640 case CALL_SETTING_TYPE_COLP:
641 set_colp(cs, status);
642 value = colp_status_to_string(status);
643 context = "ConnectedLinePresentation";
646 case CALL_SETTING_TYPE_COLR:
647 set_colr(cs, status);
648 value = colr_status_to_string(status);
649 context = "ConnectedLineRestriction";
653 __ofono_dbus_pending_reply(&cs->pending,
654 __ofono_error_failed(cs->pending));
655 ofono_error("Unknown type during COLR/COLP/CLIP/CNAP ss");
659 generate_ss_query_reply(cs, context, value);
662 static gboolean clip_cnap_colp_colr_ss(int type,
663 const char *sc, const char *sia,
664 const char *sib, const char *sic,
665 const char *dn, DBusMessage *msg, void *data)
667 struct ofono_call_settings *cs = data;
668 DBusConnection *conn = ofono_dbus_get_connection();
669 void (*query_op)(struct ofono_call_settings *cs,
670 ofono_call_settings_status_cb_t cb, void *data);
675 if (__ofono_call_settings_is_busy(cs)) {
676 DBusMessage *reply = __ofono_error_busy(msg);
677 g_dbus_send_message(conn, reply);
682 if (!strcmp(sc, "30")) {
683 cs->ss_setting = CALL_SETTING_TYPE_CLIP;
684 query_op = cs->driver->clip_query;
685 } else if (!strcmp(sc, "300")) {
686 cs->ss_setting = CALL_SETTING_TYPE_CNAP;
687 query_op = cs->driver->cnap_query;
688 } else if (!strcmp(sc, "76")) {
689 cs->ss_setting = CALL_SETTING_TYPE_COLP;
690 query_op = cs->driver->colp_query;
691 } else if (!strcmp(sc, "77")) {
692 cs->ss_setting = CALL_SETTING_TYPE_COLR;
693 query_op = cs->driver->colr_query;
698 if (type != SS_CONTROL_TYPE_QUERY || strlen(sia) || strlen(sib) ||
699 strlen(sic) || strlen(dn)) {
700 DBusMessage *reply = __ofono_error_invalid_format(msg);
701 g_dbus_send_message(conn, reply);
706 if (query_op == NULL) {
707 DBusMessage *reply = __ofono_error_not_implemented(msg);
708 g_dbus_send_message(conn, reply);
713 DBG("Received CLIP/CNAP/COLR/COLP query ss control");
715 cs->pending = dbus_message_ref(msg);
717 query_op(cs, clip_cnap_colp_colr_ss_query_cb, cs);
722 static void clir_ss_query_callback(const struct ofono_error *error,
723 int override, int network, void *data)
725 struct ofono_call_settings *cs = data;
728 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
729 DBG("setting clir via SS failed");
730 __ofono_dbus_pending_reply(&cs->pending,
731 __ofono_error_failed(cs->pending));
737 case CLIR_STATUS_UNKNOWN:
741 case CLIR_STATUS_PROVISIONED_PERMANENT:
745 case CLIR_STATUS_NOT_PROVISIONED:
749 case CLIR_STATUS_TEMPORARY_RESTRICTED:
750 if (override == OFONO_CLIR_OPTION_SUPPRESSION)
756 case CLIR_STATUS_TEMPORARY_ALLOWED:
757 if (override == OFONO_CLIR_OPTION_INVOCATION)
766 generate_ss_query_reply(cs, "CallingLineRestriction", value);
768 set_clir_network(cs, network);
769 set_clir_override(cs, override);
772 static void clir_ss_set_callback(const struct ofono_error *error, void *data)
774 struct ofono_call_settings *cs = data;
776 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
777 DBG("setting clir via SS failed with error: %s",
778 telephony_error_to_str(error));
779 __ofono_dbus_pending_reply(&cs->pending,
780 __ofono_error_from_error(error, cs->pending));
785 cs->driver->clir_query(cs, clir_ss_query_callback, cs);
788 static gboolean clir_ss_control(int type,
789 const char *sc, const char *sia,
790 const char *sib, const char *sic,
791 const char *dn, DBusMessage *msg, void *data)
793 struct ofono_call_settings *cs = data;
794 DBusConnection *conn = ofono_dbus_get_connection();
799 if (strcmp(sc, "31"))
802 if (__ofono_call_settings_is_busy(cs)) {
803 DBusMessage *reply = __ofono_error_busy(msg);
804 g_dbus_send_message(conn, reply);
809 /* This is the temporary form of CLIR, handled in voicecalls */
810 if (!strlen(sia) && !strlen(sib) & !strlen(sic) &&
811 strlen(dn) && type != SS_CONTROL_TYPE_QUERY)
814 if (strlen(sia) || strlen(sib) || strlen(sic) || strlen(dn)) {
815 DBusMessage *reply = __ofono_error_invalid_format(msg);
816 g_dbus_send_message(conn, reply);
821 if (type == SS_CONTROL_TYPE_QUERY && cs->driver->clir_query == NULL) {
822 DBusMessage *reply = __ofono_error_not_implemented(msg);
823 g_dbus_send_message(conn, reply);
828 if (type != SS_CONTROL_TYPE_QUERY && cs->driver->clir_set == NULL) {
829 DBusMessage *reply = __ofono_error_not_implemented(msg);
830 g_dbus_send_message(conn, reply);
835 cs->ss_setting = CALL_SETTING_TYPE_CLIR;
836 cs->pending = dbus_message_ref(msg);
839 case SS_CONTROL_TYPE_REGISTRATION:
840 case SS_CONTROL_TYPE_ACTIVATION:
841 cs->ss_req_type = SS_CONTROL_TYPE_ACTIVATION;
842 cs->driver->clir_set(cs, OFONO_CLIR_OPTION_SUPPRESSION,
843 clir_ss_set_callback, cs);
846 case SS_CONTROL_TYPE_QUERY:
847 cs->ss_req_type = SS_CONTROL_TYPE_QUERY;
848 cs->driver->clir_query(cs, clir_ss_query_callback, cs);
851 case SS_CONTROL_TYPE_DEACTIVATION:
852 case SS_CONTROL_TYPE_ERASURE:
853 cs->ss_req_type = SS_CONTROL_TYPE_DEACTIVATION;
854 cs->driver->clir_set(cs, OFONO_CLIR_OPTION_INVOCATION,
855 clir_ss_set_callback, cs);
862 static void cs_register_ss_controls(struct ofono_call_settings *cs)
864 __ofono_ussd_ssc_register(cs->ussd, "30", clip_cnap_colp_colr_ss,
866 __ofono_ussd_ssc_register(cs->ussd, "31", clir_ss_control, cs, NULL);
867 __ofono_ussd_ssc_register(cs->ussd, "76", clip_cnap_colp_colr_ss,
869 __ofono_ussd_ssc_register(cs->ussd, "300", clip_cnap_colp_colr_ss,
872 __ofono_ussd_ssc_register(cs->ussd, "43", cw_ss_control, cs, NULL);
874 if (cs->driver->colr_query != NULL)
875 __ofono_ussd_ssc_register(cs->ussd, "77",
876 clip_cnap_colp_colr_ss, cs, NULL);
879 static void cs_unregister_ss_controls(struct ofono_call_settings *cs)
881 __ofono_ussd_ssc_unregister(cs->ussd, "30");
882 __ofono_ussd_ssc_unregister(cs->ussd, "31");
883 __ofono_ussd_ssc_unregister(cs->ussd, "76");
884 __ofono_ussd_ssc_unregister(cs->ussd, "300");
886 __ofono_ussd_ssc_unregister(cs->ussd, "43");
888 if (cs->driver->colr_query != NULL)
889 __ofono_ussd_ssc_unregister(cs->ussd, "77");
892 gboolean __ofono_call_settings_is_busy(struct ofono_call_settings *cs)
894 return cs->pending ? TRUE : FALSE;
897 static DBusMessage *generate_get_properties_reply(struct ofono_call_settings *cs,
901 DBusMessageIter iter;
902 DBusMessageIter dict;
905 reply = dbus_message_new_method_return(msg);
909 dbus_message_iter_init_append(reply, &iter);
911 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
912 OFONO_PROPERTIES_ARRAY_SIGNATURE,
915 str = clip_status_to_string(cs->clip);
916 ofono_dbus_dict_append(&dict, "CallingLinePresentation",
917 DBUS_TYPE_STRING, &str);
919 str = cnap_status_to_string(cs->cnap);
920 ofono_dbus_dict_append(&dict, "CallingNamePresentation",
921 DBUS_TYPE_STRING, &str);
923 str = colp_status_to_string(cs->colp);
924 ofono_dbus_dict_append(&dict, "ConnectedLinePresentation",
925 DBUS_TYPE_STRING, &str);
927 str = colr_status_to_string(cs->colr);
928 ofono_dbus_dict_append(&dict, "ConnectedLineRestriction",
929 DBUS_TYPE_STRING, &str);
931 str = cdip_status_to_string(cs->cdip);
932 ofono_dbus_dict_append(&dict, "CalledLinePresentation",
933 DBUS_TYPE_STRING, &str);
935 str = clir_status_to_string(cs->clir);
936 ofono_dbus_dict_append(&dict, "CallingLineRestriction",
937 DBUS_TYPE_STRING, &str);
939 str = hide_callerid_to_string(cs->clir_setting);
940 ofono_dbus_dict_append(&dict, "HideCallerId", DBUS_TYPE_STRING, &str);
942 property_append_cw_conditions(&dict, cs->cw, BEARER_CLASS_VOICE);
944 dbus_message_iter_close_container(&iter, &dict);
949 static void cs_clir_callback(const struct ofono_error *error,
950 int override_setting, int network_setting,
953 struct ofono_call_settings *cs = data;
955 if (error->type != OFONO_ERROR_TYPE_NO_ERROR)
958 set_clir_network(cs, network_setting);
959 set_clir_override(cs, override_setting);
961 cs->flags |= CALL_SETTINGS_FLAG_CACHED;
965 DBusMessage *reply = generate_get_properties_reply(cs,
967 __ofono_dbus_pending_reply(&cs->pending, reply);
971 static void query_clir(struct ofono_call_settings *cs)
973 if (cs->driver->clir_query == NULL) {
976 generate_get_properties_reply(cs,
978 __ofono_dbus_pending_reply(&cs->pending, reply);
984 cs->driver->clir_query(cs, cs_clir_callback, cs);
987 static void cs_cdip_callback(const struct ofono_error *error,
988 int state, void *data)
990 struct ofono_call_settings *cs = data;
992 if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
998 static void query_cdip(struct ofono_call_settings *cs)
1000 if (cs->driver->cdip_query == NULL) {
1005 cs->driver->cdip_query(cs, cs_cdip_callback, cs);
1009 static void cs_cnap_callback(const struct ofono_error *error,
1010 int state, void *data)
1012 struct ofono_call_settings *cs = data;
1014 if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
1015 set_cnap(cs, state);
1020 static void query_cnap(struct ofono_call_settings *cs)
1022 if (cs->driver->cnap_query == NULL) {
1027 cs->driver->cnap_query(cs, cs_cnap_callback, cs);
1030 static void cs_clip_callback(const struct ofono_error *error,
1031 int state, void *data)
1033 struct ofono_call_settings *cs = data;
1035 if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
1036 set_clip(cs, state);
1041 static void query_clip(struct ofono_call_settings *cs)
1043 if (cs->driver->clip_query == NULL) {
1048 cs->driver->clip_query(cs, cs_clip_callback, cs);
1051 static void cs_colp_callback(const struct ofono_error *error,
1052 int state, void *data)
1054 struct ofono_call_settings *cs = data;
1056 if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
1057 set_colp(cs, state);
1062 static void query_colp(struct ofono_call_settings *cs)
1064 if (cs->driver->colp_query == NULL) {
1069 cs->driver->colp_query(cs, cs_colp_callback, cs);
1072 static void cs_colr_callback(const struct ofono_error *error,
1073 int state, void *data)
1075 struct ofono_call_settings *cs = data;
1077 if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
1078 set_colr(cs, state);
1083 static void query_colr(struct ofono_call_settings *cs)
1085 if (cs->driver->colr_query == NULL) {
1090 cs->driver->colr_query(cs, cs_colr_callback, cs);
1093 static void cs_cw_callback(const struct ofono_error *error, int status,
1096 struct ofono_call_settings *cs = data;
1098 if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
1099 set_cw(cs, status, BEARER_CLASS_VOICE);
1104 static void query_cw(struct ofono_call_settings *cs)
1106 if (cs->driver->cw_query == NULL) {
1111 cs->driver->cw_query(cs, BEARER_CLASS_DEFAULT, cs_cw_callback, cs);
1114 static DBusMessage *cs_get_properties(DBusConnection *conn, DBusMessage *msg,
1117 struct ofono_call_settings *cs = data;
1119 if (__ofono_call_settings_is_busy(cs) || __ofono_ussd_is_busy(cs->ussd))
1120 return __ofono_error_busy(msg);
1122 if (cs->flags & CALL_SETTINGS_FLAG_CACHED)
1123 return generate_get_properties_reply(cs, msg);
1125 /* Query the settings and report back */
1126 cs->pending = dbus_message_ref(msg);
1133 static void clir_set_query_callback(const struct ofono_error *error,
1134 int override_setting,
1135 int network_setting, void *data)
1137 struct ofono_call_settings *cs = data;
1140 if (!__ofono_call_settings_is_busy(cs))
1143 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
1144 ofono_error("set clir successful, but the query was not");
1146 cs->flags &= ~CALL_SETTINGS_FLAG_CACHED;
1148 reply = __ofono_error_failed(cs->pending);
1149 __ofono_dbus_pending_reply(&cs->pending, reply);
1153 reply = dbus_message_new_method_return(cs->pending);
1154 __ofono_dbus_pending_reply(&cs->pending, reply);
1156 set_clir_override(cs, override_setting);
1157 set_clir_network(cs, network_setting);
1160 static void clir_set_callback(const struct ofono_error *error, void *data)
1162 struct ofono_call_settings *cs = data;
1164 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
1165 DBG("setting clir failed");
1166 __ofono_dbus_pending_reply(&cs->pending,
1167 __ofono_error_failed(cs->pending));
1172 /* Assume that if we have clir_set, we have clir_query */
1173 cs->driver->clir_query(cs, clir_set_query_callback, cs);
1176 static DBusMessage *set_clir(DBusMessage *msg, struct ofono_call_settings *cs,
1177 const char *setting)
1181 if (cs->driver->clir_set == NULL)
1182 return __ofono_error_not_implemented(msg);
1184 if (!strcmp(setting, "default"))
1185 clir = CLIR_STATUS_NOT_PROVISIONED;
1186 else if (!strcmp(setting, "enabled"))
1187 clir = CLIR_STATUS_PROVISIONED_PERMANENT;
1188 else if (!strcmp(setting, "disabled"))
1189 clir = CLIR_STATUS_UNKNOWN;
1192 return __ofono_error_invalid_format(msg);
1194 cs->pending = dbus_message_ref(msg);
1196 cs->driver->clir_set(cs, clir, clir_set_callback, cs);
1201 static void cw_set_query_callback(const struct ofono_error *error, int status,
1204 struct ofono_call_settings *cs = data;
1206 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
1207 ofono_error("CW set succeeded, but query failed!");
1209 cs->flags &= ~CALL_SETTINGS_FLAG_CACHED;
1211 __ofono_dbus_pending_reply(&cs->pending,
1212 __ofono_error_failed(cs->pending));
1216 __ofono_dbus_pending_reply(&cs->pending,
1217 dbus_message_new_method_return(cs->pending));
1219 set_cw(cs, status, BEARER_CLASS_VOICE);
1222 static void cw_set_callback(const struct ofono_error *error, void *data)
1224 struct ofono_call_settings *cs = data;
1226 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
1227 DBG("Error occurred during CW set");
1229 __ofono_dbus_pending_reply(&cs->pending,
1230 __ofono_error_failed(cs->pending));
1235 cs->driver->cw_query(cs, BEARER_CLASS_DEFAULT,
1236 cw_set_query_callback, cs);
1239 static DBusMessage *set_cw_req(DBusMessage *msg, struct ofono_call_settings *cs,
1240 const char *setting, int cls)
1244 if (cs->driver->cw_set == NULL)
1245 return __ofono_error_not_implemented(msg);
1247 if (!strcmp(setting, "enabled"))
1249 else if (!strcmp(setting, "disabled"))
1252 return __ofono_error_invalid_format(msg);
1254 cs->pending = dbus_message_ref(msg);
1256 cs->driver->cw_set(cs, cw, cls, cw_set_callback, cs);
1261 static gboolean is_cw_property(const char *property, int mask, int *out_cls)
1267 for (i = 1; i <= BEARER_CLASS_PAD; i = i << 1) {
1268 if ((i & mask) == 0)
1271 prefix = bearer_class_to_string(i);
1273 len = strlen(prefix);
1275 if (strncmp(property, prefix, len))
1278 if (!strcmp(property+len, "CallWaiting")) {
1287 static DBusMessage *cs_set_property(DBusConnection *conn, DBusMessage *msg,
1290 struct ofono_call_settings *cs = data;
1291 DBusMessageIter iter;
1292 DBusMessageIter var;
1293 const char *property;
1296 if (__ofono_call_settings_is_busy(cs) || __ofono_ussd_is_busy(cs->ussd))
1297 return __ofono_error_busy(msg);
1299 if (!dbus_message_iter_init(msg, &iter))
1300 return __ofono_error_invalid_args(msg);
1302 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
1303 return __ofono_error_invalid_args(msg);
1305 dbus_message_iter_get_basic(&iter, &property);
1306 dbus_message_iter_next(&iter);
1308 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
1309 return __ofono_error_invalid_args(msg);
1311 dbus_message_iter_recurse(&iter, &var);
1313 if (!strcmp(property, "HideCallerId")) {
1314 const char *setting;
1316 if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_STRING)
1317 return __ofono_error_invalid_args(msg);
1319 dbus_message_iter_get_basic(&var, &setting);
1321 return set_clir(msg, cs, setting);
1322 } else if (is_cw_property(property, BEARER_CLASS_VOICE, &cls)) {
1323 const char *setting;
1325 if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_STRING)
1326 return __ofono_error_invalid_args(msg);
1328 dbus_message_iter_get_basic(&var, &setting);
1330 return set_cw_req(msg, cs, setting, cls);
1333 return __ofono_error_invalid_args(msg);
1336 static const GDBusMethodTable cs_methods[] = {
1337 { GDBUS_ASYNC_METHOD("GetProperties",
1338 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
1339 cs_get_properties) },
1340 { GDBUS_ASYNC_METHOD("SetProperty",
1341 GDBUS_ARGS({ "property", "s" }, { "value", "v" }),
1342 NULL, cs_set_property) },
1346 static const GDBusSignalTable cs_signals[] = {
1347 { GDBUS_SIGNAL("PropertyChanged",
1348 GDBUS_ARGS({ "property", "s" }, { "value", "v" })) },
1352 int ofono_call_settings_driver_register(const struct ofono_call_settings_driver *d)
1354 DBG("driver: %p, name: %s", d, d->name);
1356 if (d->probe == NULL)
1359 g_drivers = g_slist_prepend(g_drivers, (void *) d);
1364 void ofono_call_settings_driver_unregister(const struct ofono_call_settings_driver *d)
1366 DBG("driver: %p, name: %s", d, d->name);
1368 g_drivers = g_slist_remove(g_drivers, (void *) d);
1371 static void call_settings_unregister(struct ofono_atom *atom)
1373 struct ofono_call_settings *cs = __ofono_atom_get_data(atom);
1374 const char *path = __ofono_atom_get_path(cs->atom);
1375 DBusConnection *conn = ofono_dbus_get_connection();
1376 struct ofono_modem *modem = __ofono_atom_get_modem(cs->atom);
1378 ofono_modem_remove_interface(modem, OFONO_CALL_SETTINGS_INTERFACE);
1379 g_dbus_unregister_interface(conn, path, OFONO_CALL_SETTINGS_INTERFACE);
1382 cs_unregister_ss_controls(cs);
1385 __ofono_modem_remove_atom_watch(modem, cs->ussd_watch);
1388 static void call_settings_remove(struct ofono_atom *atom)
1390 struct ofono_call_settings *cs = __ofono_atom_get_data(atom);
1392 DBG("atom: %p", atom);
1397 if (cs->driver != NULL && cs->driver->remove != NULL)
1398 cs->driver->remove(cs);
1403 struct ofono_call_settings *ofono_call_settings_create(struct ofono_modem *modem,
1404 unsigned int vendor,
1408 struct ofono_call_settings *cs;
1414 cs = g_try_new0(struct ofono_call_settings, 1);
1419 /* Set all the settings to unknown state */
1420 cs->clip = CLIP_STATUS_UNKNOWN;
1421 cs->cnap = CNAP_STATUS_UNKNOWN;
1422 cs->clir = CLIR_STATUS_UNKNOWN;
1423 cs->colp = COLP_STATUS_UNKNOWN;
1424 cs->colr = COLR_STATUS_UNKNOWN;
1425 cs->atom = __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_CALL_SETTINGS,
1426 call_settings_remove, cs);
1428 for (l = g_drivers; l; l = l->next) {
1429 const struct ofono_call_settings_driver *drv = l->data;
1431 if (g_strcmp0(drv->name, driver))
1434 if (drv->probe(cs, vendor, data) < 0)
1444 static void ussd_watch(struct ofono_atom *atom,
1445 enum ofono_atom_watch_condition cond, void *data)
1447 struct ofono_call_settings *cs = data;
1449 if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) {
1454 cs->ussd = __ofono_atom_get_data(atom);
1455 cs_register_ss_controls(cs);
1458 void ofono_call_settings_register(struct ofono_call_settings *cs)
1460 DBusConnection *conn = ofono_dbus_get_connection();
1461 const char *path = __ofono_atom_get_path(cs->atom);
1462 struct ofono_modem *modem = __ofono_atom_get_modem(cs->atom);
1464 if (!g_dbus_register_interface(conn, path,
1465 OFONO_CALL_SETTINGS_INTERFACE,
1466 cs_methods, cs_signals, NULL, cs,
1468 ofono_error("Could not create %s interface",
1469 OFONO_CALL_SETTINGS_INTERFACE);
1474 ofono_modem_add_interface(modem, OFONO_CALL_SETTINGS_INTERFACE);
1476 cs->ussd_watch = __ofono_modem_add_atom_watch(modem,
1477 OFONO_ATOM_TYPE_USSD,
1478 ussd_watch, cs, NULL);
1480 __ofono_atom_register(cs->atom, call_settings_unregister);
1483 void ofono_call_settings_remove(struct ofono_call_settings *cs)
1485 __ofono_atom_free(cs->atom);
1488 void ofono_call_settings_set_data(struct ofono_call_settings *cs, void *data)
1490 cs->driver_data = data;
1493 void *ofono_call_settings_get_data(struct ofono_call_settings *cs)
1495 return cs->driver_data;