Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | /* * * oFono - Open Source Telephony * * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <string.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <errno.h> #include <glib.h> #include <gdbus.h> #include "ofono.h" #include "common.h" #define CALL_BARRING_FLAG_CACHED 0x1 #define NUM_OF_BARRINGS 5 static GSList *g_drivers = NULL; static void cb_ss_query_next_lock(struct ofono_call_barring *cb); static void get_query_next_lock(struct ofono_call_barring *cb); static void set_query_next_lock(struct ofono_call_barring *cb); struct ofono_call_barring { int flags; DBusMessage *pending; int cur_locks[NUM_OF_BARRINGS]; int new_locks[NUM_OF_BARRINGS]; int query_start; int query_end; int query_next; int ss_req_type; int ss_req_cls; int ss_req_lock; struct ofono_ussd *ussd; unsigned int ussd_watch; const struct ofono_call_barring_driver *driver; void *driver_data; struct ofono_atom *atom; }; struct call_barring_lock { const char *name; const char *value; const char *fac; }; static struct call_barring_lock cb_locks[] = { { "AllOutgoing", "all", "AO" }, { "InternationalOutgoing", "international", "OI" }, { "InternationalOutgoingExceptHome", "internationalnothome", "OX" }, { "AllIncoming", "always", "AI" }, { "IncomingWhenRoaming", "whenroaming", "IR" }, { "AllBarringServices", NULL, "AB" }, { "AllOutgoingServices", NULL, "AG" }, { "AllIncomingServices", NULL, "AC" }, { NULL, NULL, NULL }, }; /* These are inclusive */ #define CB_OUTGOING_START 0 #define CB_OUTGOING_END 2 #define CB_INCOMING_START 3 #define CB_INCOMING_END 4 #define CB_ALL_START 0 #define CB_ALL_END 4 #define CB_ALL_OUTGOING 6 #define CB_ALL_INCOMING 7 static inline void emit_barring_changed(struct ofono_call_barring *cb, int start, int end, const char *type, int cls) { DBusConnection *conn = ofono_dbus_get_connection(); const char *path = __ofono_atom_get_path(cb->atom); char property_name[64]; const char *value; int i; int j; for (i = start; i <= end; i++) if (cb->cur_locks[i] & cls) break; for (j = start; j <= end; j++) if (cb->new_locks[j] & cls) break; if (i == j) return; if (j > end) value = "disabled"; else value = cb_locks[j].value; snprintf(property_name, sizeof(property_name), "%s%s", bearer_class_to_string(cls), type); ofono_dbus_signal_property_changed(conn, path, OFONO_CALL_BARRING_INTERFACE, property_name, DBUS_TYPE_STRING, &value); } static void update_barrings(struct ofono_call_barring *cb, int mask) { int cls; int i; /* We're only interested in emitting signals for Voice, Fax & Data */ for (cls = 1; cls <= BEARER_CLASS_PAD; cls = cls << 1) { if ((cls & mask) == 0) continue; emit_barring_changed(cb, cb->query_start, CB_OUTGOING_END, "Outgoing", cls); emit_barring_changed(cb, CB_INCOMING_START, cb->query_end, "Incoming", cls); } for (i = cb->query_start; i <= cb->query_end; i++) cb->cur_locks[i] = cb->new_locks[i]; } static void cb_ss_property_append(struct ofono_call_barring *cb, DBusMessageIter *dict, int lock, int mask) { int i; char property_name[64]; const char *strvalue; for (i = 1; i <= BEARER_CLASS_PAD; i = i << 1) { if (!(mask & i)) continue; strvalue = (cb->new_locks[lock] & i) ? "enabled" : "disabled"; snprintf(property_name, sizeof(property_name), "%s%s", bearer_class_to_string(i), cb_locks[lock].name); ofono_dbus_dict_append(dict, property_name, DBUS_TYPE_STRING, &strvalue); } } static void cb_set_query_bounds(struct ofono_call_barring *cb, const char *fac, gboolean fac_only) { int i; if (!strcmp("AB", fac)) { cb->query_start = CB_ALL_START; cb->query_end = CB_ALL_END; cb->query_next = CB_ALL_START; return; } if (!strcmp("AG", fac)) goto outgoing; if (!strcmp("AC", fac)) goto incoming; for (i = 0; cb_locks[i].name; i++) { if (strcmp(cb_locks[i].fac, fac)) continue; if (fac_only) { cb->query_start = i; cb->query_end = i; cb->query_next = i; return; } if ((i >= CB_OUTGOING_START) && (i <= CB_OUTGOING_END)) goto outgoing; else if ((i >= CB_INCOMING_START) && (i <= CB_INCOMING_END)) goto incoming; } ofono_error("Unable to set query boundaries for %s", fac); return; outgoing: cb->query_start = CB_OUTGOING_START; cb->query_end = CB_OUTGOING_END; cb->query_next = CB_OUTGOING_START; return; incoming: cb->query_start = CB_INCOMING_START; cb->query_end = CB_INCOMING_END; cb->query_next = CB_INCOMING_START; return; } static void generate_ss_query_reply(struct ofono_call_barring *cb) { const char *context = "CallBarring"; const char *sig = "(ssa{sv})"; const char *ss_type = ss_control_type_to_string(cb->ss_req_type); const char *ss_fac = cb_locks[cb->ss_req_lock].name; DBusMessageIter iter; DBusMessageIter variant; DBusMessageIter vstruct; DBusMessageIter dict; DBusMessage *reply; int lock; int start, end; reply = dbus_message_new_method_return(cb->pending); dbus_message_iter_init_append(reply, &iter); dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &context); dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, sig, &variant); dbus_message_iter_open_container(&variant, DBUS_TYPE_STRUCT, NULL, &vstruct); dbus_message_iter_append_basic(&vstruct, DBUS_TYPE_STRING, &ss_type); dbus_message_iter_append_basic(&vstruct, DBUS_TYPE_STRING, &ss_fac); dbus_message_iter_open_container(&vstruct, DBUS_TYPE_ARRAY, OFONO_PROPERTIES_ARRAY_SIGNATURE, &dict); /* We report all affected locks only for the special case ones */ if (cb->ss_req_lock <= CB_ALL_END) { start = cb->ss_req_lock; end = cb->ss_req_lock; } else { start = cb->query_start; end = cb->query_end; } for (lock = start; lock <= end; lock++) cb_ss_property_append(cb, &dict, lock, cb->ss_req_cls); dbus_message_iter_close_container(&vstruct, &dict); dbus_message_iter_close_container(&variant, &vstruct); dbus_message_iter_close_container(&iter, &variant); __ofono_dbus_pending_reply(&cb->pending, reply); } static void cb_ss_query_next_lock_callback(const struct ofono_error *error, int status, void *data) { struct ofono_call_barring *cb = data; if (error->type != OFONO_ERROR_TYPE_NO_ERROR) { ofono_error("Query failed with error: %s", telephony_error_to_str(error)); cb->flags &= ~CALL_BARRING_FLAG_CACHED; __ofono_dbus_pending_reply(&cb->pending, __ofono_error_from_error(error, cb->pending)); return; } cb->new_locks[cb->query_next] = status; if (cb->query_next < cb->query_end) { cb->query_next += 1; cb_ss_query_next_lock(cb); return; } generate_ss_query_reply(cb); update_barrings(cb, BEARER_CLASS_VOICE); } static void cb_ss_query_next_lock(struct ofono_call_barring *cb) { int cls; cls = (cb->ss_req_type == SS_CONTROL_TYPE_QUERY) ? cb->ss_req_cls : cb->ss_req_cls | BEARER_CLASS_DEFAULT; cb->driver->query(cb, cb_locks[cb->query_next].fac, cls, cb_ss_query_next_lock_callback, cb); } static void cb_ss_set_lock_callback(const struct ofono_error *error, void *data) { struct ofono_call_barring *cb = data; if (error->type != OFONO_ERROR_TYPE_NO_ERROR) { DBG("Enabling/disabling Call Barring via SS failed with err:%s", telephony_error_to_str(error)); __ofono_dbus_pending_reply(&cb->pending, __ofono_error_from_error(error, cb->pending)); return; } /* Assume we have query always */ cb_ss_query_next_lock(cb); } static const char *cb_ss_service_to_fac(const char *svc) { if (!strcmp(svc, "33")) return "AO"; else if (!strcmp(svc, "331")) return "OI"; else if (!strcmp(svc, "332")) return "OX"; else if (!strcmp(svc, "35")) return "AI"; else if (!strcmp(svc, "351")) return "IR"; else if (!strcmp(svc, "330")) return "AB"; else if (!strcmp(svc, "333")) return "AG"; else if (!strcmp(svc, "353")) return "AC"; return NULL; } static gboolean cb_ss_control(int type, const char *sc, const char *sia, const char *sib, const char *sic, const char *dn, DBusMessage *msg, void *data) { struct ofono_call_barring *cb = data; DBusConnection *conn = ofono_dbus_get_connection(); int cls = BEARER_CLASS_DEFAULT; const char *fac; DBusMessage *reply; void *operation = NULL; int i; if (__ofono_call_barring_is_busy(cb)) { reply = __ofono_error_busy(msg); g_dbus_send_message(conn, reply); return TRUE; } DBG("Received call barring ss control request"); DBG("type: %d, sc: %s, sia: %s, sib: %s, sic: %s, dn: %s", type, sc, sia, sib, sic, dn); fac = cb_ss_service_to_fac(sc); if (fac == NULL) return FALSE; cb_set_query_bounds(cb, fac, type == SS_CONTROL_TYPE_QUERY); i = 0; while (cb_locks[i].name && strcmp(cb_locks[i].fac, fac)) i++; cb->ss_req_lock = i; if (strlen(sic) > 0) goto bad_format; if (strlen(dn) > 0) goto bad_format; if (type != SS_CONTROL_TYPE_QUERY && !__ofono_is_valid_net_pin(sia)) goto bad_format; switch (type) { case SS_CONTROL_TYPE_ACTIVATION: case SS_CONTROL_TYPE_DEACTIVATION: case SS_CONTROL_TYPE_REGISTRATION: case SS_CONTROL_TYPE_ERASURE: operation = cb->driver->set; break; case SS_CONTROL_TYPE_QUERY: operation = cb->driver->query; break; default: break; } if (operation == NULL) { reply = __ofono_error_not_implemented(msg); g_dbus_send_message(conn, reply); return TRUE; } /* * According to 27.007, AG, AC and AB only work with mode = 0 * We support query by querying all relevant types, since we must * do this for the deactivation case anyway */ if ((!strcmp(fac, "AG") || !strcmp(fac, "AC") || !strcmp(fac, "AB")) && (type == SS_CONTROL_TYPE_ACTIVATION || type == SS_CONTROL_TYPE_REGISTRATION)) goto bad_format; if (strlen(sib) > 0) { long service_code; char *end; service_code = strtoul(sib, &end, 10); if (end == sib || *end != '\0') goto bad_format; cls = mmi_service_code_to_bearer_class(service_code); if (cls == 0) goto bad_format; } cb->ss_req_cls = cls; cb->pending = dbus_message_ref(msg); switch (type) { case SS_CONTROL_TYPE_ACTIVATION: case SS_CONTROL_TYPE_REGISTRATION: cb->ss_req_type = SS_CONTROL_TYPE_ACTIVATION; cb->driver->set(cb, fac, 1, sia, cls, cb_ss_set_lock_callback, cb); break; case SS_CONTROL_TYPE_ERASURE: case SS_CONTROL_TYPE_DEACTIVATION: cb->ss_req_type = SS_CONTROL_TYPE_DEACTIVATION; cb->driver->set(cb, fac, 0, sia, cls, cb_ss_set_lock_callback, cb); break; case SS_CONTROL_TYPE_QUERY: cb->ss_req_type = SS_CONTROL_TYPE_QUERY; cb_ss_query_next_lock(cb); break; } return TRUE; bad_format: reply = __ofono_error_invalid_format(msg); g_dbus_send_message(conn, reply); return TRUE; } static void cb_set_passwd_callback(const struct ofono_error *error, void *data) { struct ofono_call_barring *cb = data; DBusMessage *reply; if (error->type == OFONO_ERROR_TYPE_NO_ERROR) reply = dbus_message_new_method_return(cb->pending); else { DBG("Changing Call Barring password via SS failed with err: %s", telephony_error_to_str(error)); reply = __ofono_error_from_error(error, cb->pending); } __ofono_dbus_pending_reply(&cb->pending, reply); } static gboolean cb_ss_passwd(const char *sc, const char *old, const char *new, DBusMessage *msg, void *data) { struct ofono_call_barring *cb = data; DBusConnection *conn = ofono_dbus_get_connection(); DBusMessage *reply; const char *fac; if (__ofono_call_barring_is_busy(cb)) { reply = __ofono_error_busy(msg); g_dbus_send_message(conn, reply); return TRUE; } DBG("Received call barring ss password change request"); DBG("sc: %s", sc); if (!strcmp(sc, "")) fac = "AB"; else fac = cb_ss_service_to_fac(sc); if (fac == NULL) return FALSE; if (!__ofono_is_valid_net_pin(old) || !__ofono_is_valid_net_pin(new)) goto bad_format; cb->pending = dbus_message_ref(msg); cb->driver->set_passwd(cb, fac, old, new, cb_set_passwd_callback, cb); return TRUE; bad_format: reply = __ofono_error_invalid_format(msg); g_dbus_send_message(conn, reply); return TRUE; } static void cb_register_ss_controls(struct ofono_call_barring *cb) { __ofono_ussd_ssc_register(cb->ussd, "33", cb_ss_control, cb, NULL); __ofono_ussd_ssc_register(cb->ussd, "331", cb_ss_control, cb, NULL); __ofono_ussd_ssc_register(cb->ussd, "332", cb_ss_control, cb, NULL); __ofono_ussd_ssc_register(cb->ussd, "35", cb_ss_control, cb, NULL); __ofono_ussd_ssc_register(cb->ussd, "351", cb_ss_control, cb, NULL); __ofono_ussd_ssc_register(cb->ussd, "330", cb_ss_control, cb, NULL); __ofono_ussd_ssc_register(cb->ussd, "333", cb_ss_control, cb, NULL); __ofono_ussd_ssc_register(cb->ussd, "353", cb_ss_control, cb, NULL); __ofono_ussd_passwd_register(cb->ussd, "", cb_ss_passwd, cb, NULL); __ofono_ussd_passwd_register(cb->ussd, "33", cb_ss_passwd, cb, NULL); __ofono_ussd_passwd_register(cb->ussd, "331", cb_ss_passwd, cb, NULL); __ofono_ussd_passwd_register(cb->ussd, "332", cb_ss_passwd, cb, NULL); __ofono_ussd_passwd_register(cb->ussd, "35", cb_ss_passwd, cb, NULL); __ofono_ussd_passwd_register(cb->ussd, "351", cb_ss_passwd, cb, NULL); __ofono_ussd_passwd_register(cb->ussd, "330", cb_ss_passwd, cb, NULL); __ofono_ussd_passwd_register(cb->ussd, "333", cb_ss_passwd, cb, NULL); __ofono_ussd_passwd_register(cb->ussd, "353", cb_ss_passwd, cb, NULL); } static void cb_unregister_ss_controls(struct ofono_call_barring *cb) { __ofono_ussd_ssc_unregister(cb->ussd, "33"); __ofono_ussd_ssc_unregister(cb->ussd, "331"); __ofono_ussd_ssc_unregister(cb->ussd, "332"); __ofono_ussd_ssc_unregister(cb->ussd, "35"); __ofono_ussd_ssc_unregister(cb->ussd, "351"); __ofono_ussd_ssc_unregister(cb->ussd, "330"); __ofono_ussd_ssc_unregister(cb->ussd, "333"); __ofono_ussd_ssc_unregister(cb->ussd, "353"); __ofono_ussd_passwd_unregister(cb->ussd, ""); __ofono_ussd_passwd_unregister(cb->ussd, "33"); __ofono_ussd_passwd_unregister(cb->ussd, "331"); __ofono_ussd_passwd_unregister(cb->ussd, "332"); __ofono_ussd_passwd_unregister(cb->ussd, "35"); __ofono_ussd_passwd_unregister(cb->ussd, "351"); __ofono_ussd_passwd_unregister(cb->ussd, "330"); __ofono_ussd_passwd_unregister(cb->ussd, "333"); __ofono_ussd_passwd_unregister(cb->ussd, "353"); } gboolean __ofono_call_barring_is_busy(struct ofono_call_barring *cb) { return cb->pending ? TRUE : FALSE; } static inline void cb_append_property(struct ofono_call_barring *cb, DBusMessageIter *dict, int start, int end, int cls, const char *property) { char property_name[64]; const char *value = "disabled"; int i; for (i = start; i <= end; i++) if (cb->new_locks[i] & cls) break; if (i <= end) value = cb_locks[i].value; snprintf(property_name, sizeof(property_name), "%s%s", bearer_class_to_string(cls), property); ofono_dbus_dict_append(dict, property_name, DBUS_TYPE_STRING, &value); } static void cb_get_properties_reply(struct ofono_call_barring *cb, int mask) { DBusMessage *reply; DBusMessageIter iter, dict; int j; if (!(cb->flags & CALL_BARRING_FLAG_CACHED)) ofono_error("Generating a get_properties reply with no cache"); reply = dbus_message_new_method_return(cb->pending); if (reply == NULL) return; dbus_message_iter_init_append(reply, &iter); dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, OFONO_PROPERTIES_ARRAY_SIGNATURE, &dict); for (j = 1; j <= BEARER_CLASS_PAD; j = j << 1) { if ((j & mask) == 0) continue; cb_append_property(cb, &dict, CB_OUTGOING_START, CB_OUTGOING_END, j, "Outgoing"); cb_append_property(cb, &dict, CB_INCOMING_START, CB_INCOMING_END, j, "Incoming"); } dbus_message_iter_close_container(&iter, &dict); __ofono_dbus_pending_reply(&cb->pending, reply); } static void get_query_lock_callback(const struct ofono_error *error, int status, void *data) { struct ofono_call_barring *cb = data; if (error->type == OFONO_ERROR_TYPE_NO_ERROR) { cb->new_locks[cb->query_next] = status; if (cb->query_next == CB_ALL_END) cb->flags |= CALL_BARRING_FLAG_CACHED; } if (cb->query_next < CB_ALL_END) { cb->query_next = cb->query_next + 1; get_query_next_lock(cb); return; } cb_get_properties_reply(cb, BEARER_CLASS_VOICE); update_barrings(cb, BEARER_CLASS_VOICE); } static void get_query_next_lock(struct ofono_call_barring *cb) { cb->driver->query(cb, cb_locks[cb->query_next].fac, BEARER_CLASS_DEFAULT, get_query_lock_callback, cb); } static DBusMessage *cb_get_properties(DBusConnection *conn, DBusMessage *msg, void *data) { struct ofono_call_barring *cb = data; if (__ofono_call_barring_is_busy(cb) || __ofono_ussd_is_busy(cb->ussd)) return __ofono_error_busy(msg); if (cb->driver->query == NULL) return __ofono_error_not_implemented(msg); cb->pending = dbus_message_ref(msg); if (cb->flags & CALL_BARRING_FLAG_CACHED) cb_get_properties_reply(cb, BEARER_CLASS_VOICE); else { cb->query_next = CB_ALL_START; get_query_next_lock(cb); } return NULL; } static void set_query_lock_callback(const struct ofono_error *error, int status, void *data) { struct ofono_call_barring *cb = data; if (error->type != OFONO_ERROR_TYPE_NO_ERROR) { ofono_error("Disabling all barring successful, " "but query was not"); cb->flags &= ~CALL_BARRING_FLAG_CACHED; __ofono_dbus_pending_reply(&cb->pending, __ofono_error_failed(cb->pending)); return; } cb->new_locks[cb->query_next] = status; if (cb->query_next < cb->query_end) { cb->query_next += 1; set_query_next_lock(cb); return; } __ofono_dbus_pending_reply(&cb->pending, dbus_message_new_method_return(cb->pending)); update_barrings(cb, BEARER_CLASS_VOICE); } static void set_query_next_lock(struct ofono_call_barring *cb) { cb->driver->query(cb, cb_locks[cb->query_next].fac, BEARER_CLASS_DEFAULT, set_query_lock_callback, cb); } static void set_lock_callback(const struct ofono_error *error, void *data) { struct ofono_call_barring *cb = data; if (error->type != OFONO_ERROR_TYPE_NO_ERROR) { DBG("Enabling/disabling a lock failed"); __ofono_dbus_pending_reply(&cb->pending, __ofono_error_failed(cb->pending)); return; } /* * If we successfully set the value, we must query it back * Call Barring is a special case, since according to 22.088 2.2.1: * "The PLMN will ensure that only one of the barring programs is * active per basic service group. The activation of one specific * barring program will override an already active one (i.e. the * old one will be permanently deactivated)." * So we actually query all outgoing / incoming barrings depending * on what kind we set. */ set_query_next_lock(cb); } static gboolean cb_lock_property_lookup(const char *property, const char *value, int mask, int *out_which, int *out_cls, int *out_mode) { int i, j; const char *prefix; size_t len; int start, end; for (i = 1; i <= BEARER_CLASS_PAD; i = i << 1) { if ((i & mask) == 0) continue; prefix = bearer_class_to_string(i); len = strlen(prefix); if (!strncmp(property, prefix, len)) { property += len; break; } } if (i > BEARER_CLASS_PAD) return FALSE; if (!strcmp(property, "Outgoing")) { start = CB_OUTGOING_START; end = CB_OUTGOING_END; } else if (!strcmp(property, "Incoming")) { start = CB_INCOMING_START; end = CB_INCOMING_END; } else { return FALSE; } /* * Gah, this is a special case. If we're setting a barring to * disabled, then generate a disable all outgoing/incoming * request for a particular basic service */ if (!strcmp(value, "disabled")) { *out_mode = 0; *out_cls = i; if (!strcmp(property, "Outgoing")) *out_which = CB_ALL_OUTGOING; else *out_which = CB_ALL_INCOMING; return TRUE; } for (j = start; j <= end; j++) { if (strcmp(value, cb_locks[j].value)) continue; *out_mode = 1; *out_cls = i; *out_which = j; return TRUE; } return FALSE; } static DBusMessage *cb_set_property(DBusConnection *conn, DBusMessage *msg, void *data) { struct ofono_call_barring *cb = data; DBusMessageIter iter; DBusMessageIter var; const char *name, *passwd = ""; const char *value; int lock; int cls; int mode; if (__ofono_call_barring_is_busy(cb) || __ofono_ussd_is_busy(cb->ussd)) return __ofono_error_busy(msg); if (!dbus_message_iter_init(msg, &iter)) return __ofono_error_invalid_args(msg); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return __ofono_error_invalid_args(msg); dbus_message_iter_get_basic(&iter, &name); dbus_message_iter_next(&iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) return __ofono_error_invalid_args(msg); dbus_message_iter_recurse(&iter, &var); if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_STRING) return __ofono_error_invalid_args(msg); dbus_message_iter_get_basic(&var, &value); if (!cb_lock_property_lookup(name, value, BEARER_CLASS_VOICE, &lock, &cls, &mode)) return __ofono_error_invalid_args(msg); if (dbus_message_iter_next(&iter)) { if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return __ofono_error_invalid_args(msg); dbus_message_iter_get_basic(&iter, &passwd); if (!__ofono_is_valid_net_pin(passwd)) return __ofono_error_invalid_format(msg); } if (cb->driver->set == NULL) return __ofono_error_not_implemented(msg); cb_set_query_bounds(cb, cb_locks[lock].fac, FALSE); cb->pending = dbus_message_ref(msg); cb->driver->set(cb, cb_locks[lock].fac, mode, passwd, cls, set_lock_callback, cb); return NULL; } static void disable_all_callback(const struct ofono_error *error, void *data) { struct ofono_call_barring *cb = data; if (error->type != OFONO_ERROR_TYPE_NO_ERROR) { DBG("Disabling all barring failed"); __ofono_dbus_pending_reply(&cb->pending, __ofono_error_failed(cb->pending)); return; } /* Assume if we have set, we have query */ set_query_next_lock(cb); } static DBusMessage *cb_disable_all(DBusConnection *conn, DBusMessage *msg, void *data, const char *fac) { struct ofono_call_barring *cb = data; const char *passwd; if (cb->driver->set == NULL) return __ofono_error_not_implemented(msg); if (__ofono_call_barring_is_busy(cb) || __ofono_ussd_is_busy(cb->ussd)) return __ofono_error_busy(msg); if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &passwd, DBUS_TYPE_INVALID) == FALSE) return __ofono_error_invalid_args(msg); if (!__ofono_is_valid_net_pin(passwd)) return __ofono_error_invalid_format(msg); cb_set_query_bounds(cb, fac, FALSE); cb->pending = dbus_message_ref(msg); cb->driver->set(cb, fac, 0, passwd, BEARER_CLASS_DEFAULT, disable_all_callback, cb); return NULL; } static DBusMessage *cb_disable_ab(DBusConnection *conn, DBusMessage *msg, void *data) { return cb_disable_all(conn, msg, data, "AB"); } static DBusMessage *cb_disable_ac(DBusConnection *conn, DBusMessage *msg, void *data) { return cb_disable_all(conn, msg, data, "AC"); } static DBusMessage *cb_disable_ag(DBusConnection *conn, DBusMessage *msg, void *data) { return cb_disable_all(conn, msg, data, "AG"); } static DBusMessage *cb_set_passwd(DBusConnection *conn, DBusMessage *msg, void *data) { struct ofono_call_barring *cb = data; const char *old_passwd; const char *new_passwd; if (cb->driver->set_passwd == NULL) return __ofono_error_not_implemented(msg); if (__ofono_call_barring_is_busy(cb) || __ofono_ussd_is_busy(cb->ussd)) return __ofono_error_busy(msg); if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &old_passwd, DBUS_TYPE_STRING, &new_passwd, DBUS_TYPE_INVALID) == FALSE) return __ofono_error_invalid_args(msg); if (!__ofono_is_valid_net_pin(old_passwd)) return __ofono_error_invalid_format(msg); if (!__ofono_is_valid_net_pin(new_passwd)) return __ofono_error_invalid_format(msg); cb->pending = dbus_message_ref(msg); cb->driver->set_passwd(cb, "AB", old_passwd, new_passwd, cb_set_passwd_callback, cb); return NULL; } static const GDBusMethodTable cb_methods[] = { { GDBUS_ASYNC_METHOD("GetProperties", NULL, GDBUS_ARGS({ "properties", "a{sv}" }), cb_get_properties) }, { GDBUS_ASYNC_METHOD("SetProperty", GDBUS_ARGS({ "property", "s" }, { "value", "v" }, { "pin2", "s" }), NULL, cb_set_property) }, { GDBUS_ASYNC_METHOD("DisableAll", GDBUS_ARGS({ "password", "s" }), NULL, cb_disable_ab) }, { GDBUS_ASYNC_METHOD("DisableAllIncoming", GDBUS_ARGS({ "password", "s" }), NULL, cb_disable_ac) }, { GDBUS_ASYNC_METHOD("DisableAllOutgoing", GDBUS_ARGS({ "password", "s" }), NULL, cb_disable_ag) }, { GDBUS_ASYNC_METHOD("ChangePassword", GDBUS_ARGS({ "old", "s" }, { "new", "s" }), NULL, cb_set_passwd) }, { } }; static const GDBusSignalTable cb_signals[] = { { GDBUS_SIGNAL("PropertyChanged", GDBUS_ARGS({ "name", "s" }, { "value", "v" })) }, { } }; int ofono_call_barring_driver_register(const struct ofono_call_barring_driver *d) { DBG("driver: %p, name: %s", d, d->name); if (d->probe == NULL) return -EINVAL; g_drivers = g_slist_prepend(g_drivers, (void *) d); return 0; } void ofono_call_barring_driver_unregister(const struct ofono_call_barring_driver *d) { DBG("driver: %p, name: %s", d, d->name); g_drivers = g_slist_remove(g_drivers, (void *) d); } static void call_barring_unregister(struct ofono_atom *atom) { struct ofono_call_barring *cb = __ofono_atom_get_data(atom); const char *path = __ofono_atom_get_path(cb->atom); DBusConnection *conn = ofono_dbus_get_connection(); struct ofono_modem *modem = __ofono_atom_get_modem(cb->atom); ofono_modem_remove_interface(modem, OFONO_CALL_BARRING_INTERFACE); g_dbus_unregister_interface(conn, path, OFONO_CALL_BARRING_INTERFACE); if (cb->ussd) cb_unregister_ss_controls(cb); if (cb->ussd_watch) __ofono_modem_remove_atom_watch(modem, cb->ussd_watch); } static void call_barring_remove(struct ofono_atom *atom) { struct ofono_call_barring *cb = __ofono_atom_get_data(atom); DBG("atom: %p", atom); if (cb == NULL) return; if (cb->driver != NULL && cb->driver->remove != NULL) cb->driver->remove(cb); g_free(cb); } struct ofono_call_barring *ofono_call_barring_create(struct ofono_modem *modem, unsigned int vendor, const char *driver, void *data) { struct ofono_call_barring *cb; GSList *l; if (driver == NULL) return NULL; cb = g_try_new0(struct ofono_call_barring, 1); if (cb == NULL) return NULL; cb->atom = __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_CALL_BARRING, call_barring_remove, cb); for (l = g_drivers; l; l = l->next) { const struct ofono_call_barring_driver *drv = l->data; if (g_strcmp0(drv->name, driver)) continue; if (drv->probe(cb, vendor, data) < 0) continue; cb->driver = drv; break; } return cb; } static void ussd_watch(struct ofono_atom *atom, enum ofono_atom_watch_condition cond, void *data) { struct ofono_call_barring *cb = data; if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) { cb->ussd = NULL; return; } cb->ussd = __ofono_atom_get_data(atom); cb_register_ss_controls(cb); } void ofono_call_barring_register(struct ofono_call_barring *cb) { DBusConnection *conn = ofono_dbus_get_connection(); const char *path = __ofono_atom_get_path(cb->atom); struct ofono_modem *modem = __ofono_atom_get_modem(cb->atom); if (!g_dbus_register_interface(conn, path, OFONO_CALL_BARRING_INTERFACE, cb_methods, cb_signals, NULL, cb, NULL)) { ofono_error("Could not create %s interface", OFONO_CALL_BARRING_INTERFACE); return; } ofono_modem_add_interface(modem, OFONO_CALL_BARRING_INTERFACE); cb->ussd_watch = __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_USSD, ussd_watch, cb, NULL); __ofono_atom_register(cb->atom, call_barring_unregister); } void ofono_call_barring_remove(struct ofono_call_barring *cb) { __ofono_atom_free(cb->atom); } void ofono_call_barring_set_data(struct ofono_call_barring *cb, void *data) { cb->driver_data = data; } void *ofono_call_barring_get_data(struct ofono_call_barring *cb) { return cb->driver_data; } |