blob: be951c415377aba52f90abe1a534d2bb3ddc15eb [file] [log] [blame]
Harald Welteccceef82009-08-13 00:57:54 +02001/* SMS based token authentication for ad-hoc GSM networks */
2
3/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23#include <openbsc/signal.h>
24#include <openbsc/gsm_data.h>
25#include <openbsc/gsm_04_11.h>
26#include <openbsc/gsm_04_08.h>
27#include <openbsc/gsm_subscriber.h>
28
29#define TOKEN_SMS_TEXT "HAR 2009 GSM. Please visit http://127.0.0.1/ to register"
30
31static int token_subscr_cb(unsigned int subsys, unsigned int signal,
32 void *handler_data, void *signal_data)
33{
34 struct gsm_subscriber *subscr = signal_data;
35 struct gsm_sms *sms;
36
37 if (subscr->net->auth_policy != GSM_AUTH_POLICY_TOKEN)
38 return 0;
39
40 switch (signal) {
41 case S_SUBSCR_FIRST_CONTACT:
42 /* we've seen this subscriber for the first time. */
43 sms = sms_from_text(subscr, TOKEN_SMS_TEXT);
44 if (!sms)
45 return -ENOMEM;
46 gsm411_send_sms_subscr(subscr, sms);
47 break;
48 }
49
50 return 0;
51}
52
53static int token_sms_cb(unsigned int subsys, unsigned int signal,
54 void *handler_data, void *signal_data)
55{
56 struct gsm_sms *sms = signal_data;
57 struct gsm_lchan *lchan;
58 u_int16_t rand[16];
59
60 if (signal != S_SMS_DELIVERED)
61 return 0;
62
63 /* these are not the droids we've been looking for */
64 if (!sms->receiver ||
65 !(sms->receiver->flags & GSM_SUBSCRIBER_FIRST_CONTACT))
66 return 0;
67
68 if (sms->receiver->net->auth_policy != GSM_AUTH_POLICY_TOKEN)
69 return 0;
70
71 lchan = lchan_for_subscr(sms->receiver);
72 if (lchan) {
73 /* kick the subscriber off the network */
74 gsm48_tx_mm_auth_req(lchan, rand);
75 gsm48_tx_mm_auth_rej(lchan);
76 /* close the channel */
77 //gsm48_send_rr_Release(lchan);
78 lchan_free(lchan);
79 }
80
81 /* make sure we don't allow him in again unless he clicks the web UI */
82 sms->receiver->authorized = 0;
83 db_sync_subscriber(sms->receiver);
84
85 return 0;
86}
87
88static __attribute__((constructor)) void on_dso_load_token(void)
89{
90 register_signal_handler(SS_SUBSCR, token_subscr_cb, NULL);
91 register_signal_handler(SS_SMS, token_sms_cb, NULL);
92}