Holger Hans Peter Freyther | 11b28f9 | 2010-12-24 13:48:27 +0100 | [diff] [blame^] | 1 | /* SMS queue to continously attempt to deliver SMS */ |
| 2 | /* |
| 3 | * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * The difficulty of such a queue is to send a lot of SMS without |
| 24 | * overloading the paging subsystem and the database and other users |
| 25 | * of the MSC. To make the best use we would need to know the number |
| 26 | * of pending paging requests, then throttle the number of SMS we |
| 27 | * want to send and such. |
| 28 | * We will start with a very simple SMS Queue and then try to speed |
| 29 | * things up by collecting data from other parts of the system. |
| 30 | */ |
| 31 | |
| 32 | #include <openbsc/sms_queue.h> |
| 33 | #include <openbsc/chan_alloc.h> |
| 34 | #include <openbsc/db.h> |
| 35 | #include <openbsc/debug.h> |
| 36 | #include <openbsc/gsm_data.h> |
| 37 | #include <openbsc/gsm_04_11.h> |
| 38 | #include <openbsc/signal.h> |
| 39 | |
| 40 | #include <osmocore/talloc.h> |
| 41 | |
| 42 | |
| 43 | struct gsm_sms_queue { |
| 44 | struct gsm_network *network; |
| 45 | int max_pending; |
| 46 | int pending; |
| 47 | }; |
| 48 | |
| 49 | |
| 50 | int sms_queue_start(struct gsm_network *network, int max_pending) |
| 51 | { |
| 52 | struct gsm_sms_queue *sms = talloc_zero(network, struct gsm_sms_queue); |
| 53 | if (!sms) { |
| 54 | LOGP(DMSC, LOGL_ERROR, "Failed to create the SMS queue.\n"); |
| 55 | return -1; |
| 56 | } |
| 57 | |
| 58 | network->sms_queue = sms; |
| 59 | sms->network = network; |
| 60 | sms->max_pending = max_pending; |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static int sub_ready_for_sm(struct gsm_subscriber *subscr) |
| 66 | { |
| 67 | struct gsm_subscriber_connection *conn; |
| 68 | struct gsm_sms *sms; |
| 69 | |
| 70 | /* A subscriber has attached. Check if there are |
| 71 | * any pending SMS for him to be delivered */ |
| 72 | conn = connection_for_subscr(subscr); |
| 73 | if (!conn) |
| 74 | return -1; |
| 75 | sms = db_sms_get_unsent_for_subscr(subscr); |
| 76 | if (!sms) |
| 77 | return -1; |
| 78 | gsm411_send_sms(conn, sms); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static int sms_subscr_cb(unsigned int subsys, unsigned int signal, |
| 83 | void *handler_data, void *signal_data) |
| 84 | { |
| 85 | struct gsm_subscriber *subscr = signal_data; |
| 86 | |
| 87 | if (signal != S_SUBSCR_ATTACHED) |
| 88 | return 0; |
| 89 | |
| 90 | /* this is readyForSM */ |
| 91 | return sub_ready_for_sm(subscr); |
| 92 | } |
| 93 | |
| 94 | static __attribute__((constructor)) void on_dso_load_sms(void) |
| 95 | { |
| 96 | register_signal_handler(SS_SUBSCR, sms_subscr_cb, NULL); |
| 97 | } |