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");
481 __ofono_dbus_pending_reply(&cs->pending,
482 __ofono_error_failed(cs->pending));
487 cs->driver->cw_query(cs, BEARER_CLASS_DEFAULT,
488 cw_ss_query_callback, cs);
491 static gboolean cw_ss_control(int type,
492 const char *sc, const char *sia,
493 const char *sib, const char *sic,
494 const char *dn, DBusMessage *msg, void *data)
496 struct ofono_call_settings *cs = data;
497 DBusConnection *conn = ofono_dbus_get_connection();
498 int cls = BEARER_CLASS_SS_DEFAULT;
504 if (strcmp(sc, "43"))
507 if (__ofono_call_settings_is_busy(cs)) {
508 reply = __ofono_error_busy(msg);
512 if (strlen(sib) || strlen(sib) || strlen(dn))
515 if ((type == SS_CONTROL_TYPE_QUERY && cs->driver->cw_query == NULL) ||
516 (type != SS_CONTROL_TYPE_QUERY && cs->driver->cw_set == NULL)) {
517 reply = __ofono_error_not_implemented(msg);
521 if (strlen(sia) > 0) {
525 service_code = strtoul(sia, &end, 10);
527 if (end == sia || *end != '\0')
530 cls = mmi_service_code_to_bearer_class(service_code);
535 cs->ss_req_cls = cls;
536 cs->pending = dbus_message_ref(msg);
538 /* For the default case use the more readily accepted value */
539 if (cls == BEARER_CLASS_SS_DEFAULT)
540 cls = BEARER_CLASS_DEFAULT;
543 case SS_CONTROL_TYPE_REGISTRATION:
544 case SS_CONTROL_TYPE_ACTIVATION:
545 cs->ss_req_type = SS_CONTROL_TYPE_ACTIVATION;
546 cs->driver->cw_set(cs, 1, cls, cw_ss_set_callback, cs);
549 case SS_CONTROL_TYPE_QUERY:
550 cs->ss_req_type = SS_CONTROL_TYPE_QUERY;
552 * Always query the entire set, SMS not applicable
553 * according to 22.004 Appendix A, so CLASS_DEFAULT
554 * is safe to use here
556 cs->driver->cw_query(cs, BEARER_CLASS_DEFAULT,
557 cw_ss_query_callback, cs);
560 case SS_CONTROL_TYPE_DEACTIVATION:
561 case SS_CONTROL_TYPE_ERASURE:
562 cs->ss_req_type = SS_CONTROL_TYPE_DEACTIVATION;
563 cs->driver->cw_set(cs, 0, cls, cw_ss_set_callback, cs);
570 reply = __ofono_error_invalid_format(msg);
572 g_dbus_send_message(conn, reply);
576 static void generate_ss_query_reply(struct ofono_call_settings *cs,
577 const char *context, const char *value)
579 const char *sig = "(ss)";
580 const char *ss_type = ss_control_type_to_string(cs->ss_req_type);
581 DBusMessageIter iter;
583 DBusMessageIter vstruct;
586 reply = dbus_message_new_method_return(cs->pending);
588 dbus_message_iter_init_append(reply, &iter);
590 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &context);
592 dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, sig, &var);
594 dbus_message_iter_open_container(&var, DBUS_TYPE_STRUCT, NULL,
597 dbus_message_iter_append_basic(&vstruct, DBUS_TYPE_STRING,
600 dbus_message_iter_append_basic(&vstruct, DBUS_TYPE_STRING, &value);
602 dbus_message_iter_close_container(&var, &vstruct);
604 dbus_message_iter_close_container(&iter, &var);
606 __ofono_dbus_pending_reply(&cs->pending, reply);
609 static void clip_cnap_colp_colr_ss_query_cb(const struct ofono_error *error,
610 int status, void *data)
612 struct ofono_call_settings *cs = data;
616 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
617 DBG("Error occurred during ss control query");
618 __ofono_dbus_pending_reply(&cs->pending,
619 __ofono_error_failed(cs->pending));
624 switch (cs->ss_setting) {
625 case CALL_SETTING_TYPE_CLIP:
626 set_clip(cs, status);
627 value = clip_status_to_string(status);
628 context = "CallingLinePresentation";
631 case CALL_SETTING_TYPE_CNAP:
632 set_cnap(cs, status);
633 value = cnap_status_to_string(status);
634 context = "CallingNamePresentation";
638 case CALL_SETTING_TYPE_COLP:
639 set_colp(cs, status);
640 value = colp_status_to_string(status);
641 context = "ConnectedLinePresentation";
644 case CALL_SETTING_TYPE_COLR:
645 set_colr(cs, status);
646 value = colr_status_to_string(status);
647 context = "ConnectedLineRestriction";
651 __ofono_dbus_pending_reply(&cs->pending,
652 __ofono_error_failed(cs->pending));
653 ofono_error("Unknown type during COLR/COLP/CLIP/CNAP ss");
657 generate_ss_query_reply(cs, context, value);
660 static gboolean clip_cnap_colp_colr_ss(int type,
661 const char *sc, const char *sia,
662 const char *sib, const char *sic,
663 const char *dn, DBusMessage *msg, void *data)
665 struct ofono_call_settings *cs = data;
666 DBusConnection *conn = ofono_dbus_get_connection();
667 void (*query_op)(struct ofono_call_settings *cs,
668 ofono_call_settings_status_cb_t cb, void *data);
673 if (__ofono_call_settings_is_busy(cs)) {
674 DBusMessage *reply = __ofono_error_busy(msg);
675 g_dbus_send_message(conn, reply);
680 if (!strcmp(sc, "30")) {
681 cs->ss_setting = CALL_SETTING_TYPE_CLIP;
682 query_op = cs->driver->clip_query;
683 } else if (!strcmp(sc, "300")) {
684 cs->ss_setting = CALL_SETTING_TYPE_CNAP;
685 query_op = cs->driver->cnap_query;
686 } else if (!strcmp(sc, "76")) {
687 cs->ss_setting = CALL_SETTING_TYPE_COLP;
688 query_op = cs->driver->colp_query;
689 } else if (!strcmp(sc, "77")) {
690 cs->ss_setting = CALL_SETTING_TYPE_COLR;
691 query_op = cs->driver->colr_query;
696 if (type != SS_CONTROL_TYPE_QUERY || strlen(sia) || strlen(sib) ||
697 strlen(sic) || strlen(dn)) {
698 DBusMessage *reply = __ofono_error_invalid_format(msg);
699 g_dbus_send_message(conn, reply);
704 if (query_op == NULL) {
705 DBusMessage *reply = __ofono_error_not_implemented(msg);
706 g_dbus_send_message(conn, reply);
711 DBG("Received CLIP/CNAP/COLR/COLP query ss control");
713 cs->pending = dbus_message_ref(msg);
715 query_op(cs, clip_cnap_colp_colr_ss_query_cb, cs);
720 static void clir_ss_query_callback(const struct ofono_error *error,
721 int override, int network, void *data)
723 struct ofono_call_settings *cs = data;
726 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
727 DBG("setting clir via SS failed");
728 __ofono_dbus_pending_reply(&cs->pending,
729 __ofono_error_failed(cs->pending));
735 case CLIR_STATUS_UNKNOWN:
739 case CLIR_STATUS_PROVISIONED_PERMANENT:
743 case CLIR_STATUS_NOT_PROVISIONED:
747 case CLIR_STATUS_TEMPORARY_RESTRICTED:
748 if (override == OFONO_CLIR_OPTION_SUPPRESSION)
754 case CLIR_STATUS_TEMPORARY_ALLOWED:
755 if (override == OFONO_CLIR_OPTION_INVOCATION)
764 generate_ss_query_reply(cs, "CallingLineRestriction", value);
766 set_clir_network(cs, network);
767 set_clir_override(cs, override);
770 static void clir_ss_set_callback(const struct ofono_error *error, void *data)
772 struct ofono_call_settings *cs = data;
774 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
775 DBG("setting clir via SS failed");
776 __ofono_dbus_pending_reply(&cs->pending,
777 __ofono_error_failed(cs->pending));
782 cs->driver->clir_query(cs, clir_ss_query_callback, cs);
785 static gboolean clir_ss_control(int type,
786 const char *sc, const char *sia,
787 const char *sib, const char *sic,
788 const char *dn, DBusMessage *msg, void *data)
790 struct ofono_call_settings *cs = data;
791 DBusConnection *conn = ofono_dbus_get_connection();
796 if (strcmp(sc, "31"))
799 if (__ofono_call_settings_is_busy(cs)) {
800 DBusMessage *reply = __ofono_error_busy(msg);
801 g_dbus_send_message(conn, reply);
806 /* This is the temporary form of CLIR, handled in voicecalls */
807 if (!strlen(sia) && !strlen(sib) & !strlen(sic) &&
808 strlen(dn) && type != SS_CONTROL_TYPE_QUERY)
811 if (strlen(sia) || strlen(sib) || strlen(sic) || strlen(dn)) {
812 DBusMessage *reply = __ofono_error_invalid_format(msg);
813 g_dbus_send_message(conn, reply);
818 if (type == SS_CONTROL_TYPE_QUERY && cs->driver->clir_query == NULL) {
819 DBusMessage *reply = __ofono_error_not_implemented(msg);
820 g_dbus_send_message(conn, reply);
825 if (type != SS_CONTROL_TYPE_QUERY && cs->driver->clir_set == NULL) {
826 DBusMessage *reply = __ofono_error_not_implemented(msg);
827 g_dbus_send_message(conn, reply);
832 cs->ss_setting = CALL_SETTING_TYPE_CLIR;
833 cs->pending = dbus_message_ref(msg);
836 case SS_CONTROL_TYPE_REGISTRATION:
837 case SS_CONTROL_TYPE_ACTIVATION:
838 cs->ss_req_type = SS_CONTROL_TYPE_ACTIVATION;
839 cs->driver->clir_set(cs, OFONO_CLIR_OPTION_SUPPRESSION,
840 clir_ss_set_callback, cs);
843 case SS_CONTROL_TYPE_QUERY:
844 cs->ss_req_type = SS_CONTROL_TYPE_QUERY;
845 cs->driver->clir_query(cs, clir_ss_query_callback, cs);
848 case SS_CONTROL_TYPE_DEACTIVATION:
849 case SS_CONTROL_TYPE_ERASURE:
850 cs->ss_req_type = SS_CONTROL_TYPE_DEACTIVATION;
851 cs->driver->clir_set(cs, OFONO_CLIR_OPTION_INVOCATION,
852 clir_ss_set_callback, cs);
859 static void cs_register_ss_controls(struct ofono_call_settings *cs)
861 __ofono_ussd_ssc_register(cs->ussd, "30", clip_cnap_colp_colr_ss,
863 __ofono_ussd_ssc_register(cs->ussd, "31", clir_ss_control, cs, NULL);
864 __ofono_ussd_ssc_register(cs->ussd, "76", clip_cnap_colp_colr_ss,
866 __ofono_ussd_ssc_register(cs->ussd, "300", clip_cnap_colp_colr_ss,
869 __ofono_ussd_ssc_register(cs->ussd, "43", cw_ss_control, cs, NULL);
871 if (cs->driver->colr_query != NULL)
872 __ofono_ussd_ssc_register(cs->ussd, "77",
873 clip_cnap_colp_colr_ss, cs, NULL);
876 static void cs_unregister_ss_controls(struct ofono_call_settings *cs)
878 __ofono_ussd_ssc_unregister(cs->ussd, "30");
879 __ofono_ussd_ssc_unregister(cs->ussd, "31");
880 __ofono_ussd_ssc_unregister(cs->ussd, "76");
881 __ofono_ussd_ssc_unregister(cs->ussd, "300");
883 __ofono_ussd_ssc_unregister(cs->ussd, "43");
885 if (cs->driver->colr_query != NULL)
886 __ofono_ussd_ssc_unregister(cs->ussd, "77");
889 gboolean __ofono_call_settings_is_busy(struct ofono_call_settings *cs)
891 return cs->pending ? TRUE : FALSE;
894 static DBusMessage *generate_get_properties_reply(struct ofono_call_settings *cs,
898 DBusMessageIter iter;
899 DBusMessageIter dict;
902 reply = dbus_message_new_method_return(msg);
906 dbus_message_iter_init_append(reply, &iter);
908 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
909 OFONO_PROPERTIES_ARRAY_SIGNATURE,
912 str = clip_status_to_string(cs->clip);
913 ofono_dbus_dict_append(&dict, "CallingLinePresentation",
914 DBUS_TYPE_STRING, &str);
916 str = cnap_status_to_string(cs->cnap);
917 ofono_dbus_dict_append(&dict, "CallingNamePresentation",
918 DBUS_TYPE_STRING, &str);
920 str = colp_status_to_string(cs->colp);
921 ofono_dbus_dict_append(&dict, "ConnectedLinePresentation",
922 DBUS_TYPE_STRING, &str);
924 str = colr_status_to_string(cs->colr);
925 ofono_dbus_dict_append(&dict, "ConnectedLineRestriction",
926 DBUS_TYPE_STRING, &str);
928 str = cdip_status_to_string(cs->cdip);
929 ofono_dbus_dict_append(&dict, "CalledLinePresentation",
930 DBUS_TYPE_STRING, &str);
932 str = clir_status_to_string(cs->clir);
933 ofono_dbus_dict_append(&dict, "CallingLineRestriction",
934 DBUS_TYPE_STRING, &str);
936 str = hide_callerid_to_string(cs->clir_setting);
937 ofono_dbus_dict_append(&dict, "HideCallerId", DBUS_TYPE_STRING, &str);
939 property_append_cw_conditions(&dict, cs->cw, BEARER_CLASS_VOICE);
941 dbus_message_iter_close_container(&iter, &dict);
946 static void cs_clir_callback(const struct ofono_error *error,
947 int override_setting, int network_setting,
950 struct ofono_call_settings *cs = data;
952 if (error->type != OFONO_ERROR_TYPE_NO_ERROR)
955 set_clir_network(cs, network_setting);
956 set_clir_override(cs, override_setting);
958 cs->flags |= CALL_SETTINGS_FLAG_CACHED;
962 DBusMessage *reply = generate_get_properties_reply(cs,
964 __ofono_dbus_pending_reply(&cs->pending, reply);
968 static void query_clir(struct ofono_call_settings *cs)
970 if (cs->driver->clir_query == NULL) {
973 generate_get_properties_reply(cs,
975 __ofono_dbus_pending_reply(&cs->pending, reply);
981 cs->driver->clir_query(cs, cs_clir_callback, cs);
984 static void cs_cdip_callback(const struct ofono_error *error,
985 int state, void *data)
987 struct ofono_call_settings *cs = data;
989 if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
995 static void query_cdip(struct ofono_call_settings *cs)
997 if (cs->driver->cdip_query == NULL) {
1002 cs->driver->cdip_query(cs, cs_cdip_callback, cs);
1006 static void cs_cnap_callback(const struct ofono_error *error,
1007 int state, void *data)
1009 struct ofono_call_settings *cs = data;
1011 if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
1012 set_cnap(cs, state);
1017 static void query_cnap(struct ofono_call_settings *cs)
1019 if (cs->driver->cnap_query == NULL) {
1024 cs->driver->cnap_query(cs, cs_cnap_callback, cs);
1027 static void cs_clip_callback(const struct ofono_error *error,
1028 int state, void *data)
1030 struct ofono_call_settings *cs = data;
1032 if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
1033 set_clip(cs, state);
1038 static void query_clip(struct ofono_call_settings *cs)
1040 if (cs->driver->clip_query == NULL) {
1045 cs->driver->clip_query(cs, cs_clip_callback, cs);
1048 static void cs_colp_callback(const struct ofono_error *error,
1049 int state, void *data)
1051 struct ofono_call_settings *cs = data;
1053 if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
1054 set_colp(cs, state);
1059 static void query_colp(struct ofono_call_settings *cs)
1061 if (cs->driver->colp_query == NULL) {
1066 cs->driver->colp_query(cs, cs_colp_callback, cs);
1069 static void cs_colr_callback(const struct ofono_error *error,
1070 int state, void *data)
1072 struct ofono_call_settings *cs = data;
1074 if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
1075 set_colr(cs, state);
1080 static void query_colr(struct ofono_call_settings *cs)
1082 if (cs->driver->colr_query == NULL) {
1087 cs->driver->colr_query(cs, cs_colr_callback, cs);
1090 static void cs_cw_callback(const struct ofono_error *error, int status,
1093 struct ofono_call_settings *cs = data;
1095 if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
1096 set_cw(cs, status, BEARER_CLASS_VOICE);
1101 static void query_cw(struct ofono_call_settings *cs)
1103 if (cs->driver->cw_query == NULL) {
1108 cs->driver->cw_query(cs, BEARER_CLASS_DEFAULT, cs_cw_callback, cs);
1111 static DBusMessage *cs_get_properties(DBusConnection *conn, DBusMessage *msg,
1114 struct ofono_call_settings *cs = data;
1116 if (__ofono_call_settings_is_busy(cs) || __ofono_ussd_is_busy(cs->ussd))
1117 return __ofono_error_busy(msg);
1119 if (cs->flags & CALL_SETTINGS_FLAG_CACHED)
1120 return generate_get_properties_reply(cs, msg);
1122 /* Query the settings and report back */
1123 cs->pending = dbus_message_ref(msg);
1130 static void clir_set_query_callback(const struct ofono_error *error,
1131 int override_setting,
1132 int network_setting, void *data)
1134 struct ofono_call_settings *cs = data;
1137 if (!__ofono_call_settings_is_busy(cs))
1140 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
1141 ofono_error("set clir successful, but the query was not");
1143 cs->flags &= ~CALL_SETTINGS_FLAG_CACHED;
1145 reply = __ofono_error_failed(cs->pending);
1146 __ofono_dbus_pending_reply(&cs->pending, reply);
1150 reply = dbus_message_new_method_return(cs->pending);
1151 __ofono_dbus_pending_reply(&cs->pending, reply);
1153 set_clir_override(cs, override_setting);
1154 set_clir_network(cs, network_setting);
1157 static void clir_set_callback(const struct ofono_error *error, void *data)
1159 struct ofono_call_settings *cs = data;
1161 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
1162 DBG("setting clir failed");
1163 __ofono_dbus_pending_reply(&cs->pending,
1164 __ofono_error_failed(cs->pending));
1169 /* Assume that if we have clir_set, we have clir_query */
1170 cs->driver->clir_query(cs, clir_set_query_callback, cs);
1173 static DBusMessage *set_clir(DBusMessage *msg, struct ofono_call_settings *cs,
1174 const char *setting)
1178 if (cs->driver->clir_set == NULL)
1179 return __ofono_error_not_implemented(msg);
1181 if (!strcmp(setting, "default"))
1182 clir = CLIR_STATUS_NOT_PROVISIONED;
1183 else if (!strcmp(setting, "enabled"))
1184 clir = CLIR_STATUS_PROVISIONED_PERMANENT;
1185 else if (!strcmp(setting, "disabled"))
1186 clir = CLIR_STATUS_UNKNOWN;
1189 return __ofono_error_invalid_format(msg);
1191 cs->pending = dbus_message_ref(msg);
1193 cs->driver->clir_set(cs, clir, clir_set_callback, cs);
1198 static void cw_set_query_callback(const struct ofono_error *error, int status,
1201 struct ofono_call_settings *cs = data;
1203 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
1204 ofono_error("CW set succeeded, but query failed!");
1206 cs->flags &= ~CALL_SETTINGS_FLAG_CACHED;
1208 __ofono_dbus_pending_reply(&cs->pending,
1209 __ofono_error_failed(cs->pending));
1213 __ofono_dbus_pending_reply(&cs->pending,
1214 dbus_message_new_method_return(cs->pending));
1216 set_cw(cs, status, BEARER_CLASS_VOICE);
1219 static void cw_set_callback(const struct ofono_error *error, void *data)
1221 struct ofono_call_settings *cs = data;
1223 if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
1224 DBG("Error occurred during CW set");
1226 __ofono_dbus_pending_reply(&cs->pending,
1227 __ofono_error_failed(cs->pending));
1232 cs->driver->cw_query(cs, BEARER_CLASS_DEFAULT,
1233 cw_set_query_callback, cs);
1236 static DBusMessage *set_cw_req(DBusMessage *msg, struct ofono_call_settings *cs,
1237 const char *setting, int cls)
1241 if (cs->driver->cw_set == NULL)
1242 return __ofono_error_not_implemented(msg);
1244 if (!strcmp(setting, "enabled"))
1246 else if (!strcmp(setting, "disabled"))
1249 return __ofono_error_invalid_format(msg);
1251 cs->pending = dbus_message_ref(msg);
1253 cs->driver->cw_set(cs, cw, cls, cw_set_callback, cs);
1258 static gboolean is_cw_property(const char *property, int mask, int *out_cls)
1264 for (i = 1; i <= BEARER_CLASS_PAD; i = i << 1) {
1265 if ((i & mask) == 0)
1268 prefix = bearer_class_to_string(i);
1270 len = strlen(prefix);
1272 if (strncmp(property, prefix, len))
1275 if (!strcmp(property+len, "CallWaiting")) {
1284 static DBusMessage *cs_set_property(DBusConnection *conn, DBusMessage *msg,
1287 struct ofono_call_settings *cs = data;
1288 DBusMessageIter iter;
1289 DBusMessageIter var;
1290 const char *property;
1293 if (__ofono_call_settings_is_busy(cs) || __ofono_ussd_is_busy(cs->ussd))
1294 return __ofono_error_busy(msg);
1296 if (!dbus_message_iter_init(msg, &iter))
1297 return __ofono_error_invalid_args(msg);
1299 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
1300 return __ofono_error_invalid_args(msg);
1302 dbus_message_iter_get_basic(&iter, &property);
1303 dbus_message_iter_next(&iter);
1305 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
1306 return __ofono_error_invalid_args(msg);
1308 dbus_message_iter_recurse(&iter, &var);
1310 if (!strcmp(property, "HideCallerId")) {
1311 const char *setting;
1313 if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_STRING)
1314 return __ofono_error_invalid_args(msg);
1316 dbus_message_iter_get_basic(&var, &setting);
1318 return set_clir(msg, cs, setting);
1319 } else if (is_cw_property(property, BEARER_CLASS_VOICE, &cls)) {
1320 const char *setting;
1322 if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_STRING)
1323 return __ofono_error_invalid_args(msg);
1325 dbus_message_iter_get_basic(&var, &setting);
1327 return set_cw_req(msg, cs, setting, cls);
1330 return __ofono_error_invalid_args(msg);
1333 static const GDBusMethodTable cs_methods[] = {
1334 { GDBUS_ASYNC_METHOD("GetProperties",
1335 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
1336 cs_get_properties) },
1337 { GDBUS_ASYNC_METHOD("SetProperty",
1338 GDBUS_ARGS({ "property", "s" }, { "value", "v" }),
1339 NULL, cs_set_property) },
1343 static const GDBusSignalTable cs_signals[] = {
1344 { GDBUS_SIGNAL("PropertyChanged",
1345 GDBUS_ARGS({ "property", "s" }, { "value", "v" })) },
1349 int ofono_call_settings_driver_register(const struct ofono_call_settings_driver *d)
1351 DBG("driver: %p, name: %s", d, d->name);
1353 if (d->probe == NULL)
1356 g_drivers = g_slist_prepend(g_drivers, (void *) d);
1361 void ofono_call_settings_driver_unregister(const struct ofono_call_settings_driver *d)
1363 DBG("driver: %p, name: %s", d, d->name);
1365 g_drivers = g_slist_remove(g_drivers, (void *) d);
1368 static void call_settings_unregister(struct ofono_atom *atom)
1370 struct ofono_call_settings *cs = __ofono_atom_get_data(atom);
1371 const char *path = __ofono_atom_get_path(cs->atom);
1372 DBusConnection *conn = ofono_dbus_get_connection();
1373 struct ofono_modem *modem = __ofono_atom_get_modem(cs->atom);
1375 ofono_modem_remove_interface(modem, OFONO_CALL_SETTINGS_INTERFACE);
1376 g_dbus_unregister_interface(conn, path, OFONO_CALL_SETTINGS_INTERFACE);
1379 cs_unregister_ss_controls(cs);
1382 __ofono_modem_remove_atom_watch(modem, cs->ussd_watch);
1385 static void call_settings_remove(struct ofono_atom *atom)
1387 struct ofono_call_settings *cs = __ofono_atom_get_data(atom);
1389 DBG("atom: %p", atom);
1394 if (cs->driver != NULL && cs->driver->remove != NULL)
1395 cs->driver->remove(cs);
1400 struct ofono_call_settings *ofono_call_settings_create(struct ofono_modem *modem,
1401 unsigned int vendor,
1405 struct ofono_call_settings *cs;
1411 cs = g_try_new0(struct ofono_call_settings, 1);
1416 /* Set all the settings to unknown state */
1417 cs->clip = CLIP_STATUS_UNKNOWN;
1418 cs->cnap = CNAP_STATUS_UNKNOWN;
1419 cs->clir = CLIR_STATUS_UNKNOWN;
1420 cs->colp = COLP_STATUS_UNKNOWN;
1421 cs->colr = COLR_STATUS_UNKNOWN;
1422 cs->atom = __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_CALL_SETTINGS,
1423 call_settings_remove, cs);
1425 for (l = g_drivers; l; l = l->next) {
1426 const struct ofono_call_settings_driver *drv = l->data;
1428 if (g_strcmp0(drv->name, driver))
1431 if (drv->probe(cs, vendor, data) < 0)
1441 static void ussd_watch(struct ofono_atom *atom,
1442 enum ofono_atom_watch_condition cond, void *data)
1444 struct ofono_call_settings *cs = data;
1446 if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) {
1451 cs->ussd = __ofono_atom_get_data(atom);
1452 cs_register_ss_controls(cs);
1455 void ofono_call_settings_register(struct ofono_call_settings *cs)
1457 DBusConnection *conn = ofono_dbus_get_connection();
1458 const char *path = __ofono_atom_get_path(cs->atom);
1459 struct ofono_modem *modem = __ofono_atom_get_modem(cs->atom);
1461 if (!g_dbus_register_interface(conn, path,
1462 OFONO_CALL_SETTINGS_INTERFACE,
1463 cs_methods, cs_signals, NULL, cs,
1465 ofono_error("Could not create %s interface",
1466 OFONO_CALL_SETTINGS_INTERFACE);
1471 ofono_modem_add_interface(modem, OFONO_CALL_SETTINGS_INTERFACE);
1473 cs->ussd_watch = __ofono_modem_add_atom_watch(modem,
1474 OFONO_ATOM_TYPE_USSD,
1475 ussd_watch, cs, NULL);
1477 __ofono_atom_register(cs->atom, call_settings_unregister);
1480 void ofono_call_settings_remove(struct ofono_call_settings *cs)
1482 __ofono_atom_free(cs->atom);
1485 void ofono_call_settings_set_data(struct ofono_call_settings *cs, void *data)
1487 cs->driver_data = data;
1490 void *ofono_call_settings_get_data(struct ofono_call_settings *cs)
1492 return cs->driver_data;